clang API Documentation

Sema.h
Go to the documentation of this file.
00001 //===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the Sema class, which performs semantic analysis and
00011 // builds ASTs.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_CLANG_SEMA_SEMA_H
00016 #define LLVM_CLANG_SEMA_SEMA_H
00017 
00018 #include "clang/AST/Attr.h"
00019 #include "clang/AST/DeclarationName.h"
00020 #include "clang/AST/Expr.h"
00021 #include "clang/AST/ExprObjC.h"
00022 #include "clang/AST/ExternalASTSource.h"
00023 #include "clang/AST/MangleNumberingContext.h"
00024 #include "clang/AST/NSAPI.h"
00025 #include "clang/AST/PrettyPrinter.h"
00026 #include "clang/AST/TypeLoc.h"
00027 #include "clang/Basic/ExpressionTraits.h"
00028 #include "clang/Basic/LangOptions.h"
00029 #include "clang/Basic/Module.h"
00030 #include "clang/Basic/OpenMPKinds.h"
00031 #include "clang/Basic/Specifiers.h"
00032 #include "clang/Basic/TemplateKinds.h"
00033 #include "clang/Basic/TypeTraits.h"
00034 #include "clang/Sema/AnalysisBasedWarnings.h"
00035 #include "clang/Sema/DeclSpec.h"
00036 #include "clang/Sema/ExternalSemaSource.h"
00037 #include "clang/Sema/IdentifierResolver.h"
00038 #include "clang/Sema/LocInfoType.h"
00039 #include "clang/Sema/ObjCMethodList.h"
00040 #include "clang/Sema/Ownership.h"
00041 #include "clang/Sema/Scope.h"
00042 #include "clang/Sema/ScopeInfo.h"
00043 #include "clang/Sema/TypoCorrection.h"
00044 #include "clang/Sema/Weak.h"
00045 #include "llvm/ADT/ArrayRef.h"
00046 #include "llvm/ADT/Optional.h"
00047 #include "llvm/ADT/SetVector.h"
00048 #include "llvm/ADT/SmallPtrSet.h"
00049 #include "llvm/ADT/SmallVector.h"
00050 #include "llvm/ADT/TinyPtrVector.h"
00051 #include <deque>
00052 #include <memory>
00053 #include <string>
00054 #include <vector>
00055 
00056 namespace llvm {
00057   class APSInt;
00058   template <typename ValueT> struct DenseMapInfo;
00059   template <typename ValueT, typename ValueInfoT> class DenseSet;
00060   class SmallBitVector;
00061   class InlineAsmIdentifierInfo;
00062 }
00063 
00064 namespace clang {
00065   class ADLResult;
00066   class ASTConsumer;
00067   class ASTContext;
00068   class ASTMutationListener;
00069   class ASTReader;
00070   class ASTWriter;
00071   class ArrayType;
00072   class AttributeList;
00073   class BlockDecl;
00074   class CapturedDecl;
00075   class CXXBasePath;
00076   class CXXBasePaths;
00077   class CXXBindTemporaryExpr;
00078   typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath;
00079   class CXXConstructorDecl;
00080   class CXXConversionDecl;
00081   class CXXDestructorDecl;
00082   class CXXFieldCollector;
00083   class CXXMemberCallExpr;
00084   class CXXMethodDecl;
00085   class CXXScopeSpec;
00086   class CXXTemporary;
00087   class CXXTryStmt;
00088   class CallExpr;
00089   class ClassTemplateDecl;
00090   class ClassTemplatePartialSpecializationDecl;
00091   class ClassTemplateSpecializationDecl;
00092   class VarTemplatePartialSpecializationDecl;
00093   class CodeCompleteConsumer;
00094   class CodeCompletionAllocator;
00095   class CodeCompletionTUInfo;
00096   class CodeCompletionResult;
00097   class Decl;
00098   class DeclAccessPair;
00099   class DeclContext;
00100   class DeclRefExpr;
00101   class DeclaratorDecl;
00102   class DeducedTemplateArgument;
00103   class DependentDiagnostic;
00104   class DesignatedInitExpr;
00105   class Designation;
00106   class EnableIfAttr;
00107   class EnumConstantDecl;
00108   class Expr;
00109   class ExtVectorType;
00110   class ExternalSemaSource;
00111   class FormatAttr;
00112   class FriendDecl;
00113   class FunctionDecl;
00114   class FunctionProtoType;
00115   class FunctionTemplateDecl;
00116   class ImplicitConversionSequence;
00117   class InitListExpr;
00118   class InitializationKind;
00119   class InitializationSequence;
00120   class InitializedEntity;
00121   class IntegerLiteral;
00122   class LabelStmt;
00123   class LambdaExpr;
00124   class LangOptions;
00125   class LocalInstantiationScope;
00126   class LookupResult;
00127   class MacroInfo;
00128   typedef ArrayRef<std::pair<IdentifierInfo *, SourceLocation>> ModuleIdPath;
00129   class ModuleLoader;
00130   class MultiLevelTemplateArgumentList;
00131   class NamedDecl;
00132   class ObjCCategoryDecl;
00133   class ObjCCategoryImplDecl;
00134   class ObjCCompatibleAliasDecl;
00135   class ObjCContainerDecl;
00136   class ObjCImplDecl;
00137   class ObjCImplementationDecl;
00138   class ObjCInterfaceDecl;
00139   class ObjCIvarDecl;
00140   template <class T> class ObjCList;
00141   class ObjCMessageExpr;
00142   class ObjCMethodDecl;
00143   class ObjCPropertyDecl;
00144   class ObjCProtocolDecl;
00145   class OMPThreadPrivateDecl;
00146   class OMPClause;
00147   class OverloadCandidateSet;
00148   class OverloadExpr;
00149   class ParenListExpr;
00150   class ParmVarDecl;
00151   class Preprocessor;
00152   class PseudoDestructorTypeStorage;
00153   class PseudoObjectExpr;
00154   class QualType;
00155   class StandardConversionSequence;
00156   class Stmt;
00157   class StringLiteral;
00158   class SwitchStmt;
00159   class TemplateArgument;
00160   class TemplateArgumentList;
00161   class TemplateArgumentLoc;
00162   class TemplateDecl;
00163   class TemplateParameterList;
00164   class TemplatePartialOrderingContext;
00165   class TemplateTemplateParmDecl;
00166   class Token;
00167   class TypeAliasDecl;
00168   class TypedefDecl;
00169   class TypedefNameDecl;
00170   class TypeLoc;
00171   class TypoCorrectionConsumer;
00172   class UnqualifiedId;
00173   class UnresolvedLookupExpr;
00174   class UnresolvedMemberExpr;
00175   class UnresolvedSetImpl;
00176   class UnresolvedSetIterator;
00177   class UsingDecl;
00178   class UsingShadowDecl;
00179   class ValueDecl;
00180   class VarDecl;
00181   class VarTemplateSpecializationDecl;
00182   class VisibilityAttr;
00183   class VisibleDeclConsumer;
00184   class IndirectFieldDecl;
00185   struct DeductionFailureInfo;
00186   class TemplateSpecCandidateSet;
00187 
00188 namespace sema {
00189   class AccessedEntity;
00190   class BlockScopeInfo;
00191   class CapturedRegionScopeInfo;
00192   class CapturingScopeInfo;
00193   class CompoundScopeInfo;
00194   class DelayedDiagnostic;
00195   class DelayedDiagnosticPool;
00196   class FunctionScopeInfo;
00197   class LambdaScopeInfo;
00198   class PossiblyUnreachableDiag;
00199   class TemplateDeductionInfo;
00200 }
00201 
00202 // FIXME: No way to easily map from TemplateTypeParmTypes to
00203 // TemplateTypeParmDecls, so we have this horrible PointerUnion.
00204 typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType*, NamedDecl*>,
00205                   SourceLocation> UnexpandedParameterPack;
00206 
00207 /// Sema - This implements semantic analysis and AST building for C.
00208 class Sema {
00209   Sema(const Sema &) LLVM_DELETED_FUNCTION;
00210   void operator=(const Sema &) LLVM_DELETED_FUNCTION;
00211 
00212   ///\brief Source of additional semantic information.
00213   ExternalSemaSource *ExternalSource;
00214 
00215   ///\brief Whether Sema has generated a multiplexer and has to delete it.
00216   bool isMultiplexExternalSource;
00217 
00218   static bool mightHaveNonExternalLinkage(const DeclaratorDecl *FD);
00219 
00220   static bool
00221   shouldLinkPossiblyHiddenDecl(const NamedDecl *Old, const NamedDecl *New) {
00222     // We are about to link these. It is now safe to compute the linkage of
00223     // the new decl. If the new decl has external linkage, we will
00224     // link it with the hidden decl (which also has external linkage) and
00225     // it will keep having external linkage. If it has internal linkage, we
00226     // will not link it. Since it has no previous decls, it will remain
00227     // with internal linkage.
00228     return !Old->isHidden() || New->isExternallyVisible();
00229   }
00230 
00231 public:
00232   typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
00233   typedef OpaquePtr<TemplateName> TemplateTy;
00234   typedef OpaquePtr<QualType> TypeTy;
00235 
00236   OpenCLOptions OpenCLFeatures;
00237   FPOptions FPFeatures;
00238 
00239   const LangOptions &LangOpts;
00240   Preprocessor &PP;
00241   ASTContext &Context;
00242   ASTConsumer &Consumer;
00243   DiagnosticsEngine &Diags;
00244   SourceManager &SourceMgr;
00245 
00246   /// \brief Flag indicating whether or not to collect detailed statistics.
00247   bool CollectStats;
00248 
00249   /// \brief Code-completion consumer.
00250   CodeCompleteConsumer *CodeCompleter;
00251 
00252   /// CurContext - This is the current declaration context of parsing.
00253   DeclContext *CurContext;
00254 
00255   /// \brief Generally null except when we temporarily switch decl contexts,
00256   /// like in \see ActOnObjCTemporaryExitContainerContext.
00257   DeclContext *OriginalLexicalContext;
00258 
00259   /// VAListTagName - The declaration name corresponding to __va_list_tag.
00260   /// This is used as part of a hack to omit that class from ADL results.
00261   DeclarationName VAListTagName;
00262 
00263   /// PackContext - Manages the stack for \#pragma pack. An alignment
00264   /// of 0 indicates default alignment.
00265   void *PackContext; // Really a "PragmaPackStack*"
00266 
00267   bool MSStructPragmaOn; // True when \#pragma ms_struct on
00268 
00269   /// \brief Controls member pointer representation format under the MS ABI.
00270   LangOptions::PragmaMSPointersToMembersKind
00271       MSPointerToMemberRepresentationMethod;
00272 
00273   enum PragmaVtorDispKind {
00274     PVDK_Push,          ///< #pragma vtordisp(push, mode)
00275     PVDK_Set,           ///< #pragma vtordisp(mode)
00276     PVDK_Pop,           ///< #pragma vtordisp(pop)
00277     PVDK_Reset          ///< #pragma vtordisp()
00278   };
00279 
00280   enum PragmaMsStackAction {
00281     PSK_Reset,    // #pragma ()
00282     PSK_Set,      // #pragma ("name")
00283     PSK_Push,     // #pragma (push[, id])
00284     PSK_Push_Set, // #pragma (push[, id], "name")
00285     PSK_Pop,      // #pragma (pop[, id])
00286     PSK_Pop_Set,  // #pragma (pop[, id], "name")
00287   };
00288 
00289   /// \brief Whether to insert vtordisps prior to virtual bases in the Microsoft
00290   /// C++ ABI.  Possible values are 0, 1, and 2, which mean:
00291   ///
00292   /// 0: Suppress all vtordisps
00293   /// 1: Insert vtordisps in the presence of vbase overrides and non-trivial
00294   ///    structors
00295   /// 2: Always insert vtordisps to support RTTI on partially constructed
00296   ///    objects
00297   ///
00298   /// The stack always has at least one element in it.
00299   SmallVector<MSVtorDispAttr::Mode, 2> VtorDispModeStack;
00300 
00301   /// \brief Source location for newly created implicit MSInheritanceAttrs
00302   SourceLocation ImplicitMSInheritanceAttrLoc;
00303 
00304   template<typename ValueType>
00305   struct PragmaStack {
00306     struct Slot {
00307       llvm::StringRef StackSlotLabel;
00308       ValueType Value;
00309       SourceLocation PragmaLocation;
00310       Slot(llvm::StringRef StackSlotLabel,
00311            ValueType Value,
00312            SourceLocation PragmaLocation)
00313         : StackSlotLabel(StackSlotLabel), Value(Value),
00314           PragmaLocation(PragmaLocation) {}
00315     };
00316     void Act(SourceLocation PragmaLocation,
00317              PragmaMsStackAction Action,
00318              llvm::StringRef StackSlotLabel,
00319              ValueType Value);
00320     explicit PragmaStack(const ValueType &Value)
00321       : CurrentValue(Value) {}
00322     SmallVector<Slot, 2> Stack;
00323     ValueType CurrentValue;
00324     SourceLocation CurrentPragmaLocation;
00325   };
00326   // FIXME: We should serialize / deserialize these if they occur in a PCH (but
00327   // we shouldn't do so if they're in a module).
00328   PragmaStack<StringLiteral *> DataSegStack;
00329   PragmaStack<StringLiteral *> BSSSegStack;
00330   PragmaStack<StringLiteral *> ConstSegStack;
00331   PragmaStack<StringLiteral *> CodeSegStack;
00332 
00333   /// Last section used with #pragma init_seg.
00334   StringLiteral *CurInitSeg;
00335   SourceLocation CurInitSegLoc;
00336 
00337   /// VisContext - Manages the stack for \#pragma GCC visibility.
00338   void *VisContext; // Really a "PragmaVisStack*"
00339 
00340   /// \brief This represents the last location of a "#pragma clang optimize off"
00341   /// directive if such a directive has not been closed by an "on" yet. If
00342   /// optimizations are currently "on", this is set to an invalid location.
00343   SourceLocation OptimizeOffPragmaLocation;
00344 
00345   /// \brief Flag indicating if Sema is building a recovery call expression.
00346   ///
00347   /// This flag is used to avoid building recovery call expressions
00348   /// if Sema is already doing so, which would cause infinite recursions.
00349   bool IsBuildingRecoveryCallExpr;
00350 
00351   /// ExprNeedsCleanups - True if the current evaluation context
00352   /// requires cleanups to be run at its conclusion.
00353   bool ExprNeedsCleanups;
00354 
00355   /// ExprCleanupObjects - This is the stack of objects requiring
00356   /// cleanup that are created by the current full expression.  The
00357   /// element type here is ExprWithCleanups::Object.
00358   SmallVector<BlockDecl*, 8> ExprCleanupObjects;
00359 
00360   /// \brief Store a list of either DeclRefExprs or MemberExprs
00361   ///  that contain a reference to a variable (constant) that may or may not
00362   ///  be odr-used in this Expr, and we won't know until all lvalue-to-rvalue
00363   ///  and discarded value conversions have been applied to all subexpressions 
00364   ///  of the enclosing full expression.  This is cleared at the end of each 
00365   ///  full expression. 
00366   llvm::SmallPtrSet<Expr*, 2> MaybeODRUseExprs;
00367 
00368   /// \brief Stack containing information about each of the nested
00369   /// function, block, and method scopes that are currently active.
00370   ///
00371   /// This array is never empty.  Clients should ignore the first
00372   /// element, which is used to cache a single FunctionScopeInfo
00373   /// that's used to parse every top-level function.
00374   SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes;
00375 
00376   typedef LazyVector<TypedefNameDecl *, ExternalSemaSource,
00377                      &ExternalSemaSource::ReadExtVectorDecls, 2, 2>
00378     ExtVectorDeclsType;
00379 
00380   /// ExtVectorDecls - This is a list all the extended vector types. This allows
00381   /// us to associate a raw vector type with one of the ext_vector type names.
00382   /// This is only necessary for issuing pretty diagnostics.
00383   ExtVectorDeclsType ExtVectorDecls;
00384 
00385   /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
00386   std::unique_ptr<CXXFieldCollector> FieldCollector;
00387 
00388   typedef llvm::SmallSetVector<const NamedDecl*, 16> NamedDeclSetType;
00389 
00390   /// \brief Set containing all declared private fields that are not used.
00391   NamedDeclSetType UnusedPrivateFields;
00392 
00393   /// \brief Set containing all typedefs that are likely unused.
00394   llvm::SmallSetVector<const TypedefNameDecl *, 4>
00395       UnusedLocalTypedefNameCandidates;
00396 
00397   typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy;
00398 
00399   /// PureVirtualClassDiagSet - a set of class declarations which we have
00400   /// emitted a list of pure virtual functions. Used to prevent emitting the
00401   /// same list more than once.
00402   std::unique_ptr<RecordDeclSetTy> PureVirtualClassDiagSet;
00403 
00404   /// ParsingInitForAutoVars - a set of declarations with auto types for which
00405   /// we are currently parsing the initializer.
00406   llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars;
00407 
00408   /// \brief A mapping from external names to the most recent
00409   /// locally-scoped extern "C" declaration with that name.
00410   ///
00411   /// This map contains external declarations introduced in local
00412   /// scopes, e.g.,
00413   ///
00414   /// \code
00415   /// extern "C" void f() {
00416   ///   void foo(int, int);
00417   /// }
00418   /// \endcode
00419   ///
00420   /// Here, the name "foo" will be associated with the declaration of
00421   /// "foo" within f. This name is not visible outside of
00422   /// "f". However, we still find it in two cases:
00423   ///
00424   ///   - If we are declaring another global or extern "C" entity with
00425   ///     the name "foo", we can find "foo" as a previous declaration,
00426   ///     so that the types of this external declaration can be checked
00427   ///     for compatibility.
00428   ///
00429   ///   - If we would implicitly declare "foo" (e.g., due to a call to
00430   ///     "foo" in C when no prototype or definition is visible), then
00431   ///     we find this declaration of "foo" and complain that it is
00432   ///     not visible.
00433   llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternCDecls;
00434 
00435   /// \brief Look for a locally scoped extern "C" declaration by the given name.
00436   NamedDecl *findLocallyScopedExternCDecl(DeclarationName Name);
00437 
00438   typedef LazyVector<VarDecl *, ExternalSemaSource,
00439                      &ExternalSemaSource::ReadTentativeDefinitions, 2, 2>
00440     TentativeDefinitionsType;
00441 
00442   /// \brief All the tentative definitions encountered in the TU.
00443   TentativeDefinitionsType TentativeDefinitions;
00444 
00445   typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource,
00446                      &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2>
00447     UnusedFileScopedDeclsType;
00448 
00449   /// \brief The set of file scoped decls seen so far that have not been used
00450   /// and must warn if not used. Only contains the first declaration.
00451   UnusedFileScopedDeclsType UnusedFileScopedDecls;
00452 
00453   typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource,
00454                      &ExternalSemaSource::ReadDelegatingConstructors, 2, 2>
00455     DelegatingCtorDeclsType;
00456 
00457   /// \brief All the delegating constructors seen so far in the file, used for
00458   /// cycle detection at the end of the TU.
00459   DelegatingCtorDeclsType DelegatingCtorDecls;
00460 
00461   /// \brief All the overriding destructors seen during a class definition
00462   /// (there could be multiple due to nested classes) that had their exception
00463   /// spec checks delayed, plus the overridden destructor.
00464   SmallVector<std::pair<const CXXDestructorDecl*,
00465                               const CXXDestructorDecl*>, 2>
00466       DelayedDestructorExceptionSpecChecks;
00467 
00468   /// \brief All the members seen during a class definition which were both
00469   /// explicitly defaulted and had explicitly-specified exception
00470   /// specifications, along with the function type containing their
00471   /// user-specified exception specification. Those exception specifications
00472   /// were overridden with the default specifications, but we still need to
00473   /// check whether they are compatible with the default specification, and
00474   /// we can't do that until the nesting set of class definitions is complete.
00475   SmallVector<std::pair<CXXMethodDecl*, const FunctionProtoType*>, 2>
00476     DelayedDefaultedMemberExceptionSpecs;
00477 
00478   typedef llvm::DenseMap<const FunctionDecl *, LateParsedTemplate *>
00479   LateParsedTemplateMapT;
00480   LateParsedTemplateMapT LateParsedTemplateMap;
00481 
00482   /// \brief Callback to the parser to parse templated functions when needed.
00483   typedef void LateTemplateParserCB(void *P, LateParsedTemplate &LPT);
00484   typedef void LateTemplateParserCleanupCB(void *P);
00485   LateTemplateParserCB *LateTemplateParser;
00486   LateTemplateParserCleanupCB *LateTemplateParserCleanup;
00487   void *OpaqueParser;
00488 
00489   void SetLateTemplateParser(LateTemplateParserCB *LTP,
00490                              LateTemplateParserCleanupCB *LTPCleanup,
00491                              void *P) {
00492     LateTemplateParser = LTP;
00493     LateTemplateParserCleanup = LTPCleanup;
00494     OpaqueParser = P;
00495   }
00496 
00497   class DelayedDiagnostics;
00498 
00499   class DelayedDiagnosticsState {
00500     sema::DelayedDiagnosticPool *SavedPool;
00501     friend class Sema::DelayedDiagnostics;
00502   };
00503   typedef DelayedDiagnosticsState ParsingDeclState;
00504   typedef DelayedDiagnosticsState ProcessingContextState;
00505 
00506   /// A class which encapsulates the logic for delaying diagnostics
00507   /// during parsing and other processing.
00508   class DelayedDiagnostics {
00509     /// \brief The current pool of diagnostics into which delayed
00510     /// diagnostics should go.
00511     sema::DelayedDiagnosticPool *CurPool;
00512 
00513   public:
00514     DelayedDiagnostics() : CurPool(nullptr) {}
00515 
00516     /// Adds a delayed diagnostic.
00517     void add(const sema::DelayedDiagnostic &diag); // in DelayedDiagnostic.h
00518 
00519     /// Determines whether diagnostics should be delayed.
00520     bool shouldDelayDiagnostics() { return CurPool != nullptr; }
00521 
00522     /// Returns the current delayed-diagnostics pool.
00523     sema::DelayedDiagnosticPool *getCurrentPool() const {
00524       return CurPool;
00525     }
00526 
00527     /// Enter a new scope.  Access and deprecation diagnostics will be
00528     /// collected in this pool.
00529     DelayedDiagnosticsState push(sema::DelayedDiagnosticPool &pool) {
00530       DelayedDiagnosticsState state;
00531       state.SavedPool = CurPool;
00532       CurPool = &pool;
00533       return state;
00534     }
00535 
00536     /// Leave a delayed-diagnostic state that was previously pushed.
00537     /// Do not emit any of the diagnostics.  This is performed as part
00538     /// of the bookkeeping of popping a pool "properly".
00539     void popWithoutEmitting(DelayedDiagnosticsState state) {
00540       CurPool = state.SavedPool;
00541     }
00542 
00543     /// Enter a new scope where access and deprecation diagnostics are
00544     /// not delayed.
00545     DelayedDiagnosticsState pushUndelayed() {
00546       DelayedDiagnosticsState state;
00547       state.SavedPool = CurPool;
00548       CurPool = nullptr;
00549       return state;
00550     }
00551 
00552     /// Undo a previous pushUndelayed().
00553     void popUndelayed(DelayedDiagnosticsState state) {
00554       assert(CurPool == nullptr);
00555       CurPool = state.SavedPool;
00556     }
00557   } DelayedDiagnostics;
00558 
00559   /// A RAII object to temporarily push a declaration context.
00560   class ContextRAII {
00561   private:
00562     Sema &S;
00563     DeclContext *SavedContext;
00564     ProcessingContextState SavedContextState;
00565     QualType SavedCXXThisTypeOverride;
00566 
00567   public:
00568     ContextRAII(Sema &S, DeclContext *ContextToPush, bool NewThisContext = true)
00569       : S(S), SavedContext(S.CurContext),
00570         SavedContextState(S.DelayedDiagnostics.pushUndelayed()),
00571         SavedCXXThisTypeOverride(S.CXXThisTypeOverride)
00572     {
00573       assert(ContextToPush && "pushing null context");
00574       S.CurContext = ContextToPush;
00575       if (NewThisContext)
00576         S.CXXThisTypeOverride = QualType();
00577     }
00578 
00579     void pop() {
00580       if (!SavedContext) return;
00581       S.CurContext = SavedContext;
00582       S.DelayedDiagnostics.popUndelayed(SavedContextState);
00583       S.CXXThisTypeOverride = SavedCXXThisTypeOverride;
00584       SavedContext = nullptr;
00585     }
00586 
00587     ~ContextRAII() {
00588       pop();
00589     }
00590   };
00591 
00592   /// \brief RAII object to handle the state changes required to synthesize
00593   /// a function body.
00594   class SynthesizedFunctionScope {
00595     Sema &S;
00596     Sema::ContextRAII SavedContext;
00597     
00598   public:
00599     SynthesizedFunctionScope(Sema &S, DeclContext *DC)
00600       : S(S), SavedContext(S, DC) 
00601     {
00602       S.PushFunctionScope();
00603       S.PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
00604     }
00605     
00606     ~SynthesizedFunctionScope() {
00607       S.PopExpressionEvaluationContext();
00608       S.PopFunctionScopeInfo();
00609     }
00610   };
00611 
00612   /// WeakUndeclaredIdentifiers - Identifiers contained in
00613   /// \#pragma weak before declared. rare. may alias another
00614   /// identifier, declared or undeclared
00615   llvm::DenseMap<IdentifierInfo*,WeakInfo> WeakUndeclaredIdentifiers;
00616 
00617   /// ExtnameUndeclaredIdentifiers - Identifiers contained in
00618   /// \#pragma redefine_extname before declared.  Used in Solaris system headers
00619   /// to define functions that occur in multiple standards to call the version
00620   /// in the currently selected standard.
00621   llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*> ExtnameUndeclaredIdentifiers;
00622 
00623 
00624   /// \brief Load weak undeclared identifiers from the external source.
00625   void LoadExternalWeakUndeclaredIdentifiers();
00626 
00627   /// WeakTopLevelDecl - Translation-unit scoped declarations generated by
00628   /// \#pragma weak during processing of other Decls.
00629   /// I couldn't figure out a clean way to generate these in-line, so
00630   /// we store them here and handle separately -- which is a hack.
00631   /// It would be best to refactor this.
00632   SmallVector<Decl*,2> WeakTopLevelDecl;
00633 
00634   IdentifierResolver IdResolver;
00635 
00636   /// Translation Unit Scope - useful to Objective-C actions that need
00637   /// to lookup file scope declarations in the "ordinary" C decl namespace.
00638   /// For example, user-defined classes, built-in "id" type, etc.
00639   Scope *TUScope;
00640 
00641   /// \brief The C++ "std" namespace, where the standard library resides.
00642   LazyDeclPtr StdNamespace;
00643 
00644   /// \brief The C++ "std::bad_alloc" class, which is defined by the C++
00645   /// standard library.
00646   LazyDeclPtr StdBadAlloc;
00647 
00648   /// \brief The C++ "std::initializer_list" template, which is defined in
00649   /// <initializer_list>.
00650   ClassTemplateDecl *StdInitializerList;
00651 
00652   /// \brief The C++ "type_info" declaration, which is defined in <typeinfo>.
00653   RecordDecl *CXXTypeInfoDecl;
00654 
00655   /// \brief The MSVC "_GUID" struct, which is defined in MSVC header files.
00656   RecordDecl *MSVCGuidDecl;
00657 
00658   /// \brief Caches identifiers/selectors for NSFoundation APIs.
00659   std::unique_ptr<NSAPI> NSAPIObj;
00660 
00661   /// \brief The declaration of the Objective-C NSNumber class.
00662   ObjCInterfaceDecl *NSNumberDecl;
00663 
00664   /// \brief Pointer to NSNumber type (NSNumber *).
00665   QualType NSNumberPointer;
00666 
00667   /// \brief The Objective-C NSNumber methods used to create NSNumber literals.
00668   ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods];
00669 
00670   /// \brief The declaration of the Objective-C NSString class.
00671   ObjCInterfaceDecl *NSStringDecl;
00672 
00673   /// \brief Pointer to NSString type (NSString *).
00674   QualType NSStringPointer;
00675 
00676   /// \brief The declaration of the stringWithUTF8String: method.
00677   ObjCMethodDecl *StringWithUTF8StringMethod;
00678 
00679   /// \brief The declaration of the Objective-C NSArray class.
00680   ObjCInterfaceDecl *NSArrayDecl;
00681 
00682   /// \brief The declaration of the arrayWithObjects:count: method.
00683   ObjCMethodDecl *ArrayWithObjectsMethod;
00684 
00685   /// \brief The declaration of the Objective-C NSDictionary class.
00686   ObjCInterfaceDecl *NSDictionaryDecl;
00687 
00688   /// \brief The declaration of the dictionaryWithObjects:forKeys:count: method.
00689   ObjCMethodDecl *DictionaryWithObjectsMethod;
00690 
00691   /// \brief id<NSCopying> type.
00692   QualType QIDNSCopying;
00693 
00694   /// \brief will hold 'respondsToSelector:'
00695   Selector RespondsToSelectorSel;
00696 
00697   /// \brief counter for internal MS Asm label names.
00698   unsigned MSAsmLabelNameCounter;
00699 
00700   /// A flag to remember whether the implicit forms of operator new and delete
00701   /// have been declared.
00702   bool GlobalNewDeleteDeclared;
00703 
00704   /// A flag to indicate that we're in a context that permits abstract
00705   /// references to fields.  This is really a 
00706   bool AllowAbstractFieldReference;
00707 
00708   /// \brief Describes how the expressions currently being parsed are
00709   /// evaluated at run-time, if at all.
00710   enum ExpressionEvaluationContext {
00711     /// \brief The current expression and its subexpressions occur within an
00712     /// unevaluated operand (C++11 [expr]p7), such as the subexpression of
00713     /// \c sizeof, where the type of the expression may be significant but
00714     /// no code will be generated to evaluate the value of the expression at
00715     /// run time.
00716     Unevaluated,
00717 
00718     /// \brief The current expression occurs within an unevaluated
00719     /// operand that unconditionally permits abstract references to
00720     /// fields, such as a SIZE operator in MS-style inline assembly.
00721     UnevaluatedAbstract,
00722 
00723     /// \brief The current context is "potentially evaluated" in C++11 terms,
00724     /// but the expression is evaluated at compile-time (like the values of
00725     /// cases in a switch statement).
00726     ConstantEvaluated,
00727 
00728     /// \brief The current expression is potentially evaluated at run time,
00729     /// which means that code may be generated to evaluate the value of the
00730     /// expression at run time.
00731     PotentiallyEvaluated,
00732 
00733     /// \brief The current expression is potentially evaluated, but any
00734     /// declarations referenced inside that expression are only used if
00735     /// in fact the current expression is used.
00736     ///
00737     /// This value is used when parsing default function arguments, for which
00738     /// we would like to provide diagnostics (e.g., passing non-POD arguments
00739     /// through varargs) but do not want to mark declarations as "referenced"
00740     /// until the default argument is used.
00741     PotentiallyEvaluatedIfUsed
00742   };
00743 
00744   /// \brief Data structure used to record current or nested
00745   /// expression evaluation contexts.
00746   struct ExpressionEvaluationContextRecord {
00747     /// \brief The expression evaluation context.
00748     ExpressionEvaluationContext Context;
00749 
00750     /// \brief Whether the enclosing context needed a cleanup.
00751     bool ParentNeedsCleanups;
00752 
00753     /// \brief Whether we are in a decltype expression.
00754     bool IsDecltype;
00755 
00756     /// \brief The number of active cleanup objects when we entered
00757     /// this expression evaluation context.
00758     unsigned NumCleanupObjects;
00759 
00760     /// \brief The number of typos encountered during this expression evaluation
00761     /// context (i.e. the number of TypoExprs created).
00762     unsigned NumTypos;
00763 
00764     llvm::SmallPtrSet<Expr*, 2> SavedMaybeODRUseExprs;
00765 
00766     /// \brief The lambdas that are present within this context, if it
00767     /// is indeed an unevaluated context.
00768     SmallVector<LambdaExpr *, 2> Lambdas;
00769 
00770     /// \brief The declaration that provides context for lambda expressions
00771     /// and block literals if the normal declaration context does not
00772     /// suffice, e.g., in a default function argument.
00773     Decl *ManglingContextDecl;
00774 
00775     /// \brief The context information used to mangle lambda expressions
00776     /// and block literals within this context.
00777     ///
00778     /// This mangling information is allocated lazily, since most contexts
00779     /// do not have lambda expressions or block literals.
00780     IntrusiveRefCntPtr<MangleNumberingContext> MangleNumbering;
00781 
00782     /// \brief If we are processing a decltype type, a set of call expressions
00783     /// for which we have deferred checking the completeness of the return type.
00784     SmallVector<CallExpr *, 8> DelayedDecltypeCalls;
00785 
00786     /// \brief If we are processing a decltype type, a set of temporary binding
00787     /// expressions for which we have deferred checking the destructor.
00788     SmallVector<CXXBindTemporaryExpr *, 8> DelayedDecltypeBinds;
00789 
00790     ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context,
00791                                       unsigned NumCleanupObjects,
00792                                       bool ParentNeedsCleanups,
00793                                       Decl *ManglingContextDecl,
00794                                       bool IsDecltype)
00795       : Context(Context), ParentNeedsCleanups(ParentNeedsCleanups),
00796         IsDecltype(IsDecltype), NumCleanupObjects(NumCleanupObjects),
00797         NumTypos(0),
00798         ManglingContextDecl(ManglingContextDecl), MangleNumbering() { }
00799 
00800     /// \brief Retrieve the mangling numbering context, used to consistently
00801     /// number constructs like lambdas for mangling.
00802     MangleNumberingContext &getMangleNumberingContext(ASTContext &Ctx);
00803 
00804     bool isUnevaluated() const {
00805       return Context == Unevaluated || Context == UnevaluatedAbstract;
00806     }
00807   };
00808 
00809   /// A stack of expression evaluation contexts.
00810   SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts;
00811 
00812   /// \brief Compute the mangling number context for a lambda expression or
00813   /// block literal.
00814   ///
00815   /// \param DC - The DeclContext containing the lambda expression or
00816   /// block literal.
00817   /// \param[out] ManglingContextDecl - Returns the ManglingContextDecl
00818   /// associated with the context, if relevant.
00819   MangleNumberingContext *getCurrentMangleNumberContext(
00820     const DeclContext *DC,
00821     Decl *&ManglingContextDecl);
00822 
00823 
00824   /// SpecialMemberOverloadResult - The overloading result for a special member
00825   /// function.
00826   ///
00827   /// This is basically a wrapper around PointerIntPair. The lowest bits of the
00828   /// integer are used to determine whether overload resolution succeeded.
00829   class SpecialMemberOverloadResult : public llvm::FastFoldingSetNode {
00830   public:
00831     enum Kind {
00832       NoMemberOrDeleted,
00833       Ambiguous,
00834       Success
00835     };
00836 
00837   private:
00838     llvm::PointerIntPair<CXXMethodDecl*, 2> Pair;
00839 
00840   public:
00841     SpecialMemberOverloadResult(const llvm::FoldingSetNodeID &ID)
00842       : FastFoldingSetNode(ID)
00843     {}
00844 
00845     CXXMethodDecl *getMethod() const { return Pair.getPointer(); }
00846     void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); }
00847 
00848     Kind getKind() const { return static_cast<Kind>(Pair.getInt()); }
00849     void setKind(Kind K) { Pair.setInt(K); }
00850   };
00851 
00852   /// \brief A cache of special member function overload resolution results
00853   /// for C++ records.
00854   llvm::FoldingSet<SpecialMemberOverloadResult> SpecialMemberCache;
00855 
00856   /// \brief The kind of translation unit we are processing.
00857   ///
00858   /// When we're processing a complete translation unit, Sema will perform
00859   /// end-of-translation-unit semantic tasks (such as creating
00860   /// initializers for tentative definitions in C) once parsing has
00861   /// completed. Modules and precompiled headers perform different kinds of
00862   /// checks.
00863   TranslationUnitKind TUKind;
00864 
00865   llvm::BumpPtrAllocator BumpAlloc;
00866 
00867   /// \brief The number of SFINAE diagnostics that have been trapped.
00868   unsigned NumSFINAEErrors;
00869 
00870   typedef llvm::DenseMap<ParmVarDecl *, llvm::TinyPtrVector<ParmVarDecl *>>
00871     UnparsedDefaultArgInstantiationsMap;
00872 
00873   /// \brief A mapping from parameters with unparsed default arguments to the
00874   /// set of instantiations of each parameter.
00875   ///
00876   /// This mapping is a temporary data structure used when parsing
00877   /// nested class templates or nested classes of class templates,
00878   /// where we might end up instantiating an inner class before the
00879   /// default arguments of its methods have been parsed.
00880   UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations;
00881 
00882   // Contains the locations of the beginning of unparsed default
00883   // argument locations.
00884   llvm::DenseMap<ParmVarDecl *, SourceLocation> UnparsedDefaultArgLocs;
00885 
00886   /// UndefinedInternals - all the used, undefined objects which require a
00887   /// definition in this translation unit.
00888   llvm::DenseMap<NamedDecl *, SourceLocation> UndefinedButUsed;
00889 
00890   /// Obtain a sorted list of functions that are undefined but ODR-used.
00891   void getUndefinedButUsed(
00892       SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined);
00893 
00894   typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods;
00895   typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool;
00896 
00897   /// Method Pool - allows efficient lookup when typechecking messages to "id".
00898   /// We need to maintain a list, since selectors can have differing signatures
00899   /// across classes. In Cocoa, this happens to be extremely uncommon (only 1%
00900   /// of selectors are "overloaded").
00901   /// At the head of the list it is recorded whether there were 0, 1, or >= 2
00902   /// methods inside categories with a particular selector.
00903   GlobalMethodPool MethodPool;
00904 
00905   /// Method selectors used in a \@selector expression. Used for implementation
00906   /// of -Wselector.
00907   llvm::DenseMap<Selector, SourceLocation> ReferencedSelectors;
00908 
00909   /// Kinds of C++ special members.
00910   enum CXXSpecialMember {
00911     CXXDefaultConstructor,
00912     CXXCopyConstructor,
00913     CXXMoveConstructor,
00914     CXXCopyAssignment,
00915     CXXMoveAssignment,
00916     CXXDestructor,
00917     CXXInvalid
00918   };
00919 
00920   typedef std::pair<CXXRecordDecl*, CXXSpecialMember> SpecialMemberDecl;
00921 
00922   /// The C++ special members which we are currently in the process of
00923   /// declaring. If this process recursively triggers the declaration of the
00924   /// same special member, we should act as if it is not yet declared.
00925   llvm::SmallSet<SpecialMemberDecl, 4> SpecialMembersBeingDeclared;
00926 
00927   void ReadMethodPool(Selector Sel);
00928 
00929   /// Private Helper predicate to check for 'self'.
00930   bool isSelfExpr(Expr *RExpr);
00931   bool isSelfExpr(Expr *RExpr, const ObjCMethodDecl *Method);
00932 
00933   /// \brief Cause the active diagnostic on the DiagosticsEngine to be
00934   /// emitted. This is closely coupled to the SemaDiagnosticBuilder class and
00935   /// should not be used elsewhere.
00936   void EmitCurrentDiagnostic(unsigned DiagID);
00937 
00938   /// Records and restores the FP_CONTRACT state on entry/exit of compound
00939   /// statements.
00940   class FPContractStateRAII {
00941   public:
00942     FPContractStateRAII(Sema& S)
00943       : S(S), OldFPContractState(S.FPFeatures.fp_contract) {}
00944     ~FPContractStateRAII() {
00945       S.FPFeatures.fp_contract = OldFPContractState;
00946     }
00947   private:
00948     Sema& S;
00949     bool OldFPContractState : 1;
00950   };
00951 
00952   void addImplicitTypedef(StringRef Name, QualType T);
00953 
00954 public:
00955   Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
00956        TranslationUnitKind TUKind = TU_Complete,
00957        CodeCompleteConsumer *CompletionConsumer = nullptr);
00958   ~Sema();
00959 
00960   /// \brief Perform initialization that occurs after the parser has been
00961   /// initialized but before it parses anything.
00962   void Initialize();
00963 
00964   const LangOptions &getLangOpts() const { return LangOpts; }
00965   OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; }
00966   FPOptions     &getFPOptions() { return FPFeatures; }
00967 
00968   DiagnosticsEngine &getDiagnostics() const { return Diags; }
00969   SourceManager &getSourceManager() const { return SourceMgr; }
00970   Preprocessor &getPreprocessor() const { return PP; }
00971   ASTContext &getASTContext() const { return Context; }
00972   ASTConsumer &getASTConsumer() const { return Consumer; }
00973   ASTMutationListener *getASTMutationListener() const;
00974   ExternalSemaSource* getExternalSource() const { return ExternalSource; }
00975 
00976   ///\brief Registers an external source. If an external source already exists,
00977   /// creates a multiplex external source and appends to it.
00978   ///
00979   ///\param[in] E - A non-null external sema source.
00980   ///
00981   void addExternalSource(ExternalSemaSource *E);
00982 
00983   void PrintStats() const;
00984 
00985   /// \brief Helper class that creates diagnostics with optional
00986   /// template instantiation stacks.
00987   ///
00988   /// This class provides a wrapper around the basic DiagnosticBuilder
00989   /// class that emits diagnostics. SemaDiagnosticBuilder is
00990   /// responsible for emitting the diagnostic (as DiagnosticBuilder
00991   /// does) and, if the diagnostic comes from inside a template
00992   /// instantiation, printing the template instantiation stack as
00993   /// well.
00994   class SemaDiagnosticBuilder : public DiagnosticBuilder {
00995     Sema &SemaRef;
00996     unsigned DiagID;
00997 
00998   public:
00999     SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID)
01000       : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { }
01001 
01002     ~SemaDiagnosticBuilder() {
01003       // If we aren't active, there is nothing to do.
01004       if (!isActive()) return;
01005 
01006       // Otherwise, we need to emit the diagnostic. First flush the underlying
01007       // DiagnosticBuilder data, and clear the diagnostic builder itself so it
01008       // won't emit the diagnostic in its own destructor.
01009       //
01010       // This seems wasteful, in that as written the DiagnosticBuilder dtor will
01011       // do its own needless checks to see if the diagnostic needs to be
01012       // emitted. However, because we take care to ensure that the builder
01013       // objects never escape, a sufficiently smart compiler will be able to
01014       // eliminate that code.
01015       FlushCounts();
01016       Clear();
01017 
01018       // Dispatch to Sema to emit the diagnostic.
01019       SemaRef.EmitCurrentDiagnostic(DiagID);
01020     }
01021 
01022     /// Teach operator<< to produce an object of the correct type.
01023     template<typename T>
01024     friend const SemaDiagnosticBuilder &operator<<(
01025         const SemaDiagnosticBuilder &Diag, const T &Value) {
01026       const DiagnosticBuilder &BaseDiag = Diag;
01027       BaseDiag << Value;
01028       return Diag;
01029     }
01030   };
01031 
01032   /// \brief Emit a diagnostic.
01033   SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
01034     DiagnosticBuilder DB = Diags.Report(Loc, DiagID);
01035     return SemaDiagnosticBuilder(DB, *this, DiagID);
01036   }
01037 
01038   /// \brief Emit a partial diagnostic.
01039   SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic& PD);
01040 
01041   /// \brief Build a partial diagnostic.
01042   PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h
01043 
01044   bool findMacroSpelling(SourceLocation &loc, StringRef name);
01045 
01046   /// \brief Get a string to suggest for zero-initialization of a type.
01047   std::string
01048   getFixItZeroInitializerForType(QualType T, SourceLocation Loc) const;
01049   std::string getFixItZeroLiteralForType(QualType T, SourceLocation Loc) const;
01050 
01051   /// \brief Calls \c Lexer::getLocForEndOfToken()
01052   SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset = 0);
01053 
01054   /// \brief Retrieve the module loader associated with the preprocessor.
01055   ModuleLoader &getModuleLoader() const;
01056 
01057   void emitAndClearUnusedLocalTypedefWarnings();
01058 
01059   void ActOnEndOfTranslationUnit();
01060 
01061   void CheckDelegatingCtorCycles();
01062 
01063   Scope *getScopeForContext(DeclContext *Ctx);
01064 
01065   void PushFunctionScope();
01066   void PushBlockScope(Scope *BlockScope, BlockDecl *Block);
01067   sema::LambdaScopeInfo *PushLambdaScope();
01068 
01069   /// \brief This is used to inform Sema what the current TemplateParameterDepth
01070   /// is during Parsing.  Currently it is used to pass on the depth
01071   /// when parsing generic lambda 'auto' parameters.
01072   void RecordParsingTemplateParameterDepth(unsigned Depth);
01073   
01074   void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD,
01075                                RecordDecl *RD,
01076                                CapturedRegionKind K);
01077   void
01078   PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP = nullptr,
01079                        const Decl *D = nullptr,
01080                        const BlockExpr *blkExpr = nullptr);
01081 
01082   sema::FunctionScopeInfo *getCurFunction() const {
01083     return FunctionScopes.back();
01084   }
01085   
01086   sema::FunctionScopeInfo *getEnclosingFunction() const {
01087     if (FunctionScopes.empty())
01088       return nullptr;
01089     
01090     for (int e = FunctionScopes.size()-1; e >= 0; --e) {
01091       if (isa<sema::BlockScopeInfo>(FunctionScopes[e]))
01092         continue;
01093       return FunctionScopes[e];
01094     }
01095     return nullptr;
01096   }
01097   
01098   template <typename ExprT>
01099   void recordUseOfEvaluatedWeak(const ExprT *E, bool IsRead=true) {
01100     if (!isUnevaluatedContext())
01101       getCurFunction()->recordUseOfWeak(E, IsRead);
01102   }
01103   
01104   void PushCompoundScope();
01105   void PopCompoundScope();
01106 
01107   sema::CompoundScopeInfo &getCurCompoundScope() const;
01108 
01109   bool hasAnyUnrecoverableErrorsInThisFunction() const;
01110 
01111   /// \brief Retrieve the current block, if any.
01112   sema::BlockScopeInfo *getCurBlock();
01113 
01114   /// \brief Retrieve the current lambda scope info, if any.
01115   sema::LambdaScopeInfo *getCurLambda();
01116 
01117   /// \brief Retrieve the current generic lambda info, if any.
01118   sema::LambdaScopeInfo *getCurGenericLambda();
01119 
01120   /// \brief Retrieve the current captured region, if any.
01121   sema::CapturedRegionScopeInfo *getCurCapturedRegion();
01122 
01123   /// WeakTopLevelDeclDecls - access to \#pragma weak-generated Decls
01124   SmallVectorImpl<Decl *> &WeakTopLevelDecls() { return WeakTopLevelDecl; }
01125 
01126   void ActOnComment(SourceRange Comment);
01127 
01128   //===--------------------------------------------------------------------===//
01129   // Type Analysis / Processing: SemaType.cpp.
01130   //
01131 
01132   QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs,
01133                               const DeclSpec *DS = nullptr);
01134   QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVRA,
01135                               const DeclSpec *DS = nullptr);
01136   QualType BuildPointerType(QualType T,
01137                             SourceLocation Loc, DeclarationName Entity);
01138   QualType BuildReferenceType(QualType T, bool LValueRef,
01139                               SourceLocation Loc, DeclarationName Entity);
01140   QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
01141                           Expr *ArraySize, unsigned Quals,
01142                           SourceRange Brackets, DeclarationName Entity);
01143   QualType BuildExtVectorType(QualType T, Expr *ArraySize,
01144                               SourceLocation AttrLoc);
01145 
01146   bool CheckFunctionReturnType(QualType T, SourceLocation Loc);
01147 
01148   /// \brief Build a function type.
01149   ///
01150   /// This routine checks the function type according to C++ rules and
01151   /// under the assumption that the result type and parameter types have
01152   /// just been instantiated from a template. It therefore duplicates
01153   /// some of the behavior of GetTypeForDeclarator, but in a much
01154   /// simpler form that is only suitable for this narrow use case.
01155   ///
01156   /// \param T The return type of the function.
01157   ///
01158   /// \param ParamTypes The parameter types of the function. This array
01159   /// will be modified to account for adjustments to the types of the
01160   /// function parameters.
01161   ///
01162   /// \param Loc The location of the entity whose type involves this
01163   /// function type or, if there is no such entity, the location of the
01164   /// type that will have function type.
01165   ///
01166   /// \param Entity The name of the entity that involves the function
01167   /// type, if known.
01168   ///
01169   /// \param EPI Extra information about the function type. Usually this will
01170   /// be taken from an existing function with the same prototype.
01171   ///
01172   /// \returns A suitable function type, if there are no errors. The
01173   /// unqualified type will always be a FunctionProtoType.
01174   /// Otherwise, returns a NULL type.
01175   QualType BuildFunctionType(QualType T,
01176                              MutableArrayRef<QualType> ParamTypes,
01177                              SourceLocation Loc, DeclarationName Entity,
01178                              const FunctionProtoType::ExtProtoInfo &EPI);
01179 
01180   QualType BuildMemberPointerType(QualType T, QualType Class,
01181                                   SourceLocation Loc,
01182                                   DeclarationName Entity);
01183   QualType BuildBlockPointerType(QualType T,
01184                                  SourceLocation Loc, DeclarationName Entity);
01185   QualType BuildParenType(QualType T);
01186   QualType BuildAtomicType(QualType T, SourceLocation Loc);
01187 
01188   TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S);
01189   TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy);
01190   TypeSourceInfo *GetTypeSourceInfoForDeclarator(Declarator &D, QualType T,
01191                                                TypeSourceInfo *ReturnTypeInfo);
01192 
01193   /// \brief Package the given type and TSI into a ParsedType.
01194   ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo);
01195   DeclarationNameInfo GetNameForDeclarator(Declarator &D);
01196   DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name);
01197   static QualType GetTypeFromParser(ParsedType Ty,
01198                                     TypeSourceInfo **TInfo = nullptr);
01199   CanThrowResult canThrow(const Expr *E);
01200   const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc,
01201                                                 const FunctionProtoType *FPT);
01202   void UpdateExceptionSpec(FunctionDecl *FD,
01203                            const FunctionProtoType::ExceptionSpecInfo &ESI);
01204   bool CheckSpecifiedExceptionType(QualType &T, const SourceRange &Range);
01205   bool CheckDistantExceptionSpec(QualType T);
01206   bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New);
01207   bool CheckEquivalentExceptionSpec(
01208       const FunctionProtoType *Old, SourceLocation OldLoc,
01209       const FunctionProtoType *New, SourceLocation NewLoc);
01210   bool CheckEquivalentExceptionSpec(
01211       const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
01212       const FunctionProtoType *Old, SourceLocation OldLoc,
01213       const FunctionProtoType *New, SourceLocation NewLoc,
01214       bool *MissingExceptionSpecification = nullptr,
01215       bool *MissingEmptyExceptionSpecification = nullptr,
01216       bool AllowNoexceptAllMatchWithNoSpec = false,
01217       bool IsOperatorNew = false);
01218   bool CheckExceptionSpecSubset(
01219       const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
01220       const FunctionProtoType *Superset, SourceLocation SuperLoc,
01221       const FunctionProtoType *Subset, SourceLocation SubLoc);
01222   bool CheckParamExceptionSpec(const PartialDiagnostic & NoteID,
01223       const FunctionProtoType *Target, SourceLocation TargetLoc,
01224       const FunctionProtoType *Source, SourceLocation SourceLoc);
01225 
01226   TypeResult ActOnTypeName(Scope *S, Declarator &D);
01227 
01228   /// \brief The parser has parsed the context-sensitive type 'instancetype'
01229   /// in an Objective-C message declaration. Return the appropriate type.
01230   ParsedType ActOnObjCInstanceType(SourceLocation Loc);
01231 
01232   /// \brief Abstract class used to diagnose incomplete types.
01233   struct TypeDiagnoser {
01234     bool Suppressed;
01235 
01236     TypeDiagnoser(bool Suppressed = false) : Suppressed(Suppressed) { }
01237 
01238     virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0;
01239     virtual ~TypeDiagnoser() {}
01240   };
01241 
01242   static int getPrintable(int I) { return I; }
01243   static unsigned getPrintable(unsigned I) { return I; }
01244   static bool getPrintable(bool B) { return B; }
01245   static const char * getPrintable(const char *S) { return S; }
01246   static StringRef getPrintable(StringRef S) { return S; }
01247   static const std::string &getPrintable(const std::string &S) { return S; }
01248   static const IdentifierInfo *getPrintable(const IdentifierInfo *II) {
01249     return II;
01250   }
01251   static DeclarationName getPrintable(DeclarationName N) { return N; }
01252   static QualType getPrintable(QualType T) { return T; }
01253   static SourceRange getPrintable(SourceRange R) { return R; }
01254   static SourceRange getPrintable(SourceLocation L) { return L; }
01255   static SourceRange getPrintable(Expr *E) { return E->getSourceRange(); }
01256   static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();}
01257 
01258   template<typename T1>
01259   class BoundTypeDiagnoser1 : public TypeDiagnoser {
01260     unsigned DiagID;
01261     const T1 &Arg1;
01262 
01263   public:
01264     BoundTypeDiagnoser1(unsigned DiagID, const T1 &Arg1)
01265       : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1) { }
01266     void diagnose(Sema &S, SourceLocation Loc, QualType T) override {
01267       if (Suppressed) return;
01268       S.Diag(Loc, DiagID) << getPrintable(Arg1) << T;
01269     }
01270 
01271     virtual ~BoundTypeDiagnoser1() { }
01272   };
01273 
01274   template<typename T1, typename T2>
01275   class BoundTypeDiagnoser2 : public TypeDiagnoser {
01276     unsigned DiagID;
01277     const T1 &Arg1;
01278     const T2 &Arg2;
01279 
01280   public:
01281     BoundTypeDiagnoser2(unsigned DiagID, const T1 &Arg1,
01282                                   const T2 &Arg2)
01283       : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1),
01284         Arg2(Arg2) { }
01285 
01286     void diagnose(Sema &S, SourceLocation Loc, QualType T) override {
01287       if (Suppressed) return;
01288       S.Diag(Loc, DiagID) << getPrintable(Arg1) << getPrintable(Arg2) << T;
01289     }
01290 
01291     virtual ~BoundTypeDiagnoser2() { }
01292   };
01293 
01294   template<typename T1, typename T2, typename T3>
01295   class BoundTypeDiagnoser3 : public TypeDiagnoser {
01296     unsigned DiagID;
01297     const T1 &Arg1;
01298     const T2 &Arg2;
01299     const T3 &Arg3;
01300 
01301   public:
01302     BoundTypeDiagnoser3(unsigned DiagID, const T1 &Arg1,
01303                                   const T2 &Arg2, const T3 &Arg3)
01304     : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1),
01305       Arg2(Arg2), Arg3(Arg3) { }
01306 
01307     void diagnose(Sema &S, SourceLocation Loc, QualType T) override {
01308       if (Suppressed) return;
01309       S.Diag(Loc, DiagID)
01310         << getPrintable(Arg1) << getPrintable(Arg2) << getPrintable(Arg3) << T;
01311     }
01312 
01313     virtual ~BoundTypeDiagnoser3() { }
01314   };
01315 
01316 private:
01317   bool RequireCompleteTypeImpl(SourceLocation Loc, QualType T,
01318                            TypeDiagnoser &Diagnoser);
01319 public:
01320   bool RequireCompleteType(SourceLocation Loc, QualType T,
01321                            TypeDiagnoser &Diagnoser);
01322   bool RequireCompleteType(SourceLocation Loc, QualType T,
01323                            unsigned DiagID);
01324 
01325   template<typename T1>
01326   bool RequireCompleteType(SourceLocation Loc, QualType T,
01327                            unsigned DiagID, const T1 &Arg1) {
01328     BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
01329     return RequireCompleteType(Loc, T, Diagnoser);
01330   }
01331 
01332   template<typename T1, typename T2>
01333   bool RequireCompleteType(SourceLocation Loc, QualType T,
01334                            unsigned DiagID, const T1 &Arg1, const T2 &Arg2) {
01335     BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
01336     return RequireCompleteType(Loc, T, Diagnoser);
01337   }
01338 
01339   template<typename T1, typename T2, typename T3>
01340   bool RequireCompleteType(SourceLocation Loc, QualType T,
01341                            unsigned DiagID, const T1 &Arg1, const T2 &Arg2,
01342                            const T3 &Arg3) {
01343     BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2,
01344                                                         Arg3);
01345     return RequireCompleteType(Loc, T, Diagnoser);
01346   }
01347 
01348   bool RequireCompleteExprType(Expr *E, TypeDiagnoser &Diagnoser);
01349   bool RequireCompleteExprType(Expr *E, unsigned DiagID);
01350 
01351   template<typename T1>
01352   bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1) {
01353     BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
01354     return RequireCompleteExprType(E, Diagnoser);
01355   }
01356 
01357   template<typename T1, typename T2>
01358   bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1,
01359                                const T2 &Arg2) {
01360     BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
01361     return RequireCompleteExprType(E, Diagnoser);
01362   }
01363 
01364   template<typename T1, typename T2, typename T3>
01365   bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1,
01366                                const T2 &Arg2, const T3 &Arg3) {
01367     BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2,
01368                                                         Arg3);
01369     return RequireCompleteExprType(E, Diagnoser);
01370   }
01371 
01372   bool RequireLiteralType(SourceLocation Loc, QualType T,
01373                           TypeDiagnoser &Diagnoser);
01374   bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID);
01375 
01376   template<typename T1>
01377   bool RequireLiteralType(SourceLocation Loc, QualType T,
01378                           unsigned DiagID, const T1 &Arg1) {
01379     BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
01380     return RequireLiteralType(Loc, T, Diagnoser);
01381   }
01382 
01383   template<typename T1, typename T2>
01384   bool RequireLiteralType(SourceLocation Loc, QualType T,
01385                           unsigned DiagID, const T1 &Arg1, const T2 &Arg2) {
01386     BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
01387     return RequireLiteralType(Loc, T, Diagnoser);
01388   }
01389 
01390   template<typename T1, typename T2, typename T3>
01391   bool RequireLiteralType(SourceLocation Loc, QualType T,
01392                           unsigned DiagID, const T1 &Arg1, const T2 &Arg2,
01393                           const T3 &Arg3) {
01394     BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2,
01395                                                         Arg3);
01396     return RequireLiteralType(Loc, T, Diagnoser);
01397   }
01398 
01399   QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
01400                              const CXXScopeSpec &SS, QualType T);
01401 
01402   QualType BuildTypeofExprType(Expr *E, SourceLocation Loc);
01403   QualType BuildDecltypeType(Expr *E, SourceLocation Loc);
01404   QualType BuildUnaryTransformType(QualType BaseType,
01405                                    UnaryTransformType::UTTKind UKind,
01406                                    SourceLocation Loc);
01407 
01408   //===--------------------------------------------------------------------===//
01409   // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
01410   //
01411 
01412   /// List of decls defined in a function prototype. This contains EnumConstants
01413   /// that incorrectly end up in translation unit scope because there is no
01414   /// function to pin them on. ActOnFunctionDeclarator reads this list and patches
01415   /// them into the FunctionDecl.
01416   std::vector<NamedDecl*> DeclsInPrototypeScope;
01417 
01418   DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = nullptr);
01419 
01420   void DiagnoseUseOfUnimplementedSelectors();
01421 
01422   bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
01423 
01424   ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
01425                          Scope *S, CXXScopeSpec *SS = nullptr,
01426                          bool isClassName = false,
01427                          bool HasTrailingDot = false,
01428                          ParsedType ObjectType = ParsedType(),
01429                          bool IsCtorOrDtorName = false,
01430                          bool WantNontrivialTypeSourceInfo = false,
01431                          IdentifierInfo **CorrectedII = nullptr);
01432   TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S);
01433   bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S);
01434   void DiagnoseUnknownTypeName(IdentifierInfo *&II,
01435                                SourceLocation IILoc,
01436                                Scope *S,
01437                                CXXScopeSpec *SS,
01438                                ParsedType &SuggestedType,
01439                                bool AllowClassTemplates = false);
01440 
01441   /// \brief For compatibility with MSVC, we delay parsing of some default
01442   /// template type arguments until instantiation time.  Emits a warning and
01443   /// returns a synthesized DependentNameType that isn't really dependent on any
01444   /// other template arguments.
01445   ParsedType ActOnDelayedDefaultTemplateArg(const IdentifierInfo &II,
01446                                             SourceLocation NameLoc);
01447 
01448   /// \brief Describes the result of the name lookup and resolution performed
01449   /// by \c ClassifyName().
01450   enum NameClassificationKind {
01451     NC_Unknown,
01452     NC_Error,
01453     NC_Keyword,
01454     NC_Type,
01455     NC_Expression,
01456     NC_NestedNameSpecifier,
01457     NC_TypeTemplate,
01458     NC_VarTemplate,
01459     NC_FunctionTemplate
01460   };
01461 
01462   class NameClassification {
01463     NameClassificationKind Kind;
01464     ExprResult Expr;
01465     TemplateName Template;
01466     ParsedType Type;
01467     const IdentifierInfo *Keyword;
01468 
01469     explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {}
01470 
01471   public:
01472     NameClassification(ExprResult Expr) : Kind(NC_Expression), Expr(Expr) {}
01473 
01474     NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {}
01475 
01476     NameClassification(const IdentifierInfo *Keyword)
01477       : Kind(NC_Keyword), Keyword(Keyword) { }
01478 
01479     static NameClassification Error() {
01480       return NameClassification(NC_Error);
01481     }
01482 
01483     static NameClassification Unknown() {
01484       return NameClassification(NC_Unknown);
01485     }
01486 
01487     static NameClassification NestedNameSpecifier() {
01488       return NameClassification(NC_NestedNameSpecifier);
01489     }
01490 
01491     static NameClassification TypeTemplate(TemplateName Name) {
01492       NameClassification Result(NC_TypeTemplate);
01493       Result.Template = Name;
01494       return Result;
01495     }
01496 
01497     static NameClassification VarTemplate(TemplateName Name) {
01498       NameClassification Result(NC_VarTemplate);
01499       Result.Template = Name;
01500       return Result;
01501     }
01502 
01503     static NameClassification FunctionTemplate(TemplateName Name) {
01504       NameClassification Result(NC_FunctionTemplate);
01505       Result.Template = Name;
01506       return Result;
01507     }
01508 
01509     NameClassificationKind getKind() const { return Kind; }
01510 
01511     ParsedType getType() const {
01512       assert(Kind == NC_Type);
01513       return Type;
01514     }
01515 
01516     ExprResult getExpression() const {
01517       assert(Kind == NC_Expression);
01518       return Expr;
01519     }
01520 
01521     TemplateName getTemplateName() const {
01522       assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate ||
01523              Kind == NC_VarTemplate);
01524       return Template;
01525     }
01526 
01527     TemplateNameKind getTemplateNameKind() const {
01528       switch (Kind) {
01529       case NC_TypeTemplate:
01530         return TNK_Type_template;
01531       case NC_FunctionTemplate:
01532         return TNK_Function_template;
01533       case NC_VarTemplate:
01534         return TNK_Var_template;
01535       default:
01536         llvm_unreachable("unsupported name classification.");
01537       }
01538     }
01539   };
01540 
01541   /// \brief Perform name lookup on the given name, classifying it based on
01542   /// the results of name lookup and the following token.
01543   ///
01544   /// This routine is used by the parser to resolve identifiers and help direct
01545   /// parsing. When the identifier cannot be found, this routine will attempt
01546   /// to correct the typo and classify based on the resulting name.
01547   ///
01548   /// \param S The scope in which we're performing name lookup.
01549   ///
01550   /// \param SS The nested-name-specifier that precedes the name.
01551   ///
01552   /// \param Name The identifier. If typo correction finds an alternative name,
01553   /// this pointer parameter will be updated accordingly.
01554   ///
01555   /// \param NameLoc The location of the identifier.
01556   ///
01557   /// \param NextToken The token following the identifier. Used to help
01558   /// disambiguate the name.
01559   ///
01560   /// \param IsAddressOfOperand True if this name is the operand of a unary
01561   ///        address of ('&') expression, assuming it is classified as an
01562   ///        expression.
01563   ///
01564   /// \param CCC The correction callback, if typo correction is desired.
01565   NameClassification
01566   ClassifyName(Scope *S, CXXScopeSpec &SS, IdentifierInfo *&Name,
01567                SourceLocation NameLoc, const Token &NextToken,
01568                bool IsAddressOfOperand,
01569                std::unique_ptr<CorrectionCandidateCallback> CCC = nullptr);
01570 
01571   Decl *ActOnDeclarator(Scope *S, Declarator &D);
01572 
01573   NamedDecl *HandleDeclarator(Scope *S, Declarator &D,
01574                               MultiTemplateParamsArg TemplateParameterLists);
01575   void RegisterLocallyScopedExternCDecl(NamedDecl *ND, Scope *S);
01576   bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info);
01577   bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC,
01578                                     DeclarationName Name,
01579                                     SourceLocation Loc);
01580   void
01581   diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals,
01582                             SourceLocation FallbackLoc,
01583                             SourceLocation ConstQualLoc = SourceLocation(),
01584                             SourceLocation VolatileQualLoc = SourceLocation(),
01585                             SourceLocation RestrictQualLoc = SourceLocation(),
01586                             SourceLocation AtomicQualLoc = SourceLocation());
01587 
01588   static bool adjustContextForLocalExternDecl(DeclContext *&DC);
01589   void DiagnoseFunctionSpecifiers(const DeclSpec &DS);
01590   void CheckShadow(Scope *S, VarDecl *D, const LookupResult& R);
01591   void CheckShadow(Scope *S, VarDecl *D);
01592   void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange);
01593   void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D);
01594   NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
01595                                     TypeSourceInfo *TInfo,
01596                                     LookupResult &Previous);
01597   NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D,
01598                                   LookupResult &Previous, bool &Redeclaration);
01599   NamedDecl *ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
01600                                      TypeSourceInfo *TInfo,
01601                                      LookupResult &Previous,
01602                                      MultiTemplateParamsArg TemplateParamLists,
01603                                      bool &AddToScope);
01604   // Returns true if the variable declaration is a redeclaration
01605   bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous);
01606   void CheckVariableDeclarationType(VarDecl *NewVD);
01607   void CheckCompleteVariableDeclaration(VarDecl *var);
01608   void MaybeSuggestAddingStaticToDecl(const FunctionDecl *D);
01609 
01610   NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
01611                                      TypeSourceInfo *TInfo,
01612                                      LookupResult &Previous,
01613                                      MultiTemplateParamsArg TemplateParamLists,
01614                                      bool &AddToScope);
01615   bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD);
01616 
01617   bool CheckConstexprFunctionDecl(const FunctionDecl *FD);
01618   bool CheckConstexprFunctionBody(const FunctionDecl *FD, Stmt *Body);
01619 
01620   void DiagnoseHiddenVirtualMethods(CXXMethodDecl *MD);
01621   void FindHiddenVirtualMethods(CXXMethodDecl *MD,
01622                           SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods);
01623   void NoteHiddenVirtualMethods(CXXMethodDecl *MD,
01624                           SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods);
01625   // Returns true if the function declaration is a redeclaration
01626   bool CheckFunctionDeclaration(Scope *S,
01627                                 FunctionDecl *NewFD, LookupResult &Previous,
01628                                 bool IsExplicitSpecialization);
01629   void CheckMain(FunctionDecl *FD, const DeclSpec &D);
01630   void CheckMSVCRTEntryPoint(FunctionDecl *FD);
01631   Decl *ActOnParamDeclarator(Scope *S, Declarator &D);
01632   ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC,
01633                                           SourceLocation Loc,
01634                                           QualType T);
01635   ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc,
01636                               SourceLocation NameLoc, IdentifierInfo *Name,
01637                               QualType T, TypeSourceInfo *TSInfo,
01638                               StorageClass SC);
01639   void ActOnParamDefaultArgument(Decl *param,
01640                                  SourceLocation EqualLoc,
01641                                  Expr *defarg);
01642   void ActOnParamUnparsedDefaultArgument(Decl *param,
01643                                          SourceLocation EqualLoc,
01644                                          SourceLocation ArgLoc);
01645   void ActOnParamDefaultArgumentError(Decl *param, SourceLocation EqualLoc);
01646   bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg,
01647                                SourceLocation EqualLoc);
01648 
01649   void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit,
01650                             bool TypeMayContainAuto);
01651   void ActOnUninitializedDecl(Decl *dcl, bool TypeMayContainAuto);
01652   void ActOnInitializerError(Decl *Dcl);
01653   void ActOnCXXForRangeDecl(Decl *D);
01654   StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc,
01655                                         IdentifierInfo *Ident,
01656                                         ParsedAttributes &Attrs,
01657                                         SourceLocation AttrEnd);
01658   void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc);
01659   void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc);
01660   void FinalizeDeclaration(Decl *D);
01661   DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS,
01662                                          ArrayRef<Decl *> Group);
01663   DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef<Decl *> Group,
01664                                       bool TypeMayContainAuto = true);
01665 
01666   /// Should be called on all declarations that might have attached
01667   /// documentation comments.
01668   void ActOnDocumentableDecl(Decl *D);
01669   void ActOnDocumentableDecls(ArrayRef<Decl *> Group);
01670 
01671   void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
01672                                        SourceLocation LocAfterDecls);
01673   void CheckForFunctionRedefinition(FunctionDecl *FD,
01674                                     const FunctionDecl *EffectiveDefinition =
01675                                         nullptr);
01676   Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
01677   Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D);
01678   void ActOnStartOfObjCMethodDef(Scope *S, Decl *D);
01679   bool isObjCMethodDecl(Decl *D) {
01680     return D && isa<ObjCMethodDecl>(D);
01681   }
01682 
01683   /// \brief Determine whether we can delay parsing the body of a function or
01684   /// function template until it is used, assuming we don't care about emitting
01685   /// code for that function.
01686   ///
01687   /// This will be \c false if we may need the body of the function in the
01688   /// middle of parsing an expression (where it's impractical to switch to
01689   /// parsing a different function), for instance, if it's constexpr in C++11
01690   /// or has an 'auto' return type in C++14. These cases are essentially bugs.
01691   bool canDelayFunctionBody(const Declarator &D);
01692 
01693   /// \brief Determine whether we can skip parsing the body of a function
01694   /// definition, assuming we don't care about analyzing its body or emitting
01695   /// code for that function.
01696   ///
01697   /// This will be \c false only if we may need the body of the function in
01698   /// order to parse the rest of the program (for instance, if it is
01699   /// \c constexpr in C++11 or has an 'auto' return type in C++14).
01700   bool canSkipFunctionBody(Decl *D);
01701 
01702   void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope);
01703   Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body);
01704   Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation);
01705   Decl *ActOnSkippedFunctionBody(Decl *Decl);
01706   void ActOnFinishInlineMethodDef(CXXMethodDecl *D);
01707 
01708   /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an
01709   /// attribute for which parsing is delayed.
01710   void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs);
01711 
01712   /// \brief Diagnose any unused parameters in the given sequence of
01713   /// ParmVarDecl pointers.
01714   void DiagnoseUnusedParameters(ParmVarDecl * const *Begin,
01715                                 ParmVarDecl * const *End);
01716 
01717   /// \brief Diagnose whether the size of parameters or return value of a
01718   /// function or obj-c method definition is pass-by-value and larger than a
01719   /// specified threshold.
01720   void DiagnoseSizeOfParametersAndReturnValue(ParmVarDecl * const *Begin,
01721                                               ParmVarDecl * const *End,
01722                                               QualType ReturnTy,
01723                                               NamedDecl *D);
01724 
01725   void DiagnoseInvalidJumps(Stmt *Body);
01726   Decl *ActOnFileScopeAsmDecl(Expr *expr,
01727                               SourceLocation AsmLoc,
01728                               SourceLocation RParenLoc);
01729 
01730   /// \brief Handle a C++11 empty-declaration and attribute-declaration.
01731   Decl *ActOnEmptyDeclaration(Scope *S,
01732                               AttributeList *AttrList,
01733                               SourceLocation SemiLoc);
01734 
01735   /// \brief The parser has processed a module import declaration.
01736   ///
01737   /// \param AtLoc The location of the '@' symbol, if any.
01738   ///
01739   /// \param ImportLoc The location of the 'import' keyword.
01740   ///
01741   /// \param Path The module access path.
01742   DeclResult ActOnModuleImport(SourceLocation AtLoc, SourceLocation ImportLoc,
01743                                ModuleIdPath Path);
01744 
01745   /// \brief The parser has processed a module import translated from a
01746   /// #include or similar preprocessing directive.
01747   void ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod);
01748 
01749   /// \brief Create an implicit import of the given module at the given
01750   /// source location, for error recovery, if possible.
01751   ///
01752   /// This routine is typically used when an entity found by name lookup
01753   /// is actually hidden within a module that we know about but the user
01754   /// has forgotten to import.
01755   void createImplicitModuleImportForErrorRecovery(SourceLocation Loc,
01756                                                   Module *Mod);
01757 
01758   /// \brief Retrieve a suitable printing policy.
01759   PrintingPolicy getPrintingPolicy() const {
01760     return getPrintingPolicy(Context, PP);
01761   }
01762 
01763   /// \brief Retrieve a suitable printing policy.
01764   static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx,
01765                                           const Preprocessor &PP);
01766 
01767   /// Scope actions.
01768   void ActOnPopScope(SourceLocation Loc, Scope *S);
01769   void ActOnTranslationUnitScope(Scope *S);
01770 
01771   Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
01772                                    DeclSpec &DS);
01773   Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
01774                                    DeclSpec &DS,
01775                                    MultiTemplateParamsArg TemplateParams,
01776                                    bool IsExplicitInstantiation = false);
01777 
01778   Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
01779                                     AccessSpecifier AS,
01780                                     RecordDecl *Record,
01781                                     const PrintingPolicy &Policy);
01782 
01783   Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS,
01784                                        RecordDecl *Record);
01785 
01786   bool isAcceptableTagRedeclaration(const TagDecl *Previous,
01787                                     TagTypeKind NewTag, bool isDefinition,
01788                                     SourceLocation NewTagLoc,
01789                                     const IdentifierInfo &Name);
01790 
01791   enum TagUseKind {
01792     TUK_Reference,   // Reference to a tag:  'struct foo *X;'
01793     TUK_Declaration, // Fwd decl of a tag:   'struct foo;'
01794     TUK_Definition,  // Definition of a tag: 'struct foo { int X; } Y;'
01795     TUK_Friend       // Friend declaration:  'friend struct foo;'
01796   };
01797 
01798   Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
01799                  SourceLocation KWLoc, CXXScopeSpec &SS,
01800                  IdentifierInfo *Name, SourceLocation NameLoc,
01801                  AttributeList *Attr, AccessSpecifier AS,
01802                  SourceLocation ModulePrivateLoc,
01803                  MultiTemplateParamsArg TemplateParameterLists,
01804                  bool &OwnedDecl, bool &IsDependent,
01805                  SourceLocation ScopedEnumKWLoc,
01806                  bool ScopedEnumUsesClassTag, TypeResult UnderlyingType,
01807                  bool IsTypeSpecifier);
01808 
01809   Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc,
01810                                 unsigned TagSpec, SourceLocation TagLoc,
01811                                 CXXScopeSpec &SS,
01812                                 IdentifierInfo *Name, SourceLocation NameLoc,
01813                                 AttributeList *Attr,
01814                                 MultiTemplateParamsArg TempParamLists);
01815 
01816   TypeResult ActOnDependentTag(Scope *S,
01817                                unsigned TagSpec,
01818                                TagUseKind TUK,
01819                                const CXXScopeSpec &SS,
01820                                IdentifierInfo *Name,
01821                                SourceLocation TagLoc,
01822                                SourceLocation NameLoc);
01823 
01824   void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart,
01825                  IdentifierInfo *ClassName,
01826                  SmallVectorImpl<Decl *> &Decls);
01827   Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart,
01828                    Declarator &D, Expr *BitfieldWidth);
01829 
01830   FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
01831                          Declarator &D, Expr *BitfieldWidth,
01832                          InClassInitStyle InitStyle,
01833                          AccessSpecifier AS);
01834   MSPropertyDecl *HandleMSProperty(Scope *S, RecordDecl *TagD,
01835                                    SourceLocation DeclStart,
01836                                    Declarator &D, Expr *BitfieldWidth,
01837                                    InClassInitStyle InitStyle,
01838                                    AccessSpecifier AS,
01839                                    AttributeList *MSPropertyAttr);
01840 
01841   FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T,
01842                             TypeSourceInfo *TInfo,
01843                             RecordDecl *Record, SourceLocation Loc,
01844                             bool Mutable, Expr *BitfieldWidth,
01845                             InClassInitStyle InitStyle,
01846                             SourceLocation TSSL,
01847                             AccessSpecifier AS, NamedDecl *PrevDecl,
01848                             Declarator *D = nullptr);
01849 
01850   bool CheckNontrivialField(FieldDecl *FD);
01851   void DiagnoseNontrivial(const CXXRecordDecl *Record, CXXSpecialMember CSM);
01852   bool SpecialMemberIsTrivial(CXXMethodDecl *MD, CXXSpecialMember CSM,
01853                               bool Diagnose = false);
01854   CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD);
01855   void ActOnLastBitfield(SourceLocation DeclStart,
01856                          SmallVectorImpl<Decl *> &AllIvarDecls);
01857   Decl *ActOnIvar(Scope *S, SourceLocation DeclStart,
01858                   Declarator &D, Expr *BitfieldWidth,
01859                   tok::ObjCKeywordKind visibility);
01860 
01861   // This is used for both record definitions and ObjC interface declarations.
01862   void ActOnFields(Scope* S, SourceLocation RecLoc, Decl *TagDecl,
01863                    ArrayRef<Decl *> Fields,
01864                    SourceLocation LBrac, SourceLocation RBrac,
01865                    AttributeList *AttrList);
01866 
01867   /// ActOnTagStartDefinition - Invoked when we have entered the
01868   /// scope of a tag's definition (e.g., for an enumeration, class,
01869   /// struct, or union).
01870   void ActOnTagStartDefinition(Scope *S, Decl *TagDecl);
01871 
01872   Decl *ActOnObjCContainerStartDefinition(Decl *IDecl);
01873 
01874   /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a
01875   /// C++ record definition's base-specifiers clause and are starting its
01876   /// member declarations.
01877   void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl,
01878                                        SourceLocation FinalLoc,
01879                                        bool IsFinalSpelledSealed,
01880                                        SourceLocation LBraceLoc);
01881 
01882   /// ActOnTagFinishDefinition - Invoked once we have finished parsing
01883   /// the definition of a tag (enumeration, class, struct, or union).
01884   void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl,
01885                                 SourceLocation RBraceLoc);
01886 
01887   void ActOnObjCContainerFinishDefinition();
01888 
01889   /// \brief Invoked when we must temporarily exit the objective-c container
01890   /// scope for parsing/looking-up C constructs.
01891   ///
01892   /// Must be followed by a call to \see ActOnObjCReenterContainerContext
01893   void ActOnObjCTemporaryExitContainerContext(DeclContext *DC);
01894   void ActOnObjCReenterContainerContext(DeclContext *DC);
01895 
01896   /// ActOnTagDefinitionError - Invoked when there was an unrecoverable
01897   /// error parsing the definition of a tag.
01898   void ActOnTagDefinitionError(Scope *S, Decl *TagDecl);
01899 
01900   EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum,
01901                                       EnumConstantDecl *LastEnumConst,
01902                                       SourceLocation IdLoc,
01903                                       IdentifierInfo *Id,
01904                                       Expr *val);
01905   bool CheckEnumUnderlyingType(TypeSourceInfo *TI);
01906   bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped,
01907                               QualType EnumUnderlyingTy, const EnumDecl *Prev);
01908 
01909   Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant,
01910                           SourceLocation IdLoc, IdentifierInfo *Id,
01911                           AttributeList *Attrs,
01912                           SourceLocation EqualLoc, Expr *Val);
01913   void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc,
01914                      SourceLocation RBraceLoc, Decl *EnumDecl,
01915                      ArrayRef<Decl *> Elements,
01916                      Scope *S, AttributeList *Attr);
01917 
01918   DeclContext *getContainingDC(DeclContext *DC);
01919 
01920   /// Set the current declaration context until it gets popped.
01921   void PushDeclContext(Scope *S, DeclContext *DC);
01922   void PopDeclContext();
01923 
01924   /// EnterDeclaratorContext - Used when we must lookup names in the context
01925   /// of a declarator's nested name specifier.
01926   void EnterDeclaratorContext(Scope *S, DeclContext *DC);
01927   void ExitDeclaratorContext(Scope *S);
01928 
01929   /// Push the parameters of D, which must be a function, into scope.
01930   void ActOnReenterFunctionContext(Scope* S, Decl* D);
01931   void ActOnExitFunctionContext();
01932 
01933   DeclContext *getFunctionLevelDeclContext();
01934 
01935   /// getCurFunctionDecl - If inside of a function body, this returns a pointer
01936   /// to the function decl for the function being parsed.  If we're currently
01937   /// in a 'block', this returns the containing context.
01938   FunctionDecl *getCurFunctionDecl();
01939 
01940   /// getCurMethodDecl - If inside of a method body, this returns a pointer to
01941   /// the method decl for the method being parsed.  If we're currently
01942   /// in a 'block', this returns the containing context.
01943   ObjCMethodDecl *getCurMethodDecl();
01944 
01945   /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
01946   /// or C function we're in, otherwise return null.  If we're currently
01947   /// in a 'block', this returns the containing context.
01948   NamedDecl *getCurFunctionOrMethodDecl();
01949 
01950   /// Add this decl to the scope shadowed decl chains.
01951   void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true);
01952 
01953   /// \brief Make the given externally-produced declaration visible at the
01954   /// top level scope.
01955   ///
01956   /// \param D The externally-produced declaration to push.
01957   ///
01958   /// \param Name The name of the externally-produced declaration.
01959   void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name);
01960 
01961   /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
01962   /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
01963   /// true if 'D' belongs to the given declaration context.
01964   ///
01965   /// \param AllowInlineNamespace If \c true, allow the declaration to be in the
01966   ///        enclosing namespace set of the context, rather than contained
01967   ///        directly within it.
01968   bool isDeclInScope(NamedDecl *D, DeclContext *Ctx, Scope *S = nullptr,
01969                      bool AllowInlineNamespace = false);
01970 
01971   /// Finds the scope corresponding to the given decl context, if it
01972   /// happens to be an enclosing scope.  Otherwise return NULL.
01973   static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC);
01974 
01975   /// Subroutines of ActOnDeclarator().
01976   TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
01977                                 TypeSourceInfo *TInfo);
01978   bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New);
01979 
01980   /// Attribute merging methods. Return true if a new attribute was added.
01981   AvailabilityAttr *mergeAvailabilityAttr(NamedDecl *D, SourceRange Range,
01982                                           IdentifierInfo *Platform,
01983                                           VersionTuple Introduced,
01984                                           VersionTuple Deprecated,
01985                                           VersionTuple Obsoleted,
01986                                           bool IsUnavailable,
01987                                           StringRef Message,
01988                                           bool Override,
01989                                           unsigned AttrSpellingListIndex);
01990   TypeVisibilityAttr *mergeTypeVisibilityAttr(Decl *D, SourceRange Range,
01991                                        TypeVisibilityAttr::VisibilityType Vis,
01992                                               unsigned AttrSpellingListIndex);
01993   VisibilityAttr *mergeVisibilityAttr(Decl *D, SourceRange Range,
01994                                       VisibilityAttr::VisibilityType Vis,
01995                                       unsigned AttrSpellingListIndex);
01996   DLLImportAttr *mergeDLLImportAttr(Decl *D, SourceRange Range,
01997                                     unsigned AttrSpellingListIndex);
01998   DLLExportAttr *mergeDLLExportAttr(Decl *D, SourceRange Range,
01999                                     unsigned AttrSpellingListIndex);
02000   MSInheritanceAttr *
02001   mergeMSInheritanceAttr(Decl *D, SourceRange Range, bool BestCase,
02002                          unsigned AttrSpellingListIndex,
02003                          MSInheritanceAttr::Spelling SemanticSpelling);
02004   FormatAttr *mergeFormatAttr(Decl *D, SourceRange Range,
02005                               IdentifierInfo *Format, int FormatIdx,
02006                               int FirstArg, unsigned AttrSpellingListIndex);
02007   SectionAttr *mergeSectionAttr(Decl *D, SourceRange Range, StringRef Name,
02008                                 unsigned AttrSpellingListIndex);
02009 
02010   /// \brief Describes the kind of merge to perform for availability
02011   /// attributes (including "deprecated", "unavailable", and "availability").
02012   enum AvailabilityMergeKind {
02013     /// \brief Don't merge availability attributes at all.
02014     AMK_None,
02015     /// \brief Merge availability attributes for a redeclaration, which requires
02016     /// an exact match.
02017     AMK_Redeclaration,
02018     /// \brief Merge availability attributes for an override, which requires
02019     /// an exact match or a weakening of constraints.
02020     AMK_Override
02021   };
02022 
02023   void mergeDeclAttributes(NamedDecl *New, Decl *Old,
02024                            AvailabilityMergeKind AMK = AMK_Redeclaration);
02025   void MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls);
02026   bool MergeFunctionDecl(FunctionDecl *New, NamedDecl *&Old, Scope *S,
02027                          bool MergeTypeWithOld);
02028   bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old,
02029                                     Scope *S, bool MergeTypeWithOld);
02030   void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old);
02031   void MergeVarDecl(VarDecl *New, LookupResult &Previous);
02032   void MergeVarDeclTypes(VarDecl *New, VarDecl *Old, bool MergeTypeWithOld);
02033   void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old);
02034   bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S);
02035 
02036   // AssignmentAction - This is used by all the assignment diagnostic functions
02037   // to represent what is actually causing the operation
02038   enum AssignmentAction {
02039     AA_Assigning,
02040     AA_Passing,
02041     AA_Returning,
02042     AA_Converting,
02043     AA_Initializing,
02044     AA_Sending,
02045     AA_Casting,
02046     AA_Passing_CFAudited
02047   };
02048 
02049   /// C++ Overloading.
02050   enum OverloadKind {
02051     /// This is a legitimate overload: the existing declarations are
02052     /// functions or function templates with different signatures.
02053     Ovl_Overload,
02054 
02055     /// This is not an overload because the signature exactly matches
02056     /// an existing declaration.
02057     Ovl_Match,
02058 
02059     /// This is not an overload because the lookup results contain a
02060     /// non-function.
02061     Ovl_NonFunction
02062   };
02063   OverloadKind CheckOverload(Scope *S,
02064                              FunctionDecl *New,
02065                              const LookupResult &OldDecls,
02066                              NamedDecl *&OldDecl,
02067                              bool IsForUsingDecl);
02068   bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl);
02069 
02070   /// \brief Checks availability of the function depending on the current
02071   /// function context.Inside an unavailable function,unavailability is ignored.
02072   ///
02073   /// \returns true if \p FD is unavailable and current context is inside
02074   /// an available function, false otherwise.
02075   bool isFunctionConsideredUnavailable(FunctionDecl *FD);
02076 
02077   ImplicitConversionSequence
02078   TryImplicitConversion(Expr *From, QualType ToType,
02079                         bool SuppressUserConversions,
02080                         bool AllowExplicit,
02081                         bool InOverloadResolution,
02082                         bool CStyle,
02083                         bool AllowObjCWritebackConversion);
02084 
02085   bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
02086   bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
02087   bool IsComplexPromotion(QualType FromType, QualType ToType);
02088   bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
02089                            bool InOverloadResolution,
02090                            QualType& ConvertedType, bool &IncompatibleObjC);
02091   bool isObjCPointerConversion(QualType FromType, QualType ToType,
02092                                QualType& ConvertedType, bool &IncompatibleObjC);
02093   bool isObjCWritebackConversion(QualType FromType, QualType ToType,
02094                                  QualType &ConvertedType);
02095   bool IsBlockPointerConversion(QualType FromType, QualType ToType,
02096                                 QualType& ConvertedType);
02097   bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
02098                                   const FunctionProtoType *NewType,
02099                                   unsigned *ArgPos = nullptr);
02100   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
02101                                   QualType FromType, QualType ToType);
02102 
02103   CastKind PrepareCastToObjCObjectPointer(ExprResult &E);
02104   bool CheckPointerConversion(Expr *From, QualType ToType,
02105                               CastKind &Kind,
02106                               CXXCastPath& BasePath,
02107                               bool IgnoreBaseAccess);
02108   bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
02109                                  bool InOverloadResolution,
02110                                  QualType &ConvertedType);
02111   bool CheckMemberPointerConversion(Expr *From, QualType ToType,
02112                                     CastKind &Kind,
02113                                     CXXCastPath &BasePath,
02114                                     bool IgnoreBaseAccess);
02115   bool IsQualificationConversion(QualType FromType, QualType ToType,
02116                                  bool CStyle, bool &ObjCLifetimeConversion);
02117   bool IsNoReturnConversion(QualType FromType, QualType ToType,
02118                             QualType &ResultTy);
02119   bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType);
02120   bool isSameOrCompatibleFunctionType(CanQualType Param, CanQualType Arg);
02121 
02122   ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
02123                                              const VarDecl *NRVOCandidate,
02124                                              QualType ResultType,
02125                                              Expr *Value,
02126                                              bool AllowNRVO = true);
02127 
02128   bool CanPerformCopyInitialization(const InitializedEntity &Entity,
02129                                     ExprResult Init);
02130   ExprResult PerformCopyInitialization(const InitializedEntity &Entity,
02131                                        SourceLocation EqualLoc,
02132                                        ExprResult Init,
02133                                        bool TopLevelOfInitList = false,
02134                                        bool AllowExplicit = false);
02135   ExprResult PerformObjectArgumentInitialization(Expr *From,
02136                                                  NestedNameSpecifier *Qualifier,
02137                                                  NamedDecl *FoundDecl,
02138                                                  CXXMethodDecl *Method);
02139 
02140   ExprResult PerformContextuallyConvertToBool(Expr *From);
02141   ExprResult PerformContextuallyConvertToObjCPointer(Expr *From);
02142 
02143   /// Contexts in which a converted constant expression is required.
02144   enum CCEKind {
02145     CCEK_CaseValue,   ///< Expression in a case label.
02146     CCEK_Enumerator,  ///< Enumerator value with fixed underlying type.
02147     CCEK_TemplateArg, ///< Value of a non-type template parameter.
02148     CCEK_NewExpr      ///< Constant expression in a noptr-new-declarator.
02149   };
02150   ExprResult CheckConvertedConstantExpression(Expr *From, QualType T,
02151                                               llvm::APSInt &Value, CCEKind CCE);
02152 
02153   /// \brief Abstract base class used to perform a contextual implicit
02154   /// conversion from an expression to any type passing a filter.
02155   class ContextualImplicitConverter {
02156   public:
02157     bool Suppress;
02158     bool SuppressConversion;
02159 
02160     ContextualImplicitConverter(bool Suppress = false,
02161                                 bool SuppressConversion = false)
02162         : Suppress(Suppress), SuppressConversion(SuppressConversion) {}
02163 
02164     /// \brief Determine whether the specified type is a valid destination type
02165     /// for this conversion.
02166     virtual bool match(QualType T) = 0;
02167 
02168     /// \brief Emits a diagnostic complaining that the expression does not have
02169     /// integral or enumeration type.
02170     virtual SemaDiagnosticBuilder
02171     diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) = 0;
02172 
02173     /// \brief Emits a diagnostic when the expression has incomplete class type.
02174     virtual SemaDiagnosticBuilder
02175     diagnoseIncomplete(Sema &S, SourceLocation Loc, QualType T) = 0;
02176 
02177     /// \brief Emits a diagnostic when the only matching conversion function
02178     /// is explicit.
02179     virtual SemaDiagnosticBuilder diagnoseExplicitConv(
02180         Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0;
02181 
02182     /// \brief Emits a note for the explicit conversion function.
02183     virtual SemaDiagnosticBuilder
02184     noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0;
02185 
02186     /// \brief Emits a diagnostic when there are multiple possible conversion
02187     /// functions.
02188     virtual SemaDiagnosticBuilder
02189     diagnoseAmbiguous(Sema &S, SourceLocation Loc, QualType T) = 0;
02190 
02191     /// \brief Emits a note for one of the candidate conversions.
02192     virtual SemaDiagnosticBuilder
02193     noteAmbiguous(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0;
02194 
02195     /// \brief Emits a diagnostic when we picked a conversion function
02196     /// (for cases when we are not allowed to pick a conversion function).
02197     virtual SemaDiagnosticBuilder diagnoseConversion(
02198         Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0;
02199 
02200     virtual ~ContextualImplicitConverter() {}
02201   };
02202 
02203   class ICEConvertDiagnoser : public ContextualImplicitConverter {
02204     bool AllowScopedEnumerations;
02205 
02206   public:
02207     ICEConvertDiagnoser(bool AllowScopedEnumerations,
02208                         bool Suppress, bool SuppressConversion)
02209         : ContextualImplicitConverter(Suppress, SuppressConversion),
02210           AllowScopedEnumerations(AllowScopedEnumerations) {}
02211 
02212     /// Match an integral or (possibly scoped) enumeration type.
02213     bool match(QualType T) override;
02214 
02215     SemaDiagnosticBuilder
02216     diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) override {
02217       return diagnoseNotInt(S, Loc, T);
02218     }
02219 
02220     /// \brief Emits a diagnostic complaining that the expression does not have
02221     /// integral or enumeration type.
02222     virtual SemaDiagnosticBuilder
02223     diagnoseNotInt(Sema &S, SourceLocation Loc, QualType T) = 0;
02224   };
02225 
02226   /// Perform a contextual implicit conversion.
02227   ExprResult PerformContextualImplicitConversion(
02228       SourceLocation Loc, Expr *FromE, ContextualImplicitConverter &Converter);
02229 
02230 
02231   enum ObjCSubscriptKind {
02232     OS_Array,
02233     OS_Dictionary,
02234     OS_Error
02235   };
02236   ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE);
02237 
02238   // Note that LK_String is intentionally after the other literals, as
02239   // this is used for diagnostics logic.
02240   enum ObjCLiteralKind {
02241     LK_Array,
02242     LK_Dictionary,
02243     LK_Numeric,
02244     LK_Boxed,
02245     LK_String,
02246     LK_Block,
02247     LK_None
02248   };
02249   ObjCLiteralKind CheckLiteralKind(Expr *FromE);
02250 
02251   ExprResult PerformObjectMemberConversion(Expr *From,
02252                                            NestedNameSpecifier *Qualifier,
02253                                            NamedDecl *FoundDecl,
02254                                            NamedDecl *Member);
02255 
02256   // Members have to be NamespaceDecl* or TranslationUnitDecl*.
02257   // TODO: make this is a typesafe union.
02258   typedef llvm::SmallPtrSet<DeclContext   *, 16> AssociatedNamespaceSet;
02259   typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet;
02260 
02261   void AddOverloadCandidate(FunctionDecl *Function,
02262                             DeclAccessPair FoundDecl,
02263                             ArrayRef<Expr *> Args,
02264                             OverloadCandidateSet& CandidateSet,
02265                             bool SuppressUserConversions = false,
02266                             bool PartialOverloading = false,
02267                             bool AllowExplicit = false);
02268   void AddFunctionCandidates(const UnresolvedSetImpl &Functions,
02269                       ArrayRef<Expr *> Args,
02270                       OverloadCandidateSet &CandidateSet,
02271                       bool SuppressUserConversions = false,
02272                       TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr);
02273   void AddMethodCandidate(DeclAccessPair FoundDecl,
02274                           QualType ObjectType,
02275                           Expr::Classification ObjectClassification,
02276                           ArrayRef<Expr *> Args,
02277                           OverloadCandidateSet& CandidateSet,
02278                           bool SuppressUserConversion = false);
02279   void AddMethodCandidate(CXXMethodDecl *Method,
02280                           DeclAccessPair FoundDecl,
02281                           CXXRecordDecl *ActingContext, QualType ObjectType,
02282                           Expr::Classification ObjectClassification,
02283                           ArrayRef<Expr *> Args,
02284                           OverloadCandidateSet& CandidateSet,
02285                           bool SuppressUserConversions = false);
02286   void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl,
02287                                   DeclAccessPair FoundDecl,
02288                                   CXXRecordDecl *ActingContext,
02289                                  TemplateArgumentListInfo *ExplicitTemplateArgs,
02290                                   QualType ObjectType,
02291                                   Expr::Classification ObjectClassification,
02292                                   ArrayRef<Expr *> Args,
02293                                   OverloadCandidateSet& CandidateSet,
02294                                   bool SuppressUserConversions = false);
02295   void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate,
02296                                     DeclAccessPair FoundDecl,
02297                                  TemplateArgumentListInfo *ExplicitTemplateArgs,
02298                                     ArrayRef<Expr *> Args,
02299                                     OverloadCandidateSet& CandidateSet,
02300                                     bool SuppressUserConversions = false);
02301   void AddConversionCandidate(CXXConversionDecl *Conversion,
02302                               DeclAccessPair FoundDecl,
02303                               CXXRecordDecl *ActingContext,
02304                               Expr *From, QualType ToType,
02305                               OverloadCandidateSet& CandidateSet,
02306                               bool AllowObjCConversionOnExplicit);
02307   void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate,
02308                                       DeclAccessPair FoundDecl,
02309                                       CXXRecordDecl *ActingContext,
02310                                       Expr *From, QualType ToType,
02311                                       OverloadCandidateSet &CandidateSet,
02312                                       bool AllowObjCConversionOnExplicit);
02313   void AddSurrogateCandidate(CXXConversionDecl *Conversion,
02314                              DeclAccessPair FoundDecl,
02315                              CXXRecordDecl *ActingContext,
02316                              const FunctionProtoType *Proto,
02317                              Expr *Object, ArrayRef<Expr *> Args,
02318                              OverloadCandidateSet& CandidateSet);
02319   void AddMemberOperatorCandidates(OverloadedOperatorKind Op,
02320                                    SourceLocation OpLoc, ArrayRef<Expr *> Args,
02321                                    OverloadCandidateSet& CandidateSet,
02322                                    SourceRange OpRange = SourceRange());
02323   void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
02324                            ArrayRef<Expr *> Args, 
02325                            OverloadCandidateSet& CandidateSet,
02326                            bool IsAssignmentOperator = false,
02327                            unsigned NumContextualBoolArguments = 0);
02328   void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
02329                                     SourceLocation OpLoc, ArrayRef<Expr *> Args,
02330                                     OverloadCandidateSet& CandidateSet);
02331   void AddArgumentDependentLookupCandidates(DeclarationName Name,
02332                                             SourceLocation Loc,
02333                                             ArrayRef<Expr *> Args,
02334                                 TemplateArgumentListInfo *ExplicitTemplateArgs,
02335                                             OverloadCandidateSet& CandidateSet,
02336                                             bool PartialOverloading = false);
02337 
02338   // Emit as a 'note' the specific overload candidate
02339   void NoteOverloadCandidate(FunctionDecl *Fn, QualType DestType = QualType());
02340 
02341   // Emit as a series of 'note's all template and non-templates
02342   // identified by the expression Expr
02343   void NoteAllOverloadCandidates(Expr* E, QualType DestType = QualType());
02344 
02345   /// Check the enable_if expressions on the given function. Returns the first
02346   /// failing attribute, or NULL if they were all successful.
02347   EnableIfAttr *CheckEnableIf(FunctionDecl *Function, ArrayRef<Expr *> Args,
02348                               bool MissingImplicitThis = false);
02349 
02350   // [PossiblyAFunctionType]  -->   [Return]
02351   // NonFunctionType --> NonFunctionType
02352   // R (A) --> R(A)
02353   // R (*)(A) --> R (A)
02354   // R (&)(A) --> R (A)
02355   // R (S::*)(A) --> R (A)
02356   QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType);
02357 
02358   FunctionDecl *
02359   ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr,
02360                                      QualType TargetType,
02361                                      bool Complain,
02362                                      DeclAccessPair &Found,
02363                                      bool *pHadMultipleCandidates = nullptr);
02364 
02365   FunctionDecl *
02366   ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl,
02367                                               bool Complain = false,
02368                                               DeclAccessPair *Found = nullptr);
02369 
02370   bool ResolveAndFixSingleFunctionTemplateSpecialization(
02371                       ExprResult &SrcExpr,
02372                       bool DoFunctionPointerConverion = false,
02373                       bool Complain = false,
02374                       const SourceRange& OpRangeForComplaining = SourceRange(),
02375                       QualType DestTypeForComplaining = QualType(),
02376                       unsigned DiagIDForComplaining = 0);
02377 
02378 
02379   Expr *FixOverloadedFunctionReference(Expr *E,
02380                                        DeclAccessPair FoundDecl,
02381                                        FunctionDecl *Fn);
02382   ExprResult FixOverloadedFunctionReference(ExprResult,
02383                                             DeclAccessPair FoundDecl,
02384                                             FunctionDecl *Fn);
02385 
02386   void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE,
02387                                    ArrayRef<Expr *> Args,
02388                                    OverloadCandidateSet &CandidateSet,
02389                                    bool PartialOverloading = false);
02390 
02391   // An enum used to represent the different possible results of building a
02392   // range-based for loop.
02393   enum ForRangeStatus {
02394     FRS_Success,
02395     FRS_NoViableFunction,
02396     FRS_DiagnosticIssued
02397   };
02398 
02399   // An enum to represent whether something is dealing with a call to begin()
02400   // or a call to end() in a range-based for loop.
02401   enum BeginEndFunction {
02402     BEF_begin,
02403     BEF_end
02404   };
02405 
02406   ForRangeStatus BuildForRangeBeginEndCall(Scope *S, SourceLocation Loc,
02407                                            SourceLocation RangeLoc,
02408                                            VarDecl *Decl,
02409                                            BeginEndFunction BEF,
02410                                            const DeclarationNameInfo &NameInfo,
02411                                            LookupResult &MemberLookup,
02412                                            OverloadCandidateSet *CandidateSet,
02413                                            Expr *Range, ExprResult *CallExpr);
02414 
02415   ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn,
02416                                      UnresolvedLookupExpr *ULE,
02417                                      SourceLocation LParenLoc,
02418                                      MultiExprArg Args,
02419                                      SourceLocation RParenLoc,
02420                                      Expr *ExecConfig,
02421                                      bool AllowTypoCorrection=true);
02422 
02423   bool buildOverloadedCallSet(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE,
02424                               MultiExprArg Args, SourceLocation RParenLoc,
02425                               OverloadCandidateSet *CandidateSet,
02426                               ExprResult *Result);
02427 
02428   ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc,
02429                                      unsigned Opc,
02430                                      const UnresolvedSetImpl &Fns,
02431                                      Expr *input);
02432 
02433   ExprResult CreateOverloadedBinOp(SourceLocation OpLoc,
02434                                    unsigned Opc,
02435                                    const UnresolvedSetImpl &Fns,
02436                                    Expr *LHS, Expr *RHS);
02437 
02438   ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
02439                                                 SourceLocation RLoc,
02440                                                 Expr *Base,Expr *Idx);
02441 
02442   ExprResult
02443   BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
02444                             SourceLocation LParenLoc,
02445                             MultiExprArg Args,
02446                             SourceLocation RParenLoc);
02447   ExprResult
02448   BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
02449                                MultiExprArg Args,
02450                                SourceLocation RParenLoc);
02451 
02452   ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base,
02453                                       SourceLocation OpLoc,
02454                                       bool *NoArrowOperatorFound = nullptr);
02455 
02456   /// CheckCallReturnType - Checks that a call expression's return type is
02457   /// complete. Returns true on failure. The location passed in is the location
02458   /// that best represents the call.
02459   bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc,
02460                            CallExpr *CE, FunctionDecl *FD);
02461 
02462   /// Helpers for dealing with blocks and functions.
02463   bool CheckParmsForFunctionDef(ParmVarDecl *const *Param,
02464                                 ParmVarDecl *const *ParamEnd,
02465                                 bool CheckParameterNames);
02466   void CheckCXXDefaultArguments(FunctionDecl *FD);
02467   void CheckExtraCXXDefaultArguments(Declarator &D);
02468   Scope *getNonFieldDeclScope(Scope *S);
02469 
02470   /// \name Name lookup
02471   ///
02472   /// These routines provide name lookup that is used during semantic
02473   /// analysis to resolve the various kinds of names (identifiers,
02474   /// overloaded operator names, constructor names, etc.) into zero or
02475   /// more declarations within a particular scope. The major entry
02476   /// points are LookupName, which performs unqualified name lookup,
02477   /// and LookupQualifiedName, which performs qualified name lookup.
02478   ///
02479   /// All name lookup is performed based on some specific criteria,
02480   /// which specify what names will be visible to name lookup and how
02481   /// far name lookup should work. These criteria are important both
02482   /// for capturing language semantics (certain lookups will ignore
02483   /// certain names, for example) and for performance, since name
02484   /// lookup is often a bottleneck in the compilation of C++. Name
02485   /// lookup criteria is specified via the LookupCriteria enumeration.
02486   ///
02487   /// The results of name lookup can vary based on the kind of name
02488   /// lookup performed, the current language, and the translation
02489   /// unit. In C, for example, name lookup will either return nothing
02490   /// (no entity found) or a single declaration. In C++, name lookup
02491   /// can additionally refer to a set of overloaded functions or
02492   /// result in an ambiguity. All of the possible results of name
02493   /// lookup are captured by the LookupResult class, which provides
02494   /// the ability to distinguish among them.
02495   //@{
02496 
02497   /// @brief Describes the kind of name lookup to perform.
02498   enum LookupNameKind {
02499     /// Ordinary name lookup, which finds ordinary names (functions,
02500     /// variables, typedefs, etc.) in C and most kinds of names
02501     /// (functions, variables, members, types, etc.) in C++.
02502     LookupOrdinaryName = 0,
02503     /// Tag name lookup, which finds the names of enums, classes,
02504     /// structs, and unions.
02505     LookupTagName,
02506     /// Label name lookup.
02507     LookupLabel,
02508     /// Member name lookup, which finds the names of
02509     /// class/struct/union members.
02510     LookupMemberName,
02511     /// Look up of an operator name (e.g., operator+) for use with
02512     /// operator overloading. This lookup is similar to ordinary name
02513     /// lookup, but will ignore any declarations that are class members.
02514     LookupOperatorName,
02515     /// Look up of a name that precedes the '::' scope resolution
02516     /// operator in C++. This lookup completely ignores operator, object,
02517     /// function, and enumerator names (C++ [basic.lookup.qual]p1).
02518     LookupNestedNameSpecifierName,
02519     /// Look up a namespace name within a C++ using directive or
02520     /// namespace alias definition, ignoring non-namespace names (C++
02521     /// [basic.lookup.udir]p1).
02522     LookupNamespaceName,
02523     /// Look up all declarations in a scope with the given name,
02524     /// including resolved using declarations.  This is appropriate
02525     /// for checking redeclarations for a using declaration.
02526     LookupUsingDeclName,
02527     /// Look up an ordinary name that is going to be redeclared as a
02528     /// name with linkage. This lookup ignores any declarations that
02529     /// are outside of the current scope unless they have linkage. See
02530     /// C99 6.2.2p4-5 and C++ [basic.link]p6.
02531     LookupRedeclarationWithLinkage,
02532     /// Look up a friend of a local class. This lookup does not look
02533     /// outside the innermost non-class scope. See C++11 [class.friend]p11.
02534     LookupLocalFriendName,
02535     /// Look up the name of an Objective-C protocol.
02536     LookupObjCProtocolName,
02537     /// Look up implicit 'self' parameter of an objective-c method.
02538     LookupObjCImplicitSelfParam,
02539     /// \brief Look up any declaration with any name.
02540     LookupAnyName
02541   };
02542 
02543   /// \brief Specifies whether (or how) name lookup is being performed for a
02544   /// redeclaration (vs. a reference).
02545   enum RedeclarationKind {
02546     /// \brief The lookup is a reference to this name that is not for the
02547     /// purpose of redeclaring the name.
02548     NotForRedeclaration = 0,
02549     /// \brief The lookup results will be used for redeclaration of a name,
02550     /// if an entity by that name already exists.
02551     ForRedeclaration
02552   };
02553 
02554   /// \brief The possible outcomes of name lookup for a literal operator.
02555   enum LiteralOperatorLookupResult {
02556     /// \brief The lookup resulted in an error.
02557     LOLR_Error,
02558     /// \brief The lookup found a single 'cooked' literal operator, which
02559     /// expects a normal literal to be built and passed to it.
02560     LOLR_Cooked,
02561     /// \brief The lookup found a single 'raw' literal operator, which expects
02562     /// a string literal containing the spelling of the literal token.
02563     LOLR_Raw,
02564     /// \brief The lookup found an overload set of literal operator templates,
02565     /// which expect the characters of the spelling of the literal token to be
02566     /// passed as a non-type template argument pack.
02567     LOLR_Template,
02568     /// \brief The lookup found an overload set of literal operator templates,
02569     /// which expect the character type and characters of the spelling of the
02570     /// string literal token to be passed as template arguments.
02571     LOLR_StringTemplate
02572   };
02573 
02574   SpecialMemberOverloadResult *LookupSpecialMember(CXXRecordDecl *D,
02575                                                    CXXSpecialMember SM,
02576                                                    bool ConstArg,
02577                                                    bool VolatileArg,
02578                                                    bool RValueThis,
02579                                                    bool ConstThis,
02580                                                    bool VolatileThis);
02581 
02582   typedef std::function<void(const TypoCorrection &)> TypoDiagnosticGenerator;
02583   typedef std::function<ExprResult(Sema &, TypoExpr *, TypoCorrection)>
02584       TypoRecoveryCallback;
02585 
02586 private:
02587   bool CppLookupName(LookupResult &R, Scope *S);
02588 
02589   struct TypoExprState {
02590     std::unique_ptr<TypoCorrectionConsumer> Consumer;
02591     TypoDiagnosticGenerator DiagHandler;
02592     TypoRecoveryCallback RecoveryHandler;
02593     TypoExprState();
02594     TypoExprState(TypoExprState&& other) LLVM_NOEXCEPT;
02595     TypoExprState& operator=(TypoExprState&& other) LLVM_NOEXCEPT;
02596   };
02597 
02598   /// \brief The set of unhandled TypoExprs and their associated state.
02599   llvm::MapVector<TypoExpr *, TypoExprState> DelayedTypos;
02600 
02601   /// \brief Creates a new TypoExpr AST node.
02602   TypoExpr *createDelayedTypo(std::unique_ptr<TypoCorrectionConsumer> TCC,
02603                               TypoDiagnosticGenerator TDG,
02604                               TypoRecoveryCallback TRC);
02605 
02606   // \brief The set of known/encountered (unique, canonicalized) NamespaceDecls.
02607   //
02608   // The boolean value will be true to indicate that the namespace was loaded
02609   // from an AST/PCH file, or false otherwise.
02610   llvm::MapVector<NamespaceDecl*, bool> KnownNamespaces;
02611 
02612   /// \brief Whether we have already loaded known namespaces from an extenal
02613   /// source.
02614   bool LoadedExternalKnownNamespaces;
02615 
02616   /// \brief Helper for CorrectTypo and CorrectTypoDelayed used to create and
02617   /// populate a new TypoCorrectionConsumer. Returns nullptr if typo correction
02618   /// should be skipped entirely.
02619   std::unique_ptr<TypoCorrectionConsumer>
02620   makeTypoCorrectionConsumer(const DeclarationNameInfo &Typo,
02621                              Sema::LookupNameKind LookupKind, Scope *S,
02622                              CXXScopeSpec *SS,
02623                              std::unique_ptr<CorrectionCandidateCallback> CCC,
02624                              DeclContext *MemberContext, bool EnteringContext,
02625                              const ObjCObjectPointerType *OPT,
02626                              bool ErrorRecovery, bool &IsUnqualifiedLookup);
02627 
02628 public:
02629   const TypoExprState &getTypoExprState(TypoExpr *TE) const;
02630 
02631   /// \brief Clears the state of the given TypoExpr.
02632   void clearDelayedTypo(TypoExpr *TE);
02633 
02634   /// \brief Look up a name, looking for a single declaration.  Return
02635   /// null if the results were absent, ambiguous, or overloaded.
02636   ///
02637   /// It is preferable to use the elaborated form and explicitly handle
02638   /// ambiguity and overloaded.
02639   NamedDecl *LookupSingleName(Scope *S, DeclarationName Name,
02640                               SourceLocation Loc,
02641                               LookupNameKind NameKind,
02642                               RedeclarationKind Redecl
02643                                 = NotForRedeclaration);
02644   bool LookupName(LookupResult &R, Scope *S,
02645                   bool AllowBuiltinCreation = false);
02646   bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
02647                            bool InUnqualifiedLookup = false);
02648   bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS,
02649                         bool AllowBuiltinCreation = false,
02650                         bool EnteringContext = false);
02651   ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc,
02652                                    RedeclarationKind Redecl
02653                                      = NotForRedeclaration);
02654   bool LookupInSuper(LookupResult &R, CXXRecordDecl *Class);
02655 
02656   void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
02657                                     QualType T1, QualType T2,
02658                                     UnresolvedSetImpl &Functions);
02659   void addOverloadedOperatorToUnresolvedSet(UnresolvedSetImpl &Functions,
02660                                             DeclAccessPair Operator,
02661                                             QualType T1, QualType T2);
02662 
02663   LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc,
02664                                  SourceLocation GnuLabelLoc = SourceLocation());
02665 
02666   DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class);
02667   CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class);
02668   CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class,
02669                                                unsigned Quals);
02670   CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals,
02671                                          bool RValueThis, unsigned ThisQuals);
02672   CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class,
02673                                               unsigned Quals);
02674   CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals,
02675                                         bool RValueThis, unsigned ThisQuals);
02676   CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class);
02677 
02678   bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id);
02679   LiteralOperatorLookupResult LookupLiteralOperator(Scope *S, LookupResult &R,
02680                                                     ArrayRef<QualType> ArgTys,
02681                                                     bool AllowRaw,
02682                                                     bool AllowTemplate,
02683                                                     bool AllowStringTemplate);
02684   bool isKnownName(StringRef name);
02685 
02686   void ArgumentDependentLookup(DeclarationName Name, SourceLocation Loc,
02687                                ArrayRef<Expr *> Args, ADLResult &Functions);
02688 
02689   void LookupVisibleDecls(Scope *S, LookupNameKind Kind,
02690                           VisibleDeclConsumer &Consumer,
02691                           bool IncludeGlobalScope = true);
02692   void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind,
02693                           VisibleDeclConsumer &Consumer,
02694                           bool IncludeGlobalScope = true);
02695 
02696   enum CorrectTypoKind {
02697     CTK_NonError,     // CorrectTypo used in a non error recovery situation.
02698     CTK_ErrorRecovery // CorrectTypo used in normal error recovery.
02699   };
02700 
02701   TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
02702                              Sema::LookupNameKind LookupKind,
02703                              Scope *S, CXXScopeSpec *SS,
02704                              std::unique_ptr<CorrectionCandidateCallback> CCC,
02705                              CorrectTypoKind Mode,
02706                              DeclContext *MemberContext = nullptr,
02707                              bool EnteringContext = false,
02708                              const ObjCObjectPointerType *OPT = nullptr,
02709                              bool RecordFailure = true);
02710 
02711   TypoExpr *CorrectTypoDelayed(const DeclarationNameInfo &Typo,
02712                                Sema::LookupNameKind LookupKind, Scope *S,
02713                                CXXScopeSpec *SS,
02714                                std::unique_ptr<CorrectionCandidateCallback> CCC,
02715                                TypoDiagnosticGenerator TDG,
02716                                TypoRecoveryCallback TRC, CorrectTypoKind Mode,
02717                                DeclContext *MemberContext = nullptr,
02718                                bool EnteringContext = false,
02719                                const ObjCObjectPointerType *OPT = nullptr);
02720 
02721   ExprResult
02722   CorrectDelayedTyposInExpr(Expr *E,
02723                             llvm::function_ref<ExprResult(Expr *)> Filter =
02724                                 [](Expr *E) -> ExprResult { return E; });
02725 
02726   ExprResult
02727   CorrectDelayedTyposInExpr(ExprResult ER,
02728                             llvm::function_ref<ExprResult(Expr *)> Filter =
02729                                 [](Expr *E) -> ExprResult { return E; }) {
02730     return ER.isInvalid() ? ER : CorrectDelayedTyposInExpr(ER.get(), Filter);
02731   }
02732 
02733   void diagnoseTypo(const TypoCorrection &Correction,
02734                     const PartialDiagnostic &TypoDiag,
02735                     bool ErrorRecovery = true);
02736 
02737   void diagnoseTypo(const TypoCorrection &Correction,
02738                     const PartialDiagnostic &TypoDiag,
02739                     const PartialDiagnostic &PrevNote,
02740                     bool ErrorRecovery = true);
02741 
02742   void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc,
02743                                           ArrayRef<Expr *> Args,
02744                                    AssociatedNamespaceSet &AssociatedNamespaces,
02745                                    AssociatedClassSet &AssociatedClasses);
02746 
02747   void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S,
02748                             bool ConsiderLinkage, bool AllowInlineNamespace);
02749 
02750   void DiagnoseAmbiguousLookup(LookupResult &Result);
02751   //@}
02752 
02753   ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id,
02754                                           SourceLocation IdLoc,
02755                                           bool TypoCorrection = false);
02756   NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
02757                                  Scope *S, bool ForRedeclaration,
02758                                  SourceLocation Loc);
02759   NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
02760                                       Scope *S);
02761   void AddKnownFunctionAttributes(FunctionDecl *FD);
02762 
02763   // More parsing and symbol table subroutines.
02764 
02765   void ProcessPragmaWeak(Scope *S, Decl *D);
02766   // Decl attributes - this routine is the top level dispatcher.
02767   void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD);
02768   void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL,
02769                                 bool IncludeCXX11Attributes = true);
02770   bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl,
02771                                       const AttributeList *AttrList);
02772 
02773   void checkUnusedDeclAttributes(Declarator &D);
02774 
02775   /// Determine if type T is a valid subject for a nonnull and similar
02776   /// attributes. By default, we look through references (the behavior used by
02777   /// nonnull), but if the second parameter is true, then we treat a reference
02778   /// type as valid.
02779   bool isValidPointerAttrType(QualType T, bool RefOkay = false);
02780 
02781   bool CheckRegparmAttr(const AttributeList &attr, unsigned &value);
02782   bool CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC, 
02783                             const FunctionDecl *FD = nullptr);
02784   bool CheckNoReturnAttr(const AttributeList &attr);
02785   bool checkStringLiteralArgumentAttr(const AttributeList &Attr,
02786                                       unsigned ArgNum, StringRef &Str,
02787                                       SourceLocation *ArgLocation = nullptr);
02788   bool checkMSInheritanceAttrOnDefinition(
02789       CXXRecordDecl *RD, SourceRange Range, bool BestCase,
02790       MSInheritanceAttr::Spelling SemanticSpelling);
02791 
02792   void CheckAlignasUnderalignment(Decl *D);
02793 
02794   /// Adjust the calling convention of a method to be the ABI default if it
02795   /// wasn't specified explicitly.  This handles method types formed from
02796   /// function type typedefs and typename template arguments.
02797   void adjustMemberFunctionCC(QualType &T, bool IsStatic);
02798 
02799   // Check if there is an explicit attribute, but only look through parens.
02800   // The intent is to look for an attribute on the current declarator, but not
02801   // one that came from a typedef.
02802   bool hasExplicitCallingConv(QualType &T);
02803 
02804   /// Get the outermost AttributedType node that sets a calling convention.
02805   /// Valid types should not have multiple attributes with different CCs.
02806   const AttributedType *getCallingConvAttributedType(QualType T) const;
02807 
02808   /// \brief Stmt attributes - this routine is the top level dispatcher.
02809   StmtResult ProcessStmtAttributes(Stmt *Stmt, AttributeList *Attrs,
02810                                    SourceRange Range);
02811 
02812   void WarnConflictingTypedMethods(ObjCMethodDecl *Method,
02813                                    ObjCMethodDecl *MethodDecl,
02814                                    bool IsProtocolMethodDecl);
02815 
02816   void CheckConflictingOverridingMethod(ObjCMethodDecl *Method,
02817                                    ObjCMethodDecl *Overridden,
02818                                    bool IsProtocolMethodDecl);
02819 
02820   /// WarnExactTypedMethods - This routine issues a warning if method
02821   /// implementation declaration matches exactly that of its declaration.
02822   void WarnExactTypedMethods(ObjCMethodDecl *Method,
02823                              ObjCMethodDecl *MethodDecl,
02824                              bool IsProtocolMethodDecl);
02825 
02826   typedef llvm::SmallPtrSet<Selector, 8> SelectorSet;
02827   typedef llvm::DenseMap<Selector, ObjCMethodDecl*> ProtocolsMethodsMap;
02828 
02829   /// CheckImplementationIvars - This routine checks if the instance variables
02830   /// listed in the implelementation match those listed in the interface.
02831   void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
02832                                 ObjCIvarDecl **Fields, unsigned nIvars,
02833                                 SourceLocation Loc);
02834 
02835   /// ImplMethodsVsClassMethods - This is main routine to warn if any method
02836   /// remains unimplemented in the class or category \@implementation.
02837   void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl,
02838                                  ObjCContainerDecl* IDecl,
02839                                  bool IncompleteImpl = false);
02840 
02841   /// DiagnoseUnimplementedProperties - This routine warns on those properties
02842   /// which must be implemented by this implementation.
02843   void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl,
02844                                        ObjCContainerDecl *CDecl,
02845                                        bool SynthesizeProperties);
02846 
02847   /// DefaultSynthesizeProperties - This routine default synthesizes all
02848   /// properties which must be synthesized in the class's \@implementation.
02849   void DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl,
02850                                     ObjCInterfaceDecl *IDecl);
02851   void DefaultSynthesizeProperties(Scope *S, Decl *D);
02852 
02853   /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is
02854   /// an ivar synthesized for 'Method' and 'Method' is a property accessor
02855   /// declared in class 'IFace'.
02856   bool IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace,
02857                                       ObjCMethodDecl *Method, ObjCIvarDecl *IV);
02858   
02859   /// DiagnoseUnusedBackingIvarInAccessor - Issue an 'unused' warning if ivar which
02860   /// backs the property is not used in the property's accessor.
02861   void DiagnoseUnusedBackingIvarInAccessor(Scope *S,
02862                                            const ObjCImplementationDecl *ImplD);
02863   
02864   /// GetIvarBackingPropertyAccessor - If method is a property setter/getter and
02865   /// it property has a backing ivar, returns this ivar; otherwise, returns NULL.
02866   /// It also returns ivar's property on success.
02867   ObjCIvarDecl *GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method,
02868                                                const ObjCPropertyDecl *&PDecl) const;
02869   
02870   /// Called by ActOnProperty to handle \@property declarations in
02871   /// class extensions.
02872   ObjCPropertyDecl *HandlePropertyInClassExtension(Scope *S,
02873                       SourceLocation AtLoc,
02874                       SourceLocation LParenLoc,
02875                       FieldDeclarator &FD,
02876                       Selector GetterSel,
02877                       Selector SetterSel,
02878                       const bool isAssign,
02879                       const bool isReadWrite,
02880                       const unsigned Attributes,
02881                       const unsigned AttributesAsWritten,
02882                       bool *isOverridingProperty,
02883                       TypeSourceInfo *T,
02884                       tok::ObjCKeywordKind MethodImplKind);
02885 
02886   /// Called by ActOnProperty and HandlePropertyInClassExtension to
02887   /// handle creating the ObjcPropertyDecl for a category or \@interface.
02888   ObjCPropertyDecl *CreatePropertyDecl(Scope *S,
02889                                        ObjCContainerDecl *CDecl,
02890                                        SourceLocation AtLoc,
02891                                        SourceLocation LParenLoc,
02892                                        FieldDeclarator &FD,
02893                                        Selector GetterSel,
02894                                        Selector SetterSel,
02895                                        const bool isAssign,
02896                                        const bool isReadWrite,
02897                                        const unsigned Attributes,
02898                                        const unsigned AttributesAsWritten,
02899                                        TypeSourceInfo *T,
02900                                        tok::ObjCKeywordKind MethodImplKind,
02901                                        DeclContext *lexicalDC = nullptr);
02902 
02903   /// AtomicPropertySetterGetterRules - This routine enforces the rule (via
02904   /// warning) when atomic property has one but not the other user-declared
02905   /// setter or getter.
02906   void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl,
02907                                        ObjCContainerDecl* IDecl);
02908 
02909   void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D);
02910 
02911   void DiagnoseMissingDesignatedInitOverrides(
02912                                           const ObjCImplementationDecl *ImplD,
02913                                           const ObjCInterfaceDecl *IFD);
02914 
02915   void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID);
02916 
02917   enum MethodMatchStrategy {
02918     MMS_loose,
02919     MMS_strict
02920   };
02921 
02922   /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
02923   /// true, or false, accordingly.
02924   bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
02925                                   const ObjCMethodDecl *PrevMethod,
02926                                   MethodMatchStrategy strategy = MMS_strict);
02927 
02928   /// MatchAllMethodDeclarations - Check methods declaraed in interface or
02929   /// or protocol against those declared in their implementations.
02930   void MatchAllMethodDeclarations(const SelectorSet &InsMap,
02931                                   const SelectorSet &ClsMap,
02932                                   SelectorSet &InsMapSeen,
02933                                   SelectorSet &ClsMapSeen,
02934                                   ObjCImplDecl* IMPDecl,
02935                                   ObjCContainerDecl* IDecl,
02936                                   bool &IncompleteImpl,
02937                                   bool ImmediateClass,
02938                                   bool WarnCategoryMethodImpl=false);
02939 
02940   /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in
02941   /// category matches with those implemented in its primary class and
02942   /// warns each time an exact match is found.
02943   void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP);
02944 
02945   /// \brief Add the given method to the list of globally-known methods.
02946   void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method);
02947 
02948 private:
02949   /// AddMethodToGlobalPool - Add an instance or factory method to the global
02950   /// pool. See descriptoin of AddInstanceMethodToGlobalPool.
02951   void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance);
02952 
02953   /// LookupMethodInGlobalPool - Returns the instance or factory method and
02954   /// optionally warns if there are multiple signatures.
02955   ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R,
02956                                            bool receiverIdOrClass,
02957                                            bool warn, bool instance);
02958 
02959 public:
02960   /// \brief - Returns instance or factory methods in global method pool for
02961   /// given selector. If no such method or only one method found, function returns
02962   /// false; otherwise, it returns true
02963   bool CollectMultipleMethodsInGlobalPool(Selector Sel,
02964                                           SmallVectorImpl<ObjCMethodDecl*>& Methods,
02965                                           bool instance);
02966     
02967   bool AreMultipleMethodsInGlobalPool(Selector Sel,
02968                                       bool instance);
02969 
02970 private:
02971   /// \brief - Returns a selector which best matches given argument list or
02972   /// nullptr if none could be found
02973   ObjCMethodDecl *SelectBestMethod(Selector Sel, MultiExprArg Args,
02974                                    bool IsInstance);
02975     
02976 
02977   /// \brief Record the typo correction failure and return an empty correction.
02978   TypoCorrection FailedCorrection(IdentifierInfo *Typo, SourceLocation TypoLoc,
02979                                   bool RecordFailure = true,
02980                                   bool IsUnqualifiedLookup = false) {
02981     if (IsUnqualifiedLookup)
02982       (void)UnqualifiedTyposCorrected[Typo];
02983     if (RecordFailure)
02984       TypoCorrectionFailures[Typo].insert(TypoLoc);
02985     return TypoCorrection();
02986   }
02987 
02988 public:
02989   /// AddInstanceMethodToGlobalPool - All instance methods in a translation
02990   /// unit are added to a global pool. This allows us to efficiently associate
02991   /// a selector with a method declaraation for purposes of typechecking
02992   /// messages sent to "id" (where the class of the object is unknown).
02993   void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
02994     AddMethodToGlobalPool(Method, impl, /*instance*/true);
02995   }
02996 
02997   /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
02998   void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
02999     AddMethodToGlobalPool(Method, impl, /*instance*/false);
03000   }
03001 
03002   /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global
03003   /// pool.
03004   void AddAnyMethodToGlobalPool(Decl *D);
03005 
03006   /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
03007   /// there are multiple signatures.
03008   ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R,
03009                                                    bool receiverIdOrClass=false,
03010                                                    bool warn=true) {
03011     return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
03012                                     warn, /*instance*/true);
03013   }
03014 
03015   /// LookupFactoryMethodInGlobalPool - Returns the method and warns if
03016   /// there are multiple signatures.
03017   ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R,
03018                                                   bool receiverIdOrClass=false,
03019                                                   bool warn=true) {
03020     return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
03021                                     warn, /*instance*/false);
03022   }
03023 
03024   const ObjCMethodDecl *SelectorsForTypoCorrection(Selector Sel,
03025                               QualType ObjectType=QualType());
03026   /// LookupImplementedMethodInGlobalPool - Returns the method which has an
03027   /// implementation.
03028   ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel);
03029 
03030   /// CollectIvarsToConstructOrDestruct - Collect those ivars which require
03031   /// initialization.
03032   void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI,
03033                                   SmallVectorImpl<ObjCIvarDecl*> &Ivars);
03034 
03035   //===--------------------------------------------------------------------===//
03036   // Statement Parsing Callbacks: SemaStmt.cpp.
03037 public:
03038   class FullExprArg {
03039   public:
03040     FullExprArg(Sema &actions) : E(nullptr) { }
03041 
03042     ExprResult release() {
03043       return E;
03044     }
03045 
03046     Expr *get() const { return E; }
03047 
03048     Expr *operator->() {
03049       return E;
03050     }
03051 
03052   private:
03053     // FIXME: No need to make the entire Sema class a friend when it's just
03054     // Sema::MakeFullExpr that needs access to the constructor below.
03055     friend class Sema;
03056 
03057     explicit FullExprArg(Expr *expr) : E(expr) {}
03058 
03059     Expr *E;
03060   };
03061 
03062   FullExprArg MakeFullExpr(Expr *Arg) {
03063     return MakeFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation());
03064   }
03065   FullExprArg MakeFullExpr(Expr *Arg, SourceLocation CC) {
03066     return FullExprArg(ActOnFinishFullExpr(Arg, CC).get());
03067   }
03068   FullExprArg MakeFullDiscardedValueExpr(Expr *Arg) {
03069     ExprResult FE =
03070       ActOnFinishFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation(),
03071                           /*DiscardedValue*/ true);
03072     return FullExprArg(FE.get());
03073   }
03074 
03075   StmtResult ActOnExprStmt(ExprResult Arg);
03076   StmtResult ActOnExprStmtError();
03077 
03078   StmtResult ActOnNullStmt(SourceLocation SemiLoc,
03079                            bool HasLeadingEmptyMacro = false);
03080 
03081   void ActOnStartOfCompoundStmt();
03082   void ActOnFinishOfCompoundStmt();
03083   StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
03084                                ArrayRef<Stmt *> Elts, bool isStmtExpr);
03085 
03086   /// \brief A RAII object to enter scope of a compound statement.
03087   class CompoundScopeRAII {
03088   public:
03089     CompoundScopeRAII(Sema &S): S(S) {
03090       S.ActOnStartOfCompoundStmt();
03091     }
03092 
03093     ~CompoundScopeRAII() {
03094       S.ActOnFinishOfCompoundStmt();
03095     }
03096 
03097   private:
03098     Sema &S;
03099   };
03100 
03101   StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl,
03102                                    SourceLocation StartLoc,
03103                                    SourceLocation EndLoc);
03104   void ActOnForEachDeclStmt(DeclGroupPtrTy Decl);
03105   StmtResult ActOnForEachLValueExpr(Expr *E);
03106   StmtResult ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal,
03107                                    SourceLocation DotDotDotLoc, Expr *RHSVal,
03108                                    SourceLocation ColonLoc);
03109   void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt);
03110 
03111   StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
03112                                       SourceLocation ColonLoc,
03113                                       Stmt *SubStmt, Scope *CurScope);
03114   StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl,
03115                             SourceLocation ColonLoc, Stmt *SubStmt);
03116 
03117   StmtResult ActOnAttributedStmt(SourceLocation AttrLoc,
03118                                  ArrayRef<const Attr*> Attrs,
03119                                  Stmt *SubStmt);
03120 
03121   StmtResult ActOnIfStmt(SourceLocation IfLoc,
03122                          FullExprArg CondVal, Decl *CondVar,
03123                          Stmt *ThenVal,
03124                          SourceLocation ElseLoc, Stmt *ElseVal);
03125   StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc,
03126                                             Expr *Cond,
03127                                             Decl *CondVar);
03128   StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
03129                                            Stmt *Switch, Stmt *Body);
03130   StmtResult ActOnWhileStmt(SourceLocation WhileLoc,
03131                             FullExprArg Cond,
03132                             Decl *CondVar, Stmt *Body);
03133   StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body,
03134                                  SourceLocation WhileLoc,
03135                                  SourceLocation CondLParen, Expr *Cond,
03136                                  SourceLocation CondRParen);
03137 
03138   StmtResult ActOnForStmt(SourceLocation ForLoc,
03139                           SourceLocation LParenLoc,
03140                           Stmt *First, FullExprArg Second,
03141                           Decl *SecondVar,
03142                           FullExprArg Third,
03143                           SourceLocation RParenLoc,
03144                           Stmt *Body);
03145   ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc,
03146                                            Expr *collection);
03147   StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
03148                                         Stmt *First, Expr *collection,
03149                                         SourceLocation RParenLoc);
03150   StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body);
03151 
03152   enum BuildForRangeKind {
03153     /// Initial building of a for-range statement.
03154     BFRK_Build,
03155     /// Instantiation or recovery rebuild of a for-range statement. Don't
03156     /// attempt any typo-correction.
03157     BFRK_Rebuild,
03158     /// Determining whether a for-range statement could be built. Avoid any
03159     /// unnecessary or irreversible actions.
03160     BFRK_Check
03161   };
03162 
03163   StmtResult ActOnCXXForRangeStmt(SourceLocation ForLoc, Stmt *LoopVar,
03164                                   SourceLocation ColonLoc, Expr *Collection,
03165                                   SourceLocation RParenLoc,
03166                                   BuildForRangeKind Kind);
03167   StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc,
03168                                   SourceLocation ColonLoc,
03169                                   Stmt *RangeDecl, Stmt *BeginEndDecl,
03170                                   Expr *Cond, Expr *Inc,
03171                                   Stmt *LoopVarDecl,
03172                                   SourceLocation RParenLoc,
03173                                   BuildForRangeKind Kind);
03174   StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body);
03175 
03176   StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
03177                            SourceLocation LabelLoc,
03178                            LabelDecl *TheDecl);
03179   StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
03180                                    SourceLocation StarLoc,
03181                                    Expr *DestExp);
03182   StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope);
03183   StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope);
03184 
03185   void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope,
03186                                 CapturedRegionKind Kind, unsigned NumParams);
03187   typedef std::pair<StringRef, QualType> CapturedParamNameType;
03188   void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope,
03189                                 CapturedRegionKind Kind,
03190                                 ArrayRef<CapturedParamNameType> Params);
03191   StmtResult ActOnCapturedRegionEnd(Stmt *S);
03192   void ActOnCapturedRegionError();
03193   RecordDecl *CreateCapturedStmtRecordDecl(CapturedDecl *&CD,
03194                                            SourceLocation Loc,
03195                                            unsigned NumParams);
03196   VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E,
03197                                    bool AllowFunctionParameters);
03198   bool isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD,
03199                               bool AllowFunctionParameters);
03200 
03201   StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
03202                              Scope *CurScope);
03203   StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
03204   StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
03205 
03206   StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
03207                              bool IsVolatile, unsigned NumOutputs,
03208                              unsigned NumInputs, IdentifierInfo **Names,
03209                              MultiExprArg Constraints, MultiExprArg Exprs,
03210                              Expr *AsmString, MultiExprArg Clobbers,
03211                              SourceLocation RParenLoc);
03212 
03213   ExprResult LookupInlineAsmIdentifier(CXXScopeSpec &SS,
03214                                        SourceLocation TemplateKWLoc,
03215                                        UnqualifiedId &Id,
03216                                        llvm::InlineAsmIdentifierInfo &Info,
03217                                        bool IsUnevaluatedContext);
03218   bool LookupInlineAsmField(StringRef Base, StringRef Member,
03219                             unsigned &Offset, SourceLocation AsmLoc);
03220   StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
03221                             ArrayRef<Token> AsmToks,
03222                             StringRef AsmString,
03223                             unsigned NumOutputs, unsigned NumInputs,
03224                             ArrayRef<StringRef> Constraints,
03225                             ArrayRef<StringRef> Clobbers,
03226                             ArrayRef<Expr*> Exprs,
03227                             SourceLocation EndLoc);
03228   LabelDecl *GetOrCreateMSAsmLabel(StringRef ExternalLabelName,
03229                                    SourceLocation Location,
03230                                    bool AlwaysCreate);
03231 
03232   VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType,
03233                                   SourceLocation StartLoc,
03234                                   SourceLocation IdLoc, IdentifierInfo *Id,
03235                                   bool Invalid = false);
03236 
03237   Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D);
03238 
03239   StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen,
03240                                   Decl *Parm, Stmt *Body);
03241 
03242   StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body);
03243 
03244   StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try,
03245                                 MultiStmtArg Catch, Stmt *Finally);
03246 
03247   StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw);
03248   StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw,
03249                                   Scope *CurScope);
03250   ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc,
03251                                             Expr *operand);
03252   StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
03253                                          Expr *SynchExpr,
03254                                          Stmt *SynchBody);
03255 
03256   StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body);
03257 
03258   VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo,
03259                                      SourceLocation StartLoc,
03260                                      SourceLocation IdLoc,
03261                                      IdentifierInfo *Id);
03262 
03263   Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D);
03264 
03265   StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
03266                                 Decl *ExDecl, Stmt *HandlerBlock);
03267   StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
03268                               ArrayRef<Stmt *> Handlers);
03269 
03270   StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ?
03271                               SourceLocation TryLoc, Stmt *TryBlock,
03272                               Stmt *Handler);
03273   StmtResult ActOnSEHExceptBlock(SourceLocation Loc,
03274                                  Expr *FilterExpr,
03275                                  Stmt *Block);
03276   StmtResult ActOnSEHFinallyBlock(SourceLocation Loc, Stmt *Block);
03277   StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope);
03278 
03279   void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock);
03280 
03281   bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const;
03282 
03283   /// \brief If it's a file scoped decl that must warn if not used, keep track
03284   /// of it.
03285   void MarkUnusedFileScopedDecl(const DeclaratorDecl *D);
03286 
03287   /// DiagnoseUnusedExprResult - If the statement passed in is an expression
03288   /// whose result is unused, warn.
03289   void DiagnoseUnusedExprResult(const Stmt *S);
03290   void DiagnoseUnusedNestedTypedefs(const RecordDecl *D);
03291   void DiagnoseUnusedDecl(const NamedDecl *ND);
03292 
03293   /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null
03294   /// statement as a \p Body, and it is located on the same line.
03295   ///
03296   /// This helps prevent bugs due to typos, such as:
03297   ///     if (condition);
03298   ///       do_stuff();
03299   void DiagnoseEmptyStmtBody(SourceLocation StmtLoc,
03300                              const Stmt *Body,
03301                              unsigned DiagID);
03302 
03303   /// Warn if a for/while loop statement \p S, which is followed by
03304   /// \p PossibleBody, has a suspicious null statement as a body.
03305   void DiagnoseEmptyLoopBody(const Stmt *S,
03306                              const Stmt *PossibleBody);
03307 
03308   ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool) {
03309     return DelayedDiagnostics.push(pool);
03310   }
03311   void PopParsingDeclaration(ParsingDeclState state, Decl *decl);
03312 
03313   typedef ProcessingContextState ParsingClassState;
03314   ParsingClassState PushParsingClass() {
03315     return DelayedDiagnostics.pushUndelayed();
03316   }
03317   void PopParsingClass(ParsingClassState state) {
03318     DelayedDiagnostics.popUndelayed(state);
03319   }
03320 
03321   void redelayDiagnostics(sema::DelayedDiagnosticPool &pool);
03322 
03323   enum AvailabilityDiagnostic { AD_Deprecation, AD_Unavailable };
03324 
03325   void EmitAvailabilityWarning(AvailabilityDiagnostic AD,
03326                                NamedDecl *D, StringRef Message,
03327                                SourceLocation Loc,
03328                                const ObjCInterfaceDecl *UnknownObjCClass,
03329                                const ObjCPropertyDecl  *ObjCProperty,
03330                                bool ObjCPropertyAccess);
03331 
03332   bool makeUnavailableInSystemHeader(SourceLocation loc,
03333                                      StringRef message);
03334 
03335   //===--------------------------------------------------------------------===//
03336   // Expression Parsing Callbacks: SemaExpr.cpp.
03337 
03338   bool CanUseDecl(NamedDecl *D);
03339   bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
03340                          const ObjCInterfaceDecl *UnknownObjCClass=nullptr,
03341                          bool ObjCPropertyAccess=false);
03342   void NoteDeletedFunction(FunctionDecl *FD);
03343   std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD);
03344   bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
03345                                         ObjCMethodDecl *Getter,
03346                                         SourceLocation Loc);
03347   void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
03348                              ArrayRef<Expr *> Args);
03349 
03350   void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext,
03351                                        Decl *LambdaContextDecl = nullptr,
03352                                        bool IsDecltype = false);
03353   enum ReuseLambdaContextDecl_t { ReuseLambdaContextDecl };
03354   void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext,
03355                                        ReuseLambdaContextDecl_t,
03356                                        bool IsDecltype = false);
03357   void PopExpressionEvaluationContext();
03358 
03359   void DiscardCleanupsInEvaluationContext();
03360 
03361   ExprResult TransformToPotentiallyEvaluated(Expr *E);
03362   ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
03363 
03364   ExprResult ActOnConstantExpression(ExprResult Res);
03365 
03366   // Functions for marking a declaration referenced.  These functions also
03367   // contain the relevant logic for marking if a reference to a function or
03368   // variable is an odr-use (in the C++11 sense).  There are separate variants
03369   // for expressions referring to a decl; these exist because odr-use marking
03370   // needs to be delayed for some constant variables when we build one of the
03371   // named expressions.
03372   void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool OdrUse);
03373   void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func,
03374                               bool OdrUse = true);
03375   void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var);
03376   void MarkDeclRefReferenced(DeclRefExpr *E);
03377   void MarkMemberReferenced(MemberExpr *E);
03378 
03379   void UpdateMarkingForLValueToRValue(Expr *E);
03380   void CleanupVarDeclMarking();
03381 
03382   enum TryCaptureKind {
03383     TryCapture_Implicit, TryCapture_ExplicitByVal, TryCapture_ExplicitByRef
03384   };
03385 
03386   /// \brief Try to capture the given variable.
03387   ///
03388   /// \param Var The variable to capture.
03389   ///
03390   /// \param Loc The location at which the capture occurs.
03391   ///
03392   /// \param Kind The kind of capture, which may be implicit (for either a
03393   /// block or a lambda), or explicit by-value or by-reference (for a lambda).
03394   ///
03395   /// \param EllipsisLoc The location of the ellipsis, if one is provided in
03396   /// an explicit lambda capture.
03397   ///
03398   /// \param BuildAndDiagnose Whether we are actually supposed to add the
03399   /// captures or diagnose errors. If false, this routine merely check whether
03400   /// the capture can occur without performing the capture itself or complaining
03401   /// if the variable cannot be captured.
03402   ///
03403   /// \param CaptureType Will be set to the type of the field used to capture
03404   /// this variable in the innermost block or lambda. Only valid when the
03405   /// variable can be captured.
03406   ///
03407   /// \param DeclRefType Will be set to the type of a reference to the capture
03408   /// from within the current scope. Only valid when the variable can be
03409   /// captured.
03410   ///
03411   /// \param FunctionScopeIndexToStopAt If non-null, it points to the index
03412   /// of the FunctionScopeInfo stack beyond which we do not attempt to capture.
03413   /// This is useful when enclosing lambdas must speculatively capture 
03414   /// variables that may or may not be used in certain specializations of
03415   /// a nested generic lambda.
03416   /// 
03417   /// \returns true if an error occurred (i.e., the variable cannot be
03418   /// captured) and false if the capture succeeded.
03419   bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, TryCaptureKind Kind,
03420                           SourceLocation EllipsisLoc, bool BuildAndDiagnose,
03421                           QualType &CaptureType,
03422                           QualType &DeclRefType, 
03423                           const unsigned *const FunctionScopeIndexToStopAt);
03424 
03425   /// \brief Try to capture the given variable.
03426   bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc,
03427                           TryCaptureKind Kind = TryCapture_Implicit,
03428                           SourceLocation EllipsisLoc = SourceLocation());
03429 
03430   /// \brief Given a variable, determine the type that a reference to that
03431   /// variable will have in the given scope.
03432   QualType getCapturedDeclRefType(VarDecl *Var, SourceLocation Loc);
03433 
03434   void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T);
03435   void MarkDeclarationsReferencedInExpr(Expr *E,
03436                                         bool SkipLocalVariables = false);
03437 
03438   /// \brief Try to recover by turning the given expression into a
03439   /// call.  Returns true if recovery was attempted or an error was
03440   /// emitted; this may also leave the ExprResult invalid.
03441   bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD,
03442                             bool ForceComplain = false,
03443                             bool (*IsPlausibleResult)(QualType) = nullptr);
03444 
03445   /// \brief Figure out if an expression could be turned into a call.
03446   bool tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy,
03447                      UnresolvedSetImpl &NonTemplateOverloads);
03448 
03449   /// \brief Conditionally issue a diagnostic based on the current
03450   /// evaluation context.
03451   ///
03452   /// \param Statement If Statement is non-null, delay reporting the
03453   /// diagnostic until the function body is parsed, and then do a basic
03454   /// reachability analysis to determine if the statement is reachable.
03455   /// If it is unreachable, the diagnostic will not be emitted.
03456   bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement,
03457                            const PartialDiagnostic &PD);
03458 
03459   // Primary Expressions.
03460   SourceRange getExprRange(Expr *E) const;
03461 
03462   ExprResult ActOnIdExpression(
03463       Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
03464       UnqualifiedId &Id, bool HasTrailingLParen, bool IsAddressOfOperand,
03465       std::unique_ptr<CorrectionCandidateCallback> CCC = nullptr,
03466       bool IsInlineAsmIdentifier = false);
03467 
03468   void DecomposeUnqualifiedId(const UnqualifiedId &Id,
03469                               TemplateArgumentListInfo &Buffer,
03470                               DeclarationNameInfo &NameInfo,
03471                               const TemplateArgumentListInfo *&TemplateArgs);
03472 
03473   bool
03474   DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
03475                       std::unique_ptr<CorrectionCandidateCallback> CCC,
03476                       TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr,
03477                       ArrayRef<Expr *> Args = None);
03478 
03479   ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S,
03480                                 IdentifierInfo *II,
03481                                 bool AllowBuiltinCreation=false);
03482 
03483   ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS,
03484                                         SourceLocation TemplateKWLoc,
03485                                         const DeclarationNameInfo &NameInfo,
03486                                         bool isAddressOfOperand,
03487                                 const TemplateArgumentListInfo *TemplateArgs);
03488 
03489   ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
03490                               ExprValueKind VK,
03491                               SourceLocation Loc,
03492                               const CXXScopeSpec *SS = nullptr);
03493   ExprResult
03494   BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK,
03495                    const DeclarationNameInfo &NameInfo,
03496                    const CXXScopeSpec *SS = nullptr,
03497                    NamedDecl *FoundD = nullptr,
03498                    const TemplateArgumentListInfo *TemplateArgs = nullptr);
03499   ExprResult
03500   BuildAnonymousStructUnionMemberReference(
03501       const CXXScopeSpec &SS,
03502       SourceLocation nameLoc,
03503       IndirectFieldDecl *indirectField,
03504       DeclAccessPair FoundDecl = DeclAccessPair::make(nullptr, AS_none),
03505       Expr *baseObjectExpr = nullptr,
03506       SourceLocation opLoc = SourceLocation());
03507 
03508   ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
03509                                              SourceLocation TemplateKWLoc,
03510                                              LookupResult &R,
03511                                 const TemplateArgumentListInfo *TemplateArgs);
03512   ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS,
03513                                      SourceLocation TemplateKWLoc,
03514                                      LookupResult &R,
03515                                 const TemplateArgumentListInfo *TemplateArgs,
03516                                      bool IsDefiniteInstance);
03517   bool UseArgumentDependentLookup(const CXXScopeSpec &SS,
03518                                   const LookupResult &R,
03519                                   bool HasTrailingLParen);
03520 
03521   ExprResult BuildQualifiedDeclarationNameExpr(
03522       CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo,
03523       bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI = nullptr);
03524 
03525   ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
03526                                        SourceLocation TemplateKWLoc,
03527                                 const DeclarationNameInfo &NameInfo,
03528                                 const TemplateArgumentListInfo *TemplateArgs);
03529 
03530   ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
03531                                       LookupResult &R,
03532                                       bool NeedsADL);
03533   ExprResult BuildDeclarationNameExpr(
03534       const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D,
03535       NamedDecl *FoundD = nullptr,
03536       const TemplateArgumentListInfo *TemplateArgs = nullptr);
03537 
03538   ExprResult BuildLiteralOperatorCall(LookupResult &R,
03539                       DeclarationNameInfo &SuffixInfo,
03540                       ArrayRef<Expr *> Args,
03541                       SourceLocation LitEndLoc,
03542                       TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr);
03543 
03544   ExprResult BuildPredefinedExpr(SourceLocation Loc,
03545                                  PredefinedExpr::IdentType IT);
03546   ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
03547   ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val);
03548 
03549   bool CheckLoopHintExpr(Expr *E, SourceLocation Loc);
03550 
03551   ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr);
03552   ExprResult ActOnCharacterConstant(const Token &Tok,
03553                                     Scope *UDLScope = nullptr);
03554   ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E);
03555   ExprResult ActOnParenListExpr(SourceLocation L,
03556                                 SourceLocation R,
03557                                 MultiExprArg Val);
03558 
03559   /// ActOnStringLiteral - The specified tokens were lexed as pasted string
03560   /// fragments (e.g. "foo" "bar" L"baz").
03561   ExprResult ActOnStringLiteral(ArrayRef<Token> StringToks,
03562                                 Scope *UDLScope = nullptr);
03563 
03564   ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc,
03565                                        SourceLocation DefaultLoc,
03566                                        SourceLocation RParenLoc,
03567                                        Expr *ControllingExpr,
03568                                        ArrayRef<ParsedType> ArgTypes,
03569                                        ArrayRef<Expr *> ArgExprs);
03570   ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc,
03571                                         SourceLocation DefaultLoc,
03572                                         SourceLocation RParenLoc,
03573                                         Expr *ControllingExpr,
03574                                         ArrayRef<TypeSourceInfo *> Types,
03575                                         ArrayRef<Expr *> Exprs);
03576 
03577   // Binary/Unary Operators.  'Tok' is the token for the operator.
03578   ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc,
03579                                   Expr *InputExpr);
03580   ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc,
03581                           UnaryOperatorKind Opc, Expr *Input);
03582   ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
03583                           tok::TokenKind Op, Expr *Input);
03584 
03585   QualType CheckAddressOfOperand(ExprResult &Operand, SourceLocation OpLoc);
03586 
03587   ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo,
03588                                             SourceLocation OpLoc,
03589                                             UnaryExprOrTypeTrait ExprKind,
03590                                             SourceRange R);
03591   ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc,
03592                                             UnaryExprOrTypeTrait ExprKind);
03593   ExprResult
03594     ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc,
03595                                   UnaryExprOrTypeTrait ExprKind,
03596                                   bool IsType, void *TyOrEx,
03597                                   const SourceRange &ArgRange);
03598 
03599   ExprResult CheckPlaceholderExpr(Expr *E);
03600   bool CheckVecStepExpr(Expr *E);
03601 
03602   bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind);
03603   bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc,
03604                                         SourceRange ExprRange,
03605                                         UnaryExprOrTypeTrait ExprKind);
03606   ExprResult ActOnSizeofParameterPackExpr(Scope *S,
03607                                           SourceLocation OpLoc,
03608                                           IdentifierInfo &Name,
03609                                           SourceLocation NameLoc,
03610                                           SourceLocation RParenLoc);
03611   ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
03612                                  tok::TokenKind Kind, Expr *Input);
03613 
03614   ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc,
03615                                      Expr *Idx, SourceLocation RLoc);
03616   ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc,
03617                                              Expr *Idx, SourceLocation RLoc);
03618 
03619   // This struct is for use by ActOnMemberAccess to allow
03620   // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after
03621   // changing the access operator from a '.' to a '->' (to see if that is the
03622   // change needed to fix an error about an unknown member, e.g. when the class
03623   // defines a custom operator->).
03624   struct ActOnMemberAccessExtraArgs {
03625     Scope *S;
03626     UnqualifiedId &Id;
03627     Decl *ObjCImpDecl;
03628     bool HasTrailingLParen;
03629   };
03630 
03631   ExprResult BuildMemberReferenceExpr(
03632       Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow,
03633       CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
03634       NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo,
03635       const TemplateArgumentListInfo *TemplateArgs,
03636       ActOnMemberAccessExtraArgs *ExtraArgs = nullptr);
03637 
03638   ExprResult
03639   BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc,
03640                            bool IsArrow, const CXXScopeSpec &SS,
03641                            SourceLocation TemplateKWLoc,
03642                            NamedDecl *FirstQualifierInScope, LookupResult &R,
03643                            const TemplateArgumentListInfo *TemplateArgs,
03644                            bool SuppressQualifierCheck = false,
03645                            ActOnMemberAccessExtraArgs *ExtraArgs = nullptr);
03646 
03647   ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow);
03648 
03649   bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType,
03650                                      const CXXScopeSpec &SS,
03651                                      const LookupResult &R);
03652 
03653   ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType,
03654                                       bool IsArrow, SourceLocation OpLoc,
03655                                       const CXXScopeSpec &SS,
03656                                       SourceLocation TemplateKWLoc,
03657                                       NamedDecl *FirstQualifierInScope,
03658                                const DeclarationNameInfo &NameInfo,
03659                                const TemplateArgumentListInfo *TemplateArgs);
03660 
03661   ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base,
03662                                    SourceLocation OpLoc,
03663                                    tok::TokenKind OpKind,
03664                                    CXXScopeSpec &SS,
03665                                    SourceLocation TemplateKWLoc,
03666                                    UnqualifiedId &Member,
03667                                    Decl *ObjCImpDecl,
03668                                    bool HasTrailingLParen);
03669 
03670   void ActOnDefaultCtorInitializers(Decl *CDtorDecl);
03671   bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
03672                                FunctionDecl *FDecl,
03673                                const FunctionProtoType *Proto,
03674                                ArrayRef<Expr *> Args,
03675                                SourceLocation RParenLoc,
03676                                bool ExecConfig = false);
03677   void CheckStaticArrayArgument(SourceLocation CallLoc,
03678                                 ParmVarDecl *Param,
03679                                 const Expr *ArgExpr);
03680 
03681   /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
03682   /// This provides the location of the left/right parens and a list of comma
03683   /// locations.
03684   ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc,
03685                            MultiExprArg ArgExprs, SourceLocation RParenLoc,
03686                            Expr *ExecConfig = nullptr,
03687                            bool IsExecConfig = false);
03688   ExprResult BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl,
03689                                    SourceLocation LParenLoc,
03690                                    ArrayRef<Expr *> Arg,
03691                                    SourceLocation RParenLoc,
03692                                    Expr *Config = nullptr,
03693                                    bool IsExecConfig = false);
03694 
03695   ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc,
03696                                      MultiExprArg ExecConfig,
03697                                      SourceLocation GGGLoc);
03698 
03699   ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc,
03700                            Declarator &D, ParsedType &Ty,
03701                            SourceLocation RParenLoc, Expr *CastExpr);
03702   ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc,
03703                                  TypeSourceInfo *Ty,
03704                                  SourceLocation RParenLoc,
03705                                  Expr *Op);
03706   CastKind PrepareScalarCast(ExprResult &src, QualType destType);
03707 
03708   /// \brief Build an altivec or OpenCL literal.
03709   ExprResult BuildVectorLiteral(SourceLocation LParenLoc,
03710                                 SourceLocation RParenLoc, Expr *E,
03711                                 TypeSourceInfo *TInfo);
03712 
03713   ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME);
03714 
03715   ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
03716                                   ParsedType Ty,
03717                                   SourceLocation RParenLoc,
03718                                   Expr *InitExpr);
03719 
03720   ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc,
03721                                       TypeSourceInfo *TInfo,
03722                                       SourceLocation RParenLoc,
03723                                       Expr *LiteralExpr);
03724 
03725   ExprResult ActOnInitList(SourceLocation LBraceLoc,
03726                            MultiExprArg InitArgList,
03727                            SourceLocation RBraceLoc);
03728 
03729   ExprResult ActOnDesignatedInitializer(Designation &Desig,
03730                                         SourceLocation Loc,
03731                                         bool GNUSyntax,
03732                                         ExprResult Init);
03733 
03734 private:
03735   static BinaryOperatorKind ConvertTokenKindToBinaryOpcode(tok::TokenKind Kind);
03736 
03737 public:
03738   ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
03739                         tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr);
03740   ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc,
03741                         BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr);
03742   ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc,
03743                                 Expr *LHSExpr, Expr *RHSExpr);
03744 
03745   /// ActOnConditionalOp - Parse a ?: operation.  Note that 'LHS' may be null
03746   /// in the case of a the GNU conditional expr extension.
03747   ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
03748                                 SourceLocation ColonLoc,
03749                                 Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr);
03750 
03751   /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
03752   ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
03753                             LabelDecl *TheDecl);
03754 
03755   void ActOnStartStmtExpr();
03756   ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt,
03757                            SourceLocation RPLoc); // "({..})"
03758   void ActOnStmtExprError();
03759 
03760   // __builtin_offsetof(type, identifier(.identifier|[expr])*)
03761   struct OffsetOfComponent {
03762     SourceLocation LocStart, LocEnd;
03763     bool isBrackets;  // true if [expr], false if .ident
03764     union {
03765       IdentifierInfo *IdentInfo;
03766       Expr *E;
03767     } U;
03768   };
03769 
03770   /// __builtin_offsetof(type, a.b[123][456].c)
03771   ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc,
03772                                   TypeSourceInfo *TInfo,
03773                                   OffsetOfComponent *CompPtr,
03774                                   unsigned NumComponents,
03775                                   SourceLocation RParenLoc);
03776   ExprResult ActOnBuiltinOffsetOf(Scope *S,
03777                                   SourceLocation BuiltinLoc,
03778                                   SourceLocation TypeLoc,
03779                                   ParsedType ParsedArgTy,
03780                                   OffsetOfComponent *CompPtr,
03781                                   unsigned NumComponents,
03782                                   SourceLocation RParenLoc);
03783 
03784   // __builtin_choose_expr(constExpr, expr1, expr2)
03785   ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
03786                              Expr *CondExpr, Expr *LHSExpr,
03787                              Expr *RHSExpr, SourceLocation RPLoc);
03788 
03789   // __builtin_va_arg(expr, type)
03790   ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty,
03791                         SourceLocation RPLoc);
03792   ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E,
03793                             TypeSourceInfo *TInfo, SourceLocation RPLoc);
03794 
03795   // __null
03796   ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
03797 
03798   bool CheckCaseExpression(Expr *E);
03799 
03800   /// \brief Describes the result of an "if-exists" condition check.
03801   enum IfExistsResult {
03802     /// \brief The symbol exists.
03803     IER_Exists,
03804 
03805     /// \brief The symbol does not exist.
03806     IER_DoesNotExist,
03807 
03808     /// \brief The name is a dependent name, so the results will differ
03809     /// from one instantiation to the next.
03810     IER_Dependent,
03811 
03812     /// \brief An error occurred.
03813     IER_Error
03814   };
03815 
03816   IfExistsResult
03817   CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS,
03818                                const DeclarationNameInfo &TargetNameInfo);
03819 
03820   IfExistsResult
03821   CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc,
03822                                bool IsIfExists, CXXScopeSpec &SS,
03823                                UnqualifiedId &Name);
03824 
03825   StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc,
03826                                         bool IsIfExists,
03827                                         NestedNameSpecifierLoc QualifierLoc,
03828                                         DeclarationNameInfo NameInfo,
03829                                         Stmt *Nested);
03830   StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc,
03831                                         bool IsIfExists,
03832                                         CXXScopeSpec &SS, UnqualifiedId &Name,
03833                                         Stmt *Nested);
03834 
03835   //===------------------------- "Block" Extension ------------------------===//
03836 
03837   /// ActOnBlockStart - This callback is invoked when a block literal is
03838   /// started.
03839   void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
03840 
03841   /// ActOnBlockArguments - This callback allows processing of block arguments.
03842   /// If there are no arguments, this is still invoked.
03843   void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo,
03844                            Scope *CurScope);
03845 
03846   /// ActOnBlockError - If there is an error parsing a block, this callback
03847   /// is invoked to pop the information about the block from the action impl.
03848   void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
03849 
03850   /// ActOnBlockStmtExpr - This is called when the body of a block statement
03851   /// literal was successfully completed.  ^(int x){...}
03852   ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body,
03853                                 Scope *CurScope);
03854 
03855   //===---------------------------- Clang Extensions ----------------------===//
03856 
03857   /// __builtin_convertvector(...)
03858   ExprResult ActOnConvertVectorExpr(Expr *E, ParsedType ParsedDestTy,
03859                                     SourceLocation BuiltinLoc,
03860                                     SourceLocation RParenLoc);
03861 
03862   //===---------------------------- OpenCL Features -----------------------===//
03863 
03864   /// __builtin_astype(...)
03865   ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy,
03866                              SourceLocation BuiltinLoc,
03867                              SourceLocation RParenLoc);
03868 
03869   //===---------------------------- C++ Features --------------------------===//
03870 
03871   // Act on C++ namespaces
03872   Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc,
03873                                SourceLocation NamespaceLoc,
03874                                SourceLocation IdentLoc,
03875                                IdentifierInfo *Ident,
03876                                SourceLocation LBrace,
03877                                AttributeList *AttrList);
03878   void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace);
03879 
03880   NamespaceDecl *getStdNamespace() const;
03881   NamespaceDecl *getOrCreateStdNamespace();
03882 
03883   CXXRecordDecl *getStdBadAlloc() const;
03884 
03885   /// \brief Tests whether Ty is an instance of std::initializer_list and, if
03886   /// it is and Element is not NULL, assigns the element type to Element.
03887   bool isStdInitializerList(QualType Ty, QualType *Element);
03888 
03889   /// \brief Looks for the std::initializer_list template and instantiates it
03890   /// with Element, or emits an error if it's not found.
03891   ///
03892   /// \returns The instantiated template, or null on error.
03893   QualType BuildStdInitializerList(QualType Element, SourceLocation Loc);
03894 
03895   /// \brief Determine whether Ctor is an initializer-list constructor, as
03896   /// defined in [dcl.init.list]p2.
03897   bool isInitListConstructor(const CXXConstructorDecl *Ctor);
03898 
03899   Decl *ActOnUsingDirective(Scope *CurScope,
03900                             SourceLocation UsingLoc,
03901                             SourceLocation NamespcLoc,
03902                             CXXScopeSpec &SS,
03903                             SourceLocation IdentLoc,
03904                             IdentifierInfo *NamespcName,
03905                             AttributeList *AttrList);
03906 
03907   void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
03908 
03909   Decl *ActOnNamespaceAliasDef(Scope *CurScope,
03910                                SourceLocation NamespaceLoc,
03911                                SourceLocation AliasLoc,
03912                                IdentifierInfo *Alias,
03913                                CXXScopeSpec &SS,
03914                                SourceLocation IdentLoc,
03915                                IdentifierInfo *Ident);
03916 
03917   void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow);
03918   bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target,
03919                             const LookupResult &PreviousDecls,
03920                             UsingShadowDecl *&PrevShadow);
03921   UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD,
03922                                         NamedDecl *Target,
03923                                         UsingShadowDecl *PrevDecl);
03924 
03925   bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc,
03926                                    bool HasTypenameKeyword,
03927                                    const CXXScopeSpec &SS,
03928                                    SourceLocation NameLoc,
03929                                    const LookupResult &Previous);
03930   bool CheckUsingDeclQualifier(SourceLocation UsingLoc,
03931                                const CXXScopeSpec &SS,
03932                                const DeclarationNameInfo &NameInfo,
03933                                SourceLocation NameLoc);
03934 
03935   NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS,
03936                                    SourceLocation UsingLoc,
03937                                    CXXScopeSpec &SS,
03938                                    DeclarationNameInfo NameInfo,
03939                                    AttributeList *AttrList,
03940                                    bool IsInstantiation,
03941                                    bool HasTypenameKeyword,
03942                                    SourceLocation TypenameLoc);
03943 
03944   bool CheckInheritingConstructorUsingDecl(UsingDecl *UD);
03945 
03946   Decl *ActOnUsingDeclaration(Scope *CurScope,
03947                               AccessSpecifier AS,
03948                               bool HasUsingKeyword,
03949                               SourceLocation UsingLoc,
03950                               CXXScopeSpec &SS,
03951                               UnqualifiedId &Name,
03952                               AttributeList *AttrList,
03953                               bool HasTypenameKeyword,
03954                               SourceLocation TypenameLoc);
03955   Decl *ActOnAliasDeclaration(Scope *CurScope,
03956                               AccessSpecifier AS,
03957                               MultiTemplateParamsArg TemplateParams,
03958                               SourceLocation UsingLoc,
03959                               UnqualifiedId &Name,
03960                               AttributeList *AttrList,
03961                               TypeResult Type);
03962 
03963   /// BuildCXXConstructExpr - Creates a complete call to a constructor,
03964   /// including handling of its default argument expressions.
03965   ///
03966   /// \param ConstructKind - a CXXConstructExpr::ConstructionKind
03967   ExprResult
03968   BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
03969                         CXXConstructorDecl *Constructor, MultiExprArg Exprs,
03970                         bool HadMultipleCandidates, bool IsListInitialization,
03971                         bool IsStdInitListInitialization,
03972                         bool RequiresZeroInit, unsigned ConstructKind,
03973                         SourceRange ParenRange);
03974 
03975   // FIXME: Can we remove this and have the above BuildCXXConstructExpr check if
03976   // the constructor can be elidable?
03977   ExprResult
03978   BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
03979                         CXXConstructorDecl *Constructor, bool Elidable,
03980                         MultiExprArg Exprs, bool HadMultipleCandidates,
03981                         bool IsListInitialization,
03982                         bool IsStdInitListInitialization, bool RequiresZeroInit,
03983                         unsigned ConstructKind, SourceRange ParenRange);
03984 
03985   ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field);
03986 
03987   /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating
03988   /// the default expr if needed.
03989   ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc,
03990                                     FunctionDecl *FD,
03991                                     ParmVarDecl *Param);
03992 
03993   /// FinalizeVarWithDestructor - Prepare for calling destructor on the
03994   /// constructed variable.
03995   void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType);
03996 
03997   /// \brief Helper class that collects exception specifications for
03998   /// implicitly-declared special member functions.
03999   class ImplicitExceptionSpecification {
04000     // Pointer to allow copying
04001     Sema *Self;
04002     // We order exception specifications thus:
04003     // noexcept is the most restrictive, but is only used in C++11.
04004     // throw() comes next.
04005     // Then a throw(collected exceptions)
04006     // Finally no specification, which is expressed as noexcept(false).
04007     // throw(...) is used instead if any called function uses it.
04008     ExceptionSpecificationType ComputedEST;
04009     llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen;
04010     SmallVector<QualType, 4> Exceptions;
04011 
04012     void ClearExceptions() {
04013       ExceptionsSeen.clear();
04014       Exceptions.clear();
04015     }
04016 
04017   public:
04018     explicit ImplicitExceptionSpecification(Sema &Self)
04019       : Self(&Self), ComputedEST(EST_BasicNoexcept) {
04020       if (!Self.getLangOpts().CPlusPlus11)
04021         ComputedEST = EST_DynamicNone;
04022     }
04023 
04024     /// \brief Get the computed exception specification type.
04025     ExceptionSpecificationType getExceptionSpecType() const {
04026       assert(ComputedEST != EST_ComputedNoexcept &&
04027              "noexcept(expr) should not be a possible result");
04028       return ComputedEST;
04029     }
04030 
04031     /// \brief The number of exceptions in the exception specification.
04032     unsigned size() const { return Exceptions.size(); }
04033 
04034     /// \brief The set of exceptions in the exception specification.
04035     const QualType *data() const { return Exceptions.data(); }
04036 
04037     /// \brief Integrate another called method into the collected data.
04038     void CalledDecl(SourceLocation CallLoc, const CXXMethodDecl *Method);
04039 
04040     /// \brief Integrate an invoked expression into the collected data.
04041     void CalledExpr(Expr *E);
04042 
04043     /// \brief Overwrite an EPI's exception specification with this
04044     /// computed exception specification.
04045     FunctionProtoType::ExceptionSpecInfo getExceptionSpec() const {
04046       FunctionProtoType::ExceptionSpecInfo ESI;
04047       ESI.Type = getExceptionSpecType();
04048       if (ESI.Type == EST_Dynamic) {
04049         ESI.Exceptions = Exceptions;
04050       } else if (ESI.Type == EST_None) {
04051         /// C++11 [except.spec]p14:
04052         ///   The exception-specification is noexcept(false) if the set of
04053         ///   potential exceptions of the special member function contains "any"
04054         ESI.Type = EST_ComputedNoexcept;
04055         ESI.NoexceptExpr = Self->ActOnCXXBoolLiteral(SourceLocation(),
04056                                                      tok::kw_false).get();
04057       }
04058       return ESI;
04059     }
04060   };
04061 
04062   /// \brief Determine what sort of exception specification a defaulted
04063   /// copy constructor of a class will have.
04064   ImplicitExceptionSpecification
04065   ComputeDefaultedDefaultCtorExceptionSpec(SourceLocation Loc,
04066                                            CXXMethodDecl *MD);
04067 
04068   /// \brief Determine what sort of exception specification a defaulted
04069   /// default constructor of a class will have, and whether the parameter
04070   /// will be const.
04071   ImplicitExceptionSpecification
04072   ComputeDefaultedCopyCtorExceptionSpec(CXXMethodDecl *MD);
04073 
04074   /// \brief Determine what sort of exception specification a defautled
04075   /// copy assignment operator of a class will have, and whether the
04076   /// parameter will be const.
04077   ImplicitExceptionSpecification
04078   ComputeDefaultedCopyAssignmentExceptionSpec(CXXMethodDecl *MD);
04079 
04080   /// \brief Determine what sort of exception specification a defaulted move
04081   /// constructor of a class will have.
04082   ImplicitExceptionSpecification
04083   ComputeDefaultedMoveCtorExceptionSpec(CXXMethodDecl *MD);
04084 
04085   /// \brief Determine what sort of exception specification a defaulted move
04086   /// assignment operator of a class will have.
04087   ImplicitExceptionSpecification
04088   ComputeDefaultedMoveAssignmentExceptionSpec(CXXMethodDecl *MD);
04089 
04090   /// \brief Determine what sort of exception specification a defaulted
04091   /// destructor of a class will have.
04092   ImplicitExceptionSpecification
04093   ComputeDefaultedDtorExceptionSpec(CXXMethodDecl *MD);
04094 
04095   /// \brief Determine what sort of exception specification an inheriting
04096   /// constructor of a class will have.
04097   ImplicitExceptionSpecification
04098   ComputeInheritingCtorExceptionSpec(CXXConstructorDecl *CD);
04099 
04100   /// \brief Evaluate the implicit exception specification for a defaulted
04101   /// special member function.
04102   void EvaluateImplicitExceptionSpec(SourceLocation Loc, CXXMethodDecl *MD);
04103 
04104   /// \brief Check the given exception-specification and update the
04105   /// exception specification information with the results.
04106   void checkExceptionSpecification(bool IsTopLevel,
04107                                    ExceptionSpecificationType EST,
04108                                    ArrayRef<ParsedType> DynamicExceptions,
04109                                    ArrayRef<SourceRange> DynamicExceptionRanges,
04110                                    Expr *NoexceptExpr,
04111                                    SmallVectorImpl<QualType> &Exceptions,
04112                                    FunctionProtoType::ExceptionSpecInfo &ESI);
04113 
04114   /// \brief Determine if we're in a case where we need to (incorrectly) eagerly
04115   /// parse an exception specification to work around a libstdc++ bug.
04116   bool isLibstdcxxEagerExceptionSpecHack(const Declarator &D);
04117 
04118   /// \brief Add an exception-specification to the given member function
04119   /// (or member function template). The exception-specification was parsed
04120   /// after the method itself was declared.
04121   void actOnDelayedExceptionSpecification(Decl *Method,
04122          ExceptionSpecificationType EST,
04123          SourceRange SpecificationRange,
04124          ArrayRef<ParsedType> DynamicExceptions,
04125          ArrayRef<SourceRange> DynamicExceptionRanges,
04126          Expr *NoexceptExpr);
04127 
04128   /// \brief Determine if a special member function should have a deleted
04129   /// definition when it is defaulted.
04130   bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM,
04131                                  bool Diagnose = false);
04132 
04133   /// \brief Declare the implicit default constructor for the given class.
04134   ///
04135   /// \param ClassDecl The class declaration into which the implicit
04136   /// default constructor will be added.
04137   ///
04138   /// \returns The implicitly-declared default constructor.
04139   CXXConstructorDecl *DeclareImplicitDefaultConstructor(
04140                                                      CXXRecordDecl *ClassDecl);
04141 
04142   /// DefineImplicitDefaultConstructor - Checks for feasibility of
04143   /// defining this constructor as the default constructor.
04144   void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
04145                                         CXXConstructorDecl *Constructor);
04146 
04147   /// \brief Declare the implicit destructor for the given class.
04148   ///
04149   /// \param ClassDecl The class declaration into which the implicit
04150   /// destructor will be added.
04151   ///
04152   /// \returns The implicitly-declared destructor.
04153   CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl);
04154 
04155   /// DefineImplicitDestructor - Checks for feasibility of
04156   /// defining this destructor as the default destructor.
04157   void DefineImplicitDestructor(SourceLocation CurrentLocation,
04158                                 CXXDestructorDecl *Destructor);
04159 
04160   /// \brief Build an exception spec for destructors that don't have one.
04161   ///
04162   /// C++11 says that user-defined destructors with no exception spec get one
04163   /// that looks as if the destructor was implicitly declared.
04164   void AdjustDestructorExceptionSpec(CXXRecordDecl *ClassDecl,
04165                                      CXXDestructorDecl *Destructor);
04166 
04167   /// \brief Declare all inheriting constructors for the given class.
04168   ///
04169   /// \param ClassDecl The class declaration into which the inheriting
04170   /// constructors will be added.
04171   void DeclareInheritingConstructors(CXXRecordDecl *ClassDecl);
04172 
04173   /// \brief Define the specified inheriting constructor.
04174   void DefineInheritingConstructor(SourceLocation UseLoc,
04175                                    CXXConstructorDecl *Constructor);
04176 
04177   /// \brief Declare the implicit copy constructor for the given class.
04178   ///
04179   /// \param ClassDecl The class declaration into which the implicit
04180   /// copy constructor will be added.
04181   ///
04182   /// \returns The implicitly-declared copy constructor.
04183   CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl);
04184 
04185   /// DefineImplicitCopyConstructor - Checks for feasibility of
04186   /// defining this constructor as the copy constructor.
04187   void DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
04188                                      CXXConstructorDecl *Constructor);
04189 
04190   /// \brief Declare the implicit move constructor for the given class.
04191   ///
04192   /// \param ClassDecl The Class declaration into which the implicit
04193   /// move constructor will be added.
04194   ///
04195   /// \returns The implicitly-declared move constructor, or NULL if it wasn't
04196   /// declared.
04197   CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl);
04198 
04199   /// DefineImplicitMoveConstructor - Checks for feasibility of
04200   /// defining this constructor as the move constructor.
04201   void DefineImplicitMoveConstructor(SourceLocation CurrentLocation,
04202                                      CXXConstructorDecl *Constructor);
04203 
04204   /// \brief Declare the implicit copy assignment operator for the given class.
04205   ///
04206   /// \param ClassDecl The class declaration into which the implicit
04207   /// copy assignment operator will be added.
04208   ///
04209   /// \returns The implicitly-declared copy assignment operator.
04210   CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl);
04211 
04212   /// \brief Defines an implicitly-declared copy assignment operator.
04213   void DefineImplicitCopyAssignment(SourceLocation CurrentLocation,
04214                                     CXXMethodDecl *MethodDecl);
04215 
04216   /// \brief Declare the implicit move assignment operator for the given class.
04217   ///
04218   /// \param ClassDecl The Class declaration into which the implicit
04219   /// move assignment operator will be added.
04220   ///
04221   /// \returns The implicitly-declared move assignment operator, or NULL if it
04222   /// wasn't declared.
04223   CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl);
04224 
04225   /// \brief Defines an implicitly-declared move assignment operator.
04226   void DefineImplicitMoveAssignment(SourceLocation CurrentLocation,
04227                                     CXXMethodDecl *MethodDecl);
04228 
04229   /// \brief Force the declaration of any implicitly-declared members of this
04230   /// class.
04231   void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class);
04232 
04233   /// \brief Determine whether the given function is an implicitly-deleted
04234   /// special member function.
04235   bool isImplicitlyDeleted(FunctionDecl *FD);
04236 
04237   /// \brief Check whether 'this' shows up in the type of a static member
04238   /// function after the (naturally empty) cv-qualifier-seq would be.
04239   ///
04240   /// \returns true if an error occurred.
04241   bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method);
04242 
04243   /// \brief Whether this' shows up in the exception specification of a static
04244   /// member function.
04245   bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method);
04246 
04247   /// \brief Check whether 'this' shows up in the attributes of the given
04248   /// static member function.
04249   ///
04250   /// \returns true if an error occurred.
04251   bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method);
04252 
04253   /// MaybeBindToTemporary - If the passed in expression has a record type with
04254   /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise
04255   /// it simply returns the passed in expression.
04256   ExprResult MaybeBindToTemporary(Expr *E);
04257 
04258   bool CompleteConstructorCall(CXXConstructorDecl *Constructor,
04259                                MultiExprArg ArgsPtr,
04260                                SourceLocation Loc,
04261                                SmallVectorImpl<Expr*> &ConvertedArgs,
04262                                bool AllowExplicit = false,
04263                                bool IsListInitialization = false);
04264 
04265   ParsedType getInheritingConstructorName(CXXScopeSpec &SS,
04266                                           SourceLocation NameLoc,
04267                                           IdentifierInfo &Name);
04268 
04269   ParsedType getDestructorName(SourceLocation TildeLoc,
04270                                IdentifierInfo &II, SourceLocation NameLoc,
04271                                Scope *S, CXXScopeSpec &SS,
04272                                ParsedType ObjectType,
04273                                bool EnteringContext);
04274 
04275   ParsedType getDestructorType(const DeclSpec& DS, ParsedType ObjectType);
04276 
04277   // Checks that reinterpret casts don't have undefined behavior.
04278   void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType,
04279                                       bool IsDereference, SourceRange Range);
04280 
04281   /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
04282   ExprResult ActOnCXXNamedCast(SourceLocation OpLoc,
04283                                tok::TokenKind Kind,
04284                                SourceLocation LAngleBracketLoc,
04285                                Declarator &D,
04286                                SourceLocation RAngleBracketLoc,
04287                                SourceLocation LParenLoc,
04288                                Expr *E,
04289                                SourceLocation RParenLoc);
04290 
04291   ExprResult BuildCXXNamedCast(SourceLocation OpLoc,
04292                                tok::TokenKind Kind,
04293                                TypeSourceInfo *Ty,
04294                                Expr *E,
04295                                SourceRange AngleBrackets,
04296                                SourceRange Parens);
04297 
04298   ExprResult BuildCXXTypeId(QualType TypeInfoType,
04299                             SourceLocation TypeidLoc,
04300                             TypeSourceInfo *Operand,
04301                             SourceLocation RParenLoc);
04302   ExprResult BuildCXXTypeId(QualType TypeInfoType,
04303                             SourceLocation TypeidLoc,
04304                             Expr *Operand,
04305                             SourceLocation RParenLoc);
04306 
04307   /// ActOnCXXTypeid - Parse typeid( something ).
04308   ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
04309                             SourceLocation LParenLoc, bool isType,
04310                             void *TyOrExpr,
04311                             SourceLocation RParenLoc);
04312 
04313   ExprResult BuildCXXUuidof(QualType TypeInfoType,
04314                             SourceLocation TypeidLoc,
04315                             TypeSourceInfo *Operand,
04316                             SourceLocation RParenLoc);
04317   ExprResult BuildCXXUuidof(QualType TypeInfoType,
04318                             SourceLocation TypeidLoc,
04319                             Expr *Operand,
04320                             SourceLocation RParenLoc);
04321 
04322   /// ActOnCXXUuidof - Parse __uuidof( something ).
04323   ExprResult ActOnCXXUuidof(SourceLocation OpLoc,
04324                             SourceLocation LParenLoc, bool isType,
04325                             void *TyOrExpr,
04326                             SourceLocation RParenLoc);
04327 
04328   /// \brief Handle a C++1z fold-expression: ( expr op ... op expr ).
04329   ExprResult ActOnCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
04330                               tok::TokenKind Operator,
04331                               SourceLocation EllipsisLoc, Expr *RHS,
04332                               SourceLocation RParenLoc);
04333   ExprResult BuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
04334                               BinaryOperatorKind Operator,
04335                               SourceLocation EllipsisLoc, Expr *RHS,
04336                               SourceLocation RParenLoc);
04337   ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
04338                                    BinaryOperatorKind Operator);
04339 
04340   //// ActOnCXXThis -  Parse 'this' pointer.
04341   ExprResult ActOnCXXThis(SourceLocation loc);
04342 
04343   /// \brief Try to retrieve the type of the 'this' pointer.
04344   ///
04345   /// \returns The type of 'this', if possible. Otherwise, returns a NULL type.
04346   QualType getCurrentThisType();
04347 
04348   /// \brief When non-NULL, the C++ 'this' expression is allowed despite the
04349   /// current context not being a non-static member function. In such cases,
04350   /// this provides the type used for 'this'.
04351   QualType CXXThisTypeOverride;
04352 
04353   /// \brief RAII object used to temporarily allow the C++ 'this' expression
04354   /// to be used, with the given qualifiers on the current class type.
04355   class CXXThisScopeRAII {
04356     Sema &S;
04357     QualType OldCXXThisTypeOverride;
04358     bool Enabled;
04359 
04360   public:
04361     /// \brief Introduce a new scope where 'this' may be allowed (when enabled),
04362     /// using the given declaration (which is either a class template or a
04363     /// class) along with the given qualifiers.
04364     /// along with the qualifiers placed on '*this'.
04365     CXXThisScopeRAII(Sema &S, Decl *ContextDecl, unsigned CXXThisTypeQuals,
04366                      bool Enabled = true);
04367 
04368     ~CXXThisScopeRAII();
04369   };
04370 
04371   /// \brief Make sure the value of 'this' is actually available in the current
04372   /// context, if it is a potentially evaluated context.
04373   ///
04374   /// \param Loc The location at which the capture of 'this' occurs.
04375   ///
04376   /// \param Explicit Whether 'this' is explicitly captured in a lambda
04377   /// capture list.
04378   ///
04379   /// \param FunctionScopeIndexToStopAt If non-null, it points to the index
04380   /// of the FunctionScopeInfo stack beyond which we do not attempt to capture.
04381   /// This is useful when enclosing lambdas must speculatively capture 
04382   /// 'this' that may or may not be used in certain specializations of
04383   /// a nested generic lambda (depending on whether the name resolves to 
04384   /// a non-static member function or a static function).
04385   /// \return returns 'true' if failed, 'false' if success.
04386   bool CheckCXXThisCapture(SourceLocation Loc, bool Explicit = false, 
04387       bool BuildAndDiagnose = true,
04388       const unsigned *const FunctionScopeIndexToStopAt = nullptr);
04389 
04390   /// \brief Determine whether the given type is the type of *this that is used
04391   /// outside of the body of a member function for a type that is currently
04392   /// being defined.
04393   bool isThisOutsideMemberFunctionBody(QualType BaseType);
04394 
04395   /// ActOnCXXBoolLiteral - Parse {true,false} literals.
04396   ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
04397 
04398 
04399   /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals.
04400   ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
04401 
04402   /// ActOnCXXNullPtrLiteral - Parse 'nullptr'.
04403   ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc);
04404 
04405   //// ActOnCXXThrow -  Parse throw expressions.
04406   ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr);
04407   ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex,
04408                            bool IsThrownVarInScope);
04409   ExprResult CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *E,
04410                                   bool IsThrownVarInScope);
04411 
04412   /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
04413   /// Can be interpreted either as function-style casting ("int(x)")
04414   /// or class type construction ("ClassType(x,y,z)")
04415   /// or creation of a value-initialized type ("int()").
04416   ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep,
04417                                        SourceLocation LParenLoc,
04418                                        MultiExprArg Exprs,
04419                                        SourceLocation RParenLoc);
04420 
04421   ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type,
04422                                        SourceLocation LParenLoc,
04423                                        MultiExprArg Exprs,
04424                                        SourceLocation RParenLoc);
04425 
04426   /// ActOnCXXNew - Parsed a C++ 'new' expression.
04427   ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
04428                          SourceLocation PlacementLParen,
04429                          MultiExprArg PlacementArgs,
04430                          SourceLocation PlacementRParen,
04431                          SourceRange TypeIdParens, Declarator &D,
04432                          Expr *Initializer);
04433   ExprResult BuildCXXNew(SourceRange Range, bool UseGlobal,
04434                          SourceLocation PlacementLParen,
04435                          MultiExprArg PlacementArgs,
04436                          SourceLocation PlacementRParen,
04437                          SourceRange TypeIdParens,
04438                          QualType AllocType,
04439                          TypeSourceInfo *AllocTypeInfo,
04440                          Expr *ArraySize,
04441                          SourceRange DirectInitRange,
04442                          Expr *Initializer,
04443                          bool TypeMayContainAuto = true);
04444 
04445   bool CheckAllocatedType(QualType AllocType, SourceLocation Loc,
04446                           SourceRange R);
04447   bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
04448                                bool UseGlobal, QualType AllocType, bool IsArray,
04449                                MultiExprArg PlaceArgs,
04450                                FunctionDecl *&OperatorNew,
04451                                FunctionDecl *&OperatorDelete);
04452   bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
04453                               DeclarationName Name, MultiExprArg Args,
04454                               DeclContext *Ctx,
04455                               bool AllowMissing, FunctionDecl *&Operator,
04456                               bool Diagnose = true);
04457   void DeclareGlobalNewDelete();
04458   void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
04459                                        QualType Param1,
04460                                        QualType Param2 = QualType(),
04461                                        bool addMallocAttr = false);
04462 
04463   bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD,
04464                                 DeclarationName Name, FunctionDecl* &Operator,
04465                                 bool Diagnose = true);
04466   FunctionDecl *FindUsualDeallocationFunction(SourceLocation StartLoc,
04467                                               bool CanProvideSize,
04468                                               DeclarationName Name);
04469 
04470   /// ActOnCXXDelete - Parsed a C++ 'delete' expression
04471   ExprResult ActOnCXXDelete(SourceLocation StartLoc,
04472                             bool UseGlobal, bool ArrayForm,
04473                             Expr *Operand);
04474 
04475   DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D);
04476   ExprResult CheckConditionVariable(VarDecl *ConditionVar,
04477                                     SourceLocation StmtLoc,
04478                                     bool ConvertToBoolean);
04479 
04480   ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen,
04481                                Expr *Operand, SourceLocation RParen);
04482   ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand,
04483                                   SourceLocation RParen);
04484 
04485   /// \brief Parsed one of the type trait support pseudo-functions.
04486   ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc,
04487                             ArrayRef<ParsedType> Args,
04488                             SourceLocation RParenLoc);
04489   ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc,
04490                             ArrayRef<TypeSourceInfo *> Args,
04491                             SourceLocation RParenLoc);
04492 
04493   /// ActOnArrayTypeTrait - Parsed one of the bianry type trait support
04494   /// pseudo-functions.
04495   ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT,
04496                                  SourceLocation KWLoc,
04497                                  ParsedType LhsTy,
04498                                  Expr *DimExpr,
04499                                  SourceLocation RParen);
04500 
04501   ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT,
04502                                  SourceLocation KWLoc,
04503                                  TypeSourceInfo *TSInfo,
04504                                  Expr *DimExpr,
04505                                  SourceLocation RParen);
04506 
04507   /// ActOnExpressionTrait - Parsed one of the unary type trait support
04508   /// pseudo-functions.
04509   ExprResult ActOnExpressionTrait(ExpressionTrait OET,
04510                                   SourceLocation KWLoc,
04511                                   Expr *Queried,
04512                                   SourceLocation RParen);
04513 
04514   ExprResult BuildExpressionTrait(ExpressionTrait OET,
04515                                   SourceLocation KWLoc,
04516                                   Expr *Queried,
04517                                   SourceLocation RParen);
04518 
04519   ExprResult ActOnStartCXXMemberReference(Scope *S,
04520                                           Expr *Base,
04521                                           SourceLocation OpLoc,
04522                                           tok::TokenKind OpKind,
04523                                           ParsedType &ObjectType,
04524                                           bool &MayBePseudoDestructor);
04525 
04526   ExprResult DiagnoseDtorReference(SourceLocation NameLoc, Expr *MemExpr);
04527 
04528   ExprResult BuildPseudoDestructorExpr(Expr *Base,
04529                                        SourceLocation OpLoc,
04530                                        tok::TokenKind OpKind,
04531                                        const CXXScopeSpec &SS,
04532                                        TypeSourceInfo *ScopeType,
04533                                        SourceLocation CCLoc,
04534                                        SourceLocation TildeLoc,
04535                                      PseudoDestructorTypeStorage DestroyedType,
04536                                        bool HasTrailingLParen);
04537 
04538   ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
04539                                        SourceLocation OpLoc,
04540                                        tok::TokenKind OpKind,
04541                                        CXXScopeSpec &SS,
04542                                        UnqualifiedId &FirstTypeName,
04543                                        SourceLocation CCLoc,
04544                                        SourceLocation TildeLoc,
04545                                        UnqualifiedId &SecondTypeName,
04546                                        bool HasTrailingLParen);
04547 
04548   ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
04549                                        SourceLocation OpLoc,
04550                                        tok::TokenKind OpKind,
04551                                        SourceLocation TildeLoc,
04552                                        const DeclSpec& DS,
04553                                        bool HasTrailingLParen);
04554 
04555   /// MaybeCreateExprWithCleanups - If the current full-expression
04556   /// requires any cleanups, surround it with a ExprWithCleanups node.
04557   /// Otherwise, just returns the passed-in expression.
04558   Expr *MaybeCreateExprWithCleanups(Expr *SubExpr);
04559   Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt);
04560   ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr);
04561 
04562   ExprResult ActOnFinishFullExpr(Expr *Expr) {
04563     return ActOnFinishFullExpr(Expr, Expr ? Expr->getExprLoc()
04564                                           : SourceLocation());
04565   }
04566   ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC,
04567                                  bool DiscardedValue = false,
04568                                  bool IsConstexpr = false,
04569                                  bool IsLambdaInitCaptureInitializer = false);
04570   StmtResult ActOnFinishFullStmt(Stmt *Stmt);
04571 
04572   // Marks SS invalid if it represents an incomplete type.
04573   bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC);
04574 
04575   DeclContext *computeDeclContext(QualType T);
04576   DeclContext *computeDeclContext(const CXXScopeSpec &SS,
04577                                   bool EnteringContext = false);
04578   bool isDependentScopeSpecifier(const CXXScopeSpec &SS);
04579   CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS);
04580 
04581   /// \brief The parser has parsed a global nested-name-specifier '::'.
04582   ///
04583   /// \param CCLoc The location of the '::'.
04584   ///
04585   /// \param SS The nested-name-specifier, which will be updated in-place
04586   /// to reflect the parsed nested-name-specifier.
04587   ///
04588   /// \returns true if an error occurred, false otherwise.
04589   bool ActOnCXXGlobalScopeSpecifier(SourceLocation CCLoc, CXXScopeSpec &SS);
04590 
04591   /// \brief The parser has parsed a '__super' nested-name-specifier.
04592   ///
04593   /// \param SuperLoc The location of the '__super' keyword.
04594   ///
04595   /// \param ColonColonLoc The location of the '::'.
04596   ///
04597   /// \param SS The nested-name-specifier, which will be updated in-place
04598   /// to reflect the parsed nested-name-specifier.
04599   ///
04600   /// \returns true if an error occurred, false otherwise.
04601   bool ActOnSuperScopeSpecifier(SourceLocation SuperLoc,
04602                                 SourceLocation ColonColonLoc, CXXScopeSpec &SS);
04603 
04604   bool isAcceptableNestedNameSpecifier(const NamedDecl *SD);
04605   NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS);
04606 
04607   bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS,
04608                                     SourceLocation IdLoc,
04609                                     IdentifierInfo &II,
04610                                     ParsedType ObjectType);
04611 
04612   bool BuildCXXNestedNameSpecifier(Scope *S,
04613                                    IdentifierInfo &Identifier,
04614                                    SourceLocation IdentifierLoc,
04615                                    SourceLocation CCLoc,
04616                                    QualType ObjectType,
04617                                    bool EnteringContext,
04618                                    CXXScopeSpec &SS,
04619                                    NamedDecl *ScopeLookupResult,
04620                                    bool ErrorRecoveryLookup,
04621                                    bool *IsCorrectedToColon = nullptr);
04622 
04623   /// \brief The parser has parsed a nested-name-specifier 'identifier::'.
04624   ///
04625   /// \param S The scope in which this nested-name-specifier occurs.
04626   ///
04627   /// \param Identifier The identifier preceding the '::'.
04628   ///
04629   /// \param IdentifierLoc The location of the identifier.
04630   ///
04631   /// \param CCLoc The location of the '::'.
04632   ///
04633   /// \param ObjectType The type of the object, if we're parsing
04634   /// nested-name-specifier in a member access expression.
04635   ///
04636   /// \param EnteringContext Whether we're entering the context nominated by
04637   /// this nested-name-specifier.
04638   ///
04639   /// \param SS The nested-name-specifier, which is both an input
04640   /// parameter (the nested-name-specifier before this type) and an
04641   /// output parameter (containing the full nested-name-specifier,
04642   /// including this new type).
04643   ///
04644   /// \param ErrorRecoveryLookup If true, then this method is called to improve
04645   /// error recovery. In this case do not emit error message.
04646   ///
04647   /// \param IsCorrectedToColon If not null, suggestions to replace '::' -> ':'
04648   /// are allowed.  The bool value pointed by this parameter is set to 'true'
04649   /// if the identifier is treated as if it was followed by ':', not '::'.
04650   ///
04651   /// \returns true if an error occurred, false otherwise.
04652   bool ActOnCXXNestedNameSpecifier(Scope *S,
04653                                    IdentifierInfo &Identifier,
04654                                    SourceLocation IdentifierLoc,
04655                                    SourceLocation CCLoc,
04656                                    ParsedType ObjectType,
04657                                    bool EnteringContext,
04658                                    CXXScopeSpec &SS,
04659                                    bool ErrorRecoveryLookup = false,
04660                                    bool *IsCorrectedToColon = nullptr);
04661 
04662   ExprResult ActOnDecltypeExpression(Expr *E);
04663 
04664   bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS,
04665                                            const DeclSpec &DS,
04666                                            SourceLocation ColonColonLoc);
04667 
04668   bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS,
04669                                  IdentifierInfo &Identifier,
04670                                  SourceLocation IdentifierLoc,
04671                                  SourceLocation ColonLoc,
04672                                  ParsedType ObjectType,
04673                                  bool EnteringContext);
04674 
04675   /// \brief The parser has parsed a nested-name-specifier
04676   /// 'template[opt] template-name < template-args >::'.
04677   ///
04678   /// \param S The scope in which this nested-name-specifier occurs.
04679   ///
04680   /// \param SS The nested-name-specifier, which is both an input
04681   /// parameter (the nested-name-specifier before this type) and an
04682   /// output parameter (containing the full nested-name-specifier,
04683   /// including this new type).
04684   ///
04685   /// \param TemplateKWLoc the location of the 'template' keyword, if any.
04686   /// \param TemplateName the template name.
04687   /// \param TemplateNameLoc The location of the template name.
04688   /// \param LAngleLoc The location of the opening angle bracket  ('<').
04689   /// \param TemplateArgs The template arguments.
04690   /// \param RAngleLoc The location of the closing angle bracket  ('>').
04691   /// \param CCLoc The location of the '::'.
04692   ///
04693   /// \param EnteringContext Whether we're entering the context of the
04694   /// nested-name-specifier.
04695   ///
04696   ///
04697   /// \returns true if an error occurred, false otherwise.
04698   bool ActOnCXXNestedNameSpecifier(Scope *S,
04699                                    CXXScopeSpec &SS,
04700                                    SourceLocation TemplateKWLoc,
04701                                    TemplateTy TemplateName,
04702                                    SourceLocation TemplateNameLoc,
04703                                    SourceLocation LAngleLoc,
04704                                    ASTTemplateArgsPtr TemplateArgs,
04705                                    SourceLocation RAngleLoc,
04706                                    SourceLocation CCLoc,
04707                                    bool EnteringContext);
04708 
04709   /// \brief Given a C++ nested-name-specifier, produce an annotation value
04710   /// that the parser can use later to reconstruct the given
04711   /// nested-name-specifier.
04712   ///
04713   /// \param SS A nested-name-specifier.
04714   ///
04715   /// \returns A pointer containing all of the information in the
04716   /// nested-name-specifier \p SS.
04717   void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS);
04718 
04719   /// \brief Given an annotation pointer for a nested-name-specifier, restore
04720   /// the nested-name-specifier structure.
04721   ///
04722   /// \param Annotation The annotation pointer, produced by
04723   /// \c SaveNestedNameSpecifierAnnotation().
04724   ///
04725   /// \param AnnotationRange The source range corresponding to the annotation.
04726   ///
04727   /// \param SS The nested-name-specifier that will be updated with the contents
04728   /// of the annotation pointer.
04729   void RestoreNestedNameSpecifierAnnotation(void *Annotation,
04730                                             SourceRange AnnotationRange,
04731                                             CXXScopeSpec &SS);
04732 
04733   bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
04734 
04735   /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
04736   /// scope or nested-name-specifier) is parsed, part of a declarator-id.
04737   /// After this method is called, according to [C++ 3.4.3p3], names should be
04738   /// looked up in the declarator-id's scope, until the declarator is parsed and
04739   /// ActOnCXXExitDeclaratorScope is called.
04740   /// The 'SS' should be a non-empty valid CXXScopeSpec.
04741   bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS);
04742 
04743   /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
04744   /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
04745   /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
04746   /// Used to indicate that names should revert to being looked up in the
04747   /// defining scope.
04748   void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
04749 
04750   /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an
04751   /// initializer for the declaration 'Dcl'.
04752   /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a
04753   /// static data member of class X, names should be looked up in the scope of
04754   /// class X.
04755   void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl);
04756 
04757   /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an
04758   /// initializer for the declaration 'Dcl'.
04759   void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl);
04760 
04761   /// \brief Create a new lambda closure type.
04762   CXXRecordDecl *createLambdaClosureType(SourceRange IntroducerRange,
04763                                          TypeSourceInfo *Info,
04764                                          bool KnownDependent, 
04765                                          LambdaCaptureDefault CaptureDefault);
04766 
04767   /// \brief Start the definition of a lambda expression.
04768   CXXMethodDecl *startLambdaDefinition(CXXRecordDecl *Class,
04769                                        SourceRange IntroducerRange,
04770                                        TypeSourceInfo *MethodType,
04771                                        SourceLocation EndLoc,
04772                                        ArrayRef<ParmVarDecl *> Params);
04773 
04774   /// \brief Endow the lambda scope info with the relevant properties.
04775   void buildLambdaScope(sema::LambdaScopeInfo *LSI, 
04776                         CXXMethodDecl *CallOperator,
04777                         SourceRange IntroducerRange,
04778                         LambdaCaptureDefault CaptureDefault,
04779                         SourceLocation CaptureDefaultLoc,
04780                         bool ExplicitParams,
04781                         bool ExplicitResultType,
04782                         bool Mutable);
04783 
04784   /// \brief Perform initialization analysis of the init-capture and perform
04785   /// any implicit conversions such as an lvalue-to-rvalue conversion if
04786   /// not being used to initialize a reference.
04787   QualType performLambdaInitCaptureInitialization(SourceLocation Loc, 
04788       bool ByRef, IdentifierInfo *Id, Expr *&Init);
04789   /// \brief Create a dummy variable within the declcontext of the lambda's
04790   ///  call operator, for name lookup purposes for a lambda init capture.
04791   ///  
04792   ///  CodeGen handles emission of lambda captures, ignoring these dummy
04793   ///  variables appropriately.
04794   VarDecl *createLambdaInitCaptureVarDecl(SourceLocation Loc, 
04795     QualType InitCaptureType, IdentifierInfo *Id, Expr *Init);
04796 
04797   /// \brief Build the implicit field for an init-capture.
04798   FieldDecl *buildInitCaptureField(sema::LambdaScopeInfo *LSI, VarDecl *Var);
04799 
04800   /// \brief Note that we have finished the explicit captures for the
04801   /// given lambda.
04802   void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI);
04803 
04804   /// \brief Introduce the lambda parameters into scope.
04805   void addLambdaParameters(CXXMethodDecl *CallOperator, Scope *CurScope);
04806 
04807   /// \brief Deduce a block or lambda's return type based on the return
04808   /// statements present in the body.
04809   void deduceClosureReturnType(sema::CapturingScopeInfo &CSI);
04810 
04811   /// ActOnStartOfLambdaDefinition - This is called just before we start
04812   /// parsing the body of a lambda; it analyzes the explicit captures and
04813   /// arguments, and sets up various data-structures for the body of the
04814   /// lambda.
04815   void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
04816                                     Declarator &ParamInfo, Scope *CurScope);
04817 
04818   /// ActOnLambdaError - If there is an error parsing a lambda, this callback
04819   /// is invoked to pop the information about the lambda.
04820   void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope,
04821                         bool IsInstantiation = false);
04822 
04823   /// ActOnLambdaExpr - This is called when the body of a lambda expression
04824   /// was successfully completed.
04825   ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body,
04826                              Scope *CurScope,
04827                              bool IsInstantiation = false);
04828 
04829   /// \brief Define the "body" of the conversion from a lambda object to a
04830   /// function pointer.
04831   ///
04832   /// This routine doesn't actually define a sensible body; rather, it fills
04833   /// in the initialization expression needed to copy the lambda object into
04834   /// the block, and IR generation actually generates the real body of the
04835   /// block pointer conversion.
04836   void DefineImplicitLambdaToFunctionPointerConversion(
04837          SourceLocation CurrentLoc, CXXConversionDecl *Conv);
04838 
04839   /// \brief Define the "body" of the conversion from a lambda object to a
04840   /// block pointer.
04841   ///
04842   /// This routine doesn't actually define a sensible body; rather, it fills
04843   /// in the initialization expression needed to copy the lambda object into
04844   /// the block, and IR generation actually generates the real body of the
04845   /// block pointer conversion.
04846   void DefineImplicitLambdaToBlockPointerConversion(SourceLocation CurrentLoc,
04847                                                     CXXConversionDecl *Conv);
04848 
04849   ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation,
04850                                            SourceLocation ConvLocation,
04851                                            CXXConversionDecl *Conv,
04852                                            Expr *Src);
04853 
04854   // ParseObjCStringLiteral - Parse Objective-C string literals.
04855   ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
04856                                     Expr **Strings,
04857                                     unsigned NumStrings);
04858 
04859   ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S);
04860 
04861   /// BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the
04862   /// numeric literal expression. Type of the expression will be "NSNumber *"
04863   /// or "id" if NSNumber is unavailable.
04864   ExprResult BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number);
04865   ExprResult ActOnObjCBoolLiteral(SourceLocation AtLoc, SourceLocation ValueLoc,
04866                                   bool Value);
04867   ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements);
04868 
04869   /// BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the
04870   /// '@' prefixed parenthesized expression. The type of the expression will
04871   /// either be "NSNumber *" or "NSString *" depending on the type of
04872   /// ValueType, which is allowed to be a built-in numeric type or
04873   /// "char *" or "const char *".
04874   ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr);
04875 
04876   ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr,
04877                                           Expr *IndexExpr,
04878                                           ObjCMethodDecl *getterMethod,
04879                                           ObjCMethodDecl *setterMethod);
04880 
04881   ExprResult BuildObjCDictionaryLiteral(SourceRange SR,
04882                                         ObjCDictionaryElement *Elements,
04883                                         unsigned NumElements);
04884 
04885   ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc,
04886                                   TypeSourceInfo *EncodedTypeInfo,
04887                                   SourceLocation RParenLoc);
04888   ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl,
04889                                     CXXConversionDecl *Method,
04890                                     bool HadMultipleCandidates);
04891 
04892   ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
04893                                        SourceLocation EncodeLoc,
04894                                        SourceLocation LParenLoc,
04895                                        ParsedType Ty,
04896                                        SourceLocation RParenLoc);
04897 
04898   /// ParseObjCSelectorExpression - Build selector expression for \@selector
04899   ExprResult ParseObjCSelectorExpression(Selector Sel,
04900                                          SourceLocation AtLoc,
04901                                          SourceLocation SelLoc,
04902                                          SourceLocation LParenLoc,
04903                                          SourceLocation RParenLoc,
04904                                          bool WarnMultipleSelectors);
04905 
04906   /// ParseObjCProtocolExpression - Build protocol expression for \@protocol
04907   ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
04908                                          SourceLocation AtLoc,
04909                                          SourceLocation ProtoLoc,
04910                                          SourceLocation LParenLoc,
04911                                          SourceLocation ProtoIdLoc,
04912                                          SourceLocation RParenLoc);
04913 
04914   //===--------------------------------------------------------------------===//
04915   // C++ Declarations
04916   //
04917   Decl *ActOnStartLinkageSpecification(Scope *S,
04918                                        SourceLocation ExternLoc,
04919                                        Expr *LangStr,
04920                                        SourceLocation LBraceLoc);
04921   Decl *ActOnFinishLinkageSpecification(Scope *S,
04922                                         Decl *LinkageSpec,
04923                                         SourceLocation RBraceLoc);
04924 
04925 
04926   //===--------------------------------------------------------------------===//
04927   // C++ Classes
04928   //
04929   bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
04930                           const CXXScopeSpec *SS = nullptr);
04931   bool isCurrentClassNameTypo(IdentifierInfo *&II, const CXXScopeSpec *SS);
04932 
04933   bool ActOnAccessSpecifier(AccessSpecifier Access,
04934                             SourceLocation ASLoc,
04935                             SourceLocation ColonLoc,
04936                             AttributeList *Attrs = nullptr);
04937 
04938   NamedDecl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
04939                                  Declarator &D,
04940                                  MultiTemplateParamsArg TemplateParameterLists,
04941                                  Expr *BitfieldWidth, const VirtSpecifiers &VS,
04942                                  InClassInitStyle InitStyle);
04943 
04944   void ActOnStartCXXInClassMemberInitializer();
04945   void ActOnFinishCXXInClassMemberInitializer(Decl *VarDecl,
04946                                               SourceLocation EqualLoc,
04947                                               Expr *Init);
04948 
04949   MemInitResult ActOnMemInitializer(Decl *ConstructorD,
04950                                     Scope *S,
04951                                     CXXScopeSpec &SS,
04952                                     IdentifierInfo *MemberOrBase,
04953                                     ParsedType TemplateTypeTy,
04954                                     const DeclSpec &DS,
04955                                     SourceLocation IdLoc,
04956                                     SourceLocation LParenLoc,
04957                                     ArrayRef<Expr *> Args,
04958                                     SourceLocation RParenLoc,
04959                                     SourceLocation EllipsisLoc);
04960 
04961   MemInitResult ActOnMemInitializer(Decl *ConstructorD,
04962                                     Scope *S,
04963                                     CXXScopeSpec &SS,
04964                                     IdentifierInfo *MemberOrBase,
04965                                     ParsedType TemplateTypeTy,
04966                                     const DeclSpec &DS,
04967                                     SourceLocation IdLoc,
04968                                     Expr *InitList,
04969                                     SourceLocation EllipsisLoc);
04970 
04971   MemInitResult BuildMemInitializer(Decl *ConstructorD,
04972                                     Scope *S,
04973                                     CXXScopeSpec &SS,
04974                                     IdentifierInfo *MemberOrBase,
04975                                     ParsedType TemplateTypeTy,
04976                                     const DeclSpec &DS,
04977                                     SourceLocation IdLoc,
04978                                     Expr *Init,
04979                                     SourceLocation EllipsisLoc);
04980 
04981   MemInitResult BuildMemberInitializer(ValueDecl *Member,
04982                                        Expr *Init,
04983                                        SourceLocation IdLoc);
04984 
04985   MemInitResult BuildBaseInitializer(QualType BaseType,
04986                                      TypeSourceInfo *BaseTInfo,
04987                                      Expr *Init,
04988                                      CXXRecordDecl *ClassDecl,
04989                                      SourceLocation EllipsisLoc);
04990 
04991   MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo,
04992                                            Expr *Init,
04993                                            CXXRecordDecl *ClassDecl);
04994 
04995   bool SetDelegatingInitializer(CXXConstructorDecl *Constructor,
04996                                 CXXCtorInitializer *Initializer);
04997 
04998   bool SetCtorInitializers(CXXConstructorDecl *Constructor, bool AnyErrors,
04999                            ArrayRef<CXXCtorInitializer *> Initializers = None);
05000 
05001   void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation);
05002 
05003 
05004   /// MarkBaseAndMemberDestructorsReferenced - Given a record decl,
05005   /// mark all the non-trivial destructors of its members and bases as
05006   /// referenced.
05007   void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
05008                                               CXXRecordDecl *Record);
05009 
05010   /// \brief The list of classes whose vtables have been used within
05011   /// this translation unit, and the source locations at which the
05012   /// first use occurred.
05013   typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse;
05014 
05015   /// \brief The list of vtables that are required but have not yet been
05016   /// materialized.
05017   SmallVector<VTableUse, 16> VTableUses;
05018 
05019   /// \brief The set of classes whose vtables have been used within
05020   /// this translation unit, and a bit that will be true if the vtable is
05021   /// required to be emitted (otherwise, it should be emitted only if needed
05022   /// by code generation).
05023   llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed;
05024 
05025   /// \brief Load any externally-stored vtable uses.
05026   void LoadExternalVTableUses();
05027 
05028   typedef LazyVector<CXXRecordDecl *, ExternalSemaSource,
05029                      &ExternalSemaSource::ReadDynamicClasses, 2, 2>
05030     DynamicClassesType;
05031 
05032   /// \brief A list of all of the dynamic classes in this translation
05033   /// unit.
05034   DynamicClassesType DynamicClasses;
05035 
05036   /// \brief Note that the vtable for the given class was used at the
05037   /// given location.
05038   void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class,
05039                       bool DefinitionRequired = false);
05040 
05041   /// \brief Mark the exception specifications of all virtual member functions
05042   /// in the given class as needed.
05043   void MarkVirtualMemberExceptionSpecsNeeded(SourceLocation Loc,
05044                                              const CXXRecordDecl *RD);
05045 
05046   /// MarkVirtualMembersReferenced - Will mark all members of the given
05047   /// CXXRecordDecl referenced.
05048   void MarkVirtualMembersReferenced(SourceLocation Loc,
05049                                     const CXXRecordDecl *RD);
05050 
05051   /// \brief Define all of the vtables that have been used in this
05052   /// translation unit and reference any virtual members used by those
05053   /// vtables.
05054   ///
05055   /// \returns true if any work was done, false otherwise.
05056   bool DefineUsedVTables();
05057 
05058   void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
05059 
05060   void ActOnMemInitializers(Decl *ConstructorDecl,
05061                             SourceLocation ColonLoc,
05062                             ArrayRef<CXXCtorInitializer*> MemInits,
05063                             bool AnyErrors);
05064 
05065   void CheckCompletedCXXClass(CXXRecordDecl *Record);
05066   void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
05067                                          Decl *TagDecl,
05068                                          SourceLocation LBrac,
05069                                          SourceLocation RBrac,
05070                                          AttributeList *AttrList);
05071   void ActOnFinishCXXMemberDecls();
05072 
05073   void ActOnReenterCXXMethodParameter(Scope *S, ParmVarDecl *Param);
05074   unsigned ActOnReenterTemplateScope(Scope *S, Decl *Template);
05075   void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record);
05076   void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
05077   void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param);
05078   void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record);
05079   void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
05080   void ActOnFinishDelayedMemberInitializers(Decl *Record);
05081   void MarkAsLateParsedTemplate(FunctionDecl *FD, Decl *FnD,
05082                                 CachedTokens &Toks);
05083   void UnmarkAsLateParsedTemplate(FunctionDecl *FD);
05084   bool IsInsideALocalClassWithinATemplateFunction();
05085 
05086   Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc,
05087                                      Expr *AssertExpr,
05088                                      Expr *AssertMessageExpr,
05089                                      SourceLocation RParenLoc);
05090   Decl *BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc,
05091                                      Expr *AssertExpr,
05092                                      StringLiteral *AssertMessageExpr,
05093                                      SourceLocation RParenLoc,
05094                                      bool Failed);
05095 
05096   FriendDecl *CheckFriendTypeDecl(SourceLocation LocStart,
05097                                   SourceLocation FriendLoc,
05098                                   TypeSourceInfo *TSInfo);
05099   Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS,
05100                             MultiTemplateParamsArg TemplateParams);
05101   NamedDecl *ActOnFriendFunctionDecl(Scope *S, Declarator &D,
05102                                      MultiTemplateParamsArg TemplateParams);
05103 
05104   QualType CheckConstructorDeclarator(Declarator &D, QualType R,
05105                                       StorageClass& SC);
05106   void CheckConstructor(CXXConstructorDecl *Constructor);
05107   QualType CheckDestructorDeclarator(Declarator &D, QualType R,
05108                                      StorageClass& SC);
05109   bool CheckDestructor(CXXDestructorDecl *Destructor);
05110   void CheckConversionDeclarator(Declarator &D, QualType &R,
05111                                  StorageClass& SC);
05112   Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
05113 
05114   void CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD);
05115   void CheckExplicitlyDefaultedMemberExceptionSpec(CXXMethodDecl *MD,
05116                                                    const FunctionProtoType *T);
05117   void CheckDelayedMemberExceptionSpecs();
05118 
05119   //===--------------------------------------------------------------------===//
05120   // C++ Derived Classes
05121   //
05122 
05123   /// ActOnBaseSpecifier - Parsed a base specifier
05124   CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
05125                                        SourceRange SpecifierRange,
05126                                        bool Virtual, AccessSpecifier Access,
05127                                        TypeSourceInfo *TInfo,
05128                                        SourceLocation EllipsisLoc);
05129 
05130   BaseResult ActOnBaseSpecifier(Decl *classdecl,
05131                                 SourceRange SpecifierRange,
05132                                 ParsedAttributes &Attrs,
05133                                 bool Virtual, AccessSpecifier Access,
05134                                 ParsedType basetype,
05135                                 SourceLocation BaseLoc,
05136                                 SourceLocation EllipsisLoc);
05137 
05138   bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
05139                             unsigned NumBases);
05140   void ActOnBaseSpecifiers(Decl *ClassDecl, CXXBaseSpecifier **Bases,
05141                            unsigned NumBases);
05142 
05143   bool IsDerivedFrom(QualType Derived, QualType Base);
05144   bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths);
05145 
05146   // FIXME: I don't like this name.
05147   void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath);
05148 
05149   bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath);
05150 
05151   bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
05152                                     SourceLocation Loc, SourceRange Range,
05153                                     CXXCastPath *BasePath = nullptr,
05154                                     bool IgnoreAccess = false);
05155   bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
05156                                     unsigned InaccessibleBaseID,
05157                                     unsigned AmbigiousBaseConvID,
05158                                     SourceLocation Loc, SourceRange Range,
05159                                     DeclarationName Name,
05160                                     CXXCastPath *BasePath);
05161 
05162   std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths);
05163 
05164   bool CheckOverridingFunctionAttributes(const CXXMethodDecl *New,
05165                                          const CXXMethodDecl *Old);
05166 
05167   /// CheckOverridingFunctionReturnType - Checks whether the return types are
05168   /// covariant, according to C++ [class.virtual]p5.
05169   bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New,
05170                                          const CXXMethodDecl *Old);
05171 
05172   /// CheckOverridingFunctionExceptionSpec - Checks whether the exception
05173   /// spec is a subset of base spec.
05174   bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New,
05175                                             const CXXMethodDecl *Old);
05176 
05177   bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange);
05178 
05179   /// CheckOverrideControl - Check C++11 override control semantics.
05180   void CheckOverrideControl(NamedDecl *D);
05181     
05182   /// DiagnoseAbsenceOfOverrideControl - Diagnose if 'override' keyword was
05183   /// not used in the declaration of an overriding method.
05184   void DiagnoseAbsenceOfOverrideControl(NamedDecl *D);
05185 
05186   /// CheckForFunctionMarkedFinal - Checks whether a virtual member function
05187   /// overrides a virtual member function marked 'final', according to
05188   /// C++11 [class.virtual]p4.
05189   bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New,
05190                                               const CXXMethodDecl *Old);
05191 
05192 
05193   //===--------------------------------------------------------------------===//
05194   // C++ Access Control
05195   //
05196 
05197   enum AccessResult {
05198     AR_accessible,
05199     AR_inaccessible,
05200     AR_dependent,
05201     AR_delayed
05202   };
05203 
05204   bool SetMemberAccessSpecifier(NamedDecl *MemberDecl,
05205                                 NamedDecl *PrevMemberDecl,
05206                                 AccessSpecifier LexicalAS);
05207 
05208   AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E,
05209                                            DeclAccessPair FoundDecl);
05210   AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E,
05211                                            DeclAccessPair FoundDecl);
05212   AccessResult CheckAllocationAccess(SourceLocation OperatorLoc,
05213                                      SourceRange PlacementRange,
05214                                      CXXRecordDecl *NamingClass,
05215                                      DeclAccessPair FoundDecl,
05216                                      bool Diagnose = true);
05217   AccessResult CheckConstructorAccess(SourceLocation Loc,
05218                                       CXXConstructorDecl *D,
05219                                       const InitializedEntity &Entity,
05220                                       AccessSpecifier Access,
05221                                       bool IsCopyBindingRefToTemp = false);
05222   AccessResult CheckConstructorAccess(SourceLocation Loc,
05223                                       CXXConstructorDecl *D,
05224                                       const InitializedEntity &Entity,
05225                                       AccessSpecifier Access,
05226                                       const PartialDiagnostic &PDiag);
05227   AccessResult CheckDestructorAccess(SourceLocation Loc,
05228                                      CXXDestructorDecl *Dtor,
05229                                      const PartialDiagnostic &PDiag,
05230                                      QualType objectType = QualType());
05231   AccessResult CheckFriendAccess(NamedDecl *D);
05232   AccessResult CheckMemberAccess(SourceLocation UseLoc,
05233                                  CXXRecordDecl *NamingClass,
05234                                  DeclAccessPair Found);
05235   AccessResult CheckMemberOperatorAccess(SourceLocation Loc,
05236                                          Expr *ObjectExpr,
05237                                          Expr *ArgExpr,
05238                                          DeclAccessPair FoundDecl);
05239   AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr,
05240                                           DeclAccessPair FoundDecl);
05241   AccessResult CheckBaseClassAccess(SourceLocation AccessLoc,
05242                                     QualType Base, QualType Derived,
05243                                     const CXXBasePath &Path,
05244                                     unsigned DiagID,
05245                                     bool ForceCheck = false,
05246                                     bool ForceUnprivileged = false);
05247   void CheckLookupAccess(const LookupResult &R);
05248   bool IsSimplyAccessible(NamedDecl *decl, DeclContext *Ctx);
05249   bool isSpecialMemberAccessibleForDeletion(CXXMethodDecl *decl,
05250                                             AccessSpecifier access,
05251                                             QualType objectType);
05252 
05253   void HandleDependentAccessCheck(const DependentDiagnostic &DD,
05254                          const MultiLevelTemplateArgumentList &TemplateArgs);
05255   void PerformDependentDiagnostics(const DeclContext *Pattern,
05256                         const MultiLevelTemplateArgumentList &TemplateArgs);
05257 
05258   void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
05259 
05260   /// \brief When true, access checking violations are treated as SFINAE
05261   /// failures rather than hard errors.
05262   bool AccessCheckingSFINAE;
05263 
05264   enum AbstractDiagSelID {
05265     AbstractNone = -1,
05266     AbstractReturnType,
05267     AbstractParamType,
05268     AbstractVariableType,
05269     AbstractFieldType,
05270     AbstractIvarType,
05271     AbstractSynthesizedIvarType,
05272     AbstractArrayType
05273   };
05274 
05275   bool RequireNonAbstractType(SourceLocation Loc, QualType T,
05276                               TypeDiagnoser &Diagnoser);
05277   template<typename T1>
05278   bool RequireNonAbstractType(SourceLocation Loc, QualType T,
05279                               unsigned DiagID,
05280                               const T1 &Arg1) {
05281     BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
05282     return RequireNonAbstractType(Loc, T, Diagnoser);
05283   }
05284 
05285   template<typename T1, typename T2>
05286   bool RequireNonAbstractType(SourceLocation Loc, QualType T,
05287                               unsigned DiagID,
05288                               const T1 &Arg1, const T2 &Arg2) {
05289     BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
05290     return RequireNonAbstractType(Loc, T, Diagnoser);
05291   }
05292 
05293   template<typename T1, typename T2, typename T3>
05294   bool RequireNonAbstractType(SourceLocation Loc, QualType T,
05295                               unsigned DiagID,
05296                               const T1 &Arg1, const T2 &Arg2, const T3 &Arg3) {
05297     BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2, Arg3);
05298     return RequireNonAbstractType(Loc, T, Diagnoser);
05299   }
05300 
05301   void DiagnoseAbstractType(const CXXRecordDecl *RD);
05302 
05303   bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID,
05304                               AbstractDiagSelID SelID = AbstractNone);
05305 
05306   //===--------------------------------------------------------------------===//
05307   // C++ Overloaded Operators [C++ 13.5]
05308   //
05309 
05310   bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
05311 
05312   bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl);
05313 
05314   //===--------------------------------------------------------------------===//
05315   // C++ Templates [C++ 14]
05316   //
05317   void FilterAcceptableTemplateNames(LookupResult &R,
05318                                      bool AllowFunctionTemplates = true);
05319   bool hasAnyAcceptableTemplateNames(LookupResult &R,
05320                                      bool AllowFunctionTemplates = true);
05321 
05322   void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS,
05323                           QualType ObjectType, bool EnteringContext,
05324                           bool &MemberOfUnknownSpecialization);
05325 
05326   TemplateNameKind isTemplateName(Scope *S,
05327                                   CXXScopeSpec &SS,
05328                                   bool hasTemplateKeyword,
05329                                   UnqualifiedId &Name,
05330                                   ParsedType ObjectType,
05331                                   bool EnteringContext,
05332                                   TemplateTy &Template,
05333                                   bool &MemberOfUnknownSpecialization);
05334 
05335   bool DiagnoseUnknownTemplateName(const IdentifierInfo &II,
05336                                    SourceLocation IILoc,
05337                                    Scope *S,
05338                                    const CXXScopeSpec *SS,
05339                                    TemplateTy &SuggestedTemplate,
05340                                    TemplateNameKind &SuggestedKind);
05341 
05342   void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
05343   TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl);
05344 
05345   Decl *ActOnTypeParameter(Scope *S, bool Typename,
05346                            SourceLocation EllipsisLoc,
05347                            SourceLocation KeyLoc,
05348                            IdentifierInfo *ParamName,
05349                            SourceLocation ParamNameLoc,
05350                            unsigned Depth, unsigned Position,
05351                            SourceLocation EqualLoc,
05352                            ParsedType DefaultArg);
05353 
05354   QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
05355   Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
05356                                       unsigned Depth,
05357                                       unsigned Position,
05358                                       SourceLocation EqualLoc,
05359                                       Expr *DefaultArg);
05360   Decl *ActOnTemplateTemplateParameter(Scope *S,
05361                                        SourceLocation TmpLoc,
05362                                        TemplateParameterList *Params,
05363                                        SourceLocation EllipsisLoc,
05364                                        IdentifierInfo *ParamName,
05365                                        SourceLocation ParamNameLoc,
05366                                        unsigned Depth,
05367                                        unsigned Position,
05368                                        SourceLocation EqualLoc,
05369                                        ParsedTemplateArgument DefaultArg);
05370 
05371   TemplateParameterList *
05372   ActOnTemplateParameterList(unsigned Depth,
05373                              SourceLocation ExportLoc,
05374                              SourceLocation TemplateLoc,
05375                              SourceLocation LAngleLoc,
05376                              Decl **Params, unsigned NumParams,
05377                              SourceLocation RAngleLoc);
05378 
05379   /// \brief The context in which we are checking a template parameter list.
05380   enum TemplateParamListContext {
05381     TPC_ClassTemplate,
05382     TPC_VarTemplate,
05383     TPC_FunctionTemplate,
05384     TPC_ClassTemplateMember,
05385     TPC_FriendClassTemplate,
05386     TPC_FriendFunctionTemplate,
05387     TPC_FriendFunctionTemplateDefinition,
05388     TPC_TypeAliasTemplate
05389   };
05390 
05391   bool CheckTemplateParameterList(TemplateParameterList *NewParams,
05392                                   TemplateParameterList *OldParams,
05393                                   TemplateParamListContext TPC);
05394   TemplateParameterList *MatchTemplateParametersToScopeSpecifier(
05395       SourceLocation DeclStartLoc, SourceLocation DeclLoc,
05396       const CXXScopeSpec &SS, TemplateIdAnnotation *TemplateId,
05397       ArrayRef<TemplateParameterList *> ParamLists,
05398       bool IsFriend, bool &IsExplicitSpecialization, bool &Invalid);
05399 
05400   DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
05401                                 SourceLocation KWLoc, CXXScopeSpec &SS,
05402                                 IdentifierInfo *Name, SourceLocation NameLoc,
05403                                 AttributeList *Attr,
05404                                 TemplateParameterList *TemplateParams,
05405                                 AccessSpecifier AS,
05406                                 SourceLocation ModulePrivateLoc,
05407                                 SourceLocation FriendLoc,
05408                                 unsigned NumOuterTemplateParamLists,
05409                             TemplateParameterList **OuterTemplateParamLists);
05410 
05411   void translateTemplateArguments(const ASTTemplateArgsPtr &In,
05412                                   TemplateArgumentListInfo &Out);
05413 
05414   void NoteAllFoundTemplates(TemplateName Name);
05415 
05416   QualType CheckTemplateIdType(TemplateName Template,
05417                                SourceLocation TemplateLoc,
05418                               TemplateArgumentListInfo &TemplateArgs);
05419 
05420   TypeResult
05421   ActOnTemplateIdType(CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
05422                       TemplateTy Template, SourceLocation TemplateLoc,
05423                       SourceLocation LAngleLoc,
05424                       ASTTemplateArgsPtr TemplateArgs,
05425                       SourceLocation RAngleLoc,
05426                       bool IsCtorOrDtorName = false);
05427 
05428   /// \brief Parsed an elaborated-type-specifier that refers to a template-id,
05429   /// such as \c class T::template apply<U>.
05430   TypeResult ActOnTagTemplateIdType(TagUseKind TUK,
05431                                     TypeSpecifierType TagSpec,
05432                                     SourceLocation TagLoc,
05433                                     CXXScopeSpec &SS,
05434                                     SourceLocation TemplateKWLoc,
05435                                     TemplateTy TemplateD,
05436                                     SourceLocation TemplateLoc,
05437                                     SourceLocation LAngleLoc,
05438                                     ASTTemplateArgsPtr TemplateArgsIn,
05439                                     SourceLocation RAngleLoc);
05440 
05441   DeclResult ActOnVarTemplateSpecialization(
05442       Scope *S, Declarator &D, TypeSourceInfo *DI,
05443       SourceLocation TemplateKWLoc, TemplateParameterList *TemplateParams,
05444       StorageClass SC, bool IsPartialSpecialization);
05445 
05446   DeclResult CheckVarTemplateId(VarTemplateDecl *Template,
05447                                 SourceLocation TemplateLoc,
05448                                 SourceLocation TemplateNameLoc,
05449                                 const TemplateArgumentListInfo &TemplateArgs);
05450 
05451   ExprResult CheckVarTemplateId(const CXXScopeSpec &SS,
05452                                 const DeclarationNameInfo &NameInfo,
05453                                 VarTemplateDecl *Template,
05454                                 SourceLocation TemplateLoc,
05455                                 const TemplateArgumentListInfo *TemplateArgs);
05456 
05457   ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS,
05458                                  SourceLocation TemplateKWLoc,
05459                                  LookupResult &R,
05460                                  bool RequiresADL,
05461                                const TemplateArgumentListInfo *TemplateArgs);
05462 
05463   ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS,
05464                                           SourceLocation TemplateKWLoc,
05465                                const DeclarationNameInfo &NameInfo,
05466                                const TemplateArgumentListInfo *TemplateArgs);
05467 
05468   TemplateNameKind ActOnDependentTemplateName(Scope *S,
05469                                               CXXScopeSpec &SS,
05470                                               SourceLocation TemplateKWLoc,
05471                                               UnqualifiedId &Name,
05472                                               ParsedType ObjectType,
05473                                               bool EnteringContext,
05474                                               TemplateTy &Template);
05475 
05476   DeclResult
05477   ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK,
05478                                    SourceLocation KWLoc,
05479                                    SourceLocation ModulePrivateLoc,
05480                                    TemplateIdAnnotation &TemplateId,
05481                                    AttributeList *Attr,
05482                                  MultiTemplateParamsArg TemplateParameterLists);
05483 
05484   Decl *ActOnTemplateDeclarator(Scope *S,
05485                                 MultiTemplateParamsArg TemplateParameterLists,
05486                                 Declarator &D);
05487 
05488   Decl *ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope,
05489                                   MultiTemplateParamsArg TemplateParameterLists,
05490                                         Declarator &D);
05491 
05492   bool
05493   CheckSpecializationInstantiationRedecl(SourceLocation NewLoc,
05494                                          TemplateSpecializationKind NewTSK,
05495                                          NamedDecl *PrevDecl,
05496                                          TemplateSpecializationKind PrevTSK,
05497                                          SourceLocation PrevPtOfInstantiation,
05498                                          bool &SuppressNew);
05499 
05500   bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD,
05501                     const TemplateArgumentListInfo &ExplicitTemplateArgs,
05502                                                     LookupResult &Previous);
05503 
05504   bool CheckFunctionTemplateSpecialization(FunctionDecl *FD,
05505                          TemplateArgumentListInfo *ExplicitTemplateArgs,
05506                                            LookupResult &Previous);
05507   bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous);
05508 
05509   DeclResult
05510   ActOnExplicitInstantiation(Scope *S,
05511                              SourceLocation ExternLoc,
05512                              SourceLocation TemplateLoc,
05513                              unsigned TagSpec,
05514                              SourceLocation KWLoc,
05515                              const CXXScopeSpec &SS,
05516                              TemplateTy Template,
05517                              SourceLocation TemplateNameLoc,
05518                              SourceLocation LAngleLoc,
05519                              ASTTemplateArgsPtr TemplateArgs,
05520                              SourceLocation RAngleLoc,
05521                              AttributeList *Attr);
05522 
05523   DeclResult
05524   ActOnExplicitInstantiation(Scope *S,
05525                              SourceLocation ExternLoc,
05526                              SourceLocation TemplateLoc,
05527                              unsigned TagSpec,
05528                              SourceLocation KWLoc,
05529                              CXXScopeSpec &SS,
05530                              IdentifierInfo *Name,
05531                              SourceLocation NameLoc,
05532                              AttributeList *Attr);
05533 
05534   DeclResult ActOnExplicitInstantiation(Scope *S,
05535                                         SourceLocation ExternLoc,
05536                                         SourceLocation TemplateLoc,
05537                                         Declarator &D);
05538 
05539   TemplateArgumentLoc
05540   SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template,
05541                                           SourceLocation TemplateLoc,
05542                                           SourceLocation RAngleLoc,
05543                                           Decl *Param,
05544                                           SmallVectorImpl<TemplateArgument>
05545                                             &Converted,
05546                                           bool &HasDefaultArg);
05547 
05548   /// \brief Specifies the context in which a particular template
05549   /// argument is being checked.
05550   enum CheckTemplateArgumentKind {
05551     /// \brief The template argument was specified in the code or was
05552     /// instantiated with some deduced template arguments.
05553     CTAK_Specified,
05554 
05555     /// \brief The template argument was deduced via template argument
05556     /// deduction.
05557     CTAK_Deduced,
05558 
05559     /// \brief The template argument was deduced from an array bound
05560     /// via template argument deduction.
05561     CTAK_DeducedFromArrayBound
05562   };
05563 
05564   bool CheckTemplateArgument(NamedDecl *Param,
05565                              TemplateArgumentLoc &Arg,
05566                              NamedDecl *Template,
05567                              SourceLocation TemplateLoc,
05568                              SourceLocation RAngleLoc,
05569                              unsigned ArgumentPackIndex,
05570                            SmallVectorImpl<TemplateArgument> &Converted,
05571                              CheckTemplateArgumentKind CTAK = CTAK_Specified);
05572 
05573   /// \brief Check that the given template arguments can be be provided to
05574   /// the given template, converting the arguments along the way.
05575   ///
05576   /// \param Template The template to which the template arguments are being
05577   /// provided.
05578   ///
05579   /// \param TemplateLoc The location of the template name in the source.
05580   ///
05581   /// \param TemplateArgs The list of template arguments. If the template is
05582   /// a template template parameter, this function may extend the set of
05583   /// template arguments to also include substituted, defaulted template
05584   /// arguments.
05585   ///
05586   /// \param PartialTemplateArgs True if the list of template arguments is
05587   /// intentionally partial, e.g., because we're checking just the initial
05588   /// set of template arguments.
05589   ///
05590   /// \param Converted Will receive the converted, canonicalized template
05591   /// arguments.
05592   ///
05593   /// \returns true if an error occurred, false otherwise.
05594   bool CheckTemplateArgumentList(TemplateDecl *Template,
05595                                  SourceLocation TemplateLoc,
05596                                  TemplateArgumentListInfo &TemplateArgs,
05597                                  bool PartialTemplateArgs,
05598                            SmallVectorImpl<TemplateArgument> &Converted);
05599 
05600   bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
05601                                  TemplateArgumentLoc &Arg,
05602                            SmallVectorImpl<TemplateArgument> &Converted);
05603 
05604   bool CheckTemplateArgument(TemplateTypeParmDecl *Param,
05605                              TypeSourceInfo *Arg);
05606   ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
05607                                    QualType InstantiatedParamType, Expr *Arg,
05608                                    TemplateArgument &Converted,
05609                                CheckTemplateArgumentKind CTAK = CTAK_Specified);
05610   bool CheckTemplateArgument(TemplateTemplateParmDecl *Param,
05611                              TemplateArgumentLoc &Arg,
05612                              unsigned ArgumentPackIndex);
05613 
05614   ExprResult
05615   BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg,
05616                                           QualType ParamType,
05617                                           SourceLocation Loc);
05618   ExprResult
05619   BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
05620                                               SourceLocation Loc);
05621 
05622   /// \brief Enumeration describing how template parameter lists are compared
05623   /// for equality.
05624   enum TemplateParameterListEqualKind {
05625     /// \brief We are matching the template parameter lists of two templates
05626     /// that might be redeclarations.
05627     ///
05628     /// \code
05629     /// template<typename T> struct X;
05630     /// template<typename T> struct X;
05631     /// \endcode
05632     TPL_TemplateMatch,
05633 
05634     /// \brief We are matching the template parameter lists of two template
05635     /// template parameters as part of matching the template parameter lists
05636     /// of two templates that might be redeclarations.
05637     ///
05638     /// \code
05639     /// template<template<int I> class TT> struct X;
05640     /// template<template<int Value> class Other> struct X;
05641     /// \endcode
05642     TPL_TemplateTemplateParmMatch,
05643 
05644     /// \brief We are matching the template parameter lists of a template
05645     /// template argument against the template parameter lists of a template
05646     /// template parameter.
05647     ///
05648     /// \code
05649     /// template<template<int Value> class Metafun> struct X;
05650     /// template<int Value> struct integer_c;
05651     /// X<integer_c> xic;
05652     /// \endcode
05653     TPL_TemplateTemplateArgumentMatch
05654   };
05655 
05656   bool TemplateParameterListsAreEqual(TemplateParameterList *New,
05657                                       TemplateParameterList *Old,
05658                                       bool Complain,
05659                                       TemplateParameterListEqualKind Kind,
05660                                       SourceLocation TemplateArgLoc
05661                                         = SourceLocation());
05662 
05663   bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams);
05664 
05665   /// \brief Called when the parser has parsed a C++ typename
05666   /// specifier, e.g., "typename T::type".
05667   ///
05668   /// \param S The scope in which this typename type occurs.
05669   /// \param TypenameLoc the location of the 'typename' keyword
05670   /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
05671   /// \param II the identifier we're retrieving (e.g., 'type' in the example).
05672   /// \param IdLoc the location of the identifier.
05673   TypeResult
05674   ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
05675                     const CXXScopeSpec &SS, const IdentifierInfo &II,
05676                     SourceLocation IdLoc);
05677 
05678   /// \brief Called when the parser has parsed a C++ typename
05679   /// specifier that ends in a template-id, e.g.,
05680   /// "typename MetaFun::template apply<T1, T2>".
05681   ///
05682   /// \param S The scope in which this typename type occurs.
05683   /// \param TypenameLoc the location of the 'typename' keyword
05684   /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
05685   /// \param TemplateLoc the location of the 'template' keyword, if any.
05686   /// \param TemplateName The template name.
05687   /// \param TemplateNameLoc The location of the template name.
05688   /// \param LAngleLoc The location of the opening angle bracket  ('<').
05689   /// \param TemplateArgs The template arguments.
05690   /// \param RAngleLoc The location of the closing angle bracket  ('>').
05691   TypeResult
05692   ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
05693                     const CXXScopeSpec &SS,
05694                     SourceLocation TemplateLoc,
05695                     TemplateTy TemplateName,
05696                     SourceLocation TemplateNameLoc,
05697                     SourceLocation LAngleLoc,
05698                     ASTTemplateArgsPtr TemplateArgs,
05699                     SourceLocation RAngleLoc);
05700 
05701   QualType CheckTypenameType(ElaboratedTypeKeyword Keyword,
05702                              SourceLocation KeywordLoc,
05703                              NestedNameSpecifierLoc QualifierLoc,
05704                              const IdentifierInfo &II,
05705                              SourceLocation IILoc);
05706 
05707   TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
05708                                                     SourceLocation Loc,
05709                                                     DeclarationName Name);
05710   bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS);
05711 
05712   ExprResult RebuildExprInCurrentInstantiation(Expr *E);
05713   bool RebuildTemplateParamsInCurrentInstantiation(
05714                                                 TemplateParameterList *Params);
05715 
05716   std::string
05717   getTemplateArgumentBindingsText(const TemplateParameterList *Params,
05718                                   const TemplateArgumentList &Args);
05719 
05720   std::string
05721   getTemplateArgumentBindingsText(const TemplateParameterList *Params,
05722                                   const TemplateArgument *Args,
05723                                   unsigned NumArgs);
05724 
05725   //===--------------------------------------------------------------------===//
05726   // C++ Variadic Templates (C++0x [temp.variadic])
05727   //===--------------------------------------------------------------------===//
05728 
05729   /// Determine whether an unexpanded parameter pack might be permitted in this
05730   /// location. Useful for error recovery.
05731   bool isUnexpandedParameterPackPermitted();
05732 
05733   /// \brief The context in which an unexpanded parameter pack is
05734   /// being diagnosed.
05735   ///
05736   /// Note that the values of this enumeration line up with the first
05737   /// argument to the \c err_unexpanded_parameter_pack diagnostic.
05738   enum UnexpandedParameterPackContext {
05739     /// \brief An arbitrary expression.
05740     UPPC_Expression = 0,
05741 
05742     /// \brief The base type of a class type.
05743     UPPC_BaseType,
05744 
05745     /// \brief The type of an arbitrary declaration.
05746     UPPC_DeclarationType,
05747 
05748     /// \brief The type of a data member.
05749     UPPC_DataMemberType,
05750 
05751     /// \brief The size of a bit-field.
05752     UPPC_BitFieldWidth,
05753 
05754     /// \brief The expression in a static assertion.
05755     UPPC_StaticAssertExpression,
05756 
05757     /// \brief The fixed underlying type of an enumeration.
05758     UPPC_FixedUnderlyingType,
05759 
05760     /// \brief The enumerator value.
05761     UPPC_EnumeratorValue,
05762 
05763     /// \brief A using declaration.
05764     UPPC_UsingDeclaration,
05765 
05766     /// \brief A friend declaration.
05767     UPPC_FriendDeclaration,
05768 
05769     /// \brief A declaration qualifier.
05770     UPPC_DeclarationQualifier,
05771 
05772     /// \brief An initializer.
05773     UPPC_Initializer,
05774 
05775     /// \brief A default argument.
05776     UPPC_DefaultArgument,
05777 
05778     /// \brief The type of a non-type template parameter.
05779     UPPC_NonTypeTemplateParameterType,
05780 
05781     /// \brief The type of an exception.
05782     UPPC_ExceptionType,
05783 
05784     /// \brief Partial specialization.
05785     UPPC_PartialSpecialization,
05786 
05787     /// \brief Microsoft __if_exists.
05788     UPPC_IfExists,
05789 
05790     /// \brief Microsoft __if_not_exists.
05791     UPPC_IfNotExists,
05792 
05793     /// \brief Lambda expression.
05794     UPPC_Lambda,
05795 
05796     /// \brief Block expression,
05797     UPPC_Block
05798   };
05799 
05800   /// \brief Diagnose unexpanded parameter packs.
05801   ///
05802   /// \param Loc The location at which we should emit the diagnostic.
05803   ///
05804   /// \param UPPC The context in which we are diagnosing unexpanded
05805   /// parameter packs.
05806   ///
05807   /// \param Unexpanded the set of unexpanded parameter packs.
05808   ///
05809   /// \returns true if an error occurred, false otherwise.
05810   bool DiagnoseUnexpandedParameterPacks(SourceLocation Loc,
05811                                         UnexpandedParameterPackContext UPPC,
05812                                   ArrayRef<UnexpandedParameterPack> Unexpanded);
05813 
05814   /// \brief If the given type contains an unexpanded parameter pack,
05815   /// diagnose the error.
05816   ///
05817   /// \param Loc The source location where a diagnostc should be emitted.
05818   ///
05819   /// \param T The type that is being checked for unexpanded parameter
05820   /// packs.
05821   ///
05822   /// \returns true if an error occurred, false otherwise.
05823   bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T,
05824                                        UnexpandedParameterPackContext UPPC);
05825 
05826   /// \brief If the given expression contains an unexpanded parameter
05827   /// pack, diagnose the error.
05828   ///
05829   /// \param E The expression that is being checked for unexpanded
05830   /// parameter packs.
05831   ///
05832   /// \returns true if an error occurred, false otherwise.
05833   bool DiagnoseUnexpandedParameterPack(Expr *E,
05834                        UnexpandedParameterPackContext UPPC = UPPC_Expression);
05835 
05836   /// \brief If the given nested-name-specifier contains an unexpanded
05837   /// parameter pack, diagnose the error.
05838   ///
05839   /// \param SS The nested-name-specifier that is being checked for
05840   /// unexpanded parameter packs.
05841   ///
05842   /// \returns true if an error occurred, false otherwise.
05843   bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS,
05844                                        UnexpandedParameterPackContext UPPC);
05845 
05846   /// \brief If the given name contains an unexpanded parameter pack,
05847   /// diagnose the error.
05848   ///
05849   /// \param NameInfo The name (with source location information) that
05850   /// is being checked for unexpanded parameter packs.
05851   ///
05852   /// \returns true if an error occurred, false otherwise.
05853   bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo,
05854                                        UnexpandedParameterPackContext UPPC);
05855 
05856   /// \brief If the given template name contains an unexpanded parameter pack,
05857   /// diagnose the error.
05858   ///
05859   /// \param Loc The location of the template name.
05860   ///
05861   /// \param Template The template name that is being checked for unexpanded
05862   /// parameter packs.
05863   ///
05864   /// \returns true if an error occurred, false otherwise.
05865   bool DiagnoseUnexpandedParameterPack(SourceLocation Loc,
05866                                        TemplateName Template,
05867                                        UnexpandedParameterPackContext UPPC);
05868 
05869   /// \brief If the given template argument contains an unexpanded parameter
05870   /// pack, diagnose the error.
05871   ///
05872   /// \param Arg The template argument that is being checked for unexpanded
05873   /// parameter packs.
05874   ///
05875   /// \returns true if an error occurred, false otherwise.
05876   bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg,
05877                                        UnexpandedParameterPackContext UPPC);
05878 
05879   /// \brief Collect the set of unexpanded parameter packs within the given
05880   /// template argument.
05881   ///
05882   /// \param Arg The template argument that will be traversed to find
05883   /// unexpanded parameter packs.
05884   void collectUnexpandedParameterPacks(TemplateArgument Arg,
05885                    SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
05886 
05887   /// \brief Collect the set of unexpanded parameter packs within the given
05888   /// template argument.
05889   ///
05890   /// \param Arg The template argument that will be traversed to find
05891   /// unexpanded parameter packs.
05892   void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg,
05893                     SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
05894 
05895   /// \brief Collect the set of unexpanded parameter packs within the given
05896   /// type.
05897   ///
05898   /// \param T The type that will be traversed to find
05899   /// unexpanded parameter packs.
05900   void collectUnexpandedParameterPacks(QualType T,
05901                    SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
05902 
05903   /// \brief Collect the set of unexpanded parameter packs within the given
05904   /// type.
05905   ///
05906   /// \param TL The type that will be traversed to find
05907   /// unexpanded parameter packs.
05908   void collectUnexpandedParameterPacks(TypeLoc TL,
05909                    SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
05910 
05911   /// \brief Collect the set of unexpanded parameter packs within the given
05912   /// nested-name-specifier.
05913   ///
05914   /// \param SS The nested-name-specifier that will be traversed to find
05915   /// unexpanded parameter packs.
05916   void collectUnexpandedParameterPacks(CXXScopeSpec &SS,
05917                          SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
05918 
05919   /// \brief Collect the set of unexpanded parameter packs within the given
05920   /// name.
05921   ///
05922   /// \param NameInfo The name that will be traversed to find
05923   /// unexpanded parameter packs.
05924   void collectUnexpandedParameterPacks(const DeclarationNameInfo &NameInfo,
05925                          SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
05926 
05927   /// \brief Invoked when parsing a template argument followed by an
05928   /// ellipsis, which creates a pack expansion.
05929   ///
05930   /// \param Arg The template argument preceding the ellipsis, which
05931   /// may already be invalid.
05932   ///
05933   /// \param EllipsisLoc The location of the ellipsis.
05934   ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg,
05935                                             SourceLocation EllipsisLoc);
05936 
05937   /// \brief Invoked when parsing a type followed by an ellipsis, which
05938   /// creates a pack expansion.
05939   ///
05940   /// \param Type The type preceding the ellipsis, which will become
05941   /// the pattern of the pack expansion.
05942   ///
05943   /// \param EllipsisLoc The location of the ellipsis.
05944   TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc);
05945 
05946   /// \brief Construct a pack expansion type from the pattern of the pack
05947   /// expansion.
05948   TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern,
05949                                      SourceLocation EllipsisLoc,
05950                                      Optional<unsigned> NumExpansions);
05951 
05952   /// \brief Construct a pack expansion type from the pattern of the pack
05953   /// expansion.
05954   QualType CheckPackExpansion(QualType Pattern,
05955                               SourceRange PatternRange,
05956                               SourceLocation EllipsisLoc,
05957                               Optional<unsigned> NumExpansions);
05958 
05959   /// \brief Invoked when parsing an expression followed by an ellipsis, which
05960   /// creates a pack expansion.
05961   ///
05962   /// \param Pattern The expression preceding the ellipsis, which will become
05963   /// the pattern of the pack expansion.
05964   ///
05965   /// \param EllipsisLoc The location of the ellipsis.
05966   ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc);
05967 
05968   /// \brief Invoked when parsing an expression followed by an ellipsis, which
05969   /// creates a pack expansion.
05970   ///
05971   /// \param Pattern The expression preceding the ellipsis, which will become
05972   /// the pattern of the pack expansion.
05973   ///
05974   /// \param EllipsisLoc The location of the ellipsis.
05975   ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
05976                                 Optional<unsigned> NumExpansions);
05977 
05978   /// \brief Determine whether we could expand a pack expansion with the
05979   /// given set of parameter packs into separate arguments by repeatedly
05980   /// transforming the pattern.
05981   ///
05982   /// \param EllipsisLoc The location of the ellipsis that identifies the
05983   /// pack expansion.
05984   ///
05985   /// \param PatternRange The source range that covers the entire pattern of
05986   /// the pack expansion.
05987   ///
05988   /// \param Unexpanded The set of unexpanded parameter packs within the
05989   /// pattern.
05990   ///
05991   /// \param ShouldExpand Will be set to \c true if the transformer should
05992   /// expand the corresponding pack expansions into separate arguments. When
05993   /// set, \c NumExpansions must also be set.
05994   ///
05995   /// \param RetainExpansion Whether the caller should add an unexpanded
05996   /// pack expansion after all of the expanded arguments. This is used
05997   /// when extending explicitly-specified template argument packs per
05998   /// C++0x [temp.arg.explicit]p9.
05999   ///
06000   /// \param NumExpansions The number of separate arguments that will be in
06001   /// the expanded form of the corresponding pack expansion. This is both an
06002   /// input and an output parameter, which can be set by the caller if the
06003   /// number of expansions is known a priori (e.g., due to a prior substitution)
06004   /// and will be set by the callee when the number of expansions is known.
06005   /// The callee must set this value when \c ShouldExpand is \c true; it may
06006   /// set this value in other cases.
06007   ///
06008   /// \returns true if an error occurred (e.g., because the parameter packs
06009   /// are to be instantiated with arguments of different lengths), false
06010   /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
06011   /// must be set.
06012   bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc,
06013                                        SourceRange PatternRange,
06014                              ArrayRef<UnexpandedParameterPack> Unexpanded,
06015                              const MultiLevelTemplateArgumentList &TemplateArgs,
06016                                        bool &ShouldExpand,
06017                                        bool &RetainExpansion,
06018                                        Optional<unsigned> &NumExpansions);
06019 
06020   /// \brief Determine the number of arguments in the given pack expansion
06021   /// type.
06022   ///
06023   /// This routine assumes that the number of arguments in the expansion is
06024   /// consistent across all of the unexpanded parameter packs in its pattern.
06025   ///
06026   /// Returns an empty Optional if the type can't be expanded.
06027   Optional<unsigned> getNumArgumentsInExpansion(QualType T,
06028       const MultiLevelTemplateArgumentList &TemplateArgs);
06029 
06030   /// \brief Determine whether the given declarator contains any unexpanded
06031   /// parameter packs.
06032   ///
06033   /// This routine is used by the parser to disambiguate function declarators
06034   /// with an ellipsis prior to the ')', e.g.,
06035   ///
06036   /// \code
06037   ///   void f(T...);
06038   /// \endcode
06039   ///
06040   /// To determine whether we have an (unnamed) function parameter pack or
06041   /// a variadic function.
06042   ///
06043   /// \returns true if the declarator contains any unexpanded parameter packs,
06044   /// false otherwise.
06045   bool containsUnexpandedParameterPacks(Declarator &D);
06046 
06047   /// \brief Returns the pattern of the pack expansion for a template argument.
06048   ///
06049   /// \param OrigLoc The template argument to expand.
06050   ///
06051   /// \param Ellipsis Will be set to the location of the ellipsis.
06052   ///
06053   /// \param NumExpansions Will be set to the number of expansions that will
06054   /// be generated from this pack expansion, if known a priori.
06055   TemplateArgumentLoc getTemplateArgumentPackExpansionPattern(
06056       TemplateArgumentLoc OrigLoc,
06057       SourceLocation &Ellipsis,
06058       Optional<unsigned> &NumExpansions) const;
06059 
06060   //===--------------------------------------------------------------------===//
06061   // C++ Template Argument Deduction (C++ [temp.deduct])
06062   //===--------------------------------------------------------------------===//
06063 
06064   QualType adjustCCAndNoReturn(QualType ArgFunctionType, QualType FunctionType);
06065 
06066   /// \brief Describes the result of template argument deduction.
06067   ///
06068   /// The TemplateDeductionResult enumeration describes the result of
06069   /// template argument deduction, as returned from
06070   /// DeduceTemplateArguments(). The separate TemplateDeductionInfo
06071   /// structure provides additional information about the results of
06072   /// template argument deduction, e.g., the deduced template argument
06073   /// list (if successful) or the specific template parameters or
06074   /// deduced arguments that were involved in the failure.
06075   enum TemplateDeductionResult {
06076     /// \brief Template argument deduction was successful.
06077     TDK_Success = 0,
06078     /// \brief The declaration was invalid; do nothing.
06079     TDK_Invalid,
06080     /// \brief Template argument deduction exceeded the maximum template
06081     /// instantiation depth (which has already been diagnosed).
06082     TDK_InstantiationDepth,
06083     /// \brief Template argument deduction did not deduce a value
06084     /// for every template parameter.
06085     TDK_Incomplete,
06086     /// \brief Template argument deduction produced inconsistent
06087     /// deduced values for the given template parameter.
06088     TDK_Inconsistent,
06089     /// \brief Template argument deduction failed due to inconsistent
06090     /// cv-qualifiers on a template parameter type that would
06091     /// otherwise be deduced, e.g., we tried to deduce T in "const T"
06092     /// but were given a non-const "X".
06093     TDK_Underqualified,
06094     /// \brief Substitution of the deduced template argument values
06095     /// resulted in an error.
06096     TDK_SubstitutionFailure,
06097     /// \brief A non-depnedent component of the parameter did not match the
06098     /// corresponding component of the argument.
06099     TDK_NonDeducedMismatch,
06100     /// \brief When performing template argument deduction for a function
06101     /// template, there were too many call arguments.
06102     TDK_TooManyArguments,
06103     /// \brief When performing template argument deduction for a function
06104     /// template, there were too few call arguments.
06105     TDK_TooFewArguments,
06106     /// \brief The explicitly-specified template arguments were not valid
06107     /// template arguments for the given template.
06108     TDK_InvalidExplicitArguments,
06109     /// \brief The arguments included an overloaded function name that could
06110     /// not be resolved to a suitable function.
06111     TDK_FailedOverloadResolution,
06112     /// \brief Deduction failed; that's all we know.
06113     TDK_MiscellaneousDeductionFailure
06114   };
06115 
06116   TemplateDeductionResult
06117   DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
06118                           const TemplateArgumentList &TemplateArgs,
06119                           sema::TemplateDeductionInfo &Info);
06120 
06121   TemplateDeductionResult
06122   DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial,
06123                           const TemplateArgumentList &TemplateArgs,
06124                           sema::TemplateDeductionInfo &Info);
06125 
06126   TemplateDeductionResult SubstituteExplicitTemplateArguments(
06127       FunctionTemplateDecl *FunctionTemplate,
06128       TemplateArgumentListInfo &ExplicitTemplateArgs,
06129       SmallVectorImpl<DeducedTemplateArgument> &Deduced,
06130       SmallVectorImpl<QualType> &ParamTypes, QualType *FunctionType,
06131       sema::TemplateDeductionInfo &Info);
06132 
06133   /// brief A function argument from which we performed template argument
06134   // deduction for a call.
06135   struct OriginalCallArg {
06136     OriginalCallArg(QualType OriginalParamType,
06137                     unsigned ArgIdx,
06138                     QualType OriginalArgType)
06139       : OriginalParamType(OriginalParamType), ArgIdx(ArgIdx),
06140         OriginalArgType(OriginalArgType) { }
06141 
06142     QualType OriginalParamType;
06143     unsigned ArgIdx;
06144     QualType OriginalArgType;
06145   };
06146 
06147   TemplateDeductionResult
06148   FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate,
06149                       SmallVectorImpl<DeducedTemplateArgument> &Deduced,
06150                                   unsigned NumExplicitlySpecified,
06151                                   FunctionDecl *&Specialization,
06152                                   sema::TemplateDeductionInfo &Info,
06153            SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = nullptr);
06154 
06155   TemplateDeductionResult
06156   DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
06157                           TemplateArgumentListInfo *ExplicitTemplateArgs,
06158                           ArrayRef<Expr *> Args,
06159                           FunctionDecl *&Specialization,
06160                           sema::TemplateDeductionInfo &Info);
06161 
06162   TemplateDeductionResult
06163   DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
06164                           TemplateArgumentListInfo *ExplicitTemplateArgs,
06165                           QualType ArgFunctionType,
06166                           FunctionDecl *&Specialization,
06167                           sema::TemplateDeductionInfo &Info,
06168                           bool InOverloadResolution = false);
06169 
06170   TemplateDeductionResult
06171   DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
06172                           QualType ToType,
06173                           CXXConversionDecl *&Specialization,
06174                           sema::TemplateDeductionInfo &Info);
06175 
06176   TemplateDeductionResult
06177   DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
06178                           TemplateArgumentListInfo *ExplicitTemplateArgs,
06179                           FunctionDecl *&Specialization,
06180                           sema::TemplateDeductionInfo &Info,
06181                           bool InOverloadResolution = false);
06182 
06183   /// \brief Substitute Replacement for \p auto in \p TypeWithAuto
06184   QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement);
06185   /// \brief Substitute Replacement for auto in TypeWithAuto
06186   TypeSourceInfo* SubstAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, 
06187                                           QualType Replacement);
06188 
06189   /// \brief Result type of DeduceAutoType.
06190   enum DeduceAutoResult {
06191     DAR_Succeeded,
06192     DAR_Failed,
06193     DAR_FailedAlreadyDiagnosed
06194   };
06195 
06196   DeduceAutoResult DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer,
06197                                   QualType &Result);
06198   DeduceAutoResult DeduceAutoType(TypeLoc AutoTypeLoc, Expr *&Initializer,
06199                                   QualType &Result);
06200   void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init);
06201   bool DeduceReturnType(FunctionDecl *FD, SourceLocation Loc,
06202                         bool Diagnose = true);
06203 
06204   TypeLoc getReturnTypeLoc(FunctionDecl *FD) const;
06205 
06206   bool DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD,
06207                                         SourceLocation ReturnLoc,
06208                                         Expr *&RetExpr, AutoType *AT);
06209 
06210   FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1,
06211                                                    FunctionTemplateDecl *FT2,
06212                                                    SourceLocation Loc,
06213                                            TemplatePartialOrderingContext TPOC,
06214                                                    unsigned NumCallArguments1,
06215                                                    unsigned NumCallArguments2);
06216   UnresolvedSetIterator
06217   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
06218                      TemplateSpecCandidateSet &FailedCandidates,
06219                      SourceLocation Loc,
06220                      const PartialDiagnostic &NoneDiag,
06221                      const PartialDiagnostic &AmbigDiag,
06222                      const PartialDiagnostic &CandidateDiag,
06223                      bool Complain = true, QualType TargetType = QualType());
06224 
06225   ClassTemplatePartialSpecializationDecl *
06226   getMoreSpecializedPartialSpecialization(
06227                                   ClassTemplatePartialSpecializationDecl *PS1,
06228                                   ClassTemplatePartialSpecializationDecl *PS2,
06229                                   SourceLocation Loc);
06230 
06231   VarTemplatePartialSpecializationDecl *getMoreSpecializedPartialSpecialization(
06232       VarTemplatePartialSpecializationDecl *PS1,
06233       VarTemplatePartialSpecializationDecl *PS2, SourceLocation Loc);
06234 
06235   void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs,
06236                                   bool OnlyDeduced,
06237                                   unsigned Depth,
06238                                   llvm::SmallBitVector &Used);
06239   void MarkDeducedTemplateParameters(
06240                                   const FunctionTemplateDecl *FunctionTemplate,
06241                                   llvm::SmallBitVector &Deduced) {
06242     return MarkDeducedTemplateParameters(Context, FunctionTemplate, Deduced);
06243   }
06244   static void MarkDeducedTemplateParameters(ASTContext &Ctx,
06245                                   const FunctionTemplateDecl *FunctionTemplate,
06246                                   llvm::SmallBitVector &Deduced);
06247 
06248   //===--------------------------------------------------------------------===//
06249   // C++ Template Instantiation
06250   //
06251 
06252   MultiLevelTemplateArgumentList
06253   getTemplateInstantiationArgs(NamedDecl *D,
06254                                const TemplateArgumentList *Innermost = nullptr,
06255                                bool RelativeToPrimary = false,
06256                                const FunctionDecl *Pattern = nullptr);
06257 
06258   /// \brief A template instantiation that is currently in progress.
06259   struct ActiveTemplateInstantiation {
06260     /// \brief The kind of template instantiation we are performing
06261     enum InstantiationKind {
06262       /// We are instantiating a template declaration. The entity is
06263       /// the declaration we're instantiating (e.g., a CXXRecordDecl).
06264       TemplateInstantiation,
06265 
06266       /// We are instantiating a default argument for a template
06267       /// parameter. The Entity is the template, and
06268       /// TemplateArgs/NumTemplateArguments provides the template
06269       /// arguments as specified.
06270       /// FIXME: Use a TemplateArgumentList
06271       DefaultTemplateArgumentInstantiation,
06272 
06273       /// We are instantiating a default argument for a function.
06274       /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs
06275       /// provides the template arguments as specified.
06276       DefaultFunctionArgumentInstantiation,
06277 
06278       /// We are substituting explicit template arguments provided for
06279       /// a function template. The entity is a FunctionTemplateDecl.
06280       ExplicitTemplateArgumentSubstitution,
06281 
06282       /// We are substituting template argument determined as part of
06283       /// template argument deduction for either a class template
06284       /// partial specialization or a function template. The
06285       /// Entity is either a ClassTemplatePartialSpecializationDecl or
06286       /// a FunctionTemplateDecl.
06287       DeducedTemplateArgumentSubstitution,
06288 
06289       /// We are substituting prior template arguments into a new
06290       /// template parameter. The template parameter itself is either a
06291       /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl.
06292       PriorTemplateArgumentSubstitution,
06293 
06294       /// We are checking the validity of a default template argument that
06295       /// has been used when naming a template-id.
06296       DefaultTemplateArgumentChecking,
06297 
06298       /// We are instantiating the exception specification for a function
06299       /// template which was deferred until it was needed.
06300       ExceptionSpecInstantiation
06301     } Kind;
06302 
06303     /// \brief The point of instantiation within the source code.
06304     SourceLocation PointOfInstantiation;
06305 
06306     /// \brief The template (or partial specialization) in which we are
06307     /// performing the instantiation, for substitutions of prior template
06308     /// arguments.
06309     NamedDecl *Template;
06310 
06311     /// \brief The entity that is being instantiated.
06312     Decl *Entity;
06313 
06314     /// \brief The list of template arguments we are substituting, if they
06315     /// are not part of the entity.
06316     const TemplateArgument *TemplateArgs;
06317 
06318     /// \brief The number of template arguments in TemplateArgs.
06319     unsigned NumTemplateArgs;
06320 
06321     /// \brief The template deduction info object associated with the
06322     /// substitution or checking of explicit or deduced template arguments.
06323     sema::TemplateDeductionInfo *DeductionInfo;
06324 
06325     /// \brief The source range that covers the construct that cause
06326     /// the instantiation, e.g., the template-id that causes a class
06327     /// template instantiation.
06328     SourceRange InstantiationRange;
06329 
06330     ActiveTemplateInstantiation()
06331       : Kind(TemplateInstantiation), Template(nullptr), Entity(nullptr),
06332         TemplateArgs(nullptr), NumTemplateArgs(0), DeductionInfo(nullptr) {}
06333 
06334     /// \brief Determines whether this template is an actual instantiation
06335     /// that should be counted toward the maximum instantiation depth.
06336     bool isInstantiationRecord() const;
06337 
06338     friend bool operator==(const ActiveTemplateInstantiation &X,
06339                            const ActiveTemplateInstantiation &Y) {
06340       if (X.Kind != Y.Kind)
06341         return false;
06342 
06343       if (X.Entity != Y.Entity)
06344         return false;
06345 
06346       switch (X.Kind) {
06347       case TemplateInstantiation:
06348       case ExceptionSpecInstantiation:
06349         return true;
06350 
06351       case PriorTemplateArgumentSubstitution:
06352       case DefaultTemplateArgumentChecking:
06353         return X.Template == Y.Template && X.TemplateArgs == Y.TemplateArgs;
06354 
06355       case DefaultTemplateArgumentInstantiation:
06356       case ExplicitTemplateArgumentSubstitution:
06357       case DeducedTemplateArgumentSubstitution:
06358       case DefaultFunctionArgumentInstantiation:
06359         return X.TemplateArgs == Y.TemplateArgs;
06360 
06361       }
06362 
06363       llvm_unreachable("Invalid InstantiationKind!");
06364     }
06365 
06366     friend bool operator!=(const ActiveTemplateInstantiation &X,
06367                            const ActiveTemplateInstantiation &Y) {
06368       return !(X == Y);
06369     }
06370   };
06371 
06372   /// \brief List of active template instantiations.
06373   ///
06374   /// This vector is treated as a stack. As one template instantiation
06375   /// requires another template instantiation, additional
06376   /// instantiations are pushed onto the stack up to a
06377   /// user-configurable limit LangOptions::InstantiationDepth.
06378   SmallVector<ActiveTemplateInstantiation, 16>
06379     ActiveTemplateInstantiations;
06380 
06381   /// \brief Extra modules inspected when performing a lookup during a template
06382   /// instantiation. Computed lazily.
06383   SmallVector<Module*, 16> ActiveTemplateInstantiationLookupModules;
06384 
06385   /// \brief Cache of additional modules that should be used for name lookup
06386   /// within the current template instantiation. Computed lazily; use
06387   /// getLookupModules() to get a complete set.
06388   llvm::DenseSet<Module*> LookupModulesCache;
06389 
06390   /// \brief Get the set of additional modules that should be checked during
06391   /// name lookup. A module and its imports become visible when instanting a
06392   /// template defined within it.
06393   llvm::DenseSet<Module*> &getLookupModules();
06394 
06395   /// \brief Whether we are in a SFINAE context that is not associated with
06396   /// template instantiation.
06397   ///
06398   /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside
06399   /// of a template instantiation or template argument deduction.
06400   bool InNonInstantiationSFINAEContext;
06401 
06402   /// \brief The number of ActiveTemplateInstantiation entries in
06403   /// \c ActiveTemplateInstantiations that are not actual instantiations and,
06404   /// therefore, should not be counted as part of the instantiation depth.
06405   unsigned NonInstantiationEntries;
06406 
06407   /// \brief The last template from which a template instantiation
06408   /// error or warning was produced.
06409   ///
06410   /// This value is used to suppress printing of redundant template
06411   /// instantiation backtraces when there are multiple errors in the
06412   /// same instantiation. FIXME: Does this belong in Sema? It's tough
06413   /// to implement it anywhere else.
06414   ActiveTemplateInstantiation LastTemplateInstantiationErrorContext;
06415 
06416   /// \brief The current index into pack expansion arguments that will be
06417   /// used for substitution of parameter packs.
06418   ///
06419   /// The pack expansion index will be -1 to indicate that parameter packs
06420   /// should be instantiated as themselves. Otherwise, the index specifies
06421   /// which argument within the parameter pack will be used for substitution.
06422   int ArgumentPackSubstitutionIndex;
06423 
06424   /// \brief RAII object used to change the argument pack substitution index
06425   /// within a \c Sema object.
06426   ///
06427   /// See \c ArgumentPackSubstitutionIndex for more information.
06428   class ArgumentPackSubstitutionIndexRAII {
06429     Sema &Self;
06430     int OldSubstitutionIndex;
06431 
06432   public:
06433     ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex)
06434       : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) {
06435       Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex;
06436     }
06437 
06438     ~ArgumentPackSubstitutionIndexRAII() {
06439       Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex;
06440     }
06441   };
06442 
06443   friend class ArgumentPackSubstitutionRAII;
06444 
06445   /// \brief The stack of calls expression undergoing template instantiation.
06446   ///
06447   /// The top of this stack is used by a fixit instantiating unresolved
06448   /// function calls to fix the AST to match the textual change it prints.
06449   SmallVector<CallExpr *, 8> CallsUndergoingInstantiation;
06450 
06451   /// \brief For each declaration that involved template argument deduction, the
06452   /// set of diagnostics that were suppressed during that template argument
06453   /// deduction.
06454   ///
06455   /// FIXME: Serialize this structure to the AST file.
06456   typedef llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1> >
06457     SuppressedDiagnosticsMap;
06458   SuppressedDiagnosticsMap SuppressedDiagnostics;
06459 
06460   /// \brief A stack object to be created when performing template
06461   /// instantiation.
06462   ///
06463   /// Construction of an object of type \c InstantiatingTemplate
06464   /// pushes the current instantiation onto the stack of active
06465   /// instantiations. If the size of this stack exceeds the maximum
06466   /// number of recursive template instantiations, construction
06467   /// produces an error and evaluates true.
06468   ///
06469   /// Destruction of this object will pop the named instantiation off
06470   /// the stack.
06471   struct InstantiatingTemplate {
06472     /// \brief Note that we are instantiating a class template,
06473     /// function template, or a member thereof.
06474     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
06475                           Decl *Entity,
06476                           SourceRange InstantiationRange = SourceRange());
06477 
06478     struct ExceptionSpecification {};
06479     /// \brief Note that we are instantiating an exception specification
06480     /// of a function template.
06481     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
06482                           FunctionDecl *Entity, ExceptionSpecification,
06483                           SourceRange InstantiationRange = SourceRange());
06484 
06485     /// \brief Note that we are instantiating a default argument in a
06486     /// template-id.
06487     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
06488                           TemplateDecl *Template,
06489                           ArrayRef<TemplateArgument> TemplateArgs,
06490                           SourceRange InstantiationRange = SourceRange());
06491 
06492     /// \brief Note that we are instantiating a default argument in a
06493     /// template-id.
06494     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
06495                           FunctionTemplateDecl *FunctionTemplate,
06496                           ArrayRef<TemplateArgument> TemplateArgs,
06497                           ActiveTemplateInstantiation::InstantiationKind Kind,
06498                           sema::TemplateDeductionInfo &DeductionInfo,
06499                           SourceRange InstantiationRange = SourceRange());
06500 
06501     /// \brief Note that we are instantiating as part of template
06502     /// argument deduction for a class template partial
06503     /// specialization.
06504     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
06505                           ClassTemplatePartialSpecializationDecl *PartialSpec,
06506                           ArrayRef<TemplateArgument> TemplateArgs,
06507                           sema::TemplateDeductionInfo &DeductionInfo,
06508                           SourceRange InstantiationRange = SourceRange());
06509 
06510     /// \brief Note that we are instantiating as part of template
06511     /// argument deduction for a variable template partial
06512     /// specialization.
06513     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
06514                           VarTemplatePartialSpecializationDecl *PartialSpec,
06515                           ArrayRef<TemplateArgument> TemplateArgs,
06516                           sema::TemplateDeductionInfo &DeductionInfo,
06517                           SourceRange InstantiationRange = SourceRange());
06518 
06519     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
06520                           ParmVarDecl *Param,
06521                           ArrayRef<TemplateArgument> TemplateArgs,
06522                           SourceRange InstantiationRange = SourceRange());
06523 
06524     /// \brief Note that we are substituting prior template arguments into a
06525     /// non-type parameter.
06526     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
06527                           NamedDecl *Template,
06528                           NonTypeTemplateParmDecl *Param,
06529                           ArrayRef<TemplateArgument> TemplateArgs,
06530                           SourceRange InstantiationRange);
06531 
06532     /// \brief Note that we are substituting prior template arguments into a
06533     /// template template parameter.
06534     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
06535                           NamedDecl *Template,
06536                           TemplateTemplateParmDecl *Param,
06537                           ArrayRef<TemplateArgument> TemplateArgs,
06538                           SourceRange InstantiationRange);
06539 
06540     /// \brief Note that we are checking the default template argument
06541     /// against the template parameter for a given template-id.
06542     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
06543                           TemplateDecl *Template,
06544                           NamedDecl *Param,
06545                           ArrayRef<TemplateArgument> TemplateArgs,
06546                           SourceRange InstantiationRange);
06547 
06548 
06549     /// \brief Note that we have finished instantiating this template.
06550     void Clear();
06551 
06552     ~InstantiatingTemplate() { Clear(); }
06553 
06554     /// \brief Determines whether we have exceeded the maximum
06555     /// recursive template instantiations.
06556     bool isInvalid() const { return Invalid; }
06557 
06558   private:
06559     Sema &SemaRef;
06560     bool Invalid;
06561     bool SavedInNonInstantiationSFINAEContext;
06562     bool CheckInstantiationDepth(SourceLocation PointOfInstantiation,
06563                                  SourceRange InstantiationRange);
06564 
06565     // FIXME: Replace this with a constructor once we can use delegating
06566     // constructors in llvm.
06567     void Initialize(
06568         ActiveTemplateInstantiation::InstantiationKind Kind,
06569         SourceLocation PointOfInstantiation, SourceRange InstantiationRange,
06570         Decl *Entity, NamedDecl *Template = nullptr,
06571         ArrayRef<TemplateArgument> TemplateArgs = ArrayRef<TemplateArgument>(),
06572         sema::TemplateDeductionInfo *DeductionInfo = nullptr);
06573 
06574     InstantiatingTemplate(const InstantiatingTemplate&) LLVM_DELETED_FUNCTION;
06575 
06576     InstantiatingTemplate&
06577     operator=(const InstantiatingTemplate&) LLVM_DELETED_FUNCTION;
06578   };
06579 
06580   void PrintInstantiationStack();
06581 
06582   /// \brief Determines whether we are currently in a context where
06583   /// template argument substitution failures are not considered
06584   /// errors.
06585   ///
06586   /// \returns An empty \c Optional if we're not in a SFINAE context.
06587   /// Otherwise, contains a pointer that, if non-NULL, contains the nearest
06588   /// template-deduction context object, which can be used to capture
06589   /// diagnostics that will be suppressed.
06590   Optional<sema::TemplateDeductionInfo *> isSFINAEContext() const;
06591 
06592   /// \brief Determines whether we are currently in a context that
06593   /// is not evaluated as per C++ [expr] p5.
06594   bool isUnevaluatedContext() const {
06595     assert(!ExprEvalContexts.empty() &&
06596            "Must be in an expression evaluation context");
06597     return ExprEvalContexts.back().isUnevaluated();
06598   }
06599 
06600   /// \brief RAII class used to determine whether SFINAE has
06601   /// trapped any errors that occur during template argument
06602   /// deduction.
06603   class SFINAETrap {
06604     Sema &SemaRef;
06605     unsigned PrevSFINAEErrors;
06606     bool PrevInNonInstantiationSFINAEContext;
06607     bool PrevAccessCheckingSFINAE;
06608 
06609   public:
06610     explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false)
06611       : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors),
06612         PrevInNonInstantiationSFINAEContext(
06613                                       SemaRef.InNonInstantiationSFINAEContext),
06614         PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE)
06615     {
06616       if (!SemaRef.isSFINAEContext())
06617         SemaRef.InNonInstantiationSFINAEContext = true;
06618       SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE;
06619     }
06620 
06621     ~SFINAETrap() {
06622       SemaRef.NumSFINAEErrors = PrevSFINAEErrors;
06623       SemaRef.InNonInstantiationSFINAEContext
06624         = PrevInNonInstantiationSFINAEContext;
06625       SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE;
06626     }
06627 
06628     /// \brief Determine whether any SFINAE errors have been trapped.
06629     bool hasErrorOccurred() const {
06630       return SemaRef.NumSFINAEErrors > PrevSFINAEErrors;
06631     }
06632   };
06633 
06634   /// \brief RAII class used to indicate that we are performing provisional
06635   /// semantic analysis to determine the validity of a construct, so
06636   /// typo-correction and diagnostics in the immediate context (not within
06637   /// implicitly-instantiated templates) should be suppressed.
06638   class TentativeAnalysisScope {
06639     Sema &SemaRef;
06640     // FIXME: Using a SFINAETrap for this is a hack.
06641     SFINAETrap Trap;
06642     bool PrevDisableTypoCorrection;
06643   public:
06644     explicit TentativeAnalysisScope(Sema &SemaRef)
06645         : SemaRef(SemaRef), Trap(SemaRef, true),
06646           PrevDisableTypoCorrection(SemaRef.DisableTypoCorrection) {
06647       SemaRef.DisableTypoCorrection = true;
06648     }
06649     ~TentativeAnalysisScope() {
06650       SemaRef.DisableTypoCorrection = PrevDisableTypoCorrection;
06651     }
06652   };
06653 
06654   /// \brief The current instantiation scope used to store local
06655   /// variables.
06656   LocalInstantiationScope *CurrentInstantiationScope;
06657 
06658   /// \brief Tracks whether we are in a context where typo correction is
06659   /// disabled.
06660   bool DisableTypoCorrection;
06661 
06662   /// \brief The number of typos corrected by CorrectTypo.
06663   unsigned TyposCorrected;
06664 
06665   typedef llvm::DenseMap<IdentifierInfo *, TypoCorrection>
06666     UnqualifiedTyposCorrectedMap;
06667 
06668   /// \brief A cache containing the results of typo correction for unqualified
06669   /// name lookup.
06670   ///
06671   /// The string is the string that we corrected to (which may be empty, if
06672   /// there was no correction), while the boolean will be true when the
06673   /// string represents a keyword.
06674   UnqualifiedTyposCorrectedMap UnqualifiedTyposCorrected;
06675 
06676   typedef llvm::SmallSet<SourceLocation, 2> SrcLocSet;
06677   typedef llvm::DenseMap<IdentifierInfo *, SrcLocSet> IdentifierSourceLocations;
06678 
06679   /// \brief A cache containing identifiers for which typo correction failed and
06680   /// their locations, so that repeated attempts to correct an identifier in a
06681   /// given location are ignored if typo correction already failed for it.
06682   IdentifierSourceLocations TypoCorrectionFailures;
06683 
06684   /// \brief Worker object for performing CFG-based warnings.
06685   sema::AnalysisBasedWarnings AnalysisWarnings;
06686 
06687   /// \brief An entity for which implicit template instantiation is required.
06688   ///
06689   /// The source location associated with the declaration is the first place in
06690   /// the source code where the declaration was "used". It is not necessarily
06691   /// the point of instantiation (which will be either before or after the
06692   /// namespace-scope declaration that triggered this implicit instantiation),
06693   /// However, it is the location that diagnostics should generally refer to,
06694   /// because users will need to know what code triggered the instantiation.
06695   typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation;
06696 
06697   /// \brief The queue of implicit template instantiations that are required
06698   /// but have not yet been performed.
06699   std::deque<PendingImplicitInstantiation> PendingInstantiations;
06700 
06701   class SavePendingInstantiationsAndVTableUsesRAII {
06702   public:
06703     SavePendingInstantiationsAndVTableUsesRAII(Sema &S): S(S) {
06704       SavedPendingInstantiations.swap(S.PendingInstantiations);
06705       SavedVTableUses.swap(S.VTableUses);
06706     }
06707 
06708     ~SavePendingInstantiationsAndVTableUsesRAII() {
06709       // Restore the set of pending vtables.
06710       assert(S.VTableUses.empty() &&
06711              "VTableUses should be empty before it is discarded.");
06712       S.VTableUses.swap(SavedVTableUses);
06713 
06714       // Restore the set of pending implicit instantiations.
06715       assert(S.PendingInstantiations.empty() &&
06716              "PendingInstantiations should be empty before it is discarded.");
06717       S.PendingInstantiations.swap(SavedPendingInstantiations);
06718     }
06719 
06720   private:
06721     Sema &S;
06722     SmallVector<VTableUse, 16> SavedVTableUses;
06723     std::deque<PendingImplicitInstantiation> SavedPendingInstantiations;
06724   };
06725 
06726   /// \brief The queue of implicit template instantiations that are required
06727   /// and must be performed within the current local scope.
06728   ///
06729   /// This queue is only used for member functions of local classes in
06730   /// templates, which must be instantiated in the same scope as their
06731   /// enclosing function, so that they can reference function-local
06732   /// types, static variables, enumerators, etc.
06733   std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations;
06734 
06735   class SavePendingLocalImplicitInstantiationsRAII {
06736   public:
06737     SavePendingLocalImplicitInstantiationsRAII(Sema &S): S(S) {
06738       SavedPendingLocalImplicitInstantiations.swap(
06739           S.PendingLocalImplicitInstantiations);
06740     }
06741 
06742     ~SavePendingLocalImplicitInstantiationsRAII() {
06743       assert(S.PendingLocalImplicitInstantiations.empty() &&
06744              "there shouldn't be any pending local implicit instantiations");
06745       SavedPendingLocalImplicitInstantiations.swap(
06746           S.PendingLocalImplicitInstantiations);
06747     }
06748 
06749   private:
06750     Sema &S;
06751     std::deque<PendingImplicitInstantiation>
06752     SavedPendingLocalImplicitInstantiations;
06753   };
06754 
06755   void PerformPendingInstantiations(bool LocalOnly = false);
06756 
06757   TypeSourceInfo *SubstType(TypeSourceInfo *T,
06758                             const MultiLevelTemplateArgumentList &TemplateArgs,
06759                             SourceLocation Loc, DeclarationName Entity);
06760 
06761   QualType SubstType(QualType T,
06762                      const MultiLevelTemplateArgumentList &TemplateArgs,
06763                      SourceLocation Loc, DeclarationName Entity);
06764 
06765   TypeSourceInfo *SubstType(TypeLoc TL,
06766                             const MultiLevelTemplateArgumentList &TemplateArgs,
06767                             SourceLocation Loc, DeclarationName Entity);
06768 
06769   TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T,
06770                             const MultiLevelTemplateArgumentList &TemplateArgs,
06771                                         SourceLocation Loc,
06772                                         DeclarationName Entity,
06773                                         CXXRecordDecl *ThisContext,
06774                                         unsigned ThisTypeQuals);
06775   void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto,
06776                           const MultiLevelTemplateArgumentList &Args);
06777   ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D,
06778                             const MultiLevelTemplateArgumentList &TemplateArgs,
06779                                 int indexAdjustment,
06780                                 Optional<unsigned> NumExpansions,
06781                                 bool ExpectParameterPack);
06782   bool SubstParmTypes(SourceLocation Loc,
06783                       ParmVarDecl **Params, unsigned NumParams,
06784                       const MultiLevelTemplateArgumentList &TemplateArgs,
06785                       SmallVectorImpl<QualType> &ParamTypes,
06786                       SmallVectorImpl<ParmVarDecl *> *OutParams = nullptr);
06787   ExprResult SubstExpr(Expr *E,
06788                        const MultiLevelTemplateArgumentList &TemplateArgs);
06789 
06790   /// \brief Substitute the given template arguments into a list of
06791   /// expressions, expanding pack expansions if required.
06792   ///
06793   /// \param Exprs The list of expressions to substitute into.
06794   ///
06795   /// \param NumExprs The number of expressions in \p Exprs.
06796   ///
06797   /// \param IsCall Whether this is some form of call, in which case
06798   /// default arguments will be dropped.
06799   ///
06800   /// \param TemplateArgs The set of template arguments to substitute.
06801   ///
06802   /// \param Outputs Will receive all of the substituted arguments.
06803   ///
06804   /// \returns true if an error occurred, false otherwise.
06805   bool SubstExprs(Expr **Exprs, unsigned NumExprs, bool IsCall,
06806                   const MultiLevelTemplateArgumentList &TemplateArgs,
06807                   SmallVectorImpl<Expr *> &Outputs);
06808 
06809   StmtResult SubstStmt(Stmt *S,
06810                        const MultiLevelTemplateArgumentList &TemplateArgs);
06811 
06812   Decl *SubstDecl(Decl *D, DeclContext *Owner,
06813                   const MultiLevelTemplateArgumentList &TemplateArgs);
06814 
06815   ExprResult SubstInitializer(Expr *E,
06816                        const MultiLevelTemplateArgumentList &TemplateArgs,
06817                        bool CXXDirectInit);
06818 
06819   bool
06820   SubstBaseSpecifiers(CXXRecordDecl *Instantiation,
06821                       CXXRecordDecl *Pattern,
06822                       const MultiLevelTemplateArgumentList &TemplateArgs);
06823 
06824   bool
06825   InstantiateClass(SourceLocation PointOfInstantiation,
06826                    CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
06827                    const MultiLevelTemplateArgumentList &TemplateArgs,
06828                    TemplateSpecializationKind TSK,
06829                    bool Complain = true);
06830 
06831   bool InstantiateEnum(SourceLocation PointOfInstantiation,
06832                        EnumDecl *Instantiation, EnumDecl *Pattern,
06833                        const MultiLevelTemplateArgumentList &TemplateArgs,
06834                        TemplateSpecializationKind TSK);
06835 
06836   bool InstantiateInClassInitializer(
06837       SourceLocation PointOfInstantiation, FieldDecl *Instantiation,
06838       FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs);
06839 
06840   struct LateInstantiatedAttribute {
06841     const Attr *TmplAttr;
06842     LocalInstantiationScope *Scope;
06843     Decl *NewDecl;
06844 
06845     LateInstantiatedAttribute(const Attr *A, LocalInstantiationScope *S,
06846                               Decl *D)
06847       : TmplAttr(A), Scope(S), NewDecl(D)
06848     { }
06849   };
06850   typedef SmallVector<LateInstantiatedAttribute, 16> LateInstantiatedAttrVec;
06851 
06852   void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
06853                         const Decl *Pattern, Decl *Inst,
06854                         LateInstantiatedAttrVec *LateAttrs = nullptr,
06855                         LocalInstantiationScope *OuterMostScope = nullptr);
06856 
06857   bool
06858   InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation,
06859                            ClassTemplateSpecializationDecl *ClassTemplateSpec,
06860                            TemplateSpecializationKind TSK,
06861                            bool Complain = true);
06862 
06863   void InstantiateClassMembers(SourceLocation PointOfInstantiation,
06864                                CXXRecordDecl *Instantiation,
06865                             const MultiLevelTemplateArgumentList &TemplateArgs,
06866                                TemplateSpecializationKind TSK);
06867 
06868   void InstantiateClassTemplateSpecializationMembers(
06869                                           SourceLocation PointOfInstantiation,
06870                            ClassTemplateSpecializationDecl *ClassTemplateSpec,
06871                                                 TemplateSpecializationKind TSK);
06872 
06873   NestedNameSpecifierLoc
06874   SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
06875                            const MultiLevelTemplateArgumentList &TemplateArgs);
06876 
06877   DeclarationNameInfo
06878   SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
06879                            const MultiLevelTemplateArgumentList &TemplateArgs);
06880   TemplateName
06881   SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name,
06882                     SourceLocation Loc,
06883                     const MultiLevelTemplateArgumentList &TemplateArgs);
06884   bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs,
06885              TemplateArgumentListInfo &Result,
06886              const MultiLevelTemplateArgumentList &TemplateArgs);
06887 
06888   void InstantiateExceptionSpec(SourceLocation PointOfInstantiation,
06889                                 FunctionDecl *Function);
06890   void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
06891                                      FunctionDecl *Function,
06892                                      bool Recursive = false,
06893                                      bool DefinitionRequired = false);
06894   VarTemplateSpecializationDecl *BuildVarTemplateInstantiation(
06895       VarTemplateDecl *VarTemplate, VarDecl *FromVar,
06896       const TemplateArgumentList &TemplateArgList,
06897       const TemplateArgumentListInfo &TemplateArgsInfo,
06898       SmallVectorImpl<TemplateArgument> &Converted,
06899       SourceLocation PointOfInstantiation, void *InsertPos,
06900       LateInstantiatedAttrVec *LateAttrs = nullptr,
06901       LocalInstantiationScope *StartingScope = nullptr);
06902   VarTemplateSpecializationDecl *CompleteVarTemplateSpecializationDecl(
06903       VarTemplateSpecializationDecl *VarSpec, VarDecl *PatternDecl,
06904       const MultiLevelTemplateArgumentList &TemplateArgs);
06905   void
06906   BuildVariableInstantiation(VarDecl *NewVar, VarDecl *OldVar,
06907                              const MultiLevelTemplateArgumentList &TemplateArgs,
06908                              LateInstantiatedAttrVec *LateAttrs,
06909                              DeclContext *Owner,
06910                              LocalInstantiationScope *StartingScope,
06911                              bool InstantiatingVarTemplate = false);
06912   void InstantiateVariableInitializer(
06913       VarDecl *Var, VarDecl *OldVar,
06914       const MultiLevelTemplateArgumentList &TemplateArgs);
06915   void InstantiateVariableDefinition(SourceLocation PointOfInstantiation,
06916                                      VarDecl *Var, bool Recursive = false,
06917                                      bool DefinitionRequired = false);
06918   void InstantiateStaticDataMemberDefinition(
06919                                      SourceLocation PointOfInstantiation,
06920                                      VarDecl *Var,
06921                                      bool Recursive = false,
06922                                      bool DefinitionRequired = false);
06923 
06924   void InstantiateMemInitializers(CXXConstructorDecl *New,
06925                                   const CXXConstructorDecl *Tmpl,
06926                             const MultiLevelTemplateArgumentList &TemplateArgs);
06927 
06928   NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
06929                           const MultiLevelTemplateArgumentList &TemplateArgs);
06930   DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC,
06931                           const MultiLevelTemplateArgumentList &TemplateArgs);
06932 
06933   // Objective-C declarations.
06934   enum ObjCContainerKind {
06935     OCK_None = -1,
06936     OCK_Interface = 0,
06937     OCK_Protocol,
06938     OCK_Category,
06939     OCK_ClassExtension,
06940     OCK_Implementation,
06941     OCK_CategoryImplementation
06942   };
06943   ObjCContainerKind getObjCContainerKind() const;
06944 
06945   Decl *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
06946                                  IdentifierInfo *ClassName,
06947                                  SourceLocation ClassLoc,
06948                                  IdentifierInfo *SuperName,
06949                                  SourceLocation SuperLoc,
06950                                  Decl * const *ProtoRefs,
06951                                  unsigned NumProtoRefs,
06952                                  const SourceLocation *ProtoLocs,
06953                                  SourceLocation EndProtoLoc,
06954                                  AttributeList *AttrList);
06955   
06956   void ActOnTypedefedProtocols(SmallVectorImpl<Decl *> &ProtocolRefs,
06957                                IdentifierInfo *SuperName,
06958                                SourceLocation SuperLoc);
06959 
06960   Decl *ActOnCompatibilityAlias(
06961                     SourceLocation AtCompatibilityAliasLoc,
06962                     IdentifierInfo *AliasName,  SourceLocation AliasLocation,
06963                     IdentifierInfo *ClassName, SourceLocation ClassLocation);
06964 
06965   bool CheckForwardProtocolDeclarationForCircularDependency(
06966     IdentifierInfo *PName,
06967     SourceLocation &PLoc, SourceLocation PrevLoc,
06968     const ObjCList<ObjCProtocolDecl> &PList);
06969 
06970   Decl *ActOnStartProtocolInterface(
06971                     SourceLocation AtProtoInterfaceLoc,
06972                     IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
06973                     Decl * const *ProtoRefNames, unsigned NumProtoRefs,
06974                     const SourceLocation *ProtoLocs,
06975                     SourceLocation EndProtoLoc,
06976                     AttributeList *AttrList);
06977 
06978   Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
06979                                     IdentifierInfo *ClassName,
06980                                     SourceLocation ClassLoc,
06981                                     IdentifierInfo *CategoryName,
06982                                     SourceLocation CategoryLoc,
06983                                     Decl * const *ProtoRefs,
06984                                     unsigned NumProtoRefs,
06985                                     const SourceLocation *ProtoLocs,
06986                                     SourceLocation EndProtoLoc);
06987 
06988   Decl *ActOnStartClassImplementation(
06989                     SourceLocation AtClassImplLoc,
06990                     IdentifierInfo *ClassName, SourceLocation ClassLoc,
06991                     IdentifierInfo *SuperClassname,
06992                     SourceLocation SuperClassLoc);
06993 
06994   Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc,
06995                                          IdentifierInfo *ClassName,
06996                                          SourceLocation ClassLoc,
06997                                          IdentifierInfo *CatName,
06998                                          SourceLocation CatLoc);
06999 
07000   DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl,
07001                                                ArrayRef<Decl *> Decls);
07002 
07003   DeclGroupPtrTy ActOnForwardClassDeclaration(SourceLocation Loc,
07004                                      IdentifierInfo **IdentList,
07005                                      SourceLocation *IdentLocs,
07006                                      unsigned NumElts);
07007 
07008   DeclGroupPtrTy ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc,
07009                                         const IdentifierLocPair *IdentList,
07010                                         unsigned NumElts,
07011                                         AttributeList *attrList);
07012 
07013   void FindProtocolDeclaration(bool WarnOnDeclarations,
07014                                const IdentifierLocPair *ProtocolId,
07015                                unsigned NumProtocols,
07016                                SmallVectorImpl<Decl *> &Protocols);
07017 
07018   /// Ensure attributes are consistent with type.
07019   /// \param [in, out] Attributes The attributes to check; they will
07020   /// be modified to be consistent with \p PropertyTy.
07021   void CheckObjCPropertyAttributes(Decl *PropertyPtrTy,
07022                                    SourceLocation Loc,
07023                                    unsigned &Attributes,
07024                                    bool propertyInPrimaryClass);
07025 
07026   /// Process the specified property declaration and create decls for the
07027   /// setters and getters as needed.
07028   /// \param property The property declaration being processed
07029   /// \param CD The semantic container for the property
07030   /// \param redeclaredProperty Declaration for property if redeclared
07031   ///        in class extension.
07032   /// \param lexicalDC Container for redeclaredProperty.
07033   void ProcessPropertyDecl(ObjCPropertyDecl *property,
07034                            ObjCContainerDecl *CD,
07035                            ObjCPropertyDecl *redeclaredProperty = nullptr,
07036                            ObjCContainerDecl *lexicalDC = nullptr);
07037 
07038 
07039   void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
07040                                 ObjCPropertyDecl *SuperProperty,
07041                                 const IdentifierInfo *Name,
07042                                 bool OverridingProtocolProperty);
07043 
07044   void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
07045                                         ObjCInterfaceDecl *ID);
07046 
07047   Decl *ActOnAtEnd(Scope *S, SourceRange AtEnd,
07048                    ArrayRef<Decl *> allMethods = None,
07049                    ArrayRef<DeclGroupPtrTy> allTUVars = None);
07050 
07051   Decl *ActOnProperty(Scope *S, SourceLocation AtLoc,
07052                       SourceLocation LParenLoc,
07053                       FieldDeclarator &FD, ObjCDeclSpec &ODS,
07054                       Selector GetterSel, Selector SetterSel,
07055                       bool *OverridingProperty,
07056                       tok::ObjCKeywordKind MethodImplKind,
07057                       DeclContext *lexicalDC = nullptr);
07058 
07059   Decl *ActOnPropertyImplDecl(Scope *S,
07060                               SourceLocation AtLoc,
07061                               SourceLocation PropertyLoc,
07062                               bool ImplKind,
07063                               IdentifierInfo *PropertyId,
07064                               IdentifierInfo *PropertyIvar,
07065                               SourceLocation PropertyIvarLoc);
07066 
07067   enum ObjCSpecialMethodKind {
07068     OSMK_None,
07069     OSMK_Alloc,
07070     OSMK_New,
07071     OSMK_Copy,
07072     OSMK_RetainingInit,
07073     OSMK_NonRetainingInit
07074   };
07075 
07076   struct ObjCArgInfo {
07077     IdentifierInfo *Name;
07078     SourceLocation NameLoc;
07079     // The Type is null if no type was specified, and the DeclSpec is invalid
07080     // in this case.
07081     ParsedType Type;
07082     ObjCDeclSpec DeclSpec;
07083 
07084     /// ArgAttrs - Attribute list for this argument.
07085     AttributeList *ArgAttrs;
07086   };
07087 
07088   Decl *ActOnMethodDeclaration(
07089     Scope *S,
07090     SourceLocation BeginLoc, // location of the + or -.
07091     SourceLocation EndLoc,   // location of the ; or {.
07092     tok::TokenKind MethodType,
07093     ObjCDeclSpec &ReturnQT, ParsedType ReturnType,
07094     ArrayRef<SourceLocation> SelectorLocs, Selector Sel,
07095     // optional arguments. The number of types/arguments is obtained
07096     // from the Sel.getNumArgs().
07097     ObjCArgInfo *ArgInfo,
07098     DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args
07099     AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
07100     bool isVariadic, bool MethodDefinition);
07101 
07102   ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel,
07103                                               const ObjCObjectPointerType *OPT,
07104                                               bool IsInstance);
07105   ObjCMethodDecl *LookupMethodInObjectType(Selector Sel, QualType Ty,
07106                                            bool IsInstance);
07107 
07108   bool CheckARCMethodDecl(ObjCMethodDecl *method);
07109   bool inferObjCARCLifetime(ValueDecl *decl);
07110 
07111   ExprResult
07112   HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
07113                             Expr *BaseExpr,
07114                             SourceLocation OpLoc,
07115                             DeclarationName MemberName,
07116                             SourceLocation MemberLoc,
07117                             SourceLocation SuperLoc, QualType SuperType,
07118                             bool Super);
07119 
07120   ExprResult
07121   ActOnClassPropertyRefExpr(IdentifierInfo &receiverName,
07122                             IdentifierInfo &propertyName,
07123                             SourceLocation receiverNameLoc,
07124                             SourceLocation propertyNameLoc);
07125 
07126   ObjCMethodDecl *tryCaptureObjCSelf(SourceLocation Loc);
07127 
07128   /// \brief Describes the kind of message expression indicated by a message
07129   /// send that starts with an identifier.
07130   enum ObjCMessageKind {
07131     /// \brief The message is sent to 'super'.
07132     ObjCSuperMessage,
07133     /// \brief The message is an instance message.
07134     ObjCInstanceMessage,
07135     /// \brief The message is a class message, and the identifier is a type
07136     /// name.
07137     ObjCClassMessage
07138   };
07139 
07140   ObjCMessageKind getObjCMessageKind(Scope *S,
07141                                      IdentifierInfo *Name,
07142                                      SourceLocation NameLoc,
07143                                      bool IsSuper,
07144                                      bool HasTrailingDot,
07145                                      ParsedType &ReceiverType);
07146 
07147   ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc,
07148                                Selector Sel,
07149                                SourceLocation LBracLoc,
07150                                ArrayRef<SourceLocation> SelectorLocs,
07151                                SourceLocation RBracLoc,
07152                                MultiExprArg Args);
07153 
07154   ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo,
07155                                QualType ReceiverType,
07156                                SourceLocation SuperLoc,
07157                                Selector Sel,
07158                                ObjCMethodDecl *Method,
07159                                SourceLocation LBracLoc,
07160                                ArrayRef<SourceLocation> SelectorLocs,
07161                                SourceLocation RBracLoc,
07162                                MultiExprArg Args,
07163                                bool isImplicit = false);
07164 
07165   ExprResult BuildClassMessageImplicit(QualType ReceiverType,
07166                                        bool isSuperReceiver,
07167                                        SourceLocation Loc,
07168                                        Selector Sel,
07169                                        ObjCMethodDecl *Method,
07170                                        MultiExprArg Args);
07171 
07172   ExprResult ActOnClassMessage(Scope *S,
07173                                ParsedType Receiver,
07174                                Selector Sel,
07175                                SourceLocation LBracLoc,
07176                                ArrayRef<SourceLocation> SelectorLocs,
07177                                SourceLocation RBracLoc,
07178                                MultiExprArg Args);
07179 
07180   ExprResult BuildInstanceMessage(Expr *Receiver,
07181                                   QualType ReceiverType,
07182                                   SourceLocation SuperLoc,
07183                                   Selector Sel,
07184                                   ObjCMethodDecl *Method,
07185                                   SourceLocation LBracLoc,
07186                                   ArrayRef<SourceLocation> SelectorLocs,
07187                                   SourceLocation RBracLoc,
07188                                   MultiExprArg Args,
07189                                   bool isImplicit = false);
07190 
07191   ExprResult BuildInstanceMessageImplicit(Expr *Receiver,
07192                                           QualType ReceiverType,
07193                                           SourceLocation Loc,
07194                                           Selector Sel,
07195                                           ObjCMethodDecl *Method,
07196                                           MultiExprArg Args);
07197 
07198   ExprResult ActOnInstanceMessage(Scope *S,
07199                                   Expr *Receiver,
07200                                   Selector Sel,
07201                                   SourceLocation LBracLoc,
07202                                   ArrayRef<SourceLocation> SelectorLocs,
07203                                   SourceLocation RBracLoc,
07204                                   MultiExprArg Args);
07205 
07206   ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc,
07207                                   ObjCBridgeCastKind Kind,
07208                                   SourceLocation BridgeKeywordLoc,
07209                                   TypeSourceInfo *TSInfo,
07210                                   Expr *SubExpr);
07211 
07212   ExprResult ActOnObjCBridgedCast(Scope *S,
07213                                   SourceLocation LParenLoc,
07214                                   ObjCBridgeCastKind Kind,
07215                                   SourceLocation BridgeKeywordLoc,
07216                                   ParsedType Type,
07217                                   SourceLocation RParenLoc,
07218                                   Expr *SubExpr);
07219   
07220   void CheckTollFreeBridgeCast(QualType castType, Expr *castExpr);
07221   
07222   void CheckObjCBridgeRelatedCast(QualType castType, Expr *castExpr);
07223   
07224   bool CheckTollFreeBridgeStaticCast(QualType castType, Expr *castExpr,
07225                                      CastKind &Kind);
07226   
07227   bool checkObjCBridgeRelatedComponents(SourceLocation Loc,
07228                                         QualType DestType, QualType SrcType,
07229                                         ObjCInterfaceDecl *&RelatedClass,
07230                                         ObjCMethodDecl *&ClassMethod,
07231                                         ObjCMethodDecl *&InstanceMethod,
07232                                         TypedefNameDecl *&TDNDecl,
07233                                         bool CfToNs);
07234   
07235   bool CheckObjCBridgeRelatedConversions(SourceLocation Loc,
07236                                          QualType DestType, QualType SrcType,
07237                                          Expr *&SrcExpr);
07238   
07239   bool ConversionToObjCStringLiteralCheck(QualType DstType, Expr *&SrcExpr);
07240   
07241   bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall);
07242 
07243   /// \brief Check whether the given new method is a valid override of the
07244   /// given overridden method, and set any properties that should be inherited.
07245   void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod,
07246                                const ObjCMethodDecl *Overridden);
07247 
07248   /// \brief Describes the compatibility of a result type with its method.
07249   enum ResultTypeCompatibilityKind {
07250     RTC_Compatible,
07251     RTC_Incompatible,
07252     RTC_Unknown
07253   };
07254 
07255   void CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod,
07256                                 ObjCInterfaceDecl *CurrentClass,
07257                                 ResultTypeCompatibilityKind RTC);
07258 
07259   enum PragmaOptionsAlignKind {
07260     POAK_Native,  // #pragma options align=native
07261     POAK_Natural, // #pragma options align=natural
07262     POAK_Packed,  // #pragma options align=packed
07263     POAK_Power,   // #pragma options align=power
07264     POAK_Mac68k,  // #pragma options align=mac68k
07265     POAK_Reset    // #pragma options align=reset
07266   };
07267 
07268   /// ActOnPragmaOptionsAlign - Called on well formed \#pragma options align.
07269   void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
07270                                SourceLocation PragmaLoc);
07271 
07272   enum PragmaPackKind {
07273     PPK_Default, // #pragma pack([n])
07274     PPK_Show,    // #pragma pack(show), only supported by MSVC.
07275     PPK_Push,    // #pragma pack(push, [identifier], [n])
07276     PPK_Pop      // #pragma pack(pop, [identifier], [n])
07277   };
07278 
07279   enum PragmaMSStructKind {
07280     PMSST_OFF,  // #pragms ms_struct off
07281     PMSST_ON    // #pragms ms_struct on
07282   };
07283 
07284   enum PragmaMSCommentKind {
07285     PCK_Unknown,
07286     PCK_Linker,   // #pragma comment(linker, ...)
07287     PCK_Lib,      // #pragma comment(lib, ...)
07288     PCK_Compiler, // #pragma comment(compiler, ...)
07289     PCK_ExeStr,   // #pragma comment(exestr, ...)
07290     PCK_User      // #pragma comment(user, ...)
07291   };
07292 
07293   /// ActOnPragmaPack - Called on well formed \#pragma pack(...).
07294   void ActOnPragmaPack(PragmaPackKind Kind,
07295                        IdentifierInfo *Name,
07296                        Expr *Alignment,
07297                        SourceLocation PragmaLoc,
07298                        SourceLocation LParenLoc,
07299                        SourceLocation RParenLoc);
07300 
07301   /// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off].
07302   void ActOnPragmaMSStruct(PragmaMSStructKind Kind);
07303 
07304   /// ActOnPragmaMSComment - Called on well formed
07305   /// \#pragma comment(kind, "arg").
07306   void ActOnPragmaMSComment(PragmaMSCommentKind Kind, StringRef Arg);
07307 
07308   /// ActOnPragmaMSPointersToMembers - called on well formed \#pragma
07309   /// pointers_to_members(representation method[, general purpose
07310   /// representation]).
07311   void ActOnPragmaMSPointersToMembers(
07312       LangOptions::PragmaMSPointersToMembersKind Kind,
07313       SourceLocation PragmaLoc);
07314 
07315   /// \brief Called on well formed \#pragma vtordisp().
07316   void ActOnPragmaMSVtorDisp(PragmaVtorDispKind Kind, SourceLocation PragmaLoc,
07317                              MSVtorDispAttr::Mode Value);
07318 
07319   enum PragmaSectionKind {
07320     PSK_DataSeg,
07321     PSK_BSSSeg,
07322     PSK_ConstSeg,
07323     PSK_CodeSeg,
07324   };
07325 
07326   bool UnifySection(StringRef SectionName,
07327                     int SectionFlags,
07328                     DeclaratorDecl *TheDecl);
07329   bool UnifySection(StringRef SectionName,
07330                     int SectionFlags,
07331                     SourceLocation PragmaSectionLocation);
07332 
07333   /// \brief Called on well formed \#pragma bss_seg/data_seg/const_seg/code_seg.
07334   void ActOnPragmaMSSeg(SourceLocation PragmaLocation,
07335                         PragmaMsStackAction Action,
07336                         llvm::StringRef StackSlotLabel,
07337                         StringLiteral *SegmentName,
07338                         llvm::StringRef PragmaName);
07339 
07340   /// \brief Called on well formed \#pragma section().
07341   void ActOnPragmaMSSection(SourceLocation PragmaLocation,
07342                             int SectionFlags, StringLiteral *SegmentName);
07343 
07344   /// \brief Called on well-formed \#pragma init_seg().
07345   void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation,
07346                             StringLiteral *SegmentName);
07347 
07348   /// ActOnPragmaDetectMismatch - Call on well-formed \#pragma detect_mismatch
07349   void ActOnPragmaDetectMismatch(StringRef Name, StringRef Value);
07350 
07351   /// ActOnPragmaUnused - Called on well-formed '\#pragma unused'.
07352   void ActOnPragmaUnused(const Token &Identifier,
07353                          Scope *curScope,
07354                          SourceLocation PragmaLoc);
07355 
07356   /// ActOnPragmaVisibility - Called on well formed \#pragma GCC visibility... .
07357   void ActOnPragmaVisibility(const IdentifierInfo* VisType,
07358                              SourceLocation PragmaLoc);
07359 
07360   NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II,
07361                                  SourceLocation Loc);
07362   void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W);
07363 
07364   /// ActOnPragmaWeakID - Called on well formed \#pragma weak ident.
07365   void ActOnPragmaWeakID(IdentifierInfo* WeakName,
07366                          SourceLocation PragmaLoc,
07367                          SourceLocation WeakNameLoc);
07368 
07369   /// ActOnPragmaRedefineExtname - Called on well formed
07370   /// \#pragma redefine_extname oldname newname.
07371   void ActOnPragmaRedefineExtname(IdentifierInfo* WeakName,
07372                                   IdentifierInfo* AliasName,
07373                                   SourceLocation PragmaLoc,
07374                                   SourceLocation WeakNameLoc,
07375                                   SourceLocation AliasNameLoc);
07376 
07377   /// ActOnPragmaWeakAlias - Called on well formed \#pragma weak ident = ident.
07378   void ActOnPragmaWeakAlias(IdentifierInfo* WeakName,
07379                             IdentifierInfo* AliasName,
07380                             SourceLocation PragmaLoc,
07381                             SourceLocation WeakNameLoc,
07382                             SourceLocation AliasNameLoc);
07383 
07384   /// ActOnPragmaFPContract - Called on well formed
07385   /// \#pragma {STDC,OPENCL} FP_CONTRACT
07386   void ActOnPragmaFPContract(tok::OnOffSwitch OOS);
07387 
07388   /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to
07389   /// a the record decl, to handle '\#pragma pack' and '\#pragma options align'.
07390   void AddAlignmentAttributesForRecord(RecordDecl *RD);
07391 
07392   /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record.
07393   void AddMsStructLayoutForRecord(RecordDecl *RD);
07394 
07395   /// FreePackedContext - Deallocate and null out PackContext.
07396   void FreePackedContext();
07397 
07398   /// PushNamespaceVisibilityAttr - Note that we've entered a
07399   /// namespace with a visibility attribute.
07400   void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr,
07401                                    SourceLocation Loc);
07402 
07403   /// AddPushedVisibilityAttribute - If '\#pragma GCC visibility' was used,
07404   /// add an appropriate visibility attribute.
07405   void AddPushedVisibilityAttribute(Decl *RD);
07406 
07407   /// PopPragmaVisibility - Pop the top element of the visibility stack; used
07408   /// for '\#pragma GCC visibility' and visibility attributes on namespaces.
07409   void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc);
07410 
07411   /// FreeVisContext - Deallocate and null out VisContext.
07412   void FreeVisContext();
07413 
07414   /// AddCFAuditedAttribute - Check whether we're currently within
07415   /// '\#pragma clang arc_cf_code_audited' and, if so, consider adding
07416   /// the appropriate attribute.
07417   void AddCFAuditedAttribute(Decl *D);
07418 
07419   /// \brief Called on well formed \#pragma clang optimize.
07420   void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc);
07421 
07422   /// \brief Get the location for the currently active "\#pragma clang optimize
07423   /// off". If this location is invalid, then the state of the pragma is "on".
07424   SourceLocation getOptimizeOffPragmaLocation() const {
07425     return OptimizeOffPragmaLocation;
07426   }
07427 
07428   /// \brief Only called on function definitions; if there is a pragma in scope
07429   /// with the effect of a range-based optnone, consider marking the function
07430   /// with attribute optnone.
07431   void AddRangeBasedOptnone(FunctionDecl *FD);
07432 
07433   /// \brief Adds the 'optnone' attribute to the function declaration if there
07434   /// are no conflicts; Loc represents the location causing the 'optnone'
07435   /// attribute to be added (usually because of a pragma).
07436   void AddOptnoneAttributeIfNoConflicts(FunctionDecl *FD, SourceLocation Loc);
07437 
07438   /// AddAlignedAttr - Adds an aligned attribute to a particular declaration.
07439   void AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E,
07440                       unsigned SpellingListIndex, bool IsPackExpansion);
07441   void AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *T,
07442                       unsigned SpellingListIndex, bool IsPackExpansion);
07443 
07444   /// AddAssumeAlignedAttr - Adds an assume_aligned attribute to a particular
07445   /// declaration.
07446   void AddAssumeAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E, Expr *OE,
07447                             unsigned SpellingListIndex);
07448 
07449   /// AddAlignValueAttr - Adds an align_value attribute to a particular
07450   /// declaration.
07451   void AddAlignValueAttr(SourceRange AttrRange, Decl *D, Expr *E,
07452                          unsigned SpellingListIndex);
07453 
07454   // OpenMP directives and clauses.
07455 private:
07456   void *VarDataSharingAttributesStack;
07457   /// \brief Initialization of data-sharing attributes stack.
07458   void InitDataSharingAttributesStack();
07459   void DestroyDataSharingAttributesStack();
07460   ExprResult VerifyPositiveIntegerConstantInClause(Expr *Op,
07461                                                    OpenMPClauseKind CKind);
07462 public:
07463   ExprResult PerformOpenMPImplicitIntegerConversion(SourceLocation OpLoc,
07464                                                     Expr *Op);
07465   /// \brief Called on start of new data sharing attribute block.
07466   void StartOpenMPDSABlock(OpenMPDirectiveKind K,
07467                            const DeclarationNameInfo &DirName, Scope *CurScope,
07468                            SourceLocation Loc);
07469   /// \brief Called on end of data sharing attribute block.
07470   void EndOpenMPDSABlock(Stmt *CurDirective);
07471 
07472   // OpenMP directives and clauses.
07473   /// \brief Called on correct id-expression from the '#pragma omp
07474   /// threadprivate'.
07475   ExprResult ActOnOpenMPIdExpression(Scope *CurScope,
07476                                      CXXScopeSpec &ScopeSpec,
07477                                      const DeclarationNameInfo &Id);
07478   /// \brief Called on well-formed '#pragma omp threadprivate'.
07479   DeclGroupPtrTy ActOnOpenMPThreadprivateDirective(
07480                                      SourceLocation Loc,
07481                                      ArrayRef<Expr *> VarList);
07482   /// \brief Builds a new OpenMPThreadPrivateDecl and checks its correctness.
07483   OMPThreadPrivateDecl *CheckOMPThreadPrivateDecl(
07484                                      SourceLocation Loc,
07485                                      ArrayRef<Expr *> VarList);
07486 
07487   /// \brief Initialization of captured region for OpenMP region.
07488   void ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope);
07489   StmtResult ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind,
07490                                             const DeclarationNameInfo &DirName,
07491                                             ArrayRef<OMPClause *> Clauses,
07492                                             Stmt *AStmt,
07493                                             SourceLocation StartLoc,
07494                                             SourceLocation EndLoc);
07495   /// \brief Called on well-formed '\#pragma omp parallel' after parsing
07496   /// of the  associated statement.
07497   StmtResult ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses,
07498                                           Stmt *AStmt,
07499                                           SourceLocation StartLoc,
07500                                           SourceLocation EndLoc);
07501   /// \brief Called on well-formed '\#pragma omp simd' after parsing
07502   /// of the associated statement.
07503   StmtResult ActOnOpenMPSimdDirective(
07504       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
07505       SourceLocation EndLoc,
07506       llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA);
07507   /// \brief Called on well-formed '\#pragma omp for' after parsing
07508   /// of the associated statement.
07509   StmtResult ActOnOpenMPForDirective(
07510       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
07511       SourceLocation EndLoc,
07512       llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA);
07513   /// \brief Called on well-formed '\#pragma omp for simd' after parsing
07514   /// of the associated statement.
07515   StmtResult ActOnOpenMPForSimdDirective(
07516       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
07517       SourceLocation EndLoc,
07518       llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA);
07519   /// \brief Called on well-formed '\#pragma omp sections' after parsing
07520   /// of the associated statement.
07521   StmtResult ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses,
07522                                           Stmt *AStmt, SourceLocation StartLoc,
07523                                           SourceLocation EndLoc);
07524   /// \brief Called on well-formed '\#pragma omp section' after parsing of the
07525   /// associated statement.
07526   StmtResult ActOnOpenMPSectionDirective(Stmt *AStmt, SourceLocation StartLoc,
07527                                          SourceLocation EndLoc);
07528   /// \brief Called on well-formed '\#pragma omp single' after parsing of the
07529   /// associated statement.
07530   StmtResult ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses,
07531                                         Stmt *AStmt, SourceLocation StartLoc,
07532                                         SourceLocation EndLoc);
07533   /// \brief Called on well-formed '\#pragma omp master' after parsing of the
07534   /// associated statement.
07535   StmtResult ActOnOpenMPMasterDirective(Stmt *AStmt, SourceLocation StartLoc,
07536                                         SourceLocation EndLoc);
07537   /// \brief Called on well-formed '\#pragma omp critical' after parsing of the
07538   /// associated statement.
07539   StmtResult ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName,
07540                                           Stmt *AStmt, SourceLocation StartLoc,
07541                                           SourceLocation EndLoc);
07542   /// \brief Called on well-formed '\#pragma omp parallel for' after parsing
07543   /// of the  associated statement.
07544   StmtResult ActOnOpenMPParallelForDirective(
07545       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
07546       SourceLocation EndLoc,
07547       llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA);
07548   /// \brief Called on well-formed '\#pragma omp parallel for simd' after
07549   /// parsing of the  associated statement.
07550   StmtResult ActOnOpenMPParallelForSimdDirective(
07551       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
07552       SourceLocation EndLoc,
07553       llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA);
07554   /// \brief Called on well-formed '\#pragma omp parallel sections' after
07555   /// parsing of the  associated statement.
07556   StmtResult ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses,
07557                                                   Stmt *AStmt,
07558                                                   SourceLocation StartLoc,
07559                                                   SourceLocation EndLoc);
07560   /// \brief Called on well-formed '\#pragma omp task' after parsing of the
07561   /// associated statement.
07562   StmtResult ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses,
07563                                       Stmt *AStmt, SourceLocation StartLoc,
07564                                       SourceLocation EndLoc);
07565   /// \brief Called on well-formed '\#pragma omp taskyield'.
07566   StmtResult ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc,
07567                                            SourceLocation EndLoc);
07568   /// \brief Called on well-formed '\#pragma omp barrier'.
07569   StmtResult ActOnOpenMPBarrierDirective(SourceLocation StartLoc,
07570                                          SourceLocation EndLoc);
07571   /// \brief Called on well-formed '\#pragma omp taskwait'.
07572   StmtResult ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc,
07573                                           SourceLocation EndLoc);
07574   /// \brief Called on well-formed '\#pragma omp flush'.
07575   StmtResult ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses,
07576                                        SourceLocation StartLoc,
07577                                        SourceLocation EndLoc);
07578   /// \brief Called on well-formed '\#pragma omp ordered' after parsing of the
07579   /// associated statement.
07580   StmtResult ActOnOpenMPOrderedDirective(Stmt *AStmt, SourceLocation StartLoc,
07581                                          SourceLocation EndLoc);
07582   /// \brief Called on well-formed '\#pragma omp atomic' after parsing of the
07583   /// associated statement.
07584   StmtResult ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses,
07585                                         Stmt *AStmt, SourceLocation StartLoc,
07586                                         SourceLocation EndLoc);
07587   /// \brief Called on well-formed '\#pragma omp target' after parsing of the
07588   /// associated statement.
07589   StmtResult ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses,
07590                                         Stmt *AStmt, SourceLocation StartLoc,
07591                                         SourceLocation EndLoc);
07592   /// \brief Called on well-formed '\#pragma omp teams' after parsing of the
07593   /// associated statement.
07594   StmtResult ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses,
07595                                        Stmt *AStmt, SourceLocation StartLoc,
07596                                        SourceLocation EndLoc);
07597 
07598   OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind,
07599                                          Expr *Expr,
07600                                          SourceLocation StartLoc,
07601                                          SourceLocation LParenLoc,
07602                                          SourceLocation EndLoc);
07603   /// \brief Called on well-formed 'if' clause.
07604   OMPClause *ActOnOpenMPIfClause(Expr *Condition, SourceLocation StartLoc,
07605                                  SourceLocation LParenLoc,
07606                                  SourceLocation EndLoc);
07607   /// \brief Called on well-formed 'final' clause.
07608   OMPClause *ActOnOpenMPFinalClause(Expr *Condition, SourceLocation StartLoc,
07609                                     SourceLocation LParenLoc,
07610                                     SourceLocation EndLoc);
07611   /// \brief Called on well-formed 'num_threads' clause.
07612   OMPClause *ActOnOpenMPNumThreadsClause(Expr *NumThreads,
07613                                          SourceLocation StartLoc,
07614                                          SourceLocation LParenLoc,
07615                                          SourceLocation EndLoc);
07616   /// \brief Called on well-formed 'safelen' clause.
07617   OMPClause *ActOnOpenMPSafelenClause(Expr *Length,
07618                                       SourceLocation StartLoc,
07619                                       SourceLocation LParenLoc,
07620                                       SourceLocation EndLoc);
07621   /// \brief Called on well-formed 'collapse' clause.
07622   OMPClause *ActOnOpenMPCollapseClause(Expr *NumForLoops,
07623                                        SourceLocation StartLoc,
07624                                        SourceLocation LParenLoc,
07625                                        SourceLocation EndLoc);
07626 
07627   OMPClause *ActOnOpenMPSimpleClause(OpenMPClauseKind Kind,
07628                                      unsigned Argument,
07629                                      SourceLocation ArgumentLoc,
07630                                      SourceLocation StartLoc,
07631                                      SourceLocation LParenLoc,
07632                                      SourceLocation EndLoc);
07633   /// \brief Called on well-formed 'default' clause.
07634   OMPClause *ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind,
07635                                       SourceLocation KindLoc,
07636                                       SourceLocation StartLoc,
07637                                       SourceLocation LParenLoc,
07638                                       SourceLocation EndLoc);
07639   /// \brief Called on well-formed 'proc_bind' clause.
07640   OMPClause *ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind,
07641                                        SourceLocation KindLoc,
07642                                        SourceLocation StartLoc,
07643                                        SourceLocation LParenLoc,
07644                                        SourceLocation EndLoc);
07645 
07646   OMPClause *ActOnOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind,
07647                                                 unsigned Argument, Expr *Expr,
07648                                                 SourceLocation StartLoc,
07649                                                 SourceLocation LParenLoc,
07650                                                 SourceLocation ArgumentLoc,
07651                                                 SourceLocation CommaLoc,
07652                                                 SourceLocation EndLoc);
07653   /// \brief Called on well-formed 'schedule' clause.
07654   OMPClause *ActOnOpenMPScheduleClause(OpenMPScheduleClauseKind Kind,
07655                                        Expr *ChunkSize, SourceLocation StartLoc,
07656                                        SourceLocation LParenLoc,
07657                                        SourceLocation KindLoc,
07658                                        SourceLocation CommaLoc,
07659                                        SourceLocation EndLoc);
07660 
07661   OMPClause *ActOnOpenMPClause(OpenMPClauseKind Kind, SourceLocation StartLoc,
07662                                SourceLocation EndLoc);
07663   /// \brief Called on well-formed 'ordered' clause.
07664   OMPClause *ActOnOpenMPOrderedClause(SourceLocation StartLoc,
07665                                       SourceLocation EndLoc);
07666   /// \brief Called on well-formed 'nowait' clause.
07667   OMPClause *ActOnOpenMPNowaitClause(SourceLocation StartLoc,
07668                                      SourceLocation EndLoc);
07669   /// \brief Called on well-formed 'untied' clause.
07670   OMPClause *ActOnOpenMPUntiedClause(SourceLocation StartLoc,
07671                                      SourceLocation EndLoc);
07672   /// \brief Called on well-formed 'mergeable' clause.
07673   OMPClause *ActOnOpenMPMergeableClause(SourceLocation StartLoc,
07674                                         SourceLocation EndLoc);
07675   /// \brief Called on well-formed 'read' clause.
07676   OMPClause *ActOnOpenMPReadClause(SourceLocation StartLoc,
07677                                    SourceLocation EndLoc);
07678   /// \brief Called on well-formed 'write' clause.
07679   OMPClause *ActOnOpenMPWriteClause(SourceLocation StartLoc,
07680                                     SourceLocation EndLoc);
07681   /// \brief Called on well-formed 'update' clause.
07682   OMPClause *ActOnOpenMPUpdateClause(SourceLocation StartLoc,
07683                                      SourceLocation EndLoc);
07684   /// \brief Called on well-formed 'capture' clause.
07685   OMPClause *ActOnOpenMPCaptureClause(SourceLocation StartLoc,
07686                                       SourceLocation EndLoc);
07687   /// \brief Called on well-formed 'seq_cst' clause.
07688   OMPClause *ActOnOpenMPSeqCstClause(SourceLocation StartLoc,
07689                                      SourceLocation EndLoc);
07690 
07691   OMPClause *
07692   ActOnOpenMPVarListClause(OpenMPClauseKind Kind, ArrayRef<Expr *> Vars,
07693                            Expr *TailExpr, SourceLocation StartLoc,
07694                            SourceLocation LParenLoc, SourceLocation ColonLoc,
07695                            SourceLocation EndLoc,
07696                            CXXScopeSpec &ReductionIdScopeSpec,
07697                            const DeclarationNameInfo &ReductionId);
07698   /// \brief Called on well-formed 'private' clause.
07699   OMPClause *ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList,
07700                                       SourceLocation StartLoc,
07701                                       SourceLocation LParenLoc,
07702                                       SourceLocation EndLoc);
07703   /// \brief Called on well-formed 'firstprivate' clause.
07704   OMPClause *ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList,
07705                                            SourceLocation StartLoc,
07706                                            SourceLocation LParenLoc,
07707                                            SourceLocation EndLoc);
07708   /// \brief Called on well-formed 'lastprivate' clause.
07709   OMPClause *ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList,
07710                                           SourceLocation StartLoc,
07711                                           SourceLocation LParenLoc,
07712                                           SourceLocation EndLoc);
07713   /// \brief Called on well-formed 'shared' clause.
07714   OMPClause *ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList,
07715                                      SourceLocation StartLoc,
07716                                      SourceLocation LParenLoc,
07717                                      SourceLocation EndLoc);
07718   /// \brief Called on well-formed 'reduction' clause.
07719   OMPClause *
07720   ActOnOpenMPReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc,
07721                              SourceLocation LParenLoc, SourceLocation ColonLoc,
07722                              SourceLocation EndLoc,
07723                              CXXScopeSpec &ReductionIdScopeSpec,
07724                              const DeclarationNameInfo &ReductionId);
07725   /// \brief Called on well-formed 'linear' clause.
07726   OMPClause *ActOnOpenMPLinearClause(ArrayRef<Expr *> VarList,
07727                                      Expr *Step,
07728                                      SourceLocation StartLoc,
07729                                      SourceLocation LParenLoc,
07730                                      SourceLocation ColonLoc,
07731                                      SourceLocation EndLoc);
07732   /// \brief Called on well-formed 'aligned' clause.
07733   OMPClause *ActOnOpenMPAlignedClause(ArrayRef<Expr *> VarList,
07734                                       Expr *Alignment,
07735                                       SourceLocation StartLoc,
07736                                       SourceLocation LParenLoc,
07737                                       SourceLocation ColonLoc,
07738                                       SourceLocation EndLoc);
07739   /// \brief Called on well-formed 'copyin' clause.
07740   OMPClause *ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList,
07741                                      SourceLocation StartLoc,
07742                                      SourceLocation LParenLoc,
07743                                      SourceLocation EndLoc);
07744   /// \brief Called on well-formed 'copyprivate' clause.
07745   OMPClause *ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList,
07746                                           SourceLocation StartLoc,
07747                                           SourceLocation LParenLoc,
07748                                           SourceLocation EndLoc);
07749   /// \brief Called on well-formed 'flush' pseudo clause.
07750   OMPClause *ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList,
07751                                     SourceLocation StartLoc,
07752                                     SourceLocation LParenLoc,
07753                                     SourceLocation EndLoc);
07754 
07755   /// \brief The kind of conversion being performed.
07756   enum CheckedConversionKind {
07757     /// \brief An implicit conversion.
07758     CCK_ImplicitConversion,
07759     /// \brief A C-style cast.
07760     CCK_CStyleCast,
07761     /// \brief A functional-style cast.
07762     CCK_FunctionalCast,
07763     /// \brief A cast other than a C-style cast.
07764     CCK_OtherCast
07765   };
07766 
07767   /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
07768   /// cast.  If there is already an implicit cast, merge into the existing one.
07769   /// If isLvalue, the result of the cast is an lvalue.
07770   ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK,
07771                                ExprValueKind VK = VK_RValue,
07772                                const CXXCastPath *BasePath = nullptr,
07773                                CheckedConversionKind CCK
07774                                   = CCK_ImplicitConversion);
07775 
07776   /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding
07777   /// to the conversion from scalar type ScalarTy to the Boolean type.
07778   static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy);
07779 
07780   /// IgnoredValueConversions - Given that an expression's result is
07781   /// syntactically ignored, perform any conversions that are
07782   /// required.
07783   ExprResult IgnoredValueConversions(Expr *E);
07784 
07785   // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
07786   // functions and arrays to their respective pointers (C99 6.3.2.1).
07787   ExprResult UsualUnaryConversions(Expr *E);
07788 
07789   /// CallExprUnaryConversions - a special case of an unary conversion
07790   /// performed on a function designator of a call expression.
07791   ExprResult CallExprUnaryConversions(Expr *E);
07792 
07793   // DefaultFunctionArrayConversion - converts functions and arrays
07794   // to their respective pointers (C99 6.3.2.1).
07795   ExprResult DefaultFunctionArrayConversion(Expr *E);
07796 
07797   // DefaultFunctionArrayLvalueConversion - converts functions and
07798   // arrays to their respective pointers and performs the
07799   // lvalue-to-rvalue conversion.
07800   ExprResult DefaultFunctionArrayLvalueConversion(Expr *E);
07801 
07802   // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on
07803   // the operand.  This is DefaultFunctionArrayLvalueConversion,
07804   // except that it assumes the operand isn't of function or array
07805   // type.
07806   ExprResult DefaultLvalueConversion(Expr *E);
07807 
07808   // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
07809   // do not have a prototype. Integer promotions are performed on each
07810   // argument, and arguments that have type float are promoted to double.
07811   ExprResult DefaultArgumentPromotion(Expr *E);
07812 
07813   // Used for emitting the right warning by DefaultVariadicArgumentPromotion
07814   enum VariadicCallType {
07815     VariadicFunction,
07816     VariadicBlock,
07817     VariadicMethod,
07818     VariadicConstructor,
07819     VariadicDoesNotApply
07820   };
07821 
07822   VariadicCallType getVariadicCallType(FunctionDecl *FDecl,
07823                                        const FunctionProtoType *Proto,
07824                                        Expr *Fn);
07825 
07826   // Used for determining in which context a type is allowed to be passed to a
07827   // vararg function.
07828   enum VarArgKind {
07829     VAK_Valid,
07830     VAK_ValidInCXX11,
07831     VAK_Undefined,
07832     VAK_MSVCUndefined,
07833     VAK_Invalid
07834   };
07835 
07836   // Determines which VarArgKind fits an expression.
07837   VarArgKind isValidVarArgType(const QualType &Ty);
07838 
07839   /// Check to see if the given expression is a valid argument to a variadic
07840   /// function, issuing a diagnostic if not.
07841   void checkVariadicArgument(const Expr *E, VariadicCallType CT);
07842 
07843   /// Check to see if a given expression could have '.c_str()' called on it.
07844   bool hasCStrMethod(const Expr *E);
07845 
07846   /// GatherArgumentsForCall - Collector argument expressions for various
07847   /// form of call prototypes.
07848   bool GatherArgumentsForCall(SourceLocation CallLoc, FunctionDecl *FDecl,
07849                               const FunctionProtoType *Proto,
07850                               unsigned FirstParam, ArrayRef<Expr *> Args,
07851                               SmallVectorImpl<Expr *> &AllArgs,
07852                               VariadicCallType CallType = VariadicDoesNotApply,
07853                               bool AllowExplicit = false,
07854                               bool IsListInitialization = false);
07855 
07856   // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
07857   // will create a runtime trap if the resulting type is not a POD type.
07858   ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT,
07859                                               FunctionDecl *FDecl);
07860 
07861   // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
07862   // operands and then handles various conversions that are common to binary
07863   // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
07864   // routine returns the first non-arithmetic type found. The client is
07865   // responsible for emitting appropriate error diagnostics.
07866   QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS,
07867                                       bool IsCompAssign = false);
07868 
07869   /// AssignConvertType - All of the 'assignment' semantic checks return this
07870   /// enum to indicate whether the assignment was allowed.  These checks are
07871   /// done for simple assignments, as well as initialization, return from
07872   /// function, argument passing, etc.  The query is phrased in terms of a
07873   /// source and destination type.
07874   enum AssignConvertType {
07875     /// Compatible - the types are compatible according to the standard.
07876     Compatible,
07877 
07878     /// PointerToInt - The assignment converts a pointer to an int, which we
07879     /// accept as an extension.
07880     PointerToInt,
07881 
07882     /// IntToPointer - The assignment converts an int to a pointer, which we
07883     /// accept as an extension.
07884     IntToPointer,
07885 
07886     /// FunctionVoidPointer - The assignment is between a function pointer and
07887     /// void*, which the standard doesn't allow, but we accept as an extension.
07888     FunctionVoidPointer,
07889 
07890     /// IncompatiblePointer - The assignment is between two pointers types that
07891     /// are not compatible, but we accept them as an extension.
07892     IncompatiblePointer,
07893 
07894     /// IncompatiblePointer - The assignment is between two pointers types which
07895     /// point to integers which have a different sign, but are otherwise
07896     /// identical. This is a subset of the above, but broken out because it's by
07897     /// far the most common case of incompatible pointers.
07898     IncompatiblePointerSign,
07899 
07900     /// CompatiblePointerDiscardsQualifiers - The assignment discards
07901     /// c/v/r qualifiers, which we accept as an extension.
07902     CompatiblePointerDiscardsQualifiers,
07903 
07904     /// IncompatiblePointerDiscardsQualifiers - The assignment
07905     /// discards qualifiers that we don't permit to be discarded,
07906     /// like address spaces.
07907     IncompatiblePointerDiscardsQualifiers,
07908 
07909     /// IncompatibleNestedPointerQualifiers - The assignment is between two
07910     /// nested pointer types, and the qualifiers other than the first two
07911     /// levels differ e.g. char ** -> const char **, but we accept them as an
07912     /// extension.
07913     IncompatibleNestedPointerQualifiers,
07914 
07915     /// IncompatibleVectors - The assignment is between two vector types that
07916     /// have the same size, which we accept as an extension.
07917     IncompatibleVectors,
07918 
07919     /// IntToBlockPointer - The assignment converts an int to a block
07920     /// pointer. We disallow this.
07921     IntToBlockPointer,
07922 
07923     /// IncompatibleBlockPointer - The assignment is between two block
07924     /// pointers types that are not compatible.
07925     IncompatibleBlockPointer,
07926 
07927     /// IncompatibleObjCQualifiedId - The assignment is between a qualified
07928     /// id type and something else (that is incompatible with it). For example,
07929     /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
07930     IncompatibleObjCQualifiedId,
07931 
07932     /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an
07933     /// object with __weak qualifier.
07934     IncompatibleObjCWeakRef,
07935 
07936     /// Incompatible - We reject this conversion outright, it is invalid to
07937     /// represent it in the AST.
07938     Incompatible
07939   };
07940 
07941   /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
07942   /// assignment conversion type specified by ConvTy.  This returns true if the
07943   /// conversion was invalid or false if the conversion was accepted.
07944   bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
07945                                 SourceLocation Loc,
07946                                 QualType DstType, QualType SrcType,
07947                                 Expr *SrcExpr, AssignmentAction Action,
07948                                 bool *Complained = nullptr);
07949 
07950   /// DiagnoseAssignmentEnum - Warn if assignment to enum is a constant
07951   /// integer not in the range of enum values.
07952   void DiagnoseAssignmentEnum(QualType DstType, QualType SrcType,
07953                               Expr *SrcExpr);
07954 
07955   /// CheckAssignmentConstraints - Perform type checking for assignment,
07956   /// argument passing, variable initialization, and function return values.
07957   /// C99 6.5.16.
07958   AssignConvertType CheckAssignmentConstraints(SourceLocation Loc,
07959                                                QualType LHSType,
07960                                                QualType RHSType);
07961 
07962   /// Check assignment constraints and prepare for a conversion of the
07963   /// RHS to the LHS type.
07964   AssignConvertType CheckAssignmentConstraints(QualType LHSType,
07965                                                ExprResult &RHS,
07966                                                CastKind &Kind);
07967 
07968   // CheckSingleAssignmentConstraints - Currently used by
07969   // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
07970   // this routine performs the default function/array converions.
07971   AssignConvertType CheckSingleAssignmentConstraints(QualType LHSType,
07972                                                      ExprResult &RHS,
07973                                                      bool Diagnose = true,
07974                                                      bool DiagnoseCFAudited = false);
07975 
07976   // \brief If the lhs type is a transparent union, check whether we
07977   // can initialize the transparent union with the given expression.
07978   AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType,
07979                                                              ExprResult &RHS);
07980 
07981   bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
07982 
07983   bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType);
07984 
07985   ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
07986                                        AssignmentAction Action,
07987                                        bool AllowExplicit = false);
07988   ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
07989                                        AssignmentAction Action,
07990                                        bool AllowExplicit,
07991                                        ImplicitConversionSequence& ICS);
07992   ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
07993                                        const ImplicitConversionSequence& ICS,
07994                                        AssignmentAction Action,
07995                                        CheckedConversionKind CCK
07996                                           = CCK_ImplicitConversion);
07997   ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
07998                                        const StandardConversionSequence& SCS,
07999                                        AssignmentAction Action,
08000                                        CheckedConversionKind CCK);
08001 
08002   /// the following "Check" methods will return a valid/converted QualType
08003   /// or a null QualType (indicating an error diagnostic was issued).
08004 
08005   /// type checking binary operators (subroutines of CreateBuiltinBinOp).
08006   QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS,
08007                            ExprResult &RHS);
08008   QualType CheckPointerToMemberOperands( // C++ 5.5
08009     ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK,
08010     SourceLocation OpLoc, bool isIndirect);
08011   QualType CheckMultiplyDivideOperands( // C99 6.5.5
08012     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign,
08013     bool IsDivide);
08014   QualType CheckRemainderOperands( // C99 6.5.5
08015     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
08016     bool IsCompAssign = false);
08017   QualType CheckAdditionOperands( // C99 6.5.6
08018     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc,
08019     QualType* CompLHSTy = nullptr);
08020   QualType CheckSubtractionOperands( // C99 6.5.6
08021     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
08022     QualType* CompLHSTy = nullptr);
08023   QualType CheckShiftOperands( // C99 6.5.7
08024     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc,
08025     bool IsCompAssign = false);
08026   QualType CheckCompareOperands( // C99 6.5.8/9
08027     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned OpaqueOpc,
08028                                 bool isRelational);
08029   QualType CheckBitwiseOperands( // C99 6.5.[10...12]
08030     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
08031     bool IsCompAssign = false);
08032   QualType CheckLogicalOperands( // C99 6.5.[13,14]
08033     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc);
08034   // CheckAssignmentOperands is used for both simple and compound assignment.
08035   // For simple assignment, pass both expressions and a null converted type.
08036   // For compound assignment, pass both expressions and the converted type.
08037   QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
08038     Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType);
08039 
08040   ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc,
08041                                      UnaryOperatorKind Opcode, Expr *Op);
08042   ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc,
08043                                          BinaryOperatorKind Opcode,
08044                                          Expr *LHS, Expr *RHS);
08045   ExprResult checkPseudoObjectRValue(Expr *E);
08046   Expr *recreateSyntacticForm(PseudoObjectExpr *E);
08047 
08048   QualType CheckConditionalOperands( // C99 6.5.15
08049     ExprResult &Cond, ExprResult &LHS, ExprResult &RHS,
08050     ExprValueKind &VK, ExprObjectKind &OK, SourceLocation QuestionLoc);
08051   QualType CXXCheckConditionalOperands( // C++ 5.16
08052     ExprResult &cond, ExprResult &lhs, ExprResult &rhs,
08053     ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc);
08054   QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2,
08055                                     bool *NonStandardCompositeType = nullptr);
08056   QualType FindCompositePointerType(SourceLocation Loc,
08057                                     ExprResult &E1, ExprResult &E2,
08058                                     bool *NonStandardCompositeType = nullptr) {
08059     Expr *E1Tmp = E1.get(), *E2Tmp = E2.get();
08060     QualType Composite = FindCompositePointerType(Loc, E1Tmp, E2Tmp,
08061                                                   NonStandardCompositeType);
08062     E1 = E1Tmp;
08063     E2 = E2Tmp;
08064     return Composite;
08065   }
08066 
08067   QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS,
08068                                         SourceLocation QuestionLoc);
08069 
08070   bool DiagnoseConditionalForNull(Expr *LHSExpr, Expr *RHSExpr,
08071                                   SourceLocation QuestionLoc);
08072 
08073   void DiagnoseAlwaysNonNullPointer(Expr *E,
08074                                     Expr::NullPointerConstantKind NullType,
08075                                     bool IsEqual, SourceRange Range);
08076 
08077   /// type checking for vector binary operators.
08078   QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS,
08079                                SourceLocation Loc, bool IsCompAssign);
08080   QualType GetSignedVectorType(QualType V);
08081   QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS,
08082                                       SourceLocation Loc, bool isRelational);
08083   QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS,
08084                                       SourceLocation Loc);
08085 
08086   bool isLaxVectorConversion(QualType srcType, QualType destType);
08087 
08088   /// type checking declaration initializers (C99 6.7.8)
08089   bool CheckForConstantInitializer(Expr *e, QualType t);
08090 
08091   // type checking C++ declaration initializers (C++ [dcl.init]).
08092 
08093   /// ReferenceCompareResult - Expresses the result of comparing two
08094   /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
08095   /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
08096   enum ReferenceCompareResult {
08097     /// Ref_Incompatible - The two types are incompatible, so direct
08098     /// reference binding is not possible.
08099     Ref_Incompatible = 0,
08100     /// Ref_Related - The two types are reference-related, which means
08101     /// that their unqualified forms (T1 and T2) are either the same
08102     /// or T1 is a base class of T2.
08103     Ref_Related,
08104     /// Ref_Compatible_With_Added_Qualification - The two types are
08105     /// reference-compatible with added qualification, meaning that
08106     /// they are reference-compatible and the qualifiers on T1 (cv1)
08107     /// are greater than the qualifiers on T2 (cv2).
08108     Ref_Compatible_With_Added_Qualification,
08109     /// Ref_Compatible - The two types are reference-compatible and
08110     /// have equivalent qualifiers (cv1 == cv2).
08111     Ref_Compatible
08112   };
08113 
08114   ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc,
08115                                                       QualType T1, QualType T2,
08116                                                       bool &DerivedToBase,
08117                                                       bool &ObjCConversion,
08118                                                 bool &ObjCLifetimeConversion);
08119 
08120   ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType,
08121                                  Expr *CastExpr, CastKind &CastKind,
08122                                  ExprValueKind &VK, CXXCastPath &Path);
08123 
08124   /// \brief Force an expression with unknown-type to an expression of the
08125   /// given type.
08126   ExprResult forceUnknownAnyToType(Expr *E, QualType ToType);
08127 
08128   /// \brief Type-check an expression that's being passed to an
08129   /// __unknown_anytype parameter.
08130   ExprResult checkUnknownAnyArg(SourceLocation callLoc,
08131                                 Expr *result, QualType &paramType);
08132 
08133   // CheckVectorCast - check type constraints for vectors.
08134   // Since vectors are an extension, there are no C standard reference for this.
08135   // We allow casting between vectors and integer datatypes of the same size.
08136   // returns true if the cast is invalid
08137   bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty,
08138                        CastKind &Kind);
08139 
08140   // CheckExtVectorCast - check type constraints for extended vectors.
08141   // Since vectors are an extension, there are no C standard reference for this.
08142   // We allow casting between vectors and integer datatypes of the same size,
08143   // or vectors and the element type of that vector.
08144   // returns the cast expr
08145   ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr,
08146                                 CastKind &Kind);
08147 
08148   ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
08149                                         SourceLocation LParenLoc,
08150                                         Expr *CastExpr,
08151                                         SourceLocation RParenLoc);
08152 
08153   enum ARCConversionResult { ACR_okay, ACR_unbridged };
08154 
08155   /// \brief Checks for invalid conversions and casts between
08156   /// retainable pointers and other pointer kinds.
08157   ARCConversionResult CheckObjCARCConversion(SourceRange castRange,
08158                                              QualType castType, Expr *&op,
08159                                              CheckedConversionKind CCK,
08160                                              bool DiagnoseCFAudited = false,
08161                                              BinaryOperatorKind Opc = BO_PtrMemD
08162                                              );
08163 
08164   Expr *stripARCUnbridgedCast(Expr *e);
08165   void diagnoseARCUnbridgedCast(Expr *e);
08166 
08167   bool CheckObjCARCUnavailableWeakConversion(QualType castType,
08168                                              QualType ExprType);
08169 
08170   /// checkRetainCycles - Check whether an Objective-C message send
08171   /// might create an obvious retain cycle.
08172   void checkRetainCycles(ObjCMessageExpr *msg);
08173   void checkRetainCycles(Expr *receiver, Expr *argument);
08174   void checkRetainCycles(VarDecl *Var, Expr *Init);
08175 
08176   /// checkUnsafeAssigns - Check whether +1 expr is being assigned
08177   /// to weak/__unsafe_unretained type.
08178   bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS);
08179 
08180   /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned
08181   /// to weak/__unsafe_unretained expression.
08182   void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS);
08183 
08184   /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
08185   /// \param Method - May be null.
08186   /// \param [out] ReturnType - The return type of the send.
08187   /// \return true iff there were any incompatible types.
08188   bool CheckMessageArgumentTypes(QualType ReceiverType,
08189                                  MultiExprArg Args, Selector Sel,
08190                                  ArrayRef<SourceLocation> SelectorLocs,
08191                                  ObjCMethodDecl *Method, bool isClassMessage,
08192                                  bool isSuperMessage,
08193                                  SourceLocation lbrac, SourceLocation rbrac,
08194                                  SourceRange RecRange,
08195                                  QualType &ReturnType, ExprValueKind &VK);
08196 
08197   /// \brief Determine the result of a message send expression based on
08198   /// the type of the receiver, the method expected to receive the message,
08199   /// and the form of the message send.
08200   QualType getMessageSendResultType(QualType ReceiverType,
08201                                     ObjCMethodDecl *Method,
08202                                     bool isClassMessage, bool isSuperMessage);
08203 
08204   /// \brief If the given expression involves a message send to a method
08205   /// with a related result type, emit a note describing what happened.
08206   void EmitRelatedResultTypeNote(const Expr *E);
08207 
08208   /// \brief Given that we had incompatible pointer types in a return
08209   /// statement, check whether we're in a method with a related result
08210   /// type, and if so, emit a note describing what happened.
08211   void EmitRelatedResultTypeNoteForReturn(QualType destType);
08212 
08213   /// CheckBooleanCondition - Diagnose problems involving the use of
08214   /// the given expression as a boolean condition (e.g. in an if
08215   /// statement).  Also performs the standard function and array
08216   /// decays, possibly changing the input variable.
08217   ///
08218   /// \param Loc - A location associated with the condition, e.g. the
08219   /// 'if' keyword.
08220   /// \return true iff there were any errors
08221   ExprResult CheckBooleanCondition(Expr *E, SourceLocation Loc);
08222 
08223   ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc,
08224                                    Expr *SubExpr);
08225 
08226   /// DiagnoseAssignmentAsCondition - Given that an expression is
08227   /// being used as a boolean condition, warn if it's an assignment.
08228   void DiagnoseAssignmentAsCondition(Expr *E);
08229 
08230   /// \brief Redundant parentheses over an equality comparison can indicate
08231   /// that the user intended an assignment used as condition.
08232   void DiagnoseEqualityWithExtraParens(ParenExpr *ParenE);
08233 
08234   /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
08235   ExprResult CheckCXXBooleanCondition(Expr *CondExpr);
08236 
08237   /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
08238   /// the specified width and sign.  If an overflow occurs, detect it and emit
08239   /// the specified diagnostic.
08240   void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
08241                                           unsigned NewWidth, bool NewSign,
08242                                           SourceLocation Loc, unsigned DiagID);
08243 
08244   /// Checks that the Objective-C declaration is declared in the global scope.
08245   /// Emits an error and marks the declaration as invalid if it's not declared
08246   /// in the global scope.
08247   bool CheckObjCDeclScope(Decl *D);
08248 
08249   /// \brief Abstract base class used for diagnosing integer constant
08250   /// expression violations.
08251   class VerifyICEDiagnoser {
08252   public:
08253     bool Suppress;
08254 
08255     VerifyICEDiagnoser(bool Suppress = false) : Suppress(Suppress) { }
08256 
08257     virtual void diagnoseNotICE(Sema &S, SourceLocation Loc, SourceRange SR) =0;
08258     virtual void diagnoseFold(Sema &S, SourceLocation Loc, SourceRange SR);
08259     virtual ~VerifyICEDiagnoser() { }
08260   };
08261 
08262   /// VerifyIntegerConstantExpression - Verifies that an expression is an ICE,
08263   /// and reports the appropriate diagnostics. Returns false on success.
08264   /// Can optionally return the value of the expression.
08265   ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
08266                                              VerifyICEDiagnoser &Diagnoser,
08267                                              bool AllowFold = true);
08268   ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
08269                                              unsigned DiagID,
08270                                              bool AllowFold = true);
08271   ExprResult VerifyIntegerConstantExpression(Expr *E,
08272                                              llvm::APSInt *Result = nullptr);
08273 
08274   /// VerifyBitField - verifies that a bit field expression is an ICE and has
08275   /// the correct width, and that the field type is valid.
08276   /// Returns false on success.
08277   /// Can optionally return whether the bit-field is of width 0
08278   ExprResult VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
08279                             QualType FieldTy, bool IsMsStruct,
08280                             Expr *BitWidth, bool *ZeroWidth = nullptr);
08281 
08282   enum CUDAFunctionTarget {
08283     CFT_Device,
08284     CFT_Global,
08285     CFT_Host,
08286     CFT_HostDevice,
08287     CFT_InvalidTarget
08288   };
08289 
08290   CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D);
08291 
08292   bool CheckCUDATarget(CUDAFunctionTarget CallerTarget,
08293                        CUDAFunctionTarget CalleeTarget);
08294 
08295   bool CheckCUDATarget(const FunctionDecl *Caller, const FunctionDecl *Callee);
08296 
08297   /// Given a implicit special member, infer its CUDA target from the
08298   /// calls it needs to make to underlying base/field special members.
08299   /// \param ClassDecl the class for which the member is being created.
08300   /// \param CSM the kind of special member.
08301   /// \param MemberDecl the special member itself.
08302   /// \param ConstRHS true if this is a copy operation with a const object on
08303   ///        its RHS.
08304   /// \param Diagnose true if this call should emit diagnostics.
08305   /// \return true if there was an error inferring.
08306   /// The result of this call is implicit CUDA target attribute(s) attached to
08307   /// the member declaration.
08308   bool inferCUDATargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl,
08309                                                CXXSpecialMember CSM,
08310                                                CXXMethodDecl *MemberDecl,
08311                                                bool ConstRHS,
08312                                                bool Diagnose);
08313 
08314   /// \name Code completion
08315   //@{
08316   /// \brief Describes the context in which code completion occurs.
08317   enum ParserCompletionContext {
08318     /// \brief Code completion occurs at top-level or namespace context.
08319     PCC_Namespace,
08320     /// \brief Code completion occurs within a class, struct, or union.
08321     PCC_Class,
08322     /// \brief Code completion occurs within an Objective-C interface, protocol,
08323     /// or category.
08324     PCC_ObjCInterface,
08325     /// \brief Code completion occurs within an Objective-C implementation or
08326     /// category implementation
08327     PCC_ObjCImplementation,
08328     /// \brief Code completion occurs within the list of instance variables
08329     /// in an Objective-C interface, protocol, category, or implementation.
08330     PCC_ObjCInstanceVariableList,
08331     /// \brief Code completion occurs following one or more template
08332     /// headers.
08333     PCC_Template,
08334     /// \brief Code completion occurs following one or more template
08335     /// headers within a class.
08336     PCC_MemberTemplate,
08337     /// \brief Code completion occurs within an expression.
08338     PCC_Expression,
08339     /// \brief Code completion occurs within a statement, which may
08340     /// also be an expression or a declaration.
08341     PCC_Statement,
08342     /// \brief Code completion occurs at the beginning of the
08343     /// initialization statement (or expression) in a for loop.
08344     PCC_ForInit,
08345     /// \brief Code completion occurs within the condition of an if,
08346     /// while, switch, or for statement.
08347     PCC_Condition,
08348     /// \brief Code completion occurs within the body of a function on a
08349     /// recovery path, where we do not have a specific handle on our position
08350     /// in the grammar.
08351     PCC_RecoveryInFunction,
08352     /// \brief Code completion occurs where only a type is permitted.
08353     PCC_Type,
08354     /// \brief Code completion occurs in a parenthesized expression, which
08355     /// might also be a type cast.
08356     PCC_ParenthesizedExpression,
08357     /// \brief Code completion occurs within a sequence of declaration
08358     /// specifiers within a function, method, or block.
08359     PCC_LocalDeclarationSpecifiers
08360   };
08361 
08362   void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path);
08363   void CodeCompleteOrdinaryName(Scope *S,
08364                                 ParserCompletionContext CompletionContext);
08365   void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS,
08366                             bool AllowNonIdentifiers,
08367                             bool AllowNestedNameSpecifiers);
08368 
08369   struct CodeCompleteExpressionData;
08370   void CodeCompleteExpression(Scope *S,
08371                               const CodeCompleteExpressionData &Data);
08372   void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
08373                                        SourceLocation OpLoc,
08374                                        bool IsArrow);
08375   void CodeCompletePostfixExpression(Scope *S, ExprResult LHS);
08376   void CodeCompleteTag(Scope *S, unsigned TagSpec);
08377   void CodeCompleteTypeQualifiers(DeclSpec &DS);
08378   void CodeCompleteCase(Scope *S);
08379   void CodeCompleteCall(Scope *S, Expr *Fn, ArrayRef<Expr *> Args);
08380   void CodeCompleteInitializer(Scope *S, Decl *D);
08381   void CodeCompleteReturn(Scope *S);
08382   void CodeCompleteAfterIf(Scope *S);
08383   void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS);
08384 
08385   void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS,
08386                                bool EnteringContext);
08387   void CodeCompleteUsing(Scope *S);
08388   void CodeCompleteUsingDirective(Scope *S);
08389   void CodeCompleteNamespaceDecl(Scope *S);
08390   void CodeCompleteNamespaceAliasDecl(Scope *S);
08391   void CodeCompleteOperatorName(Scope *S);
08392   void CodeCompleteConstructorInitializer(
08393                                 Decl *Constructor,
08394                                 ArrayRef<CXXCtorInitializer *> Initializers);
08395 
08396   void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro,
08397                                     bool AfterAmpersand);
08398 
08399   void CodeCompleteObjCAtDirective(Scope *S);
08400   void CodeCompleteObjCAtVisibility(Scope *S);
08401   void CodeCompleteObjCAtStatement(Scope *S);
08402   void CodeCompleteObjCAtExpression(Scope *S);
08403   void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS);
08404   void CodeCompleteObjCPropertyGetter(Scope *S);
08405   void CodeCompleteObjCPropertySetter(Scope *S);
08406   void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS,
08407                                    bool IsParameter);
08408   void CodeCompleteObjCMessageReceiver(Scope *S);
08409   void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc,
08410                                     ArrayRef<IdentifierInfo *> SelIdents,
08411                                     bool AtArgumentExpression);
08412   void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver,
08413                                     ArrayRef<IdentifierInfo *> SelIdents,
08414                                     bool AtArgumentExpression,
08415                                     bool IsSuper = false);
08416   void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver,
08417                                        ArrayRef<IdentifierInfo *> SelIdents,
08418                                        bool AtArgumentExpression,
08419                                        ObjCInterfaceDecl *Super = nullptr);
08420   void CodeCompleteObjCForCollection(Scope *S,
08421                                      DeclGroupPtrTy IterationVar);
08422   void CodeCompleteObjCSelector(Scope *S,
08423                                 ArrayRef<IdentifierInfo *> SelIdents);
08424   void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
08425                                           unsigned NumProtocols);
08426   void CodeCompleteObjCProtocolDecl(Scope *S);
08427   void CodeCompleteObjCInterfaceDecl(Scope *S);
08428   void CodeCompleteObjCSuperclass(Scope *S,
08429                                   IdentifierInfo *ClassName,
08430                                   SourceLocation ClassNameLoc);
08431   void CodeCompleteObjCImplementationDecl(Scope *S);
08432   void CodeCompleteObjCInterfaceCategory(Scope *S,
08433                                          IdentifierInfo *ClassName,
08434                                          SourceLocation ClassNameLoc);
08435   void CodeCompleteObjCImplementationCategory(Scope *S,
08436                                               IdentifierInfo *ClassName,
08437                                               SourceLocation ClassNameLoc);
08438   void CodeCompleteObjCPropertyDefinition(Scope *S);
08439   void CodeCompleteObjCPropertySynthesizeIvar(Scope *S,
08440                                               IdentifierInfo *PropertyName);
08441   void CodeCompleteObjCMethodDecl(Scope *S,
08442                                   bool IsInstanceMethod,
08443                                   ParsedType ReturnType);
08444   void CodeCompleteObjCMethodDeclSelector(Scope *S,
08445                                           bool IsInstanceMethod,
08446                                           bool AtParameterName,
08447                                           ParsedType ReturnType,
08448                                           ArrayRef<IdentifierInfo *> SelIdents);
08449   void CodeCompletePreprocessorDirective(bool InConditional);
08450   void CodeCompleteInPreprocessorConditionalExclusion(Scope *S);
08451   void CodeCompletePreprocessorMacroName(bool IsDefinition);
08452   void CodeCompletePreprocessorExpression();
08453   void CodeCompletePreprocessorMacroArgument(Scope *S,
08454                                              IdentifierInfo *Macro,
08455                                              MacroInfo *MacroInfo,
08456                                              unsigned Argument);
08457   void CodeCompleteNaturalLanguage();
08458   void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator,
08459                                    CodeCompletionTUInfo &CCTUInfo,
08460                   SmallVectorImpl<CodeCompletionResult> &Results);
08461   //@}
08462 
08463   //===--------------------------------------------------------------------===//
08464   // Extra semantic analysis beyond the C type system
08465 
08466 public:
08467   SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
08468                                                 unsigned ByteNo) const;
08469 
08470 private:
08471   void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
08472                         const ArraySubscriptExpr *ASE=nullptr,
08473                         bool AllowOnePastEnd=true, bool IndexNegated=false);
08474   void CheckArrayAccess(const Expr *E);
08475   // Used to grab the relevant information from a FormatAttr and a
08476   // FunctionDeclaration.
08477   struct FormatStringInfo {
08478     unsigned FormatIdx;
08479     unsigned FirstDataArg;
08480     bool HasVAListArg;
08481   };
08482 
08483   bool getFormatStringInfo(const FormatAttr *Format, bool IsCXXMember,
08484                            FormatStringInfo *FSI);
08485   bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall,
08486                          const FunctionProtoType *Proto);
08487   bool CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation loc,
08488                            ArrayRef<const Expr *> Args);
08489   bool CheckPointerCall(NamedDecl *NDecl, CallExpr *TheCall,
08490                         const FunctionProtoType *Proto);
08491   bool CheckOtherCall(CallExpr *TheCall, const FunctionProtoType *Proto);
08492   void CheckConstructorCall(FunctionDecl *FDecl,
08493                             ArrayRef<const Expr *> Args,
08494                             const FunctionProtoType *Proto,
08495                             SourceLocation Loc);
08496 
08497   void checkCall(NamedDecl *FDecl, ArrayRef<const Expr *> Args,
08498                  unsigned NumParams, bool IsMemberFunction, SourceLocation Loc,
08499                  SourceRange Range, VariadicCallType CallType);
08500 
08501   bool CheckObjCString(Expr *Arg);
08502 
08503   ExprResult CheckBuiltinFunctionCall(FunctionDecl *FDecl,
08504                           unsigned BuiltinID, CallExpr *TheCall);
08505 
08506   bool CheckARMBuiltinExclusiveCall(unsigned BuiltinID, CallExpr *TheCall,
08507                                     unsigned MaxWidth);
08508   bool CheckNeonBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
08509   bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
08510 
08511   bool CheckAArch64BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
08512   bool CheckMipsBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
08513   bool CheckX86BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
08514 
08515   bool SemaBuiltinVAStart(CallExpr *TheCall);
08516   bool SemaBuiltinVAStartARM(CallExpr *Call);
08517   bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
08518   bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs);
08519 
08520 public:
08521   // Used by C++ template instantiation.
08522   ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
08523   ExprResult SemaConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo,
08524                                    SourceLocation BuiltinLoc,
08525                                    SourceLocation RParenLoc);
08526 
08527 private:
08528   bool SemaBuiltinPrefetch(CallExpr *TheCall);
08529   bool SemaBuiltinAssume(CallExpr *TheCall);
08530   bool SemaBuiltinAssumeAligned(CallExpr *TheCall);
08531   bool SemaBuiltinLongjmp(CallExpr *TheCall);
08532   ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult);
08533   ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult,
08534                                      AtomicExpr::AtomicOp Op);
08535   bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum,
08536                               llvm::APSInt &Result);
08537   bool SemaBuiltinConstantArgRange(CallExpr *TheCall, int ArgNum,
08538                                    int Low, int High);
08539 
08540 public:
08541   enum FormatStringType {
08542     FST_Scanf,
08543     FST_Printf,
08544     FST_NSString,
08545     FST_Strftime,
08546     FST_Strfmon,
08547     FST_Kprintf,
08548     FST_Unknown
08549   };
08550   static FormatStringType GetFormatStringType(const FormatAttr *Format);
08551 
08552   void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr,
08553                          ArrayRef<const Expr *> Args, bool HasVAListArg,
08554                          unsigned format_idx, unsigned firstDataArg,
08555                          FormatStringType Type, bool inFunctionCall,
08556                          VariadicCallType CallType,
08557                          llvm::SmallBitVector &CheckedVarArgs);
08558   
08559   bool FormatStringHasSArg(const StringLiteral *FExpr);
08560   
08561   bool GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx);
08562 
08563 private:
08564   bool CheckFormatArguments(const FormatAttr *Format,
08565                             ArrayRef<const Expr *> Args,
08566                             bool IsCXXMember,
08567                             VariadicCallType CallType,
08568                             SourceLocation Loc, SourceRange Range,
08569                             llvm::SmallBitVector &CheckedVarArgs);
08570   bool CheckFormatArguments(ArrayRef<const Expr *> Args,
08571                             bool HasVAListArg, unsigned format_idx,
08572                             unsigned firstDataArg, FormatStringType Type,
08573                             VariadicCallType CallType,
08574                             SourceLocation Loc, SourceRange range,
08575                             llvm::SmallBitVector &CheckedVarArgs);
08576 
08577   void CheckAbsoluteValueFunction(const CallExpr *Call,
08578                                   const FunctionDecl *FDecl,
08579                                   IdentifierInfo *FnInfo);
08580 
08581   void CheckMemaccessArguments(const CallExpr *Call,
08582                                unsigned BId,
08583                                IdentifierInfo *FnName);
08584 
08585   void CheckStrlcpycatArguments(const CallExpr *Call,
08586                                 IdentifierInfo *FnName);
08587 
08588   void CheckStrncatArguments(const CallExpr *Call,
08589                              IdentifierInfo *FnName);
08590 
08591   void CheckReturnValExpr(Expr *RetValExp, QualType lhsType,
08592                           SourceLocation ReturnLoc,
08593                           bool isObjCMethod = false,
08594                           const AttrVec *Attrs = nullptr,
08595                           const FunctionDecl *FD = nullptr);
08596 
08597   void CheckFloatComparison(SourceLocation Loc, Expr* LHS, Expr* RHS);
08598   void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation());
08599   void CheckBoolLikeConversion(Expr *E, SourceLocation CC);
08600   void CheckForIntOverflow(Expr *E);
08601   void CheckUnsequencedOperations(Expr *E);
08602 
08603   /// \brief Perform semantic checks on a completed expression. This will either
08604   /// be a full-expression or a default argument expression.
08605   void CheckCompletedExpr(Expr *E, SourceLocation CheckLoc = SourceLocation(),
08606                           bool IsConstexpr = false);
08607 
08608   void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field,
08609                                    Expr *Init);
08610 
08611   /// \brief Check if the given expression contains 'break' or 'continue'
08612   /// statement that produces control flow different from GCC.
08613   void CheckBreakContinueBinding(Expr *E);
08614 
08615 public:
08616   /// \brief Register a magic integral constant to be used as a type tag.
08617   void RegisterTypeTagForDatatype(const IdentifierInfo *ArgumentKind,
08618                                   uint64_t MagicValue, QualType Type,
08619                                   bool LayoutCompatible, bool MustBeNull);
08620 
08621   struct TypeTagData {
08622     TypeTagData() {}
08623 
08624     TypeTagData(QualType Type, bool LayoutCompatible, bool MustBeNull) :
08625         Type(Type), LayoutCompatible(LayoutCompatible),
08626         MustBeNull(MustBeNull)
08627     {}
08628 
08629     QualType Type;
08630 
08631     /// If true, \c Type should be compared with other expression's types for
08632     /// layout-compatibility.
08633     unsigned LayoutCompatible : 1;
08634     unsigned MustBeNull : 1;
08635   };
08636 
08637   /// A pair of ArgumentKind identifier and magic value.  This uniquely
08638   /// identifies the magic value.
08639   typedef std::pair<const IdentifierInfo *, uint64_t> TypeTagMagicValue;
08640 
08641 private:
08642   /// \brief A map from magic value to type information.
08643   std::unique_ptr<llvm::DenseMap<TypeTagMagicValue, TypeTagData>>
08644       TypeTagForDatatypeMagicValues;
08645 
08646   /// \brief Peform checks on a call of a function with argument_with_type_tag
08647   /// or pointer_with_type_tag attributes.
08648   void CheckArgumentWithTypeTag(const ArgumentWithTypeTagAttr *Attr,
08649                                 const Expr * const *ExprArgs);
08650 
08651   /// \brief The parser's current scope.
08652   ///
08653   /// The parser maintains this state here.
08654   Scope *CurScope;
08655 
08656   mutable IdentifierInfo *Ident_super;
08657   mutable IdentifierInfo *Ident___float128;
08658 
08659 protected:
08660   friend class Parser;
08661   friend class InitializationSequence;
08662   friend class ASTReader;
08663   friend class ASTWriter;
08664 
08665 public:
08666   /// \brief Retrieve the parser's current scope.
08667   ///
08668   /// This routine must only be used when it is certain that semantic analysis
08669   /// and the parser are in precisely the same context, which is not the case
08670   /// when, e.g., we are performing any kind of template instantiation.
08671   /// Therefore, the only safe places to use this scope are in the parser
08672   /// itself and in routines directly invoked from the parser and *never* from
08673   /// template substitution or instantiation.
08674   Scope *getCurScope() const { return CurScope; }
08675 
08676   void incrementMSLocalManglingNumber() const {
08677     return CurScope->incrementMSLocalManglingNumber();
08678   }
08679 
08680   IdentifierInfo *getSuperIdentifier() const;
08681   IdentifierInfo *getFloat128Identifier() const;
08682 
08683   Decl *getObjCDeclContext() const;
08684 
08685   DeclContext *getCurLexicalContext() const {
08686     return OriginalLexicalContext ? OriginalLexicalContext : CurContext;
08687   }
08688 
08689   AvailabilityResult getCurContextAvailability() const;
08690   
08691   const DeclContext *getCurObjCLexicalContext() const {
08692     const DeclContext *DC = getCurLexicalContext();
08693     // A category implicitly has the attribute of the interface.
08694     if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(DC))
08695       DC = CatD->getClassInterface();
08696     return DC;
08697   }
08698 };
08699 
08700 /// \brief RAII object that enters a new expression evaluation context.
08701 class EnterExpressionEvaluationContext {
08702   Sema &Actions;
08703 
08704 public:
08705   EnterExpressionEvaluationContext(Sema &Actions,
08706                                    Sema::ExpressionEvaluationContext NewContext,
08707                                    Decl *LambdaContextDecl = nullptr,
08708                                    bool IsDecltype = false)
08709     : Actions(Actions) {
08710     Actions.PushExpressionEvaluationContext(NewContext, LambdaContextDecl,
08711                                             IsDecltype);
08712   }
08713   EnterExpressionEvaluationContext(Sema &Actions,
08714                                    Sema::ExpressionEvaluationContext NewContext,
08715                                    Sema::ReuseLambdaContextDecl_t,
08716                                    bool IsDecltype = false)
08717     : Actions(Actions) {
08718     Actions.PushExpressionEvaluationContext(NewContext, 
08719                                             Sema::ReuseLambdaContextDecl,
08720                                             IsDecltype);
08721   }
08722 
08723   ~EnterExpressionEvaluationContext() {
08724     Actions.PopExpressionEvaluationContext();
08725   }
08726 };
08727 
08728 DeductionFailureInfo
08729 MakeDeductionFailureInfo(ASTContext &Context, Sema::TemplateDeductionResult TDK,
08730                          sema::TemplateDeductionInfo &Info);
08731 
08732 /// \brief Contains a late templated function.
08733 /// Will be parsed at the end of the translation unit, used by Sema & Parser.
08734 struct LateParsedTemplate {
08735   CachedTokens Toks;
08736   /// \brief The template function declaration to be late parsed.
08737   Decl *D;
08738 };
08739 
08740 } // end namespace clang
08741 
08742 #endif