Home | History | Annotate | Download | only in Sema
      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/DeclarationName.h"
     20 #include "clang/AST/Expr.h"
     21 #include "clang/AST/ExprObjC.h"
     22 #include "clang/AST/ExternalASTSource.h"
     23 #include "clang/AST/MangleNumberingContext.h"
     24 #include "clang/AST/NSAPI.h"
     25 #include "clang/AST/PrettyPrinter.h"
     26 #include "clang/AST/TypeLoc.h"
     27 #include "clang/Basic/ExpressionTraits.h"
     28 #include "clang/Basic/LangOptions.h"
     29 #include "clang/Basic/Module.h"
     30 #include "clang/Basic/OpenMPKinds.h"
     31 #include "clang/Basic/Specifiers.h"
     32 #include "clang/Basic/TemplateKinds.h"
     33 #include "clang/Basic/TypeTraits.h"
     34 #include "clang/Sema/AnalysisBasedWarnings.h"
     35 #include "clang/Sema/DeclSpec.h"
     36 #include "clang/Sema/ExternalSemaSource.h"
     37 #include "clang/Sema/IdentifierResolver.h"
     38 #include "clang/Sema/LocInfoType.h"
     39 #include "clang/Sema/ObjCMethodList.h"
     40 #include "clang/Sema/Ownership.h"
     41 #include "clang/Sema/Scope.h"
     42 #include "clang/Sema/ScopeInfo.h"
     43 #include "clang/Sema/TypoCorrection.h"
     44 #include "clang/Sema/Weak.h"
     45 #include "llvm/ADT/ArrayRef.h"
     46 #include "llvm/ADT/Optional.h"
     47 #include "llvm/ADT/SetVector.h"
     48 #include "llvm/ADT/SmallPtrSet.h"
     49 #include "llvm/ADT/SmallVector.h"
     50 #include "llvm/ADT/TinyPtrVector.h"
     51 #include <deque>
     52 #include <memory>
     53 #include <string>
     54 #include <vector>
     55 
     56 namespace llvm {
     57   class APSInt;
     58   template <typename ValueT> struct DenseMapInfo;
     59   template <typename ValueT, typename ValueInfoT> class DenseSet;
     60   class SmallBitVector;
     61   class InlineAsmIdentifierInfo;
     62 }
     63 
     64 namespace clang {
     65   class ADLResult;
     66   class ASTConsumer;
     67   class ASTContext;
     68   class ASTMutationListener;
     69   class ASTReader;
     70   class ASTWriter;
     71   class ArrayType;
     72   class AttributeList;
     73   class BlockDecl;
     74   class CapturedDecl;
     75   class CXXBasePath;
     76   class CXXBasePaths;
     77   class CXXBindTemporaryExpr;
     78   typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath;
     79   class CXXConstructorDecl;
     80   class CXXConversionDecl;
     81   class CXXDeleteExpr;
     82   class CXXDestructorDecl;
     83   class CXXFieldCollector;
     84   class CXXMemberCallExpr;
     85   class CXXMethodDecl;
     86   class CXXScopeSpec;
     87   class CXXTemporary;
     88   class CXXTryStmt;
     89   class CallExpr;
     90   class ClassTemplateDecl;
     91   class ClassTemplatePartialSpecializationDecl;
     92   class ClassTemplateSpecializationDecl;
     93   class VarTemplatePartialSpecializationDecl;
     94   class CodeCompleteConsumer;
     95   class CodeCompletionAllocator;
     96   class CodeCompletionTUInfo;
     97   class CodeCompletionResult;
     98   class Decl;
     99   class DeclAccessPair;
    100   class DeclContext;
    101   class DeclRefExpr;
    102   class DeclaratorDecl;
    103   class DeducedTemplateArgument;
    104   class DependentDiagnostic;
    105   class DesignatedInitExpr;
    106   class Designation;
    107   class EnableIfAttr;
    108   class EnumConstantDecl;
    109   class Expr;
    110   class ExtVectorType;
    111   class ExternalSemaSource;
    112   class FormatAttr;
    113   class FriendDecl;
    114   class FunctionDecl;
    115   class FunctionProtoType;
    116   class FunctionTemplateDecl;
    117   class ImplicitConversionSequence;
    118   class InitListExpr;
    119   class InitializationKind;
    120   class InitializationSequence;
    121   class InitializedEntity;
    122   class IntegerLiteral;
    123   class LabelStmt;
    124   class LambdaExpr;
    125   class LangOptions;
    126   class LocalInstantiationScope;
    127   class LookupResult;
    128   class MacroInfo;
    129   typedef ArrayRef<std::pair<IdentifierInfo *, SourceLocation>> ModuleIdPath;
    130   class ModuleLoader;
    131   class MultiLevelTemplateArgumentList;
    132   class NamedDecl;
    133   class ObjCCategoryDecl;
    134   class ObjCCategoryImplDecl;
    135   class ObjCCompatibleAliasDecl;
    136   class ObjCContainerDecl;
    137   class ObjCImplDecl;
    138   class ObjCImplementationDecl;
    139   class ObjCInterfaceDecl;
    140   class ObjCIvarDecl;
    141   template <class T> class ObjCList;
    142   class ObjCMessageExpr;
    143   class ObjCMethodDecl;
    144   class ObjCPropertyDecl;
    145   class ObjCProtocolDecl;
    146   class OMPThreadPrivateDecl;
    147   class OMPClause;
    148   struct OverloadCandidate;
    149   class OverloadCandidateSet;
    150   class OverloadExpr;
    151   class ParenListExpr;
    152   class ParmVarDecl;
    153   class Preprocessor;
    154   class PseudoDestructorTypeStorage;
    155   class PseudoObjectExpr;
    156   class QualType;
    157   class StandardConversionSequence;
    158   class Stmt;
    159   class StringLiteral;
    160   class SwitchStmt;
    161   class TemplateArgument;
    162   class TemplateArgumentList;
    163   class TemplateArgumentLoc;
    164   class TemplateDecl;
    165   class TemplateParameterList;
    166   class TemplatePartialOrderingContext;
    167   class TemplateTemplateParmDecl;
    168   class Token;
    169   class TypeAliasDecl;
    170   class TypedefDecl;
    171   class TypedefNameDecl;
    172   class TypeLoc;
    173   class TypoCorrectionConsumer;
    174   class UnqualifiedId;
    175   class UnresolvedLookupExpr;
    176   class UnresolvedMemberExpr;
    177   class UnresolvedSetImpl;
    178   class UnresolvedSetIterator;
    179   class UsingDecl;
    180   class UsingShadowDecl;
    181   class ValueDecl;
    182   class VarDecl;
    183   class VarTemplateSpecializationDecl;
    184   class VisibilityAttr;
    185   class VisibleDeclConsumer;
    186   class IndirectFieldDecl;
    187   struct DeductionFailureInfo;
    188   class TemplateSpecCandidateSet;
    189 
    190 namespace sema {
    191   class AccessedEntity;
    192   class BlockScopeInfo;
    193   class CapturedRegionScopeInfo;
    194   class CapturingScopeInfo;
    195   class CompoundScopeInfo;
    196   class DelayedDiagnostic;
    197   class DelayedDiagnosticPool;
    198   class FunctionScopeInfo;
    199   class LambdaScopeInfo;
    200   class PossiblyUnreachableDiag;
    201   class TemplateDeductionInfo;
    202 }
    203 
    204 namespace threadSafety {
    205   class BeforeSet;
    206   void threadSafetyCleanup(BeforeSet* Cache);
    207 }
    208 
    209 // FIXME: No way to easily map from TemplateTypeParmTypes to
    210 // TemplateTypeParmDecls, so we have this horrible PointerUnion.
    211 typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType*, NamedDecl*>,
    212                   SourceLocation> UnexpandedParameterPack;
    213 
    214 /// Describes whether we've seen any nullability information for the given
    215 /// file.
    216 struct FileNullability {
    217   /// The first pointer declarator (of any pointer kind) in the file that does
    218   /// not have a corresponding nullability annotation.
    219   SourceLocation PointerLoc;
    220 
    221   /// Which kind of pointer declarator we saw.
    222   uint8_t PointerKind;
    223 
    224   /// Whether we saw any type nullability annotations in the given file.
    225   bool SawTypeNullability = false;
    226 };
    227 
    228 /// A mapping from file IDs to a record of whether we've seen nullability
    229 /// information in that file.
    230 class FileNullabilityMap {
    231   /// A mapping from file IDs to the nullability information for each file ID.
    232   llvm::DenseMap<FileID, FileNullability> Map;
    233 
    234   /// A single-element cache based on the file ID.
    235   struct {
    236     FileID File;
    237     FileNullability Nullability;
    238   } Cache;
    239 
    240 public:
    241   FileNullability &operator[](FileID file) {
    242     // Check the single-element cache.
    243     if (file == Cache.File)
    244       return Cache.Nullability;
    245 
    246     // It's not in the single-element cache; flush the cache if we have one.
    247     if (!Cache.File.isInvalid()) {
    248       Map[Cache.File] = Cache.Nullability;
    249     }
    250 
    251     // Pull this entry into the cache.
    252     Cache.File = file;
    253     Cache.Nullability = Map[file];
    254     return Cache.Nullability;
    255   }
    256 };
    257 
    258 /// Sema - This implements semantic analysis and AST building for C.
    259 class Sema {
    260   Sema(const Sema &) = delete;
    261   void operator=(const Sema &) = delete;
    262 
    263   ///\brief Source of additional semantic information.
    264   ExternalSemaSource *ExternalSource;
    265 
    266   ///\brief Whether Sema has generated a multiplexer and has to delete it.
    267   bool isMultiplexExternalSource;
    268 
    269   static bool mightHaveNonExternalLinkage(const DeclaratorDecl *FD);
    270 
    271   bool isVisibleSlow(const NamedDecl *D);
    272 
    273   bool shouldLinkPossiblyHiddenDecl(const NamedDecl *Old,
    274                                     const NamedDecl *New) {
    275     // We are about to link these. It is now safe to compute the linkage of
    276     // the new decl. If the new decl has external linkage, we will
    277     // link it with the hidden decl (which also has external linkage) and
    278     // it will keep having external linkage. If it has internal linkage, we
    279     // will not link it. Since it has no previous decls, it will remain
    280     // with internal linkage.
    281     return isVisible(Old) || New->isExternallyVisible();
    282   }
    283   bool shouldLinkPossiblyHiddenDecl(LookupResult &Old, const NamedDecl *New);
    284 
    285 public:
    286   typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
    287   typedef OpaquePtr<TemplateName> TemplateTy;
    288   typedef OpaquePtr<QualType> TypeTy;
    289 
    290   OpenCLOptions OpenCLFeatures;
    291   FPOptions FPFeatures;
    292 
    293   const LangOptions &LangOpts;
    294   Preprocessor &PP;
    295   ASTContext &Context;
    296   ASTConsumer &Consumer;
    297   DiagnosticsEngine &Diags;
    298   SourceManager &SourceMgr;
    299 
    300   /// \brief Flag indicating whether or not to collect detailed statistics.
    301   bool CollectStats;
    302 
    303   /// \brief Code-completion consumer.
    304   CodeCompleteConsumer *CodeCompleter;
    305 
    306   /// CurContext - This is the current declaration context of parsing.
    307   DeclContext *CurContext;
    308 
    309   /// \brief Generally null except when we temporarily switch decl contexts,
    310   /// like in \see ActOnObjCTemporaryExitContainerContext.
    311   DeclContext *OriginalLexicalContext;
    312 
    313   /// VAListTagName - The declaration name corresponding to __va_list_tag.
    314   /// This is used as part of a hack to omit that class from ADL results.
    315   DeclarationName VAListTagName;
    316 
    317   /// PackContext - Manages the stack for \#pragma pack. An alignment
    318   /// of 0 indicates default alignment.
    319   void *PackContext; // Really a "PragmaPackStack*"
    320 
    321   bool MSStructPragmaOn; // True when \#pragma ms_struct on
    322 
    323   /// \brief Controls member pointer representation format under the MS ABI.
    324   LangOptions::PragmaMSPointersToMembersKind
    325       MSPointerToMemberRepresentationMethod;
    326 
    327   enum PragmaVtorDispKind {
    328     PVDK_Push,          ///< #pragma vtordisp(push, mode)
    329     PVDK_Set,           ///< #pragma vtordisp(mode)
    330     PVDK_Pop,           ///< #pragma vtordisp(pop)
    331     PVDK_Reset          ///< #pragma vtordisp()
    332   };
    333 
    334   enum PragmaMsStackAction {
    335     PSK_Reset,    // #pragma ()
    336     PSK_Set,      // #pragma ("name")
    337     PSK_Push,     // #pragma (push[, id])
    338     PSK_Push_Set, // #pragma (push[, id], "name")
    339     PSK_Pop,      // #pragma (pop[, id])
    340     PSK_Pop_Set,  // #pragma (pop[, id], "name")
    341   };
    342 
    343   /// \brief Whether to insert vtordisps prior to virtual bases in the Microsoft
    344   /// C++ ABI.  Possible values are 0, 1, and 2, which mean:
    345   ///
    346   /// 0: Suppress all vtordisps
    347   /// 1: Insert vtordisps in the presence of vbase overrides and non-trivial
    348   ///    structors
    349   /// 2: Always insert vtordisps to support RTTI on partially constructed
    350   ///    objects
    351   ///
    352   /// The stack always has at least one element in it.
    353   SmallVector<MSVtorDispAttr::Mode, 2> VtorDispModeStack;
    354 
    355   /// Stack of active SEH __finally scopes.  Can be empty.
    356   SmallVector<Scope*, 2> CurrentSEHFinally;
    357 
    358   /// \brief Source location for newly created implicit MSInheritanceAttrs
    359   SourceLocation ImplicitMSInheritanceAttrLoc;
    360 
    361   template<typename ValueType>
    362   struct PragmaStack {
    363     struct Slot {
    364       llvm::StringRef StackSlotLabel;
    365       ValueType Value;
    366       SourceLocation PragmaLocation;
    367       Slot(llvm::StringRef StackSlotLabel,
    368            ValueType Value,
    369            SourceLocation PragmaLocation)
    370         : StackSlotLabel(StackSlotLabel), Value(Value),
    371           PragmaLocation(PragmaLocation) {}
    372     };
    373     void Act(SourceLocation PragmaLocation,
    374              PragmaMsStackAction Action,
    375              llvm::StringRef StackSlotLabel,
    376              ValueType Value);
    377     explicit PragmaStack(const ValueType &Value)
    378       : CurrentValue(Value) {}
    379     SmallVector<Slot, 2> Stack;
    380     ValueType CurrentValue;
    381     SourceLocation CurrentPragmaLocation;
    382   };
    383   // FIXME: We should serialize / deserialize these if they occur in a PCH (but
    384   // we shouldn't do so if they're in a module).
    385   PragmaStack<StringLiteral *> DataSegStack;
    386   PragmaStack<StringLiteral *> BSSSegStack;
    387   PragmaStack<StringLiteral *> ConstSegStack;
    388   PragmaStack<StringLiteral *> CodeSegStack;
    389 
    390   /// A mapping that describes the nullability we've seen in each header file.
    391   FileNullabilityMap NullabilityMap;
    392 
    393   /// Last section used with #pragma init_seg.
    394   StringLiteral *CurInitSeg;
    395   SourceLocation CurInitSegLoc;
    396 
    397   /// VisContext - Manages the stack for \#pragma GCC visibility.
    398   void *VisContext; // Really a "PragmaVisStack*"
    399 
    400   /// \brief This represents the last location of a "#pragma clang optimize off"
    401   /// directive if such a directive has not been closed by an "on" yet. If
    402   /// optimizations are currently "on", this is set to an invalid location.
    403   SourceLocation OptimizeOffPragmaLocation;
    404 
    405   /// \brief Flag indicating if Sema is building a recovery call expression.
    406   ///
    407   /// This flag is used to avoid building recovery call expressions
    408   /// if Sema is already doing so, which would cause infinite recursions.
    409   bool IsBuildingRecoveryCallExpr;
    410 
    411   /// ExprNeedsCleanups - True if the current evaluation context
    412   /// requires cleanups to be run at its conclusion.
    413   bool ExprNeedsCleanups;
    414 
    415   /// ExprCleanupObjects - This is the stack of objects requiring
    416   /// cleanup that are created by the current full expression.  The
    417   /// element type here is ExprWithCleanups::Object.
    418   SmallVector<BlockDecl*, 8> ExprCleanupObjects;
    419 
    420   /// \brief Store a list of either DeclRefExprs or MemberExprs
    421   ///  that contain a reference to a variable (constant) that may or may not
    422   ///  be odr-used in this Expr, and we won't know until all lvalue-to-rvalue
    423   ///  and discarded value conversions have been applied to all subexpressions
    424   ///  of the enclosing full expression.  This is cleared at the end of each
    425   ///  full expression.
    426   llvm::SmallPtrSet<Expr*, 2> MaybeODRUseExprs;
    427 
    428   /// \brief Stack containing information about each of the nested
    429   /// function, block, and method scopes that are currently active.
    430   ///
    431   /// This array is never empty.  Clients should ignore the first
    432   /// element, which is used to cache a single FunctionScopeInfo
    433   /// that's used to parse every top-level function.
    434   SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes;
    435 
    436   typedef LazyVector<TypedefNameDecl *, ExternalSemaSource,
    437                      &ExternalSemaSource::ReadExtVectorDecls, 2, 2>
    438     ExtVectorDeclsType;
    439 
    440   /// ExtVectorDecls - This is a list all the extended vector types. This allows
    441   /// us to associate a raw vector type with one of the ext_vector type names.
    442   /// This is only necessary for issuing pretty diagnostics.
    443   ExtVectorDeclsType ExtVectorDecls;
    444 
    445   /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
    446   std::unique_ptr<CXXFieldCollector> FieldCollector;
    447 
    448   typedef llvm::SmallSetVector<const NamedDecl*, 16> NamedDeclSetType;
    449 
    450   /// \brief Set containing all declared private fields that are not used.
    451   NamedDeclSetType UnusedPrivateFields;
    452 
    453   /// \brief Set containing all typedefs that are likely unused.
    454   llvm::SmallSetVector<const TypedefNameDecl *, 4>
    455       UnusedLocalTypedefNameCandidates;
    456 
    457   /// \brief Delete-expressions to be analyzed at the end of translation unit
    458   ///
    459   /// This list contains class members, and locations of delete-expressions
    460   /// that could not be proven as to whether they mismatch with new-expression
    461   /// used in initializer of the field.
    462   typedef std::pair<SourceLocation, bool> DeleteExprLoc;
    463   typedef llvm::SmallVector<DeleteExprLoc, 4> DeleteLocs;
    464   llvm::MapVector<FieldDecl *, DeleteLocs> DeleteExprs;
    465 
    466   typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy;
    467 
    468   /// PureVirtualClassDiagSet - a set of class declarations which we have
    469   /// emitted a list of pure virtual functions. Used to prevent emitting the
    470   /// same list more than once.
    471   std::unique_ptr<RecordDeclSetTy> PureVirtualClassDiagSet;
    472 
    473   /// ParsingInitForAutoVars - a set of declarations with auto types for which
    474   /// we are currently parsing the initializer.
    475   llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars;
    476 
    477   /// \brief Look for a locally scoped extern "C" declaration by the given name.
    478   NamedDecl *findLocallyScopedExternCDecl(DeclarationName Name);
    479 
    480   typedef LazyVector<VarDecl *, ExternalSemaSource,
    481                      &ExternalSemaSource::ReadTentativeDefinitions, 2, 2>
    482     TentativeDefinitionsType;
    483 
    484   /// \brief All the tentative definitions encountered in the TU.
    485   TentativeDefinitionsType TentativeDefinitions;
    486 
    487   typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource,
    488                      &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2>
    489     UnusedFileScopedDeclsType;
    490 
    491   /// \brief The set of file scoped decls seen so far that have not been used
    492   /// and must warn if not used. Only contains the first declaration.
    493   UnusedFileScopedDeclsType UnusedFileScopedDecls;
    494 
    495   typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource,
    496                      &ExternalSemaSource::ReadDelegatingConstructors, 2, 2>
    497     DelegatingCtorDeclsType;
    498 
    499   /// \brief All the delegating constructors seen so far in the file, used for
    500   /// cycle detection at the end of the TU.
    501   DelegatingCtorDeclsType DelegatingCtorDecls;
    502 
    503   /// \brief All the overriding functions seen during a class definition
    504   /// that had their exception spec checks delayed, plus the overridden
    505   /// function.
    506   SmallVector<std::pair<const CXXMethodDecl*, const CXXMethodDecl*>, 2>
    507     DelayedExceptionSpecChecks;
    508 
    509   /// \brief All the members seen during a class definition which were both
    510   /// explicitly defaulted and had explicitly-specified exception
    511   /// specifications, along with the function type containing their
    512   /// user-specified exception specification. Those exception specifications
    513   /// were overridden with the default specifications, but we still need to
    514   /// check whether they are compatible with the default specification, and
    515   /// we can't do that until the nesting set of class definitions is complete.
    516   SmallVector<std::pair<CXXMethodDecl*, const FunctionProtoType*>, 2>
    517     DelayedDefaultedMemberExceptionSpecs;
    518 
    519   typedef llvm::MapVector<const FunctionDecl *, LateParsedTemplate *>
    520       LateParsedTemplateMapT;
    521   LateParsedTemplateMapT LateParsedTemplateMap;
    522 
    523   /// \brief Callback to the parser to parse templated functions when needed.
    524   typedef void LateTemplateParserCB(void *P, LateParsedTemplate &LPT);
    525   typedef void LateTemplateParserCleanupCB(void *P);
    526   LateTemplateParserCB *LateTemplateParser;
    527   LateTemplateParserCleanupCB *LateTemplateParserCleanup;
    528   void *OpaqueParser;
    529 
    530   void SetLateTemplateParser(LateTemplateParserCB *LTP,
    531                              LateTemplateParserCleanupCB *LTPCleanup,
    532                              void *P) {
    533     LateTemplateParser = LTP;
    534     LateTemplateParserCleanup = LTPCleanup;
    535     OpaqueParser = P;
    536   }
    537 
    538   class DelayedDiagnostics;
    539 
    540   class DelayedDiagnosticsState {
    541     sema::DelayedDiagnosticPool *SavedPool;
    542     friend class Sema::DelayedDiagnostics;
    543   };
    544   typedef DelayedDiagnosticsState ParsingDeclState;
    545   typedef DelayedDiagnosticsState ProcessingContextState;
    546 
    547   /// A class which encapsulates the logic for delaying diagnostics
    548   /// during parsing and other processing.
    549   class DelayedDiagnostics {
    550     /// \brief The current pool of diagnostics into which delayed
    551     /// diagnostics should go.
    552     sema::DelayedDiagnosticPool *CurPool;
    553 
    554   public:
    555     DelayedDiagnostics() : CurPool(nullptr) {}
    556 
    557     /// Adds a delayed diagnostic.
    558     void add(const sema::DelayedDiagnostic &diag); // in DelayedDiagnostic.h
    559 
    560     /// Determines whether diagnostics should be delayed.
    561     bool shouldDelayDiagnostics() { return CurPool != nullptr; }
    562 
    563     /// Returns the current delayed-diagnostics pool.
    564     sema::DelayedDiagnosticPool *getCurrentPool() const {
    565       return CurPool;
    566     }
    567 
    568     /// Enter a new scope.  Access and deprecation diagnostics will be
    569     /// collected in this pool.
    570     DelayedDiagnosticsState push(sema::DelayedDiagnosticPool &pool) {
    571       DelayedDiagnosticsState state;
    572       state.SavedPool = CurPool;
    573       CurPool = &pool;
    574       return state;
    575     }
    576 
    577     /// Leave a delayed-diagnostic state that was previously pushed.
    578     /// Do not emit any of the diagnostics.  This is performed as part
    579     /// of the bookkeeping of popping a pool "properly".
    580     void popWithoutEmitting(DelayedDiagnosticsState state) {
    581       CurPool = state.SavedPool;
    582     }
    583 
    584     /// Enter a new scope where access and deprecation diagnostics are
    585     /// not delayed.
    586     DelayedDiagnosticsState pushUndelayed() {
    587       DelayedDiagnosticsState state;
    588       state.SavedPool = CurPool;
    589       CurPool = nullptr;
    590       return state;
    591     }
    592 
    593     /// Undo a previous pushUndelayed().
    594     void popUndelayed(DelayedDiagnosticsState state) {
    595       assert(CurPool == nullptr);
    596       CurPool = state.SavedPool;
    597     }
    598   } DelayedDiagnostics;
    599 
    600   /// A RAII object to temporarily push a declaration context.
    601   class ContextRAII {
    602   private:
    603     Sema &S;
    604     DeclContext *SavedContext;
    605     ProcessingContextState SavedContextState;
    606     QualType SavedCXXThisTypeOverride;
    607 
    608   public:
    609     ContextRAII(Sema &S, DeclContext *ContextToPush, bool NewThisContext = true)
    610       : S(S), SavedContext(S.CurContext),
    611         SavedContextState(S.DelayedDiagnostics.pushUndelayed()),
    612         SavedCXXThisTypeOverride(S.CXXThisTypeOverride)
    613     {
    614       assert(ContextToPush && "pushing null context");
    615       S.CurContext = ContextToPush;
    616       if (NewThisContext)
    617         S.CXXThisTypeOverride = QualType();
    618     }
    619 
    620     void pop() {
    621       if (!SavedContext) return;
    622       S.CurContext = SavedContext;
    623       S.DelayedDiagnostics.popUndelayed(SavedContextState);
    624       S.CXXThisTypeOverride = SavedCXXThisTypeOverride;
    625       SavedContext = nullptr;
    626     }
    627 
    628     ~ContextRAII() {
    629       pop();
    630     }
    631   };
    632 
    633   /// \brief RAII object to handle the state changes required to synthesize
    634   /// a function body.
    635   class SynthesizedFunctionScope {
    636     Sema &S;
    637     Sema::ContextRAII SavedContext;
    638 
    639   public:
    640     SynthesizedFunctionScope(Sema &S, DeclContext *DC)
    641       : S(S), SavedContext(S, DC)
    642     {
    643       S.PushFunctionScope();
    644       S.PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
    645     }
    646 
    647     ~SynthesizedFunctionScope() {
    648       S.PopExpressionEvaluationContext();
    649       S.PopFunctionScopeInfo();
    650     }
    651   };
    652 
    653   /// WeakUndeclaredIdentifiers - Identifiers contained in
    654   /// \#pragma weak before declared. rare. may alias another
    655   /// identifier, declared or undeclared
    656   llvm::MapVector<IdentifierInfo *, WeakInfo> WeakUndeclaredIdentifiers;
    657 
    658   /// ExtnameUndeclaredIdentifiers - Identifiers contained in
    659   /// \#pragma redefine_extname before declared.  Used in Solaris system headers
    660   /// to define functions that occur in multiple standards to call the version
    661   /// in the currently selected standard.
    662   llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*> ExtnameUndeclaredIdentifiers;
    663 
    664 
    665   /// \brief Load weak undeclared identifiers from the external source.
    666   void LoadExternalWeakUndeclaredIdentifiers();
    667 
    668   /// WeakTopLevelDecl - Translation-unit scoped declarations generated by
    669   /// \#pragma weak during processing of other Decls.
    670   /// I couldn't figure out a clean way to generate these in-line, so
    671   /// we store them here and handle separately -- which is a hack.
    672   /// It would be best to refactor this.
    673   SmallVector<Decl*,2> WeakTopLevelDecl;
    674 
    675   IdentifierResolver IdResolver;
    676 
    677   /// Translation Unit Scope - useful to Objective-C actions that need
    678   /// to lookup file scope declarations in the "ordinary" C decl namespace.
    679   /// For example, user-defined classes, built-in "id" type, etc.
    680   Scope *TUScope;
    681 
    682   /// \brief The C++ "std" namespace, where the standard library resides.
    683   LazyDeclPtr StdNamespace;
    684 
    685   /// \brief The C++ "std::bad_alloc" class, which is defined by the C++
    686   /// standard library.
    687   LazyDeclPtr StdBadAlloc;
    688 
    689   /// \brief The C++ "std::initializer_list" template, which is defined in
    690   /// \<initializer_list>.
    691   ClassTemplateDecl *StdInitializerList;
    692 
    693   /// \brief The C++ "type_info" declaration, which is defined in \<typeinfo>.
    694   RecordDecl *CXXTypeInfoDecl;
    695 
    696   /// \brief The MSVC "_GUID" struct, which is defined in MSVC header files.
    697   RecordDecl *MSVCGuidDecl;
    698 
    699   /// \brief Caches identifiers/selectors for NSFoundation APIs.
    700   std::unique_ptr<NSAPI> NSAPIObj;
    701 
    702   /// \brief The declaration of the Objective-C NSNumber class.
    703   ObjCInterfaceDecl *NSNumberDecl;
    704 
    705   /// \brief The declaration of the Objective-C NSValue class.
    706   ObjCInterfaceDecl *NSValueDecl;
    707 
    708   /// \brief Pointer to NSNumber type (NSNumber *).
    709   QualType NSNumberPointer;
    710 
    711   /// \brief Pointer to NSValue type (NSValue *).
    712   QualType NSValuePointer;
    713 
    714   /// \brief The Objective-C NSNumber methods used to create NSNumber literals.
    715   ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods];
    716 
    717   /// \brief The declaration of the Objective-C NSString class.
    718   ObjCInterfaceDecl *NSStringDecl;
    719 
    720   /// \brief Pointer to NSString type (NSString *).
    721   QualType NSStringPointer;
    722 
    723   /// \brief The declaration of the stringWithUTF8String: method.
    724   ObjCMethodDecl *StringWithUTF8StringMethod;
    725 
    726   /// \brief The declaration of the valueWithBytes:objCType: method.
    727   ObjCMethodDecl *ValueWithBytesObjCTypeMethod;
    728 
    729   /// \brief The declaration of the Objective-C NSArray class.
    730   ObjCInterfaceDecl *NSArrayDecl;
    731 
    732   /// \brief The declaration of the arrayWithObjects:count: method.
    733   ObjCMethodDecl *ArrayWithObjectsMethod;
    734 
    735   /// \brief The declaration of the Objective-C NSDictionary class.
    736   ObjCInterfaceDecl *NSDictionaryDecl;
    737 
    738   /// \brief The declaration of the dictionaryWithObjects:forKeys:count: method.
    739   ObjCMethodDecl *DictionaryWithObjectsMethod;
    740 
    741   /// \brief id<NSCopying> type.
    742   QualType QIDNSCopying;
    743 
    744   /// \brief will hold 'respondsToSelector:'
    745   Selector RespondsToSelectorSel;
    746 
    747   /// \brief counter for internal MS Asm label names.
    748   unsigned MSAsmLabelNameCounter;
    749 
    750   /// A flag to remember whether the implicit forms of operator new and delete
    751   /// have been declared.
    752   bool GlobalNewDeleteDeclared;
    753 
    754   /// A flag to indicate that we're in a context that permits abstract
    755   /// references to fields.  This is really a
    756   bool AllowAbstractFieldReference;
    757 
    758   /// \brief Describes how the expressions currently being parsed are
    759   /// evaluated at run-time, if at all.
    760   enum ExpressionEvaluationContext {
    761     /// \brief The current expression and its subexpressions occur within an
    762     /// unevaluated operand (C++11 [expr]p7), such as the subexpression of
    763     /// \c sizeof, where the type of the expression may be significant but
    764     /// no code will be generated to evaluate the value of the expression at
    765     /// run time.
    766     Unevaluated,
    767 
    768     /// \brief The current expression occurs within an unevaluated
    769     /// operand that unconditionally permits abstract references to
    770     /// fields, such as a SIZE operator in MS-style inline assembly.
    771     UnevaluatedAbstract,
    772 
    773     /// \brief The current context is "potentially evaluated" in C++11 terms,
    774     /// but the expression is evaluated at compile-time (like the values of
    775     /// cases in a switch statement).
    776     ConstantEvaluated,
    777 
    778     /// \brief The current expression is potentially evaluated at run time,
    779     /// which means that code may be generated to evaluate the value of the
    780     /// expression at run time.
    781     PotentiallyEvaluated,
    782 
    783     /// \brief The current expression is potentially evaluated, but any
    784     /// declarations referenced inside that expression are only used if
    785     /// in fact the current expression is used.
    786     ///
    787     /// This value is used when parsing default function arguments, for which
    788     /// we would like to provide diagnostics (e.g., passing non-POD arguments
    789     /// through varargs) but do not want to mark declarations as "referenced"
    790     /// until the default argument is used.
    791     PotentiallyEvaluatedIfUsed
    792   };
    793 
    794   /// \brief Data structure used to record current or nested
    795   /// expression evaluation contexts.
    796   struct ExpressionEvaluationContextRecord {
    797     /// \brief The expression evaluation context.
    798     ExpressionEvaluationContext Context;
    799 
    800     /// \brief Whether the enclosing context needed a cleanup.
    801     bool ParentNeedsCleanups;
    802 
    803     /// \brief Whether we are in a decltype expression.
    804     bool IsDecltype;
    805 
    806     /// \brief The number of active cleanup objects when we entered
    807     /// this expression evaluation context.
    808     unsigned NumCleanupObjects;
    809 
    810     /// \brief The number of typos encountered during this expression evaluation
    811     /// context (i.e. the number of TypoExprs created).
    812     unsigned NumTypos;
    813 
    814     llvm::SmallPtrSet<Expr*, 2> SavedMaybeODRUseExprs;
    815 
    816     /// \brief The lambdas that are present within this context, if it
    817     /// is indeed an unevaluated context.
    818     SmallVector<LambdaExpr *, 2> Lambdas;
    819 
    820     /// \brief The declaration that provides context for lambda expressions
    821     /// and block literals if the normal declaration context does not
    822     /// suffice, e.g., in a default function argument.
    823     Decl *ManglingContextDecl;
    824 
    825     /// \brief The context information used to mangle lambda expressions
    826     /// and block literals within this context.
    827     ///
    828     /// This mangling information is allocated lazily, since most contexts
    829     /// do not have lambda expressions or block literals.
    830     IntrusiveRefCntPtr<MangleNumberingContext> MangleNumbering;
    831 
    832     /// \brief If we are processing a decltype type, a set of call expressions
    833     /// for which we have deferred checking the completeness of the return type.
    834     SmallVector<CallExpr *, 8> DelayedDecltypeCalls;
    835 
    836     /// \brief If we are processing a decltype type, a set of temporary binding
    837     /// expressions for which we have deferred checking the destructor.
    838     SmallVector<CXXBindTemporaryExpr *, 8> DelayedDecltypeBinds;
    839 
    840     ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context,
    841                                       unsigned NumCleanupObjects,
    842                                       bool ParentNeedsCleanups,
    843                                       Decl *ManglingContextDecl,
    844                                       bool IsDecltype)
    845       : Context(Context), ParentNeedsCleanups(ParentNeedsCleanups),
    846         IsDecltype(IsDecltype), NumCleanupObjects(NumCleanupObjects),
    847         NumTypos(0),
    848         ManglingContextDecl(ManglingContextDecl), MangleNumbering() { }
    849 
    850     /// \brief Retrieve the mangling numbering context, used to consistently
    851     /// number constructs like lambdas for mangling.
    852     MangleNumberingContext &getMangleNumberingContext(ASTContext &Ctx);
    853 
    854     bool isUnevaluated() const {
    855       return Context == Unevaluated || Context == UnevaluatedAbstract;
    856     }
    857   };
    858 
    859   /// A stack of expression evaluation contexts.
    860   SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts;
    861 
    862   /// \brief Compute the mangling number context for a lambda expression or
    863   /// block literal.
    864   ///
    865   /// \param DC - The DeclContext containing the lambda expression or
    866   /// block literal.
    867   /// \param[out] ManglingContextDecl - Returns the ManglingContextDecl
    868   /// associated with the context, if relevant.
    869   MangleNumberingContext *getCurrentMangleNumberContext(
    870     const DeclContext *DC,
    871     Decl *&ManglingContextDecl);
    872 
    873 
    874   /// SpecialMemberOverloadResult - The overloading result for a special member
    875   /// function.
    876   ///
    877   /// This is basically a wrapper around PointerIntPair. The lowest bits of the
    878   /// integer are used to determine whether overload resolution succeeded.
    879   class SpecialMemberOverloadResult : public llvm::FastFoldingSetNode {
    880   public:
    881     enum Kind {
    882       NoMemberOrDeleted,
    883       Ambiguous,
    884       Success
    885     };
    886 
    887   private:
    888     llvm::PointerIntPair<CXXMethodDecl*, 2> Pair;
    889 
    890   public:
    891     SpecialMemberOverloadResult(const llvm::FoldingSetNodeID &ID)
    892       : FastFoldingSetNode(ID)
    893     {}
    894 
    895     CXXMethodDecl *getMethod() const { return Pair.getPointer(); }
    896     void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); }
    897 
    898     Kind getKind() const { return static_cast<Kind>(Pair.getInt()); }
    899     void setKind(Kind K) { Pair.setInt(K); }
    900   };
    901 
    902   /// \brief A cache of special member function overload resolution results
    903   /// for C++ records.
    904   llvm::FoldingSet<SpecialMemberOverloadResult> SpecialMemberCache;
    905 
    906   /// \brief A cache of the flags available in enumerations with the flag_bits
    907   /// attribute.
    908   mutable llvm::DenseMap<const EnumDecl*, llvm::APInt> FlagBitsCache;
    909 
    910   /// \brief The kind of translation unit we are processing.
    911   ///
    912   /// When we're processing a complete translation unit, Sema will perform
    913   /// end-of-translation-unit semantic tasks (such as creating
    914   /// initializers for tentative definitions in C) once parsing has
    915   /// completed. Modules and precompiled headers perform different kinds of
    916   /// checks.
    917   TranslationUnitKind TUKind;
    918 
    919   llvm::BumpPtrAllocator BumpAlloc;
    920 
    921   /// \brief The number of SFINAE diagnostics that have been trapped.
    922   unsigned NumSFINAEErrors;
    923 
    924   typedef llvm::DenseMap<ParmVarDecl *, llvm::TinyPtrVector<ParmVarDecl *>>
    925     UnparsedDefaultArgInstantiationsMap;
    926 
    927   /// \brief A mapping from parameters with unparsed default arguments to the
    928   /// set of instantiations of each parameter.
    929   ///
    930   /// This mapping is a temporary data structure used when parsing
    931   /// nested class templates or nested classes of class templates,
    932   /// where we might end up instantiating an inner class before the
    933   /// default arguments of its methods have been parsed.
    934   UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations;
    935 
    936   // Contains the locations of the beginning of unparsed default
    937   // argument locations.
    938   llvm::DenseMap<ParmVarDecl *, SourceLocation> UnparsedDefaultArgLocs;
    939 
    940   /// UndefinedInternals - all the used, undefined objects which require a
    941   /// definition in this translation unit.
    942   llvm::DenseMap<NamedDecl *, SourceLocation> UndefinedButUsed;
    943 
    944   /// Obtain a sorted list of functions that are undefined but ODR-used.
    945   void getUndefinedButUsed(
    946       SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined);
    947 
    948   /// Retrieves list of suspicious delete-expressions that will be checked at
    949   /// the end of translation unit.
    950   const llvm::MapVector<FieldDecl *, DeleteLocs> &
    951   getMismatchingDeleteExpressions() const;
    952 
    953   typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods;
    954   typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool;
    955 
    956   /// Method Pool - allows efficient lookup when typechecking messages to "id".
    957   /// We need to maintain a list, since selectors can have differing signatures
    958   /// across classes. In Cocoa, this happens to be extremely uncommon (only 1%
    959   /// of selectors are "overloaded").
    960   /// At the head of the list it is recorded whether there were 0, 1, or >= 2
    961   /// methods inside categories with a particular selector.
    962   GlobalMethodPool MethodPool;
    963 
    964   /// Method selectors used in a \@selector expression. Used for implementation
    965   /// of -Wselector.
    966   llvm::MapVector<Selector, SourceLocation> ReferencedSelectors;
    967 
    968   /// Kinds of C++ special members.
    969   enum CXXSpecialMember {
    970     CXXDefaultConstructor,
    971     CXXCopyConstructor,
    972     CXXMoveConstructor,
    973     CXXCopyAssignment,
    974     CXXMoveAssignment,
    975     CXXDestructor,
    976     CXXInvalid
    977   };
    978 
    979   typedef std::pair<CXXRecordDecl*, CXXSpecialMember> SpecialMemberDecl;
    980 
    981   /// The C++ special members which we are currently in the process of
    982   /// declaring. If this process recursively triggers the declaration of the
    983   /// same special member, we should act as if it is not yet declared.
    984   llvm::SmallSet<SpecialMemberDecl, 4> SpecialMembersBeingDeclared;
    985 
    986   void ReadMethodPool(Selector Sel);
    987 
    988   /// Private Helper predicate to check for 'self'.
    989   bool isSelfExpr(Expr *RExpr);
    990   bool isSelfExpr(Expr *RExpr, const ObjCMethodDecl *Method);
    991 
    992   /// \brief Cause the active diagnostic on the DiagosticsEngine to be
    993   /// emitted. This is closely coupled to the SemaDiagnosticBuilder class and
    994   /// should not be used elsewhere.
    995   void EmitCurrentDiagnostic(unsigned DiagID);
    996 
    997   /// Records and restores the FP_CONTRACT state on entry/exit of compound
    998   /// statements.
    999   class FPContractStateRAII {
   1000   public:
   1001     FPContractStateRAII(Sema& S)
   1002       : S(S), OldFPContractState(S.FPFeatures.fp_contract) {}
   1003     ~FPContractStateRAII() {
   1004       S.FPFeatures.fp_contract = OldFPContractState;
   1005     }
   1006   private:
   1007     Sema& S;
   1008     bool OldFPContractState : 1;
   1009   };
   1010 
   1011   /// Records and restores the vtordisp state on entry/exit of C++ method body.
   1012   class VtorDispStackRAII {
   1013   public:
   1014     VtorDispStackRAII(Sema &S, bool ShouldSaveAndRestore)
   1015       : S(S), ShouldSaveAndRestore(ShouldSaveAndRestore), OldVtorDispStack() {
   1016       if (ShouldSaveAndRestore)
   1017         OldVtorDispStack = S.VtorDispModeStack;
   1018     }
   1019     ~VtorDispStackRAII() {
   1020       if (ShouldSaveAndRestore)
   1021         S.VtorDispModeStack = OldVtorDispStack;
   1022     }
   1023   private:
   1024     Sema &S;
   1025     bool ShouldSaveAndRestore;
   1026     SmallVector<MSVtorDispAttr::Mode, 2> OldVtorDispStack;
   1027   };
   1028 
   1029   void addImplicitTypedef(StringRef Name, QualType T);
   1030 
   1031 public:
   1032   Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
   1033        TranslationUnitKind TUKind = TU_Complete,
   1034        CodeCompleteConsumer *CompletionConsumer = nullptr);
   1035   ~Sema();
   1036 
   1037   /// \brief Perform initialization that occurs after the parser has been
   1038   /// initialized but before it parses anything.
   1039   void Initialize();
   1040 
   1041   const LangOptions &getLangOpts() const { return LangOpts; }
   1042   OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; }
   1043   FPOptions     &getFPOptions() { return FPFeatures; }
   1044 
   1045   DiagnosticsEngine &getDiagnostics() const { return Diags; }
   1046   SourceManager &getSourceManager() const { return SourceMgr; }
   1047   Preprocessor &getPreprocessor() const { return PP; }
   1048   ASTContext &getASTContext() const { return Context; }
   1049   ASTConsumer &getASTConsumer() const { return Consumer; }
   1050   ASTMutationListener *getASTMutationListener() const;
   1051   ExternalSemaSource* getExternalSource() const { return ExternalSource; }
   1052 
   1053   ///\brief Registers an external source. If an external source already exists,
   1054   /// creates a multiplex external source and appends to it.
   1055   ///
   1056   ///\param[in] E - A non-null external sema source.
   1057   ///
   1058   void addExternalSource(ExternalSemaSource *E);
   1059 
   1060   void PrintStats() const;
   1061 
   1062   /// \brief Helper class that creates diagnostics with optional
   1063   /// template instantiation stacks.
   1064   ///
   1065   /// This class provides a wrapper around the basic DiagnosticBuilder
   1066   /// class that emits diagnostics. SemaDiagnosticBuilder is
   1067   /// responsible for emitting the diagnostic (as DiagnosticBuilder
   1068   /// does) and, if the diagnostic comes from inside a template
   1069   /// instantiation, printing the template instantiation stack as
   1070   /// well.
   1071   class SemaDiagnosticBuilder : public DiagnosticBuilder {
   1072     Sema &SemaRef;
   1073     unsigned DiagID;
   1074 
   1075   public:
   1076     SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID)
   1077       : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { }
   1078 
   1079     // This is a cunning lie. DiagnosticBuilder actually performs move
   1080     // construction in its copy constructor (but due to varied uses, it's not
   1081     // possible to conveniently express this as actual move construction). So
   1082     // the default copy ctor here is fine, because the base class disables the
   1083     // source anyway, so the user-defined ~SemaDiagnosticBuilder is a safe no-op
   1084     // in that case anwyay.
   1085     SemaDiagnosticBuilder(const SemaDiagnosticBuilder&) = default;
   1086 
   1087     ~SemaDiagnosticBuilder() {
   1088       // If we aren't active, there is nothing to do.
   1089       if (!isActive()) return;
   1090 
   1091       // Otherwise, we need to emit the diagnostic. First flush the underlying
   1092       // DiagnosticBuilder data, and clear the diagnostic builder itself so it
   1093       // won't emit the diagnostic in its own destructor.
   1094       //
   1095       // This seems wasteful, in that as written the DiagnosticBuilder dtor will
   1096       // do its own needless checks to see if the diagnostic needs to be
   1097       // emitted. However, because we take care to ensure that the builder
   1098       // objects never escape, a sufficiently smart compiler will be able to
   1099       // eliminate that code.
   1100       FlushCounts();
   1101       Clear();
   1102 
   1103       // Dispatch to Sema to emit the diagnostic.
   1104       SemaRef.EmitCurrentDiagnostic(DiagID);
   1105     }
   1106 
   1107     /// Teach operator<< to produce an object of the correct type.
   1108     template<typename T>
   1109     friend const SemaDiagnosticBuilder &operator<<(
   1110         const SemaDiagnosticBuilder &Diag, const T &Value) {
   1111       const DiagnosticBuilder &BaseDiag = Diag;
   1112       BaseDiag << Value;
   1113       return Diag;
   1114     }
   1115   };
   1116 
   1117   /// \brief Emit a diagnostic.
   1118   SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
   1119     DiagnosticBuilder DB = Diags.Report(Loc, DiagID);
   1120     return SemaDiagnosticBuilder(DB, *this, DiagID);
   1121   }
   1122 
   1123   /// \brief Emit a partial diagnostic.
   1124   SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic& PD);
   1125 
   1126   /// \brief Build a partial diagnostic.
   1127   PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h
   1128 
   1129   bool findMacroSpelling(SourceLocation &loc, StringRef name);
   1130 
   1131   /// \brief Get a string to suggest for zero-initialization of a type.
   1132   std::string
   1133   getFixItZeroInitializerForType(QualType T, SourceLocation Loc) const;
   1134   std::string getFixItZeroLiteralForType(QualType T, SourceLocation Loc) const;
   1135 
   1136   /// \brief Calls \c Lexer::getLocForEndOfToken()
   1137   SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset = 0);
   1138 
   1139   /// \brief Retrieve the module loader associated with the preprocessor.
   1140   ModuleLoader &getModuleLoader() const;
   1141 
   1142   void emitAndClearUnusedLocalTypedefWarnings();
   1143 
   1144   void ActOnEndOfTranslationUnit();
   1145 
   1146   void CheckDelegatingCtorCycles();
   1147 
   1148   Scope *getScopeForContext(DeclContext *Ctx);
   1149 
   1150   void PushFunctionScope();
   1151   void PushBlockScope(Scope *BlockScope, BlockDecl *Block);
   1152   sema::LambdaScopeInfo *PushLambdaScope();
   1153 
   1154   /// \brief This is used to inform Sema what the current TemplateParameterDepth
   1155   /// is during Parsing.  Currently it is used to pass on the depth
   1156   /// when parsing generic lambda 'auto' parameters.
   1157   void RecordParsingTemplateParameterDepth(unsigned Depth);
   1158 
   1159   void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD,
   1160                                RecordDecl *RD,
   1161                                CapturedRegionKind K);
   1162   void
   1163   PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP = nullptr,
   1164                        const Decl *D = nullptr,
   1165                        const BlockExpr *blkExpr = nullptr);
   1166 
   1167   sema::FunctionScopeInfo *getCurFunction() const {
   1168     return FunctionScopes.back();
   1169   }
   1170 
   1171   sema::FunctionScopeInfo *getEnclosingFunction() const {
   1172     if (FunctionScopes.empty())
   1173       return nullptr;
   1174 
   1175     for (int e = FunctionScopes.size()-1; e >= 0; --e) {
   1176       if (isa<sema::BlockScopeInfo>(FunctionScopes[e]))
   1177         continue;
   1178       return FunctionScopes[e];
   1179     }
   1180     return nullptr;
   1181   }
   1182 
   1183   template <typename ExprT>
   1184   void recordUseOfEvaluatedWeak(const ExprT *E, bool IsRead=true) {
   1185     if (!isUnevaluatedContext())
   1186       getCurFunction()->recordUseOfWeak(E, IsRead);
   1187   }
   1188 
   1189   void PushCompoundScope();
   1190   void PopCompoundScope();
   1191 
   1192   sema::CompoundScopeInfo &getCurCompoundScope() const;
   1193 
   1194   bool hasAnyUnrecoverableErrorsInThisFunction() const;
   1195 
   1196   /// \brief Retrieve the current block, if any.
   1197   sema::BlockScopeInfo *getCurBlock();
   1198 
   1199   /// \brief Retrieve the current lambda scope info, if any.
   1200   sema::LambdaScopeInfo *getCurLambda();
   1201 
   1202   /// \brief Retrieve the current generic lambda info, if any.
   1203   sema::LambdaScopeInfo *getCurGenericLambda();
   1204 
   1205   /// \brief Retrieve the current captured region, if any.
   1206   sema::CapturedRegionScopeInfo *getCurCapturedRegion();
   1207 
   1208   /// WeakTopLevelDeclDecls - access to \#pragma weak-generated Decls
   1209   SmallVectorImpl<Decl *> &WeakTopLevelDecls() { return WeakTopLevelDecl; }
   1210 
   1211   void ActOnComment(SourceRange Comment);
   1212 
   1213   //===--------------------------------------------------------------------===//
   1214   // Type Analysis / Processing: SemaType.cpp.
   1215   //
   1216 
   1217   QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs,
   1218                               const DeclSpec *DS = nullptr);
   1219   QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVRA,
   1220                               const DeclSpec *DS = nullptr);
   1221   QualType BuildPointerType(QualType T,
   1222                             SourceLocation Loc, DeclarationName Entity);
   1223   QualType BuildReferenceType(QualType T, bool LValueRef,
   1224                               SourceLocation Loc, DeclarationName Entity);
   1225   QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
   1226                           Expr *ArraySize, unsigned Quals,
   1227                           SourceRange Brackets, DeclarationName Entity);
   1228   QualType BuildExtVectorType(QualType T, Expr *ArraySize,
   1229                               SourceLocation AttrLoc);
   1230 
   1231   bool CheckFunctionReturnType(QualType T, SourceLocation Loc);
   1232 
   1233   /// \brief Build a function type.
   1234   ///
   1235   /// This routine checks the function type according to C++ rules and
   1236   /// under the assumption that the result type and parameter types have
   1237   /// just been instantiated from a template. It therefore duplicates
   1238   /// some of the behavior of GetTypeForDeclarator, but in a much
   1239   /// simpler form that is only suitable for this narrow use case.
   1240   ///
   1241   /// \param T The return type of the function.
   1242   ///
   1243   /// \param ParamTypes The parameter types of the function. This array
   1244   /// will be modified to account for adjustments to the types of the
   1245   /// function parameters.
   1246   ///
   1247   /// \param Loc The location of the entity whose type involves this
   1248   /// function type or, if there is no such entity, the location of the
   1249   /// type that will have function type.
   1250   ///
   1251   /// \param Entity The name of the entity that involves the function
   1252   /// type, if known.
   1253   ///
   1254   /// \param EPI Extra information about the function type. Usually this will
   1255   /// be taken from an existing function with the same prototype.
   1256   ///
   1257   /// \returns A suitable function type, if there are no errors. The
   1258   /// unqualified type will always be a FunctionProtoType.
   1259   /// Otherwise, returns a NULL type.
   1260   QualType BuildFunctionType(QualType T,
   1261                              MutableArrayRef<QualType> ParamTypes,
   1262                              SourceLocation Loc, DeclarationName Entity,
   1263                              const FunctionProtoType::ExtProtoInfo &EPI);
   1264 
   1265   QualType BuildMemberPointerType(QualType T, QualType Class,
   1266                                   SourceLocation Loc,
   1267                                   DeclarationName Entity);
   1268   QualType BuildBlockPointerType(QualType T,
   1269                                  SourceLocation Loc, DeclarationName Entity);
   1270   QualType BuildParenType(QualType T);
   1271   QualType BuildAtomicType(QualType T, SourceLocation Loc);
   1272 
   1273   TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S);
   1274   TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy);
   1275   TypeSourceInfo *GetTypeSourceInfoForDeclarator(Declarator &D, QualType T,
   1276                                                TypeSourceInfo *ReturnTypeInfo);
   1277 
   1278   /// \brief Package the given type and TSI into a ParsedType.
   1279   ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo);
   1280   DeclarationNameInfo GetNameForDeclarator(Declarator &D);
   1281   DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name);
   1282   static QualType GetTypeFromParser(ParsedType Ty,
   1283                                     TypeSourceInfo **TInfo = nullptr);
   1284   CanThrowResult canThrow(const Expr *E);
   1285   const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc,
   1286                                                 const FunctionProtoType *FPT);
   1287   void UpdateExceptionSpec(FunctionDecl *FD,
   1288                            const FunctionProtoType::ExceptionSpecInfo &ESI);
   1289   bool CheckSpecifiedExceptionType(QualType &T, SourceRange Range);
   1290   bool CheckDistantExceptionSpec(QualType T);
   1291   bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New);
   1292   bool CheckEquivalentExceptionSpec(
   1293       const FunctionProtoType *Old, SourceLocation OldLoc,
   1294       const FunctionProtoType *New, SourceLocation NewLoc);
   1295   bool CheckEquivalentExceptionSpec(
   1296       const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
   1297       const FunctionProtoType *Old, SourceLocation OldLoc,
   1298       const FunctionProtoType *New, SourceLocation NewLoc,
   1299       bool *MissingExceptionSpecification = nullptr,
   1300       bool *MissingEmptyExceptionSpecification = nullptr,
   1301       bool AllowNoexceptAllMatchWithNoSpec = false,
   1302       bool IsOperatorNew = false);
   1303   bool CheckExceptionSpecSubset(
   1304       const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
   1305       const FunctionProtoType *Superset, SourceLocation SuperLoc,
   1306       const FunctionProtoType *Subset, SourceLocation SubLoc);
   1307   bool CheckParamExceptionSpec(const PartialDiagnostic & NoteID,
   1308       const FunctionProtoType *Target, SourceLocation TargetLoc,
   1309       const FunctionProtoType *Source, SourceLocation SourceLoc);
   1310 
   1311   TypeResult ActOnTypeName(Scope *S, Declarator &D);
   1312 
   1313   /// \brief The parser has parsed the context-sensitive type 'instancetype'
   1314   /// in an Objective-C message declaration. Return the appropriate type.
   1315   ParsedType ActOnObjCInstanceType(SourceLocation Loc);
   1316 
   1317   /// \brief Abstract class used to diagnose incomplete types.
   1318   struct TypeDiagnoser {
   1319     TypeDiagnoser() {}
   1320 
   1321     virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0;
   1322     virtual ~TypeDiagnoser() {}
   1323   };
   1324 
   1325   static int getPrintable(int I) { return I; }
   1326   static unsigned getPrintable(unsigned I) { return I; }
   1327   static bool getPrintable(bool B) { return B; }
   1328   static const char * getPrintable(const char *S) { return S; }
   1329   static StringRef getPrintable(StringRef S) { return S; }
   1330   static const std::string &getPrintable(const std::string &S) { return S; }
   1331   static const IdentifierInfo *getPrintable(const IdentifierInfo *II) {
   1332     return II;
   1333   }
   1334   static DeclarationName getPrintable(DeclarationName N) { return N; }
   1335   static QualType getPrintable(QualType T) { return T; }
   1336   static SourceRange getPrintable(SourceRange R) { return R; }
   1337   static SourceRange getPrintable(SourceLocation L) { return L; }
   1338   static SourceRange getPrintable(const Expr *E) { return E->getSourceRange(); }
   1339   static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();}
   1340 
   1341   template <typename... Ts> class BoundTypeDiagnoser : public TypeDiagnoser {
   1342     unsigned DiagID;
   1343     std::tuple<const Ts &...> Args;
   1344 
   1345     template <std::size_t... Is>
   1346     void emit(const SemaDiagnosticBuilder &DB,
   1347               llvm::index_sequence<Is...>) const {
   1348       // Apply all tuple elements to the builder in order.
   1349       bool Dummy[] = {false, (DB << getPrintable(std::get<Is>(Args)))...};
   1350       (void)Dummy;
   1351     }
   1352 
   1353   public:
   1354     BoundTypeDiagnoser(unsigned DiagID, const Ts &...Args)
   1355         : TypeDiagnoser(), DiagID(DiagID), Args(Args...) {
   1356       assert(DiagID != 0 && "no diagnostic for type diagnoser");
   1357     }
   1358 
   1359     void diagnose(Sema &S, SourceLocation Loc, QualType T) override {
   1360       const SemaDiagnosticBuilder &DB = S.Diag(Loc, DiagID);
   1361       emit(DB, llvm::index_sequence_for<Ts...>());
   1362       DB << T;
   1363     }
   1364   };
   1365 
   1366 private:
   1367   bool RequireCompleteTypeImpl(SourceLocation Loc, QualType T,
   1368                                TypeDiagnoser *Diagnoser);
   1369 
   1370   VisibleModuleSet VisibleModules;
   1371   llvm::SmallVector<VisibleModuleSet, 16> VisibleModulesStack;
   1372 
   1373   Module *CachedFakeTopLevelModule;
   1374 
   1375 public:
   1376   /// \brief Get the module owning an entity.
   1377   Module *getOwningModule(Decl *Entity);
   1378 
   1379   /// \brief Make a merged definition of an existing hidden definition \p ND
   1380   /// visible at the specified location.
   1381   void makeMergedDefinitionVisible(NamedDecl *ND, SourceLocation Loc);
   1382 
   1383   bool isModuleVisible(Module *M) { return VisibleModules.isVisible(M); }
   1384 
   1385   /// Determine whether a declaration is visible to name lookup.
   1386   bool isVisible(const NamedDecl *D) {
   1387     return !D->isHidden() || isVisibleSlow(D);
   1388   }
   1389   bool hasVisibleMergedDefinition(NamedDecl *Def);
   1390 
   1391   /// Determine if \p D has a visible definition. If not, suggest a declaration
   1392   /// that should be made visible to expose the definition.
   1393   bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested,
   1394                             bool OnlyNeedComplete = false);
   1395   bool hasVisibleDefinition(const NamedDecl *D) {
   1396     NamedDecl *Hidden;
   1397     return hasVisibleDefinition(const_cast<NamedDecl*>(D), &Hidden);
   1398   }
   1399 
   1400   /// Determine if the template parameter \p D has a visible default argument.
   1401   bool
   1402   hasVisibleDefaultArgument(const NamedDecl *D,
   1403                             llvm::SmallVectorImpl<Module *> *Modules = nullptr);
   1404 
   1405   /// Determine if \p A and \p B are equivalent internal linkage declarations
   1406   /// from different modules, and thus an ambiguity error can be downgraded to
   1407   /// an extension warning.
   1408   bool isEquivalentInternalLinkageDeclaration(const NamedDecl *A,
   1409                                               const NamedDecl *B);
   1410   void diagnoseEquivalentInternalLinkageDeclarations(
   1411       SourceLocation Loc, const NamedDecl *D,
   1412       ArrayRef<const NamedDecl *> Equiv);
   1413 
   1414   bool isCompleteType(SourceLocation Loc, QualType T) {
   1415     return !RequireCompleteTypeImpl(Loc, T, nullptr);
   1416   }
   1417   bool RequireCompleteType(SourceLocation Loc, QualType T,
   1418                            TypeDiagnoser &Diagnoser);
   1419   bool RequireCompleteType(SourceLocation Loc, QualType T,
   1420                            unsigned DiagID);
   1421 
   1422   template <typename... Ts>
   1423   bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID,
   1424                            const Ts &...Args) {
   1425     BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...);
   1426     return RequireCompleteType(Loc, T, Diagnoser);
   1427   }
   1428 
   1429   void completeExprArrayBound(Expr *E);
   1430   bool RequireCompleteExprType(Expr *E, TypeDiagnoser &Diagnoser);
   1431   bool RequireCompleteExprType(Expr *E, unsigned DiagID);
   1432 
   1433   template <typename... Ts>
   1434   bool RequireCompleteExprType(Expr *E, unsigned DiagID, const Ts &...Args) {
   1435     BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...);
   1436     return RequireCompleteExprType(E, Diagnoser);
   1437   }
   1438 
   1439   bool RequireLiteralType(SourceLocation Loc, QualType T,
   1440                           TypeDiagnoser &Diagnoser);
   1441   bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID);
   1442 
   1443   template <typename... Ts>
   1444   bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID,
   1445                           const Ts &...Args) {
   1446     BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...);
   1447     return RequireLiteralType(Loc, T, Diagnoser);
   1448   }
   1449 
   1450   QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
   1451                              const CXXScopeSpec &SS, QualType T);
   1452 
   1453   QualType BuildTypeofExprType(Expr *E, SourceLocation Loc);
   1454   /// If AsUnevaluated is false, E is treated as though it were an evaluated
   1455   /// context, such as when building a type for decltype(auto).
   1456   QualType BuildDecltypeType(Expr *E, SourceLocation Loc,
   1457                              bool AsUnevaluated = true);
   1458   QualType BuildUnaryTransformType(QualType BaseType,
   1459                                    UnaryTransformType::UTTKind UKind,
   1460                                    SourceLocation Loc);
   1461 
   1462   //===--------------------------------------------------------------------===//
   1463   // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
   1464   //
   1465 
   1466   struct SkipBodyInfo {
   1467     SkipBodyInfo() : ShouldSkip(false), Previous(nullptr) {}
   1468     bool ShouldSkip;
   1469     NamedDecl *Previous;
   1470   };
   1471 
   1472   /// List of decls defined in a function prototype. This contains EnumConstants
   1473   /// that incorrectly end up in translation unit scope because there is no
   1474   /// function to pin them on. ActOnFunctionDeclarator reads this list and patches
   1475   /// them into the FunctionDecl.
   1476   std::vector<NamedDecl*> DeclsInPrototypeScope;
   1477 
   1478   DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = nullptr);
   1479 
   1480   void DiagnoseUseOfUnimplementedSelectors();
   1481 
   1482   bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
   1483 
   1484   ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
   1485                          Scope *S, CXXScopeSpec *SS = nullptr,
   1486                          bool isClassName = false,
   1487                          bool HasTrailingDot = false,
   1488                          ParsedType ObjectType = ParsedType(),
   1489                          bool IsCtorOrDtorName = false,
   1490                          bool WantNontrivialTypeSourceInfo = false,
   1491                          IdentifierInfo **CorrectedII = nullptr);
   1492   TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S);
   1493   bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S);
   1494   void DiagnoseUnknownTypeName(IdentifierInfo *&II,
   1495                                SourceLocation IILoc,
   1496                                Scope *S,
   1497                                CXXScopeSpec *SS,
   1498                                ParsedType &SuggestedType,
   1499                                bool AllowClassTemplates = false);
   1500 
   1501   /// \brief For compatibility with MSVC, we delay parsing of some default
   1502   /// template type arguments until instantiation time.  Emits a warning and
   1503   /// returns a synthesized DependentNameType that isn't really dependent on any
   1504   /// other template arguments.
   1505   ParsedType ActOnDelayedDefaultTemplateArg(const IdentifierInfo &II,
   1506                                             SourceLocation NameLoc);
   1507 
   1508   /// \brief Describes the result of the name lookup and resolution performed
   1509   /// by \c ClassifyName().
   1510   enum NameClassificationKind {
   1511     NC_Unknown,
   1512     NC_Error,
   1513     NC_Keyword,
   1514     NC_Type,
   1515     NC_Expression,
   1516     NC_NestedNameSpecifier,
   1517     NC_TypeTemplate,
   1518     NC_VarTemplate,
   1519     NC_FunctionTemplate
   1520   };
   1521 
   1522   class NameClassification {
   1523     NameClassificationKind Kind;
   1524     ExprResult Expr;
   1525     TemplateName Template;
   1526     ParsedType Type;
   1527     const IdentifierInfo *Keyword;
   1528 
   1529     explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {}
   1530 
   1531   public:
   1532     NameClassification(ExprResult Expr) : Kind(NC_Expression), Expr(Expr) {}
   1533 
   1534     NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {}
   1535 
   1536     NameClassification(const IdentifierInfo *Keyword)
   1537       : Kind(NC_Keyword), Keyword(Keyword) { }
   1538 
   1539     static NameClassification Error() {
   1540       return NameClassification(NC_Error);
   1541     }
   1542 
   1543     static NameClassification Unknown() {
   1544       return NameClassification(NC_Unknown);
   1545     }
   1546 
   1547     static NameClassification NestedNameSpecifier() {
   1548       return NameClassification(NC_NestedNameSpecifier);
   1549     }
   1550 
   1551     static NameClassification TypeTemplate(TemplateName Name) {
   1552       NameClassification Result(NC_TypeTemplate);
   1553       Result.Template = Name;
   1554       return Result;
   1555     }
   1556 
   1557     static NameClassification VarTemplate(TemplateName Name) {
   1558       NameClassification Result(NC_VarTemplate);
   1559       Result.Template = Name;
   1560       return Result;
   1561     }
   1562 
   1563     static NameClassification FunctionTemplate(TemplateName Name) {
   1564       NameClassification Result(NC_FunctionTemplate);
   1565       Result.Template = Name;
   1566       return Result;
   1567     }
   1568 
   1569     NameClassificationKind getKind() const { return Kind; }
   1570 
   1571     ParsedType getType() const {
   1572       assert(Kind == NC_Type);
   1573       return Type;
   1574     }
   1575 
   1576     ExprResult getExpression() const {
   1577       assert(Kind == NC_Expression);
   1578       return Expr;
   1579     }
   1580 
   1581     TemplateName getTemplateName() const {
   1582       assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate ||
   1583              Kind == NC_VarTemplate);
   1584       return Template;
   1585     }
   1586 
   1587     TemplateNameKind getTemplateNameKind() const {
   1588       switch (Kind) {
   1589       case NC_TypeTemplate:
   1590         return TNK_Type_template;
   1591       case NC_FunctionTemplate:
   1592         return TNK_Function_template;
   1593       case NC_VarTemplate:
   1594         return TNK_Var_template;
   1595       default:
   1596         llvm_unreachable("unsupported name classification.");
   1597       }
   1598     }
   1599   };
   1600 
   1601   /// \brief Perform name lookup on the given name, classifying it based on
   1602   /// the results of name lookup and the following token.
   1603   ///
   1604   /// This routine is used by the parser to resolve identifiers and help direct
   1605   /// parsing. When the identifier cannot be found, this routine will attempt
   1606   /// to correct the typo and classify based on the resulting name.
   1607   ///
   1608   /// \param S The scope in which we're performing name lookup.
   1609   ///
   1610   /// \param SS The nested-name-specifier that precedes the name.
   1611   ///
   1612   /// \param Name The identifier. If typo correction finds an alternative name,
   1613   /// this pointer parameter will be updated accordingly.
   1614   ///
   1615   /// \param NameLoc The location of the identifier.
   1616   ///
   1617   /// \param NextToken The token following the identifier. Used to help
   1618   /// disambiguate the name.
   1619   ///
   1620   /// \param IsAddressOfOperand True if this name is the operand of a unary
   1621   ///        address of ('&') expression, assuming it is classified as an
   1622   ///        expression.
   1623   ///
   1624   /// \param CCC The correction callback, if typo correction is desired.
   1625   NameClassification
   1626   ClassifyName(Scope *S, CXXScopeSpec &SS, IdentifierInfo *&Name,
   1627                SourceLocation NameLoc, const Token &NextToken,
   1628                bool IsAddressOfOperand,
   1629                std::unique_ptr<CorrectionCandidateCallback> CCC = nullptr);
   1630 
   1631   Decl *ActOnDeclarator(Scope *S, Declarator &D);
   1632 
   1633   NamedDecl *HandleDeclarator(Scope *S, Declarator &D,
   1634                               MultiTemplateParamsArg TemplateParameterLists);
   1635   void RegisterLocallyScopedExternCDecl(NamedDecl *ND, Scope *S);
   1636   bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info);
   1637   bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC,
   1638                                     DeclarationName Name,
   1639                                     SourceLocation Loc);
   1640   void
   1641   diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals,
   1642                             SourceLocation FallbackLoc,
   1643                             SourceLocation ConstQualLoc = SourceLocation(),
   1644                             SourceLocation VolatileQualLoc = SourceLocation(),
   1645                             SourceLocation RestrictQualLoc = SourceLocation(),
   1646                             SourceLocation AtomicQualLoc = SourceLocation());
   1647 
   1648   static bool adjustContextForLocalExternDecl(DeclContext *&DC);
   1649   void DiagnoseFunctionSpecifiers(const DeclSpec &DS);
   1650   void CheckShadow(Scope *S, VarDecl *D, const LookupResult& R);
   1651   void CheckShadow(Scope *S, VarDecl *D);
   1652   void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange);
   1653   void handleTagNumbering(const TagDecl *Tag, Scope *TagScope);
   1654   void setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec,
   1655                                     TypedefNameDecl *NewTD);
   1656   void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D);
   1657   NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
   1658                                     TypeSourceInfo *TInfo,
   1659                                     LookupResult &Previous);
   1660   NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D,
   1661                                   LookupResult &Previous, bool &Redeclaration);
   1662   NamedDecl *ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
   1663                                      TypeSourceInfo *TInfo,
   1664                                      LookupResult &Previous,
   1665                                      MultiTemplateParamsArg TemplateParamLists,
   1666                                      bool &AddToScope);
   1667   // Returns true if the variable declaration is a redeclaration
   1668   bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous);
   1669   void CheckVariableDeclarationType(VarDecl *NewVD);
   1670   void CheckCompleteVariableDeclaration(VarDecl *var);
   1671   void MaybeSuggestAddingStaticToDecl(const FunctionDecl *D);
   1672 
   1673   NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
   1674                                      TypeSourceInfo *TInfo,
   1675                                      LookupResult &Previous,
   1676                                      MultiTemplateParamsArg TemplateParamLists,
   1677                                      bool &AddToScope);
   1678   bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD);
   1679 
   1680   bool CheckConstexprFunctionDecl(const FunctionDecl *FD);
   1681   bool CheckConstexprFunctionBody(const FunctionDecl *FD, Stmt *Body);
   1682 
   1683   void DiagnoseHiddenVirtualMethods(CXXMethodDecl *MD);
   1684   void FindHiddenVirtualMethods(CXXMethodDecl *MD,
   1685                           SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods);
   1686   void NoteHiddenVirtualMethods(CXXMethodDecl *MD,
   1687                           SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods);
   1688   // Returns true if the function declaration is a redeclaration
   1689   bool CheckFunctionDeclaration(Scope *S,
   1690                                 FunctionDecl *NewFD, LookupResult &Previous,
   1691                                 bool IsExplicitSpecialization);
   1692   void CheckMain(FunctionDecl *FD, const DeclSpec &D);
   1693   void CheckMSVCRTEntryPoint(FunctionDecl *FD);
   1694   Decl *ActOnParamDeclarator(Scope *S, Declarator &D);
   1695   ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC,
   1696                                           SourceLocation Loc,
   1697                                           QualType T);
   1698   ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc,
   1699                               SourceLocation NameLoc, IdentifierInfo *Name,
   1700                               QualType T, TypeSourceInfo *TSInfo,
   1701                               StorageClass SC);
   1702   void ActOnParamDefaultArgument(Decl *param,
   1703                                  SourceLocation EqualLoc,
   1704                                  Expr *defarg);
   1705   void ActOnParamUnparsedDefaultArgument(Decl *param,
   1706                                          SourceLocation EqualLoc,
   1707                                          SourceLocation ArgLoc);
   1708   void ActOnParamDefaultArgumentError(Decl *param, SourceLocation EqualLoc);
   1709   bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg,
   1710                                SourceLocation EqualLoc);
   1711 
   1712   void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit,
   1713                             bool TypeMayContainAuto);
   1714   void ActOnUninitializedDecl(Decl *dcl, bool TypeMayContainAuto);
   1715   void ActOnInitializerError(Decl *Dcl);
   1716   void ActOnPureSpecifier(Decl *D, SourceLocation PureSpecLoc);
   1717   void ActOnCXXForRangeDecl(Decl *D);
   1718   StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc,
   1719                                         IdentifierInfo *Ident,
   1720                                         ParsedAttributes &Attrs,
   1721                                         SourceLocation AttrEnd);
   1722   void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc);
   1723   void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc);
   1724   void FinalizeDeclaration(Decl *D);
   1725   DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS,
   1726                                          ArrayRef<Decl *> Group);
   1727   DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef<Decl *> Group,
   1728                                       bool TypeMayContainAuto = true);
   1729 
   1730   /// Should be called on all declarations that might have attached
   1731   /// documentation comments.
   1732   void ActOnDocumentableDecl(Decl *D);
   1733   void ActOnDocumentableDecls(ArrayRef<Decl *> Group);
   1734 
   1735   void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
   1736                                        SourceLocation LocAfterDecls);
   1737   void CheckForFunctionRedefinition(
   1738       FunctionDecl *FD, const FunctionDecl *EffectiveDefinition = nullptr,
   1739       SkipBodyInfo *SkipBody = nullptr);
   1740   Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D,
   1741                                 MultiTemplateParamsArg TemplateParamLists,
   1742                                 SkipBodyInfo *SkipBody = nullptr);
   1743   Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D,
   1744                                 SkipBodyInfo *SkipBody = nullptr);
   1745   void ActOnStartOfObjCMethodDef(Scope *S, Decl *D);
   1746   bool isObjCMethodDecl(Decl *D) {
   1747     return D && isa<ObjCMethodDecl>(D);
   1748   }
   1749 
   1750   /// \brief Determine whether we can delay parsing the body of a function or
   1751   /// function template until it is used, assuming we don't care about emitting
   1752   /// code for that function.
   1753   ///
   1754   /// This will be \c false if we may need the body of the function in the
   1755   /// middle of parsing an expression (where it's impractical to switch to
   1756   /// parsing a different function), for instance, if it's constexpr in C++11
   1757   /// or has an 'auto' return type in C++14. These cases are essentially bugs.
   1758   bool canDelayFunctionBody(const Declarator &D);
   1759 
   1760   /// \brief Determine whether we can skip parsing the body of a function
   1761   /// definition, assuming we don't care about analyzing its body or emitting
   1762   /// code for that function.
   1763   ///
   1764   /// This will be \c false only if we may need the body of the function in
   1765   /// order to parse the rest of the program (for instance, if it is
   1766   /// \c constexpr in C++11 or has an 'auto' return type in C++14).
   1767   bool canSkipFunctionBody(Decl *D);
   1768 
   1769   void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope);
   1770   Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body);
   1771   Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation);
   1772   Decl *ActOnSkippedFunctionBody(Decl *Decl);
   1773   void ActOnFinishInlineMethodDef(CXXMethodDecl *D);
   1774 
   1775   /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an
   1776   /// attribute for which parsing is delayed.
   1777   void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs);
   1778 
   1779   /// \brief Diagnose any unused parameters in the given sequence of
   1780   /// ParmVarDecl pointers.
   1781   void DiagnoseUnusedParameters(ParmVarDecl * const *Begin,
   1782                                 ParmVarDecl * const *End);
   1783 
   1784   /// \brief Diagnose whether the size of parameters or return value of a
   1785   /// function or obj-c method definition is pass-by-value and larger than a
   1786   /// specified threshold.
   1787   void DiagnoseSizeOfParametersAndReturnValue(ParmVarDecl * const *Begin,
   1788                                               ParmVarDecl * const *End,
   1789                                               QualType ReturnTy,
   1790                                               NamedDecl *D);
   1791 
   1792   void DiagnoseInvalidJumps(Stmt *Body);
   1793   Decl *ActOnFileScopeAsmDecl(Expr *expr,
   1794                               SourceLocation AsmLoc,
   1795                               SourceLocation RParenLoc);
   1796 
   1797   /// \brief Handle a C++11 empty-declaration and attribute-declaration.
   1798   Decl *ActOnEmptyDeclaration(Scope *S,
   1799                               AttributeList *AttrList,
   1800                               SourceLocation SemiLoc);
   1801 
   1802   /// \brief The parser has processed a module import declaration.
   1803   ///
   1804   /// \param AtLoc The location of the '@' symbol, if any.
   1805   ///
   1806   /// \param ImportLoc The location of the 'import' keyword.
   1807   ///
   1808   /// \param Path The module access path.
   1809   DeclResult ActOnModuleImport(SourceLocation AtLoc, SourceLocation ImportLoc,
   1810                                ModuleIdPath Path);
   1811 
   1812   /// \brief The parser has processed a module import translated from a
   1813   /// #include or similar preprocessing directive.
   1814   void ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod);
   1815 
   1816   /// \brief The parsed has entered a submodule.
   1817   void ActOnModuleBegin(SourceLocation DirectiveLoc, Module *Mod);
   1818   /// \brief The parser has left a submodule.
   1819   void ActOnModuleEnd(SourceLocation DirectiveLoc, Module *Mod);
   1820 
   1821   /// \brief Check if module import may be found in the current context,
   1822   /// emit error if not.
   1823   void diagnoseMisplacedModuleImport(Module *M, SourceLocation ImportLoc);
   1824 
   1825   /// \brief Create an implicit import of the given module at the given
   1826   /// source location, for error recovery, if possible.
   1827   ///
   1828   /// This routine is typically used when an entity found by name lookup
   1829   /// is actually hidden within a module that we know about but the user
   1830   /// has forgotten to import.
   1831   void createImplicitModuleImportForErrorRecovery(SourceLocation Loc,
   1832                                                   Module *Mod);
   1833 
   1834   /// Kinds of missing import. Note, the values of these enumerators correspond
   1835   /// to %select values in diagnostics.
   1836   enum class MissingImportKind {
   1837     Declaration,
   1838     Definition,
   1839     DefaultArgument
   1840   };
   1841 
   1842   /// \brief Diagnose that the specified declaration needs to be visible but
   1843   /// isn't, and suggest a module import that would resolve the problem.
   1844   void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl,
   1845                              bool NeedDefinition, bool Recover = true);
   1846   void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl,
   1847                              SourceLocation DeclLoc, ArrayRef<Module *> Modules,
   1848                              MissingImportKind MIK, bool Recover);
   1849 
   1850   /// \brief Retrieve a suitable printing policy.
   1851   PrintingPolicy getPrintingPolicy() const {
   1852     return getPrintingPolicy(Context, PP);
   1853   }
   1854 
   1855   /// \brief Retrieve a suitable printing policy.
   1856   static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx,
   1857                                           const Preprocessor &PP);
   1858 
   1859   /// Scope actions.
   1860   void ActOnPopScope(SourceLocation Loc, Scope *S);
   1861   void ActOnTranslationUnitScope(Scope *S);
   1862 
   1863   Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
   1864                                    DeclSpec &DS);
   1865   Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
   1866                                    DeclSpec &DS,
   1867                                    MultiTemplateParamsArg TemplateParams,
   1868                                    bool IsExplicitInstantiation = false);
   1869 
   1870   Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
   1871                                     AccessSpecifier AS,
   1872                                     RecordDecl *Record,
   1873                                     const PrintingPolicy &Policy);
   1874 
   1875   Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS,
   1876                                        RecordDecl *Record);
   1877 
   1878   bool isAcceptableTagRedeclaration(const TagDecl *Previous,
   1879                                     TagTypeKind NewTag, bool isDefinition,
   1880                                     SourceLocation NewTagLoc,
   1881                                     const IdentifierInfo *Name);
   1882 
   1883   enum TagUseKind {
   1884     TUK_Reference,   // Reference to a tag:  'struct foo *X;'
   1885     TUK_Declaration, // Fwd decl of a tag:   'struct foo;'
   1886     TUK_Definition,  // Definition of a tag: 'struct foo { int X; } Y;'
   1887     TUK_Friend       // Friend declaration:  'friend struct foo;'
   1888   };
   1889 
   1890   Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
   1891                  SourceLocation KWLoc, CXXScopeSpec &SS,
   1892                  IdentifierInfo *Name, SourceLocation NameLoc,
   1893                  AttributeList *Attr, AccessSpecifier AS,
   1894                  SourceLocation ModulePrivateLoc,
   1895                  MultiTemplateParamsArg TemplateParameterLists,
   1896                  bool &OwnedDecl, bool &IsDependent,
   1897                  SourceLocation ScopedEnumKWLoc,
   1898                  bool ScopedEnumUsesClassTag, TypeResult UnderlyingType,
   1899                  bool IsTypeSpecifier, SkipBodyInfo *SkipBody = nullptr);
   1900 
   1901   Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc,
   1902                                 unsigned TagSpec, SourceLocation TagLoc,
   1903                                 CXXScopeSpec &SS,
   1904                                 IdentifierInfo *Name, SourceLocation NameLoc,
   1905                                 AttributeList *Attr,
   1906                                 MultiTemplateParamsArg TempParamLists);
   1907 
   1908   TypeResult ActOnDependentTag(Scope *S,
   1909                                unsigned TagSpec,
   1910                                TagUseKind TUK,
   1911                                const CXXScopeSpec &SS,
   1912                                IdentifierInfo *Name,
   1913                                SourceLocation TagLoc,
   1914                                SourceLocation NameLoc);
   1915 
   1916   void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart,
   1917                  IdentifierInfo *ClassName,
   1918                  SmallVectorImpl<Decl *> &Decls);
   1919   Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart,
   1920                    Declarator &D, Expr *BitfieldWidth);
   1921 
   1922   FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
   1923                          Declarator &D, Expr *BitfieldWidth,
   1924                          InClassInitStyle InitStyle,
   1925                          AccessSpecifier AS);
   1926   MSPropertyDecl *HandleMSProperty(Scope *S, RecordDecl *TagD,
   1927                                    SourceLocation DeclStart,
   1928                                    Declarator &D, Expr *BitfieldWidth,
   1929                                    InClassInitStyle InitStyle,
   1930                                    AccessSpecifier AS,
   1931                                    AttributeList *MSPropertyAttr);
   1932 
   1933   FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T,
   1934                             TypeSourceInfo *TInfo,
   1935                             RecordDecl *Record, SourceLocation Loc,
   1936                             bool Mutable, Expr *BitfieldWidth,
   1937                             InClassInitStyle InitStyle,
   1938                             SourceLocation TSSL,
   1939                             AccessSpecifier AS, NamedDecl *PrevDecl,
   1940                             Declarator *D = nullptr);
   1941 
   1942   bool CheckNontrivialField(FieldDecl *FD);
   1943   void DiagnoseNontrivial(const CXXRecordDecl *Record, CXXSpecialMember CSM);
   1944   bool SpecialMemberIsTrivial(CXXMethodDecl *MD, CXXSpecialMember CSM,
   1945                               bool Diagnose = false);
   1946   CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD);
   1947   void ActOnLastBitfield(SourceLocation DeclStart,
   1948                          SmallVectorImpl<Decl *> &AllIvarDecls);
   1949   Decl *ActOnIvar(Scope *S, SourceLocation DeclStart,
   1950                   Declarator &D, Expr *BitfieldWidth,
   1951                   tok::ObjCKeywordKind visibility);
   1952 
   1953   // This is used for both record definitions and ObjC interface declarations.
   1954   void ActOnFields(Scope* S, SourceLocation RecLoc, Decl *TagDecl,
   1955                    ArrayRef<Decl *> Fields,
   1956                    SourceLocation LBrac, SourceLocation RBrac,
   1957                    AttributeList *AttrList);
   1958 
   1959   /// ActOnTagStartDefinition - Invoked when we have entered the
   1960   /// scope of a tag's definition (e.g., for an enumeration, class,
   1961   /// struct, or union).
   1962   void ActOnTagStartDefinition(Scope *S, Decl *TagDecl);
   1963 
   1964   typedef void *SkippedDefinitionContext;
   1965 
   1966   /// \brief Invoked when we enter a tag definition that we're skipping.
   1967   SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD);
   1968 
   1969   Decl *ActOnObjCContainerStartDefinition(Decl *IDecl);
   1970 
   1971   /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a
   1972   /// C++ record definition's base-specifiers clause and are starting its
   1973   /// member declarations.
   1974   void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl,
   1975                                        SourceLocation FinalLoc,
   1976                                        bool IsFinalSpelledSealed,
   1977                                        SourceLocation LBraceLoc);
   1978 
   1979   /// ActOnTagFinishDefinition - Invoked once we have finished parsing
   1980   /// the definition of a tag (enumeration, class, struct, or union).
   1981   void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl,
   1982                                 SourceLocation RBraceLoc);
   1983 
   1984   void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context);
   1985 
   1986   void ActOnObjCContainerFinishDefinition();
   1987 
   1988   /// \brief Invoked when we must temporarily exit the objective-c container
   1989   /// scope for parsing/looking-up C constructs.
   1990   ///
   1991   /// Must be followed by a call to \see ActOnObjCReenterContainerContext
   1992   void ActOnObjCTemporaryExitContainerContext(DeclContext *DC);
   1993   void ActOnObjCReenterContainerContext(DeclContext *DC);
   1994 
   1995   /// ActOnTagDefinitionError - Invoked when there was an unrecoverable
   1996   /// error parsing the definition of a tag.
   1997   void ActOnTagDefinitionError(Scope *S, Decl *TagDecl);
   1998 
   1999   EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum,
   2000                                       EnumConstantDecl *LastEnumConst,
   2001                                       SourceLocation IdLoc,
   2002                                       IdentifierInfo *Id,
   2003                                       Expr *val);
   2004   bool CheckEnumUnderlyingType(TypeSourceInfo *TI);
   2005   bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped,
   2006                               QualType EnumUnderlyingTy,
   2007                               bool EnumUnderlyingIsImplicit,
   2008                               const EnumDecl *Prev);
   2009 
   2010   /// Determine whether the body of an anonymous enumeration should be skipped.
   2011   /// \param II The name of the first enumerator.
   2012   SkipBodyInfo shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II,
   2013                                       SourceLocation IILoc);
   2014 
   2015   Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant,
   2016                           SourceLocation IdLoc, IdentifierInfo *Id,
   2017                           AttributeList *Attrs,
   2018                           SourceLocation EqualLoc, Expr *Val);
   2019   void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc,
   2020                      SourceLocation RBraceLoc, Decl *EnumDecl,
   2021                      ArrayRef<Decl *> Elements,
   2022                      Scope *S, AttributeList *Attr);
   2023 
   2024   DeclContext *getContainingDC(DeclContext *DC);
   2025 
   2026   /// Set the current declaration context until it gets popped.
   2027   void PushDeclContext(Scope *S, DeclContext *DC);
   2028   void PopDeclContext();
   2029 
   2030   /// EnterDeclaratorContext - Used when we must lookup names in the context
   2031   /// of a declarator's nested name specifier.
   2032   void EnterDeclaratorContext(Scope *S, DeclContext *DC);
   2033   void ExitDeclaratorContext(Scope *S);
   2034 
   2035   /// Push the parameters of D, which must be a function, into scope.
   2036   void ActOnReenterFunctionContext(Scope* S, Decl* D);
   2037   void ActOnExitFunctionContext();
   2038 
   2039   DeclContext *getFunctionLevelDeclContext();
   2040 
   2041   /// getCurFunctionDecl - If inside of a function body, this returns a pointer
   2042   /// to the function decl for the function being parsed.  If we're currently
   2043   /// in a 'block', this returns the containing context.
   2044   FunctionDecl *getCurFunctionDecl();
   2045 
   2046   /// getCurMethodDecl - If inside of a method body, this returns a pointer to
   2047   /// the method decl for the method being parsed.  If we're currently
   2048   /// in a 'block', this returns the containing context.
   2049   ObjCMethodDecl *getCurMethodDecl();
   2050 
   2051   /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
   2052   /// or C function we're in, otherwise return null.  If we're currently
   2053   /// in a 'block', this returns the containing context.
   2054   NamedDecl *getCurFunctionOrMethodDecl();
   2055 
   2056   /// Add this decl to the scope shadowed decl chains.
   2057   void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true);
   2058 
   2059   /// \brief Make the given externally-produced declaration visible at the
   2060   /// top level scope.
   2061   ///
   2062   /// \param D The externally-produced declaration to push.
   2063   ///
   2064   /// \param Name The name of the externally-produced declaration.
   2065   void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name);
   2066 
   2067   /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
   2068   /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
   2069   /// true if 'D' belongs to the given declaration context.
   2070   ///
   2071   /// \param AllowInlineNamespace If \c true, allow the declaration to be in the
   2072   ///        enclosing namespace set of the context, rather than contained
   2073   ///        directly within it.
   2074   bool isDeclInScope(NamedDecl *D, DeclContext *Ctx, Scope *S = nullptr,
   2075                      bool AllowInlineNamespace = false);
   2076 
   2077   /// Finds the scope corresponding to the given decl context, if it
   2078   /// happens to be an enclosing scope.  Otherwise return NULL.
   2079   static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC);
   2080 
   2081   /// Subroutines of ActOnDeclarator().
   2082   TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
   2083                                 TypeSourceInfo *TInfo);
   2084   bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New);
   2085 
   2086   /// \brief Describes the kind of merge to perform for availability
   2087   /// attributes (including "deprecated", "unavailable", and "availability").
   2088   enum AvailabilityMergeKind {
   2089     /// \brief Don't merge availability attributes at all.
   2090     AMK_None,
   2091     /// \brief Merge availability attributes for a redeclaration, which requires
   2092     /// an exact match.
   2093     AMK_Redeclaration,
   2094     /// \brief Merge availability attributes for an override, which requires
   2095     /// an exact match or a weakening of constraints.
   2096     AMK_Override,
   2097     /// \brief Merge availability attributes for an implementation of
   2098     /// a protocol requirement.
   2099     AMK_ProtocolImplementation,
   2100   };
   2101 
   2102   /// Attribute merging methods. Return true if a new attribute was added.
   2103   AvailabilityAttr *mergeAvailabilityAttr(NamedDecl *D, SourceRange Range,
   2104                                           IdentifierInfo *Platform,
   2105                                           VersionTuple Introduced,
   2106                                           VersionTuple Deprecated,
   2107                                           VersionTuple Obsoleted,
   2108                                           bool IsUnavailable,
   2109                                           StringRef Message,
   2110                                           AvailabilityMergeKind AMK,
   2111                                           unsigned AttrSpellingListIndex);
   2112   TypeVisibilityAttr *mergeTypeVisibilityAttr(Decl *D, SourceRange Range,
   2113                                        TypeVisibilityAttr::VisibilityType Vis,
   2114                                               unsigned AttrSpellingListIndex);
   2115   VisibilityAttr *mergeVisibilityAttr(Decl *D, SourceRange Range,
   2116                                       VisibilityAttr::VisibilityType Vis,
   2117                                       unsigned AttrSpellingListIndex);
   2118   DLLImportAttr *mergeDLLImportAttr(Decl *D, SourceRange Range,
   2119                                     unsigned AttrSpellingListIndex);
   2120   DLLExportAttr *mergeDLLExportAttr(Decl *D, SourceRange Range,
   2121                                     unsigned AttrSpellingListIndex);
   2122   MSInheritanceAttr *
   2123   mergeMSInheritanceAttr(Decl *D, SourceRange Range, bool BestCase,
   2124                          unsigned AttrSpellingListIndex,
   2125                          MSInheritanceAttr::Spelling SemanticSpelling);
   2126   FormatAttr *mergeFormatAttr(Decl *D, SourceRange Range,
   2127                               IdentifierInfo *Format, int FormatIdx,
   2128                               int FirstArg, unsigned AttrSpellingListIndex);
   2129   SectionAttr *mergeSectionAttr(Decl *D, SourceRange Range, StringRef Name,
   2130                                 unsigned AttrSpellingListIndex);
   2131   AlwaysInlineAttr *mergeAlwaysInlineAttr(Decl *D, SourceRange Range,
   2132                                           IdentifierInfo *Ident,
   2133                                           unsigned AttrSpellingListIndex);
   2134   MinSizeAttr *mergeMinSizeAttr(Decl *D, SourceRange Range,
   2135                                 unsigned AttrSpellingListIndex);
   2136   OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D, SourceRange Range,
   2137                                           unsigned AttrSpellingListIndex);
   2138   InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, SourceRange Range,
   2139                                                 IdentifierInfo *Ident,
   2140                                                 unsigned AttrSpellingListIndex);
   2141   CommonAttr *mergeCommonAttr(Decl *D, SourceRange Range, IdentifierInfo *Ident,
   2142                               unsigned AttrSpellingListIndex);
   2143 
   2144   void mergeDeclAttributes(NamedDecl *New, Decl *Old,
   2145                            AvailabilityMergeKind AMK = AMK_Redeclaration);
   2146   void MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New,
   2147                             LookupResult &OldDecls);
   2148   bool MergeFunctionDecl(FunctionDecl *New, NamedDecl *&Old, Scope *S,
   2149                          bool MergeTypeWithOld);
   2150   bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old,
   2151                                     Scope *S, bool MergeTypeWithOld);
   2152   void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old);
   2153   void MergeVarDecl(VarDecl *New, LookupResult &Previous);
   2154   void MergeVarDeclTypes(VarDecl *New, VarDecl *Old, bool MergeTypeWithOld);
   2155   void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old);
   2156   bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S);
   2157 
   2158   // AssignmentAction - This is used by all the assignment diagnostic functions
   2159   // to represent what is actually causing the operation
   2160   enum AssignmentAction {
   2161     AA_Assigning,
   2162     AA_Passing,
   2163     AA_Returning,
   2164     AA_Converting,
   2165     AA_Initializing,
   2166     AA_Sending,
   2167     AA_Casting,
   2168     AA_Passing_CFAudited
   2169   };
   2170 
   2171   /// C++ Overloading.
   2172   enum OverloadKind {
   2173     /// This is a legitimate overload: the existing declarations are
   2174     /// functions or function templates with different signatures.
   2175     Ovl_Overload,
   2176 
   2177     /// This is not an overload because the signature exactly matches
   2178     /// an existing declaration.
   2179     Ovl_Match,
   2180 
   2181     /// This is not an overload because the lookup results contain a
   2182     /// non-function.
   2183     Ovl_NonFunction
   2184   };
   2185   OverloadKind CheckOverload(Scope *S,
   2186                              FunctionDecl *New,
   2187                              const LookupResult &OldDecls,
   2188                              NamedDecl *&OldDecl,
   2189                              bool IsForUsingDecl);
   2190   bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl);
   2191 
   2192   /// \brief Checks availability of the function depending on the current
   2193   /// function context.Inside an unavailable function,unavailability is ignored.
   2194   ///
   2195   /// \returns true if \p FD is unavailable and current context is inside
   2196   /// an available function, false otherwise.
   2197   bool isFunctionConsideredUnavailable(FunctionDecl *FD);
   2198 
   2199   ImplicitConversionSequence
   2200   TryImplicitConversion(Expr *From, QualType ToType,
   2201                         bool SuppressUserConversions,
   2202                         bool AllowExplicit,
   2203                         bool InOverloadResolution,
   2204                         bool CStyle,
   2205                         bool AllowObjCWritebackConversion);
   2206 
   2207   bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
   2208   bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
   2209   bool IsComplexPromotion(QualType FromType, QualType ToType);
   2210   bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
   2211                            bool InOverloadResolution,
   2212                            QualType& ConvertedType, bool &IncompatibleObjC);
   2213   bool isObjCPointerConversion(QualType FromType, QualType ToType,
   2214                                QualType& ConvertedType, bool &IncompatibleObjC);
   2215   bool isObjCWritebackConversion(QualType FromType, QualType ToType,
   2216                                  QualType &ConvertedType);
   2217   bool IsBlockPointerConversion(QualType FromType, QualType ToType,
   2218                                 QualType& ConvertedType);
   2219   bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   2220                                   const FunctionProtoType *NewType,
   2221                                   unsigned *ArgPos = nullptr);
   2222   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
   2223                                   QualType FromType, QualType ToType);
   2224 
   2225   void maybeExtendBlockObject(ExprResult &E);
   2226   CastKind PrepareCastToObjCObjectPointer(ExprResult &E);
   2227   bool CheckPointerConversion(Expr *From, QualType ToType,
   2228                               CastKind &Kind,
   2229                               CXXCastPath& BasePath,
   2230                               bool IgnoreBaseAccess);
   2231   bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
   2232                                  bool InOverloadResolution,
   2233                                  QualType &ConvertedType);
   2234   bool CheckMemberPointerConversion(Expr *From, QualType ToType,
   2235                                     CastKind &Kind,
   2236                                     CXXCastPath &BasePath,
   2237                                     bool IgnoreBaseAccess);
   2238   bool IsQualificationConversion(QualType FromType, QualType ToType,
   2239                                  bool CStyle, bool &ObjCLifetimeConversion);
   2240   bool IsNoReturnConversion(QualType FromType, QualType ToType,
   2241                             QualType &ResultTy);
   2242   bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType);
   2243   bool isSameOrCompatibleFunctionType(CanQualType Param, CanQualType Arg);
   2244 
   2245   ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
   2246                                              const VarDecl *NRVOCandidate,
   2247                                              QualType ResultType,
   2248                                              Expr *Value,
   2249                                              bool AllowNRVO = true);
   2250 
   2251   bool CanPerformCopyInitialization(const InitializedEntity &Entity,
   2252                                     ExprResult Init);
   2253   ExprResult PerformCopyInitialization(const InitializedEntity &Entity,
   2254                                        SourceLocation EqualLoc,
   2255                                        ExprResult Init,
   2256                                        bool TopLevelOfInitList = false,
   2257                                        bool AllowExplicit = false);
   2258   ExprResult PerformObjectArgumentInitialization(Expr *From,
   2259                                                  NestedNameSpecifier *Qualifier,
   2260                                                  NamedDecl *FoundDecl,
   2261                                                  CXXMethodDecl *Method);
   2262 
   2263   ExprResult PerformContextuallyConvertToBool(Expr *From);
   2264   ExprResult PerformContextuallyConvertToObjCPointer(Expr *From);
   2265 
   2266   /// Contexts in which a converted constant expression is required.
   2267   enum CCEKind {
   2268     CCEK_CaseValue,   ///< Expression in a case label.
   2269     CCEK_Enumerator,  ///< Enumerator value with fixed underlying type.
   2270     CCEK_TemplateArg, ///< Value of a non-type template parameter.
   2271     CCEK_NewExpr      ///< Constant expression in a noptr-new-declarator.
   2272   };
   2273   ExprResult CheckConvertedConstantExpression(Expr *From, QualType T,
   2274                                               llvm::APSInt &Value, CCEKind CCE);
   2275   ExprResult CheckConvertedConstantExpression(Expr *From, QualType T,
   2276                                               APValue &Value, CCEKind CCE);
   2277 
   2278   /// \brief Abstract base class used to perform a contextual implicit
   2279   /// conversion from an expression to any type passing a filter.
   2280   class ContextualImplicitConverter {
   2281   public:
   2282     bool Suppress;
   2283     bool SuppressConversion;
   2284 
   2285     ContextualImplicitConverter(bool Suppress = false,
   2286                                 bool SuppressConversion = false)
   2287         : Suppress(Suppress), SuppressConversion(SuppressConversion) {}
   2288 
   2289     /// \brief Determine whether the specified type is a valid destination type
   2290     /// for this conversion.
   2291     virtual bool match(QualType T) = 0;
   2292 
   2293     /// \brief Emits a diagnostic complaining that the expression does not have
   2294     /// integral or enumeration type.
   2295     virtual SemaDiagnosticBuilder
   2296     diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) = 0;
   2297 
   2298     /// \brief Emits a diagnostic when the expression has incomplete class type.
   2299     virtual SemaDiagnosticBuilder
   2300     diagnoseIncomplete(Sema &S, SourceLocation Loc, QualType T) = 0;
   2301 
   2302     /// \brief Emits a diagnostic when the only matching conversion function
   2303     /// is explicit.
   2304     virtual SemaDiagnosticBuilder diagnoseExplicitConv(
   2305         Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0;
   2306 
   2307     /// \brief Emits a note for the explicit conversion function.
   2308     virtual SemaDiagnosticBuilder
   2309     noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0;
   2310 
   2311     /// \brief Emits a diagnostic when there are multiple possible conversion
   2312     /// functions.
   2313     virtual SemaDiagnosticBuilder
   2314     diagnoseAmbiguous(Sema &S, SourceLocation Loc, QualType T) = 0;
   2315 
   2316     /// \brief Emits a note for one of the candidate conversions.
   2317     virtual SemaDiagnosticBuilder
   2318     noteAmbiguous(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0;
   2319 
   2320     /// \brief Emits a diagnostic when we picked a conversion function
   2321     /// (for cases when we are not allowed to pick a conversion function).
   2322     virtual SemaDiagnosticBuilder diagnoseConversion(
   2323         Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0;
   2324 
   2325     virtual ~ContextualImplicitConverter() {}
   2326   };
   2327 
   2328   class ICEConvertDiagnoser : public ContextualImplicitConverter {
   2329     bool AllowScopedEnumerations;
   2330 
   2331   public:
   2332     ICEConvertDiagnoser(bool AllowScopedEnumerations,
   2333                         bool Suppress, bool SuppressConversion)
   2334         : ContextualImplicitConverter(Suppress, SuppressConversion),
   2335           AllowScopedEnumerations(AllowScopedEnumerations) {}
   2336 
   2337     /// Match an integral or (possibly scoped) enumeration type.
   2338     bool match(QualType T) override;
   2339 
   2340     SemaDiagnosticBuilder
   2341     diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) override {
   2342       return diagnoseNotInt(S, Loc, T);
   2343     }
   2344 
   2345     /// \brief Emits a diagnostic complaining that the expression does not have
   2346     /// integral or enumeration type.
   2347     virtual SemaDiagnosticBuilder
   2348     diagnoseNotInt(Sema &S, SourceLocation Loc, QualType T) = 0;
   2349   };
   2350 
   2351   /// Perform a contextual implicit conversion.
   2352   ExprResult PerformContextualImplicitConversion(
   2353       SourceLocation Loc, Expr *FromE, ContextualImplicitConverter &Converter);
   2354 
   2355 
   2356   enum ObjCSubscriptKind {
   2357     OS_Array,
   2358     OS_Dictionary,
   2359     OS_Error
   2360   };
   2361   ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE);
   2362 
   2363   // Note that LK_String is intentionally after the other literals, as
   2364   // this is used for diagnostics logic.
   2365   enum ObjCLiteralKind {
   2366     LK_Array,
   2367     LK_Dictionary,
   2368     LK_Numeric,
   2369     LK_Boxed,
   2370     LK_String,
   2371     LK_Block,
   2372     LK_None
   2373   };
   2374   ObjCLiteralKind CheckLiteralKind(Expr *FromE);
   2375 
   2376   ExprResult PerformObjectMemberConversion(Expr *From,
   2377                                            NestedNameSpecifier *Qualifier,
   2378                                            NamedDecl *FoundDecl,
   2379                                            NamedDecl *Member);
   2380 
   2381   // Members have to be NamespaceDecl* or TranslationUnitDecl*.
   2382   // TODO: make this is a typesafe union.
   2383   typedef llvm::SmallPtrSet<DeclContext   *, 16> AssociatedNamespaceSet;
   2384   typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet;
   2385 
   2386   void AddOverloadCandidate(FunctionDecl *Function,
   2387                             DeclAccessPair FoundDecl,
   2388                             ArrayRef<Expr *> Args,
   2389                             OverloadCandidateSet& CandidateSet,
   2390                             bool SuppressUserConversions = false,
   2391                             bool PartialOverloading = false,
   2392                             bool AllowExplicit = false);
   2393   void AddFunctionCandidates(const UnresolvedSetImpl &Functions,
   2394                       ArrayRef<Expr *> Args,
   2395                       OverloadCandidateSet &CandidateSet,
   2396                       TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr,
   2397                       bool SuppressUserConversions = false,
   2398                       bool PartialOverloading = false);
   2399   void AddMethodCandidate(DeclAccessPair FoundDecl,
   2400                           QualType ObjectType,
   2401                           Expr::Classification ObjectClassification,
   2402                           ArrayRef<Expr *> Args,
   2403                           OverloadCandidateSet& CandidateSet,
   2404                           bool SuppressUserConversion = false);
   2405   void AddMethodCandidate(CXXMethodDecl *Method,
   2406                           DeclAccessPair FoundDecl,
   2407                           CXXRecordDecl *ActingContext, QualType ObjectType,
   2408                           Expr::Classification ObjectClassification,
   2409                           ArrayRef<Expr *> Args,
   2410                           OverloadCandidateSet& CandidateSet,
   2411                           bool SuppressUserConversions = false,
   2412                           bool PartialOverloading = false);
   2413   void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl,
   2414                                   DeclAccessPair FoundDecl,
   2415                                   CXXRecordDecl *ActingContext,
   2416                                  TemplateArgumentListInfo *ExplicitTemplateArgs,
   2417                                   QualType ObjectType,
   2418                                   Expr::Classification ObjectClassification,
   2419                                   ArrayRef<Expr *> Args,
   2420                                   OverloadCandidateSet& CandidateSet,
   2421                                   bool SuppressUserConversions = false,
   2422                                   bool PartialOverloading = false);
   2423   void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate,
   2424                                     DeclAccessPair FoundDecl,
   2425                                  TemplateArgumentListInfo *ExplicitTemplateArgs,
   2426                                     ArrayRef<Expr *> Args,
   2427                                     OverloadCandidateSet& CandidateSet,
   2428                                     bool SuppressUserConversions = false,
   2429                                     bool PartialOverloading = false);
   2430   void AddConversionCandidate(CXXConversionDecl *Conversion,
   2431                               DeclAccessPair FoundDecl,
   2432                               CXXRecordDecl *ActingContext,
   2433                               Expr *From, QualType ToType,
   2434                               OverloadCandidateSet& CandidateSet,
   2435                               bool AllowObjCConversionOnExplicit);
   2436   void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate,
   2437                                       DeclAccessPair FoundDecl,
   2438                                       CXXRecordDecl *ActingContext,
   2439                                       Expr *From, QualType ToType,
   2440                                       OverloadCandidateSet &CandidateSet,
   2441                                       bool AllowObjCConversionOnExplicit);
   2442   void AddSurrogateCandidate(CXXConversionDecl *Conversion,
   2443                              DeclAccessPair FoundDecl,
   2444                              CXXRecordDecl *ActingContext,
   2445                              const FunctionProtoType *Proto,
   2446                              Expr *Object, ArrayRef<Expr *> Args,
   2447                              OverloadCandidateSet& CandidateSet);
   2448   void AddMemberOperatorCandidates(OverloadedOperatorKind Op,
   2449                                    SourceLocation OpLoc, ArrayRef<Expr *> Args,
   2450                                    OverloadCandidateSet& CandidateSet,
   2451                                    SourceRange OpRange = SourceRange());
   2452   void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
   2453                            ArrayRef<Expr *> Args,
   2454                            OverloadCandidateSet& CandidateSet,
   2455                            bool IsAssignmentOperator = false,
   2456                            unsigned NumContextualBoolArguments = 0);
   2457   void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
   2458                                     SourceLocation OpLoc, ArrayRef<Expr *> Args,
   2459                                     OverloadCandidateSet& CandidateSet);
   2460   void AddArgumentDependentLookupCandidates(DeclarationName Name,
   2461                                             SourceLocation Loc,
   2462                                             ArrayRef<Expr *> Args,
   2463                                 TemplateArgumentListInfo *ExplicitTemplateArgs,
   2464                                             OverloadCandidateSet& CandidateSet,
   2465                                             bool PartialOverloading = false);
   2466 
   2467   // Emit as a 'note' the specific overload candidate
   2468   void NoteOverloadCandidate(FunctionDecl *Fn, QualType DestType = QualType(),
   2469                              bool TakingAddress = false);
   2470 
   2471   // Emit as a series of 'note's all template and non-templates identified by
   2472   // the expression Expr
   2473   void NoteAllOverloadCandidates(Expr *E, QualType DestType = QualType(),
   2474                                  bool TakingAddress = false);
   2475 
   2476   /// Check the enable_if expressions on the given function. Returns the first
   2477   /// failing attribute, or NULL if they were all successful.
   2478   EnableIfAttr *CheckEnableIf(FunctionDecl *Function, ArrayRef<Expr *> Args,
   2479                               bool MissingImplicitThis = false);
   2480 
   2481   /// Returns whether the given function's address can be taken or not,
   2482   /// optionally emitting a diagnostic if the address can't be taken.
   2483   ///
   2484   /// Returns false if taking the address of the function is illegal.
   2485   bool checkAddressOfFunctionIsAvailable(const FunctionDecl *Function,
   2486                                          bool Complain = false,
   2487                                          SourceLocation Loc = SourceLocation());
   2488 
   2489   // [PossiblyAFunctionType]  -->   [Return]
   2490   // NonFunctionType --> NonFunctionType
   2491   // R (A) --> R(A)
   2492   // R (*)(A) --> R (A)
   2493   // R (&)(A) --> R (A)
   2494   // R (S::*)(A) --> R (A)
   2495   QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType);
   2496 
   2497   FunctionDecl *
   2498   ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr,
   2499                                      QualType TargetType,
   2500                                      bool Complain,
   2501                                      DeclAccessPair &Found,
   2502                                      bool *pHadMultipleCandidates = nullptr);
   2503 
   2504   FunctionDecl *
   2505   ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl,
   2506                                               bool Complain = false,
   2507                                               DeclAccessPair *Found = nullptr);
   2508 
   2509   bool ResolveAndFixSingleFunctionTemplateSpecialization(
   2510                       ExprResult &SrcExpr,
   2511                       bool DoFunctionPointerConverion = false,
   2512                       bool Complain = false,
   2513                       SourceRange OpRangeForComplaining = SourceRange(),
   2514                       QualType DestTypeForComplaining = QualType(),
   2515                       unsigned DiagIDForComplaining = 0);
   2516 
   2517 
   2518   Expr *FixOverloadedFunctionReference(Expr *E,
   2519                                        DeclAccessPair FoundDecl,
   2520                                        FunctionDecl *Fn);
   2521   ExprResult FixOverloadedFunctionReference(ExprResult,
   2522                                             DeclAccessPair FoundDecl,
   2523                                             FunctionDecl *Fn);
   2524 
   2525   void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE,
   2526                                    ArrayRef<Expr *> Args,
   2527                                    OverloadCandidateSet &CandidateSet,
   2528                                    bool PartialOverloading = false);
   2529 
   2530   // An enum used to represent the different possible results of building a
   2531   // range-based for loop.
   2532   enum ForRangeStatus {
   2533     FRS_Success,
   2534     FRS_NoViableFunction,
   2535     FRS_DiagnosticIssued
   2536   };
   2537 
   2538   ForRangeStatus BuildForRangeBeginEndCall(SourceLocation Loc,
   2539                                            SourceLocation RangeLoc,
   2540                                            const DeclarationNameInfo &NameInfo,
   2541                                            LookupResult &MemberLookup,
   2542                                            OverloadCandidateSet *CandidateSet,
   2543                                            Expr *Range, ExprResult *CallExpr);
   2544 
   2545   ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn,
   2546                                      UnresolvedLookupExpr *ULE,
   2547                                      SourceLocation LParenLoc,
   2548                                      MultiExprArg Args,
   2549                                      SourceLocation RParenLoc,
   2550                                      Expr *ExecConfig,
   2551                                      bool AllowTypoCorrection=true);
   2552 
   2553   bool buildOverloadedCallSet(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE,
   2554                               MultiExprArg Args, SourceLocation RParenLoc,
   2555                               OverloadCandidateSet *CandidateSet,
   2556                               ExprResult *Result);
   2557 
   2558   ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc,
   2559                                      UnaryOperatorKind Opc,
   2560                                      const UnresolvedSetImpl &Fns,
   2561                                      Expr *input);
   2562 
   2563   ExprResult CreateOverloadedBinOp(SourceLocation OpLoc,
   2564                                    BinaryOperatorKind Opc,
   2565                                    const UnresolvedSetImpl &Fns,
   2566                                    Expr *LHS, Expr *RHS);
   2567 
   2568   ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
   2569                                                 SourceLocation RLoc,
   2570                                                 Expr *Base,Expr *Idx);
   2571 
   2572   ExprResult
   2573   BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
   2574                             SourceLocation LParenLoc,
   2575                             MultiExprArg Args,
   2576                             SourceLocation RParenLoc);
   2577   ExprResult
   2578   BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
   2579                                MultiExprArg Args,
   2580                                SourceLocation RParenLoc);
   2581 
   2582   ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base,
   2583                                       SourceLocation OpLoc,
   2584                                       bool *NoArrowOperatorFound = nullptr);
   2585 
   2586   /// CheckCallReturnType - Checks that a call expression's return type is
   2587   /// complete. Returns true on failure. The location passed in is the location
   2588   /// that best represents the call.
   2589   bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc,
   2590                            CallExpr *CE, FunctionDecl *FD);
   2591 
   2592   /// Helpers for dealing with blocks and functions.
   2593   bool CheckParmsForFunctionDef(ParmVarDecl *const *Param,
   2594                                 ParmVarDecl *const *ParamEnd,
   2595                                 bool CheckParameterNames);
   2596   void CheckCXXDefaultArguments(FunctionDecl *FD);
   2597   void CheckExtraCXXDefaultArguments(Declarator &D);
   2598   Scope *getNonFieldDeclScope(Scope *S);
   2599 
   2600   /// \name Name lookup
   2601   ///
   2602   /// These routines provide name lookup that is used during semantic
   2603   /// analysis to resolve the various kinds of names (identifiers,
   2604   /// overloaded operator names, constructor names, etc.) into zero or
   2605   /// more declarations within a particular scope. The major entry
   2606   /// points are LookupName, which performs unqualified name lookup,
   2607   /// and LookupQualifiedName, which performs qualified name lookup.
   2608   ///
   2609   /// All name lookup is performed based on some specific criteria,
   2610   /// which specify what names will be visible to name lookup and how
   2611   /// far name lookup should work. These criteria are important both
   2612   /// for capturing language semantics (certain lookups will ignore
   2613   /// certain names, for example) and for performance, since name
   2614   /// lookup is often a bottleneck in the compilation of C++. Name
   2615   /// lookup criteria is specified via the LookupCriteria enumeration.
   2616   ///
   2617   /// The results of name lookup can vary based on the kind of name
   2618   /// lookup performed, the current language, and the translation
   2619   /// unit. In C, for example, name lookup will either return nothing
   2620   /// (no entity found) or a single declaration. In C++, name lookup
   2621   /// can additionally refer to a set of overloaded functions or
   2622   /// result in an ambiguity. All of the possible results of name
   2623   /// lookup are captured by the LookupResult class, which provides
   2624   /// the ability to distinguish among them.
   2625   //@{
   2626 
   2627   /// @brief Describes the kind of name lookup to perform.
   2628   enum LookupNameKind {
   2629     /// Ordinary name lookup, which finds ordinary names (functions,
   2630     /// variables, typedefs, etc.) in C and most kinds of names
   2631     /// (functions, variables, members, types, etc.) in C++.
   2632     LookupOrdinaryName = 0,
   2633     /// Tag name lookup, which finds the names of enums, classes,
   2634     /// structs, and unions.
   2635     LookupTagName,
   2636     /// Label name lookup.
   2637     LookupLabel,
   2638     /// Member name lookup, which finds the names of
   2639     /// class/struct/union members.
   2640     LookupMemberName,
   2641     /// Look up of an operator name (e.g., operator+) for use with
   2642     /// operator overloading. This lookup is similar to ordinary name
   2643     /// lookup, but will ignore any declarations that are class members.
   2644     LookupOperatorName,
   2645     /// Look up of a name that precedes the '::' scope resolution
   2646     /// operator in C++. This lookup completely ignores operator, object,
   2647     /// function, and enumerator names (C++ [basic.lookup.qual]p1).
   2648     LookupNestedNameSpecifierName,
   2649     /// Look up a namespace name within a C++ using directive or
   2650     /// namespace alias definition, ignoring non-namespace names (C++
   2651     /// [basic.lookup.udir]p1).
   2652     LookupNamespaceName,
   2653     /// Look up all declarations in a scope with the given name,
   2654     /// including resolved using declarations.  This is appropriate
   2655     /// for checking redeclarations for a using declaration.
   2656     LookupUsingDeclName,
   2657     /// Look up an ordinary name that is going to be redeclared as a
   2658     /// name with linkage. This lookup ignores any declarations that
   2659     /// are outside of the current scope unless they have linkage. See
   2660     /// C99 6.2.2p4-5 and C++ [basic.link]p6.
   2661     LookupRedeclarationWithLinkage,
   2662     /// Look up a friend of a local class. This lookup does not look
   2663     /// outside the innermost non-class scope. See C++11 [class.friend]p11.
   2664     LookupLocalFriendName,
   2665     /// Look up the name of an Objective-C protocol.
   2666     LookupObjCProtocolName,
   2667     /// Look up implicit 'self' parameter of an objective-c method.
   2668     LookupObjCImplicitSelfParam,
   2669     /// \brief Look up any declaration with any name.
   2670     LookupAnyName
   2671   };
   2672 
   2673   /// \brief Specifies whether (or how) name lookup is being performed for a
   2674   /// redeclaration (vs. a reference).
   2675   enum RedeclarationKind {
   2676     /// \brief The lookup is a reference to this name that is not for the
   2677     /// purpose of redeclaring the name.
   2678     NotForRedeclaration = 0,
   2679     /// \brief The lookup results will be used for redeclaration of a name,
   2680     /// if an entity by that name already exists.
   2681     ForRedeclaration
   2682   };
   2683 
   2684   /// \brief The possible outcomes of name lookup for a literal operator.
   2685   enum LiteralOperatorLookupResult {
   2686     /// \brief The lookup resulted in an error.
   2687     LOLR_Error,
   2688     /// \brief The lookup found a single 'cooked' literal operator, which
   2689     /// expects a normal literal to be built and passed to it.
   2690     LOLR_Cooked,
   2691     /// \brief The lookup found a single 'raw' literal operator, which expects
   2692     /// a string literal containing the spelling of the literal token.
   2693     LOLR_Raw,
   2694     /// \brief The lookup found an overload set of literal operator templates,
   2695     /// which expect the characters of the spelling of the literal token to be
   2696     /// passed as a non-type template argument pack.
   2697     LOLR_Template,
   2698     /// \brief The lookup found an overload set of literal operator templates,
   2699     /// which expect the character type and characters of the spelling of the
   2700     /// string literal token to be passed as template arguments.
   2701     LOLR_StringTemplate
   2702   };
   2703 
   2704   SpecialMemberOverloadResult *LookupSpecialMember(CXXRecordDecl *D,
   2705                                                    CXXSpecialMember SM,
   2706                                                    bool ConstArg,
   2707                                                    bool VolatileArg,
   2708                                                    bool RValueThis,
   2709                                                    bool ConstThis,
   2710                                                    bool VolatileThis);
   2711 
   2712   typedef std::function<void(const TypoCorrection &)> TypoDiagnosticGenerator;
   2713   typedef std::function<ExprResult(Sema &, TypoExpr *, TypoCorrection)>
   2714       TypoRecoveryCallback;
   2715 
   2716 private:
   2717   bool CppLookupName(LookupResult &R, Scope *S);
   2718 
   2719   struct TypoExprState {
   2720     std::unique_ptr<TypoCorrectionConsumer> Consumer;
   2721     TypoDiagnosticGenerator DiagHandler;
   2722     TypoRecoveryCallback RecoveryHandler;
   2723     TypoExprState();
   2724     TypoExprState(TypoExprState&& other) LLVM_NOEXCEPT;
   2725     TypoExprState& operator=(TypoExprState&& other) LLVM_NOEXCEPT;
   2726   };
   2727 
   2728   /// \brief The set of unhandled TypoExprs and their associated state.
   2729   llvm::MapVector<TypoExpr *, TypoExprState> DelayedTypos;
   2730 
   2731   /// \brief Creates a new TypoExpr AST node.
   2732   TypoExpr *createDelayedTypo(std::unique_ptr<TypoCorrectionConsumer> TCC,
   2733                               TypoDiagnosticGenerator TDG,
   2734                               TypoRecoveryCallback TRC);
   2735 
   2736   // \brief The set of known/encountered (unique, canonicalized) NamespaceDecls.
   2737   //
   2738   // The boolean value will be true to indicate that the namespace was loaded
   2739   // from an AST/PCH file, or false otherwise.
   2740   llvm::MapVector<NamespaceDecl*, bool> KnownNamespaces;
   2741 
   2742   /// \brief Whether we have already loaded known namespaces from an extenal
   2743   /// source.
   2744   bool LoadedExternalKnownNamespaces;
   2745 
   2746   /// \brief Helper for CorrectTypo and CorrectTypoDelayed used to create and
   2747   /// populate a new TypoCorrectionConsumer. Returns nullptr if typo correction
   2748   /// should be skipped entirely.
   2749   std::unique_ptr<TypoCorrectionConsumer>
   2750   makeTypoCorrectionConsumer(const DeclarationNameInfo &Typo,
   2751                              Sema::LookupNameKind LookupKind, Scope *S,
   2752                              CXXScopeSpec *SS,
   2753                              std::unique_ptr<CorrectionCandidateCallback> CCC,
   2754                              DeclContext *MemberContext, bool EnteringContext,
   2755                              const ObjCObjectPointerType *OPT,
   2756                              bool ErrorRecovery);
   2757 
   2758 public:
   2759   const TypoExprState &getTypoExprState(TypoExpr *TE) const;
   2760 
   2761   /// \brief Clears the state of the given TypoExpr.
   2762   void clearDelayedTypo(TypoExpr *TE);
   2763 
   2764   /// \brief Look up a name, looking for a single declaration.  Return
   2765   /// null if the results were absent, ambiguous, or overloaded.
   2766   ///
   2767   /// It is preferable to use the elaborated form and explicitly handle
   2768   /// ambiguity and overloaded.
   2769   NamedDecl *LookupSingleName(Scope *S, DeclarationName Name,
   2770                               SourceLocation Loc,
   2771                               LookupNameKind NameKind,
   2772                               RedeclarationKind Redecl
   2773                                 = NotForRedeclaration);
   2774   bool LookupName(LookupResult &R, Scope *S,
   2775                   bool AllowBuiltinCreation = false);
   2776   bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
   2777                            bool InUnqualifiedLookup = false);
   2778   bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
   2779                            CXXScopeSpec &SS);
   2780   bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS,
   2781                         bool AllowBuiltinCreation = false,
   2782                         bool EnteringContext = false);
   2783   ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc,
   2784                                    RedeclarationKind Redecl
   2785                                      = NotForRedeclaration);
   2786   bool LookupInSuper(LookupResult &R, CXXRecordDecl *Class);
   2787 
   2788   void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
   2789                                     QualType T1, QualType T2,
   2790                                     UnresolvedSetImpl &Functions);
   2791   void addOverloadedOperatorToUnresolvedSet(UnresolvedSetImpl &Functions,
   2792                                             DeclAccessPair Operator,
   2793                                             QualType T1, QualType T2);
   2794 
   2795   LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc,
   2796                                  SourceLocation GnuLabelLoc = SourceLocation());
   2797 
   2798   DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class);
   2799   CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class);
   2800   CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class,
   2801                                                unsigned Quals);
   2802   CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals,
   2803                                          bool RValueThis, unsigned ThisQuals);
   2804   CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class,
   2805                                               unsigned Quals);
   2806   CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals,
   2807                                         bool RValueThis, unsigned ThisQuals);
   2808   CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class);
   2809 
   2810   bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id);
   2811   LiteralOperatorLookupResult LookupLiteralOperator(Scope *S, LookupResult &R,
   2812                                                     ArrayRef<QualType> ArgTys,
   2813                                                     bool AllowRaw,
   2814                                                     bool AllowTemplate,
   2815                                                     bool AllowStringTemplate);
   2816   bool isKnownName(StringRef name);
   2817 
   2818   void ArgumentDependentLookup(DeclarationName Name, SourceLocation Loc,
   2819                                ArrayRef<Expr *> Args, ADLResult &Functions);
   2820 
   2821   void LookupVisibleDecls(Scope *S, LookupNameKind Kind,
   2822                           VisibleDeclConsumer &Consumer,
   2823                           bool IncludeGlobalScope = true);
   2824   void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind,
   2825                           VisibleDeclConsumer &Consumer,
   2826                           bool IncludeGlobalScope = true);
   2827 
   2828   enum CorrectTypoKind {
   2829     CTK_NonError,     // CorrectTypo used in a non error recovery situation.
   2830     CTK_ErrorRecovery // CorrectTypo used in normal error recovery.
   2831   };
   2832 
   2833   TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
   2834                              Sema::LookupNameKind LookupKind,
   2835                              Scope *S, CXXScopeSpec *SS,
   2836                              std::unique_ptr<CorrectionCandidateCallback> CCC,
   2837                              CorrectTypoKind Mode,
   2838                              DeclContext *MemberContext = nullptr,
   2839                              bool EnteringContext = false,
   2840                              const ObjCObjectPointerType *OPT = nullptr,
   2841                              bool RecordFailure = true);
   2842 
   2843   TypoExpr *CorrectTypoDelayed(const DeclarationNameInfo &Typo,
   2844                                Sema::LookupNameKind LookupKind, Scope *S,
   2845                                CXXScopeSpec *SS,
   2846                                std::unique_ptr<CorrectionCandidateCallback> CCC,
   2847                                TypoDiagnosticGenerator TDG,
   2848                                TypoRecoveryCallback TRC, CorrectTypoKind Mode,
   2849                                DeclContext *MemberContext = nullptr,
   2850                                bool EnteringContext = false,
   2851                                const ObjCObjectPointerType *OPT = nullptr);
   2852 
   2853   /// \brief Process any TypoExprs in the given Expr and its children,
   2854   /// generating diagnostics as appropriate and returning a new Expr if there
   2855   /// were typos that were all successfully corrected and ExprError if one or
   2856   /// more typos could not be corrected.
   2857   ///
   2858   /// \param E The Expr to check for TypoExprs.
   2859   ///
   2860   /// \param InitDecl A VarDecl to avoid because the Expr being corrected is its
   2861   /// initializer.
   2862   ///
   2863   /// \param Filter A function applied to a newly rebuilt Expr to determine if
   2864   /// it is an acceptable/usable result from a single combination of typo
   2865   /// corrections. As long as the filter returns ExprError, different
   2866   /// combinations of corrections will be tried until all are exhausted.
   2867   ExprResult
   2868   CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl = nullptr,
   2869                             llvm::function_ref<ExprResult(Expr *)> Filter =
   2870                                 [](Expr *E) -> ExprResult { return E; });
   2871 
   2872   ExprResult
   2873   CorrectDelayedTyposInExpr(Expr *E,
   2874                             llvm::function_ref<ExprResult(Expr *)> Filter) {
   2875     return CorrectDelayedTyposInExpr(E, nullptr, Filter);
   2876   }
   2877 
   2878   ExprResult
   2879   CorrectDelayedTyposInExpr(ExprResult ER, VarDecl *InitDecl = nullptr,
   2880                             llvm::function_ref<ExprResult(Expr *)> Filter =
   2881                                 [](Expr *E) -> ExprResult { return E; }) {
   2882     return ER.isInvalid() ? ER : CorrectDelayedTyposInExpr(ER.get(), Filter);
   2883   }
   2884 
   2885   ExprResult
   2886   CorrectDelayedTyposInExpr(ExprResult ER,
   2887                             llvm::function_ref<ExprResult(Expr *)> Filter) {
   2888     return CorrectDelayedTyposInExpr(ER, nullptr, Filter);
   2889   }
   2890 
   2891   void diagnoseTypo(const TypoCorrection &Correction,
   2892                     const PartialDiagnostic &TypoDiag,
   2893                     bool ErrorRecovery = true);
   2894 
   2895   void diagnoseTypo(const TypoCorrection &Correction,
   2896                     const PartialDiagnostic &TypoDiag,
   2897                     const PartialDiagnostic &PrevNote,
   2898                     bool ErrorRecovery = true);
   2899 
   2900   void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc,
   2901                                           ArrayRef<Expr *> Args,
   2902                                    AssociatedNamespaceSet &AssociatedNamespaces,
   2903                                    AssociatedClassSet &AssociatedClasses);
   2904 
   2905   void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S,
   2906                             bool ConsiderLinkage, bool AllowInlineNamespace);
   2907 
   2908   void DiagnoseAmbiguousLookup(LookupResult &Result);
   2909   //@}
   2910 
   2911   ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id,
   2912                                           SourceLocation IdLoc,
   2913                                           bool TypoCorrection = false);
   2914   NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
   2915                                  Scope *S, bool ForRedeclaration,
   2916                                  SourceLocation Loc);
   2917   NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
   2918                                       Scope *S);
   2919   void AddKnownFunctionAttributes(FunctionDecl *FD);
   2920 
   2921   // More parsing and symbol table subroutines.
   2922 
   2923   void ProcessPragmaWeak(Scope *S, Decl *D);
   2924   // Decl attributes - this routine is the top level dispatcher.
   2925   void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD);
   2926   void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL,
   2927                                 bool IncludeCXX11Attributes = true);
   2928   bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl,
   2929                                       const AttributeList *AttrList);
   2930 
   2931   void checkUnusedDeclAttributes(Declarator &D);
   2932 
   2933   /// Determine if type T is a valid subject for a nonnull and similar
   2934   /// attributes. By default, we look through references (the behavior used by
   2935   /// nonnull), but if the second parameter is true, then we treat a reference
   2936   /// type as valid.
   2937   bool isValidPointerAttrType(QualType T, bool RefOkay = false);
   2938 
   2939   bool CheckRegparmAttr(const AttributeList &attr, unsigned &value);
   2940   bool CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC,
   2941                             const FunctionDecl *FD = nullptr);
   2942   bool CheckNoReturnAttr(const AttributeList &attr);
   2943   bool checkStringLiteralArgumentAttr(const AttributeList &Attr,
   2944                                       unsigned ArgNum, StringRef &Str,
   2945                                       SourceLocation *ArgLocation = nullptr);
   2946   bool checkSectionName(SourceLocation LiteralLoc, StringRef Str);
   2947   void checkTargetAttr(SourceLocation LiteralLoc, StringRef Str);
   2948   bool checkMSInheritanceAttrOnDefinition(
   2949       CXXRecordDecl *RD, SourceRange Range, bool BestCase,
   2950       MSInheritanceAttr::Spelling SemanticSpelling);
   2951 
   2952   void CheckAlignasUnderalignment(Decl *D);
   2953 
   2954   /// Adjust the calling convention of a method to be the ABI default if it
   2955   /// wasn't specified explicitly.  This handles method types formed from
   2956   /// function type typedefs and typename template arguments.
   2957   void adjustMemberFunctionCC(QualType &T, bool IsStatic, bool IsCtorOrDtor,
   2958                               SourceLocation Loc);
   2959 
   2960   // Check if there is an explicit attribute, but only look through parens.
   2961   // The intent is to look for an attribute on the current declarator, but not
   2962   // one that came from a typedef.
   2963   bool hasExplicitCallingConv(QualType &T);
   2964 
   2965   /// Get the outermost AttributedType node that sets a calling convention.
   2966   /// Valid types should not have multiple attributes with different CCs.
   2967   const AttributedType *getCallingConvAttributedType(QualType T) const;
   2968 
   2969   /// Check whether a nullability type specifier can be added to the given
   2970   /// type.
   2971   ///
   2972   /// \param type The type to which the nullability specifier will be
   2973   /// added. On success, this type will be updated appropriately.
   2974   ///
   2975   /// \param nullability The nullability specifier to add.
   2976   ///
   2977   /// \param nullabilityLoc The location of the nullability specifier.
   2978   ///
   2979   /// \param isContextSensitive Whether this nullability specifier was
   2980   /// written as a context-sensitive keyword (in an Objective-C
   2981   /// method) or an Objective-C property attribute, rather than as an
   2982   /// underscored type specifier.
   2983   ///
   2984   /// \returns true if nullability cannot be applied, false otherwise.
   2985   bool checkNullabilityTypeSpecifier(QualType &type, NullabilityKind nullability,
   2986                                      SourceLocation nullabilityLoc,
   2987                                      bool isContextSensitive);
   2988 
   2989   /// \brief Stmt attributes - this routine is the top level dispatcher.
   2990   StmtResult ProcessStmtAttributes(Stmt *Stmt, AttributeList *Attrs,
   2991                                    SourceRange Range);
   2992 
   2993   void WarnConflictingTypedMethods(ObjCMethodDecl *Method,
   2994                                    ObjCMethodDecl *MethodDecl,
   2995                                    bool IsProtocolMethodDecl);
   2996 
   2997   void CheckConflictingOverridingMethod(ObjCMethodDecl *Method,
   2998                                    ObjCMethodDecl *Overridden,
   2999                                    bool IsProtocolMethodDecl);
   3000 
   3001   /// WarnExactTypedMethods - This routine issues a warning if method
   3002   /// implementation declaration matches exactly that of its declaration.
   3003   void WarnExactTypedMethods(ObjCMethodDecl *Method,
   3004                              ObjCMethodDecl *MethodDecl,
   3005                              bool IsProtocolMethodDecl);
   3006 
   3007   typedef llvm::SmallPtrSet<Selector, 8> SelectorSet;
   3008   typedef llvm::DenseMap<Selector, ObjCMethodDecl*> ProtocolsMethodsMap;
   3009 
   3010   /// CheckImplementationIvars - This routine checks if the instance variables
   3011   /// listed in the implelementation match those listed in the interface.
   3012   void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
   3013                                 ObjCIvarDecl **Fields, unsigned nIvars,
   3014                                 SourceLocation Loc);
   3015 
   3016   /// ImplMethodsVsClassMethods - This is main routine to warn if any method
   3017   /// remains unimplemented in the class or category \@implementation.
   3018   void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl,
   3019                                  ObjCContainerDecl* IDecl,
   3020                                  bool IncompleteImpl = false);
   3021 
   3022   /// DiagnoseUnimplementedProperties - This routine warns on those properties
   3023   /// which must be implemented by this implementation.
   3024   void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl,
   3025                                        ObjCContainerDecl *CDecl,
   3026                                        bool SynthesizeProperties);
   3027 
   3028   /// Diagnose any null-resettable synthesized setters.
   3029   void diagnoseNullResettableSynthesizedSetters(const ObjCImplDecl *impDecl);
   3030 
   3031   /// DefaultSynthesizeProperties - This routine default synthesizes all
   3032   /// properties which must be synthesized in the class's \@implementation.
   3033   void DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl,
   3034                                     ObjCInterfaceDecl *IDecl);
   3035   void DefaultSynthesizeProperties(Scope *S, Decl *D);
   3036 
   3037   /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is
   3038   /// an ivar synthesized for 'Method' and 'Method' is a property accessor
   3039   /// declared in class 'IFace'.
   3040   bool IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace,
   3041                                       ObjCMethodDecl *Method, ObjCIvarDecl *IV);
   3042 
   3043   /// DiagnoseUnusedBackingIvarInAccessor - Issue an 'unused' warning if ivar which
   3044   /// backs the property is not used in the property's accessor.
   3045   void DiagnoseUnusedBackingIvarInAccessor(Scope *S,
   3046                                            const ObjCImplementationDecl *ImplD);
   3047 
   3048   /// GetIvarBackingPropertyAccessor - If method is a property setter/getter and
   3049   /// it property has a backing ivar, returns this ivar; otherwise, returns NULL.
   3050   /// It also returns ivar's property on success.
   3051   ObjCIvarDecl *GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method,
   3052                                                const ObjCPropertyDecl *&PDecl) const;
   3053 
   3054   /// Called by ActOnProperty to handle \@property declarations in
   3055   /// class extensions.
   3056   ObjCPropertyDecl *HandlePropertyInClassExtension(Scope *S,
   3057                       SourceLocation AtLoc,
   3058                       SourceLocation LParenLoc,
   3059                       FieldDeclarator &FD,
   3060                       Selector GetterSel,
   3061                       Selector SetterSel,
   3062                       const bool isReadWrite,
   3063                       unsigned &Attributes,
   3064                       const unsigned AttributesAsWritten,
   3065                       QualType T,
   3066                       TypeSourceInfo *TSI,
   3067                       tok::ObjCKeywordKind MethodImplKind);
   3068 
   3069   /// Called by ActOnProperty and HandlePropertyInClassExtension to
   3070   /// handle creating the ObjcPropertyDecl for a category or \@interface.
   3071   ObjCPropertyDecl *CreatePropertyDecl(Scope *S,
   3072                                        ObjCContainerDecl *CDecl,
   3073                                        SourceLocation AtLoc,
   3074                                        SourceLocation LParenLoc,
   3075                                        FieldDeclarator &FD,
   3076                                        Selector GetterSel,
   3077                                        Selector SetterSel,
   3078                                        const bool isReadWrite,
   3079                                        const unsigned Attributes,
   3080                                        const unsigned AttributesAsWritten,
   3081                                        QualType T,
   3082                                        TypeSourceInfo *TSI,
   3083                                        tok::ObjCKeywordKind MethodImplKind,
   3084                                        DeclContext *lexicalDC = nullptr);
   3085 
   3086   /// AtomicPropertySetterGetterRules - This routine enforces the rule (via
   3087   /// warning) when atomic property has one but not the other user-declared
   3088   /// setter or getter.
   3089   void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl,
   3090                                        ObjCInterfaceDecl* IDecl);
   3091 
   3092   void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D);
   3093 
   3094   void DiagnoseMissingDesignatedInitOverrides(
   3095                                           const ObjCImplementationDecl *ImplD,
   3096                                           const ObjCInterfaceDecl *IFD);
   3097 
   3098   void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID);
   3099 
   3100   enum MethodMatchStrategy {
   3101     MMS_loose,
   3102     MMS_strict
   3103   };
   3104 
   3105   /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
   3106   /// true, or false, accordingly.
   3107   bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
   3108                                   const ObjCMethodDecl *PrevMethod,
   3109                                   MethodMatchStrategy strategy = MMS_strict);
   3110 
   3111   /// MatchAllMethodDeclarations - Check methods declaraed in interface or
   3112   /// or protocol against those declared in their implementations.
   3113   void MatchAllMethodDeclarations(const SelectorSet &InsMap,
   3114                                   const SelectorSet &ClsMap,
   3115                                   SelectorSet &InsMapSeen,
   3116                                   SelectorSet &ClsMapSeen,
   3117                                   ObjCImplDecl* IMPDecl,
   3118                                   ObjCContainerDecl* IDecl,
   3119                                   bool &IncompleteImpl,
   3120                                   bool ImmediateClass,
   3121                                   bool WarnCategoryMethodImpl=false);
   3122 
   3123   /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in
   3124   /// category matches with those implemented in its primary class and
   3125   /// warns each time an exact match is found.
   3126   void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP);
   3127 
   3128   /// \brief Add the given method to the list of globally-known methods.
   3129   void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method);
   3130 
   3131 private:
   3132   /// AddMethodToGlobalPool - Add an instance or factory method to the global
   3133   /// pool. See descriptoin of AddInstanceMethodToGlobalPool.
   3134   void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance);
   3135 
   3136   /// LookupMethodInGlobalPool - Returns the instance or factory method and
   3137   /// optionally warns if there are multiple signatures.
   3138   ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R,
   3139                                            bool receiverIdOrClass,
   3140                                            bool instance);
   3141 
   3142 public:
   3143   /// \brief - Returns instance or factory methods in global method pool for
   3144   /// given selector. If no such method or only one method found, function returns
   3145   /// false; otherwise, it returns true
   3146   bool CollectMultipleMethodsInGlobalPool(Selector Sel,
   3147                                           SmallVectorImpl<ObjCMethodDecl*>& Methods,
   3148                                           bool instance);
   3149 
   3150   bool AreMultipleMethodsInGlobalPool(Selector Sel, ObjCMethodDecl *BestMethod,
   3151                                       SourceRange R,
   3152                                       bool receiverIdOrClass);
   3153 
   3154   void DiagnoseMultipleMethodInGlobalPool(SmallVectorImpl<ObjCMethodDecl*> &Methods,
   3155                                           Selector Sel, SourceRange R,
   3156                                           bool receiverIdOrClass);
   3157 
   3158 private:
   3159   /// \brief - Returns a selector which best matches given argument list or
   3160   /// nullptr if none could be found
   3161   ObjCMethodDecl *SelectBestMethod(Selector Sel, MultiExprArg Args,
   3162                                    bool IsInstance);
   3163 
   3164 
   3165   /// \brief Record the typo correction failure and return an empty correction.
   3166   TypoCorrection FailedCorrection(IdentifierInfo *Typo, SourceLocation TypoLoc,
   3167                                   bool RecordFailure = true) {
   3168     if (RecordFailure)
   3169       TypoCorrectionFailures[Typo].insert(TypoLoc);
   3170     return TypoCorrection();
   3171   }
   3172 
   3173 public:
   3174   /// AddInstanceMethodToGlobalPool - All instance methods in a translation
   3175   /// unit are added to a global pool. This allows us to efficiently associate
   3176   /// a selector with a method declaraation for purposes of typechecking
   3177   /// messages sent to "id" (where the class of the object is unknown).
   3178   void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
   3179     AddMethodToGlobalPool(Method, impl, /*instance*/true);
   3180   }
   3181 
   3182   /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
   3183   void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
   3184     AddMethodToGlobalPool(Method, impl, /*instance*/false);
   3185   }
   3186 
   3187   /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global
   3188   /// pool.
   3189   void AddAnyMethodToGlobalPool(Decl *D);
   3190 
   3191   /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
   3192   /// there are multiple signatures.
   3193   ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R,
   3194                                                    bool receiverIdOrClass=false) {
   3195     return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
   3196                                     /*instance*/true);
   3197   }
   3198 
   3199   /// LookupFactoryMethodInGlobalPool - Returns the method and warns if
   3200   /// there are multiple signatures.
   3201   ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R,
   3202                                                   bool receiverIdOrClass=false) {
   3203     return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
   3204                                     /*instance*/false);
   3205   }
   3206 
   3207   const ObjCMethodDecl *SelectorsForTypoCorrection(Selector Sel,
   3208                               QualType ObjectType=QualType());
   3209   /// LookupImplementedMethodInGlobalPool - Returns the method which has an
   3210   /// implementation.
   3211   ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel);
   3212 
   3213   /// CollectIvarsToConstructOrDestruct - Collect those ivars which require
   3214   /// initialization.
   3215   void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI,
   3216                                   SmallVectorImpl<ObjCIvarDecl*> &Ivars);
   3217 
   3218   //===--------------------------------------------------------------------===//
   3219   // Statement Parsing Callbacks: SemaStmt.cpp.
   3220 public:
   3221   class FullExprArg {
   3222   public:
   3223     FullExprArg(Sema &actions) : E(nullptr) { }
   3224 
   3225     ExprResult release() {
   3226       return E;
   3227     }
   3228 
   3229     Expr *get() const { return E; }
   3230 
   3231     Expr *operator->() {
   3232       return E;
   3233     }
   3234 
   3235   private:
   3236     // FIXME: No need to make the entire Sema class a friend when it's just
   3237     // Sema::MakeFullExpr that needs access to the constructor below.
   3238     friend class Sema;
   3239 
   3240     explicit FullExprArg(Expr *expr) : E(expr) {}
   3241 
   3242     Expr *E;
   3243   };
   3244 
   3245   FullExprArg MakeFullExpr(Expr *Arg) {
   3246     return MakeFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation());
   3247   }
   3248   FullExprArg MakeFullExpr(Expr *Arg, SourceLocation CC) {
   3249     return FullExprArg(ActOnFinishFullExpr(Arg, CC).get());
   3250   }
   3251   FullExprArg MakeFullDiscardedValueExpr(Expr *Arg) {
   3252     ExprResult FE =
   3253       ActOnFinishFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation(),
   3254                           /*DiscardedValue*/ true);
   3255     return FullExprArg(FE.get());
   3256   }
   3257 
   3258   StmtResult ActOnExprStmt(ExprResult Arg);
   3259   StmtResult ActOnExprStmtError();
   3260 
   3261   StmtResult ActOnNullStmt(SourceLocation SemiLoc,
   3262                            bool HasLeadingEmptyMacro = false);
   3263 
   3264   void ActOnStartOfCompoundStmt();
   3265   void ActOnFinishOfCompoundStmt();
   3266   StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
   3267                                ArrayRef<Stmt *> Elts, bool isStmtExpr);
   3268 
   3269   /// \brief A RAII object to enter scope of a compound statement.
   3270   class CompoundScopeRAII {
   3271   public:
   3272     CompoundScopeRAII(Sema &S): S(S) {
   3273       S.ActOnStartOfCompoundStmt();
   3274     }
   3275 
   3276     ~CompoundScopeRAII() {
   3277       S.ActOnFinishOfCompoundStmt();
   3278     }
   3279 
   3280   private:
   3281     Sema &S;
   3282   };
   3283 
   3284   /// An RAII helper that pops function a function scope on exit.
   3285   struct FunctionScopeRAII {
   3286     Sema &S;
   3287     bool Active;
   3288     FunctionScopeRAII(Sema &S) : S(S), Active(true) {}
   3289     ~FunctionScopeRAII() {
   3290       if (Active)
   3291         S.PopFunctionScopeInfo();
   3292     }
   3293     void disable() { Active = false; }
   3294   };
   3295 
   3296   StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl,
   3297                                    SourceLocation StartLoc,
   3298                                    SourceLocation EndLoc);
   3299   void ActOnForEachDeclStmt(DeclGroupPtrTy Decl);
   3300   StmtResult ActOnForEachLValueExpr(Expr *E);
   3301   StmtResult ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal,
   3302                                    SourceLocation DotDotDotLoc, Expr *RHSVal,
   3303                                    SourceLocation ColonLoc);
   3304   void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt);
   3305 
   3306   StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
   3307                                       SourceLocation ColonLoc,
   3308                                       Stmt *SubStmt, Scope *CurScope);
   3309   StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl,
   3310                             SourceLocation ColonLoc, Stmt *SubStmt);
   3311 
   3312   StmtResult ActOnAttributedStmt(SourceLocation AttrLoc,
   3313                                  ArrayRef<const Attr*> Attrs,
   3314                                  Stmt *SubStmt);
   3315 
   3316   StmtResult ActOnIfStmt(SourceLocation IfLoc,
   3317                          FullExprArg CondVal, Decl *CondVar,
   3318                          Stmt *ThenVal,
   3319                          SourceLocation ElseLoc, Stmt *ElseVal);
   3320   StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc,
   3321                                             Expr *Cond,
   3322                                             Decl *CondVar);
   3323   StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
   3324                                            Stmt *Switch, Stmt *Body);
   3325   StmtResult ActOnWhileStmt(SourceLocation WhileLoc,
   3326                             FullExprArg Cond,
   3327                             Decl *CondVar, Stmt *Body);
   3328   StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body,
   3329                                  SourceLocation WhileLoc,
   3330                                  SourceLocation CondLParen, Expr *Cond,
   3331                                  SourceLocation CondRParen);
   3332 
   3333   StmtResult ActOnForStmt(SourceLocation ForLoc,
   3334                           SourceLocation LParenLoc,
   3335                           Stmt *First, FullExprArg Second,
   3336                           Decl *SecondVar,
   3337                           FullExprArg Third,
   3338                           SourceLocation RParenLoc,
   3339                           Stmt *Body);
   3340   ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc,
   3341                                            Expr *collection);
   3342   StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
   3343                                         Stmt *First, Expr *collection,
   3344                                         SourceLocation RParenLoc);
   3345   StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body);
   3346 
   3347   enum BuildForRangeKind {
   3348     /// Initial building of a for-range statement.
   3349     BFRK_Build,
   3350     /// Instantiation or recovery rebuild of a for-range statement. Don't
   3351     /// attempt any typo-correction.
   3352     BFRK_Rebuild,
   3353     /// Determining whether a for-range statement could be built. Avoid any
   3354     /// unnecessary or irreversible actions.
   3355     BFRK_Check
   3356   };
   3357 
   3358   StmtResult ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc,
   3359                                   SourceLocation CoawaitLoc,
   3360                                   Stmt *LoopVar,
   3361                                   SourceLocation ColonLoc, Expr *Collection,
   3362                                   SourceLocation RParenLoc,
   3363                                   BuildForRangeKind Kind);
   3364   StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc,
   3365                                   SourceLocation CoawaitLoc,
   3366                                   SourceLocation ColonLoc,
   3367                                   Stmt *RangeDecl, Stmt *BeginEndDecl,
   3368                                   Expr *Cond, Expr *Inc,
   3369                                   Stmt *LoopVarDecl,
   3370                                   SourceLocation RParenLoc,
   3371                                   BuildForRangeKind Kind);
   3372   StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body);
   3373 
   3374   StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
   3375                            SourceLocation LabelLoc,
   3376                            LabelDecl *TheDecl);
   3377   StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
   3378                                    SourceLocation StarLoc,
   3379                                    Expr *DestExp);
   3380   StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope);
   3381   StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope);
   3382 
   3383   void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope,
   3384                                 CapturedRegionKind Kind, unsigned NumParams);
   3385   typedef std::pair<StringRef, QualType> CapturedParamNameType;
   3386   void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope,
   3387                                 CapturedRegionKind Kind,
   3388                                 ArrayRef<CapturedParamNameType> Params);
   3389   StmtResult ActOnCapturedRegionEnd(Stmt *S);
   3390   void ActOnCapturedRegionError();
   3391   RecordDecl *CreateCapturedStmtRecordDecl(CapturedDecl *&CD,
   3392                                            SourceLocation Loc,
   3393                                            unsigned NumParams);
   3394   VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E,
   3395                                    bool AllowFunctionParameters);
   3396   bool isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD,
   3397                               bool AllowFunctionParameters);
   3398 
   3399   StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
   3400                              Scope *CurScope);
   3401   StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
   3402   StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
   3403 
   3404   StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
   3405                              bool IsVolatile, unsigned NumOutputs,
   3406                              unsigned NumInputs, IdentifierInfo **Names,
   3407                              MultiExprArg Constraints, MultiExprArg Exprs,
   3408                              Expr *AsmString, MultiExprArg Clobbers,
   3409                              SourceLocation RParenLoc);
   3410 
   3411   ExprResult LookupInlineAsmIdentifier(CXXScopeSpec &SS,
   3412                                        SourceLocation TemplateKWLoc,
   3413                                        UnqualifiedId &Id,
   3414                                        llvm::InlineAsmIdentifierInfo &Info,
   3415                                        bool IsUnevaluatedContext);
   3416   bool LookupInlineAsmField(StringRef Base, StringRef Member,
   3417                             unsigned &Offset, SourceLocation AsmLoc);
   3418   ExprResult LookupInlineAsmVarDeclField(Expr *RefExpr, StringRef Member,
   3419                                          unsigned &Offset,
   3420                                          llvm::InlineAsmIdentifierInfo &Info,
   3421                                          SourceLocation AsmLoc);
   3422   StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
   3423                             ArrayRef<Token> AsmToks,
   3424                             StringRef AsmString,
   3425                             unsigned NumOutputs, unsigned NumInputs,
   3426                             ArrayRef<StringRef> Constraints,
   3427                             ArrayRef<StringRef> Clobbers,
   3428                             ArrayRef<Expr*> Exprs,
   3429                             SourceLocation EndLoc);
   3430   LabelDecl *GetOrCreateMSAsmLabel(StringRef ExternalLabelName,
   3431                                    SourceLocation Location,
   3432                                    bool AlwaysCreate);
   3433 
   3434   VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType,
   3435                                   SourceLocation StartLoc,
   3436                                   SourceLocation IdLoc, IdentifierInfo *Id,
   3437                                   bool Invalid = false);
   3438 
   3439   Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D);
   3440 
   3441   StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen,
   3442                                   Decl *Parm, Stmt *Body);
   3443 
   3444   StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body);
   3445 
   3446   StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try,
   3447                                 MultiStmtArg Catch, Stmt *Finally);
   3448 
   3449   StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw);
   3450   StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw,
   3451                                   Scope *CurScope);
   3452   ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc,
   3453                                             Expr *operand);
   3454   StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
   3455                                          Expr *SynchExpr,
   3456                                          Stmt *SynchBody);
   3457 
   3458   StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body);
   3459 
   3460   VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo,
   3461                                      SourceLocation StartLoc,
   3462                                      SourceLocation IdLoc,
   3463                                      IdentifierInfo *Id);
   3464 
   3465   Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D);
   3466 
   3467   StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
   3468                                 Decl *ExDecl, Stmt *HandlerBlock);
   3469   StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
   3470                               ArrayRef<Stmt *> Handlers);
   3471 
   3472   StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ?
   3473                               SourceLocation TryLoc, Stmt *TryBlock,
   3474                               Stmt *Handler);
   3475   StmtResult ActOnSEHExceptBlock(SourceLocation Loc,
   3476                                  Expr *FilterExpr,
   3477                                  Stmt *Block);
   3478   void ActOnStartSEHFinallyBlock();
   3479   void ActOnAbortSEHFinallyBlock();
   3480   StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block);
   3481   StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope);
   3482 
   3483   void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock);
   3484 
   3485   bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const;
   3486 
   3487   /// \brief If it's a file scoped decl that must warn if not used, keep track
   3488   /// of it.
   3489   void MarkUnusedFileScopedDecl(const DeclaratorDecl *D);
   3490 
   3491   /// DiagnoseUnusedExprResult - If the statement passed in is an expression
   3492   /// whose result is unused, warn.
   3493   void DiagnoseUnusedExprResult(const Stmt *S);
   3494   void DiagnoseUnusedNestedTypedefs(const RecordDecl *D);
   3495   void DiagnoseUnusedDecl(const NamedDecl *ND);
   3496 
   3497   /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null
   3498   /// statement as a \p Body, and it is located on the same line.
   3499   ///
   3500   /// This helps prevent bugs due to typos, such as:
   3501   ///     if (condition);
   3502   ///       do_stuff();
   3503   void DiagnoseEmptyStmtBody(SourceLocation StmtLoc,
   3504                              const Stmt *Body,
   3505                              unsigned DiagID);
   3506 
   3507   /// Warn if a for/while loop statement \p S, which is followed by
   3508   /// \p PossibleBody, has a suspicious null statement as a body.
   3509   void DiagnoseEmptyLoopBody(const Stmt *S,
   3510                              const Stmt *PossibleBody);
   3511 
   3512   /// Warn if a value is moved to itself.
   3513   void DiagnoseSelfMove(const Expr *LHSExpr, const Expr *RHSExpr,
   3514                         SourceLocation OpLoc);
   3515 
   3516   /// \brief Warn if we're implicitly casting from a _Nullable pointer type to a
   3517   /// _Nonnull one.
   3518   void diagnoseNullableToNonnullConversion(QualType DstType, QualType SrcType,
   3519                                            SourceLocation Loc);
   3520 
   3521   ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool) {
   3522     return DelayedDiagnostics.push(pool);
   3523   }
   3524   void PopParsingDeclaration(ParsingDeclState state, Decl *decl);
   3525 
   3526   typedef ProcessingContextState ParsingClassState;
   3527   ParsingClassState PushParsingClass() {
   3528     return DelayedDiagnostics.pushUndelayed();
   3529   }
   3530   void PopParsingClass(ParsingClassState state) {
   3531     DelayedDiagnostics.popUndelayed(state);
   3532   }
   3533 
   3534   void redelayDiagnostics(sema::DelayedDiagnosticPool &pool);
   3535 
   3536   enum AvailabilityDiagnostic { AD_Deprecation, AD_Unavailable, AD_Partial };
   3537 
   3538   void EmitAvailabilityWarning(AvailabilityDiagnostic AD,
   3539                                NamedDecl *D, StringRef Message,
   3540                                SourceLocation Loc,
   3541                                const ObjCInterfaceDecl *UnknownObjCClass,
   3542                                const ObjCPropertyDecl  *ObjCProperty,
   3543                                bool ObjCPropertyAccess);
   3544 
   3545   bool makeUnavailableInSystemHeader(SourceLocation loc,
   3546                                      UnavailableAttr::ImplicitReason reason);
   3547 
   3548   //===--------------------------------------------------------------------===//
   3549   // Expression Parsing Callbacks: SemaExpr.cpp.
   3550 
   3551   bool CanUseDecl(NamedDecl *D);
   3552   bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
   3553                          const ObjCInterfaceDecl *UnknownObjCClass=nullptr,
   3554                          bool ObjCPropertyAccess=false);
   3555   void NoteDeletedFunction(FunctionDecl *FD);
   3556   std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD);
   3557   bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
   3558                                         ObjCMethodDecl *Getter,
   3559                                         SourceLocation Loc);
   3560   void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
   3561                              ArrayRef<Expr *> Args);
   3562 
   3563   void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext,
   3564                                        Decl *LambdaContextDecl = nullptr,
   3565                                        bool IsDecltype = false);
   3566   enum ReuseLambdaContextDecl_t { ReuseLambdaContextDecl };
   3567   void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext,
   3568                                        ReuseLambdaContextDecl_t,
   3569                                        bool IsDecltype = false);
   3570   void PopExpressionEvaluationContext();
   3571 
   3572   void DiscardCleanupsInEvaluationContext();
   3573 
   3574   ExprResult TransformToPotentiallyEvaluated(Expr *E);
   3575   ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
   3576 
   3577   ExprResult ActOnConstantExpression(ExprResult Res);
   3578 
   3579   // Functions for marking a declaration referenced.  These functions also
   3580   // contain the relevant logic for marking if a reference to a function or
   3581   // variable is an odr-use (in the C++11 sense).  There are separate variants
   3582   // for expressions referring to a decl; these exist because odr-use marking
   3583   // needs to be delayed for some constant variables when we build one of the
   3584   // named expressions.
   3585   void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool OdrUse);
   3586   void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func,
   3587                               bool OdrUse = true);
   3588   void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var);
   3589   void MarkDeclRefReferenced(DeclRefExpr *E);
   3590   void MarkMemberReferenced(MemberExpr *E);
   3591 
   3592   void UpdateMarkingForLValueToRValue(Expr *E);
   3593   void CleanupVarDeclMarking();
   3594 
   3595   enum TryCaptureKind {
   3596     TryCapture_Implicit, TryCapture_ExplicitByVal, TryCapture_ExplicitByRef
   3597   };
   3598 
   3599   /// \brief Try to capture the given variable.
   3600   ///
   3601   /// \param Var The variable to capture.
   3602   ///
   3603   /// \param Loc The location at which the capture occurs.
   3604   ///
   3605   /// \param Kind The kind of capture, which may be implicit (for either a
   3606   /// block or a lambda), or explicit by-value or by-reference (for a lambda).
   3607   ///
   3608   /// \param EllipsisLoc The location of the ellipsis, if one is provided in
   3609   /// an explicit lambda capture.
   3610   ///
   3611   /// \param BuildAndDiagnose Whether we are actually supposed to add the
   3612   /// captures or diagnose errors. If false, this routine merely check whether
   3613   /// the capture can occur without performing the capture itself or complaining
   3614   /// if the variable cannot be captured.
   3615   ///
   3616   /// \param CaptureType Will be set to the type of the field used to capture
   3617   /// this variable in the innermost block or lambda. Only valid when the
   3618   /// variable can be captured.
   3619   ///
   3620   /// \param DeclRefType Will be set to the type of a reference to the capture
   3621   /// from within the current scope. Only valid when the variable can be
   3622   /// captured.
   3623   ///
   3624   /// \param FunctionScopeIndexToStopAt If non-null, it points to the index
   3625   /// of the FunctionScopeInfo stack beyond which we do not attempt to capture.
   3626   /// This is useful when enclosing lambdas must speculatively capture
   3627   /// variables that may or may not be used in certain specializations of
   3628   /// a nested generic lambda.
   3629   ///
   3630   /// \returns true if an error occurred (i.e., the variable cannot be
   3631   /// captured) and false if the capture succeeded.
   3632   bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, TryCaptureKind Kind,
   3633                           SourceLocation EllipsisLoc, bool BuildAndDiagnose,
   3634                           QualType &CaptureType,
   3635                           QualType &DeclRefType,
   3636                           const unsigned *const FunctionScopeIndexToStopAt);
   3637 
   3638   /// \brief Try to capture the given variable.
   3639   bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc,
   3640                           TryCaptureKind Kind = TryCapture_Implicit,
   3641                           SourceLocation EllipsisLoc = SourceLocation());
   3642 
   3643   /// \brief Checks if the variable must be captured.
   3644   bool NeedToCaptureVariable(VarDecl *Var, SourceLocation Loc);
   3645 
   3646   /// \brief Given a variable, determine the type that a reference to that
   3647   /// variable will have in the given scope.
   3648   QualType getCapturedDeclRefType(VarDecl *Var, SourceLocation Loc);
   3649 
   3650   void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T);
   3651   void MarkDeclarationsReferencedInExpr(Expr *E,
   3652                                         bool SkipLocalVariables = false);
   3653 
   3654   /// \brief Try to recover by turning the given expression into a
   3655   /// call.  Returns true if recovery was attempted or an error was
   3656   /// emitted; this may also leave the ExprResult invalid.
   3657   bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD,
   3658                             bool ForceComplain = false,
   3659                             bool (*IsPlausibleResult)(QualType) = nullptr);
   3660 
   3661   /// \brief Figure out if an expression could be turned into a call.
   3662   bool tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy,
   3663                      UnresolvedSetImpl &NonTemplateOverloads);
   3664 
   3665   /// \brief Conditionally issue a diagnostic based on the current
   3666   /// evaluation context.
   3667   ///
   3668   /// \param Statement If Statement is non-null, delay reporting the
   3669   /// diagnostic until the function body is parsed, and then do a basic
   3670   /// reachability analysis to determine if the statement is reachable.
   3671   /// If it is unreachable, the diagnostic will not be emitted.
   3672   bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement,
   3673                            const PartialDiagnostic &PD);
   3674 
   3675   // Primary Expressions.
   3676   SourceRange getExprRange(Expr *E) const;
   3677 
   3678   ExprResult ActOnIdExpression(
   3679       Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
   3680       UnqualifiedId &Id, bool HasTrailingLParen, bool IsAddressOfOperand,
   3681       std::unique_ptr<CorrectionCandidateCallback> CCC = nullptr,
   3682       bool IsInlineAsmIdentifier = false, Token *KeywordReplacement = nullptr);
   3683 
   3684   void DecomposeUnqualifiedId(const UnqualifiedId &Id,
   3685                               TemplateArgumentListInfo &Buffer,
   3686                               DeclarationNameInfo &NameInfo,
   3687                               const TemplateArgumentListInfo *&TemplateArgs);
   3688 
   3689   bool
   3690   DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
   3691                       std::unique_ptr<CorrectionCandidateCallback> CCC,
   3692                       TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr,
   3693                       ArrayRef<Expr *> Args = None, TypoExpr **Out = nullptr);
   3694 
   3695   ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S,
   3696                                 IdentifierInfo *II,
   3697                                 bool AllowBuiltinCreation=false);
   3698 
   3699   ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS,
   3700                                         SourceLocation TemplateKWLoc,
   3701                                         const DeclarationNameInfo &NameInfo,
   3702                                         bool isAddressOfOperand,
   3703                                 const TemplateArgumentListInfo *TemplateArgs);
   3704 
   3705   ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
   3706                               ExprValueKind VK,
   3707                               SourceLocation Loc,
   3708                               const CXXScopeSpec *SS = nullptr);
   3709   ExprResult
   3710   BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK,
   3711                    const DeclarationNameInfo &NameInfo,
   3712                    const CXXScopeSpec *SS = nullptr,
   3713                    NamedDecl *FoundD = nullptr,
   3714                    const TemplateArgumentListInfo *TemplateArgs = nullptr);
   3715   ExprResult
   3716   BuildAnonymousStructUnionMemberReference(
   3717       const CXXScopeSpec &SS,
   3718       SourceLocation nameLoc,
   3719       IndirectFieldDecl *indirectField,
   3720       DeclAccessPair FoundDecl = DeclAccessPair::make(nullptr, AS_none),
   3721       Expr *baseObjectExpr = nullptr,
   3722       SourceLocation opLoc = SourceLocation());
   3723 
   3724   ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
   3725                                              SourceLocation TemplateKWLoc,
   3726                                              LookupResult &R,
   3727                                 const TemplateArgumentListInfo *TemplateArgs,
   3728                                              const Scope *S);
   3729   ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS,
   3730                                      SourceLocation TemplateKWLoc,
   3731                                      LookupResult &R,
   3732                                 const TemplateArgumentListInfo *TemplateArgs,
   3733                                      bool IsDefiniteInstance,
   3734                                      const Scope *S);
   3735   bool UseArgumentDependentLookup(const CXXScopeSpec &SS,
   3736                                   const LookupResult &R,
   3737                                   bool HasTrailingLParen);
   3738 
   3739   ExprResult
   3740   BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS,
   3741                                     const DeclarationNameInfo &NameInfo,
   3742                                     bool IsAddressOfOperand, const Scope *S,
   3743                                     TypeSourceInfo **RecoveryTSI = nullptr);
   3744 
   3745   ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
   3746                                        SourceLocation TemplateKWLoc,
   3747                                 const DeclarationNameInfo &NameInfo,
   3748                                 const TemplateArgumentListInfo *TemplateArgs);
   3749 
   3750   ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
   3751                                       LookupResult &R,
   3752                                       bool NeedsADL,
   3753                                       bool AcceptInvalidDecl = false);
   3754   ExprResult BuildDeclarationNameExpr(
   3755       const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D,
   3756       NamedDecl *FoundD = nullptr,
   3757       const TemplateArgumentListInfo *TemplateArgs = nullptr,
   3758       bool AcceptInvalidDecl = false);
   3759 
   3760   ExprResult BuildLiteralOperatorCall(LookupResult &R,
   3761                       DeclarationNameInfo &SuffixInfo,
   3762                       ArrayRef<Expr *> Args,
   3763                       SourceLocation LitEndLoc,
   3764                       TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr);
   3765 
   3766   ExprResult BuildPredefinedExpr(SourceLocation Loc,
   3767                                  PredefinedExpr::IdentType IT);
   3768   ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
   3769   ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val);
   3770 
   3771   bool CheckLoopHintExpr(Expr *E, SourceLocation Loc);
   3772 
   3773   ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr);
   3774   ExprResult ActOnCharacterConstant(const Token &Tok,
   3775                                     Scope *UDLScope = nullptr);
   3776   ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E);
   3777   ExprResult ActOnParenListExpr(SourceLocation L,
   3778                                 SourceLocation R,
   3779                                 MultiExprArg Val);
   3780 
   3781   /// ActOnStringLiteral - The specified tokens were lexed as pasted string
   3782   /// fragments (e.g. "foo" "bar" L"baz").
   3783   ExprResult ActOnStringLiteral(ArrayRef<Token> StringToks,
   3784                                 Scope *UDLScope = nullptr);
   3785 
   3786   ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc,
   3787                                        SourceLocation DefaultLoc,
   3788                                        SourceLocation RParenLoc,
   3789                                        Expr *ControllingExpr,
   3790                                        ArrayRef<ParsedType> ArgTypes,
   3791                                        ArrayRef<Expr *> ArgExprs);
   3792   ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc,
   3793                                         SourceLocation DefaultLoc,
   3794                                         SourceLocation RParenLoc,
   3795                                         Expr *ControllingExpr,
   3796                                         ArrayRef<TypeSourceInfo *> Types,
   3797                                         ArrayRef<Expr *> Exprs);
   3798 
   3799   // Binary/Unary Operators.  'Tok' is the token for the operator.
   3800   ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc,
   3801                                   Expr *InputExpr);
   3802   ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc,
   3803                           UnaryOperatorKind Opc, Expr *Input);
   3804   ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
   3805                           tok::TokenKind Op, Expr *Input);
   3806 
   3807   QualType CheckAddressOfOperand(ExprResult &Operand, SourceLocation OpLoc);
   3808 
   3809   ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo,
   3810                                             SourceLocation OpLoc,
   3811                                             UnaryExprOrTypeTrait ExprKind,
   3812                                             SourceRange R);
   3813   ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc,
   3814                                             UnaryExprOrTypeTrait ExprKind);
   3815   ExprResult
   3816     ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc,
   3817                                   UnaryExprOrTypeTrait ExprKind,
   3818                                   bool IsType, void *TyOrEx,
   3819                                   SourceRange ArgRange);
   3820 
   3821   ExprResult CheckPlaceholderExpr(Expr *E);
   3822   bool CheckVecStepExpr(Expr *E);
   3823 
   3824   bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind);
   3825   bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc,
   3826                                         SourceRange ExprRange,
   3827                                         UnaryExprOrTypeTrait ExprKind);
   3828   ExprResult ActOnSizeofParameterPackExpr(Scope *S,
   3829                                           SourceLocation OpLoc,
   3830                                           IdentifierInfo &Name,
   3831                                           SourceLocation NameLoc,
   3832                                           SourceLocation RParenLoc);
   3833   ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
   3834                                  tok::TokenKind Kind, Expr *Input);
   3835 
   3836   ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc,
   3837                                      Expr *Idx, SourceLocation RLoc);
   3838   ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc,
   3839                                              Expr *Idx, SourceLocation RLoc);
   3840   ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc,
   3841                                       Expr *LowerBound, SourceLocation ColonLoc,
   3842                                       Expr *Length, SourceLocation RBLoc);
   3843 
   3844   // This struct is for use by ActOnMemberAccess to allow
   3845   // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after
   3846   // changing the access operator from a '.' to a '->' (to see if that is the
   3847   // change needed to fix an error about an unknown member, e.g. when the class
   3848   // defines a custom operator->).
   3849   struct ActOnMemberAccessExtraArgs {
   3850     Scope *S;
   3851     UnqualifiedId &Id;
   3852     Decl *ObjCImpDecl;
   3853   };
   3854 
   3855   ExprResult BuildMemberReferenceExpr(
   3856       Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow,
   3857       CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
   3858       NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo,
   3859       const TemplateArgumentListInfo *TemplateArgs,
   3860       const Scope *S,
   3861       ActOnMemberAccessExtraArgs *ExtraArgs = nullptr);
   3862 
   3863   ExprResult
   3864   BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc,
   3865                            bool IsArrow, const CXXScopeSpec &SS,
   3866                            SourceLocation TemplateKWLoc,
   3867                            NamedDecl *FirstQualifierInScope, LookupResult &R,
   3868                            const TemplateArgumentListInfo *TemplateArgs,
   3869                            const Scope *S,
   3870                            bool SuppressQualifierCheck = false,
   3871                            ActOnMemberAccessExtraArgs *ExtraArgs = nullptr);
   3872 
   3873   ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow);
   3874 
   3875   bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType,
   3876                                      const CXXScopeSpec &SS,
   3877                                      const LookupResult &R);
   3878 
   3879   ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType,
   3880                                       bool IsArrow, SourceLocation OpLoc,
   3881                                       const CXXScopeSpec &SS,
   3882                                       SourceLocation TemplateKWLoc,
   3883                                       NamedDecl *FirstQualifierInScope,
   3884                                const DeclarationNameInfo &NameInfo,
   3885                                const TemplateArgumentListInfo *TemplateArgs);
   3886 
   3887   ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base,
   3888                                    SourceLocation OpLoc,
   3889                                    tok::TokenKind OpKind,
   3890                                    CXXScopeSpec &SS,
   3891                                    SourceLocation TemplateKWLoc,
   3892                                    UnqualifiedId &Member,
   3893                                    Decl *ObjCImpDecl);
   3894 
   3895   void ActOnDefaultCtorInitializers(Decl *CDtorDecl);
   3896   bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
   3897                                FunctionDecl *FDecl,
   3898                                const FunctionProtoType *Proto,
   3899                                ArrayRef<Expr *> Args,
   3900                                SourceLocation RParenLoc,
   3901                                bool ExecConfig = false);
   3902   void CheckStaticArrayArgument(SourceLocation CallLoc,
   3903                                 ParmVarDecl *Param,
   3904                                 const Expr *ArgExpr);
   3905 
   3906   /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
   3907   /// This provides the location of the left/right parens and a list of comma
   3908   /// locations.
   3909   ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc,
   3910                            MultiExprArg ArgExprs, SourceLocation RParenLoc,
   3911                            Expr *ExecConfig = nullptr,
   3912                            bool IsExecConfig = false);
   3913   ExprResult BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl,
   3914                                    SourceLocation LParenLoc,
   3915                                    ArrayRef<Expr *> Arg,
   3916                                    SourceLocation RParenLoc,
   3917                                    Expr *Config = nullptr,
   3918                                    bool IsExecConfig = false);
   3919 
   3920   ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc,
   3921                                      MultiExprArg ExecConfig,
   3922                                      SourceLocation GGGLoc);
   3923 
   3924   ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc,
   3925                            Declarator &D, ParsedType &Ty,
   3926                            SourceLocation RParenLoc, Expr *CastExpr);
   3927   ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc,
   3928                                  TypeSourceInfo *Ty,
   3929                                  SourceLocation RParenLoc,
   3930                                  Expr *Op);
   3931   CastKind PrepareScalarCast(ExprResult &src, QualType destType);
   3932 
   3933   /// \brief Build an altivec or OpenCL literal.
   3934   ExprResult BuildVectorLiteral(SourceLocation LParenLoc,
   3935                                 SourceLocation RParenLoc, Expr *E,
   3936                                 TypeSourceInfo *TInfo);
   3937 
   3938   ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME);
   3939 
   3940   ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
   3941                                   ParsedType Ty,
   3942                                   SourceLocation RParenLoc,
   3943                                   Expr *InitExpr);
   3944 
   3945   ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc,
   3946                                       TypeSourceInfo *TInfo,
   3947                                       SourceLocation RParenLoc,
   3948                                       Expr *LiteralExpr);
   3949 
   3950   ExprResult ActOnInitList(SourceLocation LBraceLoc,
   3951                            MultiExprArg InitArgList,
   3952                            SourceLocation RBraceLoc);
   3953 
   3954   ExprResult ActOnDesignatedInitializer(Designation &Desig,
   3955                                         SourceLocation Loc,
   3956                                         bool GNUSyntax,
   3957                                         ExprResult Init);
   3958 
   3959 private:
   3960   static BinaryOperatorKind ConvertTokenKindToBinaryOpcode(tok::TokenKind Kind);
   3961 
   3962 public:
   3963   ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
   3964                         tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr);
   3965   ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc,
   3966                         BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr);
   3967   ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc,
   3968                                 Expr *LHSExpr, Expr *RHSExpr);
   3969 
   3970   /// ActOnConditionalOp - Parse a ?: operation.  Note that 'LHS' may be null
   3971   /// in the case of a the GNU conditional expr extension.
   3972   ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
   3973                                 SourceLocation ColonLoc,
   3974                                 Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr);
   3975 
   3976   /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
   3977   ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
   3978                             LabelDecl *TheDecl);
   3979 
   3980   void ActOnStartStmtExpr();
   3981   ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt,
   3982                            SourceLocation RPLoc); // "({..})"
   3983   void ActOnStmtExprError();
   3984 
   3985   // __builtin_offsetof(type, identifier(.identifier|[expr])*)
   3986   struct OffsetOfComponent {
   3987     SourceLocation LocStart, LocEnd;
   3988     bool isBrackets;  // true if [expr], false if .ident
   3989     union {
   3990       IdentifierInfo *IdentInfo;
   3991       Expr *E;
   3992     } U;
   3993   };
   3994 
   3995   /// __builtin_offsetof(type, a.b[123][456].c)
   3996   ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc,
   3997                                   TypeSourceInfo *TInfo,
   3998                                   ArrayRef<OffsetOfComponent> Components,
   3999                                   SourceLocation RParenLoc);
   4000   ExprResult ActOnBuiltinOffsetOf(Scope *S,
   4001                                   SourceLocation BuiltinLoc,
   4002                                   SourceLocation TypeLoc,
   4003                                   ParsedType ParsedArgTy,
   4004                                   ArrayRef<OffsetOfComponent> Components,
   4005                                   SourceLocation RParenLoc);
   4006 
   4007   // __builtin_choose_expr(constExpr, expr1, expr2)
   4008   ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
   4009                              Expr *CondExpr, Expr *LHSExpr,
   4010                              Expr *RHSExpr, SourceLocation RPLoc);
   4011 
   4012   // __builtin_va_arg(expr, type)
   4013   ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty,
   4014                         SourceLocation RPLoc);
   4015   ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E,
   4016                             TypeSourceInfo *TInfo, SourceLocation RPLoc);
   4017 
   4018   // __null
   4019   ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
   4020 
   4021   bool CheckCaseExpression(Expr *E);
   4022 
   4023   /// \brief Describes the result of an "if-exists" condition check.
   4024   enum IfExistsResult {
   4025     /// \brief The symbol exists.
   4026     IER_Exists,
   4027 
   4028     /// \brief The symbol does not exist.
   4029     IER_DoesNotExist,
   4030 
   4031     /// \brief The name is a dependent name, so the results will differ
   4032     /// from one instantiation to the next.
   4033     IER_Dependent,
   4034 
   4035     /// \brief An error occurred.
   4036     IER_Error
   4037   };
   4038 
   4039   IfExistsResult
   4040   CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS,
   4041                                const DeclarationNameInfo &TargetNameInfo);
   4042 
   4043   IfExistsResult
   4044   CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc,
   4045                                bool IsIfExists, CXXScopeSpec &SS,
   4046                                UnqualifiedId &Name);
   4047 
   4048   StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc,
   4049                                         bool IsIfExists,
   4050                                         NestedNameSpecifierLoc QualifierLoc,
   4051                                         DeclarationNameInfo NameInfo,
   4052                                         Stmt *Nested);
   4053   StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc,
   4054                                         bool IsIfExists,
   4055                                         CXXScopeSpec &SS, UnqualifiedId &Name,
   4056                                         Stmt *Nested);
   4057 
   4058   //===------------------------- "Block" Extension ------------------------===//
   4059 
   4060   /// ActOnBlockStart - This callback is invoked when a block literal is
   4061   /// started.
   4062   void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
   4063 
   4064   /// ActOnBlockArguments - This callback allows processing of block arguments.
   4065   /// If there are no arguments, this is still invoked.
   4066   void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo,
   4067                            Scope *CurScope);
   4068 
   4069   /// ActOnBlockError - If there is an error parsing a block, this callback
   4070   /// is invoked to pop the information about the block from the action impl.
   4071   void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
   4072 
   4073   /// ActOnBlockStmtExpr - This is called when the body of a block statement
   4074   /// literal was successfully completed.  ^(int x){...}
   4075   ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body,
   4076                                 Scope *CurScope);
   4077 
   4078   //===---------------------------- Clang Extensions ----------------------===//
   4079 
   4080   /// __builtin_convertvector(...)
   4081   ExprResult ActOnConvertVectorExpr(Expr *E, ParsedType ParsedDestTy,
   4082                                     SourceLocation BuiltinLoc,
   4083                                     SourceLocation RParenLoc);
   4084 
   4085   //===---------------------------- OpenCL Features -----------------------===//
   4086 
   4087   /// __builtin_astype(...)
   4088   ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy,
   4089                              SourceLocation BuiltinLoc,
   4090                              SourceLocation RParenLoc);
   4091 
   4092   //===---------------------------- C++ Features --------------------------===//
   4093 
   4094   // Act on C++ namespaces
   4095   Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc,
   4096                                SourceLocation NamespaceLoc,
   4097                                SourceLocation IdentLoc,
   4098                                IdentifierInfo *Ident,
   4099                                SourceLocation LBrace,
   4100                                AttributeList *AttrList,
   4101                                UsingDirectiveDecl * &UsingDecl);
   4102   void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace);
   4103 
   4104   NamespaceDecl *getStdNamespace() const;
   4105   NamespaceDecl *getOrCreateStdNamespace();
   4106 
   4107   CXXRecordDecl *getStdBadAlloc() const;
   4108 
   4109   /// \brief Tests whether Ty is an instance of std::initializer_list and, if
   4110   /// it is and Element is not NULL, assigns the element type to Element.
   4111   bool isStdInitializerList(QualType Ty, QualType *Element);
   4112 
   4113   /// \brief Looks for the std::initializer_list template and instantiates it
   4114   /// with Element, or emits an error if it's not found.
   4115   ///
   4116   /// \returns The instantiated template, or null on error.
   4117   QualType BuildStdInitializerList(QualType Element, SourceLocation Loc);
   4118 
   4119   /// \brief Determine whether Ctor is an initializer-list constructor, as
   4120   /// defined in [dcl.init.list]p2.
   4121   bool isInitListConstructor(const CXXConstructorDecl *Ctor);
   4122 
   4123   Decl *ActOnUsingDirective(Scope *CurScope,
   4124                             SourceLocation UsingLoc,
   4125                             SourceLocation NamespcLoc,
   4126                             CXXScopeSpec &SS,
   4127                             SourceLocation IdentLoc,
   4128                             IdentifierInfo *NamespcName,
   4129                             AttributeList *AttrList);
   4130 
   4131   void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
   4132 
   4133   Decl *ActOnNamespaceAliasDef(Scope *CurScope,
   4134                                SourceLocation NamespaceLoc,
   4135                                SourceLocation AliasLoc,
   4136                                IdentifierInfo *Alias,
   4137                                CXXScopeSpec &SS,
   4138                                SourceLocation IdentLoc,
   4139                                IdentifierInfo *Ident);
   4140 
   4141   void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow);
   4142   bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target,
   4143                             const LookupResult &PreviousDecls,
   4144                             UsingShadowDecl *&PrevShadow);
   4145   UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD,
   4146                                         NamedDecl *Target,
   4147                                         UsingShadowDecl *PrevDecl);
   4148 
   4149   bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc,
   4150                                    bool HasTypenameKeyword,
   4151                                    const CXXScopeSpec &SS,
   4152                                    SourceLocation NameLoc,
   4153                                    const LookupResult &Previous);
   4154   bool CheckUsingDeclQualifier(SourceLocation UsingLoc,
   4155                                const CXXScopeSpec &SS,
   4156                                const DeclarationNameInfo &NameInfo,
   4157                                SourceLocation NameLoc);
   4158 
   4159   NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS,
   4160                                    SourceLocation UsingLoc,
   4161                                    CXXScopeSpec &SS,
   4162                                    DeclarationNameInfo NameInfo,
   4163                                    AttributeList *AttrList,
   4164                                    bool IsInstantiation,
   4165                                    bool HasTypenameKeyword,
   4166                                    SourceLocation TypenameLoc);
   4167 
   4168   bool CheckInheritingConstructorUsingDecl(UsingDecl *UD);
   4169 
   4170   Decl *ActOnUsingDeclaration(Scope *CurScope,
   4171                               AccessSpecifier AS,
   4172                               bool HasUsingKeyword,
   4173                               SourceLocation UsingLoc,
   4174                               CXXScopeSpec &SS,
   4175                               UnqualifiedId &Name,
   4176                               AttributeList *AttrList,
   4177                               bool HasTypenameKeyword,
   4178                               SourceLocation TypenameLoc);
   4179   Decl *ActOnAliasDeclaration(Scope *CurScope,
   4180                               AccessSpecifier AS,
   4181                               MultiTemplateParamsArg TemplateParams,
   4182                               SourceLocation UsingLoc,
   4183                               UnqualifiedId &Name,
   4184                               AttributeList *AttrList,
   4185                               TypeResult Type,
   4186                               Decl *DeclFromDeclSpec);
   4187 
   4188   /// BuildCXXConstructExpr - Creates a complete call to a constructor,
   4189   /// including handling of its default argument expressions.
   4190   ///
   4191   /// \param ConstructKind - a CXXConstructExpr::ConstructionKind
   4192   ExprResult
   4193   BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
   4194                         CXXConstructorDecl *Constructor, MultiExprArg Exprs,
   4195                         bool HadMultipleCandidates, bool IsListInitialization,
   4196                         bool IsStdInitListInitialization,
   4197                         bool RequiresZeroInit, unsigned ConstructKind,
   4198                         SourceRange ParenRange);
   4199 
   4200   // FIXME: Can we remove this and have the above BuildCXXConstructExpr check if
   4201   // the constructor can be elidable?
   4202   ExprResult
   4203   BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
   4204                         CXXConstructorDecl *Constructor, bool Elidable,
   4205                         MultiExprArg Exprs, bool HadMultipleCandidates,
   4206                         bool IsListInitialization,
   4207                         bool IsStdInitListInitialization, bool RequiresZeroInit,
   4208                         unsigned ConstructKind, SourceRange ParenRange);
   4209 
   4210   ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field);
   4211 
   4212   /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating
   4213   /// the default expr if needed.
   4214   ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc,
   4215                                     FunctionDecl *FD,
   4216                                     ParmVarDecl *Param);
   4217 
   4218   /// FinalizeVarWithDestructor - Prepare for calling destructor on the
   4219   /// constructed variable.
   4220   void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType);
   4221 
   4222   /// \brief Helper class that collects exception specifications for
   4223   /// implicitly-declared special member functions.
   4224   class ImplicitExceptionSpecification {
   4225     // Pointer to allow copying
   4226     Sema *Self;
   4227     // We order exception specifications thus:
   4228     // noexcept is the most restrictive, but is only used in C++11.
   4229     // throw() comes next.
   4230     // Then a throw(collected exceptions)
   4231     // Finally no specification, which is expressed as noexcept(false).
   4232     // throw(...) is used instead if any called function uses it.
   4233     ExceptionSpecificationType ComputedEST;
   4234     llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen;
   4235     SmallVector<QualType, 4> Exceptions;
   4236 
   4237     void ClearExceptions() {
   4238       ExceptionsSeen.clear();
   4239       Exceptions.clear();
   4240     }
   4241 
   4242   public:
   4243     explicit ImplicitExceptionSpecification(Sema &Self)
   4244       : Self(&Self), ComputedEST(EST_BasicNoexcept) {
   4245       if (!Self.getLangOpts().CPlusPlus11)
   4246         ComputedEST = EST_DynamicNone;
   4247     }
   4248 
   4249     /// \brief Get the computed exception specification type.
   4250     ExceptionSpecificationType getExceptionSpecType() const {
   4251       assert(ComputedEST != EST_ComputedNoexcept &&
   4252              "noexcept(expr) should not be a possible result");
   4253       return ComputedEST;
   4254     }
   4255 
   4256     /// \brief The number of exceptions in the exception specification.
   4257     unsigned size() const { return Exceptions.size(); }
   4258 
   4259     /// \brief The set of exceptions in the exception specification.
   4260     const QualType *data() const { return Exceptions.data(); }
   4261 
   4262     /// \brief Integrate another called method into the collected data.
   4263     void CalledDecl(SourceLocation CallLoc, const CXXMethodDecl *Method);
   4264 
   4265     /// \brief Integrate an invoked expression into the collected data.
   4266     void CalledExpr(Expr *E);
   4267 
   4268     /// \brief Overwrite an EPI's exception specification with this
   4269     /// computed exception specification.
   4270     FunctionProtoType::ExceptionSpecInfo getExceptionSpec() const {
   4271       FunctionProtoType::ExceptionSpecInfo ESI;
   4272       ESI.Type = getExceptionSpecType();
   4273       if (ESI.Type == EST_Dynamic) {
   4274         ESI.Exceptions = Exceptions;
   4275       } else if (ESI.Type == EST_None) {
   4276         /// C++11 [except.spec]p14:
   4277         ///   The exception-specification is noexcept(false) if the set of
   4278         ///   potential exceptions of the special member function contains "any"
   4279         ESI.Type = EST_ComputedNoexcept;
   4280         ESI.NoexceptExpr = Self->ActOnCXXBoolLiteral(SourceLocation(),
   4281                                                      tok::kw_false).get();
   4282       }
   4283       return ESI;
   4284     }
   4285   };
   4286 
   4287   /// \brief Determine what sort of exception specification a defaulted
   4288   /// copy constructor of a class will have.
   4289   ImplicitExceptionSpecification
   4290   ComputeDefaultedDefaultCtorExceptionSpec(SourceLocation Loc,
   4291                                            CXXMethodDecl *MD);
   4292 
   4293   /// \brief Determine what sort of exception specification a defaulted
   4294   /// default constructor of a class will have, and whether the parameter
   4295   /// will be const.
   4296   ImplicitExceptionSpecification
   4297   ComputeDefaultedCopyCtorExceptionSpec(CXXMethodDecl *MD);
   4298 
   4299   /// \brief Determine what sort of exception specification a defautled
   4300   /// copy assignment operator of a class will have, and whether the
   4301   /// parameter will be const.
   4302   ImplicitExceptionSpecification
   4303   ComputeDefaultedCopyAssignmentExceptionSpec(CXXMethodDecl *MD);
   4304 
   4305   /// \brief Determine what sort of exception specification a defaulted move
   4306   /// constructor of a class will have.
   4307   ImplicitExceptionSpecification
   4308   ComputeDefaultedMoveCtorExceptionSpec(CXXMethodDecl *MD);
   4309 
   4310   /// \brief Determine what sort of exception specification a defaulted move
   4311   /// assignment operator of a class will have.
   4312   ImplicitExceptionSpecification
   4313   ComputeDefaultedMoveAssignmentExceptionSpec(CXXMethodDecl *MD);
   4314 
   4315   /// \brief Determine what sort of exception specification a defaulted
   4316   /// destructor of a class will have.
   4317   ImplicitExceptionSpecification
   4318   ComputeDefaultedDtorExceptionSpec(CXXMethodDecl *MD);
   4319 
   4320   /// \brief Determine what sort of exception specification an inheriting
   4321   /// constructor of a class will have.
   4322   ImplicitExceptionSpecification
   4323   ComputeInheritingCtorExceptionSpec(CXXConstructorDecl *CD);
   4324 
   4325   /// \brief Evaluate the implicit exception specification for a defaulted
   4326   /// special member function.
   4327   void EvaluateImplicitExceptionSpec(SourceLocation Loc, CXXMethodDecl *MD);
   4328 
   4329   /// \brief Check the given exception-specification and update the
   4330   /// exception specification information with the results.
   4331   void checkExceptionSpecification(bool IsTopLevel,
   4332                                    ExceptionSpecificationType EST,
   4333                                    ArrayRef<ParsedType> DynamicExceptions,
   4334                                    ArrayRef<SourceRange> DynamicExceptionRanges,
   4335                                    Expr *NoexceptExpr,
   4336                                    SmallVectorImpl<QualType> &Exceptions,
   4337                                    FunctionProtoType::ExceptionSpecInfo &ESI);
   4338 
   4339   /// \brief Determine if we're in a case where we need to (incorrectly) eagerly
   4340   /// parse an exception specification to work around a libstdc++ bug.
   4341   bool isLibstdcxxEagerExceptionSpecHack(const Declarator &D);
   4342 
   4343   /// \brief Add an exception-specification to the given member function
   4344   /// (or member function template). The exception-specification was parsed
   4345   /// after the method itself was declared.
   4346   void actOnDelayedExceptionSpecification(Decl *Method,
   4347          ExceptionSpecificationType EST,
   4348          SourceRange SpecificationRange,
   4349          ArrayRef<ParsedType> DynamicExceptions,
   4350          ArrayRef<SourceRange> DynamicExceptionRanges,
   4351          Expr *NoexceptExpr);
   4352 
   4353   /// \brief Determine if a special member function should have a deleted
   4354   /// definition when it is defaulted.
   4355   bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM,
   4356                                  bool Diagnose = false);
   4357 
   4358   /// \brief Declare the implicit default constructor for the given class.
   4359   ///
   4360   /// \param ClassDecl The class declaration into which the implicit
   4361   /// default constructor will be added.
   4362   ///
   4363   /// \returns The implicitly-declared default constructor.
   4364   CXXConstructorDecl *DeclareImplicitDefaultConstructor(
   4365                                                      CXXRecordDecl *ClassDecl);
   4366 
   4367   /// DefineImplicitDefaultConstructor - Checks for feasibility of
   4368   /// defining this constructor as the default constructor.
   4369   void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
   4370                                         CXXConstructorDecl *Constructor);
   4371 
   4372   /// \brief Declare the implicit destructor for the given class.
   4373   ///
   4374   /// \param ClassDecl The class declaration into which the implicit
   4375   /// destructor will be added.
   4376   ///
   4377   /// \returns The implicitly-declared destructor.
   4378   CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl);
   4379 
   4380   /// DefineImplicitDestructor - Checks for feasibility of
   4381   /// defining this destructor as the default destructor.
   4382   void DefineImplicitDestructor(SourceLocation CurrentLocation,
   4383                                 CXXDestructorDecl *Destructor);
   4384 
   4385   /// \brief Build an exception spec for destructors that don't have one.
   4386   ///
   4387   /// C++11 says that user-defined destructors with no exception spec get one
   4388   /// that looks as if the destructor was implicitly declared.
   4389   void AdjustDestructorExceptionSpec(CXXRecordDecl *ClassDecl,
   4390                                      CXXDestructorDecl *Destructor);
   4391 
   4392   /// \brief Declare all inheriting constructors for the given class.
   4393   ///
   4394   /// \param ClassDecl The class declaration into which the inheriting
   4395   /// constructors will be added.
   4396   void DeclareInheritingConstructors(CXXRecordDecl *ClassDecl);
   4397 
   4398   /// \brief Define the specified inheriting constructor.
   4399   void DefineInheritingConstructor(SourceLocation UseLoc,
   4400                                    CXXConstructorDecl *Constructor);
   4401 
   4402   /// \brief Declare the implicit copy constructor for the given class.
   4403   ///
   4404   /// \param ClassDecl The class declaration into which the implicit
   4405   /// copy constructor will be added.
   4406   ///
   4407   /// \returns The implicitly-declared copy constructor.
   4408   CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl);
   4409 
   4410   /// DefineImplicitCopyConstructor - Checks for feasibility of
   4411   /// defining this constructor as the copy constructor.
   4412   void DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
   4413                                      CXXConstructorDecl *Constructor);
   4414 
   4415   /// \brief Declare the implicit move constructor for the given class.
   4416   ///
   4417   /// \param ClassDecl The Class declaration into which the implicit
   4418   /// move constructor will be added.
   4419   ///
   4420   /// \returns The implicitly-declared move constructor, or NULL if it wasn't
   4421   /// declared.
   4422   CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl);
   4423 
   4424   /// DefineImplicitMoveConstructor - Checks for feasibility of
   4425   /// defining this constructor as the move constructor.
   4426   void DefineImplicitMoveConstructor(SourceLocation CurrentLocation,
   4427                                      CXXConstructorDecl *Constructor);
   4428 
   4429   /// \brief Declare the implicit copy assignment operator for the given class.
   4430   ///
   4431   /// \param ClassDecl The class declaration into which the implicit
   4432   /// copy assignment operator will be added.
   4433   ///
   4434   /// \returns The implicitly-declared copy assignment operator.
   4435   CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl);
   4436 
   4437   /// \brief Defines an implicitly-declared copy assignment operator.
   4438   void DefineImplicitCopyAssignment(SourceLocation CurrentLocation,
   4439                                     CXXMethodDecl *MethodDecl);
   4440 
   4441   /// \brief Declare the implicit move assignment operator for the given class.
   4442   ///
   4443   /// \param ClassDecl The Class declaration into which the implicit
   4444   /// move assignment operator will be added.
   4445   ///
   4446   /// \returns The implicitly-declared move assignment operator, or NULL if it
   4447   /// wasn't declared.
   4448   CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl);
   4449 
   4450   /// \brief Defines an implicitly-declared move assignment operator.
   4451   void DefineImplicitMoveAssignment(SourceLocation CurrentLocation,
   4452                                     CXXMethodDecl *MethodDecl);
   4453 
   4454   /// \brief Force the declaration of any implicitly-declared members of this
   4455   /// class.
   4456   void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class);
   4457 
   4458   /// \brief Determine whether the given function is an implicitly-deleted
   4459   /// special member function.
   4460   bool isImplicitlyDeleted(FunctionDecl *FD);
   4461 
   4462   /// \brief Check whether 'this' shows up in the type of a static member
   4463   /// function after the (naturally empty) cv-qualifier-seq would be.
   4464   ///
   4465   /// \returns true if an error occurred.
   4466   bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method);
   4467 
   4468   /// \brief Whether this' shows up in the exception specification of a static
   4469   /// member function.
   4470   bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method);
   4471 
   4472   /// \brief Check whether 'this' shows up in the attributes of the given
   4473   /// static member function.
   4474   ///
   4475   /// \returns true if an error occurred.
   4476   bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method);
   4477 
   4478   /// MaybeBindToTemporary - If the passed in expression has a record type with
   4479   /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise
   4480   /// it simply returns the passed in expression.
   4481   ExprResult MaybeBindToTemporary(Expr *E);
   4482 
   4483   bool CompleteConstructorCall(CXXConstructorDecl *Constructor,
   4484                                MultiExprArg ArgsPtr,
   4485                                SourceLocation Loc,
   4486                                SmallVectorImpl<Expr*> &ConvertedArgs,
   4487                                bool AllowExplicit = false,
   4488                                bool IsListInitialization = false);
   4489 
   4490   ParsedType getInheritingConstructorName(CXXScopeSpec &SS,
   4491                                           SourceLocation NameLoc,
   4492                                           IdentifierInfo &Name);
   4493 
   4494   ParsedType getDestructorName(SourceLocation TildeLoc,
   4495                                IdentifierInfo &II, SourceLocation NameLoc,
   4496                                Scope *S, CXXScopeSpec &SS,
   4497                                ParsedType ObjectType,
   4498                                bool EnteringContext);
   4499 
   4500   ParsedType getDestructorType(const DeclSpec& DS, ParsedType ObjectType);
   4501 
   4502   // Checks that reinterpret casts don't have undefined behavior.
   4503   void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType,
   4504                                       bool IsDereference, SourceRange Range);
   4505 
   4506   /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
   4507   ExprResult ActOnCXXNamedCast(SourceLocation OpLoc,
   4508                                tok::TokenKind Kind,
   4509                                SourceLocation LAngleBracketLoc,
   4510                                Declarator &D,
   4511                                SourceLocation RAngleBracketLoc,
   4512                                SourceLocation LParenLoc,
   4513                                Expr *E,
   4514                                SourceLocation RParenLoc);
   4515 
   4516   ExprResult BuildCXXNamedCast(SourceLocation OpLoc,
   4517                                tok::TokenKind Kind,
   4518                                TypeSourceInfo *Ty,
   4519                                Expr *E,
   4520                                SourceRange AngleBrackets,
   4521                                SourceRange Parens);
   4522 
   4523   ExprResult BuildCXXTypeId(QualType TypeInfoType,
   4524                             SourceLocation TypeidLoc,
   4525                             TypeSourceInfo *Operand,
   4526                             SourceLocation RParenLoc);
   4527   ExprResult BuildCXXTypeId(QualType TypeInfoType,
   4528                             SourceLocation TypeidLoc,
   4529                             Expr *Operand,
   4530                             SourceLocation RParenLoc);
   4531 
   4532   /// ActOnCXXTypeid - Parse typeid( something ).
   4533   ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
   4534                             SourceLocation LParenLoc, bool isType,
   4535                             void *TyOrExpr,
   4536                             SourceLocation RParenLoc);
   4537 
   4538   ExprResult BuildCXXUuidof(QualType TypeInfoType,
   4539                             SourceLocation TypeidLoc,
   4540                             TypeSourceInfo *Operand,
   4541                             SourceLocation RParenLoc);
   4542   ExprResult BuildCXXUuidof(QualType TypeInfoType,
   4543                             SourceLocation TypeidLoc,
   4544                             Expr *Operand,
   4545                             SourceLocation RParenLoc);
   4546 
   4547   /// ActOnCXXUuidof - Parse __uuidof( something ).
   4548   ExprResult ActOnCXXUuidof(SourceLocation OpLoc,
   4549                             SourceLocation LParenLoc, bool isType,
   4550                             void *TyOrExpr,
   4551                             SourceLocation RParenLoc);
   4552 
   4553   /// \brief Handle a C++1z fold-expression: ( expr op ... op expr ).
   4554   ExprResult ActOnCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
   4555                               tok::TokenKind Operator,
   4556                               SourceLocation EllipsisLoc, Expr *RHS,
   4557                               SourceLocation RParenLoc);
   4558   ExprResult BuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
   4559                               BinaryOperatorKind Operator,
   4560                               SourceLocation EllipsisLoc, Expr *RHS,
   4561                               SourceLocation RParenLoc);
   4562   ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
   4563                                    BinaryOperatorKind Operator);
   4564 
   4565   //// ActOnCXXThis -  Parse 'this' pointer.
   4566   ExprResult ActOnCXXThis(SourceLocation loc);
   4567 
   4568   /// \brief Try to retrieve the type of the 'this' pointer.
   4569   ///
   4570   /// \returns The type of 'this', if possible. Otherwise, returns a NULL type.
   4571   QualType getCurrentThisType();
   4572 
   4573   /// \brief When non-NULL, the C++ 'this' expression is allowed despite the
   4574   /// current context not being a non-static member function. In such cases,
   4575   /// this provides the type used for 'this'.
   4576   QualType CXXThisTypeOverride;
   4577 
   4578   /// \brief RAII object used to temporarily allow the C++ 'this' expression
   4579   /// to be used, with the given qualifiers on the current class type.
   4580   class CXXThisScopeRAII {
   4581     Sema &S;
   4582     QualType OldCXXThisTypeOverride;
   4583     bool Enabled;
   4584 
   4585   public:
   4586     /// \brief Introduce a new scope where 'this' may be allowed (when enabled),
   4587     /// using the given declaration (which is either a class template or a
   4588     /// class) along with the given qualifiers.
   4589     /// along with the qualifiers placed on '*this'.
   4590     CXXThisScopeRAII(Sema &S, Decl *ContextDecl, unsigned CXXThisTypeQuals,
   4591                      bool Enabled = true);
   4592 
   4593     ~CXXThisScopeRAII();
   4594   };
   4595 
   4596   /// \brief Make sure the value of 'this' is actually available in the current
   4597   /// context, if it is a potentially evaluated context.
   4598   ///
   4599   /// \param Loc The location at which the capture of 'this' occurs.
   4600   ///
   4601   /// \param Explicit Whether 'this' is explicitly captured in a lambda
   4602   /// capture list.
   4603   ///
   4604   /// \param FunctionScopeIndexToStopAt If non-null, it points to the index
   4605   /// of the FunctionScopeInfo stack beyond which we do not attempt to capture.
   4606   /// This is useful when enclosing lambdas must speculatively capture
   4607   /// 'this' that may or may not be used in certain specializations of
   4608   /// a nested generic lambda (depending on whether the name resolves to
   4609   /// a non-static member function or a static function).
   4610   /// \return returns 'true' if failed, 'false' if success.
   4611   bool CheckCXXThisCapture(SourceLocation Loc, bool Explicit = false,
   4612       bool BuildAndDiagnose = true,
   4613       const unsigned *const FunctionScopeIndexToStopAt = nullptr);
   4614 
   4615   /// \brief Determine whether the given type is the type of *this that is used
   4616   /// outside of the body of a member function for a type that is currently
   4617   /// being defined.
   4618   bool isThisOutsideMemberFunctionBody(QualType BaseType);
   4619 
   4620   /// ActOnCXXBoolLiteral - Parse {true,false} literals.
   4621   ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
   4622 
   4623 
   4624   /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals.
   4625   ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
   4626 
   4627   /// ActOnCXXNullPtrLiteral - Parse 'nullptr'.
   4628   ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc);
   4629 
   4630   //// ActOnCXXThrow -  Parse throw expressions.
   4631   ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr);
   4632   ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex,
   4633                            bool IsThrownVarInScope);
   4634   bool CheckCXXThrowOperand(SourceLocation ThrowLoc, QualType ThrowTy, Expr *E);
   4635 
   4636   /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
   4637   /// Can be interpreted either as function-style casting ("int(x)")
   4638   /// or class type construction ("ClassType(x,y,z)")
   4639   /// or creation of a value-initialized type ("int()").
   4640   ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep,
   4641                                        SourceLocation LParenLoc,
   4642                                        MultiExprArg Exprs,
   4643                                        SourceLocation RParenLoc);
   4644 
   4645   ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type,
   4646                                        SourceLocation LParenLoc,
   4647                                        MultiExprArg Exprs,
   4648                                        SourceLocation RParenLoc);
   4649 
   4650   /// ActOnCXXNew - Parsed a C++ 'new' expression.
   4651   ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
   4652                          SourceLocation PlacementLParen,
   4653                          MultiExprArg PlacementArgs,
   4654                          SourceLocation PlacementRParen,
   4655                          SourceRange TypeIdParens, Declarator &D,
   4656                          Expr *Initializer);
   4657   ExprResult BuildCXXNew(SourceRange Range, bool UseGlobal,
   4658                          SourceLocation PlacementLParen,
   4659                          MultiExprArg PlacementArgs,
   4660                          SourceLocation PlacementRParen,
   4661                          SourceRange TypeIdParens,
   4662                          QualType AllocType,
   4663                          TypeSourceInfo *AllocTypeInfo,
   4664                          Expr *ArraySize,
   4665                          SourceRange DirectInitRange,
   4666                          Expr *Initializer,
   4667                          bool TypeMayContainAuto = true);
   4668 
   4669   bool CheckAllocatedType(QualType AllocType, SourceLocation Loc,
   4670                           SourceRange R);
   4671   bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
   4672                                bool UseGlobal, QualType AllocType, bool IsArray,
   4673                                MultiExprArg PlaceArgs,
   4674                                FunctionDecl *&OperatorNew,
   4675                                FunctionDecl *&OperatorDelete);
   4676   bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
   4677                               DeclarationName Name, MultiExprArg Args,
   4678                               DeclContext *Ctx,
   4679                               bool AllowMissing, FunctionDecl *&Operator,
   4680                               bool Diagnose = true);
   4681   void DeclareGlobalNewDelete();
   4682   void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
   4683                                        QualType Param1,
   4684                                        QualType Param2 = QualType(),
   4685                                        bool addRestrictAttr = false);
   4686 
   4687   bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD,
   4688                                 DeclarationName Name, FunctionDecl* &Operator,
   4689                                 bool Diagnose = true);
   4690   FunctionDecl *FindUsualDeallocationFunction(SourceLocation StartLoc,
   4691                                               bool CanProvideSize,
   4692                                               DeclarationName Name);
   4693 
   4694   /// ActOnCXXDelete - Parsed a C++ 'delete' expression
   4695   ExprResult ActOnCXXDelete(SourceLocation StartLoc,
   4696                             bool UseGlobal, bool ArrayForm,
   4697                             Expr *Operand);
   4698 
   4699   DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D);
   4700   ExprResult CheckConditionVariable(VarDecl *ConditionVar,
   4701                                     SourceLocation StmtLoc,
   4702                                     bool ConvertToBoolean);
   4703 
   4704   ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen,
   4705                                Expr *Operand, SourceLocation RParen);
   4706   ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand,
   4707                                   SourceLocation RParen);
   4708 
   4709   /// \brief Parsed one of the type trait support pseudo-functions.
   4710   ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc,
   4711                             ArrayRef<ParsedType> Args,
   4712                             SourceLocation RParenLoc);
   4713   ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc,
   4714                             ArrayRef<TypeSourceInfo *> Args,
   4715                             SourceLocation RParenLoc);
   4716 
   4717   /// ActOnArrayTypeTrait - Parsed one of the bianry type trait support
   4718   /// pseudo-functions.
   4719   ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT,
   4720                                  SourceLocation KWLoc,
   4721                                  ParsedType LhsTy,
   4722                                  Expr *DimExpr,
   4723                                  SourceLocation RParen);
   4724 
   4725   ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT,
   4726                                  SourceLocation KWLoc,
   4727                                  TypeSourceInfo *TSInfo,
   4728                                  Expr *DimExpr,
   4729                                  SourceLocation RParen);
   4730 
   4731   /// ActOnExpressionTrait - Parsed one of the unary type trait support
   4732   /// pseudo-functions.
   4733   ExprResult ActOnExpressionTrait(ExpressionTrait OET,
   4734                                   SourceLocation KWLoc,
   4735                                   Expr *Queried,
   4736                                   SourceLocation RParen);
   4737 
   4738   ExprResult BuildExpressionTrait(ExpressionTrait OET,
   4739                                   SourceLocation KWLoc,
   4740                                   Expr *Queried,
   4741                                   SourceLocation RParen);
   4742 
   4743   ExprResult ActOnStartCXXMemberReference(Scope *S,
   4744                                           Expr *Base,
   4745                                           SourceLocation OpLoc,
   4746                                           tok::TokenKind OpKind,
   4747                                           ParsedType &ObjectType,
   4748                                           bool &MayBePseudoDestructor);
   4749 
   4750   ExprResult BuildPseudoDestructorExpr(Expr *Base,
   4751                                        SourceLocation OpLoc,
   4752                                        tok::TokenKind OpKind,
   4753                                        const CXXScopeSpec &SS,
   4754                                        TypeSourceInfo *ScopeType,
   4755                                        SourceLocation CCLoc,
   4756                                        SourceLocation TildeLoc,
   4757                                      PseudoDestructorTypeStorage DestroyedType);
   4758 
   4759   ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
   4760                                        SourceLocation OpLoc,
   4761                                        tok::TokenKind OpKind,
   4762                                        CXXScopeSpec &SS,
   4763                                        UnqualifiedId &FirstTypeName,
   4764                                        SourceLocation CCLoc,
   4765                                        SourceLocation TildeLoc,
   4766                                        UnqualifiedId &SecondTypeName);
   4767 
   4768   ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
   4769                                        SourceLocation OpLoc,
   4770                                        tok::TokenKind OpKind,
   4771                                        SourceLocation TildeLoc,
   4772                                        const DeclSpec& DS);
   4773 
   4774   /// MaybeCreateExprWithCleanups - If the current full-expression
   4775   /// requires any cleanups, surround it with a ExprWithCleanups node.
   4776   /// Otherwise, just returns the passed-in expression.
   4777   Expr *MaybeCreateExprWithCleanups(Expr *SubExpr);
   4778   Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt);
   4779   ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr);
   4780 
   4781   ExprResult ActOnFinishFullExpr(Expr *Expr) {
   4782     return ActOnFinishFullExpr(Expr, Expr ? Expr->getExprLoc()
   4783                                           : SourceLocation());
   4784   }
   4785   ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC,
   4786                                  bool DiscardedValue = false,
   4787                                  bool IsConstexpr = false,
   4788                                  bool IsLambdaInitCaptureInitializer = false);
   4789   StmtResult ActOnFinishFullStmt(Stmt *Stmt);
   4790 
   4791   // Marks SS invalid if it represents an incomplete type.
   4792   bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC);
   4793 
   4794   DeclContext *computeDeclContext(QualType T);
   4795   DeclContext *computeDeclContext(const CXXScopeSpec &SS,
   4796                                   bool EnteringContext = false);
   4797   bool isDependentScopeSpecifier(const CXXScopeSpec &SS);
   4798   CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS);
   4799 
   4800   /// \brief The parser has parsed a global nested-name-specifier '::'.
   4801   ///
   4802   /// \param CCLoc The location of the '::'.
   4803   ///
   4804   /// \param SS The nested-name-specifier, which will be updated in-place
   4805   /// to reflect the parsed nested-name-specifier.
   4806   ///
   4807   /// \returns true if an error occurred, false otherwise.
   4808   bool ActOnCXXGlobalScopeSpecifier(SourceLocation CCLoc, CXXScopeSpec &SS);
   4809 
   4810   /// \brief The parser has parsed a '__super' nested-name-specifier.
   4811   ///
   4812   /// \param SuperLoc The location of the '__super' keyword.
   4813   ///
   4814   /// \param ColonColonLoc The location of the '::'.
   4815   ///
   4816   /// \param SS The nested-name-specifier, which will be updated in-place
   4817   /// to reflect the parsed nested-name-specifier.
   4818   ///
   4819   /// \returns true if an error occurred, false otherwise.
   4820   bool ActOnSuperScopeSpecifier(SourceLocation SuperLoc,
   4821                                 SourceLocation ColonColonLoc, CXXScopeSpec &SS);
   4822 
   4823   bool isAcceptableNestedNameSpecifier(const NamedDecl *SD,
   4824                                        bool *CanCorrect = nullptr);
   4825   NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS);
   4826 
   4827   bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS,
   4828                                     SourceLocation IdLoc,
   4829                                     IdentifierInfo &II,
   4830                                     ParsedType ObjectType);
   4831 
   4832   bool BuildCXXNestedNameSpecifier(Scope *S,
   4833                                    IdentifierInfo &Identifier,
   4834                                    SourceLocation IdentifierLoc,
   4835                                    SourceLocation CCLoc,
   4836                                    QualType ObjectType,
   4837                                    bool EnteringContext,
   4838                                    CXXScopeSpec &SS,
   4839                                    NamedDecl *ScopeLookupResult,
   4840                                    bool ErrorRecoveryLookup,
   4841                                    bool *IsCorrectedToColon = nullptr);
   4842 
   4843   /// \brief The parser has parsed a nested-name-specifier 'identifier::'.
   4844   ///
   4845   /// \param S The scope in which this nested-name-specifier occurs.
   4846   ///
   4847   /// \param Identifier The identifier preceding the '::'.
   4848   ///
   4849   /// \param IdentifierLoc The location of the identifier.
   4850   ///
   4851   /// \param CCLoc The location of the '::'.
   4852   ///
   4853   /// \param ObjectType The type of the object, if we're parsing
   4854   /// nested-name-specifier in a member access expression.
   4855   ///
   4856   /// \param EnteringContext Whether we're entering the context nominated by
   4857   /// this nested-name-specifier.
   4858   ///
   4859   /// \param SS The nested-name-specifier, which is both an input
   4860   /// parameter (the nested-name-specifier before this type) and an
   4861   /// output parameter (containing the full nested-name-specifier,
   4862   /// including this new type).
   4863   ///
   4864   /// \param ErrorRecoveryLookup If true, then this method is called to improve
   4865   /// error recovery. In this case do not emit error message.
   4866   ///
   4867   /// \param IsCorrectedToColon If not null, suggestions to replace '::' -> ':'
   4868   /// are allowed.  The bool value pointed by this parameter is set to 'true'
   4869   /// if the identifier is treated as if it was followed by ':', not '::'.
   4870   ///
   4871   /// \returns true if an error occurred, false otherwise.
   4872   bool ActOnCXXNestedNameSpecifier(Scope *S,
   4873                                    IdentifierInfo &Identifier,
   4874                                    SourceLocation IdentifierLoc,
   4875                                    SourceLocation CCLoc,
   4876                                    ParsedType ObjectType,
   4877                                    bool EnteringContext,
   4878                                    CXXScopeSpec &SS,
   4879                                    bool ErrorRecoveryLookup = false,
   4880                                    bool *IsCorrectedToColon = nullptr);
   4881 
   4882   ExprResult ActOnDecltypeExpression(Expr *E);
   4883 
   4884   bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS,
   4885                                            const DeclSpec &DS,
   4886                                            SourceLocation ColonColonLoc);
   4887 
   4888   bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS,
   4889                                  IdentifierInfo &Identifier,
   4890                                  SourceLocation IdentifierLoc,
   4891                                  SourceLocation ColonLoc,
   4892                                  ParsedType ObjectType,
   4893                                  bool EnteringContext);
   4894 
   4895   /// \brief The parser has parsed a nested-name-specifier
   4896   /// 'template[opt] template-name < template-args >::'.
   4897   ///
   4898   /// \param S The scope in which this nested-name-specifier occurs.
   4899   ///
   4900   /// \param SS The nested-name-specifier, which is both an input
   4901   /// parameter (the nested-name-specifier before this type) and an
   4902   /// output parameter (containing the full nested-name-specifier,
   4903   /// including this new type).
   4904   ///
   4905   /// \param TemplateKWLoc the location of the 'template' keyword, if any.
   4906   /// \param TemplateName the template name.
   4907   /// \param TemplateNameLoc The location of the template name.
   4908   /// \param LAngleLoc The location of the opening angle bracket  ('<').
   4909   /// \param TemplateArgs The template arguments.
   4910   /// \param RAngleLoc The location of the closing angle bracket  ('>').
   4911   /// \param CCLoc The location of the '::'.
   4912   ///
   4913   /// \param EnteringContext Whether we're entering the context of the
   4914   /// nested-name-specifier.
   4915   ///
   4916   ///
   4917   /// \returns true if an error occurred, false otherwise.
   4918   bool ActOnCXXNestedNameSpecifier(Scope *S,
   4919                                    CXXScopeSpec &SS,
   4920                                    SourceLocation TemplateKWLoc,
   4921                                    TemplateTy TemplateName,
   4922                                    SourceLocation TemplateNameLoc,
   4923                                    SourceLocation LAngleLoc,
   4924                                    ASTTemplateArgsPtr TemplateArgs,
   4925                                    SourceLocation RAngleLoc,
   4926                                    SourceLocation CCLoc,
   4927                                    bool EnteringContext);
   4928 
   4929   /// \brief Given a C++ nested-name-specifier, produce an annotation value
   4930   /// that the parser can use later to reconstruct the given
   4931   /// nested-name-specifier.
   4932   ///
   4933   /// \param SS A nested-name-specifier.
   4934   ///
   4935   /// \returns A pointer containing all of the information in the
   4936   /// nested-name-specifier \p SS.
   4937   void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS);
   4938 
   4939   /// \brief Given an annotation pointer for a nested-name-specifier, restore
   4940   /// the nested-name-specifier structure.
   4941   ///
   4942   /// \param Annotation The annotation pointer, produced by
   4943   /// \c SaveNestedNameSpecifierAnnotation().
   4944   ///
   4945   /// \param AnnotationRange The source range corresponding to the annotation.
   4946   ///
   4947   /// \param SS The nested-name-specifier that will be updated with the contents
   4948   /// of the annotation pointer.
   4949   void RestoreNestedNameSpecifierAnnotation(void *Annotation,
   4950                                             SourceRange AnnotationRange,
   4951                                             CXXScopeSpec &SS);
   4952 
   4953   bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
   4954 
   4955   /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
   4956   /// scope or nested-name-specifier) is parsed, part of a declarator-id.
   4957   /// After this method is called, according to [C++ 3.4.3p3], names should be
   4958   /// looked up in the declarator-id's scope, until the declarator is parsed and
   4959   /// ActOnCXXExitDeclaratorScope is called.
   4960   /// The 'SS' should be a non-empty valid CXXScopeSpec.
   4961   bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS);
   4962 
   4963   /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
   4964   /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
   4965   /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
   4966   /// Used to indicate that names should revert to being looked up in the
   4967   /// defining scope.
   4968   void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
   4969 
   4970   /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an
   4971   /// initializer for the declaration 'Dcl'.
   4972   /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a
   4973   /// static data member of class X, names should be looked up in the scope of
   4974   /// class X.
   4975   void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl);
   4976 
   4977   /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an
   4978   /// initializer for the declaration 'Dcl'.
   4979   void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl);
   4980 
   4981   /// \brief Create a new lambda closure type.
   4982   CXXRecordDecl *createLambdaClosureType(SourceRange IntroducerRange,
   4983                                          TypeSourceInfo *Info,
   4984                                          bool KnownDependent,
   4985                                          LambdaCaptureDefault CaptureDefault);
   4986 
   4987   /// \brief Start the definition of a lambda expression.
   4988   CXXMethodDecl *startLambdaDefinition(CXXRecordDecl *Class,
   4989                                        SourceRange IntroducerRange,
   4990                                        TypeSourceInfo *MethodType,
   4991                                        SourceLocation EndLoc,
   4992                                        ArrayRef<ParmVarDecl *> Params);
   4993 
   4994   /// \brief Endow the lambda scope info with the relevant properties.
   4995   void buildLambdaScope(sema::LambdaScopeInfo *LSI,
   4996                         CXXMethodDecl *CallOperator,
   4997                         SourceRange IntroducerRange,
   4998                         LambdaCaptureDefault CaptureDefault,
   4999                         SourceLocation CaptureDefaultLoc,
   5000                         bool ExplicitParams,
   5001                         bool ExplicitResultType,
   5002                         bool Mutable);
   5003 
   5004   /// \brief Perform initialization analysis of the init-capture and perform
   5005   /// any implicit conversions such as an lvalue-to-rvalue conversion if
   5006   /// not being used to initialize a reference.
   5007   ParsedType actOnLambdaInitCaptureInitialization(
   5008       SourceLocation Loc, bool ByRef, IdentifierInfo *Id,
   5009       LambdaCaptureInitKind InitKind, Expr *&Init) {
   5010     return ParsedType::make(buildLambdaInitCaptureInitialization(
   5011         Loc, ByRef, Id, InitKind != LambdaCaptureInitKind::CopyInit, Init));
   5012   }
   5013   QualType buildLambdaInitCaptureInitialization(SourceLocation Loc, bool ByRef,
   5014                                                 IdentifierInfo *Id,
   5015                                                 bool DirectInit, Expr *&Init);
   5016 
   5017   /// \brief Create a dummy variable within the declcontext of the lambda's
   5018   ///  call operator, for name lookup purposes for a lambda init capture.
   5019   ///
   5020   ///  CodeGen handles emission of lambda captures, ignoring these dummy
   5021   ///  variables appropriately.
   5022   VarDecl *createLambdaInitCaptureVarDecl(SourceLocation Loc,
   5023                                           QualType InitCaptureType,
   5024                                           IdentifierInfo *Id,
   5025                                           unsigned InitStyle, Expr *Init);
   5026 
   5027   /// \brief Build the implicit field for an init-capture.
   5028   FieldDecl *buildInitCaptureField(sema::LambdaScopeInfo *LSI, VarDecl *Var);
   5029 
   5030   /// \brief Note that we have finished the explicit captures for the
   5031   /// given lambda.
   5032   void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI);
   5033 
   5034   /// \brief Introduce the lambda parameters into scope.
   5035   void addLambdaParameters(CXXMethodDecl *CallOperator, Scope *CurScope);
   5036 
   5037   /// \brief Deduce a block or lambda's return type based on the return
   5038   /// statements present in the body.
   5039   void deduceClosureReturnType(sema::CapturingScopeInfo &CSI);
   5040 
   5041   /// ActOnStartOfLambdaDefinition - This is called just before we start
   5042   /// parsing the body of a lambda; it analyzes the explicit captures and
   5043   /// arguments, and sets up various data-structures for the body of the
   5044   /// lambda.
   5045   void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
   5046                                     Declarator &ParamInfo, Scope *CurScope);
   5047 
   5048   /// ActOnLambdaError - If there is an error parsing a lambda, this callback
   5049   /// is invoked to pop the information about the lambda.
   5050   void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope,
   5051                         bool IsInstantiation = false);
   5052 
   5053   /// ActOnLambdaExpr - This is called when the body of a lambda expression
   5054   /// was successfully completed.
   5055   ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body,
   5056                              Scope *CurScope);
   5057 
   5058   /// \brief Complete a lambda-expression having processed and attached the
   5059   /// lambda body.
   5060   ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc,
   5061                              sema::LambdaScopeInfo *LSI);
   5062 
   5063   /// \brief Define the "body" of the conversion from a lambda object to a
   5064   /// function pointer.
   5065   ///
   5066   /// This routine doesn't actually define a sensible body; rather, it fills
   5067   /// in the initialization expression needed to copy the lambda object into
   5068   /// the block, and IR generation actually generates the real body of the
   5069   /// block pointer conversion.
   5070   void DefineImplicitLambdaToFunctionPointerConversion(
   5071          SourceLocation CurrentLoc, CXXConversionDecl *Conv);
   5072 
   5073   /// \brief Define the "body" of the conversion from a lambda object to a
   5074   /// block pointer.
   5075   ///
   5076   /// This routine doesn't actually define a sensible body; rather, it fills
   5077   /// in the initialization expression needed to copy the lambda object into
   5078   /// the block, and IR generation actually generates the real body of the
   5079   /// block pointer conversion.
   5080   void DefineImplicitLambdaToBlockPointerConversion(SourceLocation CurrentLoc,
   5081                                                     CXXConversionDecl *Conv);
   5082 
   5083   ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation,
   5084                                            SourceLocation ConvLocation,
   5085                                            CXXConversionDecl *Conv,
   5086                                            Expr *Src);
   5087 
   5088   // ParseObjCStringLiteral - Parse Objective-C string literals.
   5089   ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
   5090                                     Expr **Strings,
   5091                                     unsigned NumStrings);
   5092 
   5093   ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S);
   5094 
   5095   /// BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the
   5096   /// numeric literal expression. Type of the expression will be "NSNumber *"
   5097   /// or "id" if NSNumber is unavailable.
   5098   ExprResult BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number);
   5099   ExprResult ActOnObjCBoolLiteral(SourceLocation AtLoc, SourceLocation ValueLoc,
   5100                                   bool Value);
   5101   ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements);
   5102 
   5103   /// BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the
   5104   /// '@' prefixed parenthesized expression. The type of the expression will
   5105   /// either be "NSNumber *", "NSString *" or "NSValue *" depending on the type
   5106   /// of ValueType, which is allowed to be a built-in numeric type, "char *",
   5107   /// "const char *" or C structure with attribute 'objc_boxable'.
   5108   ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr);
   5109 
   5110   ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr,
   5111                                           Expr *IndexExpr,
   5112                                           ObjCMethodDecl *getterMethod,
   5113                                           ObjCMethodDecl *setterMethod);
   5114 
   5115   ExprResult BuildObjCDictionaryLiteral(SourceRange SR,
   5116                                         ObjCDictionaryElement *Elements,
   5117                                         unsigned NumElements);
   5118 
   5119   ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc,
   5120                                   TypeSourceInfo *EncodedTypeInfo,
   5121                                   SourceLocation RParenLoc);
   5122   ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl,
   5123                                     CXXConversionDecl *Method,
   5124                                     bool HadMultipleCandidates);
   5125 
   5126   ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
   5127                                        SourceLocation EncodeLoc,
   5128                                        SourceLocation LParenLoc,
   5129                                        ParsedType Ty,
   5130                                        SourceLocation RParenLoc);
   5131 
   5132   /// ParseObjCSelectorExpression - Build selector expression for \@selector
   5133   ExprResult ParseObjCSelectorExpression(Selector Sel,
   5134                                          SourceLocation AtLoc,
   5135                                          SourceLocation SelLoc,
   5136                                          SourceLocation LParenLoc,
   5137                                          SourceLocation RParenLoc,
   5138                                          bool WarnMultipleSelectors);
   5139 
   5140   /// ParseObjCProtocolExpression - Build protocol expression for \@protocol
   5141   ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
   5142                                          SourceLocation AtLoc,
   5143                                          SourceLocation ProtoLoc,
   5144                                          SourceLocation LParenLoc,
   5145                                          SourceLocation ProtoIdLoc,
   5146                                          SourceLocation RParenLoc);
   5147 
   5148   //===--------------------------------------------------------------------===//
   5149   // C++ Declarations
   5150   //
   5151   Decl *ActOnStartLinkageSpecification(Scope *S,
   5152                                        SourceLocation ExternLoc,
   5153                                        Expr *LangStr,
   5154                                        SourceLocation LBraceLoc);
   5155   Decl *ActOnFinishLinkageSpecification(Scope *S,
   5156                                         Decl *LinkageSpec,
   5157                                         SourceLocation RBraceLoc);
   5158 
   5159 
   5160   //===--------------------------------------------------------------------===//
   5161   // C++ Classes
   5162   //
   5163   bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
   5164                           const CXXScopeSpec *SS = nullptr);
   5165   bool isCurrentClassNameTypo(IdentifierInfo *&II, const CXXScopeSpec *SS);
   5166 
   5167   bool ActOnAccessSpecifier(AccessSpecifier Access,
   5168                             SourceLocation ASLoc,
   5169                             SourceLocation ColonLoc,
   5170                             AttributeList *Attrs = nullptr);
   5171 
   5172   NamedDecl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
   5173                                  Declarator &D,
   5174                                  MultiTemplateParamsArg TemplateParameterLists,
   5175                                  Expr *BitfieldWidth, const VirtSpecifiers &VS,
   5176                                  InClassInitStyle InitStyle);
   5177 
   5178   void ActOnStartCXXInClassMemberInitializer();
   5179   void ActOnFinishCXXInClassMemberInitializer(Decl *VarDecl,
   5180                                               SourceLocation EqualLoc,
   5181                                               Expr *Init);
   5182 
   5183   MemInitResult ActOnMemInitializer(Decl *ConstructorD,
   5184                                     Scope *S,
   5185                                     CXXScopeSpec &SS,
   5186                                     IdentifierInfo *MemberOrBase,
   5187                                     ParsedType TemplateTypeTy,
   5188                                     const DeclSpec &DS,
   5189                                     SourceLocation IdLoc,
   5190                                     SourceLocation LParenLoc,
   5191                                     ArrayRef<Expr *> Args,
   5192                                     SourceLocation RParenLoc,
   5193                                     SourceLocation EllipsisLoc);
   5194 
   5195   MemInitResult ActOnMemInitializer(Decl *ConstructorD,
   5196                                     Scope *S,
   5197                                     CXXScopeSpec &SS,
   5198                                     IdentifierInfo *MemberOrBase,
   5199                                     ParsedType TemplateTypeTy,
   5200                                     const DeclSpec &DS,
   5201                                     SourceLocation IdLoc,
   5202                                     Expr *InitList,
   5203                                     SourceLocation EllipsisLoc);
   5204 
   5205   MemInitResult BuildMemInitializer(Decl *ConstructorD,
   5206                                     Scope *S,
   5207                                     CXXScopeSpec &SS,
   5208                                     IdentifierInfo *MemberOrBase,
   5209                                     ParsedType TemplateTypeTy,
   5210                                     const DeclSpec &DS,
   5211                                     SourceLocation IdLoc,
   5212                                     Expr *Init,
   5213                                     SourceLocation EllipsisLoc);
   5214 
   5215   MemInitResult BuildMemberInitializer(ValueDecl *Member,
   5216                                        Expr *Init,
   5217                                        SourceLocation IdLoc);
   5218 
   5219   MemInitResult BuildBaseInitializer(QualType BaseType,
   5220                                      TypeSourceInfo *BaseTInfo,
   5221                                      Expr *Init,
   5222                                      CXXRecordDecl *ClassDecl,
   5223                                      SourceLocation EllipsisLoc);
   5224 
   5225   MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo,
   5226                                            Expr *Init,
   5227                                            CXXRecordDecl *ClassDecl);
   5228 
   5229   bool SetDelegatingInitializer(CXXConstructorDecl *Constructor,
   5230                                 CXXCtorInitializer *Initializer);
   5231 
   5232   bool SetCtorInitializers(CXXConstructorDecl *Constructor, bool AnyErrors,
   5233                            ArrayRef<CXXCtorInitializer *> Initializers = None);
   5234 
   5235   void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation);
   5236 
   5237 
   5238   /// MarkBaseAndMemberDestructorsReferenced - Given a record decl,
   5239   /// mark all the non-trivial destructors of its members and bases as
   5240   /// referenced.
   5241   void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
   5242                                               CXXRecordDecl *Record);
   5243 
   5244   /// \brief The list of classes whose vtables have been used within
   5245   /// this translation unit, and the source locations at which the
   5246   /// first use occurred.
   5247   typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse;
   5248 
   5249   /// \brief The list of vtables that are required but have not yet been
   5250   /// materialized.
   5251   SmallVector<VTableUse, 16> VTableUses;
   5252 
   5253   /// \brief The set of classes whose vtables have been used within
   5254   /// this translation unit, and a bit that will be true if the vtable is
   5255   /// required to be emitted (otherwise, it should be emitted only if needed
   5256   /// by code generation).
   5257   llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed;
   5258 
   5259   /// \brief Load any externally-stored vtable uses.
   5260   void LoadExternalVTableUses();
   5261 
   5262   /// \brief Note that the vtable for the given class was used at the
   5263   /// given location.
   5264   void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class,
   5265                       bool DefinitionRequired = false);
   5266 
   5267   /// \brief Mark the exception specifications of all virtual member functions
   5268   /// in the given class as needed.
   5269   void MarkVirtualMemberExceptionSpecsNeeded(SourceLocation Loc,
   5270                                              const CXXRecordDecl *RD);
   5271 
   5272   /// MarkVirtualMembersReferenced - Will mark all members of the given
   5273   /// CXXRecordDecl referenced.
   5274   void MarkVirtualMembersReferenced(SourceLocation Loc,
   5275                                     const CXXRecordDecl *RD);
   5276 
   5277   /// \brief Define all of the vtables that have been used in this
   5278   /// translation unit and reference any virtual members used by those
   5279   /// vtables.
   5280   ///
   5281   /// \returns true if any work was done, false otherwise.
   5282   bool DefineUsedVTables();
   5283 
   5284   void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
   5285 
   5286   void ActOnMemInitializers(Decl *ConstructorDecl,
   5287                             SourceLocation ColonLoc,
   5288                             ArrayRef<CXXCtorInitializer*> MemInits,
   5289                             bool AnyErrors);
   5290 
   5291   void checkClassLevelDLLAttribute(CXXRecordDecl *Class);
   5292   void propagateDLLAttrToBaseClassTemplate(
   5293       CXXRecordDecl *Class, Attr *ClassAttr,
   5294       ClassTemplateSpecializationDecl *BaseTemplateSpec,
   5295       SourceLocation BaseLoc);
   5296   void CheckCompletedCXXClass(CXXRecordDecl *Record);
   5297   void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
   5298                                          Decl *TagDecl,
   5299                                          SourceLocation LBrac,
   5300                                          SourceLocation RBrac,
   5301                                          AttributeList *AttrList);
   5302   void ActOnFinishCXXMemberDecls();
   5303   void ActOnFinishCXXNonNestedClass(Decl *D);
   5304 
   5305   void ActOnReenterCXXMethodParameter(Scope *S, ParmVarDecl *Param);
   5306   unsigned ActOnReenterTemplateScope(Scope *S, Decl *Template);
   5307   void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record);
   5308   void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
   5309   void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param);
   5310   void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record);
   5311   void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
   5312   void ActOnFinishDelayedMemberInitializers(Decl *Record);
   5313   void MarkAsLateParsedTemplate(FunctionDecl *FD, Decl *FnD,
   5314                                 CachedTokens &Toks);
   5315   void UnmarkAsLateParsedTemplate(FunctionDecl *FD);
   5316   bool IsInsideALocalClassWithinATemplateFunction();
   5317 
   5318   Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc,
   5319                                      Expr *AssertExpr,
   5320                                      Expr *AssertMessageExpr,
   5321                                      SourceLocation RParenLoc);
   5322   Decl *BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc,
   5323                                      Expr *AssertExpr,
   5324                                      StringLiteral *AssertMessageExpr,
   5325                                      SourceLocation RParenLoc,
   5326                                      bool Failed);
   5327 
   5328   FriendDecl *CheckFriendTypeDecl(SourceLocation LocStart,
   5329                                   SourceLocation FriendLoc,
   5330                                   TypeSourceInfo *TSInfo);
   5331   Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS,
   5332                             MultiTemplateParamsArg TemplateParams);
   5333   NamedDecl *ActOnFriendFunctionDecl(Scope *S, Declarator &D,
   5334                                      MultiTemplateParamsArg TemplateParams);
   5335 
   5336   QualType CheckConstructorDeclarator(Declarator &D, QualType R,
   5337                                       StorageClass& SC);
   5338   void CheckConstructor(CXXConstructorDecl *Constructor);
   5339   QualType CheckDestructorDeclarator(Declarator &D, QualType R,
   5340                                      StorageClass& SC);
   5341   bool CheckDestructor(CXXDestructorDecl *Destructor);
   5342   void CheckConversionDeclarator(Declarator &D, QualType &R,
   5343                                  StorageClass& SC);
   5344   Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
   5345 
   5346   void CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD);
   5347   void CheckExplicitlyDefaultedMemberExceptionSpec(CXXMethodDecl *MD,
   5348                                                    const FunctionProtoType *T);
   5349   void CheckDelayedMemberExceptionSpecs();
   5350 
   5351   //===--------------------------------------------------------------------===//
   5352   // C++ Derived Classes
   5353   //
   5354 
   5355   /// ActOnBaseSpecifier - Parsed a base specifier
   5356   CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
   5357                                        SourceRange SpecifierRange,
   5358                                        bool Virtual, AccessSpecifier Access,
   5359                                        TypeSourceInfo *TInfo,
   5360                                        SourceLocation EllipsisLoc);
   5361 
   5362   BaseResult ActOnBaseSpecifier(Decl *classdecl,
   5363                                 SourceRange SpecifierRange,
   5364                                 ParsedAttributes &Attrs,
   5365                                 bool Virtual, AccessSpecifier Access,
   5366                                 ParsedType basetype,
   5367                                 SourceLocation BaseLoc,
   5368                                 SourceLocation EllipsisLoc);
   5369 
   5370   bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
   5371                             unsigned NumBases);
   5372   void ActOnBaseSpecifiers(Decl *ClassDecl, CXXBaseSpecifier **Bases,
   5373                            unsigned NumBases);
   5374 
   5375   bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base);
   5376   bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base,
   5377                      CXXBasePaths &Paths);
   5378 
   5379   // FIXME: I don't like this name.
   5380   void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath);
   5381 
   5382   bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
   5383                                     SourceLocation Loc, SourceRange Range,
   5384                                     CXXCastPath *BasePath = nullptr,
   5385                                     bool IgnoreAccess = false);
   5386   bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
   5387                                     unsigned InaccessibleBaseID,
   5388                                     unsigned AmbigiousBaseConvID,
   5389                                     SourceLocation Loc, SourceRange Range,
   5390                                     DeclarationName Name,
   5391                                     CXXCastPath *BasePath);
   5392 
   5393   std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths);
   5394 
   5395   bool CheckOverridingFunctionAttributes(const CXXMethodDecl *New,
   5396                                          const CXXMethodDecl *Old);
   5397 
   5398   /// CheckOverridingFunctionReturnType - Checks whether the return types are
   5399   /// covariant, according to C++ [class.virtual]p5.
   5400   bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New,
   5401                                          const CXXMethodDecl *Old);
   5402 
   5403   /// CheckOverridingFunctionExceptionSpec - Checks whether the exception
   5404   /// spec is a subset of base spec.
   5405   bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New,
   5406                                             const CXXMethodDecl *Old);
   5407 
   5408   bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange);
   5409 
   5410   /// CheckOverrideControl - Check C++11 override control semantics.
   5411   void CheckOverrideControl(NamedDecl *D);
   5412 
   5413   /// DiagnoseAbsenceOfOverrideControl - Diagnose if 'override' keyword was
   5414   /// not used in the declaration of an overriding method.
   5415   void DiagnoseAbsenceOfOverrideControl(NamedDecl *D);
   5416 
   5417   /// CheckForFunctionMarkedFinal - Checks whether a virtual member function
   5418   /// overrides a virtual member function marked 'final', according to
   5419   /// C++11 [class.virtual]p4.
   5420   bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New,
   5421                                               const CXXMethodDecl *Old);
   5422 
   5423 
   5424   //===--------------------------------------------------------------------===//
   5425   // C++ Access Control
   5426   //
   5427 
   5428   enum AccessResult {
   5429     AR_accessible,
   5430     AR_inaccessible,
   5431     AR_dependent,
   5432     AR_delayed
   5433   };
   5434 
   5435   bool SetMemberAccessSpecifier(NamedDecl *MemberDecl,
   5436                                 NamedDecl *PrevMemberDecl,
   5437                                 AccessSpecifier LexicalAS);
   5438 
   5439   AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E,
   5440                                            DeclAccessPair FoundDecl);
   5441   AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E,
   5442                                            DeclAccessPair FoundDecl);
   5443   AccessResult CheckAllocationAccess(SourceLocation OperatorLoc,
   5444                                      SourceRange PlacementRange,
   5445                                      CXXRecordDecl *NamingClass,
   5446                                      DeclAccessPair FoundDecl,
   5447                                      bool Diagnose = true);
   5448   AccessResult CheckConstructorAccess(SourceLocation Loc,
   5449                                       CXXConstructorDecl *D,
   5450                                       const InitializedEntity &Entity,
   5451                                       AccessSpecifier Access,
   5452                                       bool IsCopyBindingRefToTemp = false);
   5453   AccessResult CheckConstructorAccess(SourceLocation Loc,
   5454                                       CXXConstructorDecl *D,
   5455                                       const InitializedEntity &Entity,
   5456                                       AccessSpecifier Access,
   5457                                       const PartialDiagnostic &PDiag);
   5458   AccessResult CheckDestructorAccess(SourceLocation Loc,
   5459                                      CXXDestructorDecl *Dtor,
   5460                                      const PartialDiagnostic &PDiag,
   5461                                      QualType objectType = QualType());
   5462   AccessResult CheckFriendAccess(NamedDecl *D);
   5463   AccessResult CheckMemberAccess(SourceLocation UseLoc,
   5464                                  CXXRecordDecl *NamingClass,
   5465                                  DeclAccessPair Found);
   5466   AccessResult CheckMemberOperatorAccess(SourceLocation Loc,
   5467                                          Expr *ObjectExpr,
   5468                                          Expr *ArgExpr,
   5469                                          DeclAccessPair FoundDecl);
   5470   AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr,
   5471                                           DeclAccessPair FoundDecl);
   5472   AccessResult CheckBaseClassAccess(SourceLocation AccessLoc,
   5473                                     QualType Base, QualType Derived,
   5474                                     const CXXBasePath &Path,
   5475                                     unsigned DiagID,
   5476                                     bool ForceCheck = false,
   5477                                     bool ForceUnprivileged = false);
   5478   void CheckLookupAccess(const LookupResult &R);
   5479   bool IsSimplyAccessible(NamedDecl *decl, DeclContext *Ctx);
   5480   bool isSpecialMemberAccessibleForDeletion(CXXMethodDecl *decl,
   5481                                             AccessSpecifier access,
   5482                                             QualType objectType);
   5483 
   5484   void HandleDependentAccessCheck(const DependentDiagnostic &DD,
   5485                          const MultiLevelTemplateArgumentList &TemplateArgs);
   5486   void PerformDependentDiagnostics(const DeclContext *Pattern,
   5487                         const MultiLevelTemplateArgumentList &TemplateArgs);
   5488 
   5489   void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
   5490 
   5491   /// \brief When true, access checking violations are treated as SFINAE
   5492   /// failures rather than hard errors.
   5493   bool AccessCheckingSFINAE;
   5494 
   5495   enum AbstractDiagSelID {
   5496     AbstractNone = -1,
   5497     AbstractReturnType,
   5498     AbstractParamType,
   5499     AbstractVariableType,
   5500     AbstractFieldType,
   5501     AbstractIvarType,
   5502     AbstractSynthesizedIvarType,
   5503     AbstractArrayType
   5504   };
   5505 
   5506   bool isAbstractType(SourceLocation Loc, QualType T);
   5507   bool RequireNonAbstractType(SourceLocation Loc, QualType T,
   5508                               TypeDiagnoser &Diagnoser);
   5509   template <typename... Ts>
   5510   bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID,
   5511                               const Ts &...Args) {
   5512     BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...);
   5513     return RequireNonAbstractType(Loc, T, Diagnoser);
   5514   }
   5515 
   5516   void DiagnoseAbstractType(const CXXRecordDecl *RD);
   5517 
   5518   //===--------------------------------------------------------------------===//
   5519   // C++ Overloaded Operators [C++ 13.5]
   5520   //
   5521 
   5522   bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
   5523 
   5524   bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl);
   5525 
   5526   //===--------------------------------------------------------------------===//
   5527   // C++ Templates [C++ 14]
   5528   //
   5529   void FilterAcceptableTemplateNames(LookupResult &R,
   5530                                      bool AllowFunctionTemplates = true);
   5531   bool hasAnyAcceptableTemplateNames(LookupResult &R,
   5532                                      bool AllowFunctionTemplates = true);
   5533 
   5534   void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS,
   5535                           QualType ObjectType, bool EnteringContext,
   5536                           bool &MemberOfUnknownSpecialization);
   5537 
   5538   TemplateNameKind isTemplateName(Scope *S,
   5539                                   CXXScopeSpec &SS,
   5540                                   bool hasTemplateKeyword,
   5541                                   UnqualifiedId &Name,
   5542                                   ParsedType ObjectType,
   5543                                   bool EnteringContext,
   5544                                   TemplateTy &Template,
   5545                                   bool &MemberOfUnknownSpecialization);
   5546 
   5547   bool DiagnoseUnknownTemplateName(const IdentifierInfo &II,
   5548                                    SourceLocation IILoc,
   5549                                    Scope *S,
   5550                                    const CXXScopeSpec *SS,
   5551                                    TemplateTy &SuggestedTemplate,
   5552                                    TemplateNameKind &SuggestedKind);
   5553 
   5554   void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
   5555   TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl);
   5556 
   5557   Decl *ActOnTypeParameter(Scope *S, bool Typename,
   5558                            SourceLocation EllipsisLoc,
   5559                            SourceLocation KeyLoc,
   5560                            IdentifierInfo *ParamName,
   5561                            SourceLocation ParamNameLoc,
   5562                            unsigned Depth, unsigned Position,
   5563                            SourceLocation EqualLoc,
   5564                            ParsedType DefaultArg);
   5565 
   5566   QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
   5567   Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
   5568                                       unsigned Depth,
   5569                                       unsigned Position,
   5570                                       SourceLocation EqualLoc,
   5571                                       Expr *DefaultArg);
   5572   Decl *ActOnTemplateTemplateParameter(Scope *S,
   5573                                        SourceLocation TmpLoc,
   5574                                        TemplateParameterList *Params,
   5575                                        SourceLocation EllipsisLoc,
   5576                                        IdentifierInfo *ParamName,
   5577                                        SourceLocation ParamNameLoc,
   5578                                        unsigned Depth,
   5579                                        unsigned Position,
   5580                                        SourceLocation EqualLoc,
   5581                                        ParsedTemplateArgument DefaultArg);
   5582 
   5583   TemplateParameterList *
   5584   ActOnTemplateParameterList(unsigned Depth,
   5585                              SourceLocation ExportLoc,
   5586                              SourceLocation TemplateLoc,
   5587                              SourceLocation LAngleLoc,
   5588                              Decl **Params, unsigned NumParams,
   5589                              SourceLocation RAngleLoc);
   5590 
   5591   /// \brief The context in which we are checking a template parameter list.
   5592   enum TemplateParamListContext {
   5593     TPC_ClassTemplate,
   5594     TPC_VarTemplate,
   5595     TPC_FunctionTemplate,
   5596     TPC_ClassTemplateMember,
   5597     TPC_FriendClassTemplate,
   5598     TPC_FriendFunctionTemplate,
   5599     TPC_FriendFunctionTemplateDefinition,
   5600     TPC_TypeAliasTemplate
   5601   };
   5602 
   5603   bool CheckTemplateParameterList(TemplateParameterList *NewParams,
   5604                                   TemplateParameterList *OldParams,
   5605                                   TemplateParamListContext TPC);
   5606   TemplateParameterList *MatchTemplateParametersToScopeSpecifier(
   5607       SourceLocation DeclStartLoc, SourceLocation DeclLoc,
   5608       const CXXScopeSpec &SS, TemplateIdAnnotation *TemplateId,
   5609       ArrayRef<TemplateParameterList *> ParamLists,
   5610       bool IsFriend, bool &IsExplicitSpecialization, bool &Invalid);
   5611 
   5612   DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
   5613                                 SourceLocation KWLoc, CXXScopeSpec &SS,
   5614                                 IdentifierInfo *Name, SourceLocation NameLoc,
   5615                                 AttributeList *Attr,
   5616                                 TemplateParameterList *TemplateParams,
   5617                                 AccessSpecifier AS,
   5618                                 SourceLocation ModulePrivateLoc,
   5619                                 SourceLocation FriendLoc,
   5620                                 unsigned NumOuterTemplateParamLists,
   5621                             TemplateParameterList **OuterTemplateParamLists,
   5622                                 SkipBodyInfo *SkipBody = nullptr);
   5623 
   5624   void translateTemplateArguments(const ASTTemplateArgsPtr &In,
   5625                                   TemplateArgumentListInfo &Out);
   5626 
   5627   void NoteAllFoundTemplates(TemplateName Name);
   5628 
   5629   QualType CheckTemplateIdType(TemplateName Template,
   5630                                SourceLocation TemplateLoc,
   5631                               TemplateArgumentListInfo &TemplateArgs);
   5632 
   5633   TypeResult
   5634   ActOnTemplateIdType(CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
   5635                       TemplateTy Template, SourceLocation TemplateLoc,
   5636                       SourceLocation LAngleLoc,
   5637                       ASTTemplateArgsPtr TemplateArgs,
   5638                       SourceLocation RAngleLoc,
   5639                       bool IsCtorOrDtorName = false);
   5640 
   5641   /// \brief Parsed an elaborated-type-specifier that refers to a template-id,
   5642   /// such as \c class T::template apply<U>.
   5643   TypeResult ActOnTagTemplateIdType(TagUseKind TUK,
   5644                                     TypeSpecifierType TagSpec,
   5645                                     SourceLocation TagLoc,
   5646                                     CXXScopeSpec &SS,
   5647                                     SourceLocation TemplateKWLoc,
   5648                                     TemplateTy TemplateD,
   5649                                     SourceLocation TemplateLoc,
   5650                                     SourceLocation LAngleLoc,
   5651                                     ASTTemplateArgsPtr TemplateArgsIn,
   5652                                     SourceLocation RAngleLoc);
   5653 
   5654   DeclResult ActOnVarTemplateSpecialization(
   5655       Scope *S, Declarator &D, TypeSourceInfo *DI,
   5656       SourceLocation TemplateKWLoc, TemplateParameterList *TemplateParams,
   5657       StorageClass SC, bool IsPartialSpecialization);
   5658 
   5659   DeclResult CheckVarTemplateId(VarTemplateDecl *Template,
   5660                                 SourceLocation TemplateLoc,
   5661                                 SourceLocation TemplateNameLoc,
   5662                                 const TemplateArgumentListInfo &TemplateArgs);
   5663 
   5664   ExprResult CheckVarTemplateId(const CXXScopeSpec &SS,
   5665                                 const DeclarationNameInfo &NameInfo,
   5666                                 VarTemplateDecl *Template,
   5667                                 SourceLocation TemplateLoc,
   5668                                 const TemplateArgumentListInfo *TemplateArgs);
   5669 
   5670   ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS,
   5671                                  SourceLocation TemplateKWLoc,
   5672                                  LookupResult &R,
   5673                                  bool RequiresADL,
   5674                                const TemplateArgumentListInfo *TemplateArgs);
   5675 
   5676   ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS,
   5677                                           SourceLocation TemplateKWLoc,
   5678                                const DeclarationNameInfo &NameInfo,
   5679                                const TemplateArgumentListInfo *TemplateArgs);
   5680 
   5681   TemplateNameKind ActOnDependentTemplateName(Scope *S,
   5682                                               CXXScopeSpec &SS,
   5683                                               SourceLocation TemplateKWLoc,
   5684                                               UnqualifiedId &Name,
   5685                                               ParsedType ObjectType,
   5686                                               bool EnteringContext,
   5687                                               TemplateTy &Template);
   5688 
   5689   DeclResult
   5690   ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK,
   5691                                    SourceLocation KWLoc,
   5692                                    SourceLocation ModulePrivateLoc,
   5693                                    TemplateIdAnnotation &TemplateId,
   5694                                    AttributeList *Attr,
   5695                                  MultiTemplateParamsArg TemplateParameterLists,
   5696                                    SkipBodyInfo *SkipBody = nullptr);
   5697 
   5698   Decl *ActOnTemplateDeclarator(Scope *S,
   5699                                 MultiTemplateParamsArg TemplateParameterLists,
   5700                                 Declarator &D);
   5701 
   5702   bool
   5703   CheckSpecializationInstantiationRedecl(SourceLocation NewLoc,
   5704                                          TemplateSpecializationKind NewTSK,
   5705                                          NamedDecl *PrevDecl,
   5706                                          TemplateSpecializationKind PrevTSK,
   5707                                          SourceLocation PrevPtOfInstantiation,
   5708                                          bool &SuppressNew);
   5709 
   5710   bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD,
   5711                     const TemplateArgumentListInfo &ExplicitTemplateArgs,
   5712                                                     LookupResult &Previous);
   5713 
   5714   bool CheckFunctionTemplateSpecialization(FunctionDecl *FD,
   5715                          TemplateArgumentListInfo *ExplicitTemplateArgs,
   5716                                            LookupResult &Previous);
   5717   bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous);
   5718 
   5719   DeclResult
   5720   ActOnExplicitInstantiation(Scope *S,
   5721                              SourceLocation ExternLoc,
   5722                              SourceLocation TemplateLoc,
   5723                              unsigned TagSpec,
   5724                              SourceLocation KWLoc,
   5725                              const CXXScopeSpec &SS,
   5726                              TemplateTy Template,
   5727                              SourceLocation TemplateNameLoc,
   5728                              SourceLocation LAngleLoc,
   5729                              ASTTemplateArgsPtr TemplateArgs,
   5730                              SourceLocation RAngleLoc,
   5731                              AttributeList *Attr);
   5732 
   5733   DeclResult
   5734   ActOnExplicitInstantiation(Scope *S,
   5735                              SourceLocation ExternLoc,
   5736                              SourceLocation TemplateLoc,
   5737                              unsigned TagSpec,
   5738                              SourceLocation KWLoc,
   5739                              CXXScopeSpec &SS,
   5740                              IdentifierInfo *Name,
   5741                              SourceLocation NameLoc,
   5742                              AttributeList *Attr);
   5743 
   5744   DeclResult ActOnExplicitInstantiation(Scope *S,
   5745                                         SourceLocation ExternLoc,
   5746                                         SourceLocation TemplateLoc,
   5747                                         Declarator &D);
   5748 
   5749   TemplateArgumentLoc
   5750   SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template,
   5751                                           SourceLocation TemplateLoc,
   5752                                           SourceLocation RAngleLoc,
   5753                                           Decl *Param,
   5754                                           SmallVectorImpl<TemplateArgument>
   5755                                             &Converted,
   5756                                           bool &HasDefaultArg);
   5757 
   5758   /// \brief Specifies the context in which a particular template
   5759   /// argument is being checked.
   5760   enum CheckTemplateArgumentKind {
   5761     /// \brief The template argument was specified in the code or was
   5762     /// instantiated with some deduced template arguments.
   5763     CTAK_Specified,
   5764 
   5765     /// \brief The template argument was deduced via template argument
   5766     /// deduction.
   5767     CTAK_Deduced,
   5768 
   5769     /// \brief The template argument was deduced from an array bound
   5770     /// via template argument deduction.
   5771     CTAK_DeducedFromArrayBound
   5772   };
   5773 
   5774   bool CheckTemplateArgument(NamedDecl *Param,
   5775                              TemplateArgumentLoc &Arg,
   5776                              NamedDecl *Template,
   5777                              SourceLocation TemplateLoc,
   5778                              SourceLocation RAngleLoc,
   5779                              unsigned ArgumentPackIndex,
   5780                            SmallVectorImpl<TemplateArgument> &Converted,
   5781                              CheckTemplateArgumentKind CTAK = CTAK_Specified);
   5782 
   5783   /// \brief Check that the given template arguments can be be provided to
   5784   /// the given template, converting the arguments along the way.
   5785   ///
   5786   /// \param Template The template to which the template arguments are being
   5787   /// provided.
   5788   ///
   5789   /// \param TemplateLoc The location of the template name in the source.
   5790   ///
   5791   /// \param TemplateArgs The list of template arguments. If the template is
   5792   /// a template template parameter, this function may extend the set of
   5793   /// template arguments to also include substituted, defaulted template
   5794   /// arguments.
   5795   ///
   5796   /// \param PartialTemplateArgs True if the list of template arguments is
   5797   /// intentionally partial, e.g., because we're checking just the initial
   5798   /// set of template arguments.
   5799   ///
   5800   /// \param Converted Will receive the converted, canonicalized template
   5801   /// arguments.
   5802   ///
   5803   /// \returns true if an error occurred, false otherwise.
   5804   bool CheckTemplateArgumentList(TemplateDecl *Template,
   5805                                  SourceLocation TemplateLoc,
   5806                                  TemplateArgumentListInfo &TemplateArgs,
   5807                                  bool PartialTemplateArgs,
   5808                            SmallVectorImpl<TemplateArgument> &Converted);
   5809 
   5810   bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
   5811                                  TemplateArgumentLoc &Arg,
   5812                            SmallVectorImpl<TemplateArgument> &Converted);
   5813 
   5814   bool CheckTemplateArgument(TemplateTypeParmDecl *Param,
   5815                              TypeSourceInfo *Arg);
   5816   ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
   5817                                    QualType InstantiatedParamType, Expr *Arg,
   5818                                    TemplateArgument &Converted,
   5819                                CheckTemplateArgumentKind CTAK = CTAK_Specified);
   5820   bool CheckTemplateArgument(TemplateTemplateParmDecl *Param,
   5821                              TemplateArgumentLoc &Arg,
   5822                              unsigned ArgumentPackIndex);
   5823 
   5824   ExprResult
   5825   BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg,
   5826                                           QualType ParamType,
   5827                                           SourceLocation Loc);
   5828   ExprResult
   5829   BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
   5830                                               SourceLocation Loc);
   5831 
   5832   /// \brief Enumeration describing how template parameter lists are compared
   5833   /// for equality.
   5834   enum TemplateParameterListEqualKind {
   5835     /// \brief We are matching the template parameter lists of two templates
   5836     /// that might be redeclarations.
   5837     ///
   5838     /// \code
   5839     /// template<typename T> struct X;
   5840     /// template<typename T> struct X;
   5841     /// \endcode
   5842     TPL_TemplateMatch,
   5843 
   5844     /// \brief We are matching the template parameter lists of two template
   5845     /// template parameters as part of matching the template parameter lists
   5846     /// of two templates that might be redeclarations.
   5847     ///
   5848     /// \code
   5849     /// template<template<int I> class TT> struct X;
   5850     /// template<template<int Value> class Other> struct X;
   5851     /// \endcode
   5852     TPL_TemplateTemplateParmMatch,
   5853 
   5854     /// \brief We are matching the template parameter lists of a template
   5855     /// template argument against the template parameter lists of a template
   5856     /// template parameter.
   5857     ///
   5858     /// \code
   5859     /// template<template<int Value> class Metafun> struct X;
   5860     /// template<int Value> struct integer_c;
   5861     /// X<integer_c> xic;
   5862     /// \endcode
   5863     TPL_TemplateTemplateArgumentMatch
   5864   };
   5865 
   5866   bool TemplateParameterListsAreEqual(TemplateParameterList *New,
   5867                                       TemplateParameterList *Old,
   5868                                       bool Complain,
   5869                                       TemplateParameterListEqualKind Kind,
   5870                                       SourceLocation TemplateArgLoc
   5871                                         = SourceLocation());
   5872 
   5873   bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams);
   5874 
   5875   /// \brief Called when the parser has parsed a C++ typename
   5876   /// specifier, e.g., "typename T::type".
   5877   ///
   5878   /// \param S The scope in which this typename type occurs.
   5879   /// \param TypenameLoc the location of the 'typename' keyword
   5880   /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
   5881   /// \param II the identifier we're retrieving (e.g., 'type' in the example).
   5882   /// \param IdLoc the location of the identifier.
   5883   TypeResult
   5884   ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
   5885                     const CXXScopeSpec &SS, const IdentifierInfo &II,
   5886                     SourceLocation IdLoc);
   5887 
   5888   /// \brief Called when the parser has parsed a C++ typename
   5889   /// specifier that ends in a template-id, e.g.,
   5890   /// "typename MetaFun::template apply<T1, T2>".
   5891   ///
   5892   /// \param S The scope in which this typename type occurs.
   5893   /// \param TypenameLoc the location of the 'typename' keyword
   5894   /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
   5895   /// \param TemplateLoc the location of the 'template' keyword, if any.
   5896   /// \param TemplateName The template name.
   5897   /// \param TemplateNameLoc The location of the template name.
   5898   /// \param LAngleLoc The location of the opening angle bracket  ('<').
   5899   /// \param TemplateArgs The template arguments.
   5900   /// \param RAngleLoc The location of the closing angle bracket  ('>').
   5901   TypeResult
   5902   ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
   5903                     const CXXScopeSpec &SS,
   5904                     SourceLocation TemplateLoc,
   5905                     TemplateTy TemplateName,
   5906                     SourceLocation TemplateNameLoc,
   5907                     SourceLocation LAngleLoc,
   5908                     ASTTemplateArgsPtr TemplateArgs,
   5909                     SourceLocation RAngleLoc);
   5910 
   5911   QualType CheckTypenameType(ElaboratedTypeKeyword Keyword,
   5912                              SourceLocation KeywordLoc,
   5913                              NestedNameSpecifierLoc QualifierLoc,
   5914                              const IdentifierInfo &II,
   5915                              SourceLocation IILoc);
   5916 
   5917   TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
   5918                                                     SourceLocation Loc,
   5919                                                     DeclarationName Name);
   5920   bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS);
   5921 
   5922   ExprResult RebuildExprInCurrentInstantiation(Expr *E);
   5923   bool RebuildTemplateParamsInCurrentInstantiation(
   5924                                                 TemplateParameterList *Params);
   5925 
   5926   std::string
   5927   getTemplateArgumentBindingsText(const TemplateParameterList *Params,
   5928                                   const TemplateArgumentList &Args);
   5929 
   5930   std::string
   5931   getTemplateArgumentBindingsText(const TemplateParameterList *Params,
   5932                                   const TemplateArgument *Args,
   5933                                   unsigned NumArgs);
   5934 
   5935   //===--------------------------------------------------------------------===//
   5936   // C++ Variadic Templates (C++0x [temp.variadic])
   5937   //===--------------------------------------------------------------------===//
   5938 
   5939   /// Determine whether an unexpanded parameter pack might be permitted in this
   5940   /// location. Useful for error recovery.
   5941   bool isUnexpandedParameterPackPermitted();
   5942 
   5943   /// \brief The context in which an unexpanded parameter pack is
   5944   /// being diagnosed.
   5945   ///
   5946   /// Note that the values of this enumeration line up with the first
   5947   /// argument to the \c err_unexpanded_parameter_pack diagnostic.
   5948   enum UnexpandedParameterPackContext {
   5949     /// \brief An arbitrary expression.
   5950     UPPC_Expression = 0,
   5951 
   5952     /// \brief The base type of a class type.
   5953     UPPC_BaseType,
   5954 
   5955     /// \brief The type of an arbitrary declaration.
   5956     UPPC_DeclarationType,
   5957 
   5958     /// \brief The type of a data member.
   5959     UPPC_DataMemberType,
   5960 
   5961     /// \brief The size of a bit-field.
   5962     UPPC_BitFieldWidth,
   5963 
   5964     /// \brief The expression in a static assertion.
   5965     UPPC_StaticAssertExpression,
   5966 
   5967     /// \brief The fixed underlying type of an enumeration.
   5968     UPPC_FixedUnderlyingType,
   5969 
   5970     /// \brief The enumerator value.
   5971     UPPC_EnumeratorValue,
   5972 
   5973     /// \brief A using declaration.
   5974     UPPC_UsingDeclaration,
   5975 
   5976     /// \brief A friend declaration.
   5977     UPPC_FriendDeclaration,
   5978 
   5979     /// \brief A declaration qualifier.
   5980     UPPC_DeclarationQualifier,
   5981 
   5982     /// \brief An initializer.
   5983     UPPC_Initializer,
   5984 
   5985     /// \brief A default argument.
   5986     UPPC_DefaultArgument,
   5987 
   5988     /// \brief The type of a non-type template parameter.
   5989     UPPC_NonTypeTemplateParameterType,
   5990 
   5991     /// \brief The type of an exception.
   5992     UPPC_ExceptionType,
   5993 
   5994     /// \brief Partial specialization.
   5995     UPPC_PartialSpecialization,
   5996 
   5997     /// \brief Microsoft __if_exists.
   5998     UPPC_IfExists,
   5999 
   6000     /// \brief Microsoft __if_not_exists.
   6001     UPPC_IfNotExists,
   6002 
   6003     /// \brief Lambda expression.
   6004     UPPC_Lambda,
   6005 
   6006     /// \brief Block expression,
   6007     UPPC_Block
   6008   };
   6009 
   6010   /// \brief Diagnose unexpanded parameter packs.
   6011   ///
   6012   /// \param Loc The location at which we should emit the diagnostic.
   6013   ///
   6014   /// \param UPPC The context in which we are diagnosing unexpanded
   6015   /// parameter packs.
   6016   ///
   6017   /// \param Unexpanded the set of unexpanded parameter packs.
   6018   ///
   6019   /// \returns true if an error occurred, false otherwise.
   6020   bool DiagnoseUnexpandedParameterPacks(SourceLocation Loc,
   6021                                         UnexpandedParameterPackContext UPPC,
   6022                                   ArrayRef<UnexpandedParameterPack> Unexpanded);
   6023 
   6024   /// \brief If the given type contains an unexpanded parameter pack,
   6025   /// diagnose the error.
   6026   ///
   6027   /// \param Loc The source location where a diagnostc should be emitted.
   6028   ///
   6029   /// \param T The type that is being checked for unexpanded parameter
   6030   /// packs.
   6031   ///
   6032   /// \returns true if an error occurred, false otherwise.
   6033   bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T,
   6034                                        UnexpandedParameterPackContext UPPC);
   6035 
   6036   /// \brief If the given expression contains an unexpanded parameter
   6037   /// pack, diagnose the error.
   6038   ///
   6039   /// \param E The expression that is being checked for unexpanded
   6040   /// parameter packs.
   6041   ///
   6042   /// \returns true if an error occurred, false otherwise.
   6043   bool DiagnoseUnexpandedParameterPack(Expr *E,
   6044                        UnexpandedParameterPackContext UPPC = UPPC_Expression);
   6045 
   6046   /// \brief If the given nested-name-specifier contains an unexpanded
   6047   /// parameter pack, diagnose the error.
   6048   ///
   6049   /// \param SS The nested-name-specifier that is being checked for
   6050   /// unexpanded parameter packs.
   6051   ///
   6052   /// \returns true if an error occurred, false otherwise.
   6053   bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS,
   6054                                        UnexpandedParameterPackContext UPPC);
   6055 
   6056   /// \brief If the given name contains an unexpanded parameter pack,
   6057   /// diagnose the error.
   6058   ///
   6059   /// \param NameInfo The name (with source location information) that
   6060   /// is being checked for unexpanded parameter packs.
   6061   ///
   6062   /// \returns true if an error occurred, false otherwise.
   6063   bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo,
   6064                                        UnexpandedParameterPackContext UPPC);
   6065 
   6066   /// \brief If the given template name contains an unexpanded parameter pack,
   6067   /// diagnose the error.
   6068   ///
   6069   /// \param Loc The location of the template name.
   6070   ///
   6071   /// \param Template The template name that is being checked for unexpanded
   6072   /// parameter packs.
   6073   ///
   6074   /// \returns true if an error occurred, false otherwise.
   6075   bool DiagnoseUnexpandedParameterPack(SourceLocation Loc,
   6076                                        TemplateName Template,
   6077                                        UnexpandedParameterPackContext UPPC);
   6078 
   6079   /// \brief If the given template argument contains an unexpanded parameter
   6080   /// pack, diagnose the error.
   6081   ///
   6082   /// \param Arg The template argument that is being checked for unexpanded
   6083   /// parameter packs.
   6084   ///
   6085   /// \returns true if an error occurred, false otherwise.
   6086   bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg,
   6087                                        UnexpandedParameterPackContext UPPC);
   6088 
   6089   /// \brief Collect the set of unexpanded parameter packs within the given
   6090   /// template argument.
   6091   ///
   6092   /// \param Arg The template argument that will be traversed to find
   6093   /// unexpanded parameter packs.
   6094   void collectUnexpandedParameterPacks(TemplateArgument Arg,
   6095                    SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
   6096 
   6097   /// \brief Collect the set of unexpanded parameter packs within the given
   6098   /// template argument.
   6099   ///
   6100   /// \param Arg The template argument that will be traversed to find
   6101   /// unexpanded parameter packs.
   6102   void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg,
   6103                     SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
   6104 
   6105   /// \brief Collect the set of unexpanded parameter packs within the given
   6106   /// type.
   6107   ///
   6108   /// \param T The type that will be traversed to find
   6109   /// unexpanded parameter packs.
   6110   void collectUnexpandedParameterPacks(QualType T,
   6111                    SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
   6112 
   6113   /// \brief Collect the set of unexpanded parameter packs within the given
   6114   /// type.
   6115   ///
   6116   /// \param TL The type that will be traversed to find
   6117   /// unexpanded parameter packs.
   6118   void collectUnexpandedParameterPacks(TypeLoc TL,
   6119                    SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
   6120 
   6121   /// \brief Collect the set of unexpanded parameter packs within the given
   6122   /// nested-name-specifier.
   6123   ///
   6124   /// \param SS The nested-name-specifier that will be traversed to find
   6125   /// unexpanded parameter packs.
   6126   void collectUnexpandedParameterPacks(CXXScopeSpec &SS,
   6127                          SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
   6128 
   6129   /// \brief Collect the set of unexpanded parameter packs within the given
   6130   /// name.
   6131   ///
   6132   /// \param NameInfo The name that will be traversed to find
   6133   /// unexpanded parameter packs.
   6134   void collectUnexpandedParameterPacks(const DeclarationNameInfo &NameInfo,
   6135                          SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
   6136 
   6137   /// \brief Invoked when parsing a template argument followed by an
   6138   /// ellipsis, which creates a pack expansion.
   6139   ///
   6140   /// \param Arg The template argument preceding the ellipsis, which
   6141   /// may already be invalid.
   6142   ///
   6143   /// \param EllipsisLoc The location of the ellipsis.
   6144   ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg,
   6145                                             SourceLocation EllipsisLoc);
   6146 
   6147   /// \brief Invoked when parsing a type followed by an ellipsis, which
   6148   /// creates a pack expansion.
   6149   ///
   6150   /// \param Type The type preceding the ellipsis, which will become
   6151   /// the pattern of the pack expansion.
   6152   ///
   6153   /// \param EllipsisLoc The location of the ellipsis.
   6154   TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc);
   6155 
   6156   /// \brief Construct a pack expansion type from the pattern of the pack
   6157   /// expansion.
   6158   TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern,
   6159                                      SourceLocation EllipsisLoc,
   6160                                      Optional<unsigned> NumExpansions);
   6161 
   6162   /// \brief Construct a pack expansion type from the pattern of the pack
   6163   /// expansion.
   6164   QualType CheckPackExpansion(QualType Pattern,
   6165                               SourceRange PatternRange,
   6166                               SourceLocation EllipsisLoc,
   6167                               Optional<unsigned> NumExpansions);
   6168 
   6169   /// \brief Invoked when parsing an expression followed by an ellipsis, which
   6170   /// creates a pack expansion.
   6171   ///
   6172   /// \param Pattern The expression preceding the ellipsis, which will become
   6173   /// the pattern of the pack expansion.
   6174   ///
   6175   /// \param EllipsisLoc The location of the ellipsis.
   6176   ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc);
   6177 
   6178   /// \brief Invoked when parsing an expression followed by an ellipsis, which
   6179   /// creates a pack expansion.
   6180   ///
   6181   /// \param Pattern The expression preceding the ellipsis, which will become
   6182   /// the pattern of the pack expansion.
   6183   ///
   6184   /// \param EllipsisLoc The location of the ellipsis.
   6185   ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
   6186                                 Optional<unsigned> NumExpansions);
   6187 
   6188   /// \brief Determine whether we could expand a pack expansion with the
   6189   /// given set of parameter packs into separate arguments by repeatedly
   6190   /// transforming the pattern.
   6191   ///
   6192   /// \param EllipsisLoc The location of the ellipsis that identifies the
   6193   /// pack expansion.
   6194   ///
   6195   /// \param PatternRange The source range that covers the entire pattern of
   6196   /// the pack expansion.
   6197   ///
   6198   /// \param Unexpanded The set of unexpanded parameter packs within the
   6199   /// pattern.
   6200   ///
   6201   /// \param ShouldExpand Will be set to \c true if the transformer should
   6202   /// expand the corresponding pack expansions into separate arguments. When
   6203   /// set, \c NumExpansions must also be set.
   6204   ///
   6205   /// \param RetainExpansion Whether the caller should add an unexpanded
   6206   /// pack expansion after all of the expanded arguments. This is used
   6207   /// when extending explicitly-specified template argument packs per
   6208   /// C++0x [temp.arg.explicit]p9.
   6209   ///
   6210   /// \param NumExpansions The number of separate arguments that will be in
   6211   /// the expanded form of the corresponding pack expansion. This is both an
   6212   /// input and an output parameter, which can be set by the caller if the
   6213   /// number of expansions is known a priori (e.g., due to a prior substitution)
   6214   /// and will be set by the callee when the number of expansions is known.
   6215   /// The callee must set this value when \c ShouldExpand is \c true; it may
   6216   /// set this value in other cases.
   6217   ///
   6218   /// \returns true if an error occurred (e.g., because the parameter packs
   6219   /// are to be instantiated with arguments of different lengths), false
   6220   /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
   6221   /// must be set.
   6222   bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc,
   6223                                        SourceRange PatternRange,
   6224                              ArrayRef<UnexpandedParameterPack> Unexpanded,
   6225                              const MultiLevelTemplateArgumentList &TemplateArgs,
   6226                                        bool &ShouldExpand,
   6227                                        bool &RetainExpansion,
   6228                                        Optional<unsigned> &NumExpansions);
   6229 
   6230   /// \brief Determine the number of arguments in the given pack expansion
   6231   /// type.
   6232   ///
   6233   /// This routine assumes that the number of arguments in the expansion is
   6234   /// consistent across all of the unexpanded parameter packs in its pattern.
   6235   ///
   6236   /// Returns an empty Optional if the type can't be expanded.
   6237   Optional<unsigned> getNumArgumentsInExpansion(QualType T,
   6238       const MultiLevelTemplateArgumentList &TemplateArgs);
   6239 
   6240   /// \brief Determine whether the given declarator contains any unexpanded
   6241   /// parameter packs.
   6242   ///
   6243   /// This routine is used by the parser to disambiguate function declarators
   6244   /// with an ellipsis prior to the ')', e.g.,
   6245   ///
   6246   /// \code
   6247   ///   void f(T...);
   6248   /// \endcode
   6249   ///
   6250   /// To determine whether we have an (unnamed) function parameter pack or
   6251   /// a variadic function.
   6252   ///
   6253   /// \returns true if the declarator contains any unexpanded parameter packs,
   6254   /// false otherwise.
   6255   bool containsUnexpandedParameterPacks(Declarator &D);
   6256 
   6257   /// \brief Returns the pattern of the pack expansion for a template argument.
   6258   ///
   6259   /// \param OrigLoc The template argument to expand.
   6260   ///
   6261   /// \param Ellipsis Will be set to the location of the ellipsis.
   6262   ///
   6263   /// \param NumExpansions Will be set to the number of expansions that will
   6264   /// be generated from this pack expansion, if known a priori.
   6265   TemplateArgumentLoc getTemplateArgumentPackExpansionPattern(
   6266       TemplateArgumentLoc OrigLoc,
   6267       SourceLocation &Ellipsis,
   6268       Optional<unsigned> &NumExpansions) const;
   6269 
   6270   //===--------------------------------------------------------------------===//
   6271   // C++ Template Argument Deduction (C++ [temp.deduct])
   6272   //===--------------------------------------------------------------------===//
   6273 
   6274   QualType adjustCCAndNoReturn(QualType ArgFunctionType, QualType FunctionType);
   6275 
   6276   /// \brief Describes the result of template argument deduction.
   6277   ///
   6278   /// The TemplateDeductionResult enumeration describes the result of
   6279   /// template argument deduction, as returned from
   6280   /// DeduceTemplateArguments(). The separate TemplateDeductionInfo
   6281   /// structure provides additional information about the results of
   6282   /// template argument deduction, e.g., the deduced template argument
   6283   /// list (if successful) or the specific template parameters or
   6284   /// deduced arguments that were involved in the failure.
   6285   enum TemplateDeductionResult {
   6286     /// \brief Template argument deduction was successful.
   6287     TDK_Success = 0,
   6288     /// \brief The declaration was invalid; do nothing.
   6289     TDK_Invalid,
   6290     /// \brief Template argument deduction exceeded the maximum template
   6291     /// instantiation depth (which has already been diagnosed).
   6292     TDK_InstantiationDepth,
   6293     /// \brief Template argument deduction did not deduce a value
   6294     /// for every template parameter.
   6295     TDK_Incomplete,
   6296     /// \brief Template argument deduction produced inconsistent
   6297     /// deduced values for the given template parameter.
   6298     TDK_Inconsistent,
   6299     /// \brief Template argument deduction failed due to inconsistent
   6300     /// cv-qualifiers on a template parameter type that would
   6301     /// otherwise be deduced, e.g., we tried to deduce T in "const T"
   6302     /// but were given a non-const "X".
   6303     TDK_Underqualified,
   6304     /// \brief Substitution of the deduced template argument values
   6305     /// resulted in an error.
   6306     TDK_SubstitutionFailure,
   6307     /// \brief A non-depnedent component of the parameter did not match the
   6308     /// corresponding component of the argument.
   6309     TDK_NonDeducedMismatch,
   6310     /// \brief When performing template argument deduction for a function
   6311     /// template, there were too many call arguments.
   6312     TDK_TooManyArguments,
   6313     /// \brief When performing template argument deduction for a function
   6314     /// template, there were too few call arguments.
   6315     TDK_TooFewArguments,
   6316     /// \brief The explicitly-specified template arguments were not valid
   6317     /// template arguments for the given template.
   6318     TDK_InvalidExplicitArguments,
   6319     /// \brief The arguments included an overloaded function name that could
   6320     /// not be resolved to a suitable function.
   6321     TDK_FailedOverloadResolution,
   6322     /// \brief Deduction failed; that's all we know.
   6323     TDK_MiscellaneousDeductionFailure
   6324   };
   6325 
   6326   TemplateDeductionResult
   6327   DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
   6328                           const TemplateArgumentList &TemplateArgs,
   6329                           sema::TemplateDeductionInfo &Info);
   6330 
   6331   TemplateDeductionResult
   6332   DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial,
   6333                           const TemplateArgumentList &TemplateArgs,
   6334                           sema::TemplateDeductionInfo &Info);
   6335 
   6336   TemplateDeductionResult SubstituteExplicitTemplateArguments(
   6337       FunctionTemplateDecl *FunctionTemplate,
   6338       TemplateArgumentListInfo &ExplicitTemplateArgs,
   6339       SmallVectorImpl<DeducedTemplateArgument> &Deduced,
   6340       SmallVectorImpl<QualType> &ParamTypes, QualType *FunctionType,
   6341       sema::TemplateDeductionInfo &Info);
   6342 
   6343   /// brief A function argument from which we performed template argument
   6344   // deduction for a call.
   6345   struct OriginalCallArg {
   6346     OriginalCallArg(QualType OriginalParamType,
   6347                     unsigned ArgIdx,
   6348                     QualType OriginalArgType)
   6349       : OriginalParamType(OriginalParamType), ArgIdx(ArgIdx),
   6350         OriginalArgType(OriginalArgType) { }
   6351 
   6352     QualType OriginalParamType;
   6353     unsigned ArgIdx;
   6354     QualType OriginalArgType;
   6355   };
   6356 
   6357   TemplateDeductionResult
   6358   FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate,
   6359                       SmallVectorImpl<DeducedTemplateArgument> &Deduced,
   6360                                   unsigned NumExplicitlySpecified,
   6361                                   FunctionDecl *&Specialization,
   6362                                   sema::TemplateDeductionInfo &Info,
   6363            SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = nullptr,
   6364                                   bool PartialOverloading = false);
   6365 
   6366   TemplateDeductionResult
   6367   DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
   6368                           TemplateArgumentListInfo *ExplicitTemplateArgs,
   6369                           ArrayRef<Expr *> Args,
   6370                           FunctionDecl *&Specialization,
   6371                           sema::TemplateDeductionInfo &Info,
   6372                           bool PartialOverloading = false);
   6373 
   6374   TemplateDeductionResult
   6375   DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
   6376                           TemplateArgumentListInfo *ExplicitTemplateArgs,
   6377                           QualType ArgFunctionType,
   6378                           FunctionDecl *&Specialization,
   6379                           sema::TemplateDeductionInfo &Info,
   6380                           bool InOverloadResolution = false);
   6381 
   6382   TemplateDeductionResult
   6383   DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
   6384                           QualType ToType,
   6385                           CXXConversionDecl *&Specialization,
   6386                           sema::TemplateDeductionInfo &Info);
   6387 
   6388   TemplateDeductionResult
   6389   DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
   6390                           TemplateArgumentListInfo *ExplicitTemplateArgs,
   6391                           FunctionDecl *&Specialization,
   6392                           sema::TemplateDeductionInfo &Info,
   6393                           bool InOverloadResolution = false);
   6394 
   6395   /// \brief Substitute Replacement for \p auto in \p TypeWithAuto
   6396   QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement);
   6397   /// \brief Substitute Replacement for auto in TypeWithAuto
   6398   TypeSourceInfo* SubstAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto,
   6399                                           QualType Replacement);
   6400 
   6401   /// \brief Result type of DeduceAutoType.
   6402   enum DeduceAutoResult {
   6403     DAR_Succeeded,
   6404     DAR_Failed,
   6405     DAR_FailedAlreadyDiagnosed
   6406   };
   6407 
   6408   DeduceAutoResult DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer,
   6409                                   QualType &Result);
   6410   DeduceAutoResult DeduceAutoType(TypeLoc AutoTypeLoc, Expr *&Initializer,
   6411                                   QualType &Result);
   6412   void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init);
   6413   bool DeduceReturnType(FunctionDecl *FD, SourceLocation Loc,
   6414                         bool Diagnose = true);
   6415 
   6416   QualType deduceVarTypeFromInitializer(VarDecl *VDecl, DeclarationName Name,
   6417                                         QualType Type, TypeSourceInfo *TSI,
   6418                                         SourceRange Range, bool DirectInit,
   6419                                         Expr *Init);
   6420 
   6421   TypeLoc getReturnTypeLoc(FunctionDecl *FD) const;
   6422 
   6423   bool DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD,
   6424                                         SourceLocation ReturnLoc,
   6425                                         Expr *&RetExpr, AutoType *AT);
   6426 
   6427   FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1,
   6428                                                    FunctionTemplateDecl *FT2,
   6429                                                    SourceLocation Loc,
   6430                                            TemplatePartialOrderingContext TPOC,
   6431                                                    unsigned NumCallArguments1,
   6432                                                    unsigned NumCallArguments2);
   6433   UnresolvedSetIterator
   6434   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
   6435                      TemplateSpecCandidateSet &FailedCandidates,
   6436                      SourceLocation Loc,
   6437                      const PartialDiagnostic &NoneDiag,
   6438                      const PartialDiagnostic &AmbigDiag,
   6439                      const PartialDiagnostic &CandidateDiag,
   6440                      bool Complain = true, QualType TargetType = QualType());
   6441 
   6442   ClassTemplatePartialSpecializationDecl *
   6443   getMoreSpecializedPartialSpecialization(
   6444                                   ClassTemplatePartialSpecializationDecl *PS1,
   6445                                   ClassTemplatePartialSpecializationDecl *PS2,
   6446                                   SourceLocation Loc);
   6447 
   6448   VarTemplatePartialSpecializationDecl *getMoreSpecializedPartialSpecialization(
   6449       VarTemplatePartialSpecializationDecl *PS1,
   6450       VarTemplatePartialSpecializationDecl *PS2, SourceLocation Loc);
   6451 
   6452   void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs,
   6453                                   bool OnlyDeduced,
   6454                                   unsigned Depth,
   6455                                   llvm::SmallBitVector &Used);
   6456   void MarkDeducedTemplateParameters(
   6457                                   const FunctionTemplateDecl *FunctionTemplate,
   6458                                   llvm::SmallBitVector &Deduced) {
   6459     return MarkDeducedTemplateParameters(Context, FunctionTemplate, Deduced);
   6460   }
   6461   static void MarkDeducedTemplateParameters(ASTContext &Ctx,
   6462                                   const FunctionTemplateDecl *FunctionTemplate,
   6463                                   llvm::SmallBitVector &Deduced);
   6464 
   6465   //===--------------------------------------------------------------------===//
   6466   // C++ Template Instantiation
   6467   //
   6468 
   6469   MultiLevelTemplateArgumentList
   6470   getTemplateInstantiationArgs(NamedDecl *D,
   6471                                const TemplateArgumentList *Innermost = nullptr,
   6472                                bool RelativeToPrimary = false,
   6473                                const FunctionDecl *Pattern = nullptr);
   6474 
   6475   /// \brief A template instantiation that is currently in progress.
   6476   struct ActiveTemplateInstantiation {
   6477     /// \brief The kind of template instantiation we are performing
   6478     enum InstantiationKind {
   6479       /// We are instantiating a template declaration. The entity is
   6480       /// the declaration we're instantiating (e.g., a CXXRecordDecl).
   6481       TemplateInstantiation,
   6482 
   6483       /// We are instantiating a default argument for a template
   6484       /// parameter. The Entity is the template, and
   6485       /// TemplateArgs/NumTemplateArguments provides the template
   6486       /// arguments as specified.
   6487       /// FIXME: Use a TemplateArgumentList
   6488       DefaultTemplateArgumentInstantiation,
   6489 
   6490       /// We are instantiating a default argument for a function.
   6491       /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs
   6492       /// provides the template arguments as specified.
   6493       DefaultFunctionArgumentInstantiation,
   6494 
   6495       /// We are substituting explicit template arguments provided for
   6496       /// a function template. The entity is a FunctionTemplateDecl.
   6497       ExplicitTemplateArgumentSubstitution,
   6498 
   6499       /// We are substituting template argument determined as part of
   6500       /// template argument deduction for either a class template
   6501       /// partial specialization or a function template. The
   6502       /// Entity is either a ClassTemplatePartialSpecializationDecl or
   6503       /// a FunctionTemplateDecl.
   6504       DeducedTemplateArgumentSubstitution,
   6505 
   6506       /// We are substituting prior template arguments into a new
   6507       /// template parameter. The template parameter itself is either a
   6508       /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl.
   6509       PriorTemplateArgumentSubstitution,
   6510 
   6511       /// We are checking the validity of a default template argument that
   6512       /// has been used when naming a template-id.
   6513       DefaultTemplateArgumentChecking,
   6514 
   6515       /// We are instantiating the exception specification for a function
   6516       /// template which was deferred until it was needed.
   6517       ExceptionSpecInstantiation
   6518     } Kind;
   6519 
   6520     /// \brief The point of instantiation within the source code.
   6521     SourceLocation PointOfInstantiation;
   6522 
   6523     /// \brief The template (or partial specialization) in which we are
   6524     /// performing the instantiation, for substitutions of prior template
   6525     /// arguments.
   6526     NamedDecl *Template;
   6527 
   6528     /// \brief The entity that is being instantiated.
   6529     Decl *Entity;
   6530 
   6531     /// \brief The list of template arguments we are substituting, if they
   6532     /// are not part of the entity.
   6533     const TemplateArgument *TemplateArgs;
   6534 
   6535     /// \brief The number of template arguments in TemplateArgs.
   6536     unsigned NumTemplateArgs;
   6537 
   6538     /// \brief The template deduction info object associated with the
   6539     /// substitution or checking of explicit or deduced template arguments.
   6540     sema::TemplateDeductionInfo *DeductionInfo;
   6541 
   6542     /// \brief The source range that covers the construct that cause
   6543     /// the instantiation, e.g., the template-id that causes a class
   6544     /// template instantiation.
   6545     SourceRange InstantiationRange;
   6546 
   6547     ActiveTemplateInstantiation()
   6548       : Kind(TemplateInstantiation), Template(nullptr), Entity(nullptr),
   6549         TemplateArgs(nullptr), NumTemplateArgs(0), DeductionInfo(nullptr) {}
   6550 
   6551     /// \brief Determines whether this template is an actual instantiation
   6552     /// that should be counted toward the maximum instantiation depth.
   6553     bool isInstantiationRecord() const;
   6554 
   6555     friend bool operator==(const ActiveTemplateInstantiation &X,
   6556                            const ActiveTemplateInstantiation &Y) {
   6557       if (X.Kind != Y.Kind)
   6558         return false;
   6559 
   6560       if (X.Entity != Y.Entity)
   6561         return false;
   6562 
   6563       switch (X.Kind) {
   6564       case TemplateInstantiation:
   6565       case ExceptionSpecInstantiation:
   6566         return true;
   6567 
   6568       case PriorTemplateArgumentSubstitution:
   6569       case DefaultTemplateArgumentChecking:
   6570         return X.Template == Y.Template && X.TemplateArgs == Y.TemplateArgs;
   6571 
   6572       case DefaultTemplateArgumentInstantiation:
   6573       case ExplicitTemplateArgumentSubstitution:
   6574       case DeducedTemplateArgumentSubstitution:
   6575       case DefaultFunctionArgumentInstantiation:
   6576         return X.TemplateArgs == Y.TemplateArgs;
   6577 
   6578       }
   6579 
   6580       llvm_unreachable("Invalid InstantiationKind!");
   6581     }
   6582 
   6583     friend bool operator!=(const ActiveTemplateInstantiation &X,
   6584                            const ActiveTemplateInstantiation &Y) {
   6585       return !(X == Y);
   6586     }
   6587   };
   6588 
   6589   /// \brief List of active template instantiations.
   6590   ///
   6591   /// This vector is treated as a stack. As one template instantiation
   6592   /// requires another template instantiation, additional
   6593   /// instantiations are pushed onto the stack up to a
   6594   /// user-configurable limit LangOptions::InstantiationDepth.
   6595   SmallVector<ActiveTemplateInstantiation, 16>
   6596     ActiveTemplateInstantiations;
   6597 
   6598   /// \brief Extra modules inspected when performing a lookup during a template
   6599   /// instantiation. Computed lazily.
   6600   SmallVector<Module*, 16> ActiveTemplateInstantiationLookupModules;
   6601 
   6602   /// \brief Cache of additional modules that should be used for name lookup
   6603   /// within the current template instantiation. Computed lazily; use
   6604   /// getLookupModules() to get a complete set.
   6605   llvm::DenseSet<Module*> LookupModulesCache;
   6606 
   6607   /// \brief Get the set of additional modules that should be checked during
   6608   /// name lookup. A module and its imports become visible when instanting a
   6609   /// template defined within it.
   6610   llvm::DenseSet<Module*> &getLookupModules();
   6611 
   6612   /// \brief Whether we are in a SFINAE context that is not associated with
   6613   /// template instantiation.
   6614   ///
   6615   /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside
   6616   /// of a template instantiation or template argument deduction.
   6617   bool InNonInstantiationSFINAEContext;
   6618 
   6619   /// \brief The number of ActiveTemplateInstantiation entries in
   6620   /// \c ActiveTemplateInstantiations that are not actual instantiations and,
   6621   /// therefore, should not be counted as part of the instantiation depth.
   6622   unsigned NonInstantiationEntries;
   6623 
   6624   /// \brief The last template from which a template instantiation
   6625   /// error or warning was produced.
   6626   ///
   6627   /// This value is used to suppress printing of redundant template
   6628   /// instantiation backtraces when there are multiple errors in the
   6629   /// same instantiation. FIXME: Does this belong in Sema? It's tough
   6630   /// to implement it anywhere else.
   6631   ActiveTemplateInstantiation LastTemplateInstantiationErrorContext;
   6632 
   6633   /// \brief The current index into pack expansion arguments that will be
   6634   /// used for substitution of parameter packs.
   6635   ///
   6636   /// The pack expansion index will be -1 to indicate that parameter packs
   6637   /// should be instantiated as themselves. Otherwise, the index specifies
   6638   /// which argument within the parameter pack will be used for substitution.
   6639   int ArgumentPackSubstitutionIndex;
   6640 
   6641   /// \brief RAII object used to change the argument pack substitution index
   6642   /// within a \c Sema object.
   6643   ///
   6644   /// See \c ArgumentPackSubstitutionIndex for more information.
   6645   class ArgumentPackSubstitutionIndexRAII {
   6646     Sema &Self;
   6647     int OldSubstitutionIndex;
   6648 
   6649   public:
   6650     ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex)
   6651       : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) {
   6652       Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex;
   6653     }
   6654 
   6655     ~ArgumentPackSubstitutionIndexRAII() {
   6656       Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex;
   6657     }
   6658   };
   6659 
   6660   friend class ArgumentPackSubstitutionRAII;
   6661 
   6662   /// \brief For each declaration that involved template argument deduction, the
   6663   /// set of diagnostics that were suppressed during that template argument
   6664   /// deduction.
   6665   ///
   6666   /// FIXME: Serialize this structure to the AST file.
   6667   typedef llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1> >
   6668     SuppressedDiagnosticsMap;
   6669   SuppressedDiagnosticsMap SuppressedDiagnostics;
   6670 
   6671   /// \brief A stack object to be created when performing template
   6672   /// instantiation.
   6673   ///
   6674   /// Construction of an object of type \c InstantiatingTemplate
   6675   /// pushes the current instantiation onto the stack of active
   6676   /// instantiations. If the size of this stack exceeds the maximum
   6677   /// number of recursive template instantiations, construction
   6678   /// produces an error and evaluates true.
   6679   ///
   6680   /// Destruction of this object will pop the named instantiation off
   6681   /// the stack.
   6682   struct InstantiatingTemplate {
   6683     /// \brief Note that we are instantiating a class template,
   6684     /// function template, variable template, alias template,
   6685     /// or a member thereof.
   6686     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
   6687                           Decl *Entity,
   6688                           SourceRange InstantiationRange = SourceRange());
   6689 
   6690     struct ExceptionSpecification {};
   6691     /// \brief Note that we are instantiating an exception specification
   6692     /// of a function template.
   6693     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
   6694                           FunctionDecl *Entity, ExceptionSpecification,
   6695                           SourceRange InstantiationRange = SourceRange());
   6696 
   6697     /// \brief Note that we are instantiating a default argument in a
   6698     /// template-id.
   6699     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
   6700                           TemplateDecl *Template,
   6701                           ArrayRef<TemplateArgument> TemplateArgs,
   6702                           SourceRange InstantiationRange = SourceRange());
   6703 
   6704     /// \brief Note that we are instantiating a default argument in a
   6705     /// template-id.
   6706     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
   6707                           FunctionTemplateDecl *FunctionTemplate,
   6708                           ArrayRef<TemplateArgument> TemplateArgs,
   6709                           ActiveTemplateInstantiation::InstantiationKind Kind,
   6710                           sema::TemplateDeductionInfo &DeductionInfo,
   6711                           SourceRange InstantiationRange = SourceRange());
   6712 
   6713     /// \brief Note that we are instantiating as part of template
   6714     /// argument deduction for a class template partial
   6715     /// specialization.
   6716     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
   6717                           ClassTemplatePartialSpecializationDecl *PartialSpec,
   6718                           ArrayRef<TemplateArgument> TemplateArgs,
   6719                           sema::TemplateDeductionInfo &DeductionInfo,
   6720                           SourceRange InstantiationRange = SourceRange());
   6721 
   6722     /// \brief Note that we are instantiating as part of template
   6723     /// argument deduction for a variable template partial
   6724     /// specialization.
   6725     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
   6726                           VarTemplatePartialSpecializationDecl *PartialSpec,
   6727                           ArrayRef<TemplateArgument> TemplateArgs,
   6728                           sema::TemplateDeductionInfo &DeductionInfo,
   6729                           SourceRange InstantiationRange = SourceRange());
   6730 
   6731     /// \brief Note that we are instantiating a default argument for a function
   6732     /// parameter.
   6733     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
   6734                           ParmVarDecl *Param,
   6735                           ArrayRef<TemplateArgument> TemplateArgs,
   6736                           SourceRange InstantiationRange = SourceRange());
   6737 
   6738     /// \brief Note that we are substituting prior template arguments into a
   6739     /// non-type parameter.
   6740     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
   6741                           NamedDecl *Template,
   6742                           NonTypeTemplateParmDecl *Param,
   6743                           ArrayRef<TemplateArgument> TemplateArgs,
   6744                           SourceRange InstantiationRange);
   6745 
   6746     /// \brief Note that we are substituting prior template arguments into a
   6747     /// template template parameter.
   6748     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
   6749                           NamedDecl *Template,
   6750                           TemplateTemplateParmDecl *Param,
   6751                           ArrayRef<TemplateArgument> TemplateArgs,
   6752                           SourceRange InstantiationRange);
   6753 
   6754     /// \brief Note that we are checking the default template argument
   6755     /// against the template parameter for a given template-id.
   6756     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
   6757                           TemplateDecl *Template,
   6758                           NamedDecl *Param,
   6759                           ArrayRef<TemplateArgument> TemplateArgs,
   6760                           SourceRange InstantiationRange);
   6761 
   6762 
   6763     /// \brief Note that we have finished instantiating this template.
   6764     void Clear();
   6765 
   6766     ~InstantiatingTemplate() { Clear(); }
   6767 
   6768     /// \brief Determines whether we have exceeded the maximum
   6769     /// recursive template instantiations.
   6770     bool isInvalid() const { return Invalid; }
   6771 
   6772   private:
   6773     Sema &SemaRef;
   6774     bool Invalid;
   6775     bool SavedInNonInstantiationSFINAEContext;
   6776     bool CheckInstantiationDepth(SourceLocation PointOfInstantiation,
   6777                                  SourceRange InstantiationRange);
   6778 
   6779     InstantiatingTemplate(
   6780         Sema &SemaRef, ActiveTemplateInstantiation::InstantiationKind Kind,
   6781         SourceLocation PointOfInstantiation, SourceRange InstantiationRange,
   6782         Decl *Entity, NamedDecl *Template = nullptr,
   6783         ArrayRef<TemplateArgument> TemplateArgs = None,
   6784         sema::TemplateDeductionInfo *DeductionInfo = nullptr);
   6785 
   6786     InstantiatingTemplate(const InstantiatingTemplate&) = delete;
   6787 
   6788     InstantiatingTemplate&
   6789     operator=(const InstantiatingTemplate&) = delete;
   6790   };
   6791 
   6792   void PrintInstantiationStack();
   6793 
   6794   /// \brief Determines whether we are currently in a context where
   6795   /// template argument substitution failures are not considered
   6796   /// errors.
   6797   ///
   6798   /// \returns An empty \c Optional if we're not in a SFINAE context.
   6799   /// Otherwise, contains a pointer that, if non-NULL, contains the nearest
   6800   /// template-deduction context object, which can be used to capture
   6801   /// diagnostics that will be suppressed.
   6802   Optional<sema::TemplateDeductionInfo *> isSFINAEContext() const;
   6803 
   6804   /// \brief Determines whether we are currently in a context that
   6805   /// is not evaluated as per C++ [expr] p5.
   6806   bool isUnevaluatedContext() const {
   6807     assert(!ExprEvalContexts.empty() &&
   6808            "Must be in an expression evaluation context");
   6809     return ExprEvalContexts.back().isUnevaluated();
   6810   }
   6811 
   6812   /// \brief RAII class used to determine whether SFINAE has
   6813   /// trapped any errors that occur during template argument
   6814   /// deduction.
   6815   class SFINAETrap {
   6816     Sema &SemaRef;
   6817     unsigned PrevSFINAEErrors;
   6818     bool PrevInNonInstantiationSFINAEContext;
   6819     bool PrevAccessCheckingSFINAE;
   6820 
   6821   public:
   6822     explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false)
   6823       : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors),
   6824         PrevInNonInstantiationSFINAEContext(
   6825                                       SemaRef.InNonInstantiationSFINAEContext),
   6826         PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE)
   6827     {
   6828       if (!SemaRef.isSFINAEContext())
   6829         SemaRef.InNonInstantiationSFINAEContext = true;
   6830       SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE;
   6831     }
   6832 
   6833     ~SFINAETrap() {
   6834       SemaRef.NumSFINAEErrors = PrevSFINAEErrors;
   6835       SemaRef.InNonInstantiationSFINAEContext
   6836         = PrevInNonInstantiationSFINAEContext;
   6837       SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE;
   6838     }
   6839 
   6840     /// \brief Determine whether any SFINAE errors have been trapped.
   6841     bool hasErrorOccurred() const {
   6842       return SemaRef.NumSFINAEErrors > PrevSFINAEErrors;
   6843     }
   6844   };
   6845 
   6846   /// \brief RAII class used to indicate that we are performing provisional
   6847   /// semantic analysis to determine the validity of a construct, so
   6848   /// typo-correction and diagnostics in the immediate context (not within
   6849   /// implicitly-instantiated templates) should be suppressed.
   6850   class TentativeAnalysisScope {
   6851     Sema &SemaRef;
   6852     // FIXME: Using a SFINAETrap for this is a hack.
   6853     SFINAETrap Trap;
   6854     bool PrevDisableTypoCorrection;
   6855   public:
   6856     explicit TentativeAnalysisScope(Sema &SemaRef)
   6857         : SemaRef(SemaRef), Trap(SemaRef, true),
   6858           PrevDisableTypoCorrection(SemaRef.DisableTypoCorrection) {
   6859       SemaRef.DisableTypoCorrection = true;
   6860     }
   6861     ~TentativeAnalysisScope() {
   6862       SemaRef.DisableTypoCorrection = PrevDisableTypoCorrection;
   6863     }
   6864   };
   6865 
   6866   /// \brief The current instantiation scope used to store local
   6867   /// variables.
   6868   LocalInstantiationScope *CurrentInstantiationScope;
   6869 
   6870   /// \brief Tracks whether we are in a context where typo correction is
   6871   /// disabled.
   6872   bool DisableTypoCorrection;
   6873 
   6874   /// \brief The number of typos corrected by CorrectTypo.
   6875   unsigned TyposCorrected;
   6876 
   6877   typedef llvm::SmallSet<SourceLocation, 2> SrcLocSet;
   6878   typedef llvm::DenseMap<IdentifierInfo *, SrcLocSet> IdentifierSourceLocations;
   6879 
   6880   /// \brief A cache containing identifiers for which typo correction failed and
   6881   /// their locations, so that repeated attempts to correct an identifier in a
   6882   /// given location are ignored if typo correction already failed for it.
   6883   IdentifierSourceLocations TypoCorrectionFailures;
   6884 
   6885   /// \brief Worker object for performing CFG-based warnings.
   6886   sema::AnalysisBasedWarnings AnalysisWarnings;
   6887   threadSafety::BeforeSet *ThreadSafetyDeclCache;
   6888 
   6889   /// \brief An entity for which implicit template instantiation is required.
   6890   ///
   6891   /// The source location associated with the declaration is the first place in
   6892   /// the source code where the declaration was "used". It is not necessarily
   6893   /// the point of instantiation (which will be either before or after the
   6894   /// namespace-scope declaration that triggered this implicit instantiation),
   6895   /// However, it is the location that diagnostics should generally refer to,
   6896   /// because users will need to know what code triggered the instantiation.
   6897   typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation;
   6898 
   6899   /// \brief The queue of implicit template instantiations that are required
   6900   /// but have not yet been performed.
   6901   std::deque<PendingImplicitInstantiation> PendingInstantiations;
   6902 
   6903   class SavePendingInstantiationsAndVTableUsesRAII {
   6904   public:
   6905     SavePendingInstantiationsAndVTableUsesRAII(Sema &S, bool Enabled)
   6906         : S(S), Enabled(Enabled) {
   6907       if (!Enabled) return;
   6908 
   6909       SavedPendingInstantiations.swap(S.PendingInstantiations);
   6910       SavedVTableUses.swap(S.VTableUses);
   6911     }
   6912 
   6913     ~SavePendingInstantiationsAndVTableUsesRAII() {
   6914       if (!Enabled) return;
   6915 
   6916       // Restore the set of pending vtables.
   6917       assert(S.VTableUses.empty() &&
   6918              "VTableUses should be empty before it is discarded.");
   6919       S.VTableUses.swap(SavedVTableUses);
   6920 
   6921       // Restore the set of pending implicit instantiations.
   6922       assert(S.PendingInstantiations.empty() &&
   6923              "PendingInstantiations should be empty before it is discarded.");
   6924       S.PendingInstantiations.swap(SavedPendingInstantiations);
   6925     }
   6926 
   6927   private:
   6928     Sema &S;
   6929     SmallVector<VTableUse, 16> SavedVTableUses;
   6930     std::deque<PendingImplicitInstantiation> SavedPendingInstantiations;
   6931     bool Enabled;
   6932   };
   6933 
   6934   /// \brief The queue of implicit template instantiations that are required
   6935   /// and must be performed within the current local scope.
   6936   ///
   6937   /// This queue is only used for member functions of local classes in
   6938   /// templates, which must be instantiated in the same scope as their
   6939   /// enclosing function, so that they can reference function-local
   6940   /// types, static variables, enumerators, etc.
   6941   std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations;
   6942 
   6943   class SavePendingLocalImplicitInstantiationsRAII {
   6944   public:
   6945     SavePendingLocalImplicitInstantiationsRAII(Sema &S): S(S) {
   6946       SavedPendingLocalImplicitInstantiations.swap(
   6947           S.PendingLocalImplicitInstantiations);
   6948     }
   6949 
   6950     ~SavePendingLocalImplicitInstantiationsRAII() {
   6951       assert(S.PendingLocalImplicitInstantiations.empty() &&
   6952              "there shouldn't be any pending local implicit instantiations");
   6953       SavedPendingLocalImplicitInstantiations.swap(
   6954           S.PendingLocalImplicitInstantiations);
   6955     }
   6956 
   6957   private:
   6958     Sema &S;
   6959     std::deque<PendingImplicitInstantiation>
   6960     SavedPendingLocalImplicitInstantiations;
   6961   };
   6962 
   6963   void PerformPendingInstantiations(bool LocalOnly = false);
   6964 
   6965   TypeSourceInfo *SubstType(TypeSourceInfo *T,
   6966                             const MultiLevelTemplateArgumentList &TemplateArgs,
   6967                             SourceLocation Loc, DeclarationName Entity);
   6968 
   6969   QualType SubstType(QualType T,
   6970                      const MultiLevelTemplateArgumentList &TemplateArgs,
   6971                      SourceLocation Loc, DeclarationName Entity);
   6972 
   6973   TypeSourceInfo *SubstType(TypeLoc TL,
   6974                             const MultiLevelTemplateArgumentList &TemplateArgs,
   6975                             SourceLocation Loc, DeclarationName Entity);
   6976 
   6977   TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T,
   6978                             const MultiLevelTemplateArgumentList &TemplateArgs,
   6979                                         SourceLocation Loc,
   6980                                         DeclarationName Entity,
   6981                                         CXXRecordDecl *ThisContext,
   6982                                         unsigned ThisTypeQuals);
   6983   void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto,
   6984                           const MultiLevelTemplateArgumentList &Args);
   6985   ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D,
   6986                             const MultiLevelTemplateArgumentList &TemplateArgs,
   6987                                 int indexAdjustment,
   6988                                 Optional<unsigned> NumExpansions,
   6989                                 bool ExpectParameterPack);
   6990   bool SubstParmTypes(SourceLocation Loc,
   6991                       ParmVarDecl **Params, unsigned NumParams,
   6992                       const MultiLevelTemplateArgumentList &TemplateArgs,
   6993                       SmallVectorImpl<QualType> &ParamTypes,
   6994                       SmallVectorImpl<ParmVarDecl *> *OutParams = nullptr);
   6995   ExprResult SubstExpr(Expr *E,
   6996                        const MultiLevelTemplateArgumentList &TemplateArgs);
   6997 
   6998   /// \brief Substitute the given template arguments into a list of
   6999   /// expressions, expanding pack expansions if required.
   7000   ///
   7001   /// \param Exprs The list of expressions to substitute into.
   7002   ///
   7003   /// \param NumExprs The number of expressions in \p Exprs.
   7004   ///
   7005   /// \param IsCall Whether this is some form of call, in which case
   7006   /// default arguments will be dropped.
   7007   ///
   7008   /// \param TemplateArgs The set of template arguments to substitute.
   7009   ///
   7010   /// \param Outputs Will receive all of the substituted arguments.
   7011   ///
   7012   /// \returns true if an error occurred, false otherwise.
   7013   bool SubstExprs(Expr **Exprs, unsigned NumExprs, bool IsCall,
   7014                   const MultiLevelTemplateArgumentList &TemplateArgs,
   7015                   SmallVectorImpl<Expr *> &Outputs);
   7016 
   7017   StmtResult SubstStmt(Stmt *S,
   7018                        const MultiLevelTemplateArgumentList &TemplateArgs);
   7019 
   7020   Decl *SubstDecl(Decl *D, DeclContext *Owner,
   7021                   const MultiLevelTemplateArgumentList &TemplateArgs);
   7022 
   7023   ExprResult SubstInitializer(Expr *E,
   7024                        const MultiLevelTemplateArgumentList &TemplateArgs,
   7025                        bool CXXDirectInit);
   7026 
   7027   bool
   7028   SubstBaseSpecifiers(CXXRecordDecl *Instantiation,
   7029                       CXXRecordDecl *Pattern,
   7030                       const MultiLevelTemplateArgumentList &TemplateArgs);
   7031 
   7032   bool
   7033   InstantiateClass(SourceLocation PointOfInstantiation,
   7034                    CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
   7035                    const MultiLevelTemplateArgumentList &TemplateArgs,
   7036                    TemplateSpecializationKind TSK,
   7037                    bool Complain = true);
   7038 
   7039   bool InstantiateEnum(SourceLocation PointOfInstantiation,
   7040                        EnumDecl *Instantiation, EnumDecl *Pattern,
   7041                        const MultiLevelTemplateArgumentList &TemplateArgs,
   7042                        TemplateSpecializationKind TSK);
   7043 
   7044   bool InstantiateInClassInitializer(
   7045       SourceLocation PointOfInstantiation, FieldDecl *Instantiation,
   7046       FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs);
   7047 
   7048   struct LateInstantiatedAttribute {
   7049     const Attr *TmplAttr;
   7050     LocalInstantiationScope *Scope;
   7051     Decl *NewDecl;
   7052 
   7053     LateInstantiatedAttribute(const Attr *A, LocalInstantiationScope *S,
   7054                               Decl *D)
   7055       : TmplAttr(A), Scope(S), NewDecl(D)
   7056     { }
   7057   };
   7058   typedef SmallVector<LateInstantiatedAttribute, 16> LateInstantiatedAttrVec;
   7059 
   7060   void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
   7061                         const Decl *Pattern, Decl *Inst,
   7062                         LateInstantiatedAttrVec *LateAttrs = nullptr,
   7063                         LocalInstantiationScope *OuterMostScope = nullptr);
   7064 
   7065   bool
   7066   InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation,
   7067                            ClassTemplateSpecializationDecl *ClassTemplateSpec,
   7068                            TemplateSpecializationKind TSK,
   7069                            bool Complain = true);
   7070 
   7071   void InstantiateClassMembers(SourceLocation PointOfInstantiation,
   7072                                CXXRecordDecl *Instantiation,
   7073                             const MultiLevelTemplateArgumentList &TemplateArgs,
   7074                                TemplateSpecializationKind TSK);
   7075 
   7076   void InstantiateClassTemplateSpecializationMembers(
   7077                                           SourceLocation PointOfInstantiation,
   7078                            ClassTemplateSpecializationDecl *ClassTemplateSpec,
   7079                                                 TemplateSpecializationKind TSK);
   7080 
   7081   NestedNameSpecifierLoc
   7082   SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
   7083                            const MultiLevelTemplateArgumentList &TemplateArgs);
   7084 
   7085   DeclarationNameInfo
   7086   SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
   7087                            const MultiLevelTemplateArgumentList &TemplateArgs);
   7088   TemplateName
   7089   SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name,
   7090                     SourceLocation Loc,
   7091                     const MultiLevelTemplateArgumentList &TemplateArgs);
   7092   bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs,
   7093              TemplateArgumentListInfo &Result,
   7094              const MultiLevelTemplateArgumentList &TemplateArgs);
   7095 
   7096   void InstantiateExceptionSpec(SourceLocation PointOfInstantiation,
   7097                                 FunctionDecl *Function);
   7098   void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
   7099                                      FunctionDecl *Function,
   7100                                      bool Recursive = false,
   7101                                      bool DefinitionRequired = false);
   7102   VarTemplateSpecializationDecl *BuildVarTemplateInstantiation(
   7103       VarTemplateDecl *VarTemplate, VarDecl *FromVar,
   7104       const TemplateArgumentList &TemplateArgList,
   7105       const TemplateArgumentListInfo &TemplateArgsInfo,
   7106       SmallVectorImpl<TemplateArgument> &Converted,
   7107       SourceLocation PointOfInstantiation, void *InsertPos,
   7108       LateInstantiatedAttrVec *LateAttrs = nullptr,
   7109       LocalInstantiationScope *StartingScope = nullptr);
   7110   VarTemplateSpecializationDecl *CompleteVarTemplateSpecializationDecl(
   7111       VarTemplateSpecializationDecl *VarSpec, VarDecl *PatternDecl,
   7112       const MultiLevelTemplateArgumentList &TemplateArgs);
   7113   void
   7114   BuildVariableInstantiation(VarDecl *NewVar, VarDecl *OldVar,
   7115                              const MultiLevelTemplateArgumentList &TemplateArgs,
   7116                              LateInstantiatedAttrVec *LateAttrs,
   7117                              DeclContext *Owner,
   7118                              LocalInstantiationScope *StartingScope,
   7119                              bool InstantiatingVarTemplate = false);
   7120   void InstantiateVariableInitializer(
   7121       VarDecl *Var, VarDecl *OldVar,
   7122       const MultiLevelTemplateArgumentList &TemplateArgs);
   7123   void InstantiateVariableDefinition(SourceLocation PointOfInstantiation,
   7124                                      VarDecl *Var, bool Recursive = false,
   7125                                      bool DefinitionRequired = false);
   7126   void InstantiateStaticDataMemberDefinition(
   7127                                      SourceLocation PointOfInstantiation,
   7128                                      VarDecl *Var,
   7129                                      bool Recursive = false,
   7130                                      bool DefinitionRequired = false);
   7131 
   7132   void InstantiateMemInitializers(CXXConstructorDecl *New,
   7133                                   const CXXConstructorDecl *Tmpl,
   7134                             const MultiLevelTemplateArgumentList &TemplateArgs);
   7135 
   7136   NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
   7137                           const MultiLevelTemplateArgumentList &TemplateArgs);
   7138   DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC,
   7139                           const MultiLevelTemplateArgumentList &TemplateArgs);
   7140 
   7141   // Objective-C declarations.
   7142   enum ObjCContainerKind {
   7143     OCK_None = -1,
   7144     OCK_Interface = 0,
   7145     OCK_Protocol,
   7146     OCK_Category,
   7147     OCK_ClassExtension,
   7148     OCK_Implementation,
   7149     OCK_CategoryImplementation
   7150   };
   7151   ObjCContainerKind getObjCContainerKind() const;
   7152 
   7153   DeclResult actOnObjCTypeParam(Scope *S,
   7154                                 ObjCTypeParamVariance variance,
   7155                                 SourceLocation varianceLoc,
   7156                                 unsigned index,
   7157                                 IdentifierInfo *paramName,
   7158                                 SourceLocation paramLoc,
   7159                                 SourceLocation colonLoc,
   7160                                 ParsedType typeBound);
   7161 
   7162   ObjCTypeParamList *actOnObjCTypeParamList(Scope *S, SourceLocation lAngleLoc,
   7163                                             ArrayRef<Decl *> typeParams,
   7164                                             SourceLocation rAngleLoc);
   7165   void popObjCTypeParamList(Scope *S, ObjCTypeParamList *typeParamList);
   7166 
   7167   Decl *ActOnStartClassInterface(Scope *S,
   7168                                  SourceLocation AtInterfaceLoc,
   7169                                  IdentifierInfo *ClassName,
   7170                                  SourceLocation ClassLoc,
   7171                                  ObjCTypeParamList *typeParamList,
   7172                                  IdentifierInfo *SuperName,
   7173                                  SourceLocation SuperLoc,
   7174                                  ArrayRef<ParsedType> SuperTypeArgs,
   7175                                  SourceRange SuperTypeArgsRange,
   7176                                  Decl * const *ProtoRefs,
   7177                                  unsigned NumProtoRefs,
   7178                                  const SourceLocation *ProtoLocs,
   7179                                  SourceLocation EndProtoLoc,
   7180                                  AttributeList *AttrList);
   7181 
   7182   void ActOnSuperClassOfClassInterface(Scope *S,
   7183                                        SourceLocation AtInterfaceLoc,
   7184                                        ObjCInterfaceDecl *IDecl,
   7185                                        IdentifierInfo *ClassName,
   7186                                        SourceLocation ClassLoc,
   7187                                        IdentifierInfo *SuperName,
   7188                                        SourceLocation SuperLoc,
   7189                                        ArrayRef<ParsedType> SuperTypeArgs,
   7190                                        SourceRange SuperTypeArgsRange);
   7191 
   7192   void ActOnTypedefedProtocols(SmallVectorImpl<Decl *> &ProtocolRefs,
   7193                                IdentifierInfo *SuperName,
   7194                                SourceLocation SuperLoc);
   7195 
   7196   Decl *ActOnCompatibilityAlias(
   7197                     SourceLocation AtCompatibilityAliasLoc,
   7198                     IdentifierInfo *AliasName,  SourceLocation AliasLocation,
   7199                     IdentifierInfo *ClassName, SourceLocation ClassLocation);
   7200 
   7201   bool CheckForwardProtocolDeclarationForCircularDependency(
   7202     IdentifierInfo *PName,
   7203     SourceLocation &PLoc, SourceLocation PrevLoc,
   7204     const ObjCList<ObjCProtocolDecl> &PList);
   7205 
   7206   Decl *ActOnStartProtocolInterface(
   7207                     SourceLocation AtProtoInterfaceLoc,
   7208                     IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
   7209                     Decl * const *ProtoRefNames, unsigned NumProtoRefs,
   7210                     const SourceLocation *ProtoLocs,
   7211                     SourceLocation EndProtoLoc,
   7212                     AttributeList *AttrList);
   7213 
   7214   Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
   7215                                     IdentifierInfo *ClassName,
   7216                                     SourceLocation ClassLoc,
   7217                                     ObjCTypeParamList *typeParamList,
   7218                                     IdentifierInfo *CategoryName,
   7219                                     SourceLocation CategoryLoc,
   7220                                     Decl * const *ProtoRefs,
   7221                                     unsigned NumProtoRefs,
   7222                                     const SourceLocation *ProtoLocs,
   7223                                     SourceLocation EndProtoLoc);
   7224 
   7225   Decl *ActOnStartClassImplementation(
   7226                     SourceLocation AtClassImplLoc,
   7227                     IdentifierInfo *ClassName, SourceLocation ClassLoc,
   7228                     IdentifierInfo *SuperClassname,
   7229                     SourceLocation SuperClassLoc);
   7230 
   7231   Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc,
   7232                                          IdentifierInfo *ClassName,
   7233                                          SourceLocation ClassLoc,
   7234                                          IdentifierInfo *CatName,
   7235                                          SourceLocation CatLoc);
   7236 
   7237   DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl,
   7238                                                ArrayRef<Decl *> Decls);
   7239 
   7240   DeclGroupPtrTy ActOnForwardClassDeclaration(SourceLocation Loc,
   7241                    IdentifierInfo **IdentList,
   7242                    SourceLocation *IdentLocs,
   7243                    ArrayRef<ObjCTypeParamList *> TypeParamLists,
   7244                    unsigned NumElts);
   7245 
   7246   DeclGroupPtrTy ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc,
   7247                                         ArrayRef<IdentifierLocPair> IdentList,
   7248                                         AttributeList *attrList);
   7249 
   7250   void FindProtocolDeclaration(bool WarnOnDeclarations, bool ForObjCContainer,
   7251                                ArrayRef<IdentifierLocPair> ProtocolId,
   7252                                SmallVectorImpl<Decl *> &Protocols);
   7253 
   7254   /// Given a list of identifiers (and their locations), resolve the
   7255   /// names to either Objective-C protocol qualifiers or type
   7256   /// arguments, as appropriate.
   7257   void actOnObjCTypeArgsOrProtocolQualifiers(
   7258          Scope *S,
   7259          ParsedType baseType,
   7260          SourceLocation lAngleLoc,
   7261          ArrayRef<IdentifierInfo *> identifiers,
   7262          ArrayRef<SourceLocation> identifierLocs,
   7263          SourceLocation rAngleLoc,
   7264          SourceLocation &typeArgsLAngleLoc,
   7265          SmallVectorImpl<ParsedType> &typeArgs,
   7266          SourceLocation &typeArgsRAngleLoc,
   7267          SourceLocation &protocolLAngleLoc,
   7268          SmallVectorImpl<Decl *> &protocols,
   7269          SourceLocation &protocolRAngleLoc,
   7270          bool warnOnIncompleteProtocols);
   7271 
   7272   /// Build a an Objective-C protocol-qualified 'id' type where no
   7273   /// base type was specified.
   7274   TypeResult actOnObjCProtocolQualifierType(
   7275                SourceLocation lAngleLoc,
   7276                ArrayRef<Decl *> protocols,
   7277                ArrayRef<SourceLocation> protocolLocs,
   7278                SourceLocation rAngleLoc);
   7279 
   7280   /// Build a specialized and/or protocol-qualified Objective-C type.
   7281   TypeResult actOnObjCTypeArgsAndProtocolQualifiers(
   7282                Scope *S,
   7283                SourceLocation Loc,
   7284                ParsedType BaseType,
   7285                SourceLocation TypeArgsLAngleLoc,
   7286                ArrayRef<ParsedType> TypeArgs,
   7287                SourceLocation TypeArgsRAngleLoc,
   7288                SourceLocation ProtocolLAngleLoc,
   7289                ArrayRef<Decl *> Protocols,
   7290                ArrayRef<SourceLocation> ProtocolLocs,
   7291                SourceLocation ProtocolRAngleLoc);
   7292 
   7293   /// Build an Objective-C object pointer type.
   7294   QualType BuildObjCObjectType(QualType BaseType,
   7295                                SourceLocation Loc,
   7296                                SourceLocation TypeArgsLAngleLoc,
   7297                                ArrayRef<TypeSourceInfo *> TypeArgs,
   7298                                SourceLocation TypeArgsRAngleLoc,
   7299                                SourceLocation ProtocolLAngleLoc,
   7300                                ArrayRef<ObjCProtocolDecl *> Protocols,
   7301                                ArrayRef<SourceLocation> ProtocolLocs,
   7302                                SourceLocation ProtocolRAngleLoc,
   7303                                bool FailOnError = false);
   7304 
   7305   /// Check the application of the Objective-C '__kindof' qualifier to
   7306   /// the given type.
   7307   bool checkObjCKindOfType(QualType &type, SourceLocation loc);
   7308 
   7309   /// Ensure attributes are consistent with type.
   7310   /// \param [in, out] Attributes The attributes to check; they will
   7311   /// be modified to be consistent with \p PropertyTy.
   7312   void CheckObjCPropertyAttributes(Decl *PropertyPtrTy,
   7313                                    SourceLocation Loc,
   7314                                    unsigned &Attributes,
   7315                                    bool propertyInPrimaryClass);
   7316 
   7317   /// Process the specified property declaration and create decls for the
   7318   /// setters and getters as needed.
   7319   /// \param property The property declaration being processed
   7320   void ProcessPropertyDecl(ObjCPropertyDecl *property);
   7321 
   7322 
   7323   void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
   7324                                 ObjCPropertyDecl *SuperProperty,
   7325                                 const IdentifierInfo *Name,
   7326                                 bool OverridingProtocolProperty);
   7327 
   7328   void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
   7329                                         ObjCInterfaceDecl *ID);
   7330 
   7331   Decl *ActOnAtEnd(Scope *S, SourceRange AtEnd,
   7332                    ArrayRef<Decl *> allMethods = None,
   7333                    ArrayRef<DeclGroupPtrTy> allTUVars = None);
   7334 
   7335   Decl *ActOnProperty(Scope *S, SourceLocation AtLoc,
   7336                       SourceLocation LParenLoc,
   7337                       FieldDeclarator &FD, ObjCDeclSpec &ODS,
   7338                       Selector GetterSel, Selector SetterSel,
   7339                       tok::ObjCKeywordKind MethodImplKind,
   7340                       DeclContext *lexicalDC = nullptr);
   7341 
   7342   Decl *ActOnPropertyImplDecl(Scope *S,
   7343                               SourceLocation AtLoc,
   7344                               SourceLocation PropertyLoc,
   7345                               bool ImplKind,
   7346                               IdentifierInfo *PropertyId,
   7347                               IdentifierInfo *PropertyIvar,
   7348                               SourceLocation PropertyIvarLoc);
   7349 
   7350   enum ObjCSpecialMethodKind {
   7351     OSMK_None,
   7352     OSMK_Alloc,
   7353     OSMK_New,
   7354     OSMK_Copy,
   7355     OSMK_RetainingInit,
   7356     OSMK_NonRetainingInit
   7357   };
   7358 
   7359   struct ObjCArgInfo {
   7360     IdentifierInfo *Name;
   7361     SourceLocation NameLoc;
   7362     // The Type is null if no type was specified, and the DeclSpec is invalid
   7363     // in this case.
   7364     ParsedType Type;
   7365     ObjCDeclSpec DeclSpec;
   7366 
   7367     /// ArgAttrs - Attribute list for this argument.
   7368     AttributeList *ArgAttrs;
   7369   };
   7370 
   7371   Decl *ActOnMethodDeclaration(
   7372     Scope *S,
   7373     SourceLocation BeginLoc, // location of the + or -.
   7374     SourceLocation EndLoc,   // location of the ; or {.
   7375     tok::TokenKind MethodType,
   7376     ObjCDeclSpec &ReturnQT, ParsedType ReturnType,
   7377     ArrayRef<SourceLocation> SelectorLocs, Selector Sel,
   7378     // optional arguments. The number of types/arguments is obtained
   7379     // from the Sel.getNumArgs().
   7380     ObjCArgInfo *ArgInfo,
   7381     DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args
   7382     AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
   7383     bool isVariadic, bool MethodDefinition);
   7384 
   7385   ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel,
   7386                                               const ObjCObjectPointerType *OPT,
   7387                                               bool IsInstance);
   7388   ObjCMethodDecl *LookupMethodInObjectType(Selector Sel, QualType Ty,
   7389                                            bool IsInstance);
   7390 
   7391   bool CheckARCMethodDecl(ObjCMethodDecl *method);
   7392   bool inferObjCARCLifetime(ValueDecl *decl);
   7393 
   7394   ExprResult
   7395   HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
   7396                             Expr *BaseExpr,
   7397                             SourceLocation OpLoc,
   7398                             DeclarationName MemberName,
   7399                             SourceLocation MemberLoc,
   7400                             SourceLocation SuperLoc, QualType SuperType,
   7401                             bool Super);
   7402 
   7403   ExprResult
   7404   ActOnClassPropertyRefExpr(IdentifierInfo &receiverName,
   7405                             IdentifierInfo &propertyName,
   7406                             SourceLocation receiverNameLoc,
   7407                             SourceLocation propertyNameLoc);
   7408 
   7409   ObjCMethodDecl *tryCaptureObjCSelf(SourceLocation Loc);
   7410 
   7411   /// \brief Describes the kind of message expression indicated by a message
   7412   /// send that starts with an identifier.
   7413   enum ObjCMessageKind {
   7414     /// \brief The message is sent to 'super'.
   7415     ObjCSuperMessage,
   7416     /// \brief The message is an instance message.
   7417     ObjCInstanceMessage,
   7418     /// \brief The message is a class message, and the identifier is a type
   7419     /// name.
   7420     ObjCClassMessage
   7421   };
   7422 
   7423   ObjCMessageKind getObjCMessageKind(Scope *S,
   7424                                      IdentifierInfo *Name,
   7425                                      SourceLocation NameLoc,
   7426                                      bool IsSuper,
   7427                                      bool HasTrailingDot,
   7428                                      ParsedType &ReceiverType);
   7429 
   7430   ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc,
   7431                                Selector Sel,
   7432                                SourceLocation LBracLoc,
   7433                                ArrayRef<SourceLocation> SelectorLocs,
   7434                                SourceLocation RBracLoc,
   7435                                MultiExprArg Args);
   7436 
   7437   ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo,
   7438                                QualType ReceiverType,
   7439                                SourceLocation SuperLoc,
   7440                                Selector Sel,
   7441                                ObjCMethodDecl *Method,
   7442                                SourceLocation LBracLoc,
   7443                                ArrayRef<SourceLocation> SelectorLocs,
   7444                                SourceLocation RBracLoc,
   7445                                MultiExprArg Args,
   7446                                bool isImplicit = false);
   7447 
   7448   ExprResult BuildClassMessageImplicit(QualType ReceiverType,
   7449                                        bool isSuperReceiver,
   7450                                        SourceLocation Loc,
   7451                                        Selector Sel,
   7452                                        ObjCMethodDecl *Method,
   7453                                        MultiExprArg Args);
   7454 
   7455   ExprResult ActOnClassMessage(Scope *S,
   7456                                ParsedType Receiver,
   7457                                Selector Sel,
   7458                                SourceLocation LBracLoc,
   7459                                ArrayRef<SourceLocation> SelectorLocs,
   7460                                SourceLocation RBracLoc,
   7461                                MultiExprArg Args);
   7462 
   7463   ExprResult BuildInstanceMessage(Expr *Receiver,
   7464                                   QualType ReceiverType,
   7465                                   SourceLocation SuperLoc,
   7466                                   Selector Sel,
   7467                                   ObjCMethodDecl *Method,
   7468                                   SourceLocation LBracLoc,
   7469                                   ArrayRef<SourceLocation> SelectorLocs,
   7470                                   SourceLocation RBracLoc,
   7471                                   MultiExprArg Args,
   7472                                   bool isImplicit = false);
   7473 
   7474   ExprResult BuildInstanceMessageImplicit(Expr *Receiver,
   7475                                           QualType ReceiverType,
   7476                                           SourceLocation Loc,
   7477                                           Selector Sel,
   7478                                           ObjCMethodDecl *Method,
   7479                                           MultiExprArg Args);
   7480 
   7481   ExprResult ActOnInstanceMessage(Scope *S,
   7482                                   Expr *Receiver,
   7483                                   Selector Sel,
   7484                                   SourceLocation LBracLoc,
   7485                                   ArrayRef<SourceLocation> SelectorLocs,
   7486                                   SourceLocation RBracLoc,
   7487                                   MultiExprArg Args);
   7488 
   7489   ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc,
   7490                                   ObjCBridgeCastKind Kind,
   7491                                   SourceLocation BridgeKeywordLoc,
   7492                                   TypeSourceInfo *TSInfo,
   7493                                   Expr *SubExpr);
   7494 
   7495   ExprResult ActOnObjCBridgedCast(Scope *S,
   7496                                   SourceLocation LParenLoc,
   7497                                   ObjCBridgeCastKind Kind,
   7498                                   SourceLocation BridgeKeywordLoc,
   7499                                   ParsedType Type,
   7500                                   SourceLocation RParenLoc,
   7501                                   Expr *SubExpr);
   7502 
   7503   void CheckTollFreeBridgeCast(QualType castType, Expr *castExpr);
   7504 
   7505   void CheckObjCBridgeRelatedCast(QualType castType, Expr *castExpr);
   7506 
   7507   bool CheckTollFreeBridgeStaticCast(QualType castType, Expr *castExpr,
   7508                                      CastKind &Kind);
   7509 
   7510   bool checkObjCBridgeRelatedComponents(SourceLocation Loc,
   7511                                         QualType DestType, QualType SrcType,
   7512                                         ObjCInterfaceDecl *&RelatedClass,
   7513                                         ObjCMethodDecl *&ClassMethod,
   7514                                         ObjCMethodDecl *&InstanceMethod,
   7515                                         TypedefNameDecl *&TDNDecl,
   7516                                         bool CfToNs);
   7517 
   7518   bool CheckObjCBridgeRelatedConversions(SourceLocation Loc,
   7519                                          QualType DestType, QualType SrcType,
   7520                                          Expr *&SrcExpr);
   7521 
   7522   bool ConversionToObjCStringLiteralCheck(QualType DstType, Expr *&SrcExpr);
   7523 
   7524   bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall);
   7525 
   7526   /// \brief Check whether the given new method is a valid override of the
   7527   /// given overridden method, and set any properties that should be inherited.
   7528   void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod,
   7529                                const ObjCMethodDecl *Overridden);
   7530 
   7531   /// \brief Describes the compatibility of a result type with its method.
   7532   enum ResultTypeCompatibilityKind {
   7533     RTC_Compatible,
   7534     RTC_Incompatible,
   7535     RTC_Unknown
   7536   };
   7537 
   7538   void CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod,
   7539                                 ObjCInterfaceDecl *CurrentClass,
   7540                                 ResultTypeCompatibilityKind RTC);
   7541 
   7542   enum PragmaOptionsAlignKind {
   7543     POAK_Native,  // #pragma options align=native
   7544     POAK_Natural, // #pragma options align=natural
   7545     POAK_Packed,  // #pragma options align=packed
   7546     POAK_Power,   // #pragma options align=power
   7547     POAK_Mac68k,  // #pragma options align=mac68k
   7548     POAK_Reset    // #pragma options align=reset
   7549   };
   7550 
   7551   /// ActOnPragmaOptionsAlign - Called on well formed \#pragma options align.
   7552   void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
   7553                                SourceLocation PragmaLoc);
   7554 
   7555   enum PragmaPackKind {
   7556     PPK_Default, // #pragma pack([n])
   7557     PPK_Show,    // #pragma pack(show), only supported by MSVC.
   7558     PPK_Push,    // #pragma pack(push, [identifier], [n])
   7559     PPK_Pop      // #pragma pack(pop, [identifier], [n])
   7560   };
   7561 
   7562   enum PragmaMSStructKind {
   7563     PMSST_OFF,  // #pragms ms_struct off
   7564     PMSST_ON    // #pragms ms_struct on
   7565   };
   7566 
   7567   enum PragmaMSCommentKind {
   7568     PCK_Unknown,
   7569     PCK_Linker,   // #pragma comment(linker, ...)
   7570     PCK_Lib,      // #pragma comment(lib, ...)
   7571     PCK_Compiler, // #pragma comment(compiler, ...)
   7572     PCK_ExeStr,   // #pragma comment(exestr, ...)
   7573     PCK_User      // #pragma comment(user, ...)
   7574   };
   7575 
   7576   /// ActOnPragmaPack - Called on well formed \#pragma pack(...).
   7577   void ActOnPragmaPack(PragmaPackKind Kind,
   7578                        IdentifierInfo *Name,
   7579                        Expr *Alignment,
   7580                        SourceLocation PragmaLoc,
   7581                        SourceLocation LParenLoc,
   7582                        SourceLocation RParenLoc);
   7583 
   7584   /// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off].
   7585   void ActOnPragmaMSStruct(PragmaMSStructKind Kind);
   7586 
   7587   /// ActOnPragmaMSComment - Called on well formed
   7588   /// \#pragma comment(kind, "arg").
   7589   void ActOnPragmaMSComment(PragmaMSCommentKind Kind, StringRef Arg);
   7590 
   7591   /// ActOnPragmaMSPointersToMembers - called on well formed \#pragma
   7592   /// pointers_to_members(representation method[, general purpose
   7593   /// representation]).
   7594   void ActOnPragmaMSPointersToMembers(
   7595       LangOptions::PragmaMSPointersToMembersKind Kind,
   7596       SourceLocation PragmaLoc);
   7597 
   7598   /// \brief Called on well formed \#pragma vtordisp().
   7599   void ActOnPragmaMSVtorDisp(PragmaVtorDispKind Kind, SourceLocation PragmaLoc,
   7600                              MSVtorDispAttr::Mode Value);
   7601 
   7602   enum PragmaSectionKind {
   7603     PSK_DataSeg,
   7604     PSK_BSSSeg,
   7605     PSK_ConstSeg,
   7606     PSK_CodeSeg,
   7607   };
   7608 
   7609   bool UnifySection(StringRef SectionName,
   7610                     int SectionFlags,
   7611                     DeclaratorDecl *TheDecl);
   7612   bool UnifySection(StringRef SectionName,
   7613                     int SectionFlags,
   7614                     SourceLocation PragmaSectionLocation);
   7615 
   7616   /// \brief Called on well formed \#pragma bss_seg/data_seg/const_seg/code_seg.
   7617   void ActOnPragmaMSSeg(SourceLocation PragmaLocation,
   7618                         PragmaMsStackAction Action,
   7619                         llvm::StringRef StackSlotLabel,
   7620                         StringLiteral *SegmentName,
   7621                         llvm::StringRef PragmaName);
   7622 
   7623   /// \brief Called on well formed \#pragma section().
   7624   void ActOnPragmaMSSection(SourceLocation PragmaLocation,
   7625                             int SectionFlags, StringLiteral *SegmentName);
   7626 
   7627   /// \brief Called on well-formed \#pragma init_seg().
   7628   void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation,
   7629                             StringLiteral *SegmentName);
   7630 
   7631   /// ActOnPragmaDetectMismatch - Call on well-formed \#pragma detect_mismatch
   7632   void ActOnPragmaDetectMismatch(StringRef Name, StringRef Value);
   7633 
   7634   /// ActOnPragmaUnused - Called on well-formed '\#pragma unused'.
   7635   void ActOnPragmaUnused(const Token &Identifier,
   7636                          Scope *curScope,
   7637                          SourceLocation PragmaLoc);
   7638 
   7639   /// ActOnPragmaVisibility - Called on well formed \#pragma GCC visibility... .
   7640   void ActOnPragmaVisibility(const IdentifierInfo* VisType,
   7641                              SourceLocation PragmaLoc);
   7642 
   7643   NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II,
   7644                                  SourceLocation Loc);
   7645   void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W);
   7646 
   7647   /// ActOnPragmaWeakID - Called on well formed \#pragma weak ident.
   7648   void ActOnPragmaWeakID(IdentifierInfo* WeakName,
   7649                          SourceLocation PragmaLoc,
   7650                          SourceLocation WeakNameLoc);
   7651 
   7652   /// ActOnPragmaRedefineExtname - Called on well formed
   7653   /// \#pragma redefine_extname oldname newname.
   7654   void ActOnPragmaRedefineExtname(IdentifierInfo* WeakName,
   7655                                   IdentifierInfo* AliasName,
   7656                                   SourceLocation PragmaLoc,
   7657                                   SourceLocation WeakNameLoc,
   7658                                   SourceLocation AliasNameLoc);
   7659 
   7660   /// ActOnPragmaWeakAlias - Called on well formed \#pragma weak ident = ident.
   7661   void ActOnPragmaWeakAlias(IdentifierInfo* WeakName,
   7662                             IdentifierInfo* AliasName,
   7663                             SourceLocation PragmaLoc,
   7664                             SourceLocation WeakNameLoc,
   7665                             SourceLocation AliasNameLoc);
   7666 
   7667   /// ActOnPragmaFPContract - Called on well formed
   7668   /// \#pragma {STDC,OPENCL} FP_CONTRACT
   7669   void ActOnPragmaFPContract(tok::OnOffSwitch OOS);
   7670 
   7671   /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to
   7672   /// a the record decl, to handle '\#pragma pack' and '\#pragma options align'.
   7673   void AddAlignmentAttributesForRecord(RecordDecl *RD);
   7674 
   7675   /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record.
   7676   void AddMsStructLayoutForRecord(RecordDecl *RD);
   7677 
   7678   /// FreePackedContext - Deallocate and null out PackContext.
   7679   void FreePackedContext();
   7680 
   7681   /// PushNamespaceVisibilityAttr - Note that we've entered a
   7682   /// namespace with a visibility attribute.
   7683   void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr,
   7684                                    SourceLocation Loc);
   7685 
   7686   /// AddPushedVisibilityAttribute - If '\#pragma GCC visibility' was used,
   7687   /// add an appropriate visibility attribute.
   7688   void AddPushedVisibilityAttribute(Decl *RD);
   7689 
   7690   /// PopPragmaVisibility - Pop the top element of the visibility stack; used
   7691   /// for '\#pragma GCC visibility' and visibility attributes on namespaces.
   7692   void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc);
   7693 
   7694   /// FreeVisContext - Deallocate and null out VisContext.
   7695   void FreeVisContext();
   7696 
   7697   /// AddCFAuditedAttribute - Check whether we're currently within
   7698   /// '\#pragma clang arc_cf_code_audited' and, if so, consider adding
   7699   /// the appropriate attribute.
   7700   void AddCFAuditedAttribute(Decl *D);
   7701 
   7702   /// \brief Called on well formed \#pragma clang optimize.
   7703   void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc);
   7704 
   7705   /// \brief Get the location for the currently active "\#pragma clang optimize
   7706   /// off". If this location is invalid, then the state of the pragma is "on".
   7707   SourceLocation getOptimizeOffPragmaLocation() const {
   7708     return OptimizeOffPragmaLocation;
   7709   }
   7710 
   7711   /// \brief Only called on function definitions; if there is a pragma in scope
   7712   /// with the effect of a range-based optnone, consider marking the function
   7713   /// with attribute optnone.
   7714   void AddRangeBasedOptnone(FunctionDecl *FD);
   7715 
   7716   /// \brief Adds the 'optnone' attribute to the function declaration if there
   7717   /// are no conflicts; Loc represents the location causing the 'optnone'
   7718   /// attribute to be added (usually because of a pragma).
   7719   void AddOptnoneAttributeIfNoConflicts(FunctionDecl *FD, SourceLocation Loc);
   7720 
   7721   /// AddAlignedAttr - Adds an aligned attribute to a particular declaration.
   7722   void AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E,
   7723                       unsigned SpellingListIndex, bool IsPackExpansion);
   7724   void AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *T,
   7725                       unsigned SpellingListIndex, bool IsPackExpansion);
   7726 
   7727   /// AddAssumeAlignedAttr - Adds an assume_aligned attribute to a particular
   7728   /// declaration.
   7729   void AddAssumeAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E, Expr *OE,
   7730                             unsigned SpellingListIndex);
   7731 
   7732   /// AddAlignValueAttr - Adds an align_value attribute to a particular
   7733   /// declaration.
   7734   void AddAlignValueAttr(SourceRange AttrRange, Decl *D, Expr *E,
   7735                          unsigned SpellingListIndex);
   7736 
   7737   /// AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular
   7738   /// declaration.
   7739   void AddLaunchBoundsAttr(SourceRange AttrRange, Decl *D, Expr *MaxThreads,
   7740                            Expr *MinBlocks, unsigned SpellingListIndex);
   7741 
   7742   //===--------------------------------------------------------------------===//
   7743   // C++ Coroutines TS
   7744   //
   7745   ExprResult ActOnCoawaitExpr(Scope *S, SourceLocation KwLoc, Expr *E);
   7746   ExprResult ActOnCoyieldExpr(Scope *S, SourceLocation KwLoc, Expr *E);
   7747   StmtResult ActOnCoreturnStmt(SourceLocation KwLoc, Expr *E);
   7748 
   7749   ExprResult BuildCoawaitExpr(SourceLocation KwLoc, Expr *E);
   7750   ExprResult BuildCoyieldExpr(SourceLocation KwLoc, Expr *E);
   7751   StmtResult BuildCoreturnStmt(SourceLocation KwLoc, Expr *E);
   7752 
   7753   void CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body);
   7754 
   7755   //===--------------------------------------------------------------------===//
   7756   // OpenMP directives and clauses.
   7757   //
   7758 private:
   7759   void *VarDataSharingAttributesStack;
   7760   /// \brief Initialization of data-sharing attributes stack.
   7761   void InitDataSharingAttributesStack();
   7762   void DestroyDataSharingAttributesStack();
   7763   ExprResult VerifyPositiveIntegerConstantInClause(Expr *Op,
   7764                                                    OpenMPClauseKind CKind);
   7765 public:
   7766   /// \brief Return true if the provided declaration \a VD should be captured by
   7767   /// reference in the provided scope \a RSI. This will take into account the
   7768   /// semantics of the directive and associated clauses.
   7769   bool IsOpenMPCapturedByRef(VarDecl *VD,
   7770                              const sema::CapturedRegionScopeInfo *RSI);
   7771 
   7772   /// \brief Check if the specified variable is used in one of the private
   7773   /// clauses (private, firstprivate, lastprivate, reduction etc.) in OpenMP
   7774   /// constructs.
   7775   bool IsOpenMPCapturedVar(VarDecl *VD);
   7776 
   7777   /// \brief Check if the specified variable is used in 'private' clause.
   7778   /// \param Level Relative level of nested OpenMP construct for that the check
   7779   /// is performed.
   7780   bool isOpenMPPrivateVar(VarDecl *VD, unsigned Level);
   7781 
   7782   /// \brief Check if the specified variable is captured  by 'target' directive.
   7783   /// \param Level Relative level of nested OpenMP construct for that the check
   7784   /// is performed.
   7785   bool isOpenMPTargetCapturedVar(VarDecl *VD, unsigned Level);
   7786 
   7787   ExprResult PerformOpenMPImplicitIntegerConversion(SourceLocation OpLoc,
   7788                                                     Expr *Op);
   7789   /// \brief Called on start of new data sharing attribute block.
   7790   void StartOpenMPDSABlock(OpenMPDirectiveKind K,
   7791                            const DeclarationNameInfo &DirName, Scope *CurScope,
   7792                            SourceLocation Loc);
   7793   /// \brief Start analysis of clauses.
   7794   void StartOpenMPClause(OpenMPClauseKind K);
   7795   /// \brief End analysis of clauses.
   7796   void EndOpenMPClause();
   7797   /// \brief Called on end of data sharing attribute block.
   7798   void EndOpenMPDSABlock(Stmt *CurDirective);
   7799 
   7800   /// \brief Check if the current region is an OpenMP loop region and if it is,
   7801   /// mark loop control variable, used in \p Init for loop initialization, as
   7802   /// private by default.
   7803   /// \param Init First part of the for loop.
   7804   void ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init);
   7805 
   7806   // OpenMP directives and clauses.
   7807   /// \brief Called on correct id-expression from the '#pragma omp
   7808   /// threadprivate'.
   7809   ExprResult ActOnOpenMPIdExpression(Scope *CurScope,
   7810                                      CXXScopeSpec &ScopeSpec,
   7811                                      const DeclarationNameInfo &Id);
   7812   /// \brief Called on well-formed '#pragma omp threadprivate'.
   7813   DeclGroupPtrTy ActOnOpenMPThreadprivateDirective(
   7814                                      SourceLocation Loc,
   7815                                      ArrayRef<Expr *> VarList);
   7816   /// \brief Builds a new OpenMPThreadPrivateDecl and checks its correctness.
   7817   OMPThreadPrivateDecl *CheckOMPThreadPrivateDecl(
   7818                                      SourceLocation Loc,
   7819                                      ArrayRef<Expr *> VarList);
   7820 
   7821   /// \brief Initialization of captured region for OpenMP region.
   7822   void ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope);
   7823   /// \brief End of OpenMP region.
   7824   ///
   7825   /// \param S Statement associated with the current OpenMP region.
   7826   /// \param Clauses List of clauses for the current OpenMP region.
   7827   ///
   7828   /// \returns Statement for finished OpenMP region.
   7829   StmtResult ActOnOpenMPRegionEnd(StmtResult S, ArrayRef<OMPClause *> Clauses);
   7830   StmtResult ActOnOpenMPExecutableDirective(
   7831       OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName,
   7832       OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses,
   7833       Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc);
   7834   /// \brief Called on well-formed '\#pragma omp parallel' after parsing
   7835   /// of the  associated statement.
   7836   StmtResult ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses,
   7837                                           Stmt *AStmt,
   7838                                           SourceLocation StartLoc,
   7839                                           SourceLocation EndLoc);
   7840   /// \brief Called on well-formed '\#pragma omp simd' after parsing
   7841   /// of the associated statement.
   7842   StmtResult ActOnOpenMPSimdDirective(
   7843       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
   7844       SourceLocation EndLoc,
   7845       llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA);
   7846   /// \brief Called on well-formed '\#pragma omp for' after parsing
   7847   /// of the associated statement.
   7848   StmtResult ActOnOpenMPForDirective(
   7849       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
   7850       SourceLocation EndLoc,
   7851       llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA);
   7852   /// \brief Called on well-formed '\#pragma omp for simd' after parsing
   7853   /// of the associated statement.
   7854   StmtResult ActOnOpenMPForSimdDirective(
   7855       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
   7856       SourceLocation EndLoc,
   7857       llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA);
   7858   /// \brief Called on well-formed '\#pragma omp sections' after parsing
   7859   /// of the associated statement.
   7860   StmtResult ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses,
   7861                                           Stmt *AStmt, SourceLocation StartLoc,
   7862                                           SourceLocation EndLoc);
   7863   /// \brief Called on well-formed '\#pragma omp section' after parsing of the
   7864   /// associated statement.
   7865   StmtResult ActOnOpenMPSectionDirective(Stmt *AStmt, SourceLocation StartLoc,
   7866                                          SourceLocation EndLoc);
   7867   /// \brief Called on well-formed '\#pragma omp single' after parsing of the
   7868   /// associated statement.
   7869   StmtResult ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses,
   7870                                         Stmt *AStmt, SourceLocation StartLoc,
   7871                                         SourceLocation EndLoc);
   7872   /// \brief Called on well-formed '\#pragma omp master' after parsing of the
   7873   /// associated statement.
   7874   StmtResult ActOnOpenMPMasterDirective(Stmt *AStmt, SourceLocation StartLoc,
   7875                                         SourceLocation EndLoc);
   7876   /// \brief Called on well-formed '\#pragma omp critical' after parsing of the
   7877   /// associated statement.
   7878   StmtResult ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName,
   7879                                           ArrayRef<OMPClause *> Clauses,
   7880                                           Stmt *AStmt, SourceLocation StartLoc,
   7881                                           SourceLocation EndLoc);
   7882   /// \brief Called on well-formed '\#pragma omp parallel for' after parsing
   7883   /// of the  associated statement.
   7884   StmtResult ActOnOpenMPParallelForDirective(
   7885       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
   7886       SourceLocation EndLoc,
   7887       llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA);
   7888   /// \brief Called on well-formed '\#pragma omp parallel for simd' after
   7889   /// parsing of the  associated statement.
   7890   StmtResult ActOnOpenMPParallelForSimdDirective(
   7891       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
   7892       SourceLocation EndLoc,
   7893       llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA);
   7894   /// \brief Called on well-formed '\#pragma omp parallel sections' after
   7895   /// parsing of the  associated statement.
   7896   StmtResult ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses,
   7897                                                   Stmt *AStmt,
   7898                                                   SourceLocation StartLoc,
   7899                                                   SourceLocation EndLoc);
   7900   /// \brief Called on well-formed '\#pragma omp task' after parsing of the
   7901   /// associated statement.
   7902   StmtResult ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses,
   7903                                       Stmt *AStmt, SourceLocation StartLoc,
   7904                                       SourceLocation EndLoc);
   7905   /// \brief Called on well-formed '\#pragma omp taskyield'.
   7906   StmtResult ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc,
   7907                                            SourceLocation EndLoc);
   7908   /// \brief Called on well-formed '\#pragma omp barrier'.
   7909   StmtResult ActOnOpenMPBarrierDirective(SourceLocation StartLoc,
   7910                                          SourceLocation EndLoc);
   7911   /// \brief Called on well-formed '\#pragma omp taskwait'.
   7912   StmtResult ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc,
   7913                                           SourceLocation EndLoc);
   7914   /// \brief Called on well-formed '\#pragma omp taskgroup'.
   7915   StmtResult ActOnOpenMPTaskgroupDirective(Stmt *AStmt, SourceLocation StartLoc,
   7916                                            SourceLocation EndLoc);
   7917   /// \brief Called on well-formed '\#pragma omp flush'.
   7918   StmtResult ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses,
   7919                                        SourceLocation StartLoc,
   7920                                        SourceLocation EndLoc);
   7921   /// \brief Called on well-formed '\#pragma omp ordered' after parsing of the
   7922   /// associated statement.
   7923   StmtResult ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses,
   7924                                          Stmt *AStmt, SourceLocation StartLoc,
   7925                                          SourceLocation EndLoc);
   7926   /// \brief Called on well-formed '\#pragma omp atomic' after parsing of the
   7927   /// associated statement.
   7928   StmtResult ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses,
   7929                                         Stmt *AStmt, SourceLocation StartLoc,
   7930                                         SourceLocation EndLoc);
   7931   /// \brief Called on well-formed '\#pragma omp target' after parsing of the
   7932   /// associated statement.
   7933   StmtResult ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses,
   7934                                         Stmt *AStmt, SourceLocation StartLoc,
   7935                                         SourceLocation EndLoc);
   7936   /// \brief Called on well-formed '\#pragma omp target data' after parsing of
   7937   /// the associated statement.
   7938   StmtResult ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses,
   7939                                             Stmt *AStmt, SourceLocation StartLoc,
   7940                                             SourceLocation EndLoc);
   7941   /// \brief Called on well-formed '\#pragma omp teams' after parsing of the
   7942   /// associated statement.
   7943   StmtResult ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses,
   7944                                        Stmt *AStmt, SourceLocation StartLoc,
   7945                                        SourceLocation EndLoc);
   7946   /// \brief Called on well-formed '\#pragma omp cancellation point'.
   7947   StmtResult
   7948   ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc,
   7949                                         SourceLocation EndLoc,
   7950                                         OpenMPDirectiveKind CancelRegion);
   7951   /// \brief Called on well-formed '\#pragma omp cancel'.
   7952   StmtResult ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses,
   7953                                         SourceLocation StartLoc,
   7954                                         SourceLocation EndLoc,
   7955                                         OpenMPDirectiveKind CancelRegion);
   7956   /// \brief Called on well-formed '\#pragma omp taskloop' after parsing of the
   7957   /// associated statement.
   7958   StmtResult ActOnOpenMPTaskLoopDirective(
   7959       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
   7960       SourceLocation EndLoc,
   7961       llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA);
   7962   /// \brief Called on well-formed '\#pragma omp taskloop simd' after parsing of
   7963   /// the associated statement.
   7964   StmtResult ActOnOpenMPTaskLoopSimdDirective(
   7965       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
   7966       SourceLocation EndLoc,
   7967       llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA);
   7968   /// \brief Called on well-formed '\#pragma omp distribute' after parsing
   7969   /// of the associated statement.
   7970   StmtResult ActOnOpenMPDistributeDirective(
   7971       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
   7972       SourceLocation EndLoc,
   7973       llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA);
   7974 
   7975   OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind,
   7976                                          Expr *Expr,
   7977                                          SourceLocation StartLoc,
   7978                                          SourceLocation LParenLoc,
   7979                                          SourceLocation EndLoc);
   7980   /// \brief Called on well-formed 'if' clause.
   7981   OMPClause *ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier,
   7982                                  Expr *Condition, SourceLocation StartLoc,
   7983                                  SourceLocation LParenLoc,
   7984                                  SourceLocation NameModifierLoc,
   7985                                  SourceLocation ColonLoc,
   7986                                  SourceLocation EndLoc);
   7987   /// \brief Called on well-formed 'final' clause.
   7988   OMPClause *ActOnOpenMPFinalClause(Expr *Condition, SourceLocation StartLoc,
   7989                                     SourceLocation LParenLoc,
   7990                                     SourceLocation EndLoc);
   7991   /// \brief Called on well-formed 'num_threads' clause.
   7992   OMPClause *ActOnOpenMPNumThreadsClause(Expr *NumThreads,
   7993                                          SourceLocation StartLoc,
   7994                                          SourceLocation LParenLoc,
   7995                                          SourceLocation EndLoc);
   7996   /// \brief Called on well-formed 'safelen' clause.
   7997   OMPClause *ActOnOpenMPSafelenClause(Expr *Length,
   7998                                       SourceLocation StartLoc,
   7999                                       SourceLocation LParenLoc,
   8000                                       SourceLocation EndLoc);
   8001   /// \brief Called on well-formed 'simdlen' clause.
   8002   OMPClause *ActOnOpenMPSimdlenClause(Expr *Length, SourceLocation StartLoc,
   8003                                       SourceLocation LParenLoc,
   8004                                       SourceLocation EndLoc);
   8005   /// \brief Called on well-formed 'collapse' clause.
   8006   OMPClause *ActOnOpenMPCollapseClause(Expr *NumForLoops,
   8007                                        SourceLocation StartLoc,
   8008                                        SourceLocation LParenLoc,
   8009                                        SourceLocation EndLoc);
   8010   /// \brief Called on well-formed 'ordered' clause.
   8011   OMPClause *
   8012   ActOnOpenMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc,
   8013                            SourceLocation LParenLoc = SourceLocation(),
   8014                            Expr *NumForLoops = nullptr);
   8015   /// \brief Called on well-formed 'grainsize' clause.
   8016   OMPClause *ActOnOpenMPGrainsizeClause(Expr *Size, SourceLocation StartLoc,
   8017                                         SourceLocation LParenLoc,
   8018                                         SourceLocation EndLoc);
   8019   /// \brief Called on well-formed 'num_tasks' clause.
   8020   OMPClause *ActOnOpenMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
   8021                                        SourceLocation LParenLoc,
   8022                                        SourceLocation EndLoc);
   8023   /// \brief Called on well-formed 'hint' clause.
   8024   OMPClause *ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc,
   8025                                    SourceLocation LParenLoc,
   8026                                    SourceLocation EndLoc);
   8027 
   8028   OMPClause *ActOnOpenMPSimpleClause(OpenMPClauseKind Kind,
   8029                                      unsigned Argument,
   8030                                      SourceLocation ArgumentLoc,
   8031                                      SourceLocation StartLoc,
   8032                                      SourceLocation LParenLoc,
   8033                                      SourceLocation EndLoc);
   8034   /// \brief Called on well-formed 'default' clause.
   8035   OMPClause *ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind,
   8036                                       SourceLocation KindLoc,
   8037                                       SourceLocation StartLoc,
   8038                                       SourceLocation LParenLoc,
   8039                                       SourceLocation EndLoc);
   8040   /// \brief Called on well-formed 'proc_bind' clause.
   8041   OMPClause *ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind,
   8042                                        SourceLocation KindLoc,
   8043                                        SourceLocation StartLoc,
   8044                                        SourceLocation LParenLoc,
   8045                                        SourceLocation EndLoc);
   8046 
   8047   OMPClause *ActOnOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind,
   8048                                                 unsigned Argument, Expr *Expr,
   8049                                                 SourceLocation StartLoc,
   8050                                                 SourceLocation LParenLoc,
   8051                                                 SourceLocation ArgumentLoc,
   8052                                                 SourceLocation DelimLoc,
   8053                                                 SourceLocation EndLoc);
   8054   /// \brief Called on well-formed 'schedule' clause.
   8055   OMPClause *ActOnOpenMPScheduleClause(OpenMPScheduleClauseKind Kind,
   8056                                        Expr *ChunkSize, SourceLocation StartLoc,
   8057                                        SourceLocation LParenLoc,
   8058                                        SourceLocation KindLoc,
   8059                                        SourceLocation CommaLoc,
   8060                                        SourceLocation EndLoc);
   8061 
   8062   OMPClause *ActOnOpenMPClause(OpenMPClauseKind Kind, SourceLocation StartLoc,
   8063                                SourceLocation EndLoc);
   8064   /// \brief Called on well-formed 'nowait' clause.
   8065   OMPClause *ActOnOpenMPNowaitClause(SourceLocation StartLoc,
   8066                                      SourceLocation EndLoc);
   8067   /// \brief Called on well-formed 'untied' clause.
   8068   OMPClause *ActOnOpenMPUntiedClause(SourceLocation StartLoc,
   8069                                      SourceLocation EndLoc);
   8070   /// \brief Called on well-formed 'mergeable' clause.
   8071   OMPClause *ActOnOpenMPMergeableClause(SourceLocation StartLoc,
   8072                                         SourceLocation EndLoc);
   8073   /// \brief Called on well-formed 'read' clause.
   8074   OMPClause *ActOnOpenMPReadClause(SourceLocation StartLoc,
   8075                                    SourceLocation EndLoc);
   8076   /// \brief Called on well-formed 'write' clause.
   8077   OMPClause *ActOnOpenMPWriteClause(SourceLocation StartLoc,
   8078                                     SourceLocation EndLoc);
   8079   /// \brief Called on well-formed 'update' clause.
   8080   OMPClause *ActOnOpenMPUpdateClause(SourceLocation StartLoc,
   8081                                      SourceLocation EndLoc);
   8082   /// \brief Called on well-formed 'capture' clause.
   8083   OMPClause *ActOnOpenMPCaptureClause(SourceLocation StartLoc,
   8084                                       SourceLocation EndLoc);
   8085   /// \brief Called on well-formed 'seq_cst' clause.
   8086   OMPClause *ActOnOpenMPSeqCstClause(SourceLocation StartLoc,
   8087                                      SourceLocation EndLoc);
   8088   /// \brief Called on well-formed 'threads' clause.
   8089   OMPClause *ActOnOpenMPThreadsClause(SourceLocation StartLoc,
   8090                                       SourceLocation EndLoc);
   8091   /// \brief Called on well-formed 'simd' clause.
   8092   OMPClause *ActOnOpenMPSIMDClause(SourceLocation StartLoc,
   8093                                    SourceLocation EndLoc);
   8094   /// \brief Called on well-formed 'nogroup' clause.
   8095   OMPClause *ActOnOpenMPNogroupClause(SourceLocation StartLoc,
   8096                                       SourceLocation EndLoc);
   8097 
   8098   OMPClause *ActOnOpenMPVarListClause(
   8099       OpenMPClauseKind Kind, ArrayRef<Expr *> Vars, Expr *TailExpr,
   8100       SourceLocation StartLoc, SourceLocation LParenLoc,
   8101       SourceLocation ColonLoc, SourceLocation EndLoc,
   8102       CXXScopeSpec &ReductionIdScopeSpec,
   8103       const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind,
   8104       OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier,
   8105       OpenMPMapClauseKind MapType, SourceLocation DepLinMapLoc);
   8106   /// \brief Called on well-formed 'private' clause.
   8107   OMPClause *ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList,
   8108                                       SourceLocation StartLoc,
   8109                                       SourceLocation LParenLoc,
   8110                                       SourceLocation EndLoc);
   8111   /// \brief Called on well-formed 'firstprivate' clause.
   8112   OMPClause *ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList,
   8113                                            SourceLocation StartLoc,
   8114                                            SourceLocation LParenLoc,
   8115                                            SourceLocation EndLoc);
   8116   /// \brief Called on well-formed 'lastprivate' clause.
   8117   OMPClause *ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList,
   8118                                           SourceLocation StartLoc,
   8119                                           SourceLocation LParenLoc,
   8120                                           SourceLocation EndLoc);
   8121   /// \brief Called on well-formed 'shared' clause.
   8122   OMPClause *ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList,
   8123                                      SourceLocation StartLoc,
   8124                                      SourceLocation LParenLoc,
   8125                                      SourceLocation EndLoc);
   8126   /// \brief Called on well-formed 'reduction' clause.
   8127   OMPClause *
   8128   ActOnOpenMPReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc,
   8129                              SourceLocation LParenLoc, SourceLocation ColonLoc,
   8130                              SourceLocation EndLoc,
   8131                              CXXScopeSpec &ReductionIdScopeSpec,
   8132                              const DeclarationNameInfo &ReductionId);
   8133   /// \brief Called on well-formed 'linear' clause.
   8134   OMPClause *
   8135   ActOnOpenMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
   8136                           SourceLocation StartLoc, SourceLocation LParenLoc,
   8137                           OpenMPLinearClauseKind LinKind, SourceLocation LinLoc,
   8138                           SourceLocation ColonLoc, SourceLocation EndLoc);
   8139   /// \brief Called on well-formed 'aligned' clause.
   8140   OMPClause *ActOnOpenMPAlignedClause(ArrayRef<Expr *> VarList,
   8141                                       Expr *Alignment,
   8142                                       SourceLocation StartLoc,
   8143                                       SourceLocation LParenLoc,
   8144                                       SourceLocation ColonLoc,
   8145                                       SourceLocation EndLoc);
   8146   /// \brief Called on well-formed 'copyin' clause.
   8147   OMPClause *ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList,
   8148                                      SourceLocation StartLoc,
   8149                                      SourceLocation LParenLoc,
   8150                                      SourceLocation EndLoc);
   8151   /// \brief Called on well-formed 'copyprivate' clause.
   8152   OMPClause *ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList,
   8153                                           SourceLocation StartLoc,
   8154                                           SourceLocation LParenLoc,
   8155                                           SourceLocation EndLoc);
   8156   /// \brief Called on well-formed 'flush' pseudo clause.
   8157   OMPClause *ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList,
   8158                                     SourceLocation StartLoc,
   8159                                     SourceLocation LParenLoc,
   8160                                     SourceLocation EndLoc);
   8161   /// \brief Called on well-formed 'depend' clause.
   8162   OMPClause *
   8163   ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
   8164                           SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
   8165                           SourceLocation StartLoc, SourceLocation LParenLoc,
   8166                           SourceLocation EndLoc);
   8167   /// \brief Called on well-formed 'device' clause.
   8168   OMPClause *ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc,
   8169                                      SourceLocation LParenLoc,
   8170                                      SourceLocation EndLoc);
   8171   /// \brief Called on well-formed 'map' clause.
   8172   OMPClause *ActOnOpenMPMapClause(
   8173       OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType,
   8174       SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
   8175       SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc);
   8176   /// \brief Called on well-formed 'num_teams' clause.
   8177   OMPClause *ActOnOpenMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
   8178                                        SourceLocation LParenLoc,
   8179                                        SourceLocation EndLoc);
   8180   /// \brief Called on well-formed 'thread_limit' clause.
   8181   OMPClause *ActOnOpenMPThreadLimitClause(Expr *ThreadLimit,
   8182                                           SourceLocation StartLoc,
   8183                                           SourceLocation LParenLoc,
   8184                                           SourceLocation EndLoc);
   8185   /// \brief Called on well-formed 'priority' clause.
   8186   OMPClause *ActOnOpenMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
   8187                                        SourceLocation LParenLoc,
   8188                                        SourceLocation EndLoc);
   8189 
   8190   /// \brief The kind of conversion being performed.
   8191   enum CheckedConversionKind {
   8192     /// \brief An implicit conversion.
   8193     CCK_ImplicitConversion,
   8194     /// \brief A C-style cast.
   8195     CCK_CStyleCast,
   8196     /// \brief A functional-style cast.
   8197     CCK_FunctionalCast,
   8198     /// \brief A cast other than a C-style cast.
   8199     CCK_OtherCast
   8200   };
   8201 
   8202   /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
   8203   /// cast.  If there is already an implicit cast, merge into the existing one.
   8204   /// If isLvalue, the result of the cast is an lvalue.
   8205   ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK,
   8206                                ExprValueKind VK = VK_RValue,
   8207                                const CXXCastPath *BasePath = nullptr,
   8208                                CheckedConversionKind CCK
   8209                                   = CCK_ImplicitConversion);
   8210 
   8211   /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding
   8212   /// to the conversion from scalar type ScalarTy to the Boolean type.
   8213   static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy);
   8214 
   8215   /// IgnoredValueConversions - Given that an expression's result is
   8216   /// syntactically ignored, perform any conversions that are
   8217   /// required.
   8218   ExprResult IgnoredValueConversions(Expr *E);
   8219 
   8220   // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
   8221   // functions and arrays to their respective pointers (C99 6.3.2.1).
   8222   ExprResult UsualUnaryConversions(Expr *E);
   8223 
   8224   /// CallExprUnaryConversions - a special case of an unary conversion
   8225   /// performed on a function designator of a call expression.
   8226   ExprResult CallExprUnaryConversions(Expr *E);
   8227 
   8228   // DefaultFunctionArrayConversion - converts functions and arrays
   8229   // to their respective pointers (C99 6.3.2.1).
   8230   ExprResult DefaultFunctionArrayConversion(Expr *E, bool Diagnose = true);
   8231 
   8232   // DefaultFunctionArrayLvalueConversion - converts functions and
   8233   // arrays to their respective pointers and performs the
   8234   // lvalue-to-rvalue conversion.
   8235   ExprResult DefaultFunctionArrayLvalueConversion(Expr *E,
   8236                                                   bool Diagnose = true);
   8237 
   8238   // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on
   8239   // the operand.  This is DefaultFunctionArrayLvalueConversion,
   8240   // except that it assumes the operand isn't of function or array
   8241   // type.
   8242   ExprResult DefaultLvalueConversion(Expr *E);
   8243 
   8244   // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
   8245   // do not have a prototype. Integer promotions are performed on each
   8246   // argument, and arguments that have type float are promoted to double.
   8247   ExprResult DefaultArgumentPromotion(Expr *E);
   8248 
   8249   // Used for emitting the right warning by DefaultVariadicArgumentPromotion
   8250   enum VariadicCallType {
   8251     VariadicFunction,
   8252     VariadicBlock,
   8253     VariadicMethod,
   8254     VariadicConstructor,
   8255     VariadicDoesNotApply
   8256   };
   8257 
   8258   VariadicCallType getVariadicCallType(FunctionDecl *FDecl,
   8259                                        const FunctionProtoType *Proto,
   8260                                        Expr *Fn);
   8261 
   8262   // Used for determining in which context a type is allowed to be passed to a
   8263   // vararg function.
   8264   enum VarArgKind {
   8265     VAK_Valid,
   8266     VAK_ValidInCXX11,
   8267     VAK_Undefined,
   8268     VAK_MSVCUndefined,
   8269     VAK_Invalid
   8270   };
   8271 
   8272   // Determines which VarArgKind fits an expression.
   8273   VarArgKind isValidVarArgType(const QualType &Ty);
   8274 
   8275   /// Check to see if the given expression is a valid argument to a variadic
   8276   /// function, issuing a diagnostic if not.
   8277   void checkVariadicArgument(const Expr *E, VariadicCallType CT);
   8278 
   8279   /// Check to see if a given expression could have '.c_str()' called on it.
   8280   bool hasCStrMethod(const Expr *E);
   8281 
   8282   /// GatherArgumentsForCall - Collector argument expressions for various
   8283   /// form of call prototypes.
   8284   bool GatherArgumentsForCall(SourceLocation CallLoc, FunctionDecl *FDecl,
   8285                               const FunctionProtoType *Proto,
   8286                               unsigned FirstParam, ArrayRef<Expr *> Args,
   8287                               SmallVectorImpl<Expr *> &AllArgs,
   8288                               VariadicCallType CallType = VariadicDoesNotApply,
   8289                               bool AllowExplicit = false,
   8290                               bool IsListInitialization = false);
   8291 
   8292   // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
   8293   // will create a runtime trap if the resulting type is not a POD type.
   8294   ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT,
   8295                                               FunctionDecl *FDecl);
   8296 
   8297   // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
   8298   // operands and then handles various conversions that are common to binary
   8299   // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
   8300   // routine returns the first non-arithmetic type found. The client is
   8301   // responsible for emitting appropriate error diagnostics.
   8302   QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS,
   8303                                       bool IsCompAssign = false);
   8304 
   8305   /// AssignConvertType - All of the 'assignment' semantic checks return this
   8306   /// enum to indicate whether the assignment was allowed.  These checks are
   8307   /// done for simple assignments, as well as initialization, return from
   8308   /// function, argument passing, etc.  The query is phrased in terms of a
   8309   /// source and destination type.
   8310   enum AssignConvertType {
   8311     /// Compatible - the types are compatible according to the standard.
   8312     Compatible,
   8313 
   8314     /// PointerToInt - The assignment converts a pointer to an int, which we
   8315     /// accept as an extension.
   8316     PointerToInt,
   8317 
   8318     /// IntToPointer - The assignment converts an int to a pointer, which we
   8319     /// accept as an extension.
   8320     IntToPointer,
   8321 
   8322     /// FunctionVoidPointer - The assignment is between a function pointer and
   8323     /// void*, which the standard doesn't allow, but we accept as an extension.
   8324     FunctionVoidPointer,
   8325 
   8326     /// IncompatiblePointer - The assignment is between two pointers types that
   8327     /// are not compatible, but we accept them as an extension.
   8328     IncompatiblePointer,
   8329 
   8330     /// IncompatiblePointer - The assignment is between two pointers types which
   8331     /// point to integers which have a different sign, but are otherwise
   8332     /// identical. This is a subset of the above, but broken out because it's by
   8333     /// far the most common case of incompatible pointers.
   8334     IncompatiblePointerSign,
   8335 
   8336     /// CompatiblePointerDiscardsQualifiers - The assignment discards
   8337     /// c/v/r qualifiers, which we accept as an extension.
   8338     CompatiblePointerDiscardsQualifiers,
   8339 
   8340     /// IncompatiblePointerDiscardsQualifiers - The assignment
   8341     /// discards qualifiers that we don't permit to be discarded,
   8342     /// like address spaces.
   8343     IncompatiblePointerDiscardsQualifiers,
   8344 
   8345     /// IncompatibleNestedPointerQualifiers - The assignment is between two
   8346     /// nested pointer types, and the qualifiers other than the first two
   8347     /// levels differ e.g. char ** -> const char **, but we accept them as an
   8348     /// extension.
   8349     IncompatibleNestedPointerQualifiers,
   8350 
   8351     /// IncompatibleVectors - The assignment is between two vector types that
   8352     /// have the same size, which we accept as an extension.
   8353     IncompatibleVectors,
   8354 
   8355     /// IntToBlockPointer - The assignment converts an int to a block
   8356     /// pointer. We disallow this.
   8357     IntToBlockPointer,
   8358 
   8359     /// IncompatibleBlockPointer - The assignment is between two block
   8360     /// pointers types that are not compatible.
   8361     IncompatibleBlockPointer,
   8362 
   8363     /// IncompatibleObjCQualifiedId - The assignment is between a qualified
   8364     /// id type and something else (that is incompatible with it). For example,
   8365     /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
   8366     IncompatibleObjCQualifiedId,
   8367 
   8368     /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an
   8369     /// object with __weak qualifier.
   8370     IncompatibleObjCWeakRef,
   8371 
   8372     /// Incompatible - We reject this conversion outright, it is invalid to
   8373     /// represent it in the AST.
   8374     Incompatible
   8375   };
   8376 
   8377   /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
   8378   /// assignment conversion type specified by ConvTy.  This returns true if the
   8379   /// conversion was invalid or false if the conversion was accepted.
   8380   bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
   8381                                 SourceLocation Loc,
   8382                                 QualType DstType, QualType SrcType,
   8383                                 Expr *SrcExpr, AssignmentAction Action,
   8384                                 bool *Complained = nullptr);
   8385 
   8386   /// IsValueInFlagEnum - Determine if a value is allowed as part of a flag
   8387   /// enum. If AllowMask is true, then we also allow the complement of a valid
   8388   /// value, to be used as a mask.
   8389   bool IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val,
   8390                          bool AllowMask) const;
   8391 
   8392   /// DiagnoseAssignmentEnum - Warn if assignment to enum is a constant
   8393   /// integer not in the range of enum values.
   8394   void DiagnoseAssignmentEnum(QualType DstType, QualType SrcType,
   8395                               Expr *SrcExpr);
   8396 
   8397   /// CheckAssignmentConstraints - Perform type checking for assignment,
   8398   /// argument passing, variable initialization, and function return values.
   8399   /// C99 6.5.16.
   8400   AssignConvertType CheckAssignmentConstraints(SourceLocation Loc,
   8401                                                QualType LHSType,
   8402                                                QualType RHSType);
   8403 
   8404   /// Check assignment constraints and optionally prepare for a conversion of
   8405   /// the RHS to the LHS type. The conversion is prepared for if ConvertRHS
   8406   /// is true.
   8407   AssignConvertType CheckAssignmentConstraints(QualType LHSType,
   8408                                                ExprResult &RHS,
   8409                                                CastKind &Kind,
   8410                                                bool ConvertRHS = true);
   8411 
   8412   // CheckSingleAssignmentConstraints - Currently used by
   8413   // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
   8414   // this routine performs the default function/array converions, if ConvertRHS
   8415   // is true.
   8416   AssignConvertType CheckSingleAssignmentConstraints(QualType LHSType,
   8417                                                      ExprResult &RHS,
   8418                                                      bool Diagnose = true,
   8419                                                      bool DiagnoseCFAudited = false,
   8420                                                      bool ConvertRHS = true);
   8421 
   8422   // \brief If the lhs type is a transparent union, check whether we
   8423   // can initialize the transparent union with the given expression.
   8424   AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType,
   8425                                                              ExprResult &RHS);
   8426 
   8427   bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
   8428 
   8429   bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType);
   8430 
   8431   ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
   8432                                        AssignmentAction Action,
   8433                                        bool AllowExplicit = false);
   8434   ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
   8435                                        AssignmentAction Action,
   8436                                        bool AllowExplicit,
   8437                                        ImplicitConversionSequence& ICS);
   8438   ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
   8439                                        const ImplicitConversionSequence& ICS,
   8440                                        AssignmentAction Action,
   8441                                        CheckedConversionKind CCK
   8442                                           = CCK_ImplicitConversion);
   8443   ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
   8444                                        const StandardConversionSequence& SCS,
   8445                                        AssignmentAction Action,
   8446                                        CheckedConversionKind CCK);
   8447 
   8448   /// the following "Check" methods will return a valid/converted QualType
   8449   /// or a null QualType (indicating an error diagnostic was issued).
   8450 
   8451   /// type checking binary operators (subroutines of CreateBuiltinBinOp).
   8452   QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS,
   8453                            ExprResult &RHS);
   8454   QualType CheckPointerToMemberOperands( // C++ 5.5
   8455     ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK,
   8456     SourceLocation OpLoc, bool isIndirect);
   8457   QualType CheckMultiplyDivideOperands( // C99 6.5.5
   8458     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign,
   8459     bool IsDivide);
   8460   QualType CheckRemainderOperands( // C99 6.5.5
   8461     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
   8462     bool IsCompAssign = false);
   8463   QualType CheckAdditionOperands( // C99 6.5.6
   8464     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
   8465     BinaryOperatorKind Opc, QualType* CompLHSTy = nullptr);
   8466   QualType CheckSubtractionOperands( // C99 6.5.6
   8467     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
   8468     QualType* CompLHSTy = nullptr);
   8469   QualType CheckShiftOperands( // C99 6.5.7
   8470     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
   8471     BinaryOperatorKind Opc, bool IsCompAssign = false);
   8472   QualType CheckCompareOperands( // C99 6.5.8/9
   8473     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
   8474     BinaryOperatorKind Opc, bool isRelational);
   8475   QualType CheckBitwiseOperands( // C99 6.5.[10...12]
   8476     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
   8477     bool IsCompAssign = false);
   8478   QualType CheckLogicalOperands( // C99 6.5.[13,14]
   8479     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
   8480     BinaryOperatorKind Opc);
   8481   // CheckAssignmentOperands is used for both simple and compound assignment.
   8482   // For simple assignment, pass both expressions and a null converted type.
   8483   // For compound assignment, pass both expressions and the converted type.
   8484   QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
   8485     Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType);
   8486 
   8487   ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc,
   8488                                      UnaryOperatorKind Opcode, Expr *Op);
   8489   ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc,
   8490                                          BinaryOperatorKind Opcode,
   8491                                          Expr *LHS, Expr *RHS);
   8492   ExprResult checkPseudoObjectRValue(Expr *E);
   8493   Expr *recreateSyntacticForm(PseudoObjectExpr *E);
   8494 
   8495   QualType CheckConditionalOperands( // C99 6.5.15
   8496     ExprResult &Cond, ExprResult &LHS, ExprResult &RHS,
   8497     ExprValueKind &VK, ExprObjectKind &OK, SourceLocation QuestionLoc);
   8498   QualType CXXCheckConditionalOperands( // C++ 5.16
   8499     ExprResult &cond, ExprResult &lhs, ExprResult &rhs,
   8500     ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc);
   8501   QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2,
   8502                                     bool *NonStandardCompositeType = nullptr);
   8503   QualType FindCompositePointerType(SourceLocation Loc,
   8504                                     ExprResult &E1, ExprResult &E2,
   8505                                     bool *NonStandardCompositeType = nullptr) {
   8506     Expr *E1Tmp = E1.get(), *E2Tmp = E2.get();
   8507     QualType Composite = FindCompositePointerType(Loc, E1Tmp, E2Tmp,
   8508                                                   NonStandardCompositeType);
   8509     E1 = E1Tmp;
   8510     E2 = E2Tmp;
   8511     return Composite;
   8512   }
   8513 
   8514   QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS,
   8515                                         SourceLocation QuestionLoc);
   8516 
   8517   bool DiagnoseConditionalForNull(Expr *LHSExpr, Expr *RHSExpr,
   8518                                   SourceLocation QuestionLoc);
   8519 
   8520   void DiagnoseAlwaysNonNullPointer(Expr *E,
   8521                                     Expr::NullPointerConstantKind NullType,
   8522                                     bool IsEqual, SourceRange Range);
   8523 
   8524   /// type checking for vector binary operators.
   8525   QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS,
   8526                                SourceLocation Loc, bool IsCompAssign,
   8527                                bool AllowBothBool, bool AllowBoolConversion);
   8528   QualType GetSignedVectorType(QualType V);
   8529   QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS,
   8530                                       SourceLocation Loc, bool isRelational);
   8531   QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS,
   8532                                       SourceLocation Loc);
   8533 
   8534   bool areLaxCompatibleVectorTypes(QualType srcType, QualType destType);
   8535   bool isLaxVectorConversion(QualType srcType, QualType destType);
   8536 
   8537   /// type checking declaration initializers (C99 6.7.8)
   8538   bool CheckForConstantInitializer(Expr *e, QualType t);
   8539 
   8540   // type checking C++ declaration initializers (C++ [dcl.init]).
   8541 
   8542   /// ReferenceCompareResult - Expresses the result of comparing two
   8543   /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
   8544   /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
   8545   enum ReferenceCompareResult {
   8546     /// Ref_Incompatible - The two types are incompatible, so direct
   8547     /// reference binding is not possible.
   8548     Ref_Incompatible = 0,
   8549     /// Ref_Related - The two types are reference-related, which means
   8550     /// that their unqualified forms (T1 and T2) are either the same
   8551     /// or T1 is a base class of T2.
   8552     Ref_Related,
   8553     /// Ref_Compatible_With_Added_Qualification - The two types are
   8554     /// reference-compatible with added qualification, meaning that
   8555     /// they are reference-compatible and the qualifiers on T1 (cv1)
   8556     /// are greater than the qualifiers on T2 (cv2).
   8557     Ref_Compatible_With_Added_Qualification,
   8558     /// Ref_Compatible - The two types are reference-compatible and
   8559     /// have equivalent qualifiers (cv1 == cv2).
   8560     Ref_Compatible
   8561   };
   8562 
   8563   ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc,
   8564                                                       QualType T1, QualType T2,
   8565                                                       bool &DerivedToBase,
   8566                                                       bool &ObjCConversion,
   8567                                                 bool &ObjCLifetimeConversion);
   8568 
   8569   ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType,
   8570                                  Expr *CastExpr, CastKind &CastKind,
   8571                                  ExprValueKind &VK, CXXCastPath &Path);
   8572 
   8573   /// \brief Force an expression with unknown-type to an expression of the
   8574   /// given type.
   8575   ExprResult forceUnknownAnyToType(Expr *E, QualType ToType);
   8576 
   8577   /// \brief Type-check an expression that's being passed to an
   8578   /// __unknown_anytype parameter.
   8579   ExprResult checkUnknownAnyArg(SourceLocation callLoc,
   8580                                 Expr *result, QualType &paramType);
   8581 
   8582   // CheckVectorCast - check type constraints for vectors.
   8583   // Since vectors are an extension, there are no C standard reference for this.
   8584   // We allow casting between vectors and integer datatypes of the same size.
   8585   // returns true if the cast is invalid
   8586   bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty,
   8587                        CastKind &Kind);
   8588 
   8589   // CheckExtVectorCast - check type constraints for extended vectors.
   8590   // Since vectors are an extension, there are no C standard reference for this.
   8591   // We allow casting between vectors and integer datatypes of the same size,
   8592   // or vectors and the element type of that vector.
   8593   // returns the cast expr
   8594   ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr,
   8595                                 CastKind &Kind);
   8596 
   8597   ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
   8598                                         SourceLocation LParenLoc,
   8599                                         Expr *CastExpr,
   8600                                         SourceLocation RParenLoc);
   8601 
   8602   enum ARCConversionResult { ACR_okay, ACR_unbridged };
   8603 
   8604   /// \brief Checks for invalid conversions and casts between
   8605   /// retainable pointers and other pointer kinds.
   8606   ARCConversionResult CheckObjCARCConversion(SourceRange castRange,
   8607                                              QualType castType, Expr *&op,
   8608                                              CheckedConversionKind CCK,
   8609                                              bool DiagnoseCFAudited = false,
   8610                                              BinaryOperatorKind Opc = BO_PtrMemD
   8611                                              );
   8612 
   8613   Expr *stripARCUnbridgedCast(Expr *e);
   8614   void diagnoseARCUnbridgedCast(Expr *e);
   8615 
   8616   bool CheckObjCARCUnavailableWeakConversion(QualType castType,
   8617                                              QualType ExprType);
   8618 
   8619   /// checkRetainCycles - Check whether an Objective-C message send
   8620   /// might create an obvious retain cycle.
   8621   void checkRetainCycles(ObjCMessageExpr *msg);
   8622   void checkRetainCycles(Expr *receiver, Expr *argument);
   8623   void checkRetainCycles(VarDecl *Var, Expr *Init);
   8624 
   8625   /// checkUnsafeAssigns - Check whether +1 expr is being assigned
   8626   /// to weak/__unsafe_unretained type.
   8627   bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS);
   8628 
   8629   /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned
   8630   /// to weak/__unsafe_unretained expression.
   8631   void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS);
   8632 
   8633   /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
   8634   /// \param Method - May be null.
   8635   /// \param [out] ReturnType - The return type of the send.
   8636   /// \return true iff there were any incompatible types.
   8637   bool CheckMessageArgumentTypes(QualType ReceiverType,
   8638                                  MultiExprArg Args, Selector Sel,
   8639                                  ArrayRef<SourceLocation> SelectorLocs,
   8640                                  ObjCMethodDecl *Method, bool isClassMessage,
   8641                                  bool isSuperMessage,
   8642                                  SourceLocation lbrac, SourceLocation rbrac,
   8643                                  SourceRange RecRange,
   8644                                  QualType &ReturnType, ExprValueKind &VK);
   8645 
   8646   /// \brief Determine the result of a message send expression based on
   8647   /// the type of the receiver, the method expected to receive the message,
   8648   /// and the form of the message send.
   8649   QualType getMessageSendResultType(QualType ReceiverType,
   8650                                     ObjCMethodDecl *Method,
   8651                                     bool isClassMessage, bool isSuperMessage);
   8652 
   8653   /// \brief If the given expression involves a message send to a method
   8654   /// with a related result type, emit a note describing what happened.
   8655   void EmitRelatedResultTypeNote(const Expr *E);
   8656 
   8657   /// \brief Given that we had incompatible pointer types in a return
   8658   /// statement, check whether we're in a method with a related result
   8659   /// type, and if so, emit a note describing what happened.
   8660   void EmitRelatedResultTypeNoteForReturn(QualType destType);
   8661 
   8662   /// CheckBooleanCondition - Diagnose problems involving the use of
   8663   /// the given expression as a boolean condition (e.g. in an if
   8664   /// statement).  Also performs the standard function and array
   8665   /// decays, possibly changing the input variable.
   8666   ///
   8667   /// \param Loc - A location associated with the condition, e.g. the
   8668   /// 'if' keyword.
   8669   /// \return true iff there were any errors
   8670   ExprResult CheckBooleanCondition(Expr *E, SourceLocation Loc);
   8671 
   8672   ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc,
   8673                                    Expr *SubExpr);
   8674 
   8675   /// DiagnoseAssignmentAsCondition - Given that an expression is
   8676   /// being used as a boolean condition, warn if it's an assignment.
   8677   void DiagnoseAssignmentAsCondition(Expr *E);
   8678 
   8679   /// \brief Redundant parentheses over an equality comparison can indicate
   8680   /// that the user intended an assignment used as condition.
   8681   void DiagnoseEqualityWithExtraParens(ParenExpr *ParenE);
   8682 
   8683   /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
   8684   ExprResult CheckCXXBooleanCondition(Expr *CondExpr);
   8685 
   8686   /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
   8687   /// the specified width and sign.  If an overflow occurs, detect it and emit
   8688   /// the specified diagnostic.
   8689   void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
   8690                                           unsigned NewWidth, bool NewSign,
   8691                                           SourceLocation Loc, unsigned DiagID);
   8692 
   8693   /// Checks that the Objective-C declaration is declared in the global scope.
   8694   /// Emits an error and marks the declaration as invalid if it's not declared
   8695   /// in the global scope.
   8696   bool CheckObjCDeclScope(Decl *D);
   8697 
   8698   /// \brief Abstract base class used for diagnosing integer constant
   8699   /// expression violations.
   8700   class VerifyICEDiagnoser {
   8701   public:
   8702     bool Suppress;
   8703 
   8704     VerifyICEDiagnoser(bool Suppress = false) : Suppress(Suppress) { }
   8705 
   8706     virtual void diagnoseNotICE(Sema &S, SourceLocation Loc, SourceRange SR) =0;
   8707     virtual void diagnoseFold(Sema &S, SourceLocation Loc, SourceRange SR);
   8708     virtual ~VerifyICEDiagnoser() { }
   8709   };
   8710 
   8711   /// VerifyIntegerConstantExpression - Verifies that an expression is an ICE,
   8712   /// and reports the appropriate diagnostics. Returns false on success.
   8713   /// Can optionally return the value of the expression.
   8714   ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
   8715                                              VerifyICEDiagnoser &Diagnoser,
   8716                                              bool AllowFold = true);
   8717   ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
   8718                                              unsigned DiagID,
   8719                                              bool AllowFold = true);
   8720   ExprResult VerifyIntegerConstantExpression(Expr *E,
   8721                                              llvm::APSInt *Result = nullptr);
   8722 
   8723   /// VerifyBitField - verifies that a bit field expression is an ICE and has
   8724   /// the correct width, and that the field type is valid.
   8725   /// Returns false on success.
   8726   /// Can optionally return whether the bit-field is of width 0
   8727   ExprResult VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
   8728                             QualType FieldTy, bool IsMsStruct,
   8729                             Expr *BitWidth, bool *ZeroWidth = nullptr);
   8730 
   8731   enum CUDAFunctionTarget {
   8732     CFT_Device,
   8733     CFT_Global,
   8734     CFT_Host,
   8735     CFT_HostDevice,
   8736     CFT_InvalidTarget
   8737   };
   8738 
   8739   CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D);
   8740 
   8741   enum CUDAFunctionPreference {
   8742     CFP_Never,      // Invalid caller/callee combination.
   8743     CFP_LastResort, // Lowest priority. Only in effect if
   8744                     // LangOpts.CUDADisableTargetCallChecks is true.
   8745     CFP_Fallback,   // Low priority caller/callee combination
   8746     CFP_Best,       // Preferred caller/callee combination
   8747   };
   8748 
   8749   /// Identifies relative preference of a given Caller/Callee
   8750   /// combination, based on their host/device attributes.
   8751   /// \param Caller function which needs address of \p Callee.
   8752   ///               nullptr in case of global context.
   8753   /// \param Callee target function
   8754   ///
   8755   /// \returns preference value for particular Caller/Callee combination.
   8756   CUDAFunctionPreference IdentifyCUDAPreference(const FunctionDecl *Caller,
   8757                                                 const FunctionDecl *Callee);
   8758 
   8759   bool CheckCUDATarget(const FunctionDecl *Caller, const FunctionDecl *Callee);
   8760 
   8761   /// Finds a function in \p Matches with highest calling priority
   8762   /// from \p Caller context and erases all functions with lower
   8763   /// calling priority.
   8764   void EraseUnwantedCUDAMatches(const FunctionDecl *Caller,
   8765                                 SmallVectorImpl<FunctionDecl *> &Matches);
   8766   void EraseUnwantedCUDAMatches(const FunctionDecl *Caller,
   8767                                 SmallVectorImpl<DeclAccessPair> &Matches);
   8768   void EraseUnwantedCUDAMatches(
   8769       const FunctionDecl *Caller,
   8770       SmallVectorImpl<std::pair<DeclAccessPair, FunctionDecl *>> &Matches);
   8771 
   8772   /// Given a implicit special member, infer its CUDA target from the
   8773   /// calls it needs to make to underlying base/field special members.
   8774   /// \param ClassDecl the class for which the member is being created.
   8775   /// \param CSM the kind of special member.
   8776   /// \param MemberDecl the special member itself.
   8777   /// \param ConstRHS true if this is a copy operation with a const object on
   8778   ///        its RHS.
   8779   /// \param Diagnose true if this call should emit diagnostics.
   8780   /// \return true if there was an error inferring.
   8781   /// The result of this call is implicit CUDA target attribute(s) attached to
   8782   /// the member declaration.
   8783   bool inferCUDATargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl,
   8784                                                CXXSpecialMember CSM,
   8785                                                CXXMethodDecl *MemberDecl,
   8786                                                bool ConstRHS,
   8787                                                bool Diagnose);
   8788 
   8789   /// \name Code completion
   8790   //@{
   8791   /// \brief Describes the context in which code completion occurs.
   8792   enum ParserCompletionContext {
   8793     /// \brief Code completion occurs at top-level or namespace context.
   8794     PCC_Namespace,
   8795     /// \brief Code completion occurs within a class, struct, or union.
   8796     PCC_Class,
   8797     /// \brief Code completion occurs within an Objective-C interface, protocol,
   8798     /// or category.
   8799     PCC_ObjCInterface,
   8800     /// \brief Code completion occurs within an Objective-C implementation or
   8801     /// category implementation
   8802     PCC_ObjCImplementation,
   8803     /// \brief Code completion occurs within the list of instance variables
   8804     /// in an Objective-C interface, protocol, category, or implementation.
   8805     PCC_ObjCInstanceVariableList,
   8806     /// \brief Code completion occurs following one or more template
   8807     /// headers.
   8808     PCC_Template,
   8809     /// \brief Code completion occurs following one or more template
   8810     /// headers within a class.
   8811     PCC_MemberTemplate,
   8812     /// \brief Code completion occurs within an expression.
   8813     PCC_Expression,
   8814     /// \brief Code completion occurs within a statement, which may
   8815     /// also be an expression or a declaration.
   8816     PCC_Statement,
   8817     /// \brief Code completion occurs at the beginning of the
   8818     /// initialization statement (or expression) in a for loop.
   8819     PCC_ForInit,
   8820     /// \brief Code completion occurs within the condition of an if,
   8821     /// while, switch, or for statement.
   8822     PCC_Condition,
   8823     /// \brief Code completion occurs within the body of a function on a
   8824     /// recovery path, where we do not have a specific handle on our position
   8825     /// in the grammar.
   8826     PCC_RecoveryInFunction,
   8827     /// \brief Code completion occurs where only a type is permitted.
   8828     PCC_Type,
   8829     /// \brief Code completion occurs in a parenthesized expression, which
   8830     /// might also be a type cast.
   8831     PCC_ParenthesizedExpression,
   8832     /// \brief Code completion occurs within a sequence of declaration
   8833     /// specifiers within a function, method, or block.
   8834     PCC_LocalDeclarationSpecifiers
   8835   };
   8836 
   8837   void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path);
   8838   void CodeCompleteOrdinaryName(Scope *S,
   8839                                 ParserCompletionContext CompletionContext);
   8840   void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS,
   8841                             bool AllowNonIdentifiers,
   8842                             bool AllowNestedNameSpecifiers);
   8843 
   8844   struct CodeCompleteExpressionData;
   8845   void CodeCompleteExpression(Scope *S,
   8846                               const CodeCompleteExpressionData &Data);
   8847   void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
   8848                                        SourceLocation OpLoc,
   8849                                        bool IsArrow);
   8850   void CodeCompletePostfixExpression(Scope *S, ExprResult LHS);
   8851   void CodeCompleteTag(Scope *S, unsigned TagSpec);
   8852   void CodeCompleteTypeQualifiers(DeclSpec &DS);
   8853   void CodeCompleteCase(Scope *S);
   8854   void CodeCompleteCall(Scope *S, Expr *Fn, ArrayRef<Expr *> Args);
   8855   void CodeCompleteConstructor(Scope *S, QualType Type, SourceLocation Loc,
   8856                                ArrayRef<Expr *> Args);
   8857   void CodeCompleteInitializer(Scope *S, Decl *D);
   8858   void CodeCompleteReturn(Scope *S);
   8859   void CodeCompleteAfterIf(Scope *S);
   8860   void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS);
   8861 
   8862   void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS,
   8863                                bool EnteringContext);
   8864   void CodeCompleteUsing(Scope *S);
   8865   void CodeCompleteUsingDirective(Scope *S);
   8866   void CodeCompleteNamespaceDecl(Scope *S);
   8867   void CodeCompleteNamespaceAliasDecl(Scope *S);
   8868   void CodeCompleteOperatorName(Scope *S);
   8869   void CodeCompleteConstructorInitializer(
   8870                                 Decl *Constructor,
   8871                                 ArrayRef<CXXCtorInitializer *> Initializers);
   8872 
   8873   void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro,
   8874                                     bool AfterAmpersand);
   8875 
   8876   void CodeCompleteObjCAtDirective(Scope *S);
   8877   void CodeCompleteObjCAtVisibility(Scope *S);
   8878   void CodeCompleteObjCAtStatement(Scope *S);
   8879   void CodeCompleteObjCAtExpression(Scope *S);
   8880   void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS);
   8881   void CodeCompleteObjCPropertyGetter(Scope *S);
   8882   void CodeCompleteObjCPropertySetter(Scope *S);
   8883   void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS,
   8884                                    bool IsParameter);
   8885   void CodeCompleteObjCMessageReceiver(Scope *S);
   8886   void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc,
   8887                                     ArrayRef<IdentifierInfo *> SelIdents,
   8888                                     bool AtArgumentExpression);
   8889   void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver,
   8890                                     ArrayRef<IdentifierInfo *> SelIdents,
   8891                                     bool AtArgumentExpression,
   8892                                     bool IsSuper = false);
   8893   void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver,
   8894                                        ArrayRef<IdentifierInfo *> SelIdents,
   8895                                        bool AtArgumentExpression,
   8896                                        ObjCInterfaceDecl *Super = nullptr);
   8897   void CodeCompleteObjCForCollection(Scope *S,
   8898                                      DeclGroupPtrTy IterationVar);
   8899   void CodeCompleteObjCSelector(Scope *S,
   8900                                 ArrayRef<IdentifierInfo *> SelIdents);
   8901   void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
   8902                                           unsigned NumProtocols);
   8903   void CodeCompleteObjCProtocolDecl(Scope *S);
   8904   void CodeCompleteObjCInterfaceDecl(Scope *S);
   8905   void CodeCompleteObjCSuperclass(Scope *S,
   8906                                   IdentifierInfo *ClassName,
   8907                                   SourceLocation ClassNameLoc);
   8908   void CodeCompleteObjCImplementationDecl(Scope *S);
   8909   void CodeCompleteObjCInterfaceCategory(Scope *S,
   8910                                          IdentifierInfo *ClassName,
   8911                                          SourceLocation ClassNameLoc);
   8912   void CodeCompleteObjCImplementationCategory(Scope *S,
   8913                                               IdentifierInfo *ClassName,
   8914                                               SourceLocation ClassNameLoc);
   8915   void CodeCompleteObjCPropertyDefinition(Scope *S);
   8916   void CodeCompleteObjCPropertySynthesizeIvar(Scope *S,
   8917                                               IdentifierInfo *PropertyName);
   8918   void CodeCompleteObjCMethodDecl(Scope *S,
   8919                                   bool IsInstanceMethod,
   8920                                   ParsedType ReturnType);
   8921   void CodeCompleteObjCMethodDeclSelector(Scope *S,
   8922                                           bool IsInstanceMethod,
   8923                                           bool AtParameterName,
   8924                                           ParsedType ReturnType,
   8925                                           ArrayRef<IdentifierInfo *> SelIdents);
   8926   void CodeCompletePreprocessorDirective(bool InConditional);
   8927   void CodeCompleteInPreprocessorConditionalExclusion(Scope *S);
   8928   void CodeCompletePreprocessorMacroName(bool IsDefinition);
   8929   void CodeCompletePreprocessorExpression();
   8930   void CodeCompletePreprocessorMacroArgument(Scope *S,
   8931                                              IdentifierInfo *Macro,
   8932                                              MacroInfo *MacroInfo,
   8933                                              unsigned Argument);
   8934   void CodeCompleteNaturalLanguage();
   8935   void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator,
   8936                                    CodeCompletionTUInfo &CCTUInfo,
   8937                   SmallVectorImpl<CodeCompletionResult> &Results);
   8938   //@}
   8939 
   8940   //===--------------------------------------------------------------------===//
   8941   // Extra semantic analysis beyond the C type system
   8942 
   8943 public:
   8944   SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
   8945                                                 unsigned ByteNo) const;
   8946 
   8947 private:
   8948   void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
   8949                         const ArraySubscriptExpr *ASE=nullptr,
   8950                         bool AllowOnePastEnd=true, bool IndexNegated=false);
   8951   void CheckArrayAccess(const Expr *E);
   8952   // Used to grab the relevant information from a FormatAttr and a
   8953   // FunctionDeclaration.
   8954   struct FormatStringInfo {
   8955     unsigned FormatIdx;
   8956     unsigned FirstDataArg;
   8957     bool HasVAListArg;
   8958   };
   8959 
   8960   static bool getFormatStringInfo(const FormatAttr *Format, bool IsCXXMember,
   8961                                   FormatStringInfo *FSI);
   8962   bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall,
   8963                          const FunctionProtoType *Proto);
   8964   bool CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation loc,
   8965                            ArrayRef<const Expr *> Args);
   8966   bool CheckPointerCall(NamedDecl *NDecl, CallExpr *TheCall,
   8967                         const FunctionProtoType *Proto);
   8968   bool CheckOtherCall(CallExpr *TheCall, const FunctionProtoType *Proto);
   8969   void CheckConstructorCall(FunctionDecl *FDecl,
   8970                             ArrayRef<const Expr *> Args,
   8971                             const FunctionProtoType *Proto,
   8972                             SourceLocation Loc);
   8973 
   8974   void checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto,
   8975                  ArrayRef<const Expr *> Args, bool IsMemberFunction,
   8976                  SourceLocation Loc, SourceRange Range,
   8977                  VariadicCallType CallType);
   8978 
   8979   bool CheckObjCString(Expr *Arg);
   8980 
   8981   ExprResult CheckBuiltinFunctionCall(FunctionDecl *FDecl,
   8982                                       unsigned BuiltinID, CallExpr *TheCall);
   8983 
   8984   bool CheckARMBuiltinExclusiveCall(unsigned BuiltinID, CallExpr *TheCall,
   8985                                     unsigned MaxWidth);
   8986   bool CheckNeonBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
   8987   bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
   8988 
   8989   bool CheckAArch64BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
   8990   bool CheckMipsBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
   8991   bool CheckSystemZBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
   8992   bool CheckX86BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
   8993   bool CheckPPCBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
   8994 
   8995   bool SemaBuiltinVAStartImpl(CallExpr *TheCall);
   8996   bool SemaBuiltinVAStart(CallExpr *TheCall);
   8997   bool SemaBuiltinMSVAStart(CallExpr *TheCall);
   8998   bool SemaBuiltinVAStartARM(CallExpr *Call);
   8999   bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
   9000   bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs);
   9001 
   9002 public:
   9003   // Used by C++ template instantiation.
   9004   ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
   9005   ExprResult SemaConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo,
   9006                                    SourceLocation BuiltinLoc,
   9007                                    SourceLocation RParenLoc);
   9008 
   9009 private:
   9010   bool SemaBuiltinPrefetch(CallExpr *TheCall);
   9011   bool SemaBuiltinAssume(CallExpr *TheCall);
   9012   bool SemaBuiltinAssumeAligned(CallExpr *TheCall);
   9013   bool SemaBuiltinLongjmp(CallExpr *TheCall);
   9014   bool SemaBuiltinSetjmp(CallExpr *TheCall);
   9015   ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult);
   9016   ExprResult SemaBuiltinNontemporalOverloaded(ExprResult TheCallResult);
   9017   ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult,
   9018                                      AtomicExpr::AtomicOp Op);
   9019   bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum,
   9020                               llvm::APSInt &Result);
   9021   bool SemaBuiltinConstantArgRange(CallExpr *TheCall, int ArgNum,
   9022                                    int Low, int High);
   9023   bool SemaBuiltinARMSpecialReg(unsigned BuiltinID, CallExpr *TheCall,
   9024                                 int ArgNum, unsigned ExpectedFieldNum,
   9025                                 bool AllowName);
   9026 public:
   9027   enum FormatStringType {
   9028     FST_Scanf,
   9029     FST_Printf,
   9030     FST_NSString,
   9031     FST_Strftime,
   9032     FST_Strfmon,
   9033     FST_Kprintf,
   9034     FST_FreeBSDKPrintf,
   9035     FST_OSTrace,
   9036     FST_Unknown
   9037   };
   9038   static FormatStringType GetFormatStringType(const FormatAttr *Format);
   9039 
   9040   void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr,
   9041                          ArrayRef<const Expr *> Args, bool HasVAListArg,
   9042                          unsigned format_idx, unsigned firstDataArg,
   9043                          FormatStringType Type, bool inFunctionCall,
   9044                          VariadicCallType CallType,
   9045                          llvm::SmallBitVector &CheckedVarArgs);
   9046 
   9047   bool FormatStringHasSArg(const StringLiteral *FExpr);
   9048 
   9049   static bool GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx);
   9050 
   9051 private:
   9052   bool CheckFormatArguments(const FormatAttr *Format,
   9053                             ArrayRef<const Expr *> Args,
   9054                             bool IsCXXMember,
   9055                             VariadicCallType CallType,
   9056                             SourceLocation Loc, SourceRange Range,
   9057                             llvm::SmallBitVector &CheckedVarArgs);
   9058   bool CheckFormatArguments(ArrayRef<const Expr *> Args,
   9059                             bool HasVAListArg, unsigned format_idx,
   9060                             unsigned firstDataArg, FormatStringType Type,
   9061                             VariadicCallType CallType,
   9062                             SourceLocation Loc, SourceRange range,
   9063                             llvm::SmallBitVector &CheckedVarArgs);
   9064 
   9065   void CheckAbsoluteValueFunction(const CallExpr *Call,
   9066                                   const FunctionDecl *FDecl,
   9067                                   IdentifierInfo *FnInfo);
   9068 
   9069   void CheckMemaccessArguments(const CallExpr *Call,
   9070                                unsigned BId,
   9071                                IdentifierInfo *FnName);
   9072 
   9073   void CheckStrlcpycatArguments(const CallExpr *Call,
   9074                                 IdentifierInfo *FnName);
   9075 
   9076   void CheckStrncatArguments(const CallExpr *Call,
   9077                              IdentifierInfo *FnName);
   9078 
   9079   void CheckReturnValExpr(Expr *RetValExp, QualType lhsType,
   9080                           SourceLocation ReturnLoc,
   9081                           bool isObjCMethod = false,
   9082                           const AttrVec *Attrs = nullptr,
   9083                           const FunctionDecl *FD = nullptr);
   9084 
   9085   void CheckFloatComparison(SourceLocation Loc, Expr* LHS, Expr* RHS);
   9086   void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation());
   9087   void CheckBoolLikeConversion(Expr *E, SourceLocation CC);
   9088   void CheckForIntOverflow(Expr *E);
   9089   void CheckUnsequencedOperations(Expr *E);
   9090 
   9091   /// \brief Perform semantic checks on a completed expression. This will either
   9092   /// be a full-expression or a default argument expression.
   9093   void CheckCompletedExpr(Expr *E, SourceLocation CheckLoc = SourceLocation(),
   9094                           bool IsConstexpr = false);
   9095 
   9096   void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field,
   9097                                    Expr *Init);
   9098 
   9099   /// \brief Check if the given expression contains 'break' or 'continue'
   9100   /// statement that produces control flow different from GCC.
   9101   void CheckBreakContinueBinding(Expr *E);
   9102 
   9103   /// \brief Check whether receiver is mutable ObjC container which
   9104   /// attempts to add itself into the container
   9105   void CheckObjCCircularContainer(ObjCMessageExpr *Message);
   9106 
   9107   void AnalyzeDeleteExprMismatch(const CXXDeleteExpr *DE);
   9108   void AnalyzeDeleteExprMismatch(FieldDecl *Field, SourceLocation DeleteLoc,
   9109                                  bool DeleteWasArrayForm);
   9110 public:
   9111   /// \brief Register a magic integral constant to be used as a type tag.
   9112   void RegisterTypeTagForDatatype(const IdentifierInfo *ArgumentKind,
   9113                                   uint64_t MagicValue, QualType Type,
   9114                                   bool LayoutCompatible, bool MustBeNull);
   9115 
   9116   struct TypeTagData {
   9117     TypeTagData() {}
   9118 
   9119     TypeTagData(QualType Type, bool LayoutCompatible, bool MustBeNull) :
   9120         Type(Type), LayoutCompatible(LayoutCompatible),
   9121         MustBeNull(MustBeNull)
   9122     {}
   9123 
   9124     QualType Type;
   9125 
   9126     /// If true, \c Type should be compared with other expression's types for
   9127     /// layout-compatibility.
   9128     unsigned LayoutCompatible : 1;
   9129     unsigned MustBeNull : 1;
   9130   };
   9131 
   9132   /// A pair of ArgumentKind identifier and magic value.  This uniquely
   9133   /// identifies the magic value.
   9134   typedef std::pair<const IdentifierInfo *, uint64_t> TypeTagMagicValue;
   9135 
   9136 private:
   9137   /// \brief A map from magic value to type information.
   9138   std::unique_ptr<llvm::DenseMap<TypeTagMagicValue, TypeTagData>>
   9139       TypeTagForDatatypeMagicValues;
   9140 
   9141   /// \brief Peform checks on a call of a function with argument_with_type_tag
   9142   /// or pointer_with_type_tag attributes.
   9143   void CheckArgumentWithTypeTag(const ArgumentWithTypeTagAttr *Attr,
   9144                                 const Expr * const *ExprArgs);
   9145 
   9146   /// \brief The parser's current scope.
   9147   ///
   9148   /// The parser maintains this state here.
   9149   Scope *CurScope;
   9150 
   9151   mutable IdentifierInfo *Ident_super;
   9152   mutable IdentifierInfo *Ident___float128;
   9153 
   9154   /// Nullability type specifiers.
   9155   IdentifierInfo *Ident__Nonnull = nullptr;
   9156   IdentifierInfo *Ident__Nullable = nullptr;
   9157   IdentifierInfo *Ident__Null_unspecified = nullptr;
   9158 
   9159   IdentifierInfo *Ident_NSError = nullptr;
   9160 
   9161 protected:
   9162   friend class Parser;
   9163   friend class InitializationSequence;
   9164   friend class ASTReader;
   9165   friend class ASTDeclReader;
   9166   friend class ASTWriter;
   9167 
   9168 public:
   9169   /// Retrieve the keyword associated
   9170   IdentifierInfo *getNullabilityKeyword(NullabilityKind nullability);
   9171 
   9172   /// The struct behind the CFErrorRef pointer.
   9173   RecordDecl *CFError = nullptr;
   9174 
   9175   /// Retrieve the identifier "NSError".
   9176   IdentifierInfo *getNSErrorIdent();
   9177 
   9178   /// \brief Retrieve the parser's current scope.
   9179   ///
   9180   /// This routine must only be used when it is certain that semantic analysis
   9181   /// and the parser are in precisely the same context, which is not the case
   9182   /// when, e.g., we are performing any kind of template instantiation.
   9183   /// Therefore, the only safe places to use this scope are in the parser
   9184   /// itself and in routines directly invoked from the parser and *never* from
   9185   /// template substitution or instantiation.
   9186   Scope *getCurScope() const { return CurScope; }
   9187 
   9188   void incrementMSManglingNumber() const {
   9189     return CurScope->incrementMSManglingNumber();
   9190   }
   9191 
   9192   IdentifierInfo *getSuperIdentifier() const;
   9193   IdentifierInfo *getFloat128Identifier() const;
   9194 
   9195   Decl *getObjCDeclContext() const;
   9196 
   9197   DeclContext *getCurLexicalContext() const {
   9198     return OriginalLexicalContext ? OriginalLexicalContext : CurContext;
   9199   }
   9200 
   9201   AvailabilityResult getCurContextAvailability() const;
   9202 
   9203   const DeclContext *getCurObjCLexicalContext() const {
   9204     const DeclContext *DC = getCurLexicalContext();
   9205     // A category implicitly has the attribute of the interface.
   9206     if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(DC))
   9207       DC = CatD->getClassInterface();
   9208     return DC;
   9209   }
   9210 
   9211   /// \brief To be used for checking whether the arguments being passed to
   9212   /// function exceeds the number of parameters expected for it.
   9213   static bool TooManyArguments(size_t NumParams, size_t NumArgs,
   9214                                bool PartialOverloading = false) {
   9215     // We check whether we're just after a comma in code-completion.
   9216     if (NumArgs > 0 && PartialOverloading)
   9217       return NumArgs + 1 > NumParams; // If so, we view as an extra argument.
   9218     return NumArgs > NumParams;
   9219   }
   9220 
   9221   // Emitting members of dllexported classes is delayed until the class
   9222   // (including field initializers) is fully parsed.
   9223   SmallVector<CXXRecordDecl*, 4> DelayedDllExportClasses;
   9224 };
   9225 
   9226 /// \brief RAII object that enters a new expression evaluation context.
   9227 class EnterExpressionEvaluationContext {
   9228   Sema &Actions;
   9229 
   9230 public:
   9231   EnterExpressionEvaluationContext(Sema &Actions,
   9232                                    Sema::ExpressionEvaluationContext NewContext,
   9233                                    Decl *LambdaContextDecl = nullptr,
   9234                                    bool IsDecltype = false)
   9235     : Actions(Actions) {
   9236     Actions.PushExpressionEvaluationContext(NewContext, LambdaContextDecl,
   9237                                             IsDecltype);
   9238   }
   9239   EnterExpressionEvaluationContext(Sema &Actions,
   9240                                    Sema::ExpressionEvaluationContext NewContext,
   9241                                    Sema::ReuseLambdaContextDecl_t,
   9242                                    bool IsDecltype = false)
   9243     : Actions(Actions) {
   9244     Actions.PushExpressionEvaluationContext(NewContext,
   9245                                             Sema::ReuseLambdaContextDecl,
   9246                                             IsDecltype);
   9247   }
   9248 
   9249   ~EnterExpressionEvaluationContext() {
   9250     Actions.PopExpressionEvaluationContext();
   9251   }
   9252 };
   9253 
   9254 DeductionFailureInfo
   9255 MakeDeductionFailureInfo(ASTContext &Context, Sema::TemplateDeductionResult TDK,
   9256                          sema::TemplateDeductionInfo &Info);
   9257 
   9258 /// \brief Contains a late templated function.
   9259 /// Will be parsed at the end of the translation unit, used by Sema & Parser.
   9260 struct LateParsedTemplate {
   9261   CachedTokens Toks;
   9262   /// \brief The template function declaration to be late parsed.
   9263   Decl *D;
   9264 };
   9265 
   9266 } // end namespace clang
   9267 
   9268 #endif
   9269