clang  8.0.0svn
Sema.h
Go to the documentation of this file.
1 //===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the Sema class, which performs semantic analysis and
11 // builds ASTs.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_SEMA_SEMA_H
16 #define LLVM_CLANG_SEMA_SEMA_H
17 
18 #include "clang/AST/Attr.h"
19 #include "clang/AST/Availability.h"
21 #include "clang/AST/DeclTemplate.h"
23 #include "clang/AST/Expr.h"
24 #include "clang/AST/ExprCXX.h"
25 #include "clang/AST/ExprObjC.h"
27 #include "clang/AST/LocInfoType.h"
29 #include "clang/AST/NSAPI.h"
31 #include "clang/AST/StmtCXX.h"
32 #include "clang/AST/TypeLoc.h"
33 #include "clang/AST/TypeOrdering.h"
35 #include "clang/Basic/Module.h"
38 #include "clang/Basic/Specifiers.h"
40 #include "clang/Basic/TypeTraits.h"
42 #include "clang/Sema/CleanupInfo.h"
43 #include "clang/Sema/DeclSpec.h"
47 #include "clang/Sema/Ownership.h"
48 #include "clang/Sema/Scope.h"
50 #include "clang/Sema/Weak.h"
51 #include "llvm/ADT/ArrayRef.h"
52 #include "llvm/ADT/Optional.h"
53 #include "llvm/ADT/SetVector.h"
54 #include "llvm/ADT/SmallBitVector.h"
55 #include "llvm/ADT/SmallPtrSet.h"
56 #include "llvm/ADT/SmallVector.h"
57 #include "llvm/ADT/TinyPtrVector.h"
58 #include <deque>
59 #include <memory>
60 #include <string>
61 #include <vector>
62 
63 namespace llvm {
64  class APSInt;
65  template <typename ValueT> struct DenseMapInfo;
66  template <typename ValueT, typename ValueInfoT> class DenseSet;
67  class SmallBitVector;
68  struct InlineAsmIdentifierInfo;
69 }
70 
71 namespace clang {
72  class ADLResult;
73  class ASTConsumer;
74  class ASTContext;
75  class ASTMutationListener;
76  class ASTReader;
77  class ASTWriter;
78  class ArrayType;
79  class ParsedAttr;
80  class BindingDecl;
81  class BlockDecl;
82  class CapturedDecl;
83  class CXXBasePath;
84  class CXXBasePaths;
85  class CXXBindTemporaryExpr;
87  class CXXConstructorDecl;
88  class CXXConversionDecl;
89  class CXXDeleteExpr;
90  class CXXDestructorDecl;
91  class CXXFieldCollector;
92  class CXXMemberCallExpr;
93  class CXXMethodDecl;
94  class CXXScopeSpec;
95  class CXXTemporary;
96  class CXXTryStmt;
97  class CallExpr;
98  class ClassTemplateDecl;
99  class ClassTemplatePartialSpecializationDecl;
100  class ClassTemplateSpecializationDecl;
101  class VarTemplatePartialSpecializationDecl;
102  class CodeCompleteConsumer;
103  class CodeCompletionAllocator;
104  class CodeCompletionTUInfo;
105  class CodeCompletionResult;
106  class CoroutineBodyStmt;
107  class Decl;
108  class DeclAccessPair;
109  class DeclContext;
110  class DeclRefExpr;
111  class DeclaratorDecl;
112  class DeducedTemplateArgument;
113  class DependentDiagnostic;
114  class DesignatedInitExpr;
115  class Designation;
116  class EnableIfAttr;
117  class EnumConstantDecl;
118  class Expr;
119  class ExtVectorType;
120  class FormatAttr;
121  class FriendDecl;
122  class FunctionDecl;
123  class FunctionProtoType;
124  class FunctionTemplateDecl;
125  class ImplicitConversionSequence;
127  class InitListExpr;
128  class InitializationKind;
129  class InitializationSequence;
130  class InitializedEntity;
131  class IntegerLiteral;
132  class LabelStmt;
133  class LambdaExpr;
134  class LangOptions;
135  class LocalInstantiationScope;
136  class LookupResult;
137  class MacroInfo;
139  class ModuleLoader;
140  class MultiLevelTemplateArgumentList;
141  class NamedDecl;
142  class ObjCCategoryDecl;
143  class ObjCCategoryImplDecl;
144  class ObjCCompatibleAliasDecl;
145  class ObjCContainerDecl;
146  class ObjCImplDecl;
147  class ObjCImplementationDecl;
148  class ObjCInterfaceDecl;
149  class ObjCIvarDecl;
150  template <class T> class ObjCList;
151  class ObjCMessageExpr;
152  class ObjCMethodDecl;
153  class ObjCPropertyDecl;
154  class ObjCProtocolDecl;
155  class OMPThreadPrivateDecl;
156  class OMPRequiresDecl;
157  class OMPDeclareReductionDecl;
158  class OMPDeclareSimdDecl;
159  class OMPClause;
160  struct OverloadCandidate;
161  class OverloadCandidateSet;
162  class OverloadExpr;
163  class ParenListExpr;
164  class ParmVarDecl;
165  class Preprocessor;
166  class PseudoDestructorTypeStorage;
167  class PseudoObjectExpr;
168  class QualType;
169  class StandardConversionSequence;
170  class Stmt;
171  class StringLiteral;
172  class SwitchStmt;
173  class TemplateArgument;
174  class TemplateArgumentList;
175  class TemplateArgumentLoc;
176  class TemplateDecl;
177  class TemplateInstantiationCallback;
178  class TemplateParameterList;
179  class TemplatePartialOrderingContext;
180  class TemplateTemplateParmDecl;
181  class Token;
182  class TypeAliasDecl;
183  class TypedefDecl;
184  class TypedefNameDecl;
185  class TypeLoc;
186  class TypoCorrectionConsumer;
187  class UnqualifiedId;
188  class UnresolvedLookupExpr;
189  class UnresolvedMemberExpr;
190  class UnresolvedSetImpl;
191  class UnresolvedSetIterator;
192  class UsingDecl;
193  class UsingShadowDecl;
194  class ValueDecl;
195  class VarDecl;
196  class VarTemplateSpecializationDecl;
197  class VisibilityAttr;
198  class VisibleDeclConsumer;
199  class IndirectFieldDecl;
200  struct DeductionFailureInfo;
201  class TemplateSpecCandidateSet;
202 
203 namespace sema {
204  class AccessedEntity;
205  class BlockScopeInfo;
206  class Capture;
207  class CapturedRegionScopeInfo;
208  class CapturingScopeInfo;
209  class CompoundScopeInfo;
210  class DelayedDiagnostic;
211  class DelayedDiagnosticPool;
212  class FunctionScopeInfo;
213  class LambdaScopeInfo;
214  class PossiblyUnreachableDiag;
215  class SemaPPCallbacks;
216  class TemplateDeductionInfo;
217 }
218 
219 namespace threadSafety {
220  class BeforeSet;
221  void threadSafetyCleanup(BeforeSet* Cache);
222 }
223 
224 // FIXME: No way to easily map from TemplateTypeParmTypes to
225 // TemplateTypeParmDecls, so we have this horrible PointerUnion.
226 typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType*, NamedDecl*>,
228 
229 /// Describes whether we've seen any nullability information for the given
230 /// file.
232  /// The first pointer declarator (of any pointer kind) in the file that does
233  /// not have a corresponding nullability annotation.
235 
236  /// The end location for the first pointer declarator in the file. Used for
237  /// placing fix-its.
239 
240  /// Which kind of pointer declarator we saw.
241  uint8_t PointerKind;
242 
243  /// Whether we saw any type nullability annotations in the given file.
244  bool SawTypeNullability = false;
245 };
246 
247 /// A mapping from file IDs to a record of whether we've seen nullability
248 /// information in that file.
250  /// A mapping from file IDs to the nullability information for each file ID.
251  llvm::DenseMap<FileID, FileNullability> Map;
252 
253  /// A single-element cache based on the file ID.
254  struct {
257  } Cache;
258 
259 public:
261  // Check the single-element cache.
262  if (file == Cache.File)
263  return Cache.Nullability;
264 
265  // It's not in the single-element cache; flush the cache if we have one.
266  if (!Cache.File.isInvalid()) {
267  Map[Cache.File] = Cache.Nullability;
268  }
269 
270  // Pull this entry into the cache.
271  Cache.File = file;
272  Cache.Nullability = Map[file];
273  return Cache.Nullability;
274  }
275 };
276 
277 /// Sema - This implements semantic analysis and AST building for C.
278 class Sema {
279  Sema(const Sema &) = delete;
280  void operator=(const Sema &) = delete;
281 
282  ///Source of additional semantic information.
283  ExternalSemaSource *ExternalSource;
284 
285  ///Whether Sema has generated a multiplexer and has to delete it.
286  bool isMultiplexExternalSource;
287 
288  static bool mightHaveNonExternalLinkage(const DeclaratorDecl *FD);
289 
290  bool isVisibleSlow(const NamedDecl *D);
291 
292  /// Determine whether two declarations should be linked together, given that
293  /// the old declaration might not be visible and the new declaration might
294  /// not have external linkage.
295  bool shouldLinkPossiblyHiddenDecl(const NamedDecl *Old,
296  const NamedDecl *New) {
297  if (isVisible(Old))
298  return true;
299  // See comment in below overload for why it's safe to compute the linkage
300  // of the new declaration here.
301  if (New->isExternallyDeclarable()) {
302  assert(Old->isExternallyDeclarable() &&
303  "should not have found a non-externally-declarable previous decl");
304  return true;
305  }
306  return false;
307  }
308  bool shouldLinkPossiblyHiddenDecl(LookupResult &Old, const NamedDecl *New);
309 
310 public:
314 
317 
324 
325  /// Flag indicating whether or not to collect detailed statistics.
327 
328  /// Code-completion consumer.
330 
331  /// CurContext - This is the current declaration context of parsing.
333 
334  /// Generally null except when we temporarily switch decl contexts,
335  /// like in \see ActOnObjCTemporaryExitContainerContext.
337 
338  /// VAListTagName - The declaration name corresponding to __va_list_tag.
339  /// This is used as part of a hack to omit that class from ADL results.
341 
342  bool MSStructPragmaOn; // True when \#pragma ms_struct on
343 
344  /// Controls member pointer representation format under the MS ABI.
347 
348  /// Stack of active SEH __finally scopes. Can be empty.
350 
351  /// Source location for newly created implicit MSInheritanceAttrs
353 
354  /// pragma clang section kind
356  PCSK_Invalid = 0,
357  PCSK_BSS = 1,
358  PCSK_Data = 2,
359  PCSK_Rodata = 3,
360  PCSK_Text = 4
361  };
362 
364  PCSA_Set = 0,
365  PCSA_Clear = 1
366  };
367 
369  std::string SectionName;
370  bool Valid = false;
372 
373  void Act(SourceLocation PragmaLocation,
375  StringLiteral* Name);
376  };
377 
382 
384  PSK_Reset = 0x0, // #pragma ()
385  PSK_Set = 0x1, // #pragma (value)
386  PSK_Push = 0x2, // #pragma (push[, id])
387  PSK_Pop = 0x4, // #pragma (pop[, id])
388  PSK_Show = 0x8, // #pragma (show) -- only for "pack"!
389  PSK_Push_Set = PSK_Push | PSK_Set, // #pragma (push[, id], value)
390  PSK_Pop_Set = PSK_Pop | PSK_Set, // #pragma (pop[, id], value)
391  };
392 
393  template<typename ValueType>
394  struct PragmaStack {
395  struct Slot {
396  llvm::StringRef StackSlotLabel;
397  ValueType Value;
400  Slot(llvm::StringRef StackSlotLabel, ValueType Value,
401  SourceLocation PragmaLocation, SourceLocation PragmaPushLocation)
402  : StackSlotLabel(StackSlotLabel), Value(Value),
403  PragmaLocation(PragmaLocation),
404  PragmaPushLocation(PragmaPushLocation) {}
405  };
406  void Act(SourceLocation PragmaLocation,
407  PragmaMsStackAction Action,
408  llvm::StringRef StackSlotLabel,
409  ValueType Value);
410 
411  // MSVC seems to add artificial slots to #pragma stacks on entering a C++
412  // method body to restore the stacks on exit, so it works like this:
413  //
414  // struct S {
415  // #pragma <name>(push, InternalPragmaSlot, <current_pragma_value>)
416  // void Method {}
417  // #pragma <name>(pop, InternalPragmaSlot)
418  // };
419  //
420  // It works even with #pragma vtordisp, although MSVC doesn't support
421  // #pragma vtordisp(push [, id], n)
422  // syntax.
423  //
424  // Push / pop a named sentinel slot.
425  void SentinelAction(PragmaMsStackAction Action, StringRef Label) {
426  assert((Action == PSK_Push || Action == PSK_Pop) &&
427  "Can only push / pop #pragma stack sentinels!");
428  Act(CurrentPragmaLocation, Action, Label, CurrentValue);
429  }
430 
431  // Constructors.
432  explicit PragmaStack(const ValueType &Default)
433  : DefaultValue(Default), CurrentValue(Default) {}
434 
435  bool hasValue() const { return CurrentValue != DefaultValue; }
436 
438  ValueType DefaultValue; // Value used for PSK_Reset action.
439  ValueType CurrentValue;
441  };
442  // FIXME: We should serialize / deserialize these if they occur in a PCH (but
443  // we shouldn't do so if they're in a module).
444 
445  /// Whether to insert vtordisps prior to virtual bases in the Microsoft
446  /// C++ ABI. Possible values are 0, 1, and 2, which mean:
447  ///
448  /// 0: Suppress all vtordisps
449  /// 1: Insert vtordisps in the presence of vbase overrides and non-trivial
450  /// structors
451  /// 2: Always insert vtordisps to support RTTI on partially constructed
452  /// objects
454  // #pragma pack.
455  // Sentinel to represent when the stack is set to mac68k alignment.
456  static const unsigned kMac68kAlignmentSentinel = ~0U;
458  // The current #pragma pack values and locations at each #include.
460  unsigned CurrentValue;
462  bool HasNonDefaultValue, ShouldWarnOnInclude;
463  };
465  // Segment #pragmas.
470 
471  // RAII object to push / pop sentinel slots for all MS #pragma stacks.
472  // Actions should be performed only if we enter / exit a C++ method body.
474  public:
475  PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct);
477 
478  private:
479  Sema &S;
480  StringRef SlotLabel;
481  bool ShouldAct;
482  };
483 
484  /// A mapping that describes the nullability we've seen in each header file.
486 
487  /// Last section used with #pragma init_seg.
490 
491  /// VisContext - Manages the stack for \#pragma GCC visibility.
492  void *VisContext; // Really a "PragmaVisStack*"
493 
494  /// This an attribute introduced by \#pragma clang attribute.
499  bool IsUsed;
500  };
501 
502  /// A push'd group of PragmaAttributeEntries.
504  /// The location of the push attribute.
507  };
508 
510 
511  /// The declaration that is currently receiving an attribute from the
512  /// #pragma attribute stack.
514 
515  /// This represents the last location of a "#pragma clang optimize off"
516  /// directive if such a directive has not been closed by an "on" yet. If
517  /// optimizations are currently "on", this is set to an invalid location.
519 
520  /// Flag indicating if Sema is building a recovery call expression.
521  ///
522  /// This flag is used to avoid building recovery call expressions
523  /// if Sema is already doing so, which would cause infinite recursions.
525 
526  /// Used to control the generation of ExprWithCleanups.
528 
529  /// ExprCleanupObjects - This is the stack of objects requiring
530  /// cleanup that are created by the current full expression. The
531  /// element type here is ExprWithCleanups::Object.
533 
534  /// Store a list of either DeclRefExprs or MemberExprs
535  /// that contain a reference to a variable (constant) that may or may not
536  /// be odr-used in this Expr, and we won't know until all lvalue-to-rvalue
537  /// and discarded value conversions have been applied to all subexpressions
538  /// of the enclosing full expression. This is cleared at the end of each
539  /// full expression.
540  llvm::SmallPtrSet<Expr*, 2> MaybeODRUseExprs;
541 
542  std::unique_ptr<sema::FunctionScopeInfo> PreallocatedFunctionScope;
543 
544  /// Stack containing information about each of the nested
545  /// function, block, and method scopes that are currently active.
547 
549  &ExternalSemaSource::ReadExtVectorDecls, 2, 2>
551 
552  /// ExtVectorDecls - This is a list all the extended vector types. This allows
553  /// us to associate a raw vector type with one of the ext_vector type names.
554  /// This is only necessary for issuing pretty diagnostics.
556 
557  /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
558  std::unique_ptr<CXXFieldCollector> FieldCollector;
559 
561 
562  /// Set containing all declared private fields that are not used.
563  NamedDeclSetType UnusedPrivateFields;
564 
565  /// Set containing all typedefs that are likely unused.
568 
569  /// Delete-expressions to be analyzed at the end of translation unit
570  ///
571  /// This list contains class members, and locations of delete-expressions
572  /// that could not be proven as to whether they mismatch with new-expression
573  /// used in initializer of the field.
574  typedef std::pair<SourceLocation, bool> DeleteExprLoc;
576  llvm::MapVector<FieldDecl *, DeleteLocs> DeleteExprs;
577 
578  typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy;
579 
580  /// PureVirtualClassDiagSet - a set of class declarations which we have
581  /// emitted a list of pure virtual functions. Used to prevent emitting the
582  /// same list more than once.
583  std::unique_ptr<RecordDeclSetTy> PureVirtualClassDiagSet;
584 
585  /// ParsingInitForAutoVars - a set of declarations with auto types for which
586  /// we are currently parsing the initializer.
587  llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars;
588 
589  /// Look for a locally scoped extern "C" declaration by the given name.
590  NamedDecl *findLocallyScopedExternCDecl(DeclarationName Name);
591 
592  typedef LazyVector<VarDecl *, ExternalSemaSource,
593  &ExternalSemaSource::ReadTentativeDefinitions, 2, 2>
595 
596  /// All the tentative definitions encountered in the TU.
598 
599  typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource,
600  &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2>
602 
603  /// The set of file scoped decls seen so far that have not been used
604  /// and must warn if not used. Only contains the first declaration.
606 
607  typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource,
608  &ExternalSemaSource::ReadDelegatingConstructors, 2, 2>
610 
611  /// All the delegating constructors seen so far in the file, used for
612  /// cycle detection at the end of the TU.
614 
615  /// All the overriding functions seen during a class definition
616  /// that had their exception spec checks delayed, plus the overridden
617  /// function.
620 
621  /// All the function redeclarations seen during a class definition that had
622  /// their exception spec checks delayed, plus the prior declaration they
623  /// should be checked against. Except during error recovery, the new decl
624  /// should always be a friend declaration, as that's the only valid way to
625  /// redeclare a special member before its class is complete.
628 
629  /// All the members seen during a class definition which were both
630  /// explicitly defaulted and had explicitly-specified exception
631  /// specifications, along with the function type containing their
632  /// user-specified exception specification. Those exception specifications
633  /// were overridden with the default specifications, but we still need to
634  /// check whether they are compatible with the default specification, and
635  /// we can't do that until the nesting set of class definitions is complete.
638 
639  typedef llvm::MapVector<const FunctionDecl *,
640  std::unique_ptr<LateParsedTemplate>>
643 
644  /// Callback to the parser to parse templated functions when needed.
645  typedef void LateTemplateParserCB(void *P, LateParsedTemplate &LPT);
646  typedef void LateTemplateParserCleanupCB(void *P);
647  LateTemplateParserCB *LateTemplateParser;
648  LateTemplateParserCleanupCB *LateTemplateParserCleanup;
650 
651  void SetLateTemplateParser(LateTemplateParserCB *LTP,
652  LateTemplateParserCleanupCB *LTPCleanup,
653  void *P) {
654  LateTemplateParser = LTP;
655  LateTemplateParserCleanup = LTPCleanup;
656  OpaqueParser = P;
657  }
658 
659  class DelayedDiagnostics;
660 
662  sema::DelayedDiagnosticPool *SavedPool;
664  };
667 
668  /// A class which encapsulates the logic for delaying diagnostics
669  /// during parsing and other processing.
671  /// The current pool of diagnostics into which delayed
672  /// diagnostics should go.
674 
675  public:
676  DelayedDiagnostics() : CurPool(nullptr) {}
677 
678  /// Adds a delayed diagnostic.
679  void add(const sema::DelayedDiagnostic &diag); // in DelayedDiagnostic.h
680 
681  /// Determines whether diagnostics should be delayed.
682  bool shouldDelayDiagnostics() { return CurPool != nullptr; }
683 
684  /// Returns the current delayed-diagnostics pool.
686  return CurPool;
687  }
688 
689  /// Enter a new scope. Access and deprecation diagnostics will be
690  /// collected in this pool.
693  state.SavedPool = CurPool;
694  CurPool = &pool;
695  return state;
696  }
697 
698  /// Leave a delayed-diagnostic state that was previously pushed.
699  /// Do not emit any of the diagnostics. This is performed as part
700  /// of the bookkeeping of popping a pool "properly".
702  CurPool = state.SavedPool;
703  }
704 
705  /// Enter a new scope where access and deprecation diagnostics are
706  /// not delayed.
709  state.SavedPool = CurPool;
710  CurPool = nullptr;
711  return state;
712  }
713 
714  /// Undo a previous pushUndelayed().
716  assert(CurPool == nullptr);
717  CurPool = state.SavedPool;
718  }
720 
721  /// A RAII object to temporarily push a declaration context.
722  class ContextRAII {
723  private:
724  Sema &S;
725  DeclContext *SavedContext;
726  ProcessingContextState SavedContextState;
727  QualType SavedCXXThisTypeOverride;
728 
729  public:
730  ContextRAII(Sema &S, DeclContext *ContextToPush, bool NewThisContext = true)
731  : S(S), SavedContext(S.CurContext),
732  SavedContextState(S.DelayedDiagnostics.pushUndelayed()),
733  SavedCXXThisTypeOverride(S.CXXThisTypeOverride)
734  {
735  assert(ContextToPush && "pushing null context");
736  S.CurContext = ContextToPush;
737  if (NewThisContext)
739  }
740 
741  void pop() {
742  if (!SavedContext) return;
743  S.CurContext = SavedContext;
744  S.DelayedDiagnostics.popUndelayed(SavedContextState);
745  S.CXXThisTypeOverride = SavedCXXThisTypeOverride;
746  SavedContext = nullptr;
747  }
748 
750  pop();
751  }
752  };
753 
754  /// RAII object to handle the state changes required to synthesize
755  /// a function body.
757  Sema &S;
758  Sema::ContextRAII SavedContext;
759  bool PushedCodeSynthesisContext = false;
760 
761  public:
763  : S(S), SavedContext(S, DC) {
764  S.PushFunctionScope();
766  Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
767  if (auto *FD = dyn_cast<FunctionDecl>(DC))
768  FD->setWillHaveBody(true);
769  else
770  assert(isa<ObjCMethodDecl>(DC));
771  }
772 
774  assert(!PushedCodeSynthesisContext);
775 
777  Ctx.Kind = Sema::CodeSynthesisContext::DefiningSynthesizedFunction;
778  Ctx.PointOfInstantiation = UseLoc;
779  Ctx.Entity = cast<Decl>(S.CurContext);
781 
782  PushedCodeSynthesisContext = true;
783  }
784 
786  if (PushedCodeSynthesisContext)
788  if (auto *FD = dyn_cast<FunctionDecl>(S.CurContext))
789  FD->setWillHaveBody(false);
792  }
793  };
794 
795  /// WeakUndeclaredIdentifiers - Identifiers contained in
796  /// \#pragma weak before declared. rare. may alias another
797  /// identifier, declared or undeclared
798  llvm::MapVector<IdentifierInfo *, WeakInfo> WeakUndeclaredIdentifiers;
799 
800  /// ExtnameUndeclaredIdentifiers - Identifiers contained in
801  /// \#pragma redefine_extname before declared. Used in Solaris system headers
802  /// to define functions that occur in multiple standards to call the version
803  /// in the currently selected standard.
804  llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*> ExtnameUndeclaredIdentifiers;
805 
806 
807  /// Load weak undeclared identifiers from the external source.
808  void LoadExternalWeakUndeclaredIdentifiers();
809 
810  /// WeakTopLevelDecl - Translation-unit scoped declarations generated by
811  /// \#pragma weak during processing of other Decls.
812  /// I couldn't figure out a clean way to generate these in-line, so
813  /// we store them here and handle separately -- which is a hack.
814  /// It would be best to refactor this.
816 
818 
819  /// Translation Unit Scope - useful to Objective-C actions that need
820  /// to lookup file scope declarations in the "ordinary" C decl namespace.
821  /// For example, user-defined classes, built-in "id" type, etc.
823 
824  /// The C++ "std" namespace, where the standard library resides.
826 
827  /// The C++ "std::bad_alloc" class, which is defined by the C++
828  /// standard library.
830 
831  /// The C++ "std::align_val_t" enum class, which is defined by the C++
832  /// standard library.
834 
835  /// The C++ "std::experimental" namespace, where the experimental parts
836  /// of the standard library resides.
838 
839  /// The C++ "std::initializer_list" template, which is defined in
840  /// <initializer_list>.
842 
843  /// The C++ "std::coroutine_traits" template, which is defined in
844  /// <coroutine_traits>
846 
847  /// The C++ "type_info" declaration, which is defined in <typeinfo>.
849 
850  /// The MSVC "_GUID" struct, which is defined in MSVC header files.
852 
853  /// Caches identifiers/selectors for NSFoundation APIs.
854  std::unique_ptr<NSAPI> NSAPIObj;
855 
856  /// The declaration of the Objective-C NSNumber class.
858 
859  /// The declaration of the Objective-C NSValue class.
861 
862  /// Pointer to NSNumber type (NSNumber *).
864 
865  /// Pointer to NSValue type (NSValue *).
867 
868  /// The Objective-C NSNumber methods used to create NSNumber literals.
869  ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods];
870 
871  /// The declaration of the Objective-C NSString class.
873 
874  /// Pointer to NSString type (NSString *).
876 
877  /// The declaration of the stringWithUTF8String: method.
879 
880  /// The declaration of the valueWithBytes:objCType: method.
882 
883  /// The declaration of the Objective-C NSArray class.
885 
886  /// The declaration of the arrayWithObjects:count: method.
888 
889  /// The declaration of the Objective-C NSDictionary class.
891 
892  /// The declaration of the dictionaryWithObjects:forKeys:count: method.
894 
895  /// id<NSCopying> type.
897 
898  /// will hold 'respondsToSelector:'
900 
901  /// A flag to remember whether the implicit forms of operator new and delete
902  /// have been declared.
904 
905  /// A flag to indicate that we're in a context that permits abstract
906  /// references to fields. This is really a
908 
909  /// Describes how the expressions currently being parsed are
910  /// evaluated at run-time, if at all.
912  /// The current expression and its subexpressions occur within an
913  /// unevaluated operand (C++11 [expr]p7), such as the subexpression of
914  /// \c sizeof, where the type of the expression may be significant but
915  /// no code will be generated to evaluate the value of the expression at
916  /// run time.
917  Unevaluated,
918 
919  /// The current expression occurs within a braced-init-list within
920  /// an unevaluated operand. This is mostly like a regular unevaluated
921  /// context, except that we still instantiate constexpr functions that are
922  /// referenced here so that we can perform narrowing checks correctly.
923  UnevaluatedList,
924 
925  /// The current expression occurs within a discarded statement.
926  /// This behaves largely similarly to an unevaluated operand in preventing
927  /// definitions from being required, but not in other ways.
928  DiscardedStatement,
929 
930  /// The current expression occurs within an unevaluated
931  /// operand that unconditionally permits abstract references to
932  /// fields, such as a SIZE operator in MS-style inline assembly.
933  UnevaluatedAbstract,
934 
935  /// The current context is "potentially evaluated" in C++11 terms,
936  /// but the expression is evaluated at compile-time (like the values of
937  /// cases in a switch statement).
938  ConstantEvaluated,
939 
940  /// The current expression is potentially evaluated at run time,
941  /// which means that code may be generated to evaluate the value of the
942  /// expression at run time.
943  PotentiallyEvaluated,
944 
945  /// The current expression is potentially evaluated, but any
946  /// declarations referenced inside that expression are only used if
947  /// in fact the current expression is used.
948  ///
949  /// This value is used when parsing default function arguments, for which
950  /// we would like to provide diagnostics (e.g., passing non-POD arguments
951  /// through varargs) but do not want to mark declarations as "referenced"
952  /// until the default argument is used.
953  PotentiallyEvaluatedIfUsed
954  };
955 
956  /// Data structure used to record current or nested
957  /// expression evaluation contexts.
959  /// The expression evaluation context.
961 
962  /// Whether the enclosing context needed a cleanup.
964 
965  /// Whether we are in a decltype expression.
967 
968  /// The number of active cleanup objects when we entered
969  /// this expression evaluation context.
971 
972  /// The number of typos encountered during this expression evaluation
973  /// context (i.e. the number of TypoExprs created).
974  unsigned NumTypos;
975 
976  llvm::SmallPtrSet<Expr*, 2> SavedMaybeODRUseExprs;
977 
978  /// The lambdas that are present within this context, if it
979  /// is indeed an unevaluated context.
981 
982  /// The declaration that provides context for lambda expressions
983  /// and block literals if the normal declaration context does not
984  /// suffice, e.g., in a default function argument.
986 
987  /// The context information used to mangle lambda expressions
988  /// and block literals within this context.
989  ///
990  /// This mangling information is allocated lazily, since most contexts
991  /// do not have lambda expressions or block literals.
992  std::unique_ptr<MangleNumberingContext> MangleNumbering;
993 
994  /// If we are processing a decltype type, a set of call expressions
995  /// for which we have deferred checking the completeness of the return type.
997 
998  /// If we are processing a decltype type, a set of temporary binding
999  /// expressions for which we have deferred checking the destructor.
1001 
1002  llvm::SmallPtrSet<const Expr *, 8> PossibleDerefs;
1003 
1004  /// \brief Describes whether we are in an expression constext which we have
1005  /// to handle differently.
1007  EK_Decltype, EK_TemplateArgument, EK_Other
1008  } ExprContext;
1009 
1011  unsigned NumCleanupObjects,
1012  CleanupInfo ParentCleanup,
1013  Decl *ManglingContextDecl,
1014  ExpressionKind ExprContext)
1015  : Context(Context), ParentCleanup(ParentCleanup),
1016  NumCleanupObjects(NumCleanupObjects), NumTypos(0),
1017  ManglingContextDecl(ManglingContextDecl), MangleNumbering(),
1018  ExprContext(ExprContext) {}
1019 
1020  /// Retrieve the mangling numbering context, used to consistently
1021  /// number constructs like lambdas for mangling.
1022  MangleNumberingContext &getMangleNumberingContext(ASTContext &Ctx);
1023 
1024  bool isUnevaluated() const {
1025  return Context == ExpressionEvaluationContext::Unevaluated ||
1026  Context == ExpressionEvaluationContext::UnevaluatedAbstract ||
1027  Context == ExpressionEvaluationContext::UnevaluatedList;
1028  }
1029  bool isConstantEvaluated() const {
1030  return Context == ExpressionEvaluationContext::ConstantEvaluated;
1031  }
1032  };
1033 
1034  /// A stack of expression evaluation contexts.
1036 
1037  /// Emit a warning for all pending noderef expressions that we recorded.
1038  void WarnOnPendingNoDerefs(ExpressionEvaluationContextRecord &Rec);
1039 
1040  /// Compute the mangling number context for a lambda expression or
1041  /// block literal.
1042  ///
1043  /// \param DC - The DeclContext containing the lambda expression or
1044  /// block literal.
1045  /// \param[out] ManglingContextDecl - Returns the ManglingContextDecl
1046  /// associated with the context, if relevant.
1047  MangleNumberingContext *getCurrentMangleNumberContext(
1048  const DeclContext *DC,
1049  Decl *&ManglingContextDecl);
1050 
1051 
1052  /// SpecialMemberOverloadResult - The overloading result for a special member
1053  /// function.
1054  ///
1055  /// This is basically a wrapper around PointerIntPair. The lowest bits of the
1056  /// integer are used to determine whether overload resolution succeeded.
1058  public:
1059  enum Kind {
1062  Success
1063  };
1064 
1065  private:
1066  llvm::PointerIntPair<CXXMethodDecl*, 2> Pair;
1067 
1068  public:
1071  : Pair(MD, MD->isDeleted() ? NoMemberOrDeleted : Success) {}
1072 
1073  CXXMethodDecl *getMethod() const { return Pair.getPointer(); }
1074  void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); }
1075 
1076  Kind getKind() const { return static_cast<Kind>(Pair.getInt()); }
1077  void setKind(Kind K) { Pair.setInt(K); }
1078  };
1079 
1081  : public llvm::FastFoldingSetNode,
1083  public:
1084  SpecialMemberOverloadResultEntry(const llvm::FoldingSetNodeID &ID)
1085  : FastFoldingSetNode(ID)
1086  {}
1087  };
1088 
1089  /// A cache of special member function overload resolution results
1090  /// for C++ records.
1091  llvm::FoldingSet<SpecialMemberOverloadResultEntry> SpecialMemberCache;
1092 
1093  /// A cache of the flags available in enumerations with the flag_bits
1094  /// attribute.
1095  mutable llvm::DenseMap<const EnumDecl*, llvm::APInt> FlagBitsCache;
1096 
1097  /// The kind of translation unit we are processing.
1098  ///
1099  /// When we're processing a complete translation unit, Sema will perform
1100  /// end-of-translation-unit semantic tasks (such as creating
1101  /// initializers for tentative definitions in C) once parsing has
1102  /// completed. Modules and precompiled headers perform different kinds of
1103  /// checks.
1105 
1106  llvm::BumpPtrAllocator BumpAlloc;
1107 
1108  /// The number of SFINAE diagnostics that have been trapped.
1110 
1111  typedef llvm::DenseMap<ParmVarDecl *, llvm::TinyPtrVector<ParmVarDecl *>>
1113 
1114  /// A mapping from parameters with unparsed default arguments to the
1115  /// set of instantiations of each parameter.
1116  ///
1117  /// This mapping is a temporary data structure used when parsing
1118  /// nested class templates or nested classes of class templates,
1119  /// where we might end up instantiating an inner class before the
1120  /// default arguments of its methods have been parsed.
1122 
1123  // Contains the locations of the beginning of unparsed default
1124  // argument locations.
1125  llvm::DenseMap<ParmVarDecl *, SourceLocation> UnparsedDefaultArgLocs;
1126 
1127  /// UndefinedInternals - all the used, undefined objects which require a
1128  /// definition in this translation unit.
1129  llvm::MapVector<NamedDecl *, SourceLocation> UndefinedButUsed;
1130 
1131  /// Determine if VD, which must be a variable or function, is an external
1132  /// symbol that nonetheless can't be referenced from outside this translation
1133  /// unit because its type has no linkage and it's not extern "C".
1134  bool isExternalWithNoLinkageType(ValueDecl *VD);
1135 
1136  /// Obtain a sorted list of functions that are undefined but ODR-used.
1137  void getUndefinedButUsed(
1138  SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined);
1139 
1140  /// Retrieves list of suspicious delete-expressions that will be checked at
1141  /// the end of translation unit.
1142  const llvm::MapVector<FieldDecl *, DeleteLocs> &
1143  getMismatchingDeleteExpressions() const;
1144 
1145  typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods;
1146  typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool;
1147 
1148  /// Method Pool - allows efficient lookup when typechecking messages to "id".
1149  /// We need to maintain a list, since selectors can have differing signatures
1150  /// across classes. In Cocoa, this happens to be extremely uncommon (only 1%
1151  /// of selectors are "overloaded").
1152  /// At the head of the list it is recorded whether there were 0, 1, or >= 2
1153  /// methods inside categories with a particular selector.
1154  GlobalMethodPool MethodPool;
1155 
1156  /// Method selectors used in a \@selector expression. Used for implementation
1157  /// of -Wselector.
1158  llvm::MapVector<Selector, SourceLocation> ReferencedSelectors;
1159 
1160  /// Kinds of C++ special members.
1168  CXXInvalid
1169  };
1170 
1171  typedef llvm::PointerIntPair<CXXRecordDecl *, 3, CXXSpecialMember>
1173 
1174  /// The C++ special members which we are currently in the process of
1175  /// declaring. If this process recursively triggers the declaration of the
1176  /// same special member, we should act as if it is not yet declared.
1177  llvm::SmallPtrSet<SpecialMemberDecl, 4> SpecialMembersBeingDeclared;
1178 
1179  /// The function definitions which were renamed as part of typo-correction
1180  /// to match their respective declarations. We want to keep track of them
1181  /// to ensure that we don't emit a "redefinition" error if we encounter a
1182  /// correctly named definition after the renamed definition.
1183  llvm::SmallPtrSet<const NamedDecl *, 4> TypoCorrectedFunctionDefinitions;
1184 
1185  /// Stack of types that correspond to the parameter entities that are
1186  /// currently being copy-initialized. Can be empty.
1188 
1189  void ReadMethodPool(Selector Sel);
1190  void updateOutOfDateSelector(Selector Sel);
1191 
1192  /// Private Helper predicate to check for 'self'.
1193  bool isSelfExpr(Expr *RExpr);
1194  bool isSelfExpr(Expr *RExpr, const ObjCMethodDecl *Method);
1195 
1196  /// Cause the active diagnostic on the DiagosticsEngine to be
1197  /// emitted. This is closely coupled to the SemaDiagnosticBuilder class and
1198  /// should not be used elsewhere.
1199  void EmitCurrentDiagnostic(unsigned DiagID);
1200 
1201  /// Records and restores the FP_CONTRACT state on entry/exit of compound
1202  /// statements.
1204  public:
1205  FPContractStateRAII(Sema &S) : S(S), OldFPFeaturesState(S.FPFeatures) {}
1206  ~FPContractStateRAII() { S.FPFeatures = OldFPFeaturesState; }
1207 
1208  private:
1209  Sema& S;
1210  FPOptions OldFPFeaturesState;
1211  };
1212 
1213  void addImplicitTypedef(StringRef Name, QualType T);
1214 
1215 public:
1216  Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
1218  CodeCompleteConsumer *CompletionConsumer = nullptr);
1219  ~Sema();
1220 
1221  /// Perform initialization that occurs after the parser has been
1222  /// initialized but before it parses anything.
1223  void Initialize();
1224 
1225  const LangOptions &getLangOpts() const { return LangOpts; }
1226  OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; }
1227  FPOptions &getFPOptions() { return FPFeatures; }
1228 
1229  DiagnosticsEngine &getDiagnostics() const { return Diags; }
1230  SourceManager &getSourceManager() const { return SourceMgr; }
1231  Preprocessor &getPreprocessor() const { return PP; }
1232  ASTContext &getASTContext() const { return Context; }
1233  ASTConsumer &getASTConsumer() const { return Consumer; }
1234  ASTMutationListener *getASTMutationListener() const;
1235  ExternalSemaSource* getExternalSource() const { return ExternalSource; }
1236 
1237  ///Registers an external source. If an external source already exists,
1238  /// creates a multiplex external source and appends to it.
1239  ///
1240  ///\param[in] E - A non-null external sema source.
1241  ///
1242  void addExternalSource(ExternalSemaSource *E);
1243 
1244  void PrintStats() const;
1245 
1246  /// Helper class that creates diagnostics with optional
1247  /// template instantiation stacks.
1248  ///
1249  /// This class provides a wrapper around the basic DiagnosticBuilder
1250  /// class that emits diagnostics. SemaDiagnosticBuilder is
1251  /// responsible for emitting the diagnostic (as DiagnosticBuilder
1252  /// does) and, if the diagnostic comes from inside a template
1253  /// instantiation, printing the template instantiation stack as
1254  /// well.
1256  Sema &SemaRef;
1257  unsigned DiagID;
1258 
1259  public:
1260  SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID)
1261  : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { }
1262 
1263  // This is a cunning lie. DiagnosticBuilder actually performs move
1264  // construction in its copy constructor (but due to varied uses, it's not
1265  // possible to conveniently express this as actual move construction). So
1266  // the default copy ctor here is fine, because the base class disables the
1267  // source anyway, so the user-defined ~SemaDiagnosticBuilder is a safe no-op
1268  // in that case anwyay.
1269  SemaDiagnosticBuilder(const SemaDiagnosticBuilder&) = default;
1270 
1272  // If we aren't active, there is nothing to do.
1273  if (!isActive()) return;
1274 
1275  // Otherwise, we need to emit the diagnostic. First flush the underlying
1276  // DiagnosticBuilder data, and clear the diagnostic builder itself so it
1277  // won't emit the diagnostic in its own destructor.
1278  //
1279  // This seems wasteful, in that as written the DiagnosticBuilder dtor will
1280  // do its own needless checks to see if the diagnostic needs to be
1281  // emitted. However, because we take care to ensure that the builder
1282  // objects never escape, a sufficiently smart compiler will be able to
1283  // eliminate that code.
1284  FlushCounts();
1285  Clear();
1286 
1287  // Dispatch to Sema to emit the diagnostic.
1288  SemaRef.EmitCurrentDiagnostic(DiagID);
1289  }
1290 
1291  /// Teach operator<< to produce an object of the correct type.
1292  template<typename T>
1294  const SemaDiagnosticBuilder &Diag, const T &Value) {
1295  const DiagnosticBuilder &BaseDiag = Diag;
1296  BaseDiag << Value;
1297  return Diag;
1298  }
1299  };
1300 
1301  /// Emit a diagnostic.
1303  DiagnosticBuilder DB = Diags.Report(Loc, DiagID);
1304  return SemaDiagnosticBuilder(DB, *this, DiagID);
1305  }
1306 
1307  /// Emit a partial diagnostic.
1309 
1310  /// Build a partial diagnostic.
1311  PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h
1312 
1313  bool findMacroSpelling(SourceLocation &loc, StringRef name);
1314 
1315  /// Get a string to suggest for zero-initialization of a type.
1316  std::string
1317  getFixItZeroInitializerForType(QualType T, SourceLocation Loc) const;
1318  std::string getFixItZeroLiteralForType(QualType T, SourceLocation Loc) const;
1319 
1320  /// Calls \c Lexer::getLocForEndOfToken()
1321  SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset = 0);
1322 
1323  /// Retrieve the module loader associated with the preprocessor.
1324  ModuleLoader &getModuleLoader() const;
1325 
1326  void emitAndClearUnusedLocalTypedefWarnings();
1327 
1328  void ActOnStartOfTranslationUnit();
1329  void ActOnEndOfTranslationUnit();
1330 
1331  void CheckDelegatingCtorCycles();
1332 
1333  Scope *getScopeForContext(DeclContext *Ctx);
1334 
1335  void PushFunctionScope();
1336  void PushBlockScope(Scope *BlockScope, BlockDecl *Block);
1337  sema::LambdaScopeInfo *PushLambdaScope();
1338 
1339  /// This is used to inform Sema what the current TemplateParameterDepth
1340  /// is during Parsing. Currently it is used to pass on the depth
1341  /// when parsing generic lambda 'auto' parameters.
1342  void RecordParsingTemplateParameterDepth(unsigned Depth);
1343 
1344  void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD,
1345  RecordDecl *RD,
1346  CapturedRegionKind K);
1347  void
1348  PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP = nullptr,
1349  const Decl *D = nullptr,
1350  const BlockExpr *blkExpr = nullptr);
1351 
1353  return FunctionScopes.empty() ? nullptr : FunctionScopes.back();
1354  }
1355 
1356  sema::FunctionScopeInfo *getEnclosingFunction() const;
1357 
1358  void setFunctionHasBranchIntoScope();
1359  void setFunctionHasBranchProtectedScope();
1360  void setFunctionHasIndirectGoto();
1361 
1362  void PushCompoundScope(bool IsStmtExpr);
1363  void PopCompoundScope();
1364 
1365  sema::CompoundScopeInfo &getCurCompoundScope() const;
1366 
1367  bool hasAnyUnrecoverableErrorsInThisFunction() const;
1368 
1369  /// Retrieve the current block, if any.
1370  sema::BlockScopeInfo *getCurBlock();
1371 
1372  /// Retrieve the current lambda scope info, if any.
1373  /// \param IgnoreNonLambdaCapturingScope true if should find the top-most
1374  /// lambda scope info ignoring all inner capturing scopes that are not
1375  /// lambda scopes.
1377  getCurLambda(bool IgnoreNonLambdaCapturingScope = false);
1378 
1379  /// Retrieve the current generic lambda info, if any.
1380  sema::LambdaScopeInfo *getCurGenericLambda();
1381 
1382  /// Retrieve the current captured region, if any.
1383  sema::CapturedRegionScopeInfo *getCurCapturedRegion();
1384 
1385  /// WeakTopLevelDeclDecls - access to \#pragma weak-generated Decls
1386  SmallVectorImpl<Decl *> &WeakTopLevelDecls() { return WeakTopLevelDecl; }
1387 
1388  void ActOnComment(SourceRange Comment);
1389 
1390  //===--------------------------------------------------------------------===//
1391  // Type Analysis / Processing: SemaType.cpp.
1392  //
1393 
1394  QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs,
1395  const DeclSpec *DS = nullptr);
1396  QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVRA,
1397  const DeclSpec *DS = nullptr);
1398  QualType BuildPointerType(QualType T,
1399  SourceLocation Loc, DeclarationName Entity);
1400  QualType BuildReferenceType(QualType T, bool LValueRef,
1401  SourceLocation Loc, DeclarationName Entity);
1402  QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
1403  Expr *ArraySize, unsigned Quals,
1404  SourceRange Brackets, DeclarationName Entity);
1405  QualType BuildVectorType(QualType T, Expr *VecSize, SourceLocation AttrLoc);
1406  QualType BuildExtVectorType(QualType T, Expr *ArraySize,
1407  SourceLocation AttrLoc);
1408  QualType BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace,
1409  SourceLocation AttrLoc);
1410 
1411  bool CheckFunctionReturnType(QualType T, SourceLocation Loc);
1412 
1413  /// Build a function type.
1414  ///
1415  /// This routine checks the function type according to C++ rules and
1416  /// under the assumption that the result type and parameter types have
1417  /// just been instantiated from a template. It therefore duplicates
1418  /// some of the behavior of GetTypeForDeclarator, but in a much
1419  /// simpler form that is only suitable for this narrow use case.
1420  ///
1421  /// \param T The return type of the function.
1422  ///
1423  /// \param ParamTypes The parameter types of the function. This array
1424  /// will be modified to account for adjustments to the types of the
1425  /// function parameters.
1426  ///
1427  /// \param Loc The location of the entity whose type involves this
1428  /// function type or, if there is no such entity, the location of the
1429  /// type that will have function type.
1430  ///
1431  /// \param Entity The name of the entity that involves the function
1432  /// type, if known.
1433  ///
1434  /// \param EPI Extra information about the function type. Usually this will
1435  /// be taken from an existing function with the same prototype.
1436  ///
1437  /// \returns A suitable function type, if there are no errors. The
1438  /// unqualified type will always be a FunctionProtoType.
1439  /// Otherwise, returns a NULL type.
1440  QualType BuildFunctionType(QualType T,
1441  MutableArrayRef<QualType> ParamTypes,
1442  SourceLocation Loc, DeclarationName Entity,
1443  const FunctionProtoType::ExtProtoInfo &EPI);
1444 
1445  QualType BuildMemberPointerType(QualType T, QualType Class,
1446  SourceLocation Loc,
1447  DeclarationName Entity);
1448  QualType BuildBlockPointerType(QualType T,
1449  SourceLocation Loc, DeclarationName Entity);
1450  QualType BuildParenType(QualType T);
1451  QualType BuildAtomicType(QualType T, SourceLocation Loc);
1452  QualType BuildReadPipeType(QualType T,
1453  SourceLocation Loc);
1454  QualType BuildWritePipeType(QualType T,
1455  SourceLocation Loc);
1456 
1457  TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S);
1458  TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy);
1459 
1460  /// Package the given type and TSI into a ParsedType.
1461  ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo);
1462  DeclarationNameInfo GetNameForDeclarator(Declarator &D);
1463  DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name);
1464  static QualType GetTypeFromParser(ParsedType Ty,
1465  TypeSourceInfo **TInfo = nullptr);
1466  CanThrowResult canThrow(const Expr *E);
1467  const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc,
1468  const FunctionProtoType *FPT);
1469  void UpdateExceptionSpec(FunctionDecl *FD,
1471  bool CheckSpecifiedExceptionType(QualType &T, SourceRange Range);
1472  bool CheckDistantExceptionSpec(QualType T);
1473  bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New);
1474  bool CheckEquivalentExceptionSpec(
1475  const FunctionProtoType *Old, SourceLocation OldLoc,
1476  const FunctionProtoType *New, SourceLocation NewLoc);
1477  bool CheckEquivalentExceptionSpec(
1478  const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
1479  const FunctionProtoType *Old, SourceLocation OldLoc,
1480  const FunctionProtoType *New, SourceLocation NewLoc);
1481  bool handlerCanCatch(QualType HandlerType, QualType ExceptionType);
1482  bool CheckExceptionSpecSubset(const PartialDiagnostic &DiagID,
1483  const PartialDiagnostic &NestedDiagID,
1484  const PartialDiagnostic &NoteID,
1485  const FunctionProtoType *Superset,
1486  SourceLocation SuperLoc,
1487  const FunctionProtoType *Subset,
1488  SourceLocation SubLoc);
1489  bool CheckParamExceptionSpec(const PartialDiagnostic &NestedDiagID,
1490  const PartialDiagnostic &NoteID,
1491  const FunctionProtoType *Target,
1492  SourceLocation TargetLoc,
1493  const FunctionProtoType *Source,
1494  SourceLocation SourceLoc);
1495 
1496  TypeResult ActOnTypeName(Scope *S, Declarator &D);
1497 
1498  /// The parser has parsed the context-sensitive type 'instancetype'
1499  /// in an Objective-C message declaration. Return the appropriate type.
1500  ParsedType ActOnObjCInstanceType(SourceLocation Loc);
1501 
1502  /// Abstract class used to diagnose incomplete types.
1503  struct TypeDiagnoser {
1505 
1506  virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0;
1507  virtual ~TypeDiagnoser() {}
1508  };
1509 
1510  static int getPrintable(int I) { return I; }
1511  static unsigned getPrintable(unsigned I) { return I; }
1512  static bool getPrintable(bool B) { return B; }
1513  static const char * getPrintable(const char *S) { return S; }
1514  static StringRef getPrintable(StringRef S) { return S; }
1515  static const std::string &getPrintable(const std::string &S) { return S; }
1516  static const IdentifierInfo *getPrintable(const IdentifierInfo *II) {
1517  return II;
1518  }
1520  static QualType getPrintable(QualType T) { return T; }
1521  static SourceRange getPrintable(SourceRange R) { return R; }
1522  static SourceRange getPrintable(SourceLocation L) { return L; }
1523  static SourceRange getPrintable(const Expr *E) { return E->getSourceRange(); }
1524  static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();}
1525 
1526  template <typename... Ts> class BoundTypeDiagnoser : public TypeDiagnoser {
1527  unsigned DiagID;
1528  std::tuple<const Ts &...> Args;
1529 
1530  template <std::size_t... Is>
1531  void emit(const SemaDiagnosticBuilder &DB,
1532  llvm::index_sequence<Is...>) const {
1533  // Apply all tuple elements to the builder in order.
1534  bool Dummy[] = {false, (DB << getPrintable(std::get<Is>(Args)))...};
1535  (void)Dummy;
1536  }
1537 
1538  public:
1539  BoundTypeDiagnoser(unsigned DiagID, const Ts &...Args)
1540  : TypeDiagnoser(), DiagID(DiagID), Args(Args...) {
1541  assert(DiagID != 0 && "no diagnostic for type diagnoser");
1542  }
1543 
1544  void diagnose(Sema &S, SourceLocation Loc, QualType T) override {
1545  const SemaDiagnosticBuilder &DB = S.Diag(Loc, DiagID);
1546  emit(DB, llvm::index_sequence_for<Ts...>());
1547  DB << T;
1548  }
1549  };
1550 
1551 private:
1552  /// Methods for marking which expressions involve dereferencing a pointer
1553  /// marked with the 'noderef' attribute. Expressions are checked bottom up as
1554  /// they are parsed, meaning that a noderef pointer may not be accessed. For
1555  /// example, in `&*p` where `p` is a noderef pointer, we will first parse the
1556  /// `*p`, but need to check that `address of` is called on it. This requires
1557  /// keeping a container of all pending expressions and checking if the address
1558  /// of them are eventually taken.
1559  void CheckSubscriptAccessOfNoDeref(const ArraySubscriptExpr *E);
1560  void CheckAddressOfNoDeref(const Expr *E);
1561  void CheckMemberAccessOfNoDeref(const MemberExpr *E);
1562 
1563  bool RequireCompleteTypeImpl(SourceLocation Loc, QualType T,
1564  TypeDiagnoser *Diagnoser);
1565 
1566  struct ModuleScope {
1567  clang::Module *Module = nullptr;
1568  bool ModuleInterface = false;
1569  VisibleModuleSet OuterVisibleModules;
1570  };
1571  /// The modules we're currently parsing.
1573 
1574  /// Get the module whose scope we are currently within.
1575  Module *getCurrentModule() const {
1576  return ModuleScopes.empty() ? nullptr : ModuleScopes.back().Module;
1577  }
1578 
1579  VisibleModuleSet VisibleModules;
1580 
1581 public:
1582  /// Get the module owning an entity.
1583  Module *getOwningModule(Decl *Entity) { return Entity->getOwningModule(); }
1584 
1585  /// Make a merged definition of an existing hidden definition \p ND
1586  /// visible at the specified location.
1587  void makeMergedDefinitionVisible(NamedDecl *ND);
1588 
1589  bool isModuleVisible(const Module *M, bool ModulePrivate = false);
1590 
1591  /// Determine whether a declaration is visible to name lookup.
1592  bool isVisible(const NamedDecl *D) {
1593  return !D->isHidden() || isVisibleSlow(D);
1594  }
1595 
1596  /// Determine whether any declaration of an entity is visible.
1597  bool
1599  llvm::SmallVectorImpl<Module *> *Modules = nullptr) {
1600  return isVisible(D) || hasVisibleDeclarationSlow(D, Modules);
1601  }
1602  bool hasVisibleDeclarationSlow(const NamedDecl *D,
1604 
1605  bool hasVisibleMergedDefinition(NamedDecl *Def);
1606  bool hasMergedDefinitionInCurrentModule(NamedDecl *Def);
1607 
1608  /// Determine if \p D and \p Suggested have a structurally compatible
1609  /// layout as described in C11 6.2.7/1.
1610  bool hasStructuralCompatLayout(Decl *D, Decl *Suggested);
1611 
1612  /// Determine if \p D has a visible definition. If not, suggest a declaration
1613  /// that should be made visible to expose the definition.
1614  bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested,
1615  bool OnlyNeedComplete = false);
1617  NamedDecl *Hidden;
1618  return hasVisibleDefinition(const_cast<NamedDecl*>(D), &Hidden);
1619  }
1620 
1621  /// Determine if the template parameter \p D has a visible default argument.
1622  bool
1624  llvm::SmallVectorImpl<Module *> *Modules = nullptr);
1625 
1626  /// Determine if there is a visible declaration of \p D that is an explicit
1627  /// specialization declaration for a specialization of a template. (For a
1628  /// member specialization, use hasVisibleMemberSpecialization.)
1629  bool hasVisibleExplicitSpecialization(
1630  const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr);
1631 
1632  /// Determine if there is a visible declaration of \p D that is a member
1633  /// specialization declaration (as opposed to an instantiated declaration).
1634  bool hasVisibleMemberSpecialization(
1635  const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr);
1636 
1637  /// Determine if \p A and \p B are equivalent internal linkage declarations
1638  /// from different modules, and thus an ambiguity error can be downgraded to
1639  /// an extension warning.
1640  bool isEquivalentInternalLinkageDeclaration(const NamedDecl *A,
1641  const NamedDecl *B);
1642  void diagnoseEquivalentInternalLinkageDeclarations(
1643  SourceLocation Loc, const NamedDecl *D,
1645 
1646  bool isUsualDeallocationFunction(const CXXMethodDecl *FD);
1647 
1649  return !RequireCompleteTypeImpl(Loc, T, nullptr);
1650  }
1651  bool RequireCompleteType(SourceLocation Loc, QualType T,
1652  TypeDiagnoser &Diagnoser);
1653  bool RequireCompleteType(SourceLocation Loc, QualType T,
1654  unsigned DiagID);
1655 
1656  template <typename... Ts>
1657  bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID,
1658  const Ts &...Args) {
1659  BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...);
1660  return RequireCompleteType(Loc, T, Diagnoser);
1661  }
1662 
1663  void completeExprArrayBound(Expr *E);
1664  bool RequireCompleteExprType(Expr *E, TypeDiagnoser &Diagnoser);
1665  bool RequireCompleteExprType(Expr *E, unsigned DiagID);
1666 
1667  template <typename... Ts>
1668  bool RequireCompleteExprType(Expr *E, unsigned DiagID, const Ts &...Args) {
1669  BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...);
1670  return RequireCompleteExprType(E, Diagnoser);
1671  }
1672 
1673  bool RequireLiteralType(SourceLocation Loc, QualType T,
1674  TypeDiagnoser &Diagnoser);
1675  bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID);
1676 
1677  template <typename... Ts>
1678  bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID,
1679  const Ts &...Args) {
1680  BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...);
1681  return RequireLiteralType(Loc, T, Diagnoser);
1682  }
1683 
1684  QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
1685  const CXXScopeSpec &SS, QualType T,
1686  TagDecl *OwnedTagDecl = nullptr);
1687 
1688  QualType BuildTypeofExprType(Expr *E, SourceLocation Loc);
1689  /// If AsUnevaluated is false, E is treated as though it were an evaluated
1690  /// context, such as when building a type for decltype(auto).
1691  QualType BuildDecltypeType(Expr *E, SourceLocation Loc,
1692  bool AsUnevaluated = true);
1693  QualType BuildUnaryTransformType(QualType BaseType,
1695  SourceLocation Loc);
1696 
1697  //===--------------------------------------------------------------------===//
1698  // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
1699  //
1700 
1701  struct SkipBodyInfo {
1703  : ShouldSkip(false), CheckSameAsPrevious(false), Previous(nullptr),
1704  New(nullptr) {}
1709  };
1710 
1711  DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = nullptr);
1712 
1713  void DiagnoseUseOfUnimplementedSelectors();
1714 
1715  bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
1716 
1718  Scope *S, CXXScopeSpec *SS = nullptr,
1719  bool isClassName = false, bool HasTrailingDot = false,
1720  ParsedType ObjectType = nullptr,
1721  bool IsCtorOrDtorName = false,
1722  bool WantNontrivialTypeSourceInfo = false,
1723  bool IsClassTemplateDeductionContext = true,
1724  IdentifierInfo **CorrectedII = nullptr);
1725  TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S);
1726  bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S);
1727  void DiagnoseUnknownTypeName(IdentifierInfo *&II,
1728  SourceLocation IILoc,
1729  Scope *S,
1730  CXXScopeSpec *SS,
1731  ParsedType &SuggestedType,
1732  bool IsTemplateName = false);
1733 
1734  /// Attempt to behave like MSVC in situations where lookup of an unqualified
1735  /// type name has failed in a dependent context. In these situations, we
1736  /// automatically form a DependentTypeName that will retry lookup in a related
1737  /// scope during instantiation.
1738  ParsedType ActOnMSVCUnknownTypeName(const IdentifierInfo &II,
1739  SourceLocation NameLoc,
1740  bool IsTemplateTypeArg);
1741 
1742  /// Describes the result of the name lookup and resolution performed
1743  /// by \c ClassifyName().
1753  NC_FunctionTemplate
1754  };
1755 
1758  ExprResult Expr;
1759  TemplateName Template;
1760  ParsedType Type;
1761 
1762  explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {}
1763 
1764  public:
1765  NameClassification(ExprResult Expr) : Kind(NC_Expression), Expr(Expr) {}
1766 
1767  NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {}
1768 
1769  NameClassification(const IdentifierInfo *Keyword) : Kind(NC_Keyword) {}
1770 
1772  return NameClassification(NC_Error);
1773  }
1774 
1776  return NameClassification(NC_Unknown);
1777  }
1778 
1780  return NameClassification(NC_NestedNameSpecifier);
1781  }
1782 
1784  NameClassification Result(NC_TypeTemplate);
1785  Result.Template = Name;
1786  return Result;
1787  }
1788 
1790  NameClassification Result(NC_VarTemplate);
1791  Result.Template = Name;
1792  return Result;
1793  }
1794 
1796  NameClassification Result(NC_FunctionTemplate);
1797  Result.Template = Name;
1798  return Result;
1799  }
1800 
1802 
1804  assert(Kind == NC_Type);
1805  return Type;
1806  }
1807 
1809  assert(Kind == NC_Expression);
1810  return Expr;
1811  }
1812 
1814  assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate ||
1815  Kind == NC_VarTemplate);
1816  return Template;
1817  }
1818 
1820  switch (Kind) {
1821  case NC_TypeTemplate:
1822  return TNK_Type_template;
1823  case NC_FunctionTemplate:
1824  return TNK_Function_template;
1825  case NC_VarTemplate:
1826  return TNK_Var_template;
1827  default:
1828  llvm_unreachable("unsupported name classification.");
1829  }
1830  }
1831  };
1832 
1833  /// Perform name lookup on the given name, classifying it based on
1834  /// the results of name lookup and the following token.
1835  ///
1836  /// This routine is used by the parser to resolve identifiers and help direct
1837  /// parsing. When the identifier cannot be found, this routine will attempt
1838  /// to correct the typo and classify based on the resulting name.
1839  ///
1840  /// \param S The scope in which we're performing name lookup.
1841  ///
1842  /// \param SS The nested-name-specifier that precedes the name.
1843  ///
1844  /// \param Name The identifier. If typo correction finds an alternative name,
1845  /// this pointer parameter will be updated accordingly.
1846  ///
1847  /// \param NameLoc The location of the identifier.
1848  ///
1849  /// \param NextToken The token following the identifier. Used to help
1850  /// disambiguate the name.
1851  ///
1852  /// \param IsAddressOfOperand True if this name is the operand of a unary
1853  /// address of ('&') expression, assuming it is classified as an
1854  /// expression.
1855  ///
1856  /// \param CCC The correction callback, if typo correction is desired.
1858  ClassifyName(Scope *S, CXXScopeSpec &SS, IdentifierInfo *&Name,
1859  SourceLocation NameLoc, const Token &NextToken,
1860  bool IsAddressOfOperand,
1861  std::unique_ptr<CorrectionCandidateCallback> CCC = nullptr);
1862 
1863  /// Describes the detailed kind of a template name. Used in diagnostics.
1865  ClassTemplate,
1866  FunctionTemplate,
1867  VarTemplate,
1868  AliasTemplate,
1869  TemplateTemplateParam,
1870  DependentTemplate
1871  };
1873  getTemplateNameKindForDiagnostics(TemplateName Name);
1874 
1875  /// Determine whether it's plausible that E was intended to be a
1876  /// template-name.
1877  bool mightBeIntendedToBeTemplateName(ExprResult E, bool &Dependent) {
1878  if (!getLangOpts().CPlusPlus || E.isInvalid())
1879  return false;
1880  Dependent = false;
1881  if (auto *DRE = dyn_cast<DeclRefExpr>(E.get()))
1882  return !DRE->hasExplicitTemplateArgs();
1883  if (auto *ME = dyn_cast<MemberExpr>(E.get()))
1884  return !ME->hasExplicitTemplateArgs();
1885  Dependent = true;
1886  if (auto *DSDRE = dyn_cast<DependentScopeDeclRefExpr>(E.get()))
1887  return !DSDRE->hasExplicitTemplateArgs();
1888  if (auto *DSME = dyn_cast<CXXDependentScopeMemberExpr>(E.get()))
1889  return !DSME->hasExplicitTemplateArgs();
1890  // Any additional cases recognized here should also be handled by
1891  // diagnoseExprIntendedAsTemplateName.
1892  return false;
1893  }
1894  void diagnoseExprIntendedAsTemplateName(Scope *S, ExprResult TemplateName,
1897 
1898  Decl *ActOnDeclarator(Scope *S, Declarator &D);
1899 
1900  NamedDecl *HandleDeclarator(Scope *S, Declarator &D,
1901  MultiTemplateParamsArg TemplateParameterLists);
1902  void RegisterLocallyScopedExternCDecl(NamedDecl *ND, Scope *S);
1903  bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info);
1904  bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC,
1905  DeclarationName Name, SourceLocation Loc,
1906  bool IsTemplateId);
1907  void
1908  diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals,
1909  SourceLocation FallbackLoc,
1910  SourceLocation ConstQualLoc = SourceLocation(),
1911  SourceLocation VolatileQualLoc = SourceLocation(),
1912  SourceLocation RestrictQualLoc = SourceLocation(),
1913  SourceLocation AtomicQualLoc = SourceLocation(),
1914  SourceLocation UnalignedQualLoc = SourceLocation());
1915 
1916  static bool adjustContextForLocalExternDecl(DeclContext *&DC);
1917  void DiagnoseFunctionSpecifiers(const DeclSpec &DS);
1918  NamedDecl *getShadowedDeclaration(const TypedefNameDecl *D,
1919  const LookupResult &R);
1920  NamedDecl *getShadowedDeclaration(const VarDecl *D, const LookupResult &R);
1921  void CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl,
1922  const LookupResult &R);
1923  void CheckShadow(Scope *S, VarDecl *D);
1924 
1925  /// Warn if 'E', which is an expression that is about to be modified, refers
1926  /// to a shadowing declaration.
1927  void CheckShadowingDeclModification(Expr *E, SourceLocation Loc);
1928 
1929  void DiagnoseShadowingLambdaDecls(const sema::LambdaScopeInfo *LSI);
1930 
1931 private:
1932  /// Map of current shadowing declarations to shadowed declarations. Warn if
1933  /// it looks like the user is trying to modify the shadowing declaration.
1934  llvm::DenseMap<const NamedDecl *, const NamedDecl *> ShadowingDecls;
1935 
1936 public:
1937  void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange);
1938  void handleTagNumbering(const TagDecl *Tag, Scope *TagScope);
1939  void setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec,
1940  TypedefNameDecl *NewTD);
1941  void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D);
1942  NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
1943  TypeSourceInfo *TInfo,
1945  NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D,
1946  LookupResult &Previous, bool &Redeclaration);
1947  NamedDecl *ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
1948  TypeSourceInfo *TInfo,
1949  LookupResult &Previous,
1950  MultiTemplateParamsArg TemplateParamLists,
1951  bool &AddToScope,
1952  ArrayRef<BindingDecl *> Bindings = None);
1953  NamedDecl *
1954  ActOnDecompositionDeclarator(Scope *S, Declarator &D,
1955  MultiTemplateParamsArg TemplateParamLists);
1956  // Returns true if the variable declaration is a redeclaration
1957  bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous);
1958  void CheckVariableDeclarationType(VarDecl *NewVD);
1959  bool DeduceVariableDeclarationType(VarDecl *VDecl, bool DirectInit,
1960  Expr *Init);
1961  void CheckCompleteVariableDeclaration(VarDecl *VD);
1962  void CheckCompleteDecompositionDeclaration(DecompositionDecl *DD);
1963  void MaybeSuggestAddingStaticToDecl(const FunctionDecl *D);
1964 
1965  NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
1966  TypeSourceInfo *TInfo,
1967  LookupResult &Previous,
1968  MultiTemplateParamsArg TemplateParamLists,
1969  bool &AddToScope);
1970  bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD);
1971 
1972  bool CheckConstexprFunctionDecl(const FunctionDecl *FD);
1973  bool CheckConstexprFunctionBody(const FunctionDecl *FD, Stmt *Body);
1974 
1975  void DiagnoseHiddenVirtualMethods(CXXMethodDecl *MD);
1976  void FindHiddenVirtualMethods(CXXMethodDecl *MD,
1977  SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods);
1978  void NoteHiddenVirtualMethods(CXXMethodDecl *MD,
1979  SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods);
1980  // Returns true if the function declaration is a redeclaration
1981  bool CheckFunctionDeclaration(Scope *S,
1982  FunctionDecl *NewFD, LookupResult &Previous,
1983  bool IsMemberSpecialization);
1984  bool shouldLinkDependentDeclWithPrevious(Decl *D, Decl *OldDecl);
1985  bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD,
1986  QualType NewT, QualType OldT);
1987  void CheckMain(FunctionDecl *FD, const DeclSpec &D);
1988  void CheckMSVCRTEntryPoint(FunctionDecl *FD);
1989  Attr *getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, bool IsDefinition);
1990  Decl *ActOnParamDeclarator(Scope *S, Declarator &D);
1991  ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC,
1992  SourceLocation Loc,
1993  QualType T);
1994  ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc,
1995  SourceLocation NameLoc, IdentifierInfo *Name,
1996  QualType T, TypeSourceInfo *TSInfo,
1997  StorageClass SC);
1998  void ActOnParamDefaultArgument(Decl *param,
1999  SourceLocation EqualLoc,
2000  Expr *defarg);
2001  void ActOnParamUnparsedDefaultArgument(Decl *param,
2002  SourceLocation EqualLoc,
2003  SourceLocation ArgLoc);
2004  void ActOnParamDefaultArgumentError(Decl *param, SourceLocation EqualLoc);
2005  bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg,
2006  SourceLocation EqualLoc);
2007 
2008  void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit);
2009  void ActOnUninitializedDecl(Decl *dcl);
2010  void ActOnInitializerError(Decl *Dcl);
2011 
2012  void ActOnPureSpecifier(Decl *D, SourceLocation PureSpecLoc);
2013  void ActOnCXXForRangeDecl(Decl *D);
2014  StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc,
2015  IdentifierInfo *Ident,
2016  ParsedAttributes &Attrs,
2017  SourceLocation AttrEnd);
2018  void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc);
2019  void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc);
2020  void CheckStaticLocalForDllExport(VarDecl *VD);
2021  void FinalizeDeclaration(Decl *D);
2022  DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS,
2023  ArrayRef<Decl *> Group);
2024  DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef<Decl *> Group);
2025 
2026  /// Should be called on all declarations that might have attached
2027  /// documentation comments.
2028  void ActOnDocumentableDecl(Decl *D);
2029  void ActOnDocumentableDecls(ArrayRef<Decl *> Group);
2030 
2031  void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
2032  SourceLocation LocAfterDecls);
2033  void CheckForFunctionRedefinition(
2034  FunctionDecl *FD, const FunctionDecl *EffectiveDefinition = nullptr,
2035  SkipBodyInfo *SkipBody = nullptr);
2036  Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D,
2037  MultiTemplateParamsArg TemplateParamLists,
2038  SkipBodyInfo *SkipBody = nullptr);
2039  Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D,
2040  SkipBodyInfo *SkipBody = nullptr);
2041  void ActOnStartOfObjCMethodDef(Scope *S, Decl *D);
2043  return D && isa<ObjCMethodDecl>(D);
2044  }
2045 
2046  /// Determine whether we can delay parsing the body of a function or
2047  /// function template until it is used, assuming we don't care about emitting
2048  /// code for that function.
2049  ///
2050  /// This will be \c false if we may need the body of the function in the
2051  /// middle of parsing an expression (where it's impractical to switch to
2052  /// parsing a different function), for instance, if it's constexpr in C++11
2053  /// or has an 'auto' return type in C++14. These cases are essentially bugs.
2054  bool canDelayFunctionBody(const Declarator &D);
2055 
2056  /// Determine whether we can skip parsing the body of a function
2057  /// definition, assuming we don't care about analyzing its body or emitting
2058  /// code for that function.
2059  ///
2060  /// This will be \c false only if we may need the body of the function in
2061  /// order to parse the rest of the program (for instance, if it is
2062  /// \c constexpr in C++11 or has an 'auto' return type in C++14).
2063  bool canSkipFunctionBody(Decl *D);
2064 
2065  void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope);
2066  Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body);
2067  Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation);
2068  Decl *ActOnSkippedFunctionBody(Decl *Decl);
2069  void ActOnFinishInlineFunctionDef(FunctionDecl *D);
2070 
2071  /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an
2072  /// attribute for which parsing is delayed.
2073  void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs);
2074 
2075  /// Diagnose any unused parameters in the given sequence of
2076  /// ParmVarDecl pointers.
2077  void DiagnoseUnusedParameters(ArrayRef<ParmVarDecl *> Parameters);
2078 
2079  /// Diagnose whether the size of parameters or return value of a
2080  /// function or obj-c method definition is pass-by-value and larger than a
2081  /// specified threshold.
2082  void
2083  DiagnoseSizeOfParametersAndReturnValue(ArrayRef<ParmVarDecl *> Parameters,
2084  QualType ReturnTy, NamedDecl *D);
2085 
2086  void DiagnoseInvalidJumps(Stmt *Body);
2087  Decl *ActOnFileScopeAsmDecl(Expr *expr,
2088  SourceLocation AsmLoc,
2089  SourceLocation RParenLoc);
2090 
2091  /// Handle a C++11 empty-declaration and attribute-declaration.
2092  Decl *ActOnEmptyDeclaration(Scope *S, const ParsedAttributesView &AttrList,
2093  SourceLocation SemiLoc);
2094 
2095  enum class ModuleDeclKind {
2096  Interface, ///< 'export module X;'
2097  Implementation, ///< 'module X;'
2098  Partition, ///< 'module partition X;'
2099  };
2100 
2101  /// The parser has processed a module-declaration that begins the definition
2102  /// of a module interface or implementation.
2103  DeclGroupPtrTy ActOnModuleDecl(SourceLocation StartLoc,
2104  SourceLocation ModuleLoc, ModuleDeclKind MDK,
2105  ModuleIdPath Path);
2106 
2107  /// The parser has processed a module import declaration.
2108  ///
2109  /// \param AtLoc The location of the '@' symbol, if any.
2110  ///
2111  /// \param ImportLoc The location of the 'import' keyword.
2112  ///
2113  /// \param Path The module access path.
2114  DeclResult ActOnModuleImport(SourceLocation AtLoc, SourceLocation ImportLoc,
2115  ModuleIdPath Path);
2116 
2117  /// The parser has processed a module import translated from a
2118  /// #include or similar preprocessing directive.
2119  void ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod);
2120  void BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod);
2121 
2122  /// The parsed has entered a submodule.
2123  void ActOnModuleBegin(SourceLocation DirectiveLoc, Module *Mod);
2124  /// The parser has left a submodule.
2125  void ActOnModuleEnd(SourceLocation DirectiveLoc, Module *Mod);
2126 
2127  /// Create an implicit import of the given module at the given
2128  /// source location, for error recovery, if possible.
2129  ///
2130  /// This routine is typically used when an entity found by name lookup
2131  /// is actually hidden within a module that we know about but the user
2132  /// has forgotten to import.
2133  void createImplicitModuleImportForErrorRecovery(SourceLocation Loc,
2134  Module *Mod);
2135 
2136  /// Kinds of missing import. Note, the values of these enumerators correspond
2137  /// to %select values in diagnostics.
2138  enum class MissingImportKind {
2139  Declaration,
2140  Definition,
2141  DefaultArgument,
2142  ExplicitSpecialization,
2143  PartialSpecialization
2144  };
2145 
2146  /// Diagnose that the specified declaration needs to be visible but
2147  /// isn't, and suggest a module import that would resolve the problem.
2148  void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl,
2149  MissingImportKind MIK, bool Recover = true);
2150  void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl,
2151  SourceLocation DeclLoc, ArrayRef<Module *> Modules,
2152  MissingImportKind MIK, bool Recover);
2153 
2154  Decl *ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc,
2155  SourceLocation LBraceLoc);
2156  Decl *ActOnFinishExportDecl(Scope *S, Decl *ExportDecl,
2157  SourceLocation RBraceLoc);
2158 
2159  /// We've found a use of a templated declaration that would trigger an
2160  /// implicit instantiation. Check that any relevant explicit specializations
2161  /// and partial specializations are visible, and diagnose if not.
2162  void checkSpecializationVisibility(SourceLocation Loc, NamedDecl *Spec);
2163 
2164  /// We've found a use of a template specialization that would select a
2165  /// partial specialization. Check that the partial specialization is visible,
2166  /// and diagnose if not.
2167  void checkPartialSpecializationVisibility(SourceLocation Loc,
2168  NamedDecl *Spec);
2169 
2170  /// Retrieve a suitable printing policy for diagnostics.
2172  return getPrintingPolicy(Context, PP);
2173  }
2174 
2175  /// Retrieve a suitable printing policy for diagnostics.
2176  static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx,
2177  const Preprocessor &PP);
2178 
2179  /// Scope actions.
2180  void ActOnPopScope(SourceLocation Loc, Scope *S);
2181  void ActOnTranslationUnitScope(Scope *S);
2182 
2183  Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS,
2184  RecordDecl *&AnonRecord);
2185  Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS,
2186  MultiTemplateParamsArg TemplateParams,
2187  bool IsExplicitInstantiation,
2188  RecordDecl *&AnonRecord);
2189 
2190  Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
2191  AccessSpecifier AS,
2192  RecordDecl *Record,
2193  const PrintingPolicy &Policy);
2194 
2195  Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS,
2196  RecordDecl *Record);
2197 
2198  /// Common ways to introduce type names without a tag for use in diagnostics.
2199  /// Keep in sync with err_tag_reference_non_tag.
2200  enum NonTagKind {
2210  };
2211 
2212  /// Given a non-tag type declaration, returns an enum useful for indicating
2213  /// what kind of non-tag type this is.
2214  NonTagKind getNonTagTypeDeclKind(const Decl *D, TagTypeKind TTK);
2215 
2216  bool isAcceptableTagRedeclaration(const TagDecl *Previous,
2217  TagTypeKind NewTag, bool isDefinition,
2218  SourceLocation NewTagLoc,
2219  const IdentifierInfo *Name);
2220 
2221  enum TagUseKind {
2222  TUK_Reference, // Reference to a tag: 'struct foo *X;'
2223  TUK_Declaration, // Fwd decl of a tag: 'struct foo;'
2224  TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;'
2225  TUK_Friend // Friend declaration: 'friend struct foo;'
2226  };
2227 
2228  Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
2229  SourceLocation KWLoc, CXXScopeSpec &SS, IdentifierInfo *Name,
2230  SourceLocation NameLoc, const ParsedAttributesView &Attr,
2231  AccessSpecifier AS, SourceLocation ModulePrivateLoc,
2232  MultiTemplateParamsArg TemplateParameterLists, bool &OwnedDecl,
2233  bool &IsDependent, SourceLocation ScopedEnumKWLoc,
2234  bool ScopedEnumUsesClassTag, TypeResult UnderlyingType,
2235  bool IsTypeSpecifier, bool IsTemplateParamOrArg,
2236  SkipBodyInfo *SkipBody = nullptr);
2237 
2238  Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc,
2239  unsigned TagSpec, SourceLocation TagLoc,
2240  CXXScopeSpec &SS, IdentifierInfo *Name,
2241  SourceLocation NameLoc,
2242  const ParsedAttributesView &Attr,
2243  MultiTemplateParamsArg TempParamLists);
2244 
2245  TypeResult ActOnDependentTag(Scope *S,
2246  unsigned TagSpec,
2247  TagUseKind TUK,
2248  const CXXScopeSpec &SS,
2249  IdentifierInfo *Name,
2250  SourceLocation TagLoc,
2251  SourceLocation NameLoc);
2252 
2253  void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart,
2254  IdentifierInfo *ClassName,
2255  SmallVectorImpl<Decl *> &Decls);
2256  Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart,
2257  Declarator &D, Expr *BitfieldWidth);
2258 
2259  FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
2260  Declarator &D, Expr *BitfieldWidth,
2261  InClassInitStyle InitStyle,
2262  AccessSpecifier AS);
2263  MSPropertyDecl *HandleMSProperty(Scope *S, RecordDecl *TagD,
2264  SourceLocation DeclStart, Declarator &D,
2265  Expr *BitfieldWidth,
2266  InClassInitStyle InitStyle,
2267  AccessSpecifier AS,
2268  const ParsedAttr &MSPropertyAttr);
2269 
2270  FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T,
2271  TypeSourceInfo *TInfo,
2272  RecordDecl *Record, SourceLocation Loc,
2273  bool Mutable, Expr *BitfieldWidth,
2274  InClassInitStyle InitStyle,
2275  SourceLocation TSSL,
2276  AccessSpecifier AS, NamedDecl *PrevDecl,
2277  Declarator *D = nullptr);
2278 
2279  bool CheckNontrivialField(FieldDecl *FD);
2280  void DiagnoseNontrivial(const CXXRecordDecl *Record, CXXSpecialMember CSM);
2281 
2283  /// The triviality of a method unaffected by "trivial_abi".
2285 
2286  /// The triviality of a method affected by "trivial_abi".
2287  TAH_ConsiderTrivialABI
2288  };
2289 
2290  bool SpecialMemberIsTrivial(CXXMethodDecl *MD, CXXSpecialMember CSM,
2291  TrivialABIHandling TAH = TAH_IgnoreTrivialABI,
2292  bool Diagnose = false);
2293  CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD);
2294  void ActOnLastBitfield(SourceLocation DeclStart,
2295  SmallVectorImpl<Decl *> &AllIvarDecls);
2296  Decl *ActOnIvar(Scope *S, SourceLocation DeclStart,
2297  Declarator &D, Expr *BitfieldWidth,
2298  tok::ObjCKeywordKind visibility);
2299 
2300  // This is used for both record definitions and ObjC interface declarations.
2301  void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl,
2302  ArrayRef<Decl *> Fields, SourceLocation LBrac,
2303  SourceLocation RBrac, const ParsedAttributesView &AttrList);
2304 
2305  /// ActOnTagStartDefinition - Invoked when we have entered the
2306  /// scope of a tag's definition (e.g., for an enumeration, class,
2307  /// struct, or union).
2308  void ActOnTagStartDefinition(Scope *S, Decl *TagDecl);
2309 
2310  /// Perform ODR-like check for C/ObjC when merging tag types from modules.
2311  /// Differently from C++, actually parse the body and reject / error out
2312  /// in case of a structural mismatch.
2313  bool ActOnDuplicateDefinition(DeclSpec &DS, Decl *Prev,
2314  SkipBodyInfo &SkipBody);
2315 
2317 
2318  /// Invoked when we enter a tag definition that we're skipping.
2319  SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD);
2320 
2321  Decl *ActOnObjCContainerStartDefinition(Decl *IDecl);
2322 
2323  /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a
2324  /// C++ record definition's base-specifiers clause and are starting its
2325  /// member declarations.
2326  void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl,
2327  SourceLocation FinalLoc,
2328  bool IsFinalSpelledSealed,
2329  SourceLocation LBraceLoc);
2330 
2331  /// ActOnTagFinishDefinition - Invoked once we have finished parsing
2332  /// the definition of a tag (enumeration, class, struct, or union).
2333  void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl,
2334  SourceRange BraceRange);
2335 
2336  void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context);
2337 
2338  void ActOnObjCContainerFinishDefinition();
2339 
2340  /// Invoked when we must temporarily exit the objective-c container
2341  /// scope for parsing/looking-up C constructs.
2342  ///
2343  /// Must be followed by a call to \see ActOnObjCReenterContainerContext
2344  void ActOnObjCTemporaryExitContainerContext(DeclContext *DC);
2345  void ActOnObjCReenterContainerContext(DeclContext *DC);
2346 
2347  /// ActOnTagDefinitionError - Invoked when there was an unrecoverable
2348  /// error parsing the definition of a tag.
2349  void ActOnTagDefinitionError(Scope *S, Decl *TagDecl);
2350 
2351  EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum,
2352  EnumConstantDecl *LastEnumConst,
2353  SourceLocation IdLoc,
2354  IdentifierInfo *Id,
2355  Expr *val);
2356  bool CheckEnumUnderlyingType(TypeSourceInfo *TI);
2357  bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped,
2358  QualType EnumUnderlyingTy, bool IsFixed,
2359  const EnumDecl *Prev);
2360 
2361  /// Determine whether the body of an anonymous enumeration should be skipped.
2362  /// \param II The name of the first enumerator.
2363  SkipBodyInfo shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II,
2364  SourceLocation IILoc);
2365 
2366  Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant,
2368  const ParsedAttributesView &Attrs,
2369  SourceLocation EqualLoc, Expr *Val);
2370  void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange,
2371  Decl *EnumDecl, ArrayRef<Decl *> Elements, Scope *S,
2372  const ParsedAttributesView &Attr);
2373 
2374  DeclContext *getContainingDC(DeclContext *DC);
2375 
2376  /// Set the current declaration context until it gets popped.
2377  void PushDeclContext(Scope *S, DeclContext *DC);
2378  void PopDeclContext();
2379 
2380  /// EnterDeclaratorContext - Used when we must lookup names in the context
2381  /// of a declarator's nested name specifier.
2382  void EnterDeclaratorContext(Scope *S, DeclContext *DC);
2383  void ExitDeclaratorContext(Scope *S);
2384 
2385  /// Push the parameters of D, which must be a function, into scope.
2386  void ActOnReenterFunctionContext(Scope* S, Decl* D);
2387  void ActOnExitFunctionContext();
2388 
2389  DeclContext *getFunctionLevelDeclContext();
2390 
2391  /// getCurFunctionDecl - If inside of a function body, this returns a pointer
2392  /// to the function decl for the function being parsed. If we're currently
2393  /// in a 'block', this returns the containing context.
2394  FunctionDecl *getCurFunctionDecl();
2395 
2396  /// getCurMethodDecl - If inside of a method body, this returns a pointer to
2397  /// the method decl for the method being parsed. If we're currently
2398  /// in a 'block', this returns the containing context.
2399  ObjCMethodDecl *getCurMethodDecl();
2400 
2401  /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
2402  /// or C function we're in, otherwise return null. If we're currently
2403  /// in a 'block', this returns the containing context.
2404  NamedDecl *getCurFunctionOrMethodDecl();
2405 
2406  /// Add this decl to the scope shadowed decl chains.
2407  void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true);
2408 
2409  /// Make the given externally-produced declaration visible at the
2410  /// top level scope.
2411  ///
2412  /// \param D The externally-produced declaration to push.
2413  ///
2414  /// \param Name The name of the externally-produced declaration.
2415  void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name);
2416 
2417  /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
2418  /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
2419  /// true if 'D' belongs to the given declaration context.
2420  ///
2421  /// \param AllowInlineNamespace If \c true, allow the declaration to be in the
2422  /// enclosing namespace set of the context, rather than contained
2423  /// directly within it.
2424  bool isDeclInScope(NamedDecl *D, DeclContext *Ctx, Scope *S = nullptr,
2425  bool AllowInlineNamespace = false);
2426 
2427  /// Finds the scope corresponding to the given decl context, if it
2428  /// happens to be an enclosing scope. Otherwise return NULL.
2429  static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC);
2430 
2431  /// Subroutines of ActOnDeclarator().
2432  TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
2433  TypeSourceInfo *TInfo);
2434  bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New);
2435 
2436  /// Describes the kind of merge to perform for availability
2437  /// attributes (including "deprecated", "unavailable", and "availability").
2439  /// Don't merge availability attributes at all.
2441  /// Merge availability attributes for a redeclaration, which requires
2442  /// an exact match.
2444  /// Merge availability attributes for an override, which requires
2445  /// an exact match or a weakening of constraints.
2447  /// Merge availability attributes for an implementation of
2448  /// a protocol requirement.
2450  };
2451 
2452  /// Attribute merging methods. Return true if a new attribute was added.
2453  AvailabilityAttr *mergeAvailabilityAttr(NamedDecl *D, SourceRange Range,
2454  IdentifierInfo *Platform,
2455  bool Implicit,
2456  VersionTuple Introduced,
2457  VersionTuple Deprecated,
2458  VersionTuple Obsoleted,
2459  bool IsUnavailable,
2460  StringRef Message,
2461  bool IsStrict, StringRef Replacement,
2463  unsigned AttrSpellingListIndex);
2464  TypeVisibilityAttr *mergeTypeVisibilityAttr(Decl *D, SourceRange Range,
2465  TypeVisibilityAttr::VisibilityType Vis,
2466  unsigned AttrSpellingListIndex);
2467  VisibilityAttr *mergeVisibilityAttr(Decl *D, SourceRange Range,
2468  VisibilityAttr::VisibilityType Vis,
2469  unsigned AttrSpellingListIndex);
2470  UuidAttr *mergeUuidAttr(Decl *D, SourceRange Range,
2471  unsigned AttrSpellingListIndex, StringRef Uuid);
2472  DLLImportAttr *mergeDLLImportAttr(Decl *D, SourceRange Range,
2473  unsigned AttrSpellingListIndex);
2474  DLLExportAttr *mergeDLLExportAttr(Decl *D, SourceRange Range,
2475  unsigned AttrSpellingListIndex);
2476  MSInheritanceAttr *
2477  mergeMSInheritanceAttr(Decl *D, SourceRange Range, bool BestCase,
2478  unsigned AttrSpellingListIndex,
2479  MSInheritanceAttr::Spelling SemanticSpelling);
2480  FormatAttr *mergeFormatAttr(Decl *D, SourceRange Range,
2481  IdentifierInfo *Format, int FormatIdx,
2482  int FirstArg, unsigned AttrSpellingListIndex);
2483  SectionAttr *mergeSectionAttr(Decl *D, SourceRange Range, StringRef Name,
2484  unsigned AttrSpellingListIndex);
2485  CodeSegAttr *mergeCodeSegAttr(Decl *D, SourceRange Range, StringRef Name,
2486  unsigned AttrSpellingListIndex);
2487  AlwaysInlineAttr *mergeAlwaysInlineAttr(Decl *D, SourceRange Range,
2488  IdentifierInfo *Ident,
2489  unsigned AttrSpellingListIndex);
2490  MinSizeAttr *mergeMinSizeAttr(Decl *D, SourceRange Range,
2491  unsigned AttrSpellingListIndex);
2492  OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D, SourceRange Range,
2493  unsigned AttrSpellingListIndex);
2494  InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, const ParsedAttr &AL);
2495  InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D,
2496  const InternalLinkageAttr &AL);
2497  CommonAttr *mergeCommonAttr(Decl *D, const ParsedAttr &AL);
2498  CommonAttr *mergeCommonAttr(Decl *D, const CommonAttr &AL);
2499 
2500  void mergeDeclAttributes(NamedDecl *New, Decl *Old,
2501  AvailabilityMergeKind AMK = AMK_Redeclaration);
2502  void MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New,
2503  LookupResult &OldDecls);
2504  bool MergeFunctionDecl(FunctionDecl *New, NamedDecl *&Old, Scope *S,
2505  bool MergeTypeWithOld);
2506  bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old,
2507  Scope *S, bool MergeTypeWithOld);
2508  void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old);
2509  void MergeVarDecl(VarDecl *New, LookupResult &Previous);
2510  void MergeVarDeclTypes(VarDecl *New, VarDecl *Old, bool MergeTypeWithOld);
2511  void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old);
2512  bool checkVarDeclRedefinition(VarDecl *OldDefn, VarDecl *NewDefn);
2513  void notePreviousDefinition(const NamedDecl *Old, SourceLocation New);
2514  bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S);
2515 
2516  // AssignmentAction - This is used by all the assignment diagnostic functions
2517  // to represent what is actually causing the operation
2526  AA_Passing_CFAudited
2527  };
2528 
2529  /// C++ Overloading.
2531  /// This is a legitimate overload: the existing declarations are
2532  /// functions or function templates with different signatures.
2534 
2535  /// This is not an overload because the signature exactly matches
2536  /// an existing declaration.
2538 
2539  /// This is not an overload because the lookup results contain a
2540  /// non-function.
2541  Ovl_NonFunction
2542  };
2543  OverloadKind CheckOverload(Scope *S,
2544  FunctionDecl *New,
2545  const LookupResult &OldDecls,
2546  NamedDecl *&OldDecl,
2547  bool IsForUsingDecl);
2548  bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl,
2549  bool ConsiderCudaAttrs = true);
2550 
2551  /// Checks availability of the function depending on the current
2552  /// function context.Inside an unavailable function,unavailability is ignored.
2553  ///
2554  /// \returns true if \p FD is unavailable and current context is inside
2555  /// an available function, false otherwise.
2556  bool isFunctionConsideredUnavailable(FunctionDecl *FD);
2557 
2559  TryImplicitConversion(Expr *From, QualType ToType,
2560  bool SuppressUserConversions,
2561  bool AllowExplicit,
2562  bool InOverloadResolution,
2563  bool CStyle,
2564  bool AllowObjCWritebackConversion);
2565 
2566  bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
2567  bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
2568  bool IsComplexPromotion(QualType FromType, QualType ToType);
2569  bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
2570  bool InOverloadResolution,
2571  QualType& ConvertedType, bool &IncompatibleObjC);
2572  bool isObjCPointerConversion(QualType FromType, QualType ToType,
2573  QualType& ConvertedType, bool &IncompatibleObjC);
2574  bool isObjCWritebackConversion(QualType FromType, QualType ToType,
2575  QualType &ConvertedType);
2576  bool IsBlockPointerConversion(QualType FromType, QualType ToType,
2577  QualType& ConvertedType);
2578  bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
2579  const FunctionProtoType *NewType,
2580  unsigned *ArgPos = nullptr);
2581  void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
2582  QualType FromType, QualType ToType);
2583 
2584  void maybeExtendBlockObject(ExprResult &E);
2585  CastKind PrepareCastToObjCObjectPointer(ExprResult &E);
2586  bool CheckPointerConversion(Expr *From, QualType ToType,
2587  CastKind &Kind,
2588  CXXCastPath& BasePath,
2589  bool IgnoreBaseAccess,
2590  bool Diagnose = true);
2591  bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
2592  bool InOverloadResolution,
2593  QualType &ConvertedType);
2594  bool CheckMemberPointerConversion(Expr *From, QualType ToType,
2595  CastKind &Kind,
2596  CXXCastPath &BasePath,
2597  bool IgnoreBaseAccess);
2598  bool IsQualificationConversion(QualType FromType, QualType ToType,
2599  bool CStyle, bool &ObjCLifetimeConversion);
2600  bool IsFunctionConversion(QualType FromType, QualType ToType,
2601  QualType &ResultTy);
2602  bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType);
2603  bool isSameOrCompatibleFunctionType(CanQualType Param, CanQualType Arg);
2604 
2605  ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
2606  const VarDecl *NRVOCandidate,
2607  QualType ResultType,
2608  Expr *Value,
2609  bool AllowNRVO = true);
2610 
2611  bool CanPerformCopyInitialization(const InitializedEntity &Entity,
2612  ExprResult Init);
2613  ExprResult PerformCopyInitialization(const InitializedEntity &Entity,
2614  SourceLocation EqualLoc,
2615  ExprResult Init,
2616  bool TopLevelOfInitList = false,
2617  bool AllowExplicit = false);
2618  ExprResult PerformObjectArgumentInitialization(Expr *From,
2619  NestedNameSpecifier *Qualifier,
2620  NamedDecl *FoundDecl,
2621  CXXMethodDecl *Method);
2622 
2623  /// Check that the lifetime of the initializer (and its subobjects) is
2624  /// sufficient for initializing the entity, and perform lifetime extension
2625  /// (when permitted) if not.
2626  void checkInitializerLifetime(const InitializedEntity &Entity, Expr *Init);
2627 
2628  ExprResult PerformContextuallyConvertToBool(Expr *From);
2629  ExprResult PerformContextuallyConvertToObjCPointer(Expr *From);
2630 
2631  /// Contexts in which a converted constant expression is required.
2632  enum CCEKind {
2633  CCEK_CaseValue, ///< Expression in a case label.
2634  CCEK_Enumerator, ///< Enumerator value with fixed underlying type.
2635  CCEK_TemplateArg, ///< Value of a non-type template parameter.
2636  CCEK_NewExpr, ///< Constant expression in a noptr-new-declarator.
2637  CCEK_ConstexprIf ///< Condition in a constexpr if statement.
2638  };
2640  llvm::APSInt &Value, CCEKind CCE);
2642  APValue &Value, CCEKind CCE);
2643 
2644  /// Abstract base class used to perform a contextual implicit
2645  /// conversion from an expression to any type passing a filter.
2647  public:
2648  bool Suppress;
2650 
2651  ContextualImplicitConverter(bool Suppress = false,
2652  bool SuppressConversion = false)
2653  : Suppress(Suppress), SuppressConversion(SuppressConversion) {}
2654 
2655  /// Determine whether the specified type is a valid destination type
2656  /// for this conversion.
2657  virtual bool match(QualType T) = 0;
2658 
2659  /// Emits a diagnostic complaining that the expression does not have
2660  /// integral or enumeration type.
2661  virtual SemaDiagnosticBuilder
2662  diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) = 0;
2663 
2664  /// Emits a diagnostic when the expression has incomplete class type.
2665  virtual SemaDiagnosticBuilder
2666  diagnoseIncomplete(Sema &S, SourceLocation Loc, QualType T) = 0;
2667 
2668  /// Emits a diagnostic when the only matching conversion function
2669  /// is explicit.
2670  virtual SemaDiagnosticBuilder diagnoseExplicitConv(
2671  Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0;
2672 
2673  /// Emits a note for the explicit conversion function.
2674  virtual SemaDiagnosticBuilder
2675  noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0;
2676 
2677  /// Emits a diagnostic when there are multiple possible conversion
2678  /// functions.
2679  virtual SemaDiagnosticBuilder
2680  diagnoseAmbiguous(Sema &S, SourceLocation Loc, QualType T) = 0;
2681 
2682  /// Emits a note for one of the candidate conversions.
2683  virtual SemaDiagnosticBuilder
2684  noteAmbiguous(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0;
2685 
2686  /// Emits a diagnostic when we picked a conversion function
2687  /// (for cases when we are not allowed to pick a conversion function).
2688  virtual SemaDiagnosticBuilder diagnoseConversion(
2689  Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0;
2690 
2692  };
2693 
2695  bool AllowScopedEnumerations;
2696 
2697  public:
2698  ICEConvertDiagnoser(bool AllowScopedEnumerations,
2699  bool Suppress, bool SuppressConversion)
2700  : ContextualImplicitConverter(Suppress, SuppressConversion),
2701  AllowScopedEnumerations(AllowScopedEnumerations) {}
2702 
2703  /// Match an integral or (possibly scoped) enumeration type.
2704  bool match(QualType T) override;
2705 
2708  return diagnoseNotInt(S, Loc, T);
2709  }
2710 
2711  /// Emits a diagnostic complaining that the expression does not have
2712  /// integral or enumeration type.
2713  virtual SemaDiagnosticBuilder
2714  diagnoseNotInt(Sema &S, SourceLocation Loc, QualType T) = 0;
2715  };
2716 
2717  /// Perform a contextual implicit conversion.
2718  ExprResult PerformContextualImplicitConversion(
2719  SourceLocation Loc, Expr *FromE, ContextualImplicitConverter &Converter);
2720 
2721 
2725  OS_Error
2726  };
2727  ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE);
2728 
2729  // Note that LK_String is intentionally after the other literals, as
2730  // this is used for diagnostics logic.
2738  LK_None
2739  };
2740  ObjCLiteralKind CheckLiteralKind(Expr *FromE);
2741 
2742  ExprResult PerformObjectMemberConversion(Expr *From,
2743  NestedNameSpecifier *Qualifier,
2744  NamedDecl *FoundDecl,
2745  NamedDecl *Member);
2746 
2747  // Members have to be NamespaceDecl* or TranslationUnitDecl*.
2748  // TODO: make this is a typesafe union.
2751 
2753 
2754  void AddOverloadCandidate(FunctionDecl *Function, DeclAccessPair FoundDecl,
2755  ArrayRef<Expr *> Args,
2756  OverloadCandidateSet &CandidateSet,
2757  bool SuppressUserConversions = false,
2758  bool PartialOverloading = false,
2759  bool AllowExplicit = false,
2760  ADLCallKind IsADLCandidate = ADLCallKind::NotADL,
2761  ConversionSequenceList EarlyConversions = None);
2762  void AddFunctionCandidates(const UnresolvedSetImpl &Functions,
2763  ArrayRef<Expr *> Args,
2764  OverloadCandidateSet &CandidateSet,
2765  TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr,
2766  bool SuppressUserConversions = false,
2767  bool PartialOverloading = false,
2768  bool FirstArgumentIsBase = false);
2769  void AddMethodCandidate(DeclAccessPair FoundDecl,
2770  QualType ObjectType,
2771  Expr::Classification ObjectClassification,
2772  ArrayRef<Expr *> Args,
2773  OverloadCandidateSet& CandidateSet,
2774  bool SuppressUserConversion = false);
2775  void AddMethodCandidate(CXXMethodDecl *Method,
2776  DeclAccessPair FoundDecl,
2777  CXXRecordDecl *ActingContext, QualType ObjectType,
2778  Expr::Classification ObjectClassification,
2779  ArrayRef<Expr *> Args,
2780  OverloadCandidateSet& CandidateSet,
2781  bool SuppressUserConversions = false,
2782  bool PartialOverloading = false,
2783  ConversionSequenceList EarlyConversions = None);
2784  void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl,
2785  DeclAccessPair FoundDecl,
2786  CXXRecordDecl *ActingContext,
2787  TemplateArgumentListInfo *ExplicitTemplateArgs,
2788  QualType ObjectType,
2789  Expr::Classification ObjectClassification,
2790  ArrayRef<Expr *> Args,
2791  OverloadCandidateSet& CandidateSet,
2792  bool SuppressUserConversions = false,
2793  bool PartialOverloading = false);
2794  void AddTemplateOverloadCandidate(
2795  FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl,
2796  TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args,
2797  OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false,
2798  bool PartialOverloading = false,
2799  ADLCallKind IsADLCandidate = ADLCallKind::NotADL);
2800  bool CheckNonDependentConversions(FunctionTemplateDecl *FunctionTemplate,
2801  ArrayRef<QualType> ParamTypes,
2802  ArrayRef<Expr *> Args,
2803  OverloadCandidateSet &CandidateSet,
2804  ConversionSequenceList &Conversions,
2805  bool SuppressUserConversions,
2806  CXXRecordDecl *ActingContext = nullptr,
2807  QualType ObjectType = QualType(),
2809  ObjectClassification = {});
2810  void AddConversionCandidate(CXXConversionDecl *Conversion,
2811  DeclAccessPair FoundDecl,
2812  CXXRecordDecl *ActingContext,
2813  Expr *From, QualType ToType,
2814  OverloadCandidateSet& CandidateSet,
2815  bool AllowObjCConversionOnExplicit,
2816  bool AllowResultConversion = true);
2817  void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate,
2818  DeclAccessPair FoundDecl,
2819  CXXRecordDecl *ActingContext,
2820  Expr *From, QualType ToType,
2821  OverloadCandidateSet &CandidateSet,
2822  bool AllowObjCConversionOnExplicit,
2823  bool AllowResultConversion = true);
2824  void AddSurrogateCandidate(CXXConversionDecl *Conversion,
2825  DeclAccessPair FoundDecl,
2826  CXXRecordDecl *ActingContext,
2827  const FunctionProtoType *Proto,
2828  Expr *Object, ArrayRef<Expr *> Args,
2829  OverloadCandidateSet& CandidateSet);
2830  void AddMemberOperatorCandidates(OverloadedOperatorKind Op,
2831  SourceLocation OpLoc, ArrayRef<Expr *> Args,
2832  OverloadCandidateSet& CandidateSet,
2833  SourceRange OpRange = SourceRange());
2834  void AddBuiltinCandidate(QualType *ParamTys, ArrayRef<Expr *> Args,
2835  OverloadCandidateSet& CandidateSet,
2836  bool IsAssignmentOperator = false,
2837  unsigned NumContextualBoolArguments = 0);
2838  void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
2839  SourceLocation OpLoc, ArrayRef<Expr *> Args,
2840  OverloadCandidateSet& CandidateSet);
2841  void AddArgumentDependentLookupCandidates(DeclarationName Name,
2842  SourceLocation Loc,
2843  ArrayRef<Expr *> Args,
2844  TemplateArgumentListInfo *ExplicitTemplateArgs,
2845  OverloadCandidateSet& CandidateSet,
2846  bool PartialOverloading = false);
2847 
2848  // Emit as a 'note' the specific overload candidate
2849  void NoteOverloadCandidate(NamedDecl *Found, FunctionDecl *Fn,
2850  QualType DestType = QualType(),
2851  bool TakingAddress = false);
2852 
2853  // Emit as a series of 'note's all template and non-templates identified by
2854  // the expression Expr
2855  void NoteAllOverloadCandidates(Expr *E, QualType DestType = QualType(),
2856  bool TakingAddress = false);
2857 
2858  /// Check the enable_if expressions on the given function. Returns the first
2859  /// failing attribute, or NULL if they were all successful.
2860  EnableIfAttr *CheckEnableIf(FunctionDecl *Function, ArrayRef<Expr *> Args,
2861  bool MissingImplicitThis = false);
2862 
2863  /// Find the failed Boolean condition within a given Boolean
2864  /// constant expression, and describe it with a string.
2865  std::pair<Expr *, std::string> findFailedBooleanCondition(Expr *Cond);
2866 
2867  /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any
2868  /// non-ArgDependent DiagnoseIfAttrs.
2869  ///
2870  /// Argument-dependent diagnose_if attributes should be checked each time a
2871  /// function is used as a direct callee of a function call.
2872  ///
2873  /// Returns true if any errors were emitted.
2874  bool diagnoseArgDependentDiagnoseIfAttrs(const FunctionDecl *Function,
2875  const Expr *ThisArg,
2877  SourceLocation Loc);
2878 
2879  /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any
2880  /// ArgDependent DiagnoseIfAttrs.
2881  ///
2882  /// Argument-independent diagnose_if attributes should be checked on every use
2883  /// of a function.
2884  ///
2885  /// Returns true if any errors were emitted.
2886  bool diagnoseArgIndependentDiagnoseIfAttrs(const NamedDecl *ND,
2887  SourceLocation Loc);
2888 
2889  /// Returns whether the given function's address can be taken or not,
2890  /// optionally emitting a diagnostic if the address can't be taken.
2891  ///
2892  /// Returns false if taking the address of the function is illegal.
2893  bool checkAddressOfFunctionIsAvailable(const FunctionDecl *Function,
2894  bool Complain = false,
2895  SourceLocation Loc = SourceLocation());
2896 
2897  // [PossiblyAFunctionType] --> [Return]
2898  // NonFunctionType --> NonFunctionType
2899  // R (A) --> R(A)
2900  // R (*)(A) --> R (A)
2901  // R (&)(A) --> R (A)
2902  // R (S::*)(A) --> R (A)
2903  QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType);
2904 
2905  FunctionDecl *
2906  ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr,
2907  QualType TargetType,
2908  bool Complain,
2909  DeclAccessPair &Found,
2910  bool *pHadMultipleCandidates = nullptr);
2911 
2912  FunctionDecl *
2913  resolveAddressOfOnlyViableOverloadCandidate(Expr *E,
2914  DeclAccessPair &FoundResult);
2915 
2916  bool resolveAndFixAddressOfOnlyViableOverloadCandidate(
2917  ExprResult &SrcExpr, bool DoFunctionPointerConversion = false);
2918 
2919  FunctionDecl *
2920  ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl,
2921  bool Complain = false,
2922  DeclAccessPair *Found = nullptr);
2923 
2924  bool ResolveAndFixSingleFunctionTemplateSpecialization(
2925  ExprResult &SrcExpr,
2926  bool DoFunctionPointerConverion = false,
2927  bool Complain = false,
2928  SourceRange OpRangeForComplaining = SourceRange(),
2929  QualType DestTypeForComplaining = QualType(),
2930  unsigned DiagIDForComplaining = 0);
2931 
2932 
2933  Expr *FixOverloadedFunctionReference(Expr *E,
2934  DeclAccessPair FoundDecl,
2935  FunctionDecl *Fn);
2936  ExprResult FixOverloadedFunctionReference(ExprResult,
2937  DeclAccessPair FoundDecl,
2938  FunctionDecl *Fn);
2939 
2940  void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE,
2941  ArrayRef<Expr *> Args,
2942  OverloadCandidateSet &CandidateSet,
2943  bool PartialOverloading = false);
2944 
2945  // An enum used to represent the different possible results of building a
2946  // range-based for loop.
2950  FRS_DiagnosticIssued
2951  };
2952 
2953  ForRangeStatus BuildForRangeBeginEndCall(SourceLocation Loc,
2954  SourceLocation RangeLoc,
2955  const DeclarationNameInfo &NameInfo,
2956  LookupResult &MemberLookup,
2957  OverloadCandidateSet *CandidateSet,
2958  Expr *Range, ExprResult *CallExpr);
2959 
2960  ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn,
2961  UnresolvedLookupExpr *ULE,
2962  SourceLocation LParenLoc,
2963  MultiExprArg Args,
2964  SourceLocation RParenLoc,
2965  Expr *ExecConfig,
2966  bool AllowTypoCorrection=true,
2967  bool CalleesAddressIsTaken=false);
2968 
2969  bool buildOverloadedCallSet(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE,
2970  MultiExprArg Args, SourceLocation RParenLoc,
2971  OverloadCandidateSet *CandidateSet,
2972  ExprResult *Result);
2973 
2974  ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc,
2975  UnaryOperatorKind Opc,
2976  const UnresolvedSetImpl &Fns,
2977  Expr *input, bool RequiresADL = true);
2978 
2979  ExprResult CreateOverloadedBinOp(SourceLocation OpLoc,
2980  BinaryOperatorKind Opc,
2981  const UnresolvedSetImpl &Fns,
2982  Expr *LHS, Expr *RHS,
2983  bool RequiresADL = true);
2984 
2985  ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
2986  SourceLocation RLoc,
2987  Expr *Base,Expr *Idx);
2988 
2989  ExprResult
2990  BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
2991  SourceLocation LParenLoc,
2992  MultiExprArg Args,
2993  SourceLocation RParenLoc);
2994  ExprResult
2995  BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
2996  MultiExprArg Args,
2997  SourceLocation RParenLoc);
2998 
2999  ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base,
3000  SourceLocation OpLoc,
3001  bool *NoArrowOperatorFound = nullptr);
3002 
3003  /// CheckCallReturnType - Checks that a call expression's return type is
3004  /// complete. Returns true on failure. The location passed in is the location
3005  /// that best represents the call.
3006  bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc,
3007  CallExpr *CE, FunctionDecl *FD);
3008 
3009  /// Helpers for dealing with blocks and functions.
3010  bool CheckParmsForFunctionDef(ArrayRef<ParmVarDecl *> Parameters,
3011  bool CheckParameterNames);
3012  void CheckCXXDefaultArguments(FunctionDecl *FD);
3013  void CheckExtraCXXDefaultArguments(Declarator &D);
3014  Scope *getNonFieldDeclScope(Scope *S);
3015 
3016  /// \name Name lookup
3017  ///
3018  /// These routines provide name lookup that is used during semantic
3019  /// analysis to resolve the various kinds of names (identifiers,
3020  /// overloaded operator names, constructor names, etc.) into zero or
3021  /// more declarations within a particular scope. The major entry
3022  /// points are LookupName, which performs unqualified name lookup,
3023  /// and LookupQualifiedName, which performs qualified name lookup.
3024  ///
3025  /// All name lookup is performed based on some specific criteria,
3026  /// which specify what names will be visible to name lookup and how
3027  /// far name lookup should work. These criteria are important both
3028  /// for capturing language semantics (certain lookups will ignore
3029  /// certain names, for example) and for performance, since name
3030  /// lookup is often a bottleneck in the compilation of C++. Name
3031  /// lookup criteria is specified via the LookupCriteria enumeration.
3032  ///
3033  /// The results of name lookup can vary based on the kind of name
3034  /// lookup performed, the current language, and the translation
3035  /// unit. In C, for example, name lookup will either return nothing
3036  /// (no entity found) or a single declaration. In C++, name lookup
3037  /// can additionally refer to a set of overloaded functions or
3038  /// result in an ambiguity. All of the possible results of name
3039  /// lookup are captured by the LookupResult class, which provides
3040  /// the ability to distinguish among them.
3041  //@{
3042 
3043  /// Describes the kind of name lookup to perform.
3045  /// Ordinary name lookup, which finds ordinary names (functions,
3046  /// variables, typedefs, etc.) in C and most kinds of names
3047  /// (functions, variables, members, types, etc.) in C++.
3048  LookupOrdinaryName = 0,
3049  /// Tag name lookup, which finds the names of enums, classes,
3050  /// structs, and unions.
3052  /// Label name lookup.
3054  /// Member name lookup, which finds the names of
3055  /// class/struct/union members.
3057  /// Look up of an operator name (e.g., operator+) for use with
3058  /// operator overloading. This lookup is similar to ordinary name
3059  /// lookup, but will ignore any declarations that are class members.
3061  /// Look up of a name that precedes the '::' scope resolution
3062  /// operator in C++. This lookup completely ignores operator, object,
3063  /// function, and enumerator names (C++ [basic.lookup.qual]p1).
3065  /// Look up a namespace name within a C++ using directive or
3066  /// namespace alias definition, ignoring non-namespace names (C++
3067  /// [basic.lookup.udir]p1).
3069  /// Look up all declarations in a scope with the given name,
3070  /// including resolved using declarations. This is appropriate
3071  /// for checking redeclarations for a using declaration.
3073  /// Look up an ordinary name that is going to be redeclared as a
3074  /// name with linkage. This lookup ignores any declarations that
3075  /// are outside of the current scope unless they have linkage. See
3076  /// C99 6.2.2p4-5 and C++ [basic.link]p6.
3078  /// Look up a friend of a local class. This lookup does not look
3079  /// outside the innermost non-class scope. See C++11 [class.friend]p11.
3081  /// Look up the name of an Objective-C protocol.
3083  /// Look up implicit 'self' parameter of an objective-c method.
3085  /// Look up the name of an OpenMP user-defined reduction operation.
3087  /// Look up any declaration with any name.
3088  LookupAnyName
3089  };
3090 
3091  /// Specifies whether (or how) name lookup is being performed for a
3092  /// redeclaration (vs. a reference).
3094  /// The lookup is a reference to this name that is not for the
3095  /// purpose of redeclaring the name.
3096  NotForRedeclaration = 0,
3097  /// The lookup results will be used for redeclaration of a name,
3098  /// if an entity by that name already exists and is visible.
3100  /// The lookup results will be used for redeclaration of a name
3101  /// with external linkage; non-visible lookup results with external linkage
3102  /// may also be found.
3103  ForExternalRedeclaration
3104  };
3105 
3107  // A declaration with an owning module for linkage can never link against
3108  // anything that is not visible. We don't need to check linkage here; if
3109  // the context has internal linkage, redeclaration lookup won't find things
3110  // from other TUs, and we can't safely compute linkage yet in general.
3111  if (cast<Decl>(CurContext)
3112  ->getOwningModuleForLinkage(/*IgnoreLinkage*/true))
3113  return ForVisibleRedeclaration;
3114  return ForExternalRedeclaration;
3115  }
3116 
3117  /// The possible outcomes of name lookup for a literal operator.
3119  /// The lookup resulted in an error.
3121  /// The lookup found no match but no diagnostic was issued.
3123  /// The lookup found a single 'cooked' literal operator, which
3124  /// expects a normal literal to be built and passed to it.
3126  /// The lookup found a single 'raw' literal operator, which expects
3127  /// a string literal containing the spelling of the literal token.
3129  /// The lookup found an overload set of literal operator templates,
3130  /// which expect the characters of the spelling of the literal token to be
3131  /// passed as a non-type template argument pack.
3133  /// The lookup found an overload set of literal operator templates,
3134  /// which expect the character type and characters of the spelling of the
3135  /// string literal token to be passed as template arguments.
3136  LOLR_StringTemplate
3137  };
3138 
3139  SpecialMemberOverloadResult LookupSpecialMember(CXXRecordDecl *D,
3141  bool ConstArg,
3142  bool VolatileArg,
3143  bool RValueThis,
3144  bool ConstThis,
3145  bool VolatileThis);
3146 
3147  typedef std::function<void(const TypoCorrection &)> TypoDiagnosticGenerator;
3148  typedef std::function<ExprResult(Sema &, TypoExpr *, TypoCorrection)>
3150 
3151 private:
3152  bool CppLookupName(LookupResult &R, Scope *S);
3153 
3154  struct TypoExprState {
3155  std::unique_ptr<TypoCorrectionConsumer> Consumer;
3156  TypoDiagnosticGenerator DiagHandler;
3157  TypoRecoveryCallback RecoveryHandler;
3158  TypoExprState();
3159  TypoExprState(TypoExprState &&other) noexcept;
3160  TypoExprState &operator=(TypoExprState &&other) noexcept;
3161  };
3162 
3163  /// The set of unhandled TypoExprs and their associated state.
3164  llvm::MapVector<TypoExpr *, TypoExprState> DelayedTypos;
3165 
3166  /// Creates a new TypoExpr AST node.
3167  TypoExpr *createDelayedTypo(std::unique_ptr<TypoCorrectionConsumer> TCC,
3168  TypoDiagnosticGenerator TDG,
3169  TypoRecoveryCallback TRC);
3170 
3171  // The set of known/encountered (unique, canonicalized) NamespaceDecls.
3172  //
3173  // The boolean value will be true to indicate that the namespace was loaded
3174  // from an AST/PCH file, or false otherwise.
3175  llvm::MapVector<NamespaceDecl*, bool> KnownNamespaces;
3176 
3177  /// Whether we have already loaded known namespaces from an extenal
3178  /// source.
3179  bool LoadedExternalKnownNamespaces;
3180 
3181  /// Helper for CorrectTypo and CorrectTypoDelayed used to create and
3182  /// populate a new TypoCorrectionConsumer. Returns nullptr if typo correction
3183  /// should be skipped entirely.
3184  std::unique_ptr<TypoCorrectionConsumer>
3185  makeTypoCorrectionConsumer(const DeclarationNameInfo &Typo,
3186  Sema::LookupNameKind LookupKind, Scope *S,
3187  CXXScopeSpec *SS,
3188  std::unique_ptr<CorrectionCandidateCallback> CCC,
3189  DeclContext *MemberContext, bool EnteringContext,
3190  const ObjCObjectPointerType *OPT,
3191  bool ErrorRecovery);
3192 
3193 public:
3194  const TypoExprState &getTypoExprState(TypoExpr *TE) const;
3195 
3196  /// Clears the state of the given TypoExpr.
3197  void clearDelayedTypo(TypoExpr *TE);
3198 
3199  /// Look up a name, looking for a single declaration. Return
3200  /// null if the results were absent, ambiguous, or overloaded.
3201  ///
3202  /// It is preferable to use the elaborated form and explicitly handle
3203  /// ambiguity and overloaded.
3204  NamedDecl *LookupSingleName(Scope *S, DeclarationName Name,
3205  SourceLocation Loc,
3206  LookupNameKind NameKind,
3207  RedeclarationKind Redecl
3208  = NotForRedeclaration);
3209  bool LookupName(LookupResult &R, Scope *S,
3210  bool AllowBuiltinCreation = false);
3211  bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
3212  bool InUnqualifiedLookup = false);
3213  bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
3214  CXXScopeSpec &SS);
3215  bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS,
3216  bool AllowBuiltinCreation = false,
3217  bool EnteringContext = false);
3218  ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc,
3219  RedeclarationKind Redecl
3220  = NotForRedeclaration);
3221  bool LookupInSuper(LookupResult &R, CXXRecordDecl *Class);
3222 
3223  void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
3224  QualType T1, QualType T2,
3225  UnresolvedSetImpl &Functions);
3226 
3227  LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc,
3228  SourceLocation GnuLabelLoc = SourceLocation());
3229 
3230  DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class);
3231  CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class);
3232  CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class,
3233  unsigned Quals);
3234  CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals,
3235  bool RValueThis, unsigned ThisQuals);
3236  CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class,
3237  unsigned Quals);
3238  CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals,
3239  bool RValueThis, unsigned ThisQuals);
3240  CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class);
3241 
3242  bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id);
3243  LiteralOperatorLookupResult LookupLiteralOperator(Scope *S, LookupResult &R,
3244  ArrayRef<QualType> ArgTys,
3245  bool AllowRaw,
3246  bool AllowTemplate,
3247  bool AllowStringTemplate,
3248  bool DiagnoseMissing);
3249  bool isKnownName(StringRef name);
3250 
3251  void ArgumentDependentLookup(DeclarationName Name, SourceLocation Loc,
3252  ArrayRef<Expr *> Args, ADLResult &Functions);
3253 
3254  void LookupVisibleDecls(Scope *S, LookupNameKind Kind,
3255  VisibleDeclConsumer &Consumer,
3256  bool IncludeGlobalScope = true,
3257  bool LoadExternal = true);
3259  VisibleDeclConsumer &Consumer,
3260  bool IncludeGlobalScope = true,
3261  bool IncludeDependentBases = false,
3262  bool LoadExternal = true);
3263 
3265  CTK_NonError, // CorrectTypo used in a non error recovery situation.
3266  CTK_ErrorRecovery // CorrectTypo used in normal error recovery.
3267  };
3268 
3269  TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
3270  Sema::LookupNameKind LookupKind,
3271  Scope *S, CXXScopeSpec *SS,
3272  std::unique_ptr<CorrectionCandidateCallback> CCC,
3273  CorrectTypoKind Mode,
3274  DeclContext *MemberContext = nullptr,
3275  bool EnteringContext = false,
3276  const ObjCObjectPointerType *OPT = nullptr,
3277  bool RecordFailure = true);
3278 
3279  TypoExpr *CorrectTypoDelayed(const DeclarationNameInfo &Typo,
3280  Sema::LookupNameKind LookupKind, Scope *S,
3281  CXXScopeSpec *SS,
3282  std::unique_ptr<CorrectionCandidateCallback> CCC,
3283  TypoDiagnosticGenerator TDG,
3285  DeclContext *MemberContext = nullptr,
3286  bool EnteringContext = false,
3287  const ObjCObjectPointerType *OPT = nullptr);
3288 
3289  /// Process any TypoExprs in the given Expr and its children,
3290  /// generating diagnostics as appropriate and returning a new Expr if there
3291  /// were typos that were all successfully corrected and ExprError if one or
3292  /// more typos could not be corrected.
3293  ///
3294  /// \param E The Expr to check for TypoExprs.
3295  ///
3296  /// \param InitDecl A VarDecl to avoid because the Expr being corrected is its
3297  /// initializer.
3298  ///
3299  /// \param Filter A function applied to a newly rebuilt Expr to determine if
3300  /// it is an acceptable/usable result from a single combination of typo
3301  /// corrections. As long as the filter returns ExprError, different
3302  /// combinations of corrections will be tried until all are exhausted.
3303  ExprResult
3304  CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl = nullptr,
3305  llvm::function_ref<ExprResult(Expr *)> Filter =
3306  [](Expr *E) -> ExprResult { return E; });
3307 
3308  ExprResult
3310  llvm::function_ref<ExprResult(Expr *)> Filter) {
3311  return CorrectDelayedTyposInExpr(E, nullptr, Filter);
3312  }
3313 
3314  ExprResult
3315  CorrectDelayedTyposInExpr(ExprResult ER, VarDecl *InitDecl = nullptr,
3316  llvm::function_ref<ExprResult(Expr *)> Filter =
3317  [](Expr *E) -> ExprResult { return E; }) {
3318  return ER.isInvalid() ? ER : CorrectDelayedTyposInExpr(ER.get(), Filter);
3319  }
3320 
3321  ExprResult
3323  llvm::function_ref<ExprResult(Expr *)> Filter) {
3324  return CorrectDelayedTyposInExpr(ER, nullptr, Filter);
3325  }
3326 
3327  void diagnoseTypo(const TypoCorrection &Correction,
3328  const PartialDiagnostic &TypoDiag,
3329  bool ErrorRecovery = true);
3330 
3331  void diagnoseTypo(const TypoCorrection &Correction,
3332  const PartialDiagnostic &TypoDiag,
3333  const PartialDiagnostic &PrevNote,
3334  bool ErrorRecovery = true);
3335 
3336  void MarkTypoCorrectedFunctionDefinition(const NamedDecl *F);
3337 
3338  void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc,
3339  ArrayRef<Expr *> Args,
3340  AssociatedNamespaceSet &AssociatedNamespaces,
3341  AssociatedClassSet &AssociatedClasses);
3342 
3343  void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S,
3344  bool ConsiderLinkage, bool AllowInlineNamespace);
3345 
3346  bool CheckRedeclarationModuleOwnership(NamedDecl *New, NamedDecl *Old);
3347 
3348  void DiagnoseAmbiguousLookup(LookupResult &Result);
3349  //@}
3350 
3351  ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id,
3352  SourceLocation IdLoc,
3353  bool TypoCorrection = false);
3354  NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
3355  Scope *S, bool ForRedeclaration,
3356  SourceLocation Loc);
3357  NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
3358  Scope *S);
3359  void AddKnownFunctionAttributes(FunctionDecl *FD);
3360 
3361  // More parsing and symbol table subroutines.
3362 
3363  void ProcessPragmaWeak(Scope *S, Decl *D);
3364  // Decl attributes - this routine is the top level dispatcher.
3365  void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD);
3366  // Helper for delayed processing of attributes.
3367  void ProcessDeclAttributeDelayed(Decl *D,
3368  const ParsedAttributesView &AttrList);
3369  void ProcessDeclAttributeList(Scope *S, Decl *D, const ParsedAttributesView &AL,
3370  bool IncludeCXX11Attributes = true);
3371  bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl,
3372  const ParsedAttributesView &AttrList);
3373 
3374  void checkUnusedDeclAttributes(Declarator &D);
3375 
3376  /// Determine if type T is a valid subject for a nonnull and similar
3377  /// attributes. By default, we look through references (the behavior used by
3378  /// nonnull), but if the second parameter is true, then we treat a reference
3379  /// type as valid.
3380  bool isValidPointerAttrType(QualType T, bool RefOkay = false);
3381 
3382  bool CheckRegparmAttr(const ParsedAttr &attr, unsigned &value);
3383  bool CheckCallingConvAttr(const ParsedAttr &attr, CallingConv &CC,
3384  const FunctionDecl *FD = nullptr);
3385  bool CheckAttrTarget(const ParsedAttr &CurrAttr);
3386  bool CheckAttrNoArgs(const ParsedAttr &CurrAttr);
3387  bool checkStringLiteralArgumentAttr(const ParsedAttr &Attr, unsigned ArgNum,
3388  StringRef &Str,
3389  SourceLocation *ArgLocation = nullptr);
3390  bool checkSectionName(SourceLocation LiteralLoc, StringRef Str);
3391  bool checkTargetAttr(SourceLocation LiteralLoc, StringRef Str);
3392  bool checkMSInheritanceAttrOnDefinition(
3393  CXXRecordDecl *RD, SourceRange Range, bool BestCase,
3394  MSInheritanceAttr::Spelling SemanticSpelling);
3395 
3396  void CheckAlignasUnderalignment(Decl *D);
3397 
3398  /// Adjust the calling convention of a method to be the ABI default if it
3399  /// wasn't specified explicitly. This handles method types formed from
3400  /// function type typedefs and typename template arguments.
3401  void adjustMemberFunctionCC(QualType &T, bool IsStatic, bool IsCtorOrDtor,
3402  SourceLocation Loc);
3403 
3404  // Check if there is an explicit attribute, but only look through parens.
3405  // The intent is to look for an attribute on the current declarator, but not
3406  // one that came from a typedef.
3407  bool hasExplicitCallingConv(QualType &T);
3408 
3409  /// Get the outermost AttributedType node that sets a calling convention.
3410  /// Valid types should not have multiple attributes with different CCs.
3411  const AttributedType *getCallingConvAttributedType(QualType T) const;
3412 
3413  /// Stmt attributes - this routine is the top level dispatcher.
3414  StmtResult ProcessStmtAttributes(Stmt *Stmt,
3415  const ParsedAttributesView &Attrs,
3416  SourceRange Range);
3417 
3418  void WarnConflictingTypedMethods(ObjCMethodDecl *Method,
3419  ObjCMethodDecl *MethodDecl,
3420  bool IsProtocolMethodDecl);
3421 
3422  void CheckConflictingOverridingMethod(ObjCMethodDecl *Method,
3423  ObjCMethodDecl *Overridden,
3424  bool IsProtocolMethodDecl);
3425 
3426  /// WarnExactTypedMethods - This routine issues a warning if method
3427  /// implementation declaration matches exactly that of its declaration.
3428  void WarnExactTypedMethods(ObjCMethodDecl *Method,
3429  ObjCMethodDecl *MethodDecl,
3430  bool IsProtocolMethodDecl);
3431 
3432  typedef llvm::SmallPtrSet<Selector, 8> SelectorSet;
3433 
3434  /// CheckImplementationIvars - This routine checks if the instance variables
3435  /// listed in the implelementation match those listed in the interface.
3436  void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
3437  ObjCIvarDecl **Fields, unsigned nIvars,
3438  SourceLocation Loc);
3439 
3440  /// ImplMethodsVsClassMethods - This is main routine to warn if any method
3441  /// remains unimplemented in the class or category \@implementation.
3442  void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl,
3443  ObjCContainerDecl* IDecl,
3444  bool IncompleteImpl = false);
3445 
3446  /// DiagnoseUnimplementedProperties - This routine warns on those properties
3447  /// which must be implemented by this implementation.
3448  void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl,
3449  ObjCContainerDecl *CDecl,
3450  bool SynthesizeProperties);
3451 
3452  /// Diagnose any null-resettable synthesized setters.
3453  void diagnoseNullResettableSynthesizedSetters(const ObjCImplDecl *impDecl);
3454 
3455  /// DefaultSynthesizeProperties - This routine default synthesizes all
3456  /// properties which must be synthesized in the class's \@implementation.
3457  void DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl,
3458  ObjCInterfaceDecl *IDecl,
3459  SourceLocation AtEnd);
3460  void DefaultSynthesizeProperties(Scope *S, Decl *D, SourceLocation AtEnd);
3461 
3462  /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is
3463  /// an ivar synthesized for 'Method' and 'Method' is a property accessor
3464  /// declared in class 'IFace'.
3465  bool IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace,
3466  ObjCMethodDecl *Method, ObjCIvarDecl *IV);
3467 
3468  /// DiagnoseUnusedBackingIvarInAccessor - Issue an 'unused' warning if ivar which
3469  /// backs the property is not used in the property's accessor.
3470  void DiagnoseUnusedBackingIvarInAccessor(Scope *S,
3471  const ObjCImplementationDecl *ImplD);
3472 
3473  /// GetIvarBackingPropertyAccessor - If method is a property setter/getter and
3474  /// it property has a backing ivar, returns this ivar; otherwise, returns NULL.
3475  /// It also returns ivar's property on success.
3476  ObjCIvarDecl *GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method,
3477  const ObjCPropertyDecl *&PDecl) const;
3478 
3479  /// Called by ActOnProperty to handle \@property declarations in
3480  /// class extensions.
3481  ObjCPropertyDecl *HandlePropertyInClassExtension(Scope *S,
3482  SourceLocation AtLoc,
3483  SourceLocation LParenLoc,
3484  FieldDeclarator &FD,
3485  Selector GetterSel,
3486  SourceLocation GetterNameLoc,
3487  Selector SetterSel,
3488  SourceLocation SetterNameLoc,
3489  const bool isReadWrite,
3490  unsigned &Attributes,
3491  const unsigned AttributesAsWritten,
3492  QualType T,
3493  TypeSourceInfo *TSI,
3494  tok::ObjCKeywordKind MethodImplKind);
3495 
3496  /// Called by ActOnProperty and HandlePropertyInClassExtension to
3497  /// handle creating the ObjcPropertyDecl for a category or \@interface.
3498  ObjCPropertyDecl *CreatePropertyDecl(Scope *S,
3499  ObjCContainerDecl *CDecl,
3500  SourceLocation AtLoc,
3501  SourceLocation LParenLoc,
3502  FieldDeclarator &FD,
3503  Selector GetterSel,
3504  SourceLocation GetterNameLoc,
3505  Selector SetterSel,
3506  SourceLocation SetterNameLoc,
3507  const bool isReadWrite,
3508  const unsigned Attributes,
3509  const unsigned AttributesAsWritten,
3510  QualType T,
3511  TypeSourceInfo *TSI,
3512  tok::ObjCKeywordKind MethodImplKind,
3513  DeclContext *lexicalDC = nullptr);
3514 
3515  /// AtomicPropertySetterGetterRules - This routine enforces the rule (via
3516  /// warning) when atomic property has one but not the other user-declared
3517  /// setter or getter.
3518  void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl,
3519  ObjCInterfaceDecl* IDecl);
3520 
3521  void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D);
3522 
3523  void DiagnoseMissingDesignatedInitOverrides(
3524  const ObjCImplementationDecl *ImplD,
3525  const ObjCInterfaceDecl *IFD);
3526 
3527  void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID);
3528 
3531  MMS_strict
3532  };
3533 
3534  /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
3535  /// true, or false, accordingly.
3536  bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
3537  const ObjCMethodDecl *PrevMethod,
3538  MethodMatchStrategy strategy = MMS_strict);
3539 
3540  /// MatchAllMethodDeclarations - Check methods declaraed in interface or
3541  /// or protocol against those declared in their implementations.
3542  void MatchAllMethodDeclarations(const SelectorSet &InsMap,
3543  const SelectorSet &ClsMap,
3544  SelectorSet &InsMapSeen,
3545  SelectorSet &ClsMapSeen,
3546  ObjCImplDecl* IMPDecl,
3547  ObjCContainerDecl* IDecl,
3548  bool &IncompleteImpl,
3549  bool ImmediateClass,
3550  bool WarnCategoryMethodImpl=false);
3551 
3552  /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in
3553  /// category matches with those implemented in its primary class and
3554  /// warns each time an exact match is found.
3555  void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP);
3556 
3557  /// Add the given method to the list of globally-known methods.
3558  void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method);
3559 
3560 private:
3561  /// AddMethodToGlobalPool - Add an instance or factory method to the global
3562  /// pool. See descriptoin of AddInstanceMethodToGlobalPool.
3563  void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance);
3564 
3565  /// LookupMethodInGlobalPool - Returns the instance or factory method and
3566  /// optionally warns if there are multiple signatures.
3567  ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R,
3568  bool receiverIdOrClass,
3569  bool instance);
3570 
3571 public:
3572  /// - Returns instance or factory methods in global method pool for
3573  /// given selector. It checks the desired kind first, if none is found, and
3574  /// parameter checkTheOther is set, it then checks the other kind. If no such
3575  /// method or only one method is found, function returns false; otherwise, it
3576  /// returns true.
3577  bool
3578  CollectMultipleMethodsInGlobalPool(Selector Sel,
3580  bool InstanceFirst, bool CheckTheOther,
3581  const ObjCObjectType *TypeBound = nullptr);
3582 
3583  bool
3584  AreMultipleMethodsInGlobalPool(Selector Sel, ObjCMethodDecl *BestMethod,
3585  SourceRange R, bool receiverIdOrClass,
3587 
3588  void
3589  DiagnoseMultipleMethodInGlobalPool(SmallVectorImpl<ObjCMethodDecl*> &Methods,
3590  Selector Sel, SourceRange R,
3591  bool receiverIdOrClass);
3592 
3593 private:
3594  /// - Returns a selector which best matches given argument list or
3595  /// nullptr if none could be found
3596  ObjCMethodDecl *SelectBestMethod(Selector Sel, MultiExprArg Args,
3597  bool IsInstance,
3599 
3600 
3601  /// Record the typo correction failure and return an empty correction.
3602  TypoCorrection FailedCorrection(IdentifierInfo *Typo, SourceLocation TypoLoc,
3603  bool RecordFailure = true) {
3604  if (RecordFailure)
3605  TypoCorrectionFailures[Typo].insert(TypoLoc);
3606  return TypoCorrection();
3607  }
3608 
3609 public:
3610  /// AddInstanceMethodToGlobalPool - All instance methods in a translation
3611  /// unit are added to a global pool. This allows us to efficiently associate
3612  /// a selector with a method declaraation for purposes of typechecking
3613  /// messages sent to "id" (where the class of the object is unknown).
3614  void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
3615  AddMethodToGlobalPool(Method, impl, /*instance*/true);
3616  }
3617 
3618  /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
3619  void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
3620  AddMethodToGlobalPool(Method, impl, /*instance*/false);
3621  }
3622 
3623  /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global
3624  /// pool.
3625  void AddAnyMethodToGlobalPool(Decl *D);
3626 
3627  /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
3628  /// there are multiple signatures.
3630  bool receiverIdOrClass=false) {
3631  return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
3632  /*instance*/true);
3633  }
3634 
3635  /// LookupFactoryMethodInGlobalPool - Returns the method and warns if
3636  /// there are multiple signatures.
3638  bool receiverIdOrClass=false) {
3639  return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
3640  /*instance*/false);
3641  }
3642 
3643  const ObjCMethodDecl *SelectorsForTypoCorrection(Selector Sel,
3644  QualType ObjectType=QualType());
3645  /// LookupImplementedMethodInGlobalPool - Returns the method which has an
3646  /// implementation.
3647  ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel);
3648 
3649  /// CollectIvarsToConstructOrDestruct - Collect those ivars which require
3650  /// initialization.
3651  void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI,
3653 
3654  //===--------------------------------------------------------------------===//
3655  // Statement Parsing Callbacks: SemaStmt.cpp.
3656 public:
3657  class FullExprArg {
3658  public:
3659  FullExprArg() : E(nullptr) { }
3660  FullExprArg(Sema &actions) : E(nullptr) { }
3661 
3663  return E;
3664  }
3665 
3666  Expr *get() const { return E; }
3667 
3669  return E;
3670  }
3671 
3672  private:
3673  // FIXME: No need to make the entire Sema class a friend when it's just
3674  // Sema::MakeFullExpr that needs access to the constructor below.
3675  friend class Sema;
3676 
3677  explicit FullExprArg(Expr *expr) : E(expr) {}
3678 
3679  Expr *E;
3680  };
3681 
3683  return MakeFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation());
3684  }
3686  return FullExprArg(ActOnFinishFullExpr(Arg, CC).get());
3687  }
3689  ExprResult FE =
3690  ActOnFinishFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation(),
3691  /*DiscardedValue*/ true);
3692  return FullExprArg(FE.get());
3693  }
3694 
3695  StmtResult ActOnExprStmt(ExprResult Arg);
3696  StmtResult ActOnExprStmtError();
3697 
3698  StmtResult ActOnNullStmt(SourceLocation SemiLoc,
3699  bool HasLeadingEmptyMacro = false);
3700 
3701  void ActOnStartOfCompoundStmt(bool IsStmtExpr);
3702  void ActOnFinishOfCompoundStmt();
3703  StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
3704  ArrayRef<Stmt *> Elts, bool isStmtExpr);
3705 
3706  /// A RAII object to enter scope of a compound statement.
3708  public:
3709  CompoundScopeRAII(Sema &S, bool IsStmtExpr = false) : S(S) {
3710  S.ActOnStartOfCompoundStmt(IsStmtExpr);
3711  }
3712 
3714  S.ActOnFinishOfCompoundStmt();
3715  }
3716 
3717  private:
3718  Sema &S;
3719  };
3720 
3721  /// An RAII helper that pops function a function scope on exit.
3724  bool Active;
3725  FunctionScopeRAII(Sema &S) : S(S), Active(true) {}
3727  if (Active)
3729  }
3730  void disable() { Active = false; }
3731  };
3732 
3733  StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl,
3734  SourceLocation StartLoc,
3735  SourceLocation EndLoc);
3736  void ActOnForEachDeclStmt(DeclGroupPtrTy Decl);
3737  StmtResult ActOnForEachLValueExpr(Expr *E);
3738  ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val);
3739  StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS,
3740  SourceLocation DotDotDotLoc, ExprResult RHS,
3742  void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt);
3743 
3744  StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
3745  SourceLocation ColonLoc,
3746  Stmt *SubStmt, Scope *CurScope);
3747  StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl,
3748  SourceLocation ColonLoc, Stmt *SubStmt);
3749 
3750  StmtResult ActOnAttributedStmt(SourceLocation AttrLoc,
3751  ArrayRef<const Attr*> Attrs,
3752  Stmt *SubStmt);
3753 
3754  class ConditionResult;
3755  StmtResult ActOnIfStmt(SourceLocation IfLoc, bool IsConstexpr,
3756  Stmt *InitStmt,
3757  ConditionResult Cond, Stmt *ThenVal,
3758  SourceLocation ElseLoc, Stmt *ElseVal);
3759  StmtResult BuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
3760  Stmt *InitStmt,
3761  ConditionResult Cond, Stmt *ThenVal,
3762  SourceLocation ElseLoc, Stmt *ElseVal);
3763  StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc,
3764  Stmt *InitStmt,
3765  ConditionResult Cond);
3766  StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
3767  Stmt *Switch, Stmt *Body);
3768  StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ConditionResult Cond,
3769  Stmt *Body);
3770  StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body,
3771  SourceLocation WhileLoc, SourceLocation CondLParen,
3772  Expr *Cond, SourceLocation CondRParen);
3773 
3774  StmtResult ActOnForStmt(SourceLocation ForLoc,
3775  SourceLocation LParenLoc,
3776  Stmt *First,
3777  ConditionResult Second,
3778  FullExprArg Third,
3779  SourceLocation RParenLoc,
3780  Stmt *Body);
3781  ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc,
3782  Expr *collection);
3783  StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
3784  Stmt *First, Expr *collection,
3785  SourceLocation RParenLoc);
3786  StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body);
3787 
3789  /// Initial building of a for-range statement.
3791  /// Instantiation or recovery rebuild of a for-range statement. Don't
3792  /// attempt any typo-correction.
3794  /// Determining whether a for-range statement could be built. Avoid any
3795  /// unnecessary or irreversible actions.
3796  BFRK_Check
3797  };
3798 
3799  StmtResult ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc,
3800  SourceLocation CoawaitLoc,
3801  Stmt *InitStmt,
3802  Stmt *LoopVar,
3803  SourceLocation ColonLoc, Expr *Collection,
3804  SourceLocation RParenLoc,
3806  StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc,
3807  SourceLocation CoawaitLoc,
3808  Stmt *InitStmt,
3809  SourceLocation ColonLoc,
3810  Stmt *RangeDecl, Stmt *Begin, Stmt *End,
3811  Expr *Cond, Expr *Inc,
3812  Stmt *LoopVarDecl,
3813  SourceLocation RParenLoc,
3815  StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body);
3816 
3817  StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
3818  SourceLocation LabelLoc,
3819  LabelDecl *TheDecl);
3820  StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
3821  SourceLocation StarLoc,
3822  Expr *DestExp);
3823  StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope);
3824  StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope);
3825 
3826  void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope,
3827  CapturedRegionKind Kind, unsigned NumParams);
3828  typedef std::pair<StringRef, QualType> CapturedParamNameType;
3829  void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope,
3832  StmtResult ActOnCapturedRegionEnd(Stmt *S);
3833  void ActOnCapturedRegionError();
3834  RecordDecl *CreateCapturedStmtRecordDecl(CapturedDecl *&CD,
3835  SourceLocation Loc,
3836  unsigned NumParams);
3837 
3839  CES_Strict = 0,
3840  CES_AllowParameters = 1,
3841  CES_AllowDifferentTypes = 2,
3842  CES_AllowExceptionVariables = 4,
3843  CES_FormerDefault = (CES_AllowParameters),
3844  CES_Default = (CES_AllowParameters | CES_AllowDifferentTypes),
3845  CES_AsIfByStdMove = (CES_AllowParameters | CES_AllowDifferentTypes |
3846  CES_AllowExceptionVariables),
3847  };
3848 
3849  VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E,
3851  bool isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD,
3853 
3854  StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
3855  Scope *CurScope);
3856  StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
3857  StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
3858 
3859  StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
3860  bool IsVolatile, unsigned NumOutputs,
3861  unsigned NumInputs, IdentifierInfo **Names,
3862  MultiExprArg Constraints, MultiExprArg Exprs,
3863  Expr *AsmString, MultiExprArg Clobbers,
3864  SourceLocation RParenLoc);
3865 
3866  void FillInlineAsmIdentifierInfo(Expr *Res,
3867  llvm::InlineAsmIdentifierInfo &Info);
3868  ExprResult LookupInlineAsmIdentifier(CXXScopeSpec &SS,
3869  SourceLocation TemplateKWLoc,
3870  UnqualifiedId &Id,
3871  bool IsUnevaluatedContext);
3872  bool LookupInlineAsmField(StringRef Base, StringRef Member,
3873  unsigned &Offset, SourceLocation AsmLoc);
3874  ExprResult LookupInlineAsmVarDeclField(Expr *RefExpr, StringRef Member,
3875  SourceLocation AsmLoc);
3876  StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
3877  ArrayRef<Token> AsmToks,
3878  StringRef AsmString,
3879  unsigned NumOutputs, unsigned NumInputs,
3880  ArrayRef<StringRef> Constraints,
3881  ArrayRef<StringRef> Clobbers,
3882  ArrayRef<Expr*> Exprs,
3883  SourceLocation EndLoc);
3884  LabelDecl *GetOrCreateMSAsmLabel(StringRef ExternalLabelName,
3885  SourceLocation Location,
3886  bool AlwaysCreate);
3887 
3888  VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType,
3889  SourceLocation StartLoc,
3890  SourceLocation IdLoc, IdentifierInfo *Id,
3891  bool Invalid = false);
3892 
3893  Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D);
3894 
3895  StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen,
3896  Decl *Parm, Stmt *Body);
3897 
3898  StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body);
3899 
3900  StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try,
3901  MultiStmtArg Catch, Stmt *Finally);
3902 
3903  StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw);
3904  StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw,
3905  Scope *CurScope);
3906  ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc,
3907  Expr *operand);
3908  StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
3909  Expr *SynchExpr,
3910  Stmt *SynchBody);
3911 
3912  StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body);
3913 
3914  VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo,
3915  SourceLocation StartLoc,
3916  SourceLocation IdLoc,
3917  IdentifierInfo *Id);
3918 
3919  Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D);
3920 
3921  StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
3922  Decl *ExDecl, Stmt *HandlerBlock);
3923  StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
3924  ArrayRef<Stmt *> Handlers);
3925 
3926  StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ?
3927  SourceLocation TryLoc, Stmt *TryBlock,
3928  Stmt *Handler);
3929  StmtResult ActOnSEHExceptBlock(SourceLocation Loc,
3930  Expr *FilterExpr,
3931  Stmt *Block);
3932  void ActOnStartSEHFinallyBlock();
3933  void ActOnAbortSEHFinallyBlock();
3934  StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block);
3935  StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope);
3936 
3937  void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock);
3938 
3939  bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const;
3940 
3941  /// If it's a file scoped decl that must warn if not used, keep track
3942  /// of it.
3943  void MarkUnusedFileScopedDecl(const DeclaratorDecl *D);
3944 
3945  /// DiagnoseUnusedExprResult - If the statement passed in is an expression
3946  /// whose result is unused, warn.
3947  void DiagnoseUnusedExprResult(const Stmt *S);
3948  void DiagnoseUnusedNestedTypedefs(const RecordDecl *D);
3949  void DiagnoseUnusedDecl(const NamedDecl *ND);
3950 
3951  /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null
3952  /// statement as a \p Body, and it is located on the same line.
3953  ///
3954  /// This helps prevent bugs due to typos, such as:
3955  /// if (condition);
3956  /// do_stuff();
3957  void DiagnoseEmptyStmtBody(SourceLocation StmtLoc,
3958  const Stmt *Body,
3959  unsigned DiagID);
3960 
3961  /// Warn if a for/while loop statement \p S, which is followed by
3962  /// \p PossibleBody, has a suspicious null statement as a body.
3963  void DiagnoseEmptyLoopBody(const Stmt *S,
3964  const Stmt *PossibleBody);
3965 
3966  /// Warn if a value is moved to itself.
3967  void DiagnoseSelfMove(const Expr *LHSExpr, const Expr *RHSExpr,
3968  SourceLocation OpLoc);
3969 
3970  /// Warn if we're implicitly casting from a _Nullable pointer type to a
3971  /// _Nonnull one.
3972  void diagnoseNullableToNonnullConversion(QualType DstType, QualType SrcType,
3973  SourceLocation Loc);
3974 
3975  /// Warn when implicitly casting 0 to nullptr.
3976  void diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E);
3977 
3979  return DelayedDiagnostics.push(pool);
3980  }
3981  void PopParsingDeclaration(ParsingDeclState state, Decl *decl);
3982 
3983  typedef ProcessingContextState ParsingClassState;
3984  ParsingClassState PushParsingClass() {
3986  }
3987  void PopParsingClass(ParsingClassState state) {
3989  }
3990 
3991  void redelayDiagnostics(sema::DelayedDiagnosticPool &pool);
3992 
3993  void DiagnoseAvailabilityOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
3994  const ObjCInterfaceDecl *UnknownObjCClass,
3995  bool ObjCPropertyAccess,
3996  bool AvoidPartialAvailabilityChecks = false,
3997  ObjCInterfaceDecl *ClassReceiver = nullptr);
3998 
3999  bool makeUnavailableInSystemHeader(SourceLocation loc,
4000  UnavailableAttr::ImplicitReason reason);
4001 
4002  /// Issue any -Wunguarded-availability warnings in \c FD
4003  void DiagnoseUnguardedAvailabilityViolations(Decl *FD);
4004 
4005  //===--------------------------------------------------------------------===//
4006  // Expression Parsing Callbacks: SemaExpr.cpp.
4007 
4008  bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid);
4009  bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
4010  const ObjCInterfaceDecl *UnknownObjCClass = nullptr,
4011  bool ObjCPropertyAccess = false,
4012  bool AvoidPartialAvailabilityChecks = false,
4013  ObjCInterfaceDecl *ClassReciever = nullptr);
4014  void NoteDeletedFunction(FunctionDecl *FD);
4015  void NoteDeletedInheritingConstructor(CXXConstructorDecl *CD);
4016  std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD);
4017  bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
4018  ObjCMethodDecl *Getter,
4019  SourceLocation Loc);
4020  void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
4021  ArrayRef<Expr *> Args);
4022 
4023  void PushExpressionEvaluationContext(
4024  ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl = nullptr,
4026  ExpressionEvaluationContextRecord::EK_Other);
4027  enum ReuseLambdaContextDecl_t { ReuseLambdaContextDecl };
4028  void PushExpressionEvaluationContext(
4031  ExpressionEvaluationContextRecord::EK_Other);
4032  void PopExpressionEvaluationContext();
4033 
4034  void DiscardCleanupsInEvaluationContext();
4035 
4036  ExprResult TransformToPotentiallyEvaluated(Expr *E);
4037  ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
4038 
4039  ExprResult ActOnConstantExpression(ExprResult Res);
4040 
4041  // Functions for marking a declaration referenced. These functions also
4042  // contain the relevant logic for marking if a reference to a function or
4043  // variable is an odr-use (in the C++11 sense). There are separate variants
4044  // for expressions referring to a decl; these exist because odr-use marking
4045  // needs to be delayed for some constant variables when we build one of the
4046  // named expressions.
4047  //
4048  // MightBeOdrUse indicates whether the use could possibly be an odr-use, and
4049  // should usually be true. This only needs to be set to false if the lack of
4050  // odr-use cannot be determined from the current context (for instance,
4051  // because the name denotes a virtual function and was written without an
4052  // explicit nested-name-specifier).
4053  void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse);
4054  void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func,
4055  bool MightBeOdrUse = true);
4056  void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var);
4057  void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base = nullptr);
4058  void MarkMemberReferenced(MemberExpr *E);
4059 
4060  void UpdateMarkingForLValueToRValue(Expr *E);
4061  void CleanupVarDeclMarking();
4062 
4064  TryCapture_Implicit, TryCapture_ExplicitByVal, TryCapture_ExplicitByRef
4065  };
4066 
4067  /// Try to capture the given variable.
4068  ///
4069  /// \param Var The variable to capture.
4070  ///
4071  /// \param Loc The location at which the capture occurs.
4072  ///
4073  /// \param Kind The kind of capture, which may be implicit (for either a
4074  /// block or a lambda), or explicit by-value or by-reference (for a lambda).
4075  ///
4076  /// \param EllipsisLoc The location of the ellipsis, if one is provided in
4077  /// an explicit lambda capture.
4078  ///
4079  /// \param BuildAndDiagnose Whether we are actually supposed to add the
4080  /// captures or diagnose errors. If false, this routine merely check whether
4081  /// the capture can occur without performing the capture itself or complaining
4082  /// if the variable cannot be captured.
4083  ///
4084  /// \param CaptureType Will be set to the type of the field used to capture
4085  /// this variable in the innermost block or lambda. Only valid when the
4086  /// variable can be captured.
4087  ///
4088  /// \param DeclRefType Will be set to the type of a reference to the capture
4089  /// from within the current scope. Only valid when the variable can be
4090  /// captured.
4091  ///
4092  /// \param FunctionScopeIndexToStopAt If non-null, it points to the index
4093  /// of the FunctionScopeInfo stack beyond which we do not attempt to capture.
4094  /// This is useful when enclosing lambdas must speculatively capture
4095  /// variables that may or may not be used in certain specializations of
4096  /// a nested generic lambda.
4097  ///
4098  /// \returns true if an error occurred (i.e., the variable cannot be
4099  /// captured) and false if the capture succeeded.
4100  bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, TryCaptureKind Kind,
4101  SourceLocation EllipsisLoc, bool BuildAndDiagnose,
4102  QualType &CaptureType,
4103  QualType &DeclRefType,
4104  const unsigned *const FunctionScopeIndexToStopAt);
4105 
4106  /// Try to capture the given variable.
4107  bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc,
4108  TryCaptureKind Kind = TryCapture_Implicit,
4109  SourceLocation EllipsisLoc = SourceLocation());
4110 
4111  /// Checks if the variable must be captured.
4112  bool NeedToCaptureVariable(VarDecl *Var, SourceLocation Loc);
4113 
4114  /// Given a variable, determine the type that a reference to that
4115  /// variable will have in the given scope.
4116  QualType getCapturedDeclRefType(VarDecl *Var, SourceLocation Loc);
4117 
4118  /// Mark all of the declarations referenced within a particular AST node as
4119  /// referenced. Used when template instantiation instantiates a non-dependent
4120  /// type -- entities referenced by the type are now referenced.
4121  void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T);
4122  void MarkDeclarationsReferencedInExpr(Expr *E,
4123  bool SkipLocalVariables = false);
4124 
4125  /// Try to recover by turning the given expression into a
4126  /// call. Returns true if recovery was attempted or an error was
4127  /// emitted; this may also leave the ExprResult invalid.
4128  bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD,
4129  bool ForceComplain = false,
4130  bool (*IsPlausibleResult)(QualType) = nullptr);
4131 
4132  /// Figure out if an expression could be turned into a call.
4133  bool tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy,
4134  UnresolvedSetImpl &NonTemplateOverloads);
4135 
4136  /// Conditionally issue a diagnostic based on the current
4137  /// evaluation context.
4138  ///
4139  /// \param Statement If Statement is non-null, delay reporting the
4140  /// diagnostic until the function body is parsed, and then do a basic
4141  /// reachability analysis to determine if the statement is reachable.
4142  /// If it is unreachable, the diagnostic will not be emitted.
4143  bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement,
4144  const PartialDiagnostic &PD);
4145 
4146  // Primary Expressions.
4147  SourceRange getExprRange(Expr *E) const;
4148 
4149  ExprResult ActOnIdExpression(
4150  Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
4151  UnqualifiedId &Id, bool HasTrailingLParen, bool IsAddressOfOperand,
4152  std::unique_ptr<CorrectionCandidateCallback> CCC = nullptr,
4153  bool IsInlineAsmIdentifier = false, Token *KeywordReplacement = nullptr);
4154 
4155  void DecomposeUnqualifiedId(const UnqualifiedId &Id,
4156  TemplateArgumentListInfo &Buffer,
4157  DeclarationNameInfo &NameInfo,
4158  const TemplateArgumentListInfo *&TemplateArgs);
4159 
4160  bool
4161  DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
4162  std::unique_ptr<CorrectionCandidateCallback> CCC,
4163  TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr,
4164  ArrayRef<Expr *> Args = None, TypoExpr **Out = nullptr);
4165 
4166  ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S,
4167  IdentifierInfo *II,
4168  bool AllowBuiltinCreation=false);
4169 
4170  ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS,
4171  SourceLocation TemplateKWLoc,
4172  const DeclarationNameInfo &NameInfo,
4173  bool isAddressOfOperand,
4174  const TemplateArgumentListInfo *TemplateArgs);
4175 
4176  ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
4177  ExprValueKind VK,
4178  SourceLocation Loc,
4179  const CXXScopeSpec *SS = nullptr);
4180  ExprResult
4181  BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK,
4182  const DeclarationNameInfo &NameInfo,
4183  const CXXScopeSpec *SS = nullptr,
4184  NamedDecl *FoundD = nullptr,
4185  const TemplateArgumentListInfo *TemplateArgs = nullptr);
4186  ExprResult
4187  BuildAnonymousStructUnionMemberReference(
4188  const CXXScopeSpec &SS,
4189  SourceLocation nameLoc,
4190  IndirectFieldDecl *indirectField,
4191  DeclAccessPair FoundDecl = DeclAccessPair::make(nullptr, AS_none),
4192  Expr *baseObjectExpr = nullptr,
4193  SourceLocation opLoc = SourceLocation());
4194 
4195  ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
4196  SourceLocation TemplateKWLoc,
4197  LookupResult &R,
4198  const TemplateArgumentListInfo *TemplateArgs,
4199  const Scope *S);
4200  ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS,
4201  SourceLocation TemplateKWLoc,
4202  LookupResult &R,
4203  const TemplateArgumentListInfo *TemplateArgs,
4204  bool IsDefiniteInstance,
4205  const Scope *S);
4206  bool UseArgumentDependentLookup(const CXXScopeSpec &SS,
4207  const LookupResult &R,
4208  bool HasTrailingLParen);
4209 
4210  ExprResult
4211  BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS,
4212  const DeclarationNameInfo &NameInfo,
4213  bool IsAddressOfOperand, const Scope *S,
4214  TypeSourceInfo **RecoveryTSI = nullptr);
4215 
4216  ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
4217  SourceLocation TemplateKWLoc,
4218  const DeclarationNameInfo &NameInfo,
4219  const TemplateArgumentListInfo *TemplateArgs);
4220 
4221  ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
4222  LookupResult &R,
4223  bool NeedsADL,
4224  bool AcceptInvalidDecl = false);
4225  ExprResult BuildDeclarationNameExpr(
4226  const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D,
4227  NamedDecl *FoundD = nullptr,
4228  const TemplateArgumentListInfo *TemplateArgs = nullptr,
4229  bool AcceptInvalidDecl = false);
4230 
4231  ExprResult BuildLiteralOperatorCall(LookupResult &R,
4232  DeclarationNameInfo &SuffixInfo,
4233  ArrayRef<Expr *> Args,
4234  SourceLocation LitEndLoc,
4235  TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr);
4236 
4237  ExprResult BuildPredefinedExpr(SourceLocation Loc,
4239  ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
4240  ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val);
4241 
4242  bool CheckLoopHintExpr(Expr *E, SourceLocation Loc);
4243 
4244  ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr);
4245  ExprResult ActOnCharacterConstant(const Token &Tok,
4246  Scope *UDLScope = nullptr);
4247  ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E);
4248  ExprResult ActOnParenListExpr(SourceLocation L,
4249  SourceLocation R,
4250  MultiExprArg Val);
4251 
4252  /// ActOnStringLiteral - The specified tokens were lexed as pasted string
4253  /// fragments (e.g. "foo" "bar" L"baz").
4254  ExprResult ActOnStringLiteral(ArrayRef<Token> StringToks,
4255  Scope *UDLScope = nullptr);
4256 
4257  ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc,
4258  SourceLocation DefaultLoc,
4259  SourceLocation RParenLoc,
4260  Expr *ControllingExpr,
4261  ArrayRef<ParsedType> ArgTypes,
4262  ArrayRef<Expr *> ArgExprs);
4263  ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc,
4264  SourceLocation DefaultLoc,
4265  SourceLocation RParenLoc,
4266  Expr *ControllingExpr,
4268  ArrayRef<Expr *> Exprs);
4269 
4270  // Binary/Unary Operators. 'Tok' is the token for the operator.
4271  ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc,
4272  Expr *InputExpr);
4273  ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc,
4274  UnaryOperatorKind Opc, Expr *Input);
4275  ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
4276  tok::TokenKind Op, Expr *Input);
4277 
4278  bool isQualifiedMemberAccess(Expr *E);
4279  QualType CheckAddressOfOperand(ExprResult &Operand, SourceLocation OpLoc);
4280 
4281  ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo,
4282  SourceLocation OpLoc,
4283  UnaryExprOrTypeTrait ExprKind,
4284  SourceRange R);
4285  ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc,
4286  UnaryExprOrTypeTrait ExprKind);
4287  ExprResult
4288  ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc,
4289  UnaryExprOrTypeTrait ExprKind,
4290  bool IsType, void *TyOrEx,
4291  SourceRange ArgRange);
4292 
4293  ExprResult CheckPlaceholderExpr(Expr *E);
4294  bool CheckVecStepExpr(Expr *E);
4295 
4296  bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind);
4297  bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc,
4298  SourceRange ExprRange,
4299  UnaryExprOrTypeTrait ExprKind);
4300  ExprResult ActOnSizeofParameterPackExpr(Scope *S,
4301  SourceLocation OpLoc,
4302  IdentifierInfo &Name,
4303  SourceLocation NameLoc,
4304  SourceLocation RParenLoc);
4305  ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
4306  tok::TokenKind Kind, Expr *Input);
4307 
4308  ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc,
4309  Expr *Idx, SourceLocation RLoc);
4310  ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc,
4311  Expr *Idx, SourceLocation RLoc);
4312  ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc,
4313  Expr *LowerBound, SourceLocation ColonLoc,
4314  Expr *Length, SourceLocation RBLoc);
4315 
4316  // This struct is for use by ActOnMemberAccess to allow
4317  // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after
4318  // changing the access operator from a '.' to a '->' (to see if that is the
4319  // change needed to fix an error about an unknown member, e.g. when the class
4320  // defines a custom operator->).
4322  Scope *S;
4325  };
4326 
4327  ExprResult BuildMemberReferenceExpr(
4328  Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow,
4329  CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
4330  NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo,
4331  const TemplateArgumentListInfo *TemplateArgs,
4332  const Scope *S,
4333  ActOnMemberAccessExtraArgs *ExtraArgs = nullptr);
4334 
4335  ExprResult
4336  BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc,
4337  bool IsArrow, const CXXScopeSpec &SS,
4338  SourceLocation TemplateKWLoc,
4339  NamedDecl *FirstQualifierInScope, LookupResult &R,
4340  const TemplateArgumentListInfo *TemplateArgs,
4341  const Scope *S,
4342  bool SuppressQualifierCheck = false,
4343  ActOnMemberAccessExtraArgs *ExtraArgs = nullptr);
4344 
4345  ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow,
4346  SourceLocation OpLoc,
4347  const CXXScopeSpec &SS, FieldDecl *Field,
4348  DeclAccessPair FoundDecl,
4349  const DeclarationNameInfo &MemberNameInfo);
4350 
4351  ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow);
4352 
4353  bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType,
4354  const CXXScopeSpec &SS,
4355  const LookupResult &R);
4356 
4357  ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType,
4358  bool IsArrow, SourceLocation OpLoc,
4359  const CXXScopeSpec &SS,
4360  SourceLocation TemplateKWLoc,
4361  NamedDecl *FirstQualifierInScope,
4362  const DeclarationNameInfo &NameInfo,
4363  const TemplateArgumentListInfo *TemplateArgs);
4364 
4365  ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base,
4366  SourceLocation OpLoc,
4367  tok::TokenKind OpKind,
4368  CXXScopeSpec &SS,
4369  SourceLocation TemplateKWLoc,
4370  UnqualifiedId &Member,
4371  Decl *ObjCImpDecl);
4372 
4373  void ActOnDefaultCtorInitializers(Decl *CDtorDecl);
4374  bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
4375  FunctionDecl *FDecl,
4376  const FunctionProtoType *Proto,
4377  ArrayRef<Expr *> Args,
4378  SourceLocation RParenLoc,
4379  bool ExecConfig = false);
4380  void CheckStaticArrayArgument(SourceLocation CallLoc,
4381  ParmVarDecl *Param,
4382  const Expr *ArgExpr);
4383 
4384  /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
4385  /// This provides the location of the left/right parens and a list of comma
4386  /// locations.
4387  ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc,
4388  MultiExprArg ArgExprs, SourceLocation RParenLoc,
4389  Expr *ExecConfig = nullptr,
4390  bool IsExecConfig = false);
4391  ExprResult
4392  BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, SourceLocation LParenLoc,
4393  ArrayRef<Expr *> Arg, SourceLocation RParenLoc,
4394  Expr *Config = nullptr, bool IsExecConfig = false,
4395  ADLCallKind UsesADL = ADLCallKind::NotADL);
4396 
4397  ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc,
4398  MultiExprArg ExecConfig,
4399  SourceLocation GGGLoc);
4400 
4401  ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc,
4402  Declarator &D, ParsedType &Ty,
4403  SourceLocation RParenLoc, Expr *CastExpr);
4404  ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc,
4405  TypeSourceInfo *Ty,
4406  SourceLocation RParenLoc,
4407  Expr *Op);
4408  CastKind PrepareScalarCast(ExprResult &src, QualType destType);
4409 
4410  /// Build an altivec or OpenCL literal.
4411  ExprResult BuildVectorLiteral(SourceLocation LParenLoc,
4412  SourceLocation RParenLoc, Expr *E,
4413  TypeSourceInfo *TInfo);
4414 
4415  ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME);
4416 
4417  ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
4418  ParsedType Ty,
4419  SourceLocation RParenLoc,
4420  Expr *InitExpr);
4421 
4422  ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc,
4423  TypeSourceInfo *TInfo,
4424  SourceLocation RParenLoc,
4425  Expr *LiteralExpr);
4426 
4427  ExprResult ActOnInitList(SourceLocation LBraceLoc,
4428  MultiExprArg InitArgList,
4429  SourceLocation RBraceLoc);
4430 
4431  ExprResult ActOnDesignatedInitializer(Designation &Desig,
4432  SourceLocation Loc,
4433  bool GNUSyntax,
4434  ExprResult Init);
4435 
4436 private:
4437  static BinaryOperatorKind ConvertTokenKindToBinaryOpcode(tok::TokenKind Kind);
4438 
4439 public:
4440  ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
4441  tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr);
4442  ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc,
4443  BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr);
4444  ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc,
4445  Expr *LHSExpr, Expr *RHSExpr);
4446 
4447  void DiagnoseCommaOperator(const Expr *LHS, SourceLocation Loc);
4448 
4449  /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
4450  /// in the case of a the GNU conditional expr extension.
4451  ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
4452  SourceLocation ColonLoc,
4453  Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr);
4454 
4455  /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
4456  ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
4457  LabelDecl *TheDecl);
4458 
4459  void ActOnStartStmtExpr();
4460  ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt,
4461  SourceLocation RPLoc); // "({..})"
4462  void ActOnStmtExprError();
4463 
4464  // __builtin_offsetof(type, identifier(.identifier|[expr])*)
4467  bool isBrackets; // true if [expr], false if .ident
4468  union {
4471  } U;
4472  };
4473 
4474  /// __builtin_offsetof(type, a.b[123][456].c)
4475  ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc,
4476  TypeSourceInfo *TInfo,
4477  ArrayRef<OffsetOfComponent> Components,
4478  SourceLocation RParenLoc);
4479  ExprResult ActOnBuiltinOffsetOf(Scope *S,
4480  SourceLocation BuiltinLoc,
4482  ParsedType ParsedArgTy,
4483  ArrayRef<OffsetOfComponent> Components,
4484  SourceLocation RParenLoc);
4485 
4486  // __builtin_choose_expr(constExpr, expr1, expr2)
4487  ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
4488  Expr *CondExpr, Expr *LHSExpr,
4489  Expr *RHSExpr, SourceLocation RPLoc);
4490 
4491  // __builtin_va_arg(expr, type)
4492  ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty,
4493  SourceLocation RPLoc);
4494  ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E,
4495  TypeSourceInfo *TInfo, SourceLocation RPLoc);
4496 
4497  // __null
4498  ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
4499 
4500  bool CheckCaseExpression(Expr *E);
4501 
4502  /// Describes the result of an "if-exists" condition check.
4504  /// The symbol exists.
4506 
4507  /// The symbol does not exist.
4509 
4510  /// The name is a dependent name, so the results will differ
4511  /// from one instantiation to the next.
4513 
4514  /// An error occurred.
4515  IER_Error
4516  };
4517 
4519  CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS,
4520  const DeclarationNameInfo &TargetNameInfo);
4521 
4523  CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc,
4524  bool IsIfExists, CXXScopeSpec &SS,
4525  UnqualifiedId &Name);
4526 
4527  StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc,
4528  bool IsIfExists,
4529  NestedNameSpecifierLoc QualifierLoc,
4530  DeclarationNameInfo NameInfo,
4531  Stmt *Nested);
4532  StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc,
4533  bool IsIfExists,
4534  CXXScopeSpec &SS, UnqualifiedId &Name,
4535  Stmt *Nested);
4536 
4537  //===------------------------- "Block" Extension ------------------------===//
4538 
4539  /// ActOnBlockStart - This callback is invoked when a block literal is
4540  /// started.
4541  void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
4542 
4543  /// ActOnBlockArguments - This callback allows processing of block arguments.
4544  /// If there are no arguments, this is still invoked.
4545  void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo,
4546  Scope *CurScope);
4547 
4548  /// ActOnBlockError - If there is an error parsing a block, this callback
4549  /// is invoked to pop the information about the block from the action impl.
4550  void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
4551 
4552  /// ActOnBlockStmtExpr - This is called when the body of a block statement
4553  /// literal was successfully completed. ^(int x){...}
4554  ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body,
4555  Scope *CurScope);
4556 
4557  //===---------------------------- Clang Extensions ----------------------===//
4558 
4559  /// __builtin_convertvector(...)
4560  ExprResult ActOnConvertVectorExpr(Expr *E, ParsedType ParsedDestTy,
4561  SourceLocation BuiltinLoc,
4562  SourceLocation RParenLoc);
4563 
4564  //===---------------------------- OpenCL Features -----------------------===//
4565 
4566  /// __builtin_astype(...)
4567  ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy,
4568  SourceLocation BuiltinLoc,
4569  SourceLocation RParenLoc);
4570 
4571  //===---------------------------- C++ Features --------------------------===//
4572 
4573  // Act on C++ namespaces
4574  Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc,
4575  SourceLocation NamespaceLoc,
4576  SourceLocation IdentLoc, IdentifierInfo *Ident,
4577  SourceLocation LBrace,
4578  const ParsedAttributesView &AttrList,
4580  void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace);
4581 
4582  NamespaceDecl *getStdNamespace() const;
4583  NamespaceDecl *getOrCreateStdNamespace();
4584 
4585  NamespaceDecl *lookupStdExperimentalNamespace();
4586 
4587  CXXRecordDecl *getStdBadAlloc() const;
4588  EnumDecl *getStdAlignValT() const;
4589 
4590 private:
4591  // A cache representing if we've fully checked the various comparison category
4592  // types stored in ASTContext. The bit-index corresponds to the integer value
4593  // of a ComparisonCategoryType enumerator.
4594  llvm::SmallBitVector FullyCheckedComparisonCategories;
4595 
4596  ValueDecl *tryLookupCtorInitMemberDecl(CXXRecordDecl *ClassDecl,
4597  CXXScopeSpec &SS,
4598  ParsedType TemplateTypeTy,
4599  IdentifierInfo *MemberOrBase);
4600 
4601 public:
4602  /// Lookup the specified comparison category types in the standard
4603  /// library, an check the VarDecls possibly returned by the operator<=>
4604  /// builtins for that type.
4605  ///
4606  /// \return The type of the comparison category type corresponding to the
4607  /// specified Kind, or a null type if an error occurs
4608  QualType CheckComparisonCategoryType(ComparisonCategoryType Kind,
4609  SourceLocation Loc);
4610 
4611  /// Tests whether Ty is an instance of std::initializer_list and, if
4612  /// it is and Element is not NULL, assigns the element type to Element.
4613  bool isStdInitializerList(QualType Ty, QualType *Element);
4614 
4615  /// Looks for the std::initializer_list template and instantiates it
4616  /// with Element, or emits an error if it's not found.
4617  ///
4618  /// \returns The instantiated template, or null on error.
4619  QualType BuildStdInitializerList(QualType Element, SourceLocation Loc);
4620 
4621  /// Determine whether Ctor is an initializer-list constructor, as
4622  /// defined in [dcl.init.list]p2.
4623  bool isInitListConstructor(const FunctionDecl *Ctor);
4624 
4625  Decl *ActOnUsingDirective(Scope *CurScope, SourceLocation UsingLoc,
4626  SourceLocation NamespcLoc, CXXScopeSpec &SS,
4627  SourceLocation IdentLoc,
4628  IdentifierInfo *NamespcName,
4629  const ParsedAttributesView &AttrList);
4630 
4631  void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
4632 
4633  Decl *ActOnNamespaceAliasDef(Scope *CurScope,
4634  SourceLocation NamespaceLoc,
4635  SourceLocation AliasLoc,
4636  IdentifierInfo *Alias,
4637  CXXScopeSpec &SS,
4638  SourceLocation IdentLoc,
4639  IdentifierInfo *Ident);
4640 
4641  void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow);
4642  bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target,
4643  const LookupResult &PreviousDecls,
4644  UsingShadowDecl *&PrevShadow);
4645  UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD,
4646  NamedDecl *Target,
4647  UsingShadowDecl *PrevDecl);
4648 
4649  bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc,
4650  bool HasTypenameKeyword,
4651  const CXXScopeSpec &SS,
4652  SourceLocation NameLoc,
4653  const LookupResult &Previous);
4654  bool CheckUsingDeclQualifier(SourceLocation UsingLoc,
4655  bool HasTypename,
4656  const CXXScopeSpec &SS,
4657  const DeclarationNameInfo &NameInfo,
4658  SourceLocation NameLoc);
4659 
4660  NamedDecl *BuildUsingDeclaration(
4661  Scope *S, AccessSpecifier AS, SourceLocation UsingLoc,
4662  bool HasTypenameKeyword, SourceLocation TypenameLoc, CXXScopeSpec &SS,
4663  DeclarationNameInfo NameInfo, SourceLocation EllipsisLoc,
4664  const ParsedAttributesView &AttrList, bool IsInstantiation);
4665  NamedDecl *BuildUsingPackDecl(NamedDecl *InstantiatedFrom,
4666  ArrayRef<NamedDecl *> Expansions);
4667 
4668  bool CheckInheritingConstructorUsingDecl(UsingDecl *UD);
4669 
4670  /// Given a derived-class using shadow declaration for a constructor and the
4671  /// correspnding base class constructor, find or create the implicit
4672  /// synthesized derived class constructor to use for this initialization.
4673  CXXConstructorDecl *
4674  findInheritingConstructor(SourceLocation Loc, CXXConstructorDecl *BaseCtor,
4675  ConstructorUsingShadowDecl *DerivedShadow);
4676 
4677  Decl *ActOnUsingDeclaration(Scope *CurScope, AccessSpecifier AS,
4678  SourceLocation UsingLoc,
4679  SourceLocation TypenameLoc, CXXScopeSpec &SS,
4680  UnqualifiedId &Name, SourceLocation EllipsisLoc,
4681  const ParsedAttributesView &AttrList);
4682  Decl *ActOnAliasDeclaration(Scope *CurScope, AccessSpecifier AS,
4683  MultiTemplateParamsArg TemplateParams,
4684  SourceLocation UsingLoc, UnqualifiedId &Name,
4685  const ParsedAttributesView &AttrList,
4686  TypeResult Type, Decl *DeclFromDeclSpec);
4687 
4688  /// BuildCXXConstructExpr - Creates a complete call to a constructor,
4689  /// including handling of its default argument expressions.
4690  ///
4691  /// \param ConstructKind - a CXXConstructExpr::ConstructionKind
4692  ExprResult
4693  BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
4694  NamedDecl *FoundDecl,
4695  CXXConstructorDecl *Constructor, MultiExprArg Exprs,
4696  bool HadMultipleCandidates, bool IsListInitialization,
4697  bool IsStdInitListInitialization,
4698  bool RequiresZeroInit, unsigned ConstructKind,
4699  SourceRange ParenRange);
4700 
4701  /// Build a CXXConstructExpr whose constructor has already been resolved if
4702  /// it denotes an inherited constructor.
4703  ExprResult
4704  BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
4705  CXXConstructorDecl *Constructor, bool Elidable,
4706  MultiExprArg Exprs,
4707  bool HadMultipleCandidates, bool IsListInitialization,
4708  bool IsStdInitListInitialization,
4709  bool RequiresZeroInit, unsigned ConstructKind,
4710  SourceRange ParenRange);
4711 
4712  // FIXME: Can we remove this and have the above BuildCXXConstructExpr check if
4713  // the constructor can be elidable?
4714  ExprResult
4715  BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
4716  NamedDecl *FoundDecl,
4717  CXXConstructorDecl *Constructor, bool Elidable,
4718  MultiExprArg Exprs, bool HadMultipleCandidates,
4719  bool IsListInitialization,
4720  bool IsStdInitListInitialization, bool RequiresZeroInit,
4721  unsigned ConstructKind, SourceRange ParenRange);
4722 
4723  ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field);
4724 
4725 
4726  /// Instantiate or parse a C++ default argument expression as necessary.
4727  /// Return true on error.
4728  bool CheckCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD,
4729  ParmVarDecl *Param);
4730 
4731  /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating
4732  /// the default expr if needed.
4733  ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc,
4734  FunctionDecl *FD,
4735  ParmVarDecl *Param);
4736 
4737  /// FinalizeVarWithDestructor - Prepare for calling destructor on the
4738  /// constructed variable.
4739  void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType);
4740 
4741  /// Helper class that collects exception specifications for
4742  /// implicitly-declared special member functions.
4744  // Pointer to allow copying
4745  Sema *Self;
4746  // We order exception specifications thus:
4747  // noexcept is the most restrictive, but is only used in C++11.
4748  // throw() comes next.
4749  // Then a throw(collected exceptions)
4750  // Finally no specification, which is expressed as noexcept(false).
4751  // throw(...) is used instead if any called function uses it.
4752  ExceptionSpecificationType ComputedEST;
4753  llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen;
4754  SmallVector<QualType, 4> Exceptions;
4755 
4756  void ClearExceptions() {
4757  ExceptionsSeen.clear();
4758  Exceptions.clear();
4759  }
4760 
4761  public:
4763  : Self(&Self), ComputedEST(EST_BasicNoexcept) {
4764  if (!Self.getLangOpts().CPlusPlus11)
4765  ComputedEST = EST_DynamicNone;
4766  }
4767 
4768  /// Get the computed exception specification type.
4770  assert(!isComputedNoexcept(ComputedEST) &&
4771  "noexcept(expr) should not be a possible result");
4772  return ComputedEST;
4773  }
4774 
4775  /// The number of exceptions in the exception specification.
4776  unsigned size() const { return Exceptions.size(); }
4777 
4778  /// The set of exceptions in the exception specification.
4779  const QualType *data() const { return Exceptions.data(); }
4780 
4781  /// Integrate another called method into the collected data.
4782  void CalledDecl(SourceLocation CallLoc, const CXXMethodDecl *Method);
4783 
4784  /// Integrate an invoked expression into the collected data.
4785  void CalledExpr(Expr *E);
4786 
4787  /// Overwrite an EPI's exception specification with this
4788  /// computed exception specification.
4791  ESI.Type = getExceptionSpecType();
4792  if (ESI.Type == EST_Dynamic) {
4793  ESI.Exceptions = Exceptions;
4794  } else if (ESI.Type == EST_None) {
4795  /// C++11 [except.spec]p14:
4796  /// The exception-specification is noexcept(false) if the set of
4797  /// potential exceptions of the special member function contains "any"
4798  ESI.Type = EST_NoexceptFalse;
4800  tok::kw_false).get();
4801  }
4802  return ESI;
4803  }
4804  };
4805 
4806  /// Determine what sort of exception specification a defaulted
4807  /// copy constructor of a class will have.
4809  ComputeDefaultedDefaultCtorExceptionSpec(SourceLocation Loc,
4810  CXXMethodDecl *MD);
4811 
4812  /// Determine what sort of exception specification a defaulted
4813  /// default constructor of a class will have, and whether the parameter
4814  /// will be const.
4816  ComputeDefaultedCopyCtorExceptionSpec(CXXMethodDecl *MD);
4817 
4818  /// Determine what sort of exception specification a defautled
4819  /// copy assignment operator of a class will have, and whether the
4820  /// parameter will be const.
4822  ComputeDefaultedCopyAssignmentExceptionSpec(CXXMethodDecl *MD);
4823 
4824  /// Determine what sort of exception specification a defaulted move
4825  /// constructor of a class will have.
4827  ComputeDefaultedMoveCtorExceptionSpec(CXXMethodDecl *MD);
4828 
4829  /// Determine what sort of exception specification a defaulted move
4830  /// assignment operator of a class will have.
4832  ComputeDefaultedMoveAssignmentExceptionSpec(CXXMethodDecl *MD);
4833 
4834  /// Determine what sort of exception specification a defaulted
4835  /// destructor of a class will have.
4837  ComputeDefaultedDtorExceptionSpec(CXXMethodDecl *MD);
4838 
4839  /// Determine what sort of exception specification an inheriting
4840  /// constructor of a class will have.
4842  ComputeInheritingCtorExceptionSpec(SourceLocation Loc,
4843  CXXConstructorDecl *CD);
4844 
4845  /// Evaluate the implicit exception specification for a defaulted
4846  /// special member function.
4847  void EvaluateImplicitExceptionSpec(SourceLocation Loc, CXXMethodDecl *MD);
4848 
4849  /// Check the given noexcept-specifier, convert its expression, and compute
4850  /// the appropriate ExceptionSpecificationType.
4851  ExprResult ActOnNoexceptSpec(SourceLocation NoexceptLoc, Expr *NoexceptExpr,
4853 
4854  /// Check the given exception-specification and update the
4855  /// exception specification information with the results.
4856  void checkExceptionSpecification(bool IsTopLevel,
4858  ArrayRef<ParsedType> DynamicExceptions,
4859  ArrayRef<SourceRange> DynamicExceptionRanges,
4860  Expr *NoexceptExpr,
4861  SmallVectorImpl<QualType> &Exceptions,
4863 
4864  /// Determine if we're in a case where we need to (incorrectly) eagerly
4865  /// parse an exception specification to work around a libstdc++ bug.
4866  bool isLibstdcxxEagerExceptionSpecHack(const Declarator &D);
4867 
4868  /// Add an exception-specification to the given member function
4869  /// (or member function template). The exception-specification was parsed
4870  /// after the method itself was declared.
4871  void actOnDelayedExceptionSpecification(Decl *Method,
4873  SourceRange SpecificationRange,
4874  ArrayRef<ParsedType> DynamicExceptions,
4875  ArrayRef<SourceRange> DynamicExceptionRanges,
4876  Expr *NoexceptExpr);
4877 
4879 
4880  /// Determine if a special member function should have a deleted
4881  /// definition when it is defaulted.
4882  bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM,
4883  InheritedConstructorInfo *ICI = nullptr,
4884  bool Diagnose = false);
4885 
4886  /// Declare the implicit default constructor for the given class.
4887  ///
4888  /// \param ClassDecl The class declaration into which the implicit
4889  /// default constructor will be added.
4890  ///
4891  /// \returns The implicitly-declared default constructor.
4892  CXXConstructorDecl *DeclareImplicitDefaultConstructor(
4893  CXXRecordDecl *ClassDecl);
4894 
4895  /// DefineImplicitDefaultConstructor - Checks for feasibility of
4896  /// defining this constructor as the default constructor.
4897  void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
4898  CXXConstructorDecl *Constructor);
4899 
4900  /// Declare the implicit destructor for the given class.
4901  ///
4902  /// \param ClassDecl The class declaration into which the implicit
4903  /// destructor will be added.
4904  ///
4905  /// \returns The implicitly-declared destructor.
4906  CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl);
4907 
4908  /// DefineImplicitDestructor - Checks for feasibility of
4909  /// defining this destructor as the default destructor.
4910  void DefineImplicitDestructor(SourceLocation CurrentLocation,
4911  CXXDestructorDecl *Destructor);
4912 
4913  /// Build an exception spec for destructors that don't have one.
4914  ///
4915  /// C++11 says that user-defined destructors with no exception spec get one
4916  /// that looks as if the destructor was implicitly declared.
4917  void AdjustDestructorExceptionSpec(CXXDestructorDecl *Destructor);
4918 
4919  /// Define the specified inheriting constructor.
4920  void DefineInheritingConstructor(SourceLocation UseLoc,
4921  CXXConstructorDecl *Constructor);
4922 
4923  /// Declare the implicit copy constructor for the given class.
4924  ///
4925  /// \param ClassDecl The class declaration into which the implicit
4926  /// copy constructor will be added.
4927  ///
4928  /// \returns The implicitly-declared copy constructor.
4929  CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl);
4930 
4931  /// DefineImplicitCopyConstructor - Checks for feasibility of
4932  /// defining this constructor as the copy constructor.
4933  void DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
4934  CXXConstructorDecl *Constructor);
4935 
4936  /// Declare the implicit move constructor for the given class.
4937  ///
4938  /// \param ClassDecl The Class declaration into which the implicit
4939  /// move constructor will be added.
4940  ///
4941  /// \returns The implicitly-declared move constructor, or NULL if it wasn't
4942  /// declared.
4943  CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl);
4944 
4945  /// DefineImplicitMoveConstructor - Checks for feasibility of
4946  /// defining this constructor as the move constructor.
4947  void DefineImplicitMoveConstructor(SourceLocation CurrentLocation,
4948  CXXConstructorDecl *Constructor);
4949 
4950  /// Declare the implicit copy assignment operator for the given class.
4951  ///
4952  /// \param ClassDecl The class declaration into which the implicit
4953  /// copy assignment operator will be added.
4954  ///
4955  /// \returns The implicitly-declared copy assignment operator.
4956  CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl);
4957 
4958  /// Defines an implicitly-declared copy assignment operator.
4959  void DefineImplicitCopyAssignment(SourceLocation CurrentLocation,
4960  CXXMethodDecl *MethodDecl);
4961 
4962  /// Declare the implicit move assignment operator for the given class.
4963  ///
4964  /// \param ClassDecl The Class declaration into which the implicit
4965  /// move assignment operator will be added.
4966  ///
4967  /// \returns The implicitly-declared move assignment operator, or NULL if it
4968  /// wasn't declared.
4969  CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl);
4970 
4971  /// Defines an implicitly-declared move assignment operator.
4972  void DefineImplicitMoveAssignment(SourceLocation CurrentLocation,
4973  CXXMethodDecl *MethodDecl);
4974 
4975  /// Force the declaration of any implicitly-declared members of this
4976  /// class.
4977  void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class);
4978 
4979  /// Check a completed declaration of an implicit special member.
4980  void CheckImplicitSpecialMemberDeclaration(Scope *S, FunctionDecl *FD);
4981 
4982  /// Determine whether the given function is an implicitly-deleted
4983  /// special member function.
4984  bool isImplicitlyDeleted(FunctionDecl *FD);
4985 
4986  /// Check whether 'this' shows up in the type of a static member
4987  /// function after the (naturally empty) cv-qualifier-seq would be.
4988  ///
4989  /// \returns true if an error occurred.
4990  bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method);
4991 
4992  /// Whether this' shows up in the exception specification of a static
4993  /// member function.
4994  bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method);
4995 
4996  /// Check whether 'this' shows up in the attributes of the given
4997  /// static member function.
4998  ///
4999  /// \returns true if an error occurred.
5000  bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method);
5001 
5002  /// MaybeBindToTemporary - If the passed in expression has a record type with
5003  /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise
5004  /// it simply returns the passed in expression.
5005  ExprResult MaybeBindToTemporary(Expr *E);
5006 
5007  bool CompleteConstructorCall(CXXConstructorDecl *Constructor,
5008  MultiExprArg ArgsPtr,
5009  SourceLocation Loc,
5010  SmallVectorImpl<Expr*> &ConvertedArgs,
5011  bool AllowExplicit = false,
5012  bool IsListInitialization = false);
5013 
5014  ParsedType getInheritingConstructorName(CXXScopeSpec &SS,
5015  SourceLocation NameLoc,
5016  IdentifierInfo &Name);
5017 
5018  ParsedType getConstructorName(IdentifierInfo &II, SourceLocation NameLoc,
5019  Scope *S, CXXScopeSpec &SS,
5020  bool EnteringContext);
5021  ParsedType getDestructorName(SourceLocation TildeLoc,
5022  IdentifierInfo &II, SourceLocation NameLoc,
5023  Scope *S, CXXScopeSpec &SS,
5024  ParsedType ObjectType,
5025  bool EnteringContext);
5026 
5027  ParsedType getDestructorTypeForDecltype(const DeclSpec &DS,
5028  ParsedType ObjectType);
5029 
5030  // Checks that reinterpret casts don't have undefined behavior.
5031  void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType,
5032  bool IsDereference, SourceRange Range);
5033 
5034  /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
5035  ExprResult ActOnCXXNamedCast(SourceLocation OpLoc,
5037  SourceLocation LAngleBracketLoc,
5038  Declarator &D,
5039  SourceLocation RAngleBracketLoc,
5040  SourceLocation LParenLoc,
5041  Expr *E,
5042  SourceLocation RParenLoc);
5043 
5044  ExprResult BuildCXXNamedCast(SourceLocation OpLoc,
5045  tok::TokenKind Kind,
5046  TypeSourceInfo *Ty,
5047  Expr *E,
5048  SourceRange AngleBrackets,
5049  SourceRange Parens);
5050 
5051  ExprResult BuildCXXTypeId(QualType TypeInfoType,
5052  SourceLocation TypeidLoc,
5053  TypeSourceInfo *Operand,
5054  SourceLocation RParenLoc);
5055  ExprResult BuildCXXTypeId(QualType TypeInfoType,
5056  SourceLocation TypeidLoc,
5057  Expr *Operand,
5058  SourceLocation RParenLoc);
5059 
5060  /// ActOnCXXTypeid - Parse typeid( something ).
5061  ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
5062  SourceLocation LParenLoc, bool isType,
5063  void *TyOrExpr,
5064  SourceLocation RParenLoc);
5065 
5066  ExprResult BuildCXXUuidof(QualType TypeInfoType,
5067  SourceLocation TypeidLoc,
5068  TypeSourceInfo *Operand,
5069  SourceLocation RParenLoc);
5070  ExprResult BuildCXXUuidof(QualType TypeInfoType,
5071  SourceLocation TypeidLoc,
5072  Expr *Operand,
5073  SourceLocation RParenLoc);
5074 
5075  /// ActOnCXXUuidof - Parse __uuidof( something ).
5076  ExprResult ActOnCXXUuidof(SourceLocation OpLoc,
5077  SourceLocation LParenLoc, bool isType,
5078  void *TyOrExpr,
5079  SourceLocation RParenLoc);
5080 
5081  /// Handle a C++1z fold-expression: ( expr op ... op expr ).
5082  ExprResult ActOnCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
5083  tok::TokenKind Operator,
5084  SourceLocation EllipsisLoc, Expr *RHS,
5085  SourceLocation RParenLoc);
5086  ExprResult BuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
5087  BinaryOperatorKind Operator,
5088  SourceLocation EllipsisLoc, Expr *RHS,
5089  SourceLocation RParenLoc);
5090  ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
5091  BinaryOperatorKind Operator);
5092 
5093  //// ActOnCXXThis - Parse 'this' pointer.
5094  ExprResult ActOnCXXThis(SourceLocation loc);
5095 
5096  /// Try to retrieve the type of the 'this' pointer.
5097  ///
5098  /// \returns The type of 'this', if possible. Otherwise, returns a NULL type.
5099  QualType getCurrentThisType();
5100 
5101  /// When non-NULL, the C++ 'this' expression is allowed despite the
5102  /// current context not being a non-static member function. In such cases,
5103  /// this provides the type used for 'this'.
5105 
5106  /// RAII object used to temporarily allow the C++ 'this' expression
5107  /// to be used, with the given qualifiers on the current class type.
5109  Sema &S;
5110  QualType OldCXXThisTypeOverride;
5111  bool Enabled;
5112 
5113  public:
5114  /// Introduce a new scope where 'this' may be allowed (when enabled),
5115  /// using the given declaration (which is either a class template or a
5116  /// class) along with the given qualifiers.
5117  /// along with the qualifiers placed on '*this'.
5118  CXXThisScopeRAII(Sema &S, Decl *ContextDecl, Qualifiers CXXThisTypeQuals,
5119  bool Enabled = true);
5120 
5121  ~CXXThisScopeRAII();
5122  };
5123 
5124  /// Make sure the value of 'this' is actually available in the current
5125  /// context, if it is a potentially evaluated context.
5126  ///
5127  /// \param Loc The location at which the capture of 'this' occurs.
5128  ///
5129  /// \param Explicit Whether 'this' is explicitly captured in a lambda
5130  /// capture list.
5131  ///
5132  /// \param FunctionScopeIndexToStopAt If non-null, it points to the index
5133  /// of the FunctionScopeInfo stack beyond which we do not attempt to capture.
5134  /// This is useful when enclosing lambdas must speculatively capture
5135  /// 'this' that may or may not be used in certain specializations of
5136  /// a nested generic lambda (depending on whether the name resolves to
5137  /// a non-static member function or a static function).
5138  /// \return returns 'true' if failed, 'false' if success.
5139  bool CheckCXXThisCapture(SourceLocation Loc, bool Explicit = false,
5140  bool BuildAndDiagnose = true,
5141  const unsigned *const FunctionScopeIndexToStopAt = nullptr,
5142  bool ByCopy = false);
5143 
5144  /// Determine whether the given type is the type of *this that is used
5145  /// outside of the body of a member function for a type that is currently
5146  /// being defined.
5147  bool isThisOutsideMemberFunctionBody(QualType BaseType);
5148 
5149  /// ActOnCXXBoolLiteral - Parse {true,false} literals.
5150  ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
5151 
5152 
5153  /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals.
5154  ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
5155 
5156  ExprResult
5157  ActOnObjCAvailabilityCheckExpr(llvm::ArrayRef<AvailabilitySpec> AvailSpecs,
5158  SourceLocation AtLoc, SourceLocation RParen);
5159 
5160  /// ActOnCXXNullPtrLiteral - Parse 'nullptr'.
5161  ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc);
5162 
5163  //// ActOnCXXThrow - Parse throw expressions.
5164  ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr);
5165  ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex,
5166  bool IsThrownVarInScope);
5167  bool CheckCXXThrowOperand(SourceLocation ThrowLoc, QualType ThrowTy, Expr *E);