Sema.h revision f4d918fdf7da64215db8abe63945798c66e6d132
1//===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the Sema class, which performs semantic analysis and 11// builds ASTs. 12// 13//===----------------------------------------------------------------------===// 14 15#ifndef LLVM_CLANG_SEMA_SEMA_H 16#define LLVM_CLANG_SEMA_SEMA_H 17 18#include "clang/AST/Attr.h" 19#include "clang/AST/DeclarationName.h" 20#include "clang/AST/Expr.h" 21#include "clang/AST/ExprObjC.h" 22#include "clang/AST/ExternalASTSource.h" 23#include "clang/AST/LambdaMangleContext.h" 24#include "clang/AST/NSAPI.h" 25#include "clang/AST/PrettyPrinter.h" 26#include "clang/AST/TypeLoc.h" 27#include "clang/Basic/ExpressionTraits.h" 28#include "clang/Basic/LangOptions.h" 29#include "clang/Basic/Specifiers.h" 30#include "clang/Basic/TemplateKinds.h" 31#include "clang/Basic/TypeTraits.h" 32#include "clang/Lex/ModuleLoader.h" 33#include "clang/Sema/AnalysisBasedWarnings.h" 34#include "clang/Sema/DeclSpec.h" 35#include "clang/Sema/ExternalSemaSource.h" 36#include "clang/Sema/IdentifierResolver.h" 37#include "clang/Sema/LocInfoType.h" 38#include "clang/Sema/ObjCMethodList.h" 39#include "clang/Sema/Ownership.h" 40#include "clang/Sema/TypoCorrection.h" 41#include "clang/Sema/Weak.h" 42#include "llvm/ADT/ArrayRef.h" 43#include "llvm/ADT/Optional.h" 44#include "llvm/ADT/OwningPtr.h" 45#include "llvm/ADT/SetVector.h" 46#include "llvm/ADT/SmallPtrSet.h" 47#include "llvm/ADT/SmallVector.h" 48#include <deque> 49#include <string> 50 51namespace llvm { 52 class APSInt; 53 template <typename ValueT> struct DenseMapInfo; 54 template <typename ValueT, typename ValueInfoT> class DenseSet; 55 class SmallBitVector; 56} 57 58namespace clang { 59 class ADLResult; 60 class ASTConsumer; 61 class ASTContext; 62 class ASTMutationListener; 63 class ASTReader; 64 class ASTWriter; 65 class ArrayType; 66 class AttributeList; 67 class BlockDecl; 68 class CXXBasePath; 69 class CXXBasePaths; 70 class CXXBindTemporaryExpr; 71 typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; 72 class CXXConstructorDecl; 73 class CXXConversionDecl; 74 class CXXDestructorDecl; 75 class CXXFieldCollector; 76 class CXXMemberCallExpr; 77 class CXXMethodDecl; 78 class CXXScopeSpec; 79 class CXXTemporary; 80 class CXXTryStmt; 81 class CallExpr; 82 class ClassTemplateDecl; 83 class ClassTemplatePartialSpecializationDecl; 84 class ClassTemplateSpecializationDecl; 85 class CodeCompleteConsumer; 86 class CodeCompletionAllocator; 87 class CodeCompletionTUInfo; 88 class CodeCompletionResult; 89 class Decl; 90 class DeclAccessPair; 91 class DeclContext; 92 class DeclRefExpr; 93 class DeclaratorDecl; 94 class DeducedTemplateArgument; 95 class DependentDiagnostic; 96 class DesignatedInitExpr; 97 class Designation; 98 class EnumConstantDecl; 99 class Expr; 100 class ExtVectorType; 101 class ExternalSemaSource; 102 class FormatAttr; 103 class FriendDecl; 104 class FunctionDecl; 105 class FunctionProtoType; 106 class FunctionTemplateDecl; 107 class ImplicitConversionSequence; 108 class InitListExpr; 109 class InitializationKind; 110 class InitializationSequence; 111 class InitializedEntity; 112 class IntegerLiteral; 113 class LabelStmt; 114 class LambdaExpr; 115 class LangOptions; 116 class LocalInstantiationScope; 117 class LookupResult; 118 class MacroInfo; 119 class MultiLevelTemplateArgumentList; 120 class NamedDecl; 121 class NonNullAttr; 122 class ObjCCategoryDecl; 123 class ObjCCategoryImplDecl; 124 class ObjCCompatibleAliasDecl; 125 class ObjCContainerDecl; 126 class ObjCImplDecl; 127 class ObjCImplementationDecl; 128 class ObjCInterfaceDecl; 129 class ObjCIvarDecl; 130 template <class T> class ObjCList; 131 class ObjCMessageExpr; 132 class ObjCMethodDecl; 133 class ObjCPropertyDecl; 134 class ObjCProtocolDecl; 135 class OverloadCandidateSet; 136 class OverloadExpr; 137 class ParenListExpr; 138 class ParmVarDecl; 139 class Preprocessor; 140 class PseudoDestructorTypeStorage; 141 class PseudoObjectExpr; 142 class QualType; 143 class StandardConversionSequence; 144 class Stmt; 145 class StringLiteral; 146 class SwitchStmt; 147 class TargetAttributesSema; 148 class TemplateArgument; 149 class TemplateArgumentList; 150 class TemplateArgumentLoc; 151 class TemplateDecl; 152 class TemplateParameterList; 153 class TemplatePartialOrderingContext; 154 class TemplateTemplateParmDecl; 155 class Token; 156 class TypeAliasDecl; 157 class TypedefDecl; 158 class TypedefNameDecl; 159 class TypeLoc; 160 class UnqualifiedId; 161 class UnresolvedLookupExpr; 162 class UnresolvedMemberExpr; 163 class UnresolvedSetImpl; 164 class UnresolvedSetIterator; 165 class UsingDecl; 166 class UsingShadowDecl; 167 class ValueDecl; 168 class VarDecl; 169 class VisibilityAttr; 170 class VisibleDeclConsumer; 171 class IndirectFieldDecl; 172 173namespace sema { 174 class AccessedEntity; 175 class BlockScopeInfo; 176 class CapturingScopeInfo; 177 class CompoundScopeInfo; 178 class DelayedDiagnostic; 179 class DelayedDiagnosticPool; 180 class FunctionScopeInfo; 181 class LambdaScopeInfo; 182 class PossiblyUnreachableDiag; 183 class TemplateDeductionInfo; 184} 185 186// FIXME: No way to easily map from TemplateTypeParmTypes to 187// TemplateTypeParmDecls, so we have this horrible PointerUnion. 188typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType*, NamedDecl*>, 189 SourceLocation> UnexpandedParameterPack; 190 191/// Sema - This implements semantic analysis and AST building for C. 192class Sema { 193 Sema(const Sema &) LLVM_DELETED_FUNCTION; 194 void operator=(const Sema &) LLVM_DELETED_FUNCTION; 195 mutable const TargetAttributesSema* TheTargetAttributesSema; 196 197 ///\brief Source of additional semantic information. 198 ExternalSemaSource *ExternalSource; 199 200 ///\brief Whether Sema has generated a multiplexer and has to delete it. 201 bool isMultiplexExternalSource; 202 203public: 204 typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; 205 typedef OpaquePtr<TemplateName> TemplateTy; 206 typedef OpaquePtr<QualType> TypeTy; 207 208 OpenCLOptions OpenCLFeatures; 209 FPOptions FPFeatures; 210 211 const LangOptions &LangOpts; 212 Preprocessor &PP; 213 ASTContext &Context; 214 ASTConsumer &Consumer; 215 DiagnosticsEngine &Diags; 216 SourceManager &SourceMgr; 217 218 /// \brief Flag indicating whether or not to collect detailed statistics. 219 bool CollectStats; 220 221 /// \brief Code-completion consumer. 222 CodeCompleteConsumer *CodeCompleter; 223 224 /// CurContext - This is the current declaration context of parsing. 225 DeclContext *CurContext; 226 227 /// \brief Generally null except when we temporarily switch decl contexts, 228 /// like in \see ActOnObjCTemporaryExitContainerContext. 229 DeclContext *OriginalLexicalContext; 230 231 /// VAListTagName - The declaration name corresponding to __va_list_tag. 232 /// This is used as part of a hack to omit that class from ADL results. 233 DeclarationName VAListTagName; 234 235 /// PackContext - Manages the stack for \#pragma pack. An alignment 236 /// of 0 indicates default alignment. 237 void *PackContext; // Really a "PragmaPackStack*" 238 239 bool MSStructPragmaOn; // True when \#pragma ms_struct on 240 241 /// VisContext - Manages the stack for \#pragma GCC visibility. 242 void *VisContext; // Really a "PragmaVisStack*" 243 244 /// \brief Flag indicating if Sema is building a recovery call expression. 245 /// 246 /// This flag is used to avoid building recovery call expressions 247 /// if Sema is already doing so, which would cause infinite recursions. 248 bool IsBuildingRecoveryCallExpr; 249 250 /// ExprNeedsCleanups - True if the current evaluation context 251 /// requires cleanups to be run at its conclusion. 252 bool ExprNeedsCleanups; 253 254 /// ExprCleanupObjects - This is the stack of objects requiring 255 /// cleanup that are created by the current full expression. The 256 /// element type here is ExprWithCleanups::Object. 257 SmallVector<BlockDecl*, 8> ExprCleanupObjects; 258 259 llvm::SmallPtrSet<Expr*, 8> MaybeODRUseExprs; 260 261 /// \brief Stack containing information about each of the nested 262 /// function, block, and method scopes that are currently active. 263 /// 264 /// This array is never empty. Clients should ignore the first 265 /// element, which is used to cache a single FunctionScopeInfo 266 /// that's used to parse every top-level function. 267 SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes; 268 269 typedef LazyVector<TypedefNameDecl *, ExternalSemaSource, 270 &ExternalSemaSource::ReadExtVectorDecls, 2, 2> 271 ExtVectorDeclsType; 272 273 /// ExtVectorDecls - This is a list all the extended vector types. This allows 274 /// us to associate a raw vector type with one of the ext_vector type names. 275 /// This is only necessary for issuing pretty diagnostics. 276 ExtVectorDeclsType ExtVectorDecls; 277 278 /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes. 279 OwningPtr<CXXFieldCollector> FieldCollector; 280 281 typedef llvm::SmallSetVector<const NamedDecl*, 16> NamedDeclSetType; 282 283 /// \brief Set containing all declared private fields that are not used. 284 NamedDeclSetType UnusedPrivateFields; 285 286 typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy; 287 288 /// PureVirtualClassDiagSet - a set of class declarations which we have 289 /// emitted a list of pure virtual functions. Used to prevent emitting the 290 /// same list more than once. 291 OwningPtr<RecordDeclSetTy> PureVirtualClassDiagSet; 292 293 /// ParsingInitForAutoVars - a set of declarations with auto types for which 294 /// we are currently parsing the initializer. 295 llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars; 296 297 /// \brief A mapping from external names to the most recent 298 /// locally-scoped extern "C" declaration with that name. 299 /// 300 /// This map contains external declarations introduced in local 301 /// scopes, e.g., 302 /// 303 /// \code 304 /// extern "C" void f() { 305 /// void foo(int, int); 306 /// } 307 /// \endcode 308 /// 309 /// Here, the name "foo" will be associated with the declaration of 310 /// "foo" within f. This name is not visible outside of 311 /// "f". However, we still find it in two cases: 312 /// 313 /// - If we are declaring another global or extern "C" entity with 314 /// the name "foo", we can find "foo" as a previous declaration, 315 /// so that the types of this external declaration can be checked 316 /// for compatibility. 317 /// 318 /// - If we would implicitly declare "foo" (e.g., due to a call to 319 /// "foo" in C when no prototype or definition is visible), then 320 /// we find this declaration of "foo" and complain that it is 321 /// not visible. 322 llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternCDecls; 323 324 /// \brief Look for a locally scoped extern "C" declaration by the given name. 325 llvm::DenseMap<DeclarationName, NamedDecl *>::iterator 326 findLocallyScopedExternCDecl(DeclarationName Name); 327 328 typedef LazyVector<VarDecl *, ExternalSemaSource, 329 &ExternalSemaSource::ReadTentativeDefinitions, 2, 2> 330 TentativeDefinitionsType; 331 332 /// \brief All the tentative definitions encountered in the TU. 333 TentativeDefinitionsType TentativeDefinitions; 334 335 typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource, 336 &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2> 337 UnusedFileScopedDeclsType; 338 339 /// \brief The set of file scoped decls seen so far that have not been used 340 /// and must warn if not used. Only contains the first declaration. 341 UnusedFileScopedDeclsType UnusedFileScopedDecls; 342 343 typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource, 344 &ExternalSemaSource::ReadDelegatingConstructors, 2, 2> 345 DelegatingCtorDeclsType; 346 347 /// \brief All the delegating constructors seen so far in the file, used for 348 /// cycle detection at the end of the TU. 349 DelegatingCtorDeclsType DelegatingCtorDecls; 350 351 /// \brief All the destructors seen during a class definition that had their 352 /// exception spec computation delayed because it depended on an unparsed 353 /// exception spec. 354 SmallVector<CXXDestructorDecl*, 2> DelayedDestructorExceptionSpecs; 355 356 /// \brief All the overriding destructors seen during a class definition 357 /// (there could be multiple due to nested classes) that had their exception 358 /// spec checks delayed, plus the overridden destructor. 359 SmallVector<std::pair<const CXXDestructorDecl*, 360 const CXXDestructorDecl*>, 2> 361 DelayedDestructorExceptionSpecChecks; 362 363 /// \brief All the members seen during a class definition which were both 364 /// explicitly defaulted and had explicitly-specified exception 365 /// specifications, along with the function type containing their 366 /// user-specified exception specification. Those exception specifications 367 /// were overridden with the default specifications, but we still need to 368 /// check whether they are compatible with the default specification, and 369 /// we can't do that until the nesting set of class definitions is complete. 370 SmallVector<std::pair<CXXMethodDecl*, const FunctionProtoType*>, 2> 371 DelayedDefaultedMemberExceptionSpecs; 372 373 /// \brief Callback to the parser to parse templated functions when needed. 374 typedef void LateTemplateParserCB(void *P, const FunctionDecl *FD); 375 LateTemplateParserCB *LateTemplateParser; 376 void *OpaqueParser; 377 378 void SetLateTemplateParser(LateTemplateParserCB *LTP, void *P) { 379 LateTemplateParser = LTP; 380 OpaqueParser = P; 381 } 382 383 class DelayedDiagnostics; 384 385 class DelayedDiagnosticsState { 386 sema::DelayedDiagnosticPool *SavedPool; 387 friend class Sema::DelayedDiagnostics; 388 }; 389 typedef DelayedDiagnosticsState ParsingDeclState; 390 typedef DelayedDiagnosticsState ProcessingContextState; 391 392 /// A class which encapsulates the logic for delaying diagnostics 393 /// during parsing and other processing. 394 class DelayedDiagnostics { 395 /// \brief The current pool of diagnostics into which delayed 396 /// diagnostics should go. 397 sema::DelayedDiagnosticPool *CurPool; 398 399 public: 400 DelayedDiagnostics() : CurPool(0) {} 401 402 /// Adds a delayed diagnostic. 403 void add(const sema::DelayedDiagnostic &diag); // in DelayedDiagnostic.h 404 405 /// Determines whether diagnostics should be delayed. 406 bool shouldDelayDiagnostics() { return CurPool != 0; } 407 408 /// Returns the current delayed-diagnostics pool. 409 sema::DelayedDiagnosticPool *getCurrentPool() const { 410 return CurPool; 411 } 412 413 /// Enter a new scope. Access and deprecation diagnostics will be 414 /// collected in this pool. 415 DelayedDiagnosticsState push(sema::DelayedDiagnosticPool &pool) { 416 DelayedDiagnosticsState state; 417 state.SavedPool = CurPool; 418 CurPool = &pool; 419 return state; 420 } 421 422 /// Leave a delayed-diagnostic state that was previously pushed. 423 /// Do not emit any of the diagnostics. This is performed as part 424 /// of the bookkeeping of popping a pool "properly". 425 void popWithoutEmitting(DelayedDiagnosticsState state) { 426 CurPool = state.SavedPool; 427 } 428 429 /// Enter a new scope where access and deprecation diagnostics are 430 /// not delayed. 431 DelayedDiagnosticsState pushUndelayed() { 432 DelayedDiagnosticsState state; 433 state.SavedPool = CurPool; 434 CurPool = 0; 435 return state; 436 } 437 438 /// Undo a previous pushUndelayed(). 439 void popUndelayed(DelayedDiagnosticsState state) { 440 assert(CurPool == NULL); 441 CurPool = state.SavedPool; 442 } 443 } DelayedDiagnostics; 444 445 /// A RAII object to temporarily push a declaration context. 446 class ContextRAII { 447 private: 448 Sema &S; 449 DeclContext *SavedContext; 450 ProcessingContextState SavedContextState; 451 QualType SavedCXXThisTypeOverride; 452 453 public: 454 ContextRAII(Sema &S, DeclContext *ContextToPush) 455 : S(S), SavedContext(S.CurContext), 456 SavedContextState(S.DelayedDiagnostics.pushUndelayed()), 457 SavedCXXThisTypeOverride(S.CXXThisTypeOverride) 458 { 459 assert(ContextToPush && "pushing null context"); 460 S.CurContext = ContextToPush; 461 } 462 463 void pop() { 464 if (!SavedContext) return; 465 S.CurContext = SavedContext; 466 S.DelayedDiagnostics.popUndelayed(SavedContextState); 467 S.CXXThisTypeOverride = SavedCXXThisTypeOverride; 468 SavedContext = 0; 469 } 470 471 ~ContextRAII() { 472 pop(); 473 } 474 }; 475 476 /// \brief RAII object to handle the state changes required to synthesize 477 /// a function body. 478 class SynthesizedFunctionScope { 479 Sema &S; 480 Sema::ContextRAII SavedContext; 481 482 public: 483 SynthesizedFunctionScope(Sema &S, DeclContext *DC) 484 : S(S), SavedContext(S, DC) 485 { 486 S.PushFunctionScope(); 487 S.PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); 488 } 489 490 ~SynthesizedFunctionScope() { 491 S.PopExpressionEvaluationContext(); 492 S.PopFunctionScopeInfo(); 493 } 494 }; 495 496 /// WeakUndeclaredIdentifiers - Identifiers contained in 497 /// \#pragma weak before declared. rare. may alias another 498 /// identifier, declared or undeclared 499 llvm::DenseMap<IdentifierInfo*,WeakInfo> WeakUndeclaredIdentifiers; 500 501 /// ExtnameUndeclaredIdentifiers - Identifiers contained in 502 /// \#pragma redefine_extname before declared. Used in Solaris system headers 503 /// to define functions that occur in multiple standards to call the version 504 /// in the currently selected standard. 505 llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*> ExtnameUndeclaredIdentifiers; 506 507 508 /// \brief Load weak undeclared identifiers from the external source. 509 void LoadExternalWeakUndeclaredIdentifiers(); 510 511 /// WeakTopLevelDecl - Translation-unit scoped declarations generated by 512 /// \#pragma weak during processing of other Decls. 513 /// I couldn't figure out a clean way to generate these in-line, so 514 /// we store them here and handle separately -- which is a hack. 515 /// It would be best to refactor this. 516 SmallVector<Decl*,2> WeakTopLevelDecl; 517 518 IdentifierResolver IdResolver; 519 520 /// Translation Unit Scope - useful to Objective-C actions that need 521 /// to lookup file scope declarations in the "ordinary" C decl namespace. 522 /// For example, user-defined classes, built-in "id" type, etc. 523 Scope *TUScope; 524 525 /// \brief The C++ "std" namespace, where the standard library resides. 526 LazyDeclPtr StdNamespace; 527 528 /// \brief The C++ "std::bad_alloc" class, which is defined by the C++ 529 /// standard library. 530 LazyDeclPtr StdBadAlloc; 531 532 /// \brief The C++ "std::initializer_list" template, which is defined in 533 /// \<initializer_list>. 534 ClassTemplateDecl *StdInitializerList; 535 536 /// \brief The C++ "type_info" declaration, which is defined in \<typeinfo>. 537 RecordDecl *CXXTypeInfoDecl; 538 539 /// \brief The MSVC "_GUID" struct, which is defined in MSVC header files. 540 RecordDecl *MSVCGuidDecl; 541 542 /// \brief Caches identifiers/selectors for NSFoundation APIs. 543 OwningPtr<NSAPI> NSAPIObj; 544 545 /// \brief The declaration of the Objective-C NSNumber class. 546 ObjCInterfaceDecl *NSNumberDecl; 547 548 /// \brief Pointer to NSNumber type (NSNumber *). 549 QualType NSNumberPointer; 550 551 /// \brief The Objective-C NSNumber methods used to create NSNumber literals. 552 ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods]; 553 554 /// \brief The declaration of the Objective-C NSString class. 555 ObjCInterfaceDecl *NSStringDecl; 556 557 /// \brief Pointer to NSString type (NSString *). 558 QualType NSStringPointer; 559 560 /// \brief The declaration of the stringWithUTF8String: method. 561 ObjCMethodDecl *StringWithUTF8StringMethod; 562 563 /// \brief The declaration of the Objective-C NSArray class. 564 ObjCInterfaceDecl *NSArrayDecl; 565 566 /// \brief The declaration of the arrayWithObjects:count: method. 567 ObjCMethodDecl *ArrayWithObjectsMethod; 568 569 /// \brief The declaration of the Objective-C NSDictionary class. 570 ObjCInterfaceDecl *NSDictionaryDecl; 571 572 /// \brief The declaration of the dictionaryWithObjects:forKeys:count: method. 573 ObjCMethodDecl *DictionaryWithObjectsMethod; 574 575 /// \brief id<NSCopying> type. 576 QualType QIDNSCopying; 577 578 /// A flag to remember whether the implicit forms of operator new and delete 579 /// have been declared. 580 bool GlobalNewDeleteDeclared; 581 582 /// \brief Describes how the expressions currently being parsed are 583 /// evaluated at run-time, if at all. 584 enum ExpressionEvaluationContext { 585 /// \brief The current expression and its subexpressions occur within an 586 /// unevaluated operand (C++11 [expr]p7), such as the subexpression of 587 /// \c sizeof, where the type of the expression may be significant but 588 /// no code will be generated to evaluate the value of the expression at 589 /// run time. 590 Unevaluated, 591 592 /// \brief The current context is "potentially evaluated" in C++11 terms, 593 /// but the expression is evaluated at compile-time (like the values of 594 /// cases in a switch statment). 595 ConstantEvaluated, 596 597 /// \brief The current expression is potentially evaluated at run time, 598 /// which means that code may be generated to evaluate the value of the 599 /// expression at run time. 600 PotentiallyEvaluated, 601 602 /// \brief The current expression is potentially evaluated, but any 603 /// declarations referenced inside that expression are only used if 604 /// in fact the current expression is used. 605 /// 606 /// This value is used when parsing default function arguments, for which 607 /// we would like to provide diagnostics (e.g., passing non-POD arguments 608 /// through varargs) but do not want to mark declarations as "referenced" 609 /// until the default argument is used. 610 PotentiallyEvaluatedIfUsed 611 }; 612 613 /// \brief Data structure used to record current or nested 614 /// expression evaluation contexts. 615 struct ExpressionEvaluationContextRecord { 616 /// \brief The expression evaluation context. 617 ExpressionEvaluationContext Context; 618 619 /// \brief Whether the enclosing context needed a cleanup. 620 bool ParentNeedsCleanups; 621 622 /// \brief Whether we are in a decltype expression. 623 bool IsDecltype; 624 625 /// \brief The number of active cleanup objects when we entered 626 /// this expression evaluation context. 627 unsigned NumCleanupObjects; 628 629 llvm::SmallPtrSet<Expr*, 8> SavedMaybeODRUseExprs; 630 631 /// \brief The lambdas that are present within this context, if it 632 /// is indeed an unevaluated context. 633 SmallVector<LambdaExpr *, 2> Lambdas; 634 635 /// \brief The declaration that provides context for the lambda expression 636 /// if the normal declaration context does not suffice, e.g., in a 637 /// default function argument. 638 Decl *LambdaContextDecl; 639 640 /// \brief The context information used to mangle lambda expressions 641 /// within this context. 642 /// 643 /// This mangling information is allocated lazily, since most contexts 644 /// do not have lambda expressions. 645 IntrusiveRefCntPtr<LambdaMangleContext> LambdaMangle; 646 647 /// \brief If we are processing a decltype type, a set of call expressions 648 /// for which we have deferred checking the completeness of the return type. 649 SmallVector<CallExpr *, 8> DelayedDecltypeCalls; 650 651 /// \brief If we are processing a decltype type, a set of temporary binding 652 /// expressions for which we have deferred checking the destructor. 653 SmallVector<CXXBindTemporaryExpr *, 8> DelayedDecltypeBinds; 654 655 ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context, 656 unsigned NumCleanupObjects, 657 bool ParentNeedsCleanups, 658 Decl *LambdaContextDecl, 659 bool IsDecltype) 660 : Context(Context), ParentNeedsCleanups(ParentNeedsCleanups), 661 IsDecltype(IsDecltype), NumCleanupObjects(NumCleanupObjects), 662 LambdaContextDecl(LambdaContextDecl), LambdaMangle() { } 663 664 /// \brief Retrieve the mangling context for lambdas. 665 LambdaMangleContext &getLambdaMangleContext() { 666 assert(LambdaContextDecl && "Need to have a lambda context declaration"); 667 if (!LambdaMangle) 668 LambdaMangle = new LambdaMangleContext; 669 return *LambdaMangle; 670 } 671 }; 672 673 /// A stack of expression evaluation contexts. 674 SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts; 675 676 /// SpecialMemberOverloadResult - The overloading result for a special member 677 /// function. 678 /// 679 /// This is basically a wrapper around PointerIntPair. The lowest bits of the 680 /// integer are used to determine whether overload resolution succeeded. 681 class SpecialMemberOverloadResult : public llvm::FastFoldingSetNode { 682 public: 683 enum Kind { 684 NoMemberOrDeleted, 685 Ambiguous, 686 Success 687 }; 688 689 private: 690 llvm::PointerIntPair<CXXMethodDecl*, 2> Pair; 691 692 public: 693 SpecialMemberOverloadResult(const llvm::FoldingSetNodeID &ID) 694 : FastFoldingSetNode(ID) 695 {} 696 697 CXXMethodDecl *getMethod() const { return Pair.getPointer(); } 698 void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); } 699 700 Kind getKind() const { return static_cast<Kind>(Pair.getInt()); } 701 void setKind(Kind K) { Pair.setInt(K); } 702 }; 703 704 /// \brief A cache of special member function overload resolution results 705 /// for C++ records. 706 llvm::FoldingSet<SpecialMemberOverloadResult> SpecialMemberCache; 707 708 /// \brief The kind of translation unit we are processing. 709 /// 710 /// When we're processing a complete translation unit, Sema will perform 711 /// end-of-translation-unit semantic tasks (such as creating 712 /// initializers for tentative definitions in C) once parsing has 713 /// completed. Modules and precompiled headers perform different kinds of 714 /// checks. 715 TranslationUnitKind TUKind; 716 717 llvm::BumpPtrAllocator BumpAlloc; 718 719 /// \brief The number of SFINAE diagnostics that have been trapped. 720 unsigned NumSFINAEErrors; 721 722 typedef llvm::DenseMap<ParmVarDecl *, SmallVector<ParmVarDecl *, 1> > 723 UnparsedDefaultArgInstantiationsMap; 724 725 /// \brief A mapping from parameters with unparsed default arguments to the 726 /// set of instantiations of each parameter. 727 /// 728 /// This mapping is a temporary data structure used when parsing 729 /// nested class templates or nested classes of class templates, 730 /// where we might end up instantiating an inner class before the 731 /// default arguments of its methods have been parsed. 732 UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations; 733 734 // Contains the locations of the beginning of unparsed default 735 // argument locations. 736 llvm::DenseMap<ParmVarDecl *,SourceLocation> UnparsedDefaultArgLocs; 737 738 /// UndefinedInternals - all the used, undefined objects with 739 /// internal linkage in this translation unit. 740 llvm::DenseMap<NamedDecl*, SourceLocation> UndefinedInternals; 741 742 typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods; 743 typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool; 744 745 /// Method Pool - allows efficient lookup when typechecking messages to "id". 746 /// We need to maintain a list, since selectors can have differing signatures 747 /// across classes. In Cocoa, this happens to be extremely uncommon (only 1% 748 /// of selectors are "overloaded"). 749 GlobalMethodPool MethodPool; 750 751 /// Method selectors used in a \@selector expression. Used for implementation 752 /// of -Wselector. 753 llvm::DenseMap<Selector, SourceLocation> ReferencedSelectors; 754 755 /// Kinds of C++ special members. 756 enum CXXSpecialMember { 757 CXXDefaultConstructor, 758 CXXCopyConstructor, 759 CXXMoveConstructor, 760 CXXCopyAssignment, 761 CXXMoveAssignment, 762 CXXDestructor, 763 CXXInvalid 764 }; 765 766 typedef std::pair<CXXRecordDecl*, CXXSpecialMember> SpecialMemberDecl; 767 768 /// The C++ special members which we are currently in the process of 769 /// declaring. If this process recursively triggers the declaration of the 770 /// same special member, we should act as if it is not yet declared. 771 llvm::SmallSet<SpecialMemberDecl, 4> SpecialMembersBeingDeclared; 772 773 void ReadMethodPool(Selector Sel); 774 775 /// Private Helper predicate to check for 'self'. 776 bool isSelfExpr(Expr *RExpr); 777 778 /// \brief Cause the active diagnostic on the DiagosticsEngine to be 779 /// emitted. This is closely coupled to the SemaDiagnosticBuilder class and 780 /// should not be used elsewhere. 781 void EmitCurrentDiagnostic(unsigned DiagID); 782 783 /// Records and restores the FP_CONTRACT state on entry/exit of compound 784 /// statements. 785 class FPContractStateRAII { 786 public: 787 FPContractStateRAII(Sema& S) 788 : S(S), OldFPContractState(S.FPFeatures.fp_contract) {} 789 ~FPContractStateRAII() { 790 S.FPFeatures.fp_contract = OldFPContractState; 791 } 792 private: 793 Sema& S; 794 bool OldFPContractState : 1; 795 }; 796 797public: 798 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, 799 TranslationUnitKind TUKind = TU_Complete, 800 CodeCompleteConsumer *CompletionConsumer = 0); 801 ~Sema(); 802 803 /// \brief Perform initialization that occurs after the parser has been 804 /// initialized but before it parses anything. 805 void Initialize(); 806 807 const LangOptions &getLangOpts() const { return LangOpts; } 808 OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; } 809 FPOptions &getFPOptions() { return FPFeatures; } 810 811 DiagnosticsEngine &getDiagnostics() const { return Diags; } 812 SourceManager &getSourceManager() const { return SourceMgr; } 813 const TargetAttributesSema &getTargetAttributesSema() const; 814 Preprocessor &getPreprocessor() const { return PP; } 815 ASTContext &getASTContext() const { return Context; } 816 ASTConsumer &getASTConsumer() const { return Consumer; } 817 ASTMutationListener *getASTMutationListener() const; 818 ExternalSemaSource* getExternalSource() const { return ExternalSource; } 819 820 ///\brief Registers an external source. If an external source already exists, 821 /// creates a multiplex external source and appends to it. 822 /// 823 ///\param[in] E - A non-null external sema source. 824 /// 825 void addExternalSource(ExternalSemaSource *E); 826 827 void PrintStats() const; 828 829 /// \brief Helper class that creates diagnostics with optional 830 /// template instantiation stacks. 831 /// 832 /// This class provides a wrapper around the basic DiagnosticBuilder 833 /// class that emits diagnostics. SemaDiagnosticBuilder is 834 /// responsible for emitting the diagnostic (as DiagnosticBuilder 835 /// does) and, if the diagnostic comes from inside a template 836 /// instantiation, printing the template instantiation stack as 837 /// well. 838 class SemaDiagnosticBuilder : public DiagnosticBuilder { 839 Sema &SemaRef; 840 unsigned DiagID; 841 842 public: 843 SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID) 844 : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { } 845 846 ~SemaDiagnosticBuilder() { 847 // If we aren't active, there is nothing to do. 848 if (!isActive()) return; 849 850 // Otherwise, we need to emit the diagnostic. First flush the underlying 851 // DiagnosticBuilder data, and clear the diagnostic builder itself so it 852 // won't emit the diagnostic in its own destructor. 853 // 854 // This seems wasteful, in that as written the DiagnosticBuilder dtor will 855 // do its own needless checks to see if the diagnostic needs to be 856 // emitted. However, because we take care to ensure that the builder 857 // objects never escape, a sufficiently smart compiler will be able to 858 // eliminate that code. 859 FlushCounts(); 860 Clear(); 861 862 // Dispatch to Sema to emit the diagnostic. 863 SemaRef.EmitCurrentDiagnostic(DiagID); 864 } 865 }; 866 867 /// \brief Emit a diagnostic. 868 SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) { 869 DiagnosticBuilder DB = Diags.Report(Loc, DiagID); 870 return SemaDiagnosticBuilder(DB, *this, DiagID); 871 } 872 873 /// \brief Emit a partial diagnostic. 874 SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic& PD); 875 876 /// \brief Build a partial diagnostic. 877 PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h 878 879 bool findMacroSpelling(SourceLocation &loc, StringRef name); 880 881 /// \brief Get a string to suggest for zero-initialization of a type. 882 std::string getFixItZeroInitializerForType(QualType T) const; 883 std::string getFixItZeroLiteralForType(QualType T) const; 884 885 ExprResult Owned(Expr* E) { return E; } 886 ExprResult Owned(ExprResult R) { return R; } 887 StmtResult Owned(Stmt* S) { return S; } 888 889 void ActOnEndOfTranslationUnit(); 890 891 void CheckDelegatingCtorCycles(); 892 893 Scope *getScopeForContext(DeclContext *Ctx); 894 895 void PushFunctionScope(); 896 void PushBlockScope(Scope *BlockScope, BlockDecl *Block); 897 void PushLambdaScope(CXXRecordDecl *Lambda, CXXMethodDecl *CallOperator); 898 void PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP =0, 899 const Decl *D = 0, const BlockExpr *blkExpr = 0); 900 901 sema::FunctionScopeInfo *getCurFunction() const { 902 return FunctionScopes.back(); 903 } 904 905 void PushCompoundScope(); 906 void PopCompoundScope(); 907 908 sema::CompoundScopeInfo &getCurCompoundScope() const; 909 910 bool hasAnyUnrecoverableErrorsInThisFunction() const; 911 912 /// \brief Retrieve the current block, if any. 913 sema::BlockScopeInfo *getCurBlock(); 914 915 /// \brief Retrieve the current lambda expression, if any. 916 sema::LambdaScopeInfo *getCurLambda(); 917 918 /// WeakTopLevelDeclDecls - access to \#pragma weak-generated Decls 919 SmallVector<Decl*,2> &WeakTopLevelDecls() { return WeakTopLevelDecl; } 920 921 void ActOnComment(SourceRange Comment); 922 923 //===--------------------------------------------------------------------===// 924 // Type Analysis / Processing: SemaType.cpp. 925 // 926 927 QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs); 928 QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVR) { 929 return BuildQualifiedType(T, Loc, Qualifiers::fromCVRMask(CVR)); 930 } 931 QualType BuildPointerType(QualType T, 932 SourceLocation Loc, DeclarationName Entity); 933 QualType BuildReferenceType(QualType T, bool LValueRef, 934 SourceLocation Loc, DeclarationName Entity); 935 QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, 936 Expr *ArraySize, unsigned Quals, 937 SourceRange Brackets, DeclarationName Entity); 938 QualType BuildExtVectorType(QualType T, Expr *ArraySize, 939 SourceLocation AttrLoc); 940 QualType BuildFunctionType(QualType T, 941 QualType *ParamTypes, unsigned NumParamTypes, 942 bool Variadic, bool HasTrailingReturn, 943 unsigned Quals, RefQualifierKind RefQualifier, 944 SourceLocation Loc, DeclarationName Entity, 945 FunctionType::ExtInfo Info); 946 QualType BuildMemberPointerType(QualType T, QualType Class, 947 SourceLocation Loc, 948 DeclarationName Entity); 949 QualType BuildBlockPointerType(QualType T, 950 SourceLocation Loc, DeclarationName Entity); 951 QualType BuildParenType(QualType T); 952 QualType BuildAtomicType(QualType T, SourceLocation Loc); 953 954 TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S); 955 TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy); 956 TypeSourceInfo *GetTypeSourceInfoForDeclarator(Declarator &D, QualType T, 957 TypeSourceInfo *ReturnTypeInfo); 958 959 /// \brief Package the given type and TSI into a ParsedType. 960 ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo); 961 DeclarationNameInfo GetNameForDeclarator(Declarator &D); 962 DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name); 963 static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo = 0); 964 CanThrowResult canThrow(const Expr *E); 965 const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc, 966 const FunctionProtoType *FPT); 967 bool CheckSpecifiedExceptionType(QualType &T, const SourceRange &Range); 968 bool CheckDistantExceptionSpec(QualType T); 969 bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New); 970 bool CheckEquivalentExceptionSpec( 971 const FunctionProtoType *Old, SourceLocation OldLoc, 972 const FunctionProtoType *New, SourceLocation NewLoc); 973 bool CheckEquivalentExceptionSpec( 974 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID, 975 const FunctionProtoType *Old, SourceLocation OldLoc, 976 const FunctionProtoType *New, SourceLocation NewLoc, 977 bool *MissingExceptionSpecification = 0, 978 bool *MissingEmptyExceptionSpecification = 0, 979 bool AllowNoexceptAllMatchWithNoSpec = false, 980 bool IsOperatorNew = false); 981 bool CheckExceptionSpecSubset( 982 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID, 983 const FunctionProtoType *Superset, SourceLocation SuperLoc, 984 const FunctionProtoType *Subset, SourceLocation SubLoc); 985 bool CheckParamExceptionSpec(const PartialDiagnostic & NoteID, 986 const FunctionProtoType *Target, SourceLocation TargetLoc, 987 const FunctionProtoType *Source, SourceLocation SourceLoc); 988 989 TypeResult ActOnTypeName(Scope *S, Declarator &D); 990 991 /// \brief The parser has parsed the context-sensitive type 'instancetype' 992 /// in an Objective-C message declaration. Return the appropriate type. 993 ParsedType ActOnObjCInstanceType(SourceLocation Loc); 994 995 /// \brief Abstract class used to diagnose incomplete types. 996 struct TypeDiagnoser { 997 bool Suppressed; 998 999 TypeDiagnoser(bool Suppressed = false) : Suppressed(Suppressed) { } 1000 1001 virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0; 1002 virtual ~TypeDiagnoser() {} 1003 }; 1004 1005 static int getPrintable(int I) { return I; } 1006 static unsigned getPrintable(unsigned I) { return I; } 1007 static bool getPrintable(bool B) { return B; } 1008 static const char * getPrintable(const char *S) { return S; } 1009 static StringRef getPrintable(StringRef S) { return S; } 1010 static const std::string &getPrintable(const std::string &S) { return S; } 1011 static const IdentifierInfo *getPrintable(const IdentifierInfo *II) { 1012 return II; 1013 } 1014 static DeclarationName getPrintable(DeclarationName N) { return N; } 1015 static QualType getPrintable(QualType T) { return T; } 1016 static SourceRange getPrintable(SourceRange R) { return R; } 1017 static SourceRange getPrintable(SourceLocation L) { return L; } 1018 static SourceRange getPrintable(Expr *E) { return E->getSourceRange(); } 1019 static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();} 1020 1021 template<typename T1> 1022 class BoundTypeDiagnoser1 : public TypeDiagnoser { 1023 unsigned DiagID; 1024 const T1 &Arg1; 1025 1026 public: 1027 BoundTypeDiagnoser1(unsigned DiagID, const T1 &Arg1) 1028 : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1) { } 1029 virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) { 1030 if (Suppressed) return; 1031 S.Diag(Loc, DiagID) << getPrintable(Arg1) << T; 1032 } 1033 1034 virtual ~BoundTypeDiagnoser1() { } 1035 }; 1036 1037 template<typename T1, typename T2> 1038 class BoundTypeDiagnoser2 : public TypeDiagnoser { 1039 unsigned DiagID; 1040 const T1 &Arg1; 1041 const T2 &Arg2; 1042 1043 public: 1044 BoundTypeDiagnoser2(unsigned DiagID, const T1 &Arg1, 1045 const T2 &Arg2) 1046 : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1), 1047 Arg2(Arg2) { } 1048 1049 virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) { 1050 if (Suppressed) return; 1051 S.Diag(Loc, DiagID) << getPrintable(Arg1) << getPrintable(Arg2) << T; 1052 } 1053 1054 virtual ~BoundTypeDiagnoser2() { } 1055 }; 1056 1057 template<typename T1, typename T2, typename T3> 1058 class BoundTypeDiagnoser3 : public TypeDiagnoser { 1059 unsigned DiagID; 1060 const T1 &Arg1; 1061 const T2 &Arg2; 1062 const T3 &Arg3; 1063 1064 public: 1065 BoundTypeDiagnoser3(unsigned DiagID, const T1 &Arg1, 1066 const T2 &Arg2, const T3 &Arg3) 1067 : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1), 1068 Arg2(Arg2), Arg3(Arg3) { } 1069 1070 virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) { 1071 if (Suppressed) return; 1072 S.Diag(Loc, DiagID) 1073 << getPrintable(Arg1) << getPrintable(Arg2) << getPrintable(Arg3) << T; 1074 } 1075 1076 virtual ~BoundTypeDiagnoser3() { } 1077 }; 1078 1079 bool RequireCompleteType(SourceLocation Loc, QualType T, 1080 TypeDiagnoser &Diagnoser); 1081 bool RequireCompleteType(SourceLocation Loc, QualType T, 1082 unsigned DiagID); 1083 1084 template<typename T1> 1085 bool RequireCompleteType(SourceLocation Loc, QualType T, 1086 unsigned DiagID, const T1 &Arg1) { 1087 BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1); 1088 return RequireCompleteType(Loc, T, Diagnoser); 1089 } 1090 1091 template<typename T1, typename T2> 1092 bool RequireCompleteType(SourceLocation Loc, QualType T, 1093 unsigned DiagID, const T1 &Arg1, const T2 &Arg2) { 1094 BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2); 1095 return RequireCompleteType(Loc, T, Diagnoser); 1096 } 1097 1098 template<typename T1, typename T2, typename T3> 1099 bool RequireCompleteType(SourceLocation Loc, QualType T, 1100 unsigned DiagID, const T1 &Arg1, const T2 &Arg2, 1101 const T3 &Arg3) { 1102 BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2, 1103 Arg3); 1104 return RequireCompleteType(Loc, T, Diagnoser); 1105 } 1106 1107 bool RequireCompleteExprType(Expr *E, TypeDiagnoser &Diagnoser); 1108 bool RequireCompleteExprType(Expr *E, unsigned DiagID); 1109 1110 template<typename T1> 1111 bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1) { 1112 BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1); 1113 return RequireCompleteExprType(E, Diagnoser); 1114 } 1115 1116 template<typename T1, typename T2> 1117 bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1, 1118 const T2 &Arg2) { 1119 BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2); 1120 return RequireCompleteExprType(E, Diagnoser); 1121 } 1122 1123 template<typename T1, typename T2, typename T3> 1124 bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1, 1125 const T2 &Arg2, const T3 &Arg3) { 1126 BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2, 1127 Arg3); 1128 return RequireCompleteExprType(E, Diagnoser); 1129 } 1130 1131 bool RequireLiteralType(SourceLocation Loc, QualType T, 1132 TypeDiagnoser &Diagnoser); 1133 bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID); 1134 1135 template<typename T1> 1136 bool RequireLiteralType(SourceLocation Loc, QualType T, 1137 unsigned DiagID, const T1 &Arg1) { 1138 BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1); 1139 return RequireLiteralType(Loc, T, Diagnoser); 1140 } 1141 1142 template<typename T1, typename T2> 1143 bool RequireLiteralType(SourceLocation Loc, QualType T, 1144 unsigned DiagID, const T1 &Arg1, const T2 &Arg2) { 1145 BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2); 1146 return RequireLiteralType(Loc, T, Diagnoser); 1147 } 1148 1149 template<typename T1, typename T2, typename T3> 1150 bool RequireLiteralType(SourceLocation Loc, QualType T, 1151 unsigned DiagID, const T1 &Arg1, const T2 &Arg2, 1152 const T3 &Arg3) { 1153 BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2, 1154 Arg3); 1155 return RequireLiteralType(Loc, T, Diagnoser); 1156 } 1157 1158 QualType getElaboratedType(ElaboratedTypeKeyword Keyword, 1159 const CXXScopeSpec &SS, QualType T); 1160 1161 QualType BuildTypeofExprType(Expr *E, SourceLocation Loc); 1162 QualType BuildDecltypeType(Expr *E, SourceLocation Loc); 1163 QualType BuildUnaryTransformType(QualType BaseType, 1164 UnaryTransformType::UTTKind UKind, 1165 SourceLocation Loc); 1166 1167 //===--------------------------------------------------------------------===// 1168 // Symbol table / Decl tracking callbacks: SemaDecl.cpp. 1169 // 1170 1171 /// List of decls defined in a function prototype. This contains EnumConstants 1172 /// that incorrectly end up in translation unit scope because there is no 1173 /// function to pin them on. ActOnFunctionDeclarator reads this list and patches 1174 /// them into the FunctionDecl. 1175 std::vector<NamedDecl*> DeclsInPrototypeScope; 1176 /// Nonzero if we are currently parsing a function declarator. This is a counter 1177 /// as opposed to a boolean so we can deal with nested function declarators 1178 /// such as: 1179 /// void f(void (*g)(), ...) 1180 unsigned InFunctionDeclarator; 1181 1182 DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = 0); 1183 1184 void DiagnoseUseOfUnimplementedSelectors(); 1185 1186 bool isSimpleTypeSpecifier(tok::TokenKind Kind) const; 1187 1188 ParsedType getTypeName(IdentifierInfo &II, SourceLocation NameLoc, 1189 Scope *S, CXXScopeSpec *SS = 0, 1190 bool isClassName = false, 1191 bool HasTrailingDot = false, 1192 ParsedType ObjectType = ParsedType(), 1193 bool IsCtorOrDtorName = false, 1194 bool WantNontrivialTypeSourceInfo = false, 1195 IdentifierInfo **CorrectedII = 0); 1196 TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S); 1197 bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S); 1198 bool DiagnoseUnknownTypeName(IdentifierInfo *&II, 1199 SourceLocation IILoc, 1200 Scope *S, 1201 CXXScopeSpec *SS, 1202 ParsedType &SuggestedType); 1203 1204 /// \brief Describes the result of the name lookup and resolution performed 1205 /// by \c ClassifyName(). 1206 enum NameClassificationKind { 1207 NC_Unknown, 1208 NC_Error, 1209 NC_Keyword, 1210 NC_Type, 1211 NC_Expression, 1212 NC_NestedNameSpecifier, 1213 NC_TypeTemplate, 1214 NC_FunctionTemplate 1215 }; 1216 1217 class NameClassification { 1218 NameClassificationKind Kind; 1219 ExprResult Expr; 1220 TemplateName Template; 1221 ParsedType Type; 1222 const IdentifierInfo *Keyword; 1223 1224 explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {} 1225 1226 public: 1227 NameClassification(ExprResult Expr) : Kind(NC_Expression), Expr(Expr) {} 1228 1229 NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {} 1230 1231 NameClassification(const IdentifierInfo *Keyword) 1232 : Kind(NC_Keyword), Keyword(Keyword) { } 1233 1234 static NameClassification Error() { 1235 return NameClassification(NC_Error); 1236 } 1237 1238 static NameClassification Unknown() { 1239 return NameClassification(NC_Unknown); 1240 } 1241 1242 static NameClassification NestedNameSpecifier() { 1243 return NameClassification(NC_NestedNameSpecifier); 1244 } 1245 1246 static NameClassification TypeTemplate(TemplateName Name) { 1247 NameClassification Result(NC_TypeTemplate); 1248 Result.Template = Name; 1249 return Result; 1250 } 1251 1252 static NameClassification FunctionTemplate(TemplateName Name) { 1253 NameClassification Result(NC_FunctionTemplate); 1254 Result.Template = Name; 1255 return Result; 1256 } 1257 1258 NameClassificationKind getKind() const { return Kind; } 1259 1260 ParsedType getType() const { 1261 assert(Kind == NC_Type); 1262 return Type; 1263 } 1264 1265 ExprResult getExpression() const { 1266 assert(Kind == NC_Expression); 1267 return Expr; 1268 } 1269 1270 TemplateName getTemplateName() const { 1271 assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate); 1272 return Template; 1273 } 1274 1275 TemplateNameKind getTemplateNameKind() const { 1276 assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate); 1277 return Kind == NC_TypeTemplate? TNK_Type_template : TNK_Function_template; 1278 } 1279 }; 1280 1281 /// \brief Perform name lookup on the given name, classifying it based on 1282 /// the results of name lookup and the following token. 1283 /// 1284 /// This routine is used by the parser to resolve identifiers and help direct 1285 /// parsing. When the identifier cannot be found, this routine will attempt 1286 /// to correct the typo and classify based on the resulting name. 1287 /// 1288 /// \param S The scope in which we're performing name lookup. 1289 /// 1290 /// \param SS The nested-name-specifier that precedes the name. 1291 /// 1292 /// \param Name The identifier. If typo correction finds an alternative name, 1293 /// this pointer parameter will be updated accordingly. 1294 /// 1295 /// \param NameLoc The location of the identifier. 1296 /// 1297 /// \param NextToken The token following the identifier. Used to help 1298 /// disambiguate the name. 1299 /// 1300 /// \param IsAddressOfOperand True if this name is the operand of a unary 1301 /// address of ('&') expression, assuming it is classified as an 1302 /// expression. 1303 /// 1304 /// \param CCC The correction callback, if typo correction is desired. 1305 NameClassification ClassifyName(Scope *S, 1306 CXXScopeSpec &SS, 1307 IdentifierInfo *&Name, 1308 SourceLocation NameLoc, 1309 const Token &NextToken, 1310 bool IsAddressOfOperand, 1311 CorrectionCandidateCallback *CCC = 0); 1312 1313 Decl *ActOnDeclarator(Scope *S, Declarator &D); 1314 1315 NamedDecl *HandleDeclarator(Scope *S, Declarator &D, 1316 MultiTemplateParamsArg TemplateParameterLists); 1317 void RegisterLocallyScopedExternCDecl(NamedDecl *ND, 1318 const LookupResult &Previous, 1319 Scope *S); 1320 bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info); 1321 bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, 1322 DeclarationName Name, 1323 SourceLocation Loc); 1324 void DiagnoseFunctionSpecifiers(Declarator& D); 1325 void CheckShadow(Scope *S, VarDecl *D, const LookupResult& R); 1326 void CheckShadow(Scope *S, VarDecl *D); 1327 void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange); 1328 void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D); 1329 NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, 1330 TypeSourceInfo *TInfo, 1331 LookupResult &Previous); 1332 NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D, 1333 LookupResult &Previous, bool &Redeclaration); 1334 NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, 1335 TypeSourceInfo *TInfo, 1336 LookupResult &Previous, 1337 MultiTemplateParamsArg TemplateParamLists); 1338 // Returns true if the variable declaration is a redeclaration 1339 bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous); 1340 void CheckCompleteVariableDeclaration(VarDecl *var); 1341 void ActOnStartFunctionDeclarator(); 1342 void ActOnEndFunctionDeclarator(); 1343 NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, 1344 TypeSourceInfo *TInfo, 1345 LookupResult &Previous, 1346 MultiTemplateParamsArg TemplateParamLists, 1347 bool &AddToScope); 1348 bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD); 1349 void checkVoidParamDecl(ParmVarDecl *Param); 1350 1351 bool CheckConstexprFunctionDecl(const FunctionDecl *FD); 1352 bool CheckConstexprFunctionBody(const FunctionDecl *FD, Stmt *Body); 1353 1354 void DiagnoseHiddenVirtualMethods(CXXRecordDecl *DC, CXXMethodDecl *MD); 1355 // Returns true if the function declaration is a redeclaration 1356 bool CheckFunctionDeclaration(Scope *S, 1357 FunctionDecl *NewFD, LookupResult &Previous, 1358 bool IsExplicitSpecialization); 1359 void CheckMain(FunctionDecl *FD, const DeclSpec &D); 1360 Decl *ActOnParamDeclarator(Scope *S, Declarator &D); 1361 ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC, 1362 SourceLocation Loc, 1363 QualType T); 1364 ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc, 1365 SourceLocation NameLoc, IdentifierInfo *Name, 1366 QualType T, TypeSourceInfo *TSInfo, 1367 StorageClass SC, StorageClass SCAsWritten); 1368 void ActOnParamDefaultArgument(Decl *param, 1369 SourceLocation EqualLoc, 1370 Expr *defarg); 1371 void ActOnParamUnparsedDefaultArgument(Decl *param, 1372 SourceLocation EqualLoc, 1373 SourceLocation ArgLoc); 1374 void ActOnParamDefaultArgumentError(Decl *param); 1375 bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, 1376 SourceLocation EqualLoc); 1377 1378 void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit, 1379 bool TypeMayContainAuto); 1380 void ActOnUninitializedDecl(Decl *dcl, bool TypeMayContainAuto); 1381 void ActOnInitializerError(Decl *Dcl); 1382 void ActOnCXXForRangeDecl(Decl *D); 1383 void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc); 1384 void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc); 1385 void FinalizeDeclaration(Decl *D); 1386 DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, 1387 Decl **Group, 1388 unsigned NumDecls); 1389 DeclGroupPtrTy BuildDeclaratorGroup(Decl **Group, unsigned NumDecls, 1390 bool TypeMayContainAuto = true); 1391 1392 /// Should be called on all declarations that might have attached 1393 /// documentation comments. 1394 void ActOnDocumentableDecl(Decl *D); 1395 void ActOnDocumentableDecls(Decl **Group, unsigned NumDecls); 1396 1397 void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, 1398 SourceLocation LocAfterDecls); 1399 void CheckForFunctionRedefinition(FunctionDecl *FD); 1400 Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D); 1401 Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D); 1402 void ActOnStartOfObjCMethodDef(Scope *S, Decl *D); 1403 bool isObjCMethodDecl(Decl *D) { 1404 return D && isa<ObjCMethodDecl>(D); 1405 } 1406 1407 /// \brief Determine whether we can skip parsing the body of a function 1408 /// definition, assuming we don't care about analyzing its body or emitting 1409 /// code for that function. 1410 /// 1411 /// This will be \c false only if we may need the body of the function in 1412 /// order to parse the rest of the program (for instance, if it is 1413 /// \c constexpr in C++11 or has an 'auto' return type in C++14). 1414 bool canSkipFunctionBody(Decl *D); 1415 1416 void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope); 1417 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body); 1418 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation); 1419 Decl *ActOnSkippedFunctionBody(Decl *Decl); 1420 1421 /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an 1422 /// attribute for which parsing is delayed. 1423 void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs); 1424 1425 /// \brief Diagnose any unused parameters in the given sequence of 1426 /// ParmVarDecl pointers. 1427 void DiagnoseUnusedParameters(ParmVarDecl * const *Begin, 1428 ParmVarDecl * const *End); 1429 1430 /// \brief Diagnose whether the size of parameters or return value of a 1431 /// function or obj-c method definition is pass-by-value and larger than a 1432 /// specified threshold. 1433 void DiagnoseSizeOfParametersAndReturnValue(ParmVarDecl * const *Begin, 1434 ParmVarDecl * const *End, 1435 QualType ReturnTy, 1436 NamedDecl *D); 1437 1438 void DiagnoseInvalidJumps(Stmt *Body); 1439 Decl *ActOnFileScopeAsmDecl(Expr *expr, 1440 SourceLocation AsmLoc, 1441 SourceLocation RParenLoc); 1442 1443 /// \brief The parser has processed a module import declaration. 1444 /// 1445 /// \param AtLoc The location of the '@' symbol, if any. 1446 /// 1447 /// \param ImportLoc The location of the 'import' keyword. 1448 /// 1449 /// \param Path The module access path. 1450 DeclResult ActOnModuleImport(SourceLocation AtLoc, SourceLocation ImportLoc, 1451 ModuleIdPath Path); 1452 1453 /// \brief Create an implicit import of the given module at the given 1454 /// source location. 1455 /// 1456 /// This routine is typically used for error recovery, when the entity found 1457 /// by name lookup is actually hidden within a module that we know about but 1458 /// the user has forgotten to import. 1459 void createImplicitModuleImport(SourceLocation Loc, Module *Mod); 1460 1461 /// \brief Retrieve a suitable printing policy. 1462 PrintingPolicy getPrintingPolicy() const { 1463 return getPrintingPolicy(Context, PP); 1464 } 1465 1466 /// \brief Retrieve a suitable printing policy. 1467 static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx, 1468 const Preprocessor &PP); 1469 1470 /// Scope actions. 1471 void ActOnPopScope(SourceLocation Loc, Scope *S); 1472 void ActOnTranslationUnitScope(Scope *S); 1473 1474 Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, 1475 DeclSpec &DS); 1476 Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, 1477 DeclSpec &DS, 1478 MultiTemplateParamsArg TemplateParams); 1479 1480 Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, 1481 AccessSpecifier AS, 1482 RecordDecl *Record); 1483 1484 Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS, 1485 RecordDecl *Record); 1486 1487 bool isAcceptableTagRedeclaration(const TagDecl *Previous, 1488 TagTypeKind NewTag, bool isDefinition, 1489 SourceLocation NewTagLoc, 1490 const IdentifierInfo &Name); 1491 1492 enum TagUseKind { 1493 TUK_Reference, // Reference to a tag: 'struct foo *X;' 1494 TUK_Declaration, // Fwd decl of a tag: 'struct foo;' 1495 TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;' 1496 TUK_Friend // Friend declaration: 'friend struct foo;' 1497 }; 1498 1499 Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, 1500 SourceLocation KWLoc, CXXScopeSpec &SS, 1501 IdentifierInfo *Name, SourceLocation NameLoc, 1502 AttributeList *Attr, AccessSpecifier AS, 1503 SourceLocation ModulePrivateLoc, 1504 MultiTemplateParamsArg TemplateParameterLists, 1505 bool &OwnedDecl, bool &IsDependent, 1506 SourceLocation ScopedEnumKWLoc, 1507 bool ScopedEnumUsesClassTag, TypeResult UnderlyingType); 1508 1509 Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc, 1510 unsigned TagSpec, SourceLocation TagLoc, 1511 CXXScopeSpec &SS, 1512 IdentifierInfo *Name, SourceLocation NameLoc, 1513 AttributeList *Attr, 1514 MultiTemplateParamsArg TempParamLists); 1515 1516 TypeResult ActOnDependentTag(Scope *S, 1517 unsigned TagSpec, 1518 TagUseKind TUK, 1519 const CXXScopeSpec &SS, 1520 IdentifierInfo *Name, 1521 SourceLocation TagLoc, 1522 SourceLocation NameLoc); 1523 1524 void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart, 1525 IdentifierInfo *ClassName, 1526 SmallVectorImpl<Decl *> &Decls); 1527 Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart, 1528 Declarator &D, Expr *BitfieldWidth); 1529 1530 FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, 1531 Declarator &D, Expr *BitfieldWidth, 1532 InClassInitStyle InitStyle, 1533 AccessSpecifier AS); 1534 1535 FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T, 1536 TypeSourceInfo *TInfo, 1537 RecordDecl *Record, SourceLocation Loc, 1538 bool Mutable, Expr *BitfieldWidth, 1539 InClassInitStyle InitStyle, 1540 SourceLocation TSSL, 1541 AccessSpecifier AS, NamedDecl *PrevDecl, 1542 Declarator *D = 0); 1543 1544 bool CheckNontrivialField(FieldDecl *FD); 1545 void DiagnoseNontrivial(const CXXRecordDecl *Record, CXXSpecialMember CSM); 1546 bool SpecialMemberIsTrivial(CXXMethodDecl *MD, CXXSpecialMember CSM, 1547 bool Diagnose = false); 1548 CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD); 1549 void ActOnLastBitfield(SourceLocation DeclStart, 1550 SmallVectorImpl<Decl *> &AllIvarDecls); 1551 Decl *ActOnIvar(Scope *S, SourceLocation DeclStart, 1552 Declarator &D, Expr *BitfieldWidth, 1553 tok::ObjCKeywordKind visibility); 1554 1555 // This is used for both record definitions and ObjC interface declarations. 1556 void ActOnFields(Scope* S, SourceLocation RecLoc, Decl *TagDecl, 1557 ArrayRef<Decl *> Fields, 1558 SourceLocation LBrac, SourceLocation RBrac, 1559 AttributeList *AttrList); 1560 1561 /// ActOnTagStartDefinition - Invoked when we have entered the 1562 /// scope of a tag's definition (e.g., for an enumeration, class, 1563 /// struct, or union). 1564 void ActOnTagStartDefinition(Scope *S, Decl *TagDecl); 1565 1566 Decl *ActOnObjCContainerStartDefinition(Decl *IDecl); 1567 1568 /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a 1569 /// C++ record definition's base-specifiers clause and are starting its 1570 /// member declarations. 1571 void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl, 1572 SourceLocation FinalLoc, 1573 SourceLocation LBraceLoc); 1574 1575 /// ActOnTagFinishDefinition - Invoked once we have finished parsing 1576 /// the definition of a tag (enumeration, class, struct, or union). 1577 void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, 1578 SourceLocation RBraceLoc); 1579 1580 void ActOnObjCContainerFinishDefinition(); 1581 1582 /// \brief Invoked when we must temporarily exit the objective-c container 1583 /// scope for parsing/looking-up C constructs. 1584 /// 1585 /// Must be followed by a call to \see ActOnObjCReenterContainerContext 1586 void ActOnObjCTemporaryExitContainerContext(DeclContext *DC); 1587 void ActOnObjCReenterContainerContext(DeclContext *DC); 1588 1589 /// ActOnTagDefinitionError - Invoked when there was an unrecoverable 1590 /// error parsing the definition of a tag. 1591 void ActOnTagDefinitionError(Scope *S, Decl *TagDecl); 1592 1593 EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum, 1594 EnumConstantDecl *LastEnumConst, 1595 SourceLocation IdLoc, 1596 IdentifierInfo *Id, 1597 Expr *val); 1598 bool CheckEnumUnderlyingType(TypeSourceInfo *TI); 1599 bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped, 1600 QualType EnumUnderlyingTy, const EnumDecl *Prev); 1601 1602 Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, 1603 SourceLocation IdLoc, IdentifierInfo *Id, 1604 AttributeList *Attrs, 1605 SourceLocation EqualLoc, Expr *Val); 1606 void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, 1607 SourceLocation RBraceLoc, Decl *EnumDecl, 1608 Decl **Elements, unsigned NumElements, 1609 Scope *S, AttributeList *Attr); 1610 1611 DeclContext *getContainingDC(DeclContext *DC); 1612 1613 /// Set the current declaration context until it gets popped. 1614 void PushDeclContext(Scope *S, DeclContext *DC); 1615 void PopDeclContext(); 1616 1617 /// EnterDeclaratorContext - Used when we must lookup names in the context 1618 /// of a declarator's nested name specifier. 1619 void EnterDeclaratorContext(Scope *S, DeclContext *DC); 1620 void ExitDeclaratorContext(Scope *S); 1621 1622 /// Push the parameters of D, which must be a function, into scope. 1623 void ActOnReenterFunctionContext(Scope* S, Decl* D); 1624 void ActOnExitFunctionContext(); 1625 1626 DeclContext *getFunctionLevelDeclContext(); 1627 1628 /// getCurFunctionDecl - If inside of a function body, this returns a pointer 1629 /// to the function decl for the function being parsed. If we're currently 1630 /// in a 'block', this returns the containing context. 1631 FunctionDecl *getCurFunctionDecl(); 1632 1633 /// getCurMethodDecl - If inside of a method body, this returns a pointer to 1634 /// the method decl for the method being parsed. If we're currently 1635 /// in a 'block', this returns the containing context. 1636 ObjCMethodDecl *getCurMethodDecl(); 1637 1638 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method 1639 /// or C function we're in, otherwise return null. If we're currently 1640 /// in a 'block', this returns the containing context. 1641 NamedDecl *getCurFunctionOrMethodDecl(); 1642 1643 /// Add this decl to the scope shadowed decl chains. 1644 void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true); 1645 1646 /// \brief Make the given externally-produced declaration visible at the 1647 /// top level scope. 1648 /// 1649 /// \param D The externally-produced declaration to push. 1650 /// 1651 /// \param Name The name of the externally-produced declaration. 1652 void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name); 1653 1654 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true 1655 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns 1656 /// true if 'D' belongs to the given declaration context. 1657 /// 1658 /// \param ExplicitInstantiationOrSpecialization When true, we are checking 1659 /// whether the declaration is in scope for the purposes of explicit template 1660 /// instantiation or specialization. The default is false. 1661 bool isDeclInScope(NamedDecl *&D, DeclContext *Ctx, Scope *S = 0, 1662 bool ExplicitInstantiationOrSpecialization = false); 1663 1664 /// Finds the scope corresponding to the given decl context, if it 1665 /// happens to be an enclosing scope. Otherwise return NULL. 1666 static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC); 1667 1668 /// Subroutines of ActOnDeclarator(). 1669 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T, 1670 TypeSourceInfo *TInfo); 1671 bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New); 1672 1673 /// Attribute merging methods. Return true if a new attribute was added. 1674 AvailabilityAttr *mergeAvailabilityAttr(NamedDecl *D, SourceRange Range, 1675 IdentifierInfo *Platform, 1676 VersionTuple Introduced, 1677 VersionTuple Deprecated, 1678 VersionTuple Obsoleted, 1679 bool IsUnavailable, 1680 StringRef Message, 1681 bool Override); 1682 VisibilityAttr *mergeVisibilityAttr(Decl *D, SourceRange Range, 1683 VisibilityAttr::VisibilityType Vis); 1684 DLLImportAttr *mergeDLLImportAttr(Decl *D, SourceRange Range); 1685 DLLExportAttr *mergeDLLExportAttr(Decl *D, SourceRange Range); 1686 FormatAttr *mergeFormatAttr(Decl *D, SourceRange Range, StringRef Format, 1687 int FormatIdx, int FirstArg); 1688 SectionAttr *mergeSectionAttr(Decl *D, SourceRange Range, StringRef Name); 1689 bool mergeDeclAttribute(NamedDecl *New, InheritableAttr *Attr, 1690 bool Override); 1691 1692 /// \brief Describes the kind of merge to perform for availability 1693 /// attributes (including "deprecated", "unavailable", and "availability"). 1694 enum AvailabilityMergeKind { 1695 /// \brief Don't merge availability attributes at all. 1696 AMK_None, 1697 /// \brief Merge availability attributes for a redeclaration, which requires 1698 /// an exact match. 1699 AMK_Redeclaration, 1700 /// \brief Merge availability attributes for an override, which requires 1701 /// an exact match or a weakening of constraints. 1702 AMK_Override 1703 }; 1704 1705 void mergeDeclAttributes(NamedDecl *New, Decl *Old, 1706 AvailabilityMergeKind AMK = AMK_Redeclaration); 1707 void MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls); 1708 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old, Scope *S); 1709 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old, 1710 Scope *S); 1711 void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old); 1712 void MergeVarDecl(VarDecl *New, LookupResult &OldDecls); 1713 void MergeVarDeclTypes(VarDecl *New, VarDecl *Old); 1714 void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old); 1715 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S); 1716 1717 // AssignmentAction - This is used by all the assignment diagnostic functions 1718 // to represent what is actually causing the operation 1719 enum AssignmentAction { 1720 AA_Assigning, 1721 AA_Passing, 1722 AA_Returning, 1723 AA_Converting, 1724 AA_Initializing, 1725 AA_Sending, 1726 AA_Casting 1727 }; 1728 1729 /// C++ Overloading. 1730 enum OverloadKind { 1731 /// This is a legitimate overload: the existing declarations are 1732 /// functions or function templates with different signatures. 1733 Ovl_Overload, 1734 1735 /// This is not an overload because the signature exactly matches 1736 /// an existing declaration. 1737 Ovl_Match, 1738 1739 /// This is not an overload because the lookup results contain a 1740 /// non-function. 1741 Ovl_NonFunction 1742 }; 1743 OverloadKind CheckOverload(Scope *S, 1744 FunctionDecl *New, 1745 const LookupResult &OldDecls, 1746 NamedDecl *&OldDecl, 1747 bool IsForUsingDecl); 1748 bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl); 1749 1750 /// \brief Checks availability of the function depending on the current 1751 /// function context.Inside an unavailable function,unavailability is ignored. 1752 /// 1753 /// \returns true if \p FD is unavailable and current context is inside 1754 /// an available function, false otherwise. 1755 bool isFunctionConsideredUnavailable(FunctionDecl *FD); 1756 1757 ImplicitConversionSequence 1758 TryImplicitConversion(Expr *From, QualType ToType, 1759 bool SuppressUserConversions, 1760 bool AllowExplicit, 1761 bool InOverloadResolution, 1762 bool CStyle, 1763 bool AllowObjCWritebackConversion); 1764 1765 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType); 1766 bool IsFloatingPointPromotion(QualType FromType, QualType ToType); 1767 bool IsComplexPromotion(QualType FromType, QualType ToType); 1768 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType, 1769 bool InOverloadResolution, 1770 QualType& ConvertedType, bool &IncompatibleObjC); 1771 bool isObjCPointerConversion(QualType FromType, QualType ToType, 1772 QualType& ConvertedType, bool &IncompatibleObjC); 1773 bool isObjCWritebackConversion(QualType FromType, QualType ToType, 1774 QualType &ConvertedType); 1775 bool IsBlockPointerConversion(QualType FromType, QualType ToType, 1776 QualType& ConvertedType); 1777 bool FunctionArgTypesAreEqual(const FunctionProtoType *OldType, 1778 const FunctionProtoType *NewType, 1779 unsigned *ArgPos = 0); 1780 void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, 1781 QualType FromType, QualType ToType); 1782 1783 CastKind PrepareCastToObjCObjectPointer(ExprResult &E); 1784 bool CheckPointerConversion(Expr *From, QualType ToType, 1785 CastKind &Kind, 1786 CXXCastPath& BasePath, 1787 bool IgnoreBaseAccess); 1788 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType, 1789 bool InOverloadResolution, 1790 QualType &ConvertedType); 1791 bool CheckMemberPointerConversion(Expr *From, QualType ToType, 1792 CastKind &Kind, 1793 CXXCastPath &BasePath, 1794 bool IgnoreBaseAccess); 1795 bool IsQualificationConversion(QualType FromType, QualType ToType, 1796 bool CStyle, bool &ObjCLifetimeConversion); 1797 bool IsNoReturnConversion(QualType FromType, QualType ToType, 1798 QualType &ResultTy); 1799 bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType); 1800 1801 1802 ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity, 1803 const VarDecl *NRVOCandidate, 1804 QualType ResultType, 1805 Expr *Value, 1806 bool AllowNRVO = true); 1807 1808 bool CanPerformCopyInitialization(const InitializedEntity &Entity, 1809 ExprResult Init); 1810 ExprResult PerformCopyInitialization(const InitializedEntity &Entity, 1811 SourceLocation EqualLoc, 1812 ExprResult Init, 1813 bool TopLevelOfInitList = false, 1814 bool AllowExplicit = false); 1815 ExprResult PerformObjectArgumentInitialization(Expr *From, 1816 NestedNameSpecifier *Qualifier, 1817 NamedDecl *FoundDecl, 1818 CXXMethodDecl *Method); 1819 1820 ExprResult PerformContextuallyConvertToBool(Expr *From); 1821 ExprResult PerformContextuallyConvertToObjCPointer(Expr *From); 1822 1823 /// Contexts in which a converted constant expression is required. 1824 enum CCEKind { 1825 CCEK_CaseValue, ///< Expression in a case label. 1826 CCEK_Enumerator, ///< Enumerator value with fixed underlying type. 1827 CCEK_TemplateArg ///< Value of a non-type template parameter. 1828 }; 1829 ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, 1830 llvm::APSInt &Value, CCEKind CCE); 1831 1832 /// \brief Abstract base class used to diagnose problems that occur while 1833 /// trying to convert an expression to integral or enumeration type. 1834 class ICEConvertDiagnoser { 1835 public: 1836 bool Suppress; 1837 bool SuppressConversion; 1838 1839 ICEConvertDiagnoser(bool Suppress = false, 1840 bool SuppressConversion = false) 1841 : Suppress(Suppress), SuppressConversion(SuppressConversion) { } 1842 1843 /// \brief Emits a diagnostic complaining that the expression does not have 1844 /// integral or enumeration type. 1845 virtual DiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, 1846 QualType T) = 0; 1847 1848 /// \brief Emits a diagnostic when the expression has incomplete class type. 1849 virtual DiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, 1850 QualType T) = 0; 1851 1852 /// \brief Emits a diagnostic when the only matching conversion function 1853 /// is explicit. 1854 virtual DiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, 1855 QualType T, 1856 QualType ConvTy) = 0; 1857 1858 /// \brief Emits a note for the explicit conversion function. 1859 virtual DiagnosticBuilder 1860 noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; 1861 1862 /// \brief Emits a diagnostic when there are multiple possible conversion 1863 /// functions. 1864 virtual DiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, 1865 QualType T) = 0; 1866 1867 /// \brief Emits a note for one of the candidate conversions. 1868 virtual DiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, 1869 QualType ConvTy) = 0; 1870 1871 /// \brief Emits a diagnostic when we picked a conversion function 1872 /// (for cases when we are not allowed to pick a conversion function). 1873 virtual DiagnosticBuilder diagnoseConversion(Sema &S, SourceLocation Loc, 1874 QualType T, 1875 QualType ConvTy) = 0; 1876 1877 virtual ~ICEConvertDiagnoser() {} 1878 }; 1879 1880 ExprResult 1881 ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *FromE, 1882 ICEConvertDiagnoser &Diagnoser, 1883 bool AllowScopedEnumerations); 1884 1885 enum ObjCSubscriptKind { 1886 OS_Array, 1887 OS_Dictionary, 1888 OS_Error 1889 }; 1890 ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE); 1891 1892 // Note that LK_String is intentionally after the other literals, as 1893 // this is used for diagnostics logic. 1894 enum ObjCLiteralKind { 1895 LK_Array, 1896 LK_Dictionary, 1897 LK_Numeric, 1898 LK_Boxed, 1899 LK_String, 1900 LK_Block, 1901 LK_None 1902 }; 1903 ObjCLiteralKind CheckLiteralKind(Expr *FromE); 1904 1905 ExprResult PerformObjectMemberConversion(Expr *From, 1906 NestedNameSpecifier *Qualifier, 1907 NamedDecl *FoundDecl, 1908 NamedDecl *Member); 1909 1910 // Members have to be NamespaceDecl* or TranslationUnitDecl*. 1911 // TODO: make this is a typesafe union. 1912 typedef llvm::SmallPtrSet<DeclContext *, 16> AssociatedNamespaceSet; 1913 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet; 1914 1915 void AddOverloadCandidate(FunctionDecl *Function, 1916 DeclAccessPair FoundDecl, 1917 ArrayRef<Expr *> Args, 1918 OverloadCandidateSet& CandidateSet, 1919 bool SuppressUserConversions = false, 1920 bool PartialOverloading = false, 1921 bool AllowExplicit = false); 1922 void AddFunctionCandidates(const UnresolvedSetImpl &Functions, 1923 ArrayRef<Expr *> Args, 1924 OverloadCandidateSet& CandidateSet, 1925 bool SuppressUserConversions = false, 1926 TemplateArgumentListInfo *ExplicitTemplateArgs = 0); 1927 void AddMethodCandidate(DeclAccessPair FoundDecl, 1928 QualType ObjectType, 1929 Expr::Classification ObjectClassification, 1930 Expr **Args, unsigned NumArgs, 1931 OverloadCandidateSet& CandidateSet, 1932 bool SuppressUserConversion = false); 1933 void AddMethodCandidate(CXXMethodDecl *Method, 1934 DeclAccessPair FoundDecl, 1935 CXXRecordDecl *ActingContext, QualType ObjectType, 1936 Expr::Classification ObjectClassification, 1937 ArrayRef<Expr *> Args, 1938 OverloadCandidateSet& CandidateSet, 1939 bool SuppressUserConversions = false); 1940 void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, 1941 DeclAccessPair FoundDecl, 1942 CXXRecordDecl *ActingContext, 1943 TemplateArgumentListInfo *ExplicitTemplateArgs, 1944 QualType ObjectType, 1945 Expr::Classification ObjectClassification, 1946 ArrayRef<Expr *> Args, 1947 OverloadCandidateSet& CandidateSet, 1948 bool SuppressUserConversions = false); 1949 void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate, 1950 DeclAccessPair FoundDecl, 1951 TemplateArgumentListInfo *ExplicitTemplateArgs, 1952 ArrayRef<Expr *> Args, 1953 OverloadCandidateSet& CandidateSet, 1954 bool SuppressUserConversions = false); 1955 void AddConversionCandidate(CXXConversionDecl *Conversion, 1956 DeclAccessPair FoundDecl, 1957 CXXRecordDecl *ActingContext, 1958 Expr *From, QualType ToType, 1959 OverloadCandidateSet& CandidateSet); 1960 void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate, 1961 DeclAccessPair FoundDecl, 1962 CXXRecordDecl *ActingContext, 1963 Expr *From, QualType ToType, 1964 OverloadCandidateSet &CandidateSet); 1965 void AddSurrogateCandidate(CXXConversionDecl *Conversion, 1966 DeclAccessPair FoundDecl, 1967 CXXRecordDecl *ActingContext, 1968 const FunctionProtoType *Proto, 1969 Expr *Object, ArrayRef<Expr *> Args, 1970 OverloadCandidateSet& CandidateSet); 1971 void AddMemberOperatorCandidates(OverloadedOperatorKind Op, 1972 SourceLocation OpLoc, 1973 Expr **Args, unsigned NumArgs, 1974 OverloadCandidateSet& CandidateSet, 1975 SourceRange OpRange = SourceRange()); 1976 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys, 1977 Expr **Args, unsigned NumArgs, 1978 OverloadCandidateSet& CandidateSet, 1979 bool IsAssignmentOperator = false, 1980 unsigned NumContextualBoolArguments = 0); 1981 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, 1982 SourceLocation OpLoc, 1983 Expr **Args, unsigned NumArgs, 1984 OverloadCandidateSet& CandidateSet); 1985 void AddArgumentDependentLookupCandidates(DeclarationName Name, 1986 bool Operator, SourceLocation Loc, 1987 ArrayRef<Expr *> Args, 1988 TemplateArgumentListInfo *ExplicitTemplateArgs, 1989 OverloadCandidateSet& CandidateSet, 1990 bool PartialOverloading = false); 1991 1992 // Emit as a 'note' the specific overload candidate 1993 void NoteOverloadCandidate(FunctionDecl *Fn, QualType DestType = QualType()); 1994 1995 // Emit as a series of 'note's all template and non-templates 1996 // identified by the expression Expr 1997 void NoteAllOverloadCandidates(Expr* E, QualType DestType = QualType()); 1998 1999 // [PossiblyAFunctionType] --> [Return] 2000 // NonFunctionType --> NonFunctionType 2001 // R (A) --> R(A) 2002 // R (*)(A) --> R (A) 2003 // R (&)(A) --> R (A) 2004 // R (S::*)(A) --> R (A) 2005 QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType); 2006 2007 FunctionDecl * 2008 ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, 2009 QualType TargetType, 2010 bool Complain, 2011 DeclAccessPair &Found, 2012 bool *pHadMultipleCandidates = 0); 2013 2014 FunctionDecl *ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl, 2015 bool Complain = false, 2016 DeclAccessPair* Found = 0); 2017 2018 bool ResolveAndFixSingleFunctionTemplateSpecialization( 2019 ExprResult &SrcExpr, 2020 bool DoFunctionPointerConverion = false, 2021 bool Complain = false, 2022 const SourceRange& OpRangeForComplaining = SourceRange(), 2023 QualType DestTypeForComplaining = QualType(), 2024 unsigned DiagIDForComplaining = 0); 2025 2026 2027 Expr *FixOverloadedFunctionReference(Expr *E, 2028 DeclAccessPair FoundDecl, 2029 FunctionDecl *Fn); 2030 ExprResult FixOverloadedFunctionReference(ExprResult, 2031 DeclAccessPair FoundDecl, 2032 FunctionDecl *Fn); 2033 2034 void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE, 2035 ArrayRef<Expr *> Args, 2036 OverloadCandidateSet &CandidateSet, 2037 bool PartialOverloading = false); 2038 2039 // An enum used to represent the different possible results of building a 2040 // range-based for loop. 2041 enum ForRangeStatus { 2042 FRS_Success, 2043 FRS_NoViableFunction, 2044 FRS_DiagnosticIssued 2045 }; 2046 2047 // An enum to represent whether something is dealing with a call to begin() 2048 // or a call to end() in a range-based for loop. 2049 enum BeginEndFunction { 2050 BEF_begin, 2051 BEF_end 2052 }; 2053 2054 ForRangeStatus BuildForRangeBeginEndCall(Scope *S, SourceLocation Loc, 2055 SourceLocation RangeLoc, 2056 VarDecl *Decl, 2057 BeginEndFunction BEF, 2058 const DeclarationNameInfo &NameInfo, 2059 LookupResult &MemberLookup, 2060 OverloadCandidateSet *CandidateSet, 2061 Expr *Range, ExprResult *CallExpr); 2062 2063 ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn, 2064 UnresolvedLookupExpr *ULE, 2065 SourceLocation LParenLoc, 2066 Expr **Args, unsigned NumArgs, 2067 SourceLocation RParenLoc, 2068 Expr *ExecConfig, 2069 bool AllowTypoCorrection=true); 2070 2071 bool buildOverloadedCallSet(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE, 2072 Expr **Args, unsigned NumArgs, 2073 SourceLocation RParenLoc, 2074 OverloadCandidateSet *CandidateSet, 2075 ExprResult *Result); 2076 2077 ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, 2078 unsigned Opc, 2079 const UnresolvedSetImpl &Fns, 2080 Expr *input); 2081 2082 ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, 2083 unsigned Opc, 2084 const UnresolvedSetImpl &Fns, 2085 Expr *LHS, Expr *RHS); 2086 2087 ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, 2088 SourceLocation RLoc, 2089 Expr *Base,Expr *Idx); 2090 2091 ExprResult 2092 BuildCallToMemberFunction(Scope *S, Expr *MemExpr, 2093 SourceLocation LParenLoc, Expr **Args, 2094 unsigned NumArgs, SourceLocation RParenLoc); 2095 ExprResult 2096 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc, 2097 Expr **Args, unsigned NumArgs, 2098 SourceLocation RParenLoc); 2099 2100 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, 2101 SourceLocation OpLoc); 2102 2103 /// CheckCallReturnType - Checks that a call expression's return type is 2104 /// complete. Returns true on failure. The location passed in is the location 2105 /// that best represents the call. 2106 bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc, 2107 CallExpr *CE, FunctionDecl *FD); 2108 2109 /// Helpers for dealing with blocks and functions. 2110 bool CheckParmsForFunctionDef(ParmVarDecl **Param, ParmVarDecl **ParamEnd, 2111 bool CheckParameterNames); 2112 void CheckCXXDefaultArguments(FunctionDecl *FD); 2113 void CheckExtraCXXDefaultArguments(Declarator &D); 2114 Scope *getNonFieldDeclScope(Scope *S); 2115 2116 /// \name Name lookup 2117 /// 2118 /// These routines provide name lookup that is used during semantic 2119 /// analysis to resolve the various kinds of names (identifiers, 2120 /// overloaded operator names, constructor names, etc.) into zero or 2121 /// more declarations within a particular scope. The major entry 2122 /// points are LookupName, which performs unqualified name lookup, 2123 /// and LookupQualifiedName, which performs qualified name lookup. 2124 /// 2125 /// All name lookup is performed based on some specific criteria, 2126 /// which specify what names will be visible to name lookup and how 2127 /// far name lookup should work. These criteria are important both 2128 /// for capturing language semantics (certain lookups will ignore 2129 /// certain names, for example) and for performance, since name 2130 /// lookup is often a bottleneck in the compilation of C++. Name 2131 /// lookup criteria is specified via the LookupCriteria enumeration. 2132 /// 2133 /// The results of name lookup can vary based on the kind of name 2134 /// lookup performed, the current language, and the translation 2135 /// unit. In C, for example, name lookup will either return nothing 2136 /// (no entity found) or a single declaration. In C++, name lookup 2137 /// can additionally refer to a set of overloaded functions or 2138 /// result in an ambiguity. All of the possible results of name 2139 /// lookup are captured by the LookupResult class, which provides 2140 /// the ability to distinguish among them. 2141 //@{ 2142 2143 /// @brief Describes the kind of name lookup to perform. 2144 enum LookupNameKind { 2145 /// Ordinary name lookup, which finds ordinary names (functions, 2146 /// variables, typedefs, etc.) in C and most kinds of names 2147 /// (functions, variables, members, types, etc.) in C++. 2148 LookupOrdinaryName = 0, 2149 /// Tag name lookup, which finds the names of enums, classes, 2150 /// structs, and unions. 2151 LookupTagName, 2152 /// Label name lookup. 2153 LookupLabel, 2154 /// Member name lookup, which finds the names of 2155 /// class/struct/union members. 2156 LookupMemberName, 2157 /// Look up of an operator name (e.g., operator+) for use with 2158 /// operator overloading. This lookup is similar to ordinary name 2159 /// lookup, but will ignore any declarations that are class members. 2160 LookupOperatorName, 2161 /// Look up of a name that precedes the '::' scope resolution 2162 /// operator in C++. This lookup completely ignores operator, object, 2163 /// function, and enumerator names (C++ [basic.lookup.qual]p1). 2164 LookupNestedNameSpecifierName, 2165 /// Look up a namespace name within a C++ using directive or 2166 /// namespace alias definition, ignoring non-namespace names (C++ 2167 /// [basic.lookup.udir]p1). 2168 LookupNamespaceName, 2169 /// Look up all declarations in a scope with the given name, 2170 /// including resolved using declarations. This is appropriate 2171 /// for checking redeclarations for a using declaration. 2172 LookupUsingDeclName, 2173 /// Look up an ordinary name that is going to be redeclared as a 2174 /// name with linkage. This lookup ignores any declarations that 2175 /// are outside of the current scope unless they have linkage. See 2176 /// C99 6.2.2p4-5 and C++ [basic.link]p6. 2177 LookupRedeclarationWithLinkage, 2178 /// Look up the name of an Objective-C protocol. 2179 LookupObjCProtocolName, 2180 /// Look up implicit 'self' parameter of an objective-c method. 2181 LookupObjCImplicitSelfParam, 2182 /// \brief Look up any declaration with any name. 2183 LookupAnyName 2184 }; 2185 2186 /// \brief Specifies whether (or how) name lookup is being performed for a 2187 /// redeclaration (vs. a reference). 2188 enum RedeclarationKind { 2189 /// \brief The lookup is a reference to this name that is not for the 2190 /// purpose of redeclaring the name. 2191 NotForRedeclaration = 0, 2192 /// \brief The lookup results will be used for redeclaration of a name, 2193 /// if an entity by that name already exists. 2194 ForRedeclaration 2195 }; 2196 2197 /// \brief The possible outcomes of name lookup for a literal operator. 2198 enum LiteralOperatorLookupResult { 2199 /// \brief The lookup resulted in an error. 2200 LOLR_Error, 2201 /// \brief The lookup found a single 'cooked' literal operator, which 2202 /// expects a normal literal to be built and passed to it. 2203 LOLR_Cooked, 2204 /// \brief The lookup found a single 'raw' literal operator, which expects 2205 /// a string literal containing the spelling of the literal token. 2206 LOLR_Raw, 2207 /// \brief The lookup found an overload set of literal operator templates, 2208 /// which expect the characters of the spelling of the literal token to be 2209 /// passed as a non-type template argument pack. 2210 LOLR_Template 2211 }; 2212 2213 SpecialMemberOverloadResult *LookupSpecialMember(CXXRecordDecl *D, 2214 CXXSpecialMember SM, 2215 bool ConstArg, 2216 bool VolatileArg, 2217 bool RValueThis, 2218 bool ConstThis, 2219 bool VolatileThis); 2220 2221private: 2222 bool CppLookupName(LookupResult &R, Scope *S); 2223 2224 // \brief The set of known/encountered (unique, canonicalized) NamespaceDecls. 2225 // 2226 // The boolean value will be true to indicate that the namespace was loaded 2227 // from an AST/PCH file, or false otherwise. 2228 llvm::DenseMap<NamespaceDecl*, bool> KnownNamespaces; 2229 2230 /// \brief Whether we have already loaded known namespaces from an extenal 2231 /// source. 2232 bool LoadedExternalKnownNamespaces; 2233 2234public: 2235 /// \brief Look up a name, looking for a single declaration. Return 2236 /// null if the results were absent, ambiguous, or overloaded. 2237 /// 2238 /// It is preferable to use the elaborated form and explicitly handle 2239 /// ambiguity and overloaded. 2240 NamedDecl *LookupSingleName(Scope *S, DeclarationName Name, 2241 SourceLocation Loc, 2242 LookupNameKind NameKind, 2243 RedeclarationKind Redecl 2244 = NotForRedeclaration); 2245 bool LookupName(LookupResult &R, Scope *S, 2246 bool AllowBuiltinCreation = false); 2247 bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, 2248 bool InUnqualifiedLookup = false); 2249 bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, 2250 bool AllowBuiltinCreation = false, 2251 bool EnteringContext = false); 2252 ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc, 2253 RedeclarationKind Redecl 2254 = NotForRedeclaration); 2255 2256 void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, 2257 QualType T1, QualType T2, 2258 UnresolvedSetImpl &Functions); 2259 2260 LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, 2261 SourceLocation GnuLabelLoc = SourceLocation()); 2262 2263 DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class); 2264 CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class); 2265 CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class, 2266 unsigned Quals); 2267 CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals, 2268 bool RValueThis, unsigned ThisQuals); 2269 CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class, 2270 unsigned Quals); 2271 CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals, 2272 bool RValueThis, unsigned ThisQuals); 2273 CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class); 2274 2275 LiteralOperatorLookupResult LookupLiteralOperator(Scope *S, LookupResult &R, 2276 ArrayRef<QualType> ArgTys, 2277 bool AllowRawAndTemplate); 2278 bool isKnownName(StringRef name); 2279 2280 void ArgumentDependentLookup(DeclarationName Name, bool Operator, 2281 SourceLocation Loc, 2282 ArrayRef<Expr *> Args, 2283 ADLResult &Functions); 2284 2285 void LookupVisibleDecls(Scope *S, LookupNameKind Kind, 2286 VisibleDeclConsumer &Consumer, 2287 bool IncludeGlobalScope = true); 2288 void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind, 2289 VisibleDeclConsumer &Consumer, 2290 bool IncludeGlobalScope = true); 2291 2292 TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, 2293 Sema::LookupNameKind LookupKind, 2294 Scope *S, CXXScopeSpec *SS, 2295 CorrectionCandidateCallback &CCC, 2296 DeclContext *MemberContext = 0, 2297 bool EnteringContext = false, 2298 const ObjCObjectPointerType *OPT = 0); 2299 2300 void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc, 2301 ArrayRef<Expr *> Args, 2302 AssociatedNamespaceSet &AssociatedNamespaces, 2303 AssociatedClassSet &AssociatedClasses); 2304 2305 void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S, 2306 bool ConsiderLinkage, 2307 bool ExplicitInstantiationOrSpecialization); 2308 2309 bool DiagnoseAmbiguousLookup(LookupResult &Result); 2310 //@} 2311 2312 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id, 2313 SourceLocation IdLoc, 2314 bool TypoCorrection = false); 2315 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, 2316 Scope *S, bool ForRedeclaration, 2317 SourceLocation Loc); 2318 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, 2319 Scope *S); 2320 void AddKnownFunctionAttributes(FunctionDecl *FD); 2321 2322 // More parsing and symbol table subroutines. 2323 2324 // Decl attributes - this routine is the top level dispatcher. 2325 void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD, 2326 bool NonInheritable = true, bool Inheritable = true); 2327 void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL, 2328 bool NonInheritable = true, bool Inheritable = true); 2329 bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl, 2330 const AttributeList *AttrList); 2331 2332 void checkUnusedDeclAttributes(Declarator &D); 2333 2334 bool CheckRegparmAttr(const AttributeList &attr, unsigned &value); 2335 bool CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC, 2336 const FunctionDecl *FD = 0); 2337 bool CheckNoReturnAttr(const AttributeList &attr); 2338 2339 /// \brief Stmt attributes - this routine is the top level dispatcher. 2340 StmtResult ProcessStmtAttributes(Stmt *Stmt, AttributeList *Attrs, 2341 SourceRange Range); 2342 2343 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method, 2344 bool &IncompleteImpl, unsigned DiagID); 2345 void WarnConflictingTypedMethods(ObjCMethodDecl *Method, 2346 ObjCMethodDecl *MethodDecl, 2347 bool IsProtocolMethodDecl); 2348 2349 void CheckConflictingOverridingMethod(ObjCMethodDecl *Method, 2350 ObjCMethodDecl *Overridden, 2351 bool IsProtocolMethodDecl); 2352 2353 /// WarnExactTypedMethods - This routine issues a warning if method 2354 /// implementation declaration matches exactly that of its declaration. 2355 void WarnExactTypedMethods(ObjCMethodDecl *Method, 2356 ObjCMethodDecl *MethodDecl, 2357 bool IsProtocolMethodDecl); 2358 2359 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl, 2360 ObjCInterfaceDecl *IDecl); 2361 2362 typedef llvm::SmallPtrSet<Selector, 8> SelectorSet; 2363 typedef llvm::DenseMap<Selector, ObjCMethodDecl*> ProtocolsMethodsMap; 2364 2365 /// CheckProtocolMethodDefs - This routine checks unimplemented 2366 /// methods declared in protocol, and those referenced by it. 2367 void CheckProtocolMethodDefs(SourceLocation ImpLoc, 2368 ObjCProtocolDecl *PDecl, 2369 bool& IncompleteImpl, 2370 const SelectorSet &InsMap, 2371 const SelectorSet &ClsMap, 2372 ObjCContainerDecl *CDecl); 2373 2374 /// CheckImplementationIvars - This routine checks if the instance variables 2375 /// listed in the implelementation match those listed in the interface. 2376 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, 2377 ObjCIvarDecl **Fields, unsigned nIvars, 2378 SourceLocation Loc); 2379 2380 /// ImplMethodsVsClassMethods - This is main routine to warn if any method 2381 /// remains unimplemented in the class or category \@implementation. 2382 void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl, 2383 ObjCContainerDecl* IDecl, 2384 bool IncompleteImpl = false); 2385 2386 /// DiagnoseUnimplementedProperties - This routine warns on those properties 2387 /// which must be implemented by this implementation. 2388 void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl, 2389 ObjCContainerDecl *CDecl, 2390 const SelectorSet &InsMap); 2391 2392 /// DefaultSynthesizeProperties - This routine default synthesizes all 2393 /// properties which must be synthesized in the class's \@implementation. 2394 void DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl, 2395 ObjCInterfaceDecl *IDecl); 2396 void DefaultSynthesizeProperties(Scope *S, Decl *D); 2397 2398 /// CollectImmediateProperties - This routine collects all properties in 2399 /// the class and its conforming protocols; but not those it its super class. 2400 void CollectImmediateProperties(ObjCContainerDecl *CDecl, 2401 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap, 2402 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& SuperPropMap); 2403 2404 /// Called by ActOnProperty to handle \@property declarations in 2405 /// class extensions. 2406 Decl *HandlePropertyInClassExtension(Scope *S, 2407 SourceLocation AtLoc, 2408 SourceLocation LParenLoc, 2409 FieldDeclarator &FD, 2410 Selector GetterSel, 2411 Selector SetterSel, 2412 const bool isAssign, 2413 const bool isReadWrite, 2414 const unsigned Attributes, 2415 const unsigned AttributesAsWritten, 2416 bool *isOverridingProperty, 2417 TypeSourceInfo *T, 2418 tok::ObjCKeywordKind MethodImplKind); 2419 2420 /// Called by ActOnProperty and HandlePropertyInClassExtension to 2421 /// handle creating the ObjcPropertyDecl for a category or \@interface. 2422 ObjCPropertyDecl *CreatePropertyDecl(Scope *S, 2423 ObjCContainerDecl *CDecl, 2424 SourceLocation AtLoc, 2425 SourceLocation LParenLoc, 2426 FieldDeclarator &FD, 2427 Selector GetterSel, 2428 Selector SetterSel, 2429 const bool isAssign, 2430 const bool isReadWrite, 2431 const unsigned Attributes, 2432 const unsigned AttributesAsWritten, 2433 TypeSourceInfo *T, 2434 tok::ObjCKeywordKind MethodImplKind, 2435 DeclContext *lexicalDC = 0); 2436 2437 /// AtomicPropertySetterGetterRules - This routine enforces the rule (via 2438 /// warning) when atomic property has one but not the other user-declared 2439 /// setter or getter. 2440 void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl, 2441 ObjCContainerDecl* IDecl); 2442 2443 void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D); 2444 2445 void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID); 2446 2447 enum MethodMatchStrategy { 2448 MMS_loose, 2449 MMS_strict 2450 }; 2451 2452 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns 2453 /// true, or false, accordingly. 2454 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, 2455 const ObjCMethodDecl *PrevMethod, 2456 MethodMatchStrategy strategy = MMS_strict); 2457 2458 /// MatchAllMethodDeclarations - Check methods declaraed in interface or 2459 /// or protocol against those declared in their implementations. 2460 void MatchAllMethodDeclarations(const SelectorSet &InsMap, 2461 const SelectorSet &ClsMap, 2462 SelectorSet &InsMapSeen, 2463 SelectorSet &ClsMapSeen, 2464 ObjCImplDecl* IMPDecl, 2465 ObjCContainerDecl* IDecl, 2466 bool &IncompleteImpl, 2467 bool ImmediateClass, 2468 bool WarnCategoryMethodImpl=false); 2469 2470 /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in 2471 /// category matches with those implemented in its primary class and 2472 /// warns each time an exact match is found. 2473 void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP); 2474 2475 /// \brief Add the given method to the list of globally-known methods. 2476 void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method); 2477 2478private: 2479 /// AddMethodToGlobalPool - Add an instance or factory method to the global 2480 /// pool. See descriptoin of AddInstanceMethodToGlobalPool. 2481 void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance); 2482 2483 /// LookupMethodInGlobalPool - Returns the instance or factory method and 2484 /// optionally warns if there are multiple signatures. 2485 ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R, 2486 bool receiverIdOrClass, 2487 bool warn, bool instance); 2488 2489public: 2490 /// AddInstanceMethodToGlobalPool - All instance methods in a translation 2491 /// unit are added to a global pool. This allows us to efficiently associate 2492 /// a selector with a method declaraation for purposes of typechecking 2493 /// messages sent to "id" (where the class of the object is unknown). 2494 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { 2495 AddMethodToGlobalPool(Method, impl, /*instance*/true); 2496 } 2497 2498 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods. 2499 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { 2500 AddMethodToGlobalPool(Method, impl, /*instance*/false); 2501 } 2502 2503 /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global 2504 /// pool. 2505 void AddAnyMethodToGlobalPool(Decl *D); 2506 2507 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if 2508 /// there are multiple signatures. 2509 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, 2510 bool receiverIdOrClass=false, 2511 bool warn=true) { 2512 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, 2513 warn, /*instance*/true); 2514 } 2515 2516 /// LookupFactoryMethodInGlobalPool - Returns the method and warns if 2517 /// there are multiple signatures. 2518 ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R, 2519 bool receiverIdOrClass=false, 2520 bool warn=true) { 2521 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, 2522 warn, /*instance*/false); 2523 } 2524 2525 /// LookupImplementedMethodInGlobalPool - Returns the method which has an 2526 /// implementation. 2527 ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel); 2528 2529 /// CollectIvarsToConstructOrDestruct - Collect those ivars which require 2530 /// initialization. 2531 void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI, 2532 SmallVectorImpl<ObjCIvarDecl*> &Ivars); 2533 2534 //===--------------------------------------------------------------------===// 2535 // Statement Parsing Callbacks: SemaStmt.cpp. 2536public: 2537 class FullExprArg { 2538 public: 2539 FullExprArg(Sema &actions) : E(0) { } 2540 2541 // FIXME: The const_cast here is ugly. RValue references would make this 2542 // much nicer (or we could duplicate a bunch of the move semantics 2543 // emulation code from Ownership.h). 2544 FullExprArg(const FullExprArg& Other) : E(Other.E) {} 2545 2546 ExprResult release() { 2547 return E; 2548 } 2549 2550 Expr *get() const { return E; } 2551 2552 Expr *operator->() { 2553 return E; 2554 } 2555 2556 private: 2557 // FIXME: No need to make the entire Sema class a friend when it's just 2558 // Sema::MakeFullExpr that needs access to the constructor below. 2559 friend class Sema; 2560 2561 explicit FullExprArg(Expr *expr) : E(expr) {} 2562 2563 Expr *E; 2564 }; 2565 2566 FullExprArg MakeFullExpr(Expr *Arg) { 2567 return MakeFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation()); 2568 } 2569 FullExprArg MakeFullExpr(Expr *Arg, SourceLocation CC) { 2570 return FullExprArg(ActOnFinishFullExpr(Arg, CC).release()); 2571 } 2572 FullExprArg MakeFullDiscardedValueExpr(Expr *Arg) { 2573 ExprResult FE = 2574 ActOnFinishFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation(), 2575 /*DiscardedValue*/ true); 2576 return FullExprArg(FE.release()); 2577 } 2578 2579 StmtResult ActOnExprStmt(ExprResult Arg); 2580 2581 StmtResult ActOnNullStmt(SourceLocation SemiLoc, 2582 bool HasLeadingEmptyMacro = false); 2583 2584 void ActOnStartOfCompoundStmt(); 2585 void ActOnFinishOfCompoundStmt(); 2586 StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, 2587 MultiStmtArg Elts, 2588 bool isStmtExpr); 2589 2590 /// \brief A RAII object to enter scope of a compound statement. 2591 class CompoundScopeRAII { 2592 public: 2593 CompoundScopeRAII(Sema &S): S(S) { 2594 S.ActOnStartOfCompoundStmt(); 2595 } 2596 2597 ~CompoundScopeRAII() { 2598 S.ActOnFinishOfCompoundStmt(); 2599 } 2600 2601 private: 2602 Sema &S; 2603 }; 2604 2605 StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, 2606 SourceLocation StartLoc, 2607 SourceLocation EndLoc); 2608 void ActOnForEachDeclStmt(DeclGroupPtrTy Decl); 2609 StmtResult ActOnForEachLValueExpr(Expr *E); 2610 StmtResult ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal, 2611 SourceLocation DotDotDotLoc, Expr *RHSVal, 2612 SourceLocation ColonLoc); 2613 void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt); 2614 2615 StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, 2616 SourceLocation ColonLoc, 2617 Stmt *SubStmt, Scope *CurScope); 2618 StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, 2619 SourceLocation ColonLoc, Stmt *SubStmt); 2620 2621 StmtResult ActOnAttributedStmt(SourceLocation AttrLoc, 2622 ArrayRef<const Attr*> Attrs, 2623 Stmt *SubStmt); 2624 2625 StmtResult ActOnIfStmt(SourceLocation IfLoc, 2626 FullExprArg CondVal, Decl *CondVar, 2627 Stmt *ThenVal, 2628 SourceLocation ElseLoc, Stmt *ElseVal); 2629 StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, 2630 Expr *Cond, 2631 Decl *CondVar); 2632 StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, 2633 Stmt *Switch, Stmt *Body); 2634 StmtResult ActOnWhileStmt(SourceLocation WhileLoc, 2635 FullExprArg Cond, 2636 Decl *CondVar, Stmt *Body); 2637 StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, 2638 SourceLocation WhileLoc, 2639 SourceLocation CondLParen, Expr *Cond, 2640 SourceLocation CondRParen); 2641 2642 StmtResult ActOnForStmt(SourceLocation ForLoc, 2643 SourceLocation LParenLoc, 2644 Stmt *First, FullExprArg Second, 2645 Decl *SecondVar, 2646 FullExprArg Third, 2647 SourceLocation RParenLoc, 2648 Stmt *Body); 2649 ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc, 2650 Expr *collection); 2651 StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, 2652 Stmt *First, Expr *collection, 2653 SourceLocation RParenLoc); 2654 StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body); 2655 2656 enum BuildForRangeKind { 2657 /// Initial building of a for-range statement. 2658 BFRK_Build, 2659 /// Instantiation or recovery rebuild of a for-range statement. Don't 2660 /// attempt any typo-correction. 2661 BFRK_Rebuild, 2662 /// Determining whether a for-range statement could be built. Avoid any 2663 /// unnecessary or irreversible actions. 2664 BFRK_Check 2665 }; 2666 2667 StmtResult ActOnCXXForRangeStmt(SourceLocation ForLoc, Stmt *LoopVar, 2668 SourceLocation ColonLoc, Expr *Collection, 2669 SourceLocation RParenLoc, 2670 BuildForRangeKind Kind); 2671 StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, 2672 SourceLocation ColonLoc, 2673 Stmt *RangeDecl, Stmt *BeginEndDecl, 2674 Expr *Cond, Expr *Inc, 2675 Stmt *LoopVarDecl, 2676 SourceLocation RParenLoc, 2677 BuildForRangeKind Kind); 2678 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body); 2679 2680 StmtResult ActOnGotoStmt(SourceLocation GotoLoc, 2681 SourceLocation LabelLoc, 2682 LabelDecl *TheDecl); 2683 StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, 2684 SourceLocation StarLoc, 2685 Expr *DestExp); 2686 StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope); 2687 StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope); 2688 2689 const VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E, 2690 bool AllowFunctionParameters); 2691 2692 StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp); 2693 StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp); 2694 2695 StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, 2696 bool IsVolatile, unsigned NumOutputs, 2697 unsigned NumInputs, IdentifierInfo **Names, 2698 MultiExprArg Constraints, MultiExprArg Exprs, 2699 Expr *AsmString, MultiExprArg Clobbers, 2700 SourceLocation RParenLoc); 2701 2702 NamedDecl *LookupInlineAsmIdentifier(StringRef Name, SourceLocation Loc, 2703 unsigned &Size, bool &IsVarDecl); 2704 bool LookupInlineAsmField(StringRef Base, StringRef Member, 2705 unsigned &Offset, SourceLocation AsmLoc); 2706 StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, 2707 ArrayRef<Token> AsmToks, SourceLocation EndLoc); 2708 2709 VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType, 2710 SourceLocation StartLoc, 2711 SourceLocation IdLoc, IdentifierInfo *Id, 2712 bool Invalid = false); 2713 2714 Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D); 2715 2716 StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, 2717 Decl *Parm, Stmt *Body); 2718 2719 StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body); 2720 2721 StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, 2722 MultiStmtArg Catch, Stmt *Finally); 2723 2724 StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw); 2725 StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, 2726 Scope *CurScope); 2727 ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, 2728 Expr *operand); 2729 StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, 2730 Expr *SynchExpr, 2731 Stmt *SynchBody); 2732 2733 StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body); 2734 2735 VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo, 2736 SourceLocation StartLoc, 2737 SourceLocation IdLoc, 2738 IdentifierInfo *Id); 2739 2740 Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D); 2741 2742 StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, 2743 Decl *ExDecl, Stmt *HandlerBlock); 2744 StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, 2745 MultiStmtArg Handlers); 2746 2747 StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ? 2748 SourceLocation TryLoc, 2749 Stmt *TryBlock, 2750 Stmt *Handler); 2751 2752 StmtResult ActOnSEHExceptBlock(SourceLocation Loc, 2753 Expr *FilterExpr, 2754 Stmt *Block); 2755 2756 StmtResult ActOnSEHFinallyBlock(SourceLocation Loc, 2757 Stmt *Block); 2758 2759 void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock); 2760 2761 bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const; 2762 2763 /// \brief If it's a file scoped decl that must warn if not used, keep track 2764 /// of it. 2765 void MarkUnusedFileScopedDecl(const DeclaratorDecl *D); 2766 2767 /// DiagnoseUnusedExprResult - If the statement passed in is an expression 2768 /// whose result is unused, warn. 2769 void DiagnoseUnusedExprResult(const Stmt *S); 2770 void DiagnoseUnusedDecl(const NamedDecl *ND); 2771 2772 /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null 2773 /// statement as a \p Body, and it is located on the same line. 2774 /// 2775 /// This helps prevent bugs due to typos, such as: 2776 /// if (condition); 2777 /// do_stuff(); 2778 void DiagnoseEmptyStmtBody(SourceLocation StmtLoc, 2779 const Stmt *Body, 2780 unsigned DiagID); 2781 2782 /// Warn if a for/while loop statement \p S, which is followed by 2783 /// \p PossibleBody, has a suspicious null statement as a body. 2784 void DiagnoseEmptyLoopBody(const Stmt *S, 2785 const Stmt *PossibleBody); 2786 2787 ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool) { 2788 return DelayedDiagnostics.push(pool); 2789 } 2790 void PopParsingDeclaration(ParsingDeclState state, Decl *decl); 2791 2792 typedef ProcessingContextState ParsingClassState; 2793 ParsingClassState PushParsingClass() { 2794 return DelayedDiagnostics.pushUndelayed(); 2795 } 2796 void PopParsingClass(ParsingClassState state) { 2797 DelayedDiagnostics.popUndelayed(state); 2798 } 2799 2800 void redelayDiagnostics(sema::DelayedDiagnosticPool &pool); 2801 2802 void EmitDeprecationWarning(NamedDecl *D, StringRef Message, 2803 SourceLocation Loc, 2804 const ObjCInterfaceDecl *UnknownObjCClass, 2805 const ObjCPropertyDecl *ObjCProperty); 2806 2807 void HandleDelayedDeprecationCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); 2808 2809 bool makeUnavailableInSystemHeader(SourceLocation loc, 2810 StringRef message); 2811 2812 //===--------------------------------------------------------------------===// 2813 // Expression Parsing Callbacks: SemaExpr.cpp. 2814 2815 bool CanUseDecl(NamedDecl *D); 2816 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, 2817 const ObjCInterfaceDecl *UnknownObjCClass=0); 2818 void NoteDeletedFunction(FunctionDecl *FD); 2819 std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD); 2820 bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, 2821 ObjCMethodDecl *Getter, 2822 SourceLocation Loc); 2823 void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, 2824 Expr **Args, unsigned NumArgs); 2825 2826 void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext, 2827 Decl *LambdaContextDecl = 0, 2828 bool IsDecltype = false); 2829 enum ReuseLambdaContextDecl_t { ReuseLambdaContextDecl }; 2830 void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext, 2831 ReuseLambdaContextDecl_t, 2832 bool IsDecltype = false); 2833 void PopExpressionEvaluationContext(); 2834 2835 void DiscardCleanupsInEvaluationContext(); 2836 2837 ExprResult TransformToPotentiallyEvaluated(Expr *E); 2838 ExprResult HandleExprEvaluationContextForTypeof(Expr *E); 2839 2840 ExprResult ActOnConstantExpression(ExprResult Res); 2841 2842 // Functions for marking a declaration referenced. These functions also 2843 // contain the relevant logic for marking if a reference to a function or 2844 // variable is an odr-use (in the C++11 sense). There are separate variants 2845 // for expressions referring to a decl; these exist because odr-use marking 2846 // needs to be delayed for some constant variables when we build one of the 2847 // named expressions. 2848 void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D); 2849 void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func); 2850 void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var); 2851 void MarkDeclRefReferenced(DeclRefExpr *E); 2852 void MarkMemberReferenced(MemberExpr *E); 2853 2854 void UpdateMarkingForLValueToRValue(Expr *E); 2855 void CleanupVarDeclMarking(); 2856 2857 enum TryCaptureKind { 2858 TryCapture_Implicit, TryCapture_ExplicitByVal, TryCapture_ExplicitByRef 2859 }; 2860 2861 /// \brief Try to capture the given variable. 2862 /// 2863 /// \param Var The variable to capture. 2864 /// 2865 /// \param Loc The location at which the capture occurs. 2866 /// 2867 /// \param Kind The kind of capture, which may be implicit (for either a 2868 /// block or a lambda), or explicit by-value or by-reference (for a lambda). 2869 /// 2870 /// \param EllipsisLoc The location of the ellipsis, if one is provided in 2871 /// an explicit lambda capture. 2872 /// 2873 /// \param BuildAndDiagnose Whether we are actually supposed to add the 2874 /// captures or diagnose errors. If false, this routine merely check whether 2875 /// the capture can occur without performing the capture itself or complaining 2876 /// if the variable cannot be captured. 2877 /// 2878 /// \param CaptureType Will be set to the type of the field used to capture 2879 /// this variable in the innermost block or lambda. Only valid when the 2880 /// variable can be captured. 2881 /// 2882 /// \param DeclRefType Will be set to the type of a reference to the capture 2883 /// from within the current scope. Only valid when the variable can be 2884 /// captured. 2885 /// 2886 /// \returns true if an error occurred (i.e., the variable cannot be 2887 /// captured) and false if the capture succeeded. 2888 bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, TryCaptureKind Kind, 2889 SourceLocation EllipsisLoc, bool BuildAndDiagnose, 2890 QualType &CaptureType, 2891 QualType &DeclRefType); 2892 2893 /// \brief Try to capture the given variable. 2894 bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, 2895 TryCaptureKind Kind = TryCapture_Implicit, 2896 SourceLocation EllipsisLoc = SourceLocation()); 2897 2898 /// \brief Given a variable, determine the type that a reference to that 2899 /// variable will have in the given scope. 2900 QualType getCapturedDeclRefType(VarDecl *Var, SourceLocation Loc); 2901 2902 void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T); 2903 void MarkDeclarationsReferencedInExpr(Expr *E, 2904 bool SkipLocalVariables = false); 2905 2906 /// \brief Try to recover by turning the given expression into a 2907 /// call. Returns true if recovery was attempted or an error was 2908 /// emitted; this may also leave the ExprResult invalid. 2909 bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD, 2910 bool ForceComplain = false, 2911 bool (*IsPlausibleResult)(QualType) = 0); 2912 2913 /// \brief Figure out if an expression could be turned into a call. 2914 bool isExprCallable(const Expr &E, QualType &ZeroArgCallReturnTy, 2915 UnresolvedSetImpl &NonTemplateOverloads); 2916 2917 /// \brief Conditionally issue a diagnostic based on the current 2918 /// evaluation context. 2919 /// 2920 /// \param Statement If Statement is non-null, delay reporting the 2921 /// diagnostic until the function body is parsed, and then do a basic 2922 /// reachability analysis to determine if the statement is reachable. 2923 /// If it is unreachable, the diagnostic will not be emitted. 2924 bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, 2925 const PartialDiagnostic &PD); 2926 2927 // Primary Expressions. 2928 SourceRange getExprRange(Expr *E) const; 2929 2930 ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, 2931 SourceLocation TemplateKWLoc, 2932 UnqualifiedId &Id, 2933 bool HasTrailingLParen, bool IsAddressOfOperand, 2934 CorrectionCandidateCallback *CCC = 0); 2935 2936 void DecomposeUnqualifiedId(const UnqualifiedId &Id, 2937 TemplateArgumentListInfo &Buffer, 2938 DeclarationNameInfo &NameInfo, 2939 const TemplateArgumentListInfo *&TemplateArgs); 2940 2941 bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, 2942 CorrectionCandidateCallback &CCC, 2943 TemplateArgumentListInfo *ExplicitTemplateArgs = 0, 2944 ArrayRef<Expr *> Args = ArrayRef<Expr *>()); 2945 2946 ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S, 2947 IdentifierInfo *II, 2948 bool AllowBuiltinCreation=false); 2949 2950 ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS, 2951 SourceLocation TemplateKWLoc, 2952 const DeclarationNameInfo &NameInfo, 2953 bool isAddressOfOperand, 2954 const TemplateArgumentListInfo *TemplateArgs); 2955 2956 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty, 2957 ExprValueKind VK, 2958 SourceLocation Loc, 2959 const CXXScopeSpec *SS = 0); 2960 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty, 2961 ExprValueKind VK, 2962 const DeclarationNameInfo &NameInfo, 2963 const CXXScopeSpec *SS = 0); 2964 ExprResult 2965 BuildAnonymousStructUnionMemberReference(const CXXScopeSpec &SS, 2966 SourceLocation nameLoc, 2967 IndirectFieldDecl *indirectField, 2968 Expr *baseObjectExpr = 0, 2969 SourceLocation opLoc = SourceLocation()); 2970 ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS, 2971 SourceLocation TemplateKWLoc, 2972 LookupResult &R, 2973 const TemplateArgumentListInfo *TemplateArgs); 2974 ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS, 2975 SourceLocation TemplateKWLoc, 2976 LookupResult &R, 2977 const TemplateArgumentListInfo *TemplateArgs, 2978 bool IsDefiniteInstance); 2979 bool UseArgumentDependentLookup(const CXXScopeSpec &SS, 2980 const LookupResult &R, 2981 bool HasTrailingLParen); 2982 2983 ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, 2984 const DeclarationNameInfo &NameInfo, 2985 bool IsAddressOfOperand); 2986 ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS, 2987 SourceLocation TemplateKWLoc, 2988 const DeclarationNameInfo &NameInfo, 2989 const TemplateArgumentListInfo *TemplateArgs); 2990 2991 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, 2992 LookupResult &R, 2993 bool NeedsADL); 2994 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, 2995 const DeclarationNameInfo &NameInfo, 2996 NamedDecl *D); 2997 2998 ExprResult BuildLiteralOperatorCall(LookupResult &R, 2999 DeclarationNameInfo &SuffixInfo, 3000 ArrayRef<Expr*> Args, 3001 SourceLocation LitEndLoc, 3002 TemplateArgumentListInfo *ExplicitTemplateArgs = 0); 3003 3004 ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind); 3005 ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val); 3006 ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = 0); 3007 ExprResult ActOnCharacterConstant(const Token &Tok, Scope *UDLScope = 0); 3008 ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E); 3009 ExprResult ActOnParenListExpr(SourceLocation L, 3010 SourceLocation R, 3011 MultiExprArg Val); 3012 3013 /// ActOnStringLiteral - The specified tokens were lexed as pasted string 3014 /// fragments (e.g. "foo" "bar" L"baz"). 3015 ExprResult ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks, 3016 Scope *UDLScope = 0); 3017 3018 ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc, 3019 SourceLocation DefaultLoc, 3020 SourceLocation RParenLoc, 3021 Expr *ControllingExpr, 3022 MultiTypeArg ArgTypes, 3023 MultiExprArg ArgExprs); 3024 ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, 3025 SourceLocation DefaultLoc, 3026 SourceLocation RParenLoc, 3027 Expr *ControllingExpr, 3028 TypeSourceInfo **Types, 3029 Expr **Exprs, 3030 unsigned NumAssocs); 3031 3032 // Binary/Unary Operators. 'Tok' is the token for the operator. 3033 ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, 3034 Expr *InputExpr); 3035 ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, 3036 UnaryOperatorKind Opc, Expr *Input); 3037 ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, 3038 tok::TokenKind Op, Expr *Input); 3039 3040 ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, 3041 SourceLocation OpLoc, 3042 UnaryExprOrTypeTrait ExprKind, 3043 SourceRange R); 3044 ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc, 3045 UnaryExprOrTypeTrait ExprKind); 3046 ExprResult 3047 ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, 3048 UnaryExprOrTypeTrait ExprKind, 3049 bool IsType, void *TyOrEx, 3050 const SourceRange &ArgRange); 3051 3052 ExprResult CheckPlaceholderExpr(Expr *E); 3053 bool CheckVecStepExpr(Expr *E); 3054 3055 bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind); 3056 bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc, 3057 SourceRange ExprRange, 3058 UnaryExprOrTypeTrait ExprKind); 3059 ExprResult ActOnSizeofParameterPackExpr(Scope *S, 3060 SourceLocation OpLoc, 3061 IdentifierInfo &Name, 3062 SourceLocation NameLoc, 3063 SourceLocation RParenLoc); 3064 ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, 3065 tok::TokenKind Kind, Expr *Input); 3066 3067 ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, 3068 Expr *Idx, SourceLocation RLoc); 3069 ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, 3070 Expr *Idx, SourceLocation RLoc); 3071 3072 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, 3073 SourceLocation OpLoc, bool IsArrow, 3074 CXXScopeSpec &SS, 3075 SourceLocation TemplateKWLoc, 3076 NamedDecl *FirstQualifierInScope, 3077 const DeclarationNameInfo &NameInfo, 3078 const TemplateArgumentListInfo *TemplateArgs); 3079 3080 // This struct is for use by ActOnMemberAccess to allow 3081 // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after 3082 // changing the access operator from a '.' to a '->' (to see if that is the 3083 // change needed to fix an error about an unknown member, e.g. when the class 3084 // defines a custom operator->). 3085 struct ActOnMemberAccessExtraArgs { 3086 Scope *S; 3087 UnqualifiedId &Id; 3088 Decl *ObjCImpDecl; 3089 bool HasTrailingLParen; 3090 }; 3091 3092 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, 3093 SourceLocation OpLoc, bool IsArrow, 3094 const CXXScopeSpec &SS, 3095 SourceLocation TemplateKWLoc, 3096 NamedDecl *FirstQualifierInScope, 3097 LookupResult &R, 3098 const TemplateArgumentListInfo *TemplateArgs, 3099 bool SuppressQualifierCheck = false, 3100 ActOnMemberAccessExtraArgs *ExtraArgs = 0); 3101 3102 ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow); 3103 ExprResult LookupMemberExpr(LookupResult &R, ExprResult &Base, 3104 bool &IsArrow, SourceLocation OpLoc, 3105 CXXScopeSpec &SS, 3106 Decl *ObjCImpDecl, 3107 bool HasTemplateArgs); 3108 3109 bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType, 3110 const CXXScopeSpec &SS, 3111 const LookupResult &R); 3112 3113 ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType, 3114 bool IsArrow, SourceLocation OpLoc, 3115 const CXXScopeSpec &SS, 3116 SourceLocation TemplateKWLoc, 3117 NamedDecl *FirstQualifierInScope, 3118 const DeclarationNameInfo &NameInfo, 3119 const TemplateArgumentListInfo *TemplateArgs); 3120 3121 ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, 3122 SourceLocation OpLoc, 3123 tok::TokenKind OpKind, 3124 CXXScopeSpec &SS, 3125 SourceLocation TemplateKWLoc, 3126 UnqualifiedId &Member, 3127 Decl *ObjCImpDecl, 3128 bool HasTrailingLParen); 3129 3130 void ActOnDefaultCtorInitializers(Decl *CDtorDecl); 3131 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, 3132 FunctionDecl *FDecl, 3133 const FunctionProtoType *Proto, 3134 Expr **Args, unsigned NumArgs, 3135 SourceLocation RParenLoc, 3136 bool ExecConfig = false); 3137 void CheckStaticArrayArgument(SourceLocation CallLoc, 3138 ParmVarDecl *Param, 3139 const Expr *ArgExpr); 3140 3141 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. 3142 /// This provides the location of the left/right parens and a list of comma 3143 /// locations. 3144 ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, 3145 MultiExprArg ArgExprs, SourceLocation RParenLoc, 3146 Expr *ExecConfig = 0, bool IsExecConfig = false); 3147 ExprResult BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, 3148 SourceLocation LParenLoc, 3149 Expr **Args, unsigned NumArgs, 3150 SourceLocation RParenLoc, 3151 Expr *Config = 0, 3152 bool IsExecConfig = false); 3153 3154 ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc, 3155 MultiExprArg ExecConfig, 3156 SourceLocation GGGLoc); 3157 3158 ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, 3159 Declarator &D, ParsedType &Ty, 3160 SourceLocation RParenLoc, Expr *CastExpr); 3161 ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, 3162 TypeSourceInfo *Ty, 3163 SourceLocation RParenLoc, 3164 Expr *Op); 3165 CastKind PrepareScalarCast(ExprResult &src, QualType destType); 3166 3167 /// \brief Build an altivec or OpenCL literal. 3168 ExprResult BuildVectorLiteral(SourceLocation LParenLoc, 3169 SourceLocation RParenLoc, Expr *E, 3170 TypeSourceInfo *TInfo); 3171 3172 ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME); 3173 3174 ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, 3175 ParsedType Ty, 3176 SourceLocation RParenLoc, 3177 Expr *InitExpr); 3178 3179 ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, 3180 TypeSourceInfo *TInfo, 3181 SourceLocation RParenLoc, 3182 Expr *LiteralExpr); 3183 3184 ExprResult ActOnInitList(SourceLocation LBraceLoc, 3185 MultiExprArg InitArgList, 3186 SourceLocation RBraceLoc); 3187 3188 ExprResult ActOnDesignatedInitializer(Designation &Desig, 3189 SourceLocation Loc, 3190 bool GNUSyntax, 3191 ExprResult Init); 3192 3193 ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, 3194 tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr); 3195 ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, 3196 BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr); 3197 ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, 3198 Expr *LHSExpr, Expr *RHSExpr); 3199 3200 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null 3201 /// in the case of a the GNU conditional expr extension. 3202 ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, 3203 SourceLocation ColonLoc, 3204 Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr); 3205 3206 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". 3207 ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, 3208 LabelDecl *TheDecl); 3209 3210 void ActOnStartStmtExpr(); 3211 ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, 3212 SourceLocation RPLoc); // "({..})" 3213 void ActOnStmtExprError(); 3214 3215 // __builtin_offsetof(type, identifier(.identifier|[expr])*) 3216 struct OffsetOfComponent { 3217 SourceLocation LocStart, LocEnd; 3218 bool isBrackets; // true if [expr], false if .ident 3219 union { 3220 IdentifierInfo *IdentInfo; 3221 Expr *E; 3222 } U; 3223 }; 3224 3225 /// __builtin_offsetof(type, a.b[123][456].c) 3226 ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, 3227 TypeSourceInfo *TInfo, 3228 OffsetOfComponent *CompPtr, 3229 unsigned NumComponents, 3230 SourceLocation RParenLoc); 3231 ExprResult ActOnBuiltinOffsetOf(Scope *S, 3232 SourceLocation BuiltinLoc, 3233 SourceLocation TypeLoc, 3234 ParsedType ParsedArgTy, 3235 OffsetOfComponent *CompPtr, 3236 unsigned NumComponents, 3237 SourceLocation RParenLoc); 3238 3239 // __builtin_choose_expr(constExpr, expr1, expr2) 3240 ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, 3241 Expr *CondExpr, Expr *LHSExpr, 3242 Expr *RHSExpr, SourceLocation RPLoc); 3243 3244 // __builtin_va_arg(expr, type) 3245 ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty, 3246 SourceLocation RPLoc); 3247 ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, 3248 TypeSourceInfo *TInfo, SourceLocation RPLoc); 3249 3250 // __null 3251 ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); 3252 3253 bool CheckCaseExpression(Expr *E); 3254 3255 /// \brief Describes the result of an "if-exists" condition check. 3256 enum IfExistsResult { 3257 /// \brief The symbol exists. 3258 IER_Exists, 3259 3260 /// \brief The symbol does not exist. 3261 IER_DoesNotExist, 3262 3263 /// \brief The name is a dependent name, so the results will differ 3264 /// from one instantiation to the next. 3265 IER_Dependent, 3266 3267 /// \brief An error occurred. 3268 IER_Error 3269 }; 3270 3271 IfExistsResult 3272 CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS, 3273 const DeclarationNameInfo &TargetNameInfo); 3274 3275 IfExistsResult 3276 CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc, 3277 bool IsIfExists, CXXScopeSpec &SS, 3278 UnqualifiedId &Name); 3279 3280 StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, 3281 bool IsIfExists, 3282 NestedNameSpecifierLoc QualifierLoc, 3283 DeclarationNameInfo NameInfo, 3284 Stmt *Nested); 3285 StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, 3286 bool IsIfExists, 3287 CXXScopeSpec &SS, UnqualifiedId &Name, 3288 Stmt *Nested); 3289 3290 //===------------------------- "Block" Extension ------------------------===// 3291 3292 /// ActOnBlockStart - This callback is invoked when a block literal is 3293 /// started. 3294 void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); 3295 3296 /// ActOnBlockArguments - This callback allows processing of block arguments. 3297 /// If there are no arguments, this is still invoked. 3298 void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo, 3299 Scope *CurScope); 3300 3301 /// ActOnBlockError - If there is an error parsing a block, this callback 3302 /// is invoked to pop the information about the block from the action impl. 3303 void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); 3304 3305 /// ActOnBlockStmtExpr - This is called when the body of a block statement 3306 /// literal was successfully completed. ^(int x){...} 3307 ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, 3308 Scope *CurScope); 3309 3310 //===---------------------------- OpenCL Features -----------------------===// 3311 3312 /// __builtin_astype(...) 3313 ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy, 3314 SourceLocation BuiltinLoc, 3315 SourceLocation RParenLoc); 3316 3317 //===---------------------------- C++ Features --------------------------===// 3318 3319 // Act on C++ namespaces 3320 Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc, 3321 SourceLocation NamespaceLoc, 3322 SourceLocation IdentLoc, 3323 IdentifierInfo *Ident, 3324 SourceLocation LBrace, 3325 AttributeList *AttrList); 3326 void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace); 3327 3328 NamespaceDecl *getStdNamespace() const; 3329 NamespaceDecl *getOrCreateStdNamespace(); 3330 3331 CXXRecordDecl *getStdBadAlloc() const; 3332 3333 /// \brief Tests whether Ty is an instance of std::initializer_list and, if 3334 /// it is and Element is not NULL, assigns the element type to Element. 3335 bool isStdInitializerList(QualType Ty, QualType *Element); 3336 3337 /// \brief Looks for the std::initializer_list template and instantiates it 3338 /// with Element, or emits an error if it's not found. 3339 /// 3340 /// \returns The instantiated template, or null on error. 3341 QualType BuildStdInitializerList(QualType Element, SourceLocation Loc); 3342 3343 /// \brief Determine whether Ctor is an initializer-list constructor, as 3344 /// defined in [dcl.init.list]p2. 3345 bool isInitListConstructor(const CXXConstructorDecl *Ctor); 3346 3347 Decl *ActOnUsingDirective(Scope *CurScope, 3348 SourceLocation UsingLoc, 3349 SourceLocation NamespcLoc, 3350 CXXScopeSpec &SS, 3351 SourceLocation IdentLoc, 3352 IdentifierInfo *NamespcName, 3353 AttributeList *AttrList); 3354 3355 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); 3356 3357 Decl *ActOnNamespaceAliasDef(Scope *CurScope, 3358 SourceLocation NamespaceLoc, 3359 SourceLocation AliasLoc, 3360 IdentifierInfo *Alias, 3361 CXXScopeSpec &SS, 3362 SourceLocation IdentLoc, 3363 IdentifierInfo *Ident); 3364 3365 void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow); 3366 bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target, 3367 const LookupResult &PreviousDecls); 3368 UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD, 3369 NamedDecl *Target); 3370 3371 bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc, 3372 bool isTypeName, 3373 const CXXScopeSpec &SS, 3374 SourceLocation NameLoc, 3375 const LookupResult &Previous); 3376 bool CheckUsingDeclQualifier(SourceLocation UsingLoc, 3377 const CXXScopeSpec &SS, 3378 SourceLocation NameLoc); 3379 3380 NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS, 3381 SourceLocation UsingLoc, 3382 CXXScopeSpec &SS, 3383 const DeclarationNameInfo &NameInfo, 3384 AttributeList *AttrList, 3385 bool IsInstantiation, 3386 bool IsTypeName, 3387 SourceLocation TypenameLoc); 3388 3389 bool CheckInheritingConstructorUsingDecl(UsingDecl *UD); 3390 3391 Decl *ActOnUsingDeclaration(Scope *CurScope, 3392 AccessSpecifier AS, 3393 bool HasUsingKeyword, 3394 SourceLocation UsingLoc, 3395 CXXScopeSpec &SS, 3396 UnqualifiedId &Name, 3397 AttributeList *AttrList, 3398 bool IsTypeName, 3399 SourceLocation TypenameLoc); 3400 Decl *ActOnAliasDeclaration(Scope *CurScope, 3401 AccessSpecifier AS, 3402 MultiTemplateParamsArg TemplateParams, 3403 SourceLocation UsingLoc, 3404 UnqualifiedId &Name, 3405 TypeResult Type); 3406 3407 /// BuildCXXConstructExpr - Creates a complete call to a constructor, 3408 /// including handling of its default argument expressions. 3409 /// 3410 /// \param ConstructKind - a CXXConstructExpr::ConstructionKind 3411 ExprResult 3412 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, 3413 CXXConstructorDecl *Constructor, MultiExprArg Exprs, 3414 bool HadMultipleCandidates, bool IsListInitialization, 3415 bool RequiresZeroInit, unsigned ConstructKind, 3416 SourceRange ParenRange); 3417 3418 // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if 3419 // the constructor can be elidable? 3420 ExprResult 3421 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, 3422 CXXConstructorDecl *Constructor, bool Elidable, 3423 MultiExprArg Exprs, bool HadMultipleCandidates, 3424 bool IsListInitialization, bool RequiresZeroInit, 3425 unsigned ConstructKind, SourceRange ParenRange); 3426 3427 /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating 3428 /// the default expr if needed. 3429 ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, 3430 FunctionDecl *FD, 3431 ParmVarDecl *Param); 3432 3433 /// FinalizeVarWithDestructor - Prepare for calling destructor on the 3434 /// constructed variable. 3435 void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType); 3436 3437 /// \brief Helper class that collects exception specifications for 3438 /// implicitly-declared special member functions. 3439 class ImplicitExceptionSpecification { 3440 // Pointer to allow copying 3441 Sema *Self; 3442 // We order exception specifications thus: 3443 // noexcept is the most restrictive, but is only used in C++11. 3444 // throw() comes next. 3445 // Then a throw(collected exceptions) 3446 // Finally no specification, which is expressed as noexcept(false). 3447 // throw(...) is used instead if any called function uses it. 3448 ExceptionSpecificationType ComputedEST; 3449 llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen; 3450 SmallVector<QualType, 4> Exceptions; 3451 3452 void ClearExceptions() { 3453 ExceptionsSeen.clear(); 3454 Exceptions.clear(); 3455 } 3456 3457 public: 3458 explicit ImplicitExceptionSpecification(Sema &Self) 3459 : Self(&Self), ComputedEST(EST_BasicNoexcept) { 3460 if (!Self.getLangOpts().CPlusPlus11) 3461 ComputedEST = EST_DynamicNone; 3462 } 3463 3464 /// \brief Get the computed exception specification type. 3465 ExceptionSpecificationType getExceptionSpecType() const { 3466 assert(ComputedEST != EST_ComputedNoexcept && 3467 "noexcept(expr) should not be a possible result"); 3468 return ComputedEST; 3469 } 3470 3471 /// \brief The number of exceptions in the exception specification. 3472 unsigned size() const { return Exceptions.size(); } 3473 3474 /// \brief The set of exceptions in the exception specification. 3475 const QualType *data() const { return Exceptions.data(); } 3476 3477 /// \brief Integrate another called method into the collected data. 3478 void CalledDecl(SourceLocation CallLoc, CXXMethodDecl *Method); 3479 3480 /// \brief Integrate an invoked expression into the collected data. 3481 void CalledExpr(Expr *E); 3482 3483 /// \brief Overwrite an EPI's exception specification with this 3484 /// computed exception specification. 3485 void getEPI(FunctionProtoType::ExtProtoInfo &EPI) const { 3486 EPI.ExceptionSpecType = getExceptionSpecType(); 3487 if (EPI.ExceptionSpecType == EST_Dynamic) { 3488 EPI.NumExceptions = size(); 3489 EPI.Exceptions = data(); 3490 } else if (EPI.ExceptionSpecType == EST_None) { 3491 /// C++11 [except.spec]p14: 3492 /// The exception-specification is noexcept(false) if the set of 3493 /// potential exceptions of the special member function contains "any" 3494 EPI.ExceptionSpecType = EST_ComputedNoexcept; 3495 EPI.NoexceptExpr = Self->ActOnCXXBoolLiteral(SourceLocation(), 3496 tok::kw_false).take(); 3497 } 3498 } 3499 FunctionProtoType::ExtProtoInfo getEPI() const { 3500 FunctionProtoType::ExtProtoInfo EPI; 3501 getEPI(EPI); 3502 return EPI; 3503 } 3504 }; 3505 3506 /// \brief Determine what sort of exception specification a defaulted 3507 /// copy constructor of a class will have. 3508 ImplicitExceptionSpecification 3509 ComputeDefaultedDefaultCtorExceptionSpec(SourceLocation Loc, 3510 CXXMethodDecl *MD); 3511 3512 /// \brief Determine what sort of exception specification a defaulted 3513 /// default constructor of a class will have, and whether the parameter 3514 /// will be const. 3515 ImplicitExceptionSpecification 3516 ComputeDefaultedCopyCtorExceptionSpec(CXXMethodDecl *MD); 3517 3518 /// \brief Determine what sort of exception specification a defautled 3519 /// copy assignment operator of a class will have, and whether the 3520 /// parameter will be const. 3521 ImplicitExceptionSpecification 3522 ComputeDefaultedCopyAssignmentExceptionSpec(CXXMethodDecl *MD); 3523 3524 /// \brief Determine what sort of exception specification a defaulted move 3525 /// constructor of a class will have. 3526 ImplicitExceptionSpecification 3527 ComputeDefaultedMoveCtorExceptionSpec(CXXMethodDecl *MD); 3528 3529 /// \brief Determine what sort of exception specification a defaulted move 3530 /// assignment operator of a class will have. 3531 ImplicitExceptionSpecification 3532 ComputeDefaultedMoveAssignmentExceptionSpec(CXXMethodDecl *MD); 3533 3534 /// \brief Determine what sort of exception specification a defaulted 3535 /// destructor of a class will have. 3536 ImplicitExceptionSpecification 3537 ComputeDefaultedDtorExceptionSpec(CXXMethodDecl *MD); 3538 3539 /// \brief Evaluate the implicit exception specification for a defaulted 3540 /// special member function. 3541 void EvaluateImplicitExceptionSpec(SourceLocation Loc, CXXMethodDecl *MD); 3542 3543 /// \brief Check the given exception-specification and update the 3544 /// extended prototype information with the results. 3545 void checkExceptionSpecification(ExceptionSpecificationType EST, 3546 ArrayRef<ParsedType> DynamicExceptions, 3547 ArrayRef<SourceRange> DynamicExceptionRanges, 3548 Expr *NoexceptExpr, 3549 SmallVectorImpl<QualType> &Exceptions, 3550 FunctionProtoType::ExtProtoInfo &EPI); 3551 3552 /// \brief Determine if a special member function should have a deleted 3553 /// definition when it is defaulted. 3554 bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM, 3555 bool Diagnose = false); 3556 3557 /// \brief Declare the implicit default constructor for the given class. 3558 /// 3559 /// \param ClassDecl The class declaration into which the implicit 3560 /// default constructor will be added. 3561 /// 3562 /// \returns The implicitly-declared default constructor. 3563 CXXConstructorDecl *DeclareImplicitDefaultConstructor( 3564 CXXRecordDecl *ClassDecl); 3565 3566 /// DefineImplicitDefaultConstructor - Checks for feasibility of 3567 /// defining this constructor as the default constructor. 3568 void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, 3569 CXXConstructorDecl *Constructor); 3570 3571 /// \brief Declare the implicit destructor for the given class. 3572 /// 3573 /// \param ClassDecl The class declaration into which the implicit 3574 /// destructor will be added. 3575 /// 3576 /// \returns The implicitly-declared destructor. 3577 CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl); 3578 3579 /// DefineImplicitDestructor - Checks for feasibility of 3580 /// defining this destructor as the default destructor. 3581 void DefineImplicitDestructor(SourceLocation CurrentLocation, 3582 CXXDestructorDecl *Destructor); 3583 3584 /// \brief Build an exception spec for destructors that don't have one. 3585 /// 3586 /// C++11 says that user-defined destructors with no exception spec get one 3587 /// that looks as if the destructor was implicitly declared. 3588 void AdjustDestructorExceptionSpec(CXXRecordDecl *ClassDecl, 3589 CXXDestructorDecl *Destructor); 3590 3591 /// \brief Declare all inherited constructors for the given class. 3592 /// 3593 /// \param ClassDecl The class declaration into which the inherited 3594 /// constructors will be added. 3595 void DeclareInheritedConstructors(CXXRecordDecl *ClassDecl); 3596 3597 /// \brief Declare the implicit copy constructor for the given class. 3598 /// 3599 /// \param ClassDecl The class declaration into which the implicit 3600 /// copy constructor will be added. 3601 /// 3602 /// \returns The implicitly-declared copy constructor. 3603 CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl); 3604 3605 /// DefineImplicitCopyConstructor - Checks for feasibility of 3606 /// defining this constructor as the copy constructor. 3607 void DefineImplicitCopyConstructor(SourceLocation CurrentLocation, 3608 CXXConstructorDecl *Constructor); 3609 3610 /// \brief Declare the implicit move constructor for the given class. 3611 /// 3612 /// \param ClassDecl The Class declaration into which the implicit 3613 /// move constructor will be added. 3614 /// 3615 /// \returns The implicitly-declared move constructor, or NULL if it wasn't 3616 /// declared. 3617 CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl); 3618 3619 /// DefineImplicitMoveConstructor - Checks for feasibility of 3620 /// defining this constructor as the move constructor. 3621 void DefineImplicitMoveConstructor(SourceLocation CurrentLocation, 3622 CXXConstructorDecl *Constructor); 3623 3624 /// \brief Declare the implicit copy assignment operator for the given class. 3625 /// 3626 /// \param ClassDecl The class declaration into which the implicit 3627 /// copy assignment operator will be added. 3628 /// 3629 /// \returns The implicitly-declared copy assignment operator. 3630 CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl); 3631 3632 /// \brief Defines an implicitly-declared copy assignment operator. 3633 void DefineImplicitCopyAssignment(SourceLocation CurrentLocation, 3634 CXXMethodDecl *MethodDecl); 3635 3636 /// \brief Declare the implicit move assignment operator for the given class. 3637 /// 3638 /// \param ClassDecl The Class declaration into which the implicit 3639 /// move assignment operator will be added. 3640 /// 3641 /// \returns The implicitly-declared move assignment operator, or NULL if it 3642 /// wasn't declared. 3643 CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl); 3644 3645 /// \brief Defines an implicitly-declared move assignment operator. 3646 void DefineImplicitMoveAssignment(SourceLocation CurrentLocation, 3647 CXXMethodDecl *MethodDecl); 3648 3649 /// \brief Force the declaration of any implicitly-declared members of this 3650 /// class. 3651 void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class); 3652 3653 /// \brief Determine whether the given function is an implicitly-deleted 3654 /// special member function. 3655 bool isImplicitlyDeleted(FunctionDecl *FD); 3656 3657 /// \brief Check whether 'this' shows up in the type of a static member 3658 /// function after the (naturally empty) cv-qualifier-seq would be. 3659 /// 3660 /// \returns true if an error occurred. 3661 bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method); 3662 3663 /// \brief Whether this' shows up in the exception specification of a static 3664 /// member function. 3665 bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method); 3666 3667 /// \brief Check whether 'this' shows up in the attributes of the given 3668 /// static member function. 3669 /// 3670 /// \returns true if an error occurred. 3671 bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method); 3672 3673 /// MaybeBindToTemporary - If the passed in expression has a record type with 3674 /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise 3675 /// it simply returns the passed in expression. 3676 ExprResult MaybeBindToTemporary(Expr *E); 3677 3678 bool CompleteConstructorCall(CXXConstructorDecl *Constructor, 3679 MultiExprArg ArgsPtr, 3680 SourceLocation Loc, 3681 SmallVectorImpl<Expr*> &ConvertedArgs, 3682 bool AllowExplicit = false); 3683 3684 ParsedType getDestructorName(SourceLocation TildeLoc, 3685 IdentifierInfo &II, SourceLocation NameLoc, 3686 Scope *S, CXXScopeSpec &SS, 3687 ParsedType ObjectType, 3688 bool EnteringContext); 3689 3690 ParsedType getDestructorType(const DeclSpec& DS, ParsedType ObjectType); 3691 3692 // Checks that reinterpret casts don't have undefined behavior. 3693 void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, 3694 bool IsDereference, SourceRange Range); 3695 3696 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's. 3697 ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, 3698 tok::TokenKind Kind, 3699 SourceLocation LAngleBracketLoc, 3700 Declarator &D, 3701 SourceLocation RAngleBracketLoc, 3702 SourceLocation LParenLoc, 3703 Expr *E, 3704 SourceLocation RParenLoc); 3705 3706 ExprResult BuildCXXNamedCast(SourceLocation OpLoc, 3707 tok::TokenKind Kind, 3708 TypeSourceInfo *Ty, 3709 Expr *E, 3710 SourceRange AngleBrackets, 3711 SourceRange Parens); 3712 3713 ExprResult BuildCXXTypeId(QualType TypeInfoType, 3714 SourceLocation TypeidLoc, 3715 TypeSourceInfo *Operand, 3716 SourceLocation RParenLoc); 3717 ExprResult BuildCXXTypeId(QualType TypeInfoType, 3718 SourceLocation TypeidLoc, 3719 Expr *Operand, 3720 SourceLocation RParenLoc); 3721 3722 /// ActOnCXXTypeid - Parse typeid( something ). 3723 ExprResult ActOnCXXTypeid(SourceLocation OpLoc, 3724 SourceLocation LParenLoc, bool isType, 3725 void *TyOrExpr, 3726 SourceLocation RParenLoc); 3727 3728 ExprResult BuildCXXUuidof(QualType TypeInfoType, 3729 SourceLocation TypeidLoc, 3730 TypeSourceInfo *Operand, 3731 SourceLocation RParenLoc); 3732 ExprResult BuildCXXUuidof(QualType TypeInfoType, 3733 SourceLocation TypeidLoc, 3734 Expr *Operand, 3735 SourceLocation RParenLoc); 3736 3737 /// ActOnCXXUuidof - Parse __uuidof( something ). 3738 ExprResult ActOnCXXUuidof(SourceLocation OpLoc, 3739 SourceLocation LParenLoc, bool isType, 3740 void *TyOrExpr, 3741 SourceLocation RParenLoc); 3742 3743 3744 //// ActOnCXXThis - Parse 'this' pointer. 3745 ExprResult ActOnCXXThis(SourceLocation loc); 3746 3747 /// \brief Try to retrieve the type of the 'this' pointer. 3748 /// 3749 /// \returns The type of 'this', if possible. Otherwise, returns a NULL type. 3750 QualType getCurrentThisType(); 3751 3752 /// \brief When non-NULL, the C++ 'this' expression is allowed despite the 3753 /// current context not being a non-static member function. In such cases, 3754 /// this provides the type used for 'this'. 3755 QualType CXXThisTypeOverride; 3756 3757 /// \brief RAII object used to temporarily allow the C++ 'this' expression 3758 /// to be used, with the given qualifiers on the current class type. 3759 class CXXThisScopeRAII { 3760 Sema &S; 3761 QualType OldCXXThisTypeOverride; 3762 bool Enabled; 3763 3764 public: 3765 /// \brief Introduce a new scope where 'this' may be allowed (when enabled), 3766 /// using the given declaration (which is either a class template or a 3767 /// class) along with the given qualifiers. 3768 /// along with the qualifiers placed on '*this'. 3769 CXXThisScopeRAII(Sema &S, Decl *ContextDecl, unsigned CXXThisTypeQuals, 3770 bool Enabled = true); 3771 3772 ~CXXThisScopeRAII(); 3773 }; 3774 3775 /// \brief Make sure the value of 'this' is actually available in the current 3776 /// context, if it is a potentially evaluated context. 3777 /// 3778 /// \param Loc The location at which the capture of 'this' occurs. 3779 /// 3780 /// \param Explicit Whether 'this' is explicitly captured in a lambda 3781 /// capture list. 3782 void CheckCXXThisCapture(SourceLocation Loc, bool Explicit = false); 3783 3784 /// \brief Determine whether the given type is the type of *this that is used 3785 /// outside of the body of a member function for a type that is currently 3786 /// being defined. 3787 bool isThisOutsideMemberFunctionBody(QualType BaseType); 3788 3789 /// ActOnCXXBoolLiteral - Parse {true,false} literals. 3790 ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); 3791 3792 3793 /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals. 3794 ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); 3795 3796 /// ActOnCXXNullPtrLiteral - Parse 'nullptr'. 3797 ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc); 3798 3799 //// ActOnCXXThrow - Parse throw expressions. 3800 ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr); 3801 ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, 3802 bool IsThrownVarInScope); 3803 ExprResult CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *E, 3804 bool IsThrownVarInScope); 3805 3806 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. 3807 /// Can be interpreted either as function-style casting ("int(x)") 3808 /// or class type construction ("ClassType(x,y,z)") 3809 /// or creation of a value-initialized type ("int()"). 3810 ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep, 3811 SourceLocation LParenLoc, 3812 MultiExprArg Exprs, 3813 SourceLocation RParenLoc); 3814 3815 ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, 3816 SourceLocation LParenLoc, 3817 MultiExprArg Exprs, 3818 SourceLocation RParenLoc); 3819 3820 /// ActOnCXXNew - Parsed a C++ 'new' expression. 3821 ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, 3822 SourceLocation PlacementLParen, 3823 MultiExprArg PlacementArgs, 3824 SourceLocation PlacementRParen, 3825 SourceRange TypeIdParens, Declarator &D, 3826 Expr *Initializer); 3827 ExprResult BuildCXXNew(SourceRange Range, bool UseGlobal, 3828 SourceLocation PlacementLParen, 3829 MultiExprArg PlacementArgs, 3830 SourceLocation PlacementRParen, 3831 SourceRange TypeIdParens, 3832 QualType AllocType, 3833 TypeSourceInfo *AllocTypeInfo, 3834 Expr *ArraySize, 3835 SourceRange DirectInitRange, 3836 Expr *Initializer, 3837 bool TypeMayContainAuto = true); 3838 3839 bool CheckAllocatedType(QualType AllocType, SourceLocation Loc, 3840 SourceRange R); 3841 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, 3842 bool UseGlobal, QualType AllocType, bool IsArray, 3843 Expr **PlaceArgs, unsigned NumPlaceArgs, 3844 FunctionDecl *&OperatorNew, 3845 FunctionDecl *&OperatorDelete); 3846 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range, 3847 DeclarationName Name, Expr** Args, 3848 unsigned NumArgs, DeclContext *Ctx, 3849 bool AllowMissing, FunctionDecl *&Operator, 3850 bool Diagnose = true); 3851 void DeclareGlobalNewDelete(); 3852 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, 3853 QualType Argument, 3854 bool addMallocAttr = false); 3855 3856 bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, 3857 DeclarationName Name, FunctionDecl* &Operator, 3858 bool Diagnose = true); 3859 3860 /// ActOnCXXDelete - Parsed a C++ 'delete' expression 3861 ExprResult ActOnCXXDelete(SourceLocation StartLoc, 3862 bool UseGlobal, bool ArrayForm, 3863 Expr *Operand); 3864 3865 DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D); 3866 ExprResult CheckConditionVariable(VarDecl *ConditionVar, 3867 SourceLocation StmtLoc, 3868 bool ConvertToBoolean); 3869 3870 ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen, 3871 Expr *Operand, SourceLocation RParen); 3872 ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, 3873 SourceLocation RParen); 3874 3875 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support 3876 /// pseudo-functions. 3877 ExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT, 3878 SourceLocation KWLoc, 3879 ParsedType Ty, 3880 SourceLocation RParen); 3881 3882 ExprResult BuildUnaryTypeTrait(UnaryTypeTrait OTT, 3883 SourceLocation KWLoc, 3884 TypeSourceInfo *T, 3885 SourceLocation RParen); 3886 3887 /// ActOnBinaryTypeTrait - Parsed one of the bianry type trait support 3888 /// pseudo-functions. 3889 ExprResult ActOnBinaryTypeTrait(BinaryTypeTrait OTT, 3890 SourceLocation KWLoc, 3891 ParsedType LhsTy, 3892 ParsedType RhsTy, 3893 SourceLocation RParen); 3894 3895 ExprResult BuildBinaryTypeTrait(BinaryTypeTrait BTT, 3896 SourceLocation KWLoc, 3897 TypeSourceInfo *LhsT, 3898 TypeSourceInfo *RhsT, 3899 SourceLocation RParen); 3900 3901 /// \brief Parsed one of the type trait support pseudo-functions. 3902 ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc, 3903 ArrayRef<ParsedType> Args, 3904 SourceLocation RParenLoc); 3905 ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, 3906 ArrayRef<TypeSourceInfo *> Args, 3907 SourceLocation RParenLoc); 3908 3909 /// ActOnArrayTypeTrait - Parsed one of the bianry type trait support 3910 /// pseudo-functions. 3911 ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT, 3912 SourceLocation KWLoc, 3913 ParsedType LhsTy, 3914 Expr *DimExpr, 3915 SourceLocation RParen); 3916 3917 ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, 3918 SourceLocation KWLoc, 3919 TypeSourceInfo *TSInfo, 3920 Expr *DimExpr, 3921 SourceLocation RParen); 3922 3923 /// ActOnExpressionTrait - Parsed one of the unary type trait support 3924 /// pseudo-functions. 3925 ExprResult ActOnExpressionTrait(ExpressionTrait OET, 3926 SourceLocation KWLoc, 3927 Expr *Queried, 3928 SourceLocation RParen); 3929 3930 ExprResult BuildExpressionTrait(ExpressionTrait OET, 3931 SourceLocation KWLoc, 3932 Expr *Queried, 3933 SourceLocation RParen); 3934 3935 ExprResult ActOnStartCXXMemberReference(Scope *S, 3936 Expr *Base, 3937 SourceLocation OpLoc, 3938 tok::TokenKind OpKind, 3939 ParsedType &ObjectType, 3940 bool &MayBePseudoDestructor); 3941 3942 ExprResult DiagnoseDtorReference(SourceLocation NameLoc, Expr *MemExpr); 3943 3944 ExprResult BuildPseudoDestructorExpr(Expr *Base, 3945 SourceLocation OpLoc, 3946 tok::TokenKind OpKind, 3947 const CXXScopeSpec &SS, 3948 TypeSourceInfo *ScopeType, 3949 SourceLocation CCLoc, 3950 SourceLocation TildeLoc, 3951 PseudoDestructorTypeStorage DestroyedType, 3952 bool HasTrailingLParen); 3953 3954 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, 3955 SourceLocation OpLoc, 3956 tok::TokenKind OpKind, 3957 CXXScopeSpec &SS, 3958 UnqualifiedId &FirstTypeName, 3959 SourceLocation CCLoc, 3960 SourceLocation TildeLoc, 3961 UnqualifiedId &SecondTypeName, 3962 bool HasTrailingLParen); 3963 3964 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, 3965 SourceLocation OpLoc, 3966 tok::TokenKind OpKind, 3967 SourceLocation TildeLoc, 3968 const DeclSpec& DS, 3969 bool HasTrailingLParen); 3970 3971 /// MaybeCreateExprWithCleanups - If the current full-expression 3972 /// requires any cleanups, surround it with a ExprWithCleanups node. 3973 /// Otherwise, just returns the passed-in expression. 3974 Expr *MaybeCreateExprWithCleanups(Expr *SubExpr); 3975 Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt); 3976 ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr); 3977 3978 ExprResult ActOnFinishFullExpr(Expr *Expr) { 3979 return ActOnFinishFullExpr(Expr, Expr ? Expr->getExprLoc() 3980 : SourceLocation()); 3981 } 3982 ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC, 3983 bool DiscardedValue = false); 3984 StmtResult ActOnFinishFullStmt(Stmt *Stmt); 3985 3986 // Marks SS invalid if it represents an incomplete type. 3987 bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC); 3988 3989 DeclContext *computeDeclContext(QualType T); 3990 DeclContext *computeDeclContext(const CXXScopeSpec &SS, 3991 bool EnteringContext = false); 3992 bool isDependentScopeSpecifier(const CXXScopeSpec &SS); 3993 CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS); 3994 bool isUnknownSpecialization(const CXXScopeSpec &SS); 3995 3996 /// \brief The parser has parsed a global nested-name-specifier '::'. 3997 /// 3998 /// \param S The scope in which this nested-name-specifier occurs. 3999 /// 4000 /// \param CCLoc The location of the '::'. 4001 /// 4002 /// \param SS The nested-name-specifier, which will be updated in-place 4003 /// to reflect the parsed nested-name-specifier. 4004 /// 4005 /// \returns true if an error occurred, false otherwise. 4006 bool ActOnCXXGlobalScopeSpecifier(Scope *S, SourceLocation CCLoc, 4007 CXXScopeSpec &SS); 4008 4009 bool isAcceptableNestedNameSpecifier(NamedDecl *SD); 4010 NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS); 4011 4012 bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS, 4013 SourceLocation IdLoc, 4014 IdentifierInfo &II, 4015 ParsedType ObjectType); 4016 4017 bool BuildCXXNestedNameSpecifier(Scope *S, 4018 IdentifierInfo &Identifier, 4019 SourceLocation IdentifierLoc, 4020 SourceLocation CCLoc, 4021 QualType ObjectType, 4022 bool EnteringContext, 4023 CXXScopeSpec &SS, 4024 NamedDecl *ScopeLookupResult, 4025 bool ErrorRecoveryLookup); 4026 4027 /// \brief The parser has parsed a nested-name-specifier 'identifier::'. 4028 /// 4029 /// \param S The scope in which this nested-name-specifier occurs. 4030 /// 4031 /// \param Identifier The identifier preceding the '::'. 4032 /// 4033 /// \param IdentifierLoc The location of the identifier. 4034 /// 4035 /// \param CCLoc The location of the '::'. 4036 /// 4037 /// \param ObjectType The type of the object, if we're parsing 4038 /// nested-name-specifier in a member access expression. 4039 /// 4040 /// \param EnteringContext Whether we're entering the context nominated by 4041 /// this nested-name-specifier. 4042 /// 4043 /// \param SS The nested-name-specifier, which is both an input 4044 /// parameter (the nested-name-specifier before this type) and an 4045 /// output parameter (containing the full nested-name-specifier, 4046 /// including this new type). 4047 /// 4048 /// \returns true if an error occurred, false otherwise. 4049 bool ActOnCXXNestedNameSpecifier(Scope *S, 4050 IdentifierInfo &Identifier, 4051 SourceLocation IdentifierLoc, 4052 SourceLocation CCLoc, 4053 ParsedType ObjectType, 4054 bool EnteringContext, 4055 CXXScopeSpec &SS); 4056 4057 ExprResult ActOnDecltypeExpression(Expr *E); 4058 4059 bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, 4060 const DeclSpec &DS, 4061 SourceLocation ColonColonLoc); 4062 4063 bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, 4064 IdentifierInfo &Identifier, 4065 SourceLocation IdentifierLoc, 4066 SourceLocation ColonLoc, 4067 ParsedType ObjectType, 4068 bool EnteringContext); 4069 4070 /// \brief The parser has parsed a nested-name-specifier 4071 /// 'template[opt] template-name < template-args >::'. 4072 /// 4073 /// \param S The scope in which this nested-name-specifier occurs. 4074 /// 4075 /// \param SS The nested-name-specifier, which is both an input 4076 /// parameter (the nested-name-specifier before this type) and an 4077 /// output parameter (containing the full nested-name-specifier, 4078 /// including this new type). 4079 /// 4080 /// \param TemplateKWLoc the location of the 'template' keyword, if any. 4081 /// \param TemplateName the template name. 4082 /// \param TemplateNameLoc The location of the template name. 4083 /// \param LAngleLoc The location of the opening angle bracket ('<'). 4084 /// \param TemplateArgs The template arguments. 4085 /// \param RAngleLoc The location of the closing angle bracket ('>'). 4086 /// \param CCLoc The location of the '::'. 4087 /// 4088 /// \param EnteringContext Whether we're entering the context of the 4089 /// nested-name-specifier. 4090 /// 4091 /// 4092 /// \returns true if an error occurred, false otherwise. 4093 bool ActOnCXXNestedNameSpecifier(Scope *S, 4094 CXXScopeSpec &SS, 4095 SourceLocation TemplateKWLoc, 4096 TemplateTy TemplateName, 4097 SourceLocation TemplateNameLoc, 4098 SourceLocation LAngleLoc, 4099 ASTTemplateArgsPtr TemplateArgs, 4100 SourceLocation RAngleLoc, 4101 SourceLocation CCLoc, 4102 bool EnteringContext); 4103 4104 /// \brief Given a C++ nested-name-specifier, produce an annotation value 4105 /// that the parser can use later to reconstruct the given 4106 /// nested-name-specifier. 4107 /// 4108 /// \param SS A nested-name-specifier. 4109 /// 4110 /// \returns A pointer containing all of the information in the 4111 /// nested-name-specifier \p SS. 4112 void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS); 4113 4114 /// \brief Given an annotation pointer for a nested-name-specifier, restore 4115 /// the nested-name-specifier structure. 4116 /// 4117 /// \param Annotation The annotation pointer, produced by 4118 /// \c SaveNestedNameSpecifierAnnotation(). 4119 /// 4120 /// \param AnnotationRange The source range corresponding to the annotation. 4121 /// 4122 /// \param SS The nested-name-specifier that will be updated with the contents 4123 /// of the annotation pointer. 4124 void RestoreNestedNameSpecifierAnnotation(void *Annotation, 4125 SourceRange AnnotationRange, 4126 CXXScopeSpec &SS); 4127 4128 bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); 4129 4130 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global 4131 /// scope or nested-name-specifier) is parsed, part of a declarator-id. 4132 /// After this method is called, according to [C++ 3.4.3p3], names should be 4133 /// looked up in the declarator-id's scope, until the declarator is parsed and 4134 /// ActOnCXXExitDeclaratorScope is called. 4135 /// The 'SS' should be a non-empty valid CXXScopeSpec. 4136 bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS); 4137 4138 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously 4139 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same 4140 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. 4141 /// Used to indicate that names should revert to being looked up in the 4142 /// defining scope. 4143 void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); 4144 4145 /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an 4146 /// initializer for the declaration 'Dcl'. 4147 /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a 4148 /// static data member of class X, names should be looked up in the scope of 4149 /// class X. 4150 void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl); 4151 4152 /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an 4153 /// initializer for the declaration 'Dcl'. 4154 void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl); 4155 4156 /// \brief Create a new lambda closure type. 4157 CXXRecordDecl *createLambdaClosureType(SourceRange IntroducerRange, 4158 TypeSourceInfo *Info, 4159 bool KnownDependent); 4160 4161 /// \brief Start the definition of a lambda expression. 4162 CXXMethodDecl *startLambdaDefinition(CXXRecordDecl *Class, 4163 SourceRange IntroducerRange, 4164 TypeSourceInfo *MethodType, 4165 SourceLocation EndLoc, 4166 ArrayRef<ParmVarDecl *> Params); 4167 4168 /// \brief Introduce the scope for a lambda expression. 4169 sema::LambdaScopeInfo *enterLambdaScope(CXXMethodDecl *CallOperator, 4170 SourceRange IntroducerRange, 4171 LambdaCaptureDefault CaptureDefault, 4172 bool ExplicitParams, 4173 bool ExplicitResultType, 4174 bool Mutable); 4175 4176 /// \brief Note that we have finished the explicit captures for the 4177 /// given lambda. 4178 void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI); 4179 4180 /// \brief Introduce the lambda parameters into scope. 4181 void addLambdaParameters(CXXMethodDecl *CallOperator, Scope *CurScope); 4182 4183 /// \brief Deduce a block or lambda's return type based on the return 4184 /// statements present in the body. 4185 void deduceClosureReturnType(sema::CapturingScopeInfo &CSI); 4186 4187 /// ActOnStartOfLambdaDefinition - This is called just before we start 4188 /// parsing the body of a lambda; it analyzes the explicit captures and 4189 /// arguments, and sets up various data-structures for the body of the 4190 /// lambda. 4191 void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, 4192 Declarator &ParamInfo, Scope *CurScope); 4193 4194 /// ActOnLambdaError - If there is an error parsing a lambda, this callback 4195 /// is invoked to pop the information about the lambda. 4196 void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope, 4197 bool IsInstantiation = false); 4198 4199 /// ActOnLambdaExpr - This is called when the body of a lambda expression 4200 /// was successfully completed. 4201 ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body, 4202 Scope *CurScope, 4203 bool IsInstantiation = false); 4204 4205 /// \brief Define the "body" of the conversion from a lambda object to a 4206 /// function pointer. 4207 /// 4208 /// This routine doesn't actually define a sensible body; rather, it fills 4209 /// in the initialization expression needed to copy the lambda object into 4210 /// the block, and IR generation actually generates the real body of the 4211 /// block pointer conversion. 4212 void DefineImplicitLambdaToFunctionPointerConversion( 4213 SourceLocation CurrentLoc, CXXConversionDecl *Conv); 4214 4215 /// \brief Define the "body" of the conversion from a lambda object to a 4216 /// block pointer. 4217 /// 4218 /// This routine doesn't actually define a sensible body; rather, it fills 4219 /// in the initialization expression needed to copy the lambda object into 4220 /// the block, and IR generation actually generates the real body of the 4221 /// block pointer conversion. 4222 void DefineImplicitLambdaToBlockPointerConversion(SourceLocation CurrentLoc, 4223 CXXConversionDecl *Conv); 4224 4225 ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, 4226 SourceLocation ConvLocation, 4227 CXXConversionDecl *Conv, 4228 Expr *Src); 4229 4230 // ParseObjCStringLiteral - Parse Objective-C string literals. 4231 ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, 4232 Expr **Strings, 4233 unsigned NumStrings); 4234 4235 ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S); 4236 4237 /// BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the 4238 /// numeric literal expression. Type of the expression will be "NSNumber *" 4239 /// or "id" if NSNumber is unavailable. 4240 ExprResult BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number); 4241 ExprResult ActOnObjCBoolLiteral(SourceLocation AtLoc, SourceLocation ValueLoc, 4242 bool Value); 4243 ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements); 4244 4245 /// BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the 4246 /// '@' prefixed parenthesized expression. The type of the expression will 4247 /// either be "NSNumber *" or "NSString *" depending on the type of 4248 /// ValueType, which is allowed to be a built-in numeric type or 4249 /// "char *" or "const char *". 4250 ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr); 4251 4252 ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, 4253 Expr *IndexExpr, 4254 ObjCMethodDecl *getterMethod, 4255 ObjCMethodDecl *setterMethod); 4256 4257 ExprResult BuildObjCDictionaryLiteral(SourceRange SR, 4258 ObjCDictionaryElement *Elements, 4259 unsigned NumElements); 4260 4261 ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, 4262 TypeSourceInfo *EncodedTypeInfo, 4263 SourceLocation RParenLoc); 4264 ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, 4265 CXXConversionDecl *Method, 4266 bool HadMultipleCandidates); 4267 4268 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, 4269 SourceLocation EncodeLoc, 4270 SourceLocation LParenLoc, 4271 ParsedType Ty, 4272 SourceLocation RParenLoc); 4273 4274 /// ParseObjCSelectorExpression - Build selector expression for \@selector 4275 ExprResult ParseObjCSelectorExpression(Selector Sel, 4276 SourceLocation AtLoc, 4277 SourceLocation SelLoc, 4278 SourceLocation LParenLoc, 4279 SourceLocation RParenLoc); 4280 4281 /// ParseObjCProtocolExpression - Build protocol expression for \@protocol 4282 ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName, 4283 SourceLocation AtLoc, 4284 SourceLocation ProtoLoc, 4285 SourceLocation LParenLoc, 4286 SourceLocation ProtoIdLoc, 4287 SourceLocation RParenLoc); 4288 4289 //===--------------------------------------------------------------------===// 4290 // C++ Declarations 4291 // 4292 Decl *ActOnStartLinkageSpecification(Scope *S, 4293 SourceLocation ExternLoc, 4294 SourceLocation LangLoc, 4295 StringRef Lang, 4296 SourceLocation LBraceLoc); 4297 Decl *ActOnFinishLinkageSpecification(Scope *S, 4298 Decl *LinkageSpec, 4299 SourceLocation RBraceLoc); 4300 4301 4302 //===--------------------------------------------------------------------===// 4303 // C++ Classes 4304 // 4305 bool isCurrentClassName(const IdentifierInfo &II, Scope *S, 4306 const CXXScopeSpec *SS = 0); 4307 4308 bool ActOnAccessSpecifier(AccessSpecifier Access, 4309 SourceLocation ASLoc, 4310 SourceLocation ColonLoc, 4311 AttributeList *Attrs = 0); 4312 4313 NamedDecl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, 4314 Declarator &D, 4315 MultiTemplateParamsArg TemplateParameterLists, 4316 Expr *BitfieldWidth, const VirtSpecifiers &VS, 4317 InClassInitStyle InitStyle); 4318 void ActOnCXXInClassMemberInitializer(Decl *VarDecl, SourceLocation EqualLoc, 4319 Expr *Init); 4320 4321 MemInitResult ActOnMemInitializer(Decl *ConstructorD, 4322 Scope *S, 4323 CXXScopeSpec &SS, 4324 IdentifierInfo *MemberOrBase, 4325 ParsedType TemplateTypeTy, 4326 const DeclSpec &DS, 4327 SourceLocation IdLoc, 4328 SourceLocation LParenLoc, 4329 Expr **Args, unsigned NumArgs, 4330 SourceLocation RParenLoc, 4331 SourceLocation EllipsisLoc); 4332 4333 MemInitResult ActOnMemInitializer(Decl *ConstructorD, 4334 Scope *S, 4335 CXXScopeSpec &SS, 4336 IdentifierInfo *MemberOrBase, 4337 ParsedType TemplateTypeTy, 4338 const DeclSpec &DS, 4339 SourceLocation IdLoc, 4340 Expr *InitList, 4341 SourceLocation EllipsisLoc); 4342 4343 MemInitResult BuildMemInitializer(Decl *ConstructorD, 4344 Scope *S, 4345 CXXScopeSpec &SS, 4346 IdentifierInfo *MemberOrBase, 4347 ParsedType TemplateTypeTy, 4348 const DeclSpec &DS, 4349 SourceLocation IdLoc, 4350 Expr *Init, 4351 SourceLocation EllipsisLoc); 4352 4353 MemInitResult BuildMemberInitializer(ValueDecl *Member, 4354 Expr *Init, 4355 SourceLocation IdLoc); 4356 4357 MemInitResult BuildBaseInitializer(QualType BaseType, 4358 TypeSourceInfo *BaseTInfo, 4359 Expr *Init, 4360 CXXRecordDecl *ClassDecl, 4361 SourceLocation EllipsisLoc); 4362 4363 MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo, 4364 Expr *Init, 4365 CXXRecordDecl *ClassDecl); 4366 4367 bool SetDelegatingInitializer(CXXConstructorDecl *Constructor, 4368 CXXCtorInitializer *Initializer); 4369 4370 bool SetCtorInitializers(CXXConstructorDecl *Constructor, 4371 CXXCtorInitializer **Initializers, 4372 unsigned NumInitializers, bool AnyErrors); 4373 4374 void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation); 4375 4376 4377 /// MarkBaseAndMemberDestructorsReferenced - Given a record decl, 4378 /// mark all the non-trivial destructors of its members and bases as 4379 /// referenced. 4380 void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc, 4381 CXXRecordDecl *Record); 4382 4383 /// \brief The list of classes whose vtables have been used within 4384 /// this translation unit, and the source locations at which the 4385 /// first use occurred. 4386 typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse; 4387 4388 /// \brief The list of vtables that are required but have not yet been 4389 /// materialized. 4390 SmallVector<VTableUse, 16> VTableUses; 4391 4392 /// \brief The set of classes whose vtables have been used within 4393 /// this translation unit, and a bit that will be true if the vtable is 4394 /// required to be emitted (otherwise, it should be emitted only if needed 4395 /// by code generation). 4396 llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed; 4397 4398 /// \brief Load any externally-stored vtable uses. 4399 void LoadExternalVTableUses(); 4400 4401 typedef LazyVector<CXXRecordDecl *, ExternalSemaSource, 4402 &ExternalSemaSource::ReadDynamicClasses, 2, 2> 4403 DynamicClassesType; 4404 4405 /// \brief A list of all of the dynamic classes in this translation 4406 /// unit. 4407 DynamicClassesType DynamicClasses; 4408 4409 /// \brief Note that the vtable for the given class was used at the 4410 /// given location. 4411 void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, 4412 bool DefinitionRequired = false); 4413 4414 /// \brief Mark the exception specifications of all virtual member functions 4415 /// in the given class as needed. 4416 void MarkVirtualMemberExceptionSpecsNeeded(SourceLocation Loc, 4417 const CXXRecordDecl *RD); 4418 4419 /// MarkVirtualMembersReferenced - Will mark all members of the given 4420 /// CXXRecordDecl referenced. 4421 void MarkVirtualMembersReferenced(SourceLocation Loc, 4422 const CXXRecordDecl *RD); 4423 4424 /// \brief Define all of the vtables that have been used in this 4425 /// translation unit and reference any virtual members used by those 4426 /// vtables. 4427 /// 4428 /// \returns true if any work was done, false otherwise. 4429 bool DefineUsedVTables(); 4430 4431 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); 4432 4433 void ActOnMemInitializers(Decl *ConstructorDecl, 4434 SourceLocation ColonLoc, 4435 CXXCtorInitializer **MemInits, 4436 unsigned NumMemInits, 4437 bool AnyErrors); 4438 4439 void CheckCompletedCXXClass(CXXRecordDecl *Record); 4440 void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, 4441 Decl *TagDecl, 4442 SourceLocation LBrac, 4443 SourceLocation RBrac, 4444 AttributeList *AttrList); 4445 void ActOnFinishCXXMemberDecls(); 4446 4447 void ActOnReenterTemplateScope(Scope *S, Decl *Template); 4448 void ActOnReenterDeclaratorTemplateScope(Scope *S, DeclaratorDecl *D); 4449 void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record); 4450 void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 4451 void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param); 4452 void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record); 4453 void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 4454 void ActOnFinishDelayedMemberInitializers(Decl *Record); 4455 void MarkAsLateParsedTemplate(FunctionDecl *FD, bool Flag = true); 4456 bool IsInsideALocalClassWithinATemplateFunction(); 4457 4458 Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, 4459 Expr *AssertExpr, 4460 Expr *AssertMessageExpr, 4461 SourceLocation RParenLoc); 4462 Decl *BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc, 4463 Expr *AssertExpr, 4464 StringLiteral *AssertMessageExpr, 4465 SourceLocation RParenLoc, 4466 bool Failed); 4467 4468 FriendDecl *CheckFriendTypeDecl(SourceLocation LocStart, 4469 SourceLocation FriendLoc, 4470 TypeSourceInfo *TSInfo); 4471 Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS, 4472 MultiTemplateParamsArg TemplateParams); 4473 NamedDecl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, 4474 MultiTemplateParamsArg TemplateParams); 4475 4476 QualType CheckConstructorDeclarator(Declarator &D, QualType R, 4477 StorageClass& SC); 4478 void CheckConstructor(CXXConstructorDecl *Constructor); 4479 QualType CheckDestructorDeclarator(Declarator &D, QualType R, 4480 StorageClass& SC); 4481 bool CheckDestructor(CXXDestructorDecl *Destructor); 4482 void CheckConversionDeclarator(Declarator &D, QualType &R, 4483 StorageClass& SC); 4484 Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion); 4485 4486 void CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD); 4487 void CheckExplicitlyDefaultedMemberExceptionSpec(CXXMethodDecl *MD, 4488 const FunctionProtoType *T); 4489 void CheckDelayedExplicitlyDefaultedMemberExceptionSpecs(); 4490 4491 //===--------------------------------------------------------------------===// 4492 // C++ Derived Classes 4493 // 4494 4495 /// ActOnBaseSpecifier - Parsed a base specifier 4496 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, 4497 SourceRange SpecifierRange, 4498 bool Virtual, AccessSpecifier Access, 4499 TypeSourceInfo *TInfo, 4500 SourceLocation EllipsisLoc); 4501 4502 BaseResult ActOnBaseSpecifier(Decl *classdecl, 4503 SourceRange SpecifierRange, 4504 bool Virtual, AccessSpecifier Access, 4505 ParsedType basetype, 4506 SourceLocation BaseLoc, 4507 SourceLocation EllipsisLoc); 4508 4509 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases, 4510 unsigned NumBases); 4511 void ActOnBaseSpecifiers(Decl *ClassDecl, CXXBaseSpecifier **Bases, 4512 unsigned NumBases); 4513 4514 bool IsDerivedFrom(QualType Derived, QualType Base); 4515 bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths); 4516 4517 // FIXME: I don't like this name. 4518 void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath); 4519 4520 bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath); 4521 4522 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 4523 SourceLocation Loc, SourceRange Range, 4524 CXXCastPath *BasePath = 0, 4525 bool IgnoreAccess = false); 4526 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 4527 unsigned InaccessibleBaseID, 4528 unsigned AmbigiousBaseConvID, 4529 SourceLocation Loc, SourceRange Range, 4530 DeclarationName Name, 4531 CXXCastPath *BasePath); 4532 4533 std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths); 4534 4535 bool CheckOverridingFunctionAttributes(const CXXMethodDecl *New, 4536 const CXXMethodDecl *Old); 4537 4538 /// CheckOverridingFunctionReturnType - Checks whether the return types are 4539 /// covariant, according to C++ [class.virtual]p5. 4540 bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, 4541 const CXXMethodDecl *Old); 4542 4543 /// CheckOverridingFunctionExceptionSpec - Checks whether the exception 4544 /// spec is a subset of base spec. 4545 bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, 4546 const CXXMethodDecl *Old); 4547 4548 bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange); 4549 4550 /// CheckOverrideControl - Check C++11 override control semantics. 4551 void CheckOverrideControl(Decl *D); 4552 4553 /// CheckForFunctionMarkedFinal - Checks whether a virtual member function 4554 /// overrides a virtual member function marked 'final', according to 4555 /// C++11 [class.virtual]p4. 4556 bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New, 4557 const CXXMethodDecl *Old); 4558 4559 4560 //===--------------------------------------------------------------------===// 4561 // C++ Access Control 4562 // 4563 4564 enum AccessResult { 4565 AR_accessible, 4566 AR_inaccessible, 4567 AR_dependent, 4568 AR_delayed 4569 }; 4570 4571 bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, 4572 NamedDecl *PrevMemberDecl, 4573 AccessSpecifier LexicalAS); 4574 4575 AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E, 4576 DeclAccessPair FoundDecl); 4577 AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E, 4578 DeclAccessPair FoundDecl); 4579 AccessResult CheckAllocationAccess(SourceLocation OperatorLoc, 4580 SourceRange PlacementRange, 4581 CXXRecordDecl *NamingClass, 4582 DeclAccessPair FoundDecl, 4583 bool Diagnose = true); 4584 AccessResult CheckConstructorAccess(SourceLocation Loc, 4585 CXXConstructorDecl *D, 4586 const InitializedEntity &Entity, 4587 AccessSpecifier Access, 4588 bool IsCopyBindingRefToTemp = false); 4589 AccessResult CheckConstructorAccess(SourceLocation Loc, 4590 CXXConstructorDecl *D, 4591 const InitializedEntity &Entity, 4592 AccessSpecifier Access, 4593 const PartialDiagnostic &PDiag); 4594 AccessResult CheckDestructorAccess(SourceLocation Loc, 4595 CXXDestructorDecl *Dtor, 4596 const PartialDiagnostic &PDiag, 4597 QualType objectType = QualType()); 4598 AccessResult CheckFriendAccess(NamedDecl *D); 4599 AccessResult CheckMemberOperatorAccess(SourceLocation Loc, 4600 Expr *ObjectExpr, 4601 Expr *ArgExpr, 4602 DeclAccessPair FoundDecl); 4603 AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, 4604 DeclAccessPair FoundDecl); 4605 AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, 4606 QualType Base, QualType Derived, 4607 const CXXBasePath &Path, 4608 unsigned DiagID, 4609 bool ForceCheck = false, 4610 bool ForceUnprivileged = false); 4611 void CheckLookupAccess(const LookupResult &R); 4612 bool IsSimplyAccessible(NamedDecl *decl, DeclContext *Ctx); 4613 bool isSpecialMemberAccessibleForDeletion(CXXMethodDecl *decl, 4614 AccessSpecifier access, 4615 QualType objectType); 4616 4617 void HandleDependentAccessCheck(const DependentDiagnostic &DD, 4618 const MultiLevelTemplateArgumentList &TemplateArgs); 4619 void PerformDependentDiagnostics(const DeclContext *Pattern, 4620 const MultiLevelTemplateArgumentList &TemplateArgs); 4621 4622 void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); 4623 4624 /// \brief When true, access checking violations are treated as SFINAE 4625 /// failures rather than hard errors. 4626 bool AccessCheckingSFINAE; 4627 4628 enum AbstractDiagSelID { 4629 AbstractNone = -1, 4630 AbstractReturnType, 4631 AbstractParamType, 4632 AbstractVariableType, 4633 AbstractFieldType, 4634 AbstractIvarType, 4635 AbstractArrayType 4636 }; 4637 4638 bool RequireNonAbstractType(SourceLocation Loc, QualType T, 4639 TypeDiagnoser &Diagnoser); 4640 template<typename T1> 4641 bool RequireNonAbstractType(SourceLocation Loc, QualType T, 4642 unsigned DiagID, 4643 const T1 &Arg1) { 4644 BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1); 4645 return RequireNonAbstractType(Loc, T, Diagnoser); 4646 } 4647 4648 template<typename T1, typename T2> 4649 bool RequireNonAbstractType(SourceLocation Loc, QualType T, 4650 unsigned DiagID, 4651 const T1 &Arg1, const T2 &Arg2) { 4652 BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2); 4653 return RequireNonAbstractType(Loc, T, Diagnoser); 4654 } 4655 4656 template<typename T1, typename T2, typename T3> 4657 bool RequireNonAbstractType(SourceLocation Loc, QualType T, 4658 unsigned DiagID, 4659 const T1 &Arg1, const T2 &Arg2, const T3 &Arg3) { 4660 BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2, Arg3); 4661 return RequireNonAbstractType(Loc, T, Diagnoser); 4662 } 4663 4664 void DiagnoseAbstractType(const CXXRecordDecl *RD); 4665 4666 bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, 4667 AbstractDiagSelID SelID = AbstractNone); 4668 4669 //===--------------------------------------------------------------------===// 4670 // C++ Overloaded Operators [C++ 13.5] 4671 // 4672 4673 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); 4674 4675 bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl); 4676 4677 //===--------------------------------------------------------------------===// 4678 // C++ Templates [C++ 14] 4679 // 4680 void FilterAcceptableTemplateNames(LookupResult &R, 4681 bool AllowFunctionTemplates = true); 4682 bool hasAnyAcceptableTemplateNames(LookupResult &R, 4683 bool AllowFunctionTemplates = true); 4684 4685 void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS, 4686 QualType ObjectType, bool EnteringContext, 4687 bool &MemberOfUnknownSpecialization); 4688 4689 TemplateNameKind isTemplateName(Scope *S, 4690 CXXScopeSpec &SS, 4691 bool hasTemplateKeyword, 4692 UnqualifiedId &Name, 4693 ParsedType ObjectType, 4694 bool EnteringContext, 4695 TemplateTy &Template, 4696 bool &MemberOfUnknownSpecialization); 4697 4698 bool DiagnoseUnknownTemplateName(const IdentifierInfo &II, 4699 SourceLocation IILoc, 4700 Scope *S, 4701 const CXXScopeSpec *SS, 4702 TemplateTy &SuggestedTemplate, 4703 TemplateNameKind &SuggestedKind); 4704 4705 void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); 4706 TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl); 4707 4708 Decl *ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis, 4709 SourceLocation EllipsisLoc, 4710 SourceLocation KeyLoc, 4711 IdentifierInfo *ParamName, 4712 SourceLocation ParamNameLoc, 4713 unsigned Depth, unsigned Position, 4714 SourceLocation EqualLoc, 4715 ParsedType DefaultArg); 4716 4717 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); 4718 Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, 4719 unsigned Depth, 4720 unsigned Position, 4721 SourceLocation EqualLoc, 4722 Expr *DefaultArg); 4723 Decl *ActOnTemplateTemplateParameter(Scope *S, 4724 SourceLocation TmpLoc, 4725 TemplateParameterList *Params, 4726 SourceLocation EllipsisLoc, 4727 IdentifierInfo *ParamName, 4728 SourceLocation ParamNameLoc, 4729 unsigned Depth, 4730 unsigned Position, 4731 SourceLocation EqualLoc, 4732 ParsedTemplateArgument DefaultArg); 4733 4734 TemplateParameterList * 4735 ActOnTemplateParameterList(unsigned Depth, 4736 SourceLocation ExportLoc, 4737 SourceLocation TemplateLoc, 4738 SourceLocation LAngleLoc, 4739 Decl **Params, unsigned NumParams, 4740 SourceLocation RAngleLoc); 4741 4742 /// \brief The context in which we are checking a template parameter 4743 /// list. 4744 enum TemplateParamListContext { 4745 TPC_ClassTemplate, 4746 TPC_FunctionTemplate, 4747 TPC_ClassTemplateMember, 4748 TPC_FriendFunctionTemplate, 4749 TPC_FriendFunctionTemplateDefinition, 4750 TPC_TypeAliasTemplate 4751 }; 4752 4753 bool CheckTemplateParameterList(TemplateParameterList *NewParams, 4754 TemplateParameterList *OldParams, 4755 TemplateParamListContext TPC); 4756 TemplateParameterList * 4757 MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, 4758 SourceLocation DeclLoc, 4759 const CXXScopeSpec &SS, 4760 TemplateParameterList **ParamLists, 4761 unsigned NumParamLists, 4762 bool IsFriend, 4763 bool &IsExplicitSpecialization, 4764 bool &Invalid); 4765 4766 DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, 4767 SourceLocation KWLoc, CXXScopeSpec &SS, 4768 IdentifierInfo *Name, SourceLocation NameLoc, 4769 AttributeList *Attr, 4770 TemplateParameterList *TemplateParams, 4771 AccessSpecifier AS, 4772 SourceLocation ModulePrivateLoc, 4773 unsigned NumOuterTemplateParamLists, 4774 TemplateParameterList **OuterTemplateParamLists); 4775 4776 void translateTemplateArguments(const ASTTemplateArgsPtr &In, 4777 TemplateArgumentListInfo &Out); 4778 4779 void NoteAllFoundTemplates(TemplateName Name); 4780 4781 QualType CheckTemplateIdType(TemplateName Template, 4782 SourceLocation TemplateLoc, 4783 TemplateArgumentListInfo &TemplateArgs); 4784 4785 TypeResult 4786 ActOnTemplateIdType(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, 4787 TemplateTy Template, SourceLocation TemplateLoc, 4788 SourceLocation LAngleLoc, 4789 ASTTemplateArgsPtr TemplateArgs, 4790 SourceLocation RAngleLoc, 4791 bool IsCtorOrDtorName = false); 4792 4793 /// \brief Parsed an elaborated-type-specifier that refers to a template-id, 4794 /// such as \c class T::template apply<U>. 4795 TypeResult ActOnTagTemplateIdType(TagUseKind TUK, 4796 TypeSpecifierType TagSpec, 4797 SourceLocation TagLoc, 4798 CXXScopeSpec &SS, 4799 SourceLocation TemplateKWLoc, 4800 TemplateTy TemplateD, 4801 SourceLocation TemplateLoc, 4802 SourceLocation LAngleLoc, 4803 ASTTemplateArgsPtr TemplateArgsIn, 4804 SourceLocation RAngleLoc); 4805 4806 4807 ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, 4808 SourceLocation TemplateKWLoc, 4809 LookupResult &R, 4810 bool RequiresADL, 4811 const TemplateArgumentListInfo *TemplateArgs); 4812 4813 ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, 4814 SourceLocation TemplateKWLoc, 4815 const DeclarationNameInfo &NameInfo, 4816 const TemplateArgumentListInfo *TemplateArgs); 4817 4818 TemplateNameKind ActOnDependentTemplateName(Scope *S, 4819 CXXScopeSpec &SS, 4820 SourceLocation TemplateKWLoc, 4821 UnqualifiedId &Name, 4822 ParsedType ObjectType, 4823 bool EnteringContext, 4824 TemplateTy &Template); 4825 4826 DeclResult 4827 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK, 4828 SourceLocation KWLoc, 4829 SourceLocation ModulePrivateLoc, 4830 CXXScopeSpec &SS, 4831 TemplateTy Template, 4832 SourceLocation TemplateNameLoc, 4833 SourceLocation LAngleLoc, 4834 ASTTemplateArgsPtr TemplateArgs, 4835 SourceLocation RAngleLoc, 4836 AttributeList *Attr, 4837 MultiTemplateParamsArg TemplateParameterLists); 4838 4839 Decl *ActOnTemplateDeclarator(Scope *S, 4840 MultiTemplateParamsArg TemplateParameterLists, 4841 Declarator &D); 4842 4843 Decl *ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope, 4844 MultiTemplateParamsArg TemplateParameterLists, 4845 Declarator &D); 4846 4847 bool 4848 CheckSpecializationInstantiationRedecl(SourceLocation NewLoc, 4849 TemplateSpecializationKind NewTSK, 4850 NamedDecl *PrevDecl, 4851 TemplateSpecializationKind PrevTSK, 4852 SourceLocation PrevPtOfInstantiation, 4853 bool &SuppressNew); 4854 4855 bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD, 4856 const TemplateArgumentListInfo &ExplicitTemplateArgs, 4857 LookupResult &Previous); 4858 4859 bool CheckFunctionTemplateSpecialization(FunctionDecl *FD, 4860 TemplateArgumentListInfo *ExplicitTemplateArgs, 4861 LookupResult &Previous); 4862 bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous); 4863 4864 DeclResult 4865 ActOnExplicitInstantiation(Scope *S, 4866 SourceLocation ExternLoc, 4867 SourceLocation TemplateLoc, 4868 unsigned TagSpec, 4869 SourceLocation KWLoc, 4870 const CXXScopeSpec &SS, 4871 TemplateTy Template, 4872 SourceLocation TemplateNameLoc, 4873 SourceLocation LAngleLoc, 4874 ASTTemplateArgsPtr TemplateArgs, 4875 SourceLocation RAngleLoc, 4876 AttributeList *Attr); 4877 4878 DeclResult 4879 ActOnExplicitInstantiation(Scope *S, 4880 SourceLocation ExternLoc, 4881 SourceLocation TemplateLoc, 4882 unsigned TagSpec, 4883 SourceLocation KWLoc, 4884 CXXScopeSpec &SS, 4885 IdentifierInfo *Name, 4886 SourceLocation NameLoc, 4887 AttributeList *Attr); 4888 4889 DeclResult ActOnExplicitInstantiation(Scope *S, 4890 SourceLocation ExternLoc, 4891 SourceLocation TemplateLoc, 4892 Declarator &D); 4893 4894 TemplateArgumentLoc 4895 SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, 4896 SourceLocation TemplateLoc, 4897 SourceLocation RAngleLoc, 4898 Decl *Param, 4899 SmallVectorImpl<TemplateArgument> &Converted); 4900 4901 /// \brief Specifies the context in which a particular template 4902 /// argument is being checked. 4903 enum CheckTemplateArgumentKind { 4904 /// \brief The template argument was specified in the code or was 4905 /// instantiated with some deduced template arguments. 4906 CTAK_Specified, 4907 4908 /// \brief The template argument was deduced via template argument 4909 /// deduction. 4910 CTAK_Deduced, 4911 4912 /// \brief The template argument was deduced from an array bound 4913 /// via template argument deduction. 4914 CTAK_DeducedFromArrayBound 4915 }; 4916 4917 bool CheckTemplateArgument(NamedDecl *Param, 4918 const TemplateArgumentLoc &Arg, 4919 NamedDecl *Template, 4920 SourceLocation TemplateLoc, 4921 SourceLocation RAngleLoc, 4922 unsigned ArgumentPackIndex, 4923 SmallVectorImpl<TemplateArgument> &Converted, 4924 CheckTemplateArgumentKind CTAK = CTAK_Specified); 4925 4926 /// \brief Check that the given template arguments can be be provided to 4927 /// the given template, converting the arguments along the way. 4928 /// 4929 /// \param Template The template to which the template arguments are being 4930 /// provided. 4931 /// 4932 /// \param TemplateLoc The location of the template name in the source. 4933 /// 4934 /// \param TemplateArgs The list of template arguments. If the template is 4935 /// a template template parameter, this function may extend the set of 4936 /// template arguments to also include substituted, defaulted template 4937 /// arguments. 4938 /// 4939 /// \param PartialTemplateArgs True if the list of template arguments is 4940 /// intentionally partial, e.g., because we're checking just the initial 4941 /// set of template arguments. 4942 /// 4943 /// \param Converted Will receive the converted, canonicalized template 4944 /// arguments. 4945 /// 4946 /// 4947 /// \param ExpansionIntoFixedList If non-NULL, will be set true to indicate 4948 /// when the template arguments contain a pack expansion that is being 4949 /// expanded into a fixed parameter list. 4950 /// 4951 /// \returns True if an error occurred, false otherwise. 4952 bool CheckTemplateArgumentList(TemplateDecl *Template, 4953 SourceLocation TemplateLoc, 4954 TemplateArgumentListInfo &TemplateArgs, 4955 bool PartialTemplateArgs, 4956 SmallVectorImpl<TemplateArgument> &Converted, 4957 bool *ExpansionIntoFixedList = 0); 4958 4959 bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param, 4960 const TemplateArgumentLoc &Arg, 4961 SmallVectorImpl<TemplateArgument> &Converted); 4962 4963 bool CheckTemplateArgument(TemplateTypeParmDecl *Param, 4964 TypeSourceInfo *Arg); 4965 ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param, 4966 QualType InstantiatedParamType, Expr *Arg, 4967 TemplateArgument &Converted, 4968 CheckTemplateArgumentKind CTAK = CTAK_Specified); 4969 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, 4970 const TemplateArgumentLoc &Arg, 4971 unsigned ArgumentPackIndex); 4972 4973 ExprResult 4974 BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, 4975 QualType ParamType, 4976 SourceLocation Loc); 4977 ExprResult 4978 BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, 4979 SourceLocation Loc); 4980 4981 /// \brief Enumeration describing how template parameter lists are compared 4982 /// for equality. 4983 enum TemplateParameterListEqualKind { 4984 /// \brief We are matching the template parameter lists of two templates 4985 /// that might be redeclarations. 4986 /// 4987 /// \code 4988 /// template<typename T> struct X; 4989 /// template<typename T> struct X; 4990 /// \endcode 4991 TPL_TemplateMatch, 4992 4993 /// \brief We are matching the template parameter lists of two template 4994 /// template parameters as part of matching the template parameter lists 4995 /// of two templates that might be redeclarations. 4996 /// 4997 /// \code 4998 /// template<template<int I> class TT> struct X; 4999 /// template<template<int Value> class Other> struct X; 5000 /// \endcode 5001 TPL_TemplateTemplateParmMatch, 5002 5003 /// \brief We are matching the template parameter lists of a template 5004 /// template argument against the template parameter lists of a template 5005 /// template parameter. 5006 /// 5007 /// \code 5008 /// template<template<int Value> class Metafun> struct X; 5009 /// template<int Value> struct integer_c; 5010 /// X<integer_c> xic; 5011 /// \endcode 5012 TPL_TemplateTemplateArgumentMatch 5013 }; 5014 5015 bool TemplateParameterListsAreEqual(TemplateParameterList *New, 5016 TemplateParameterList *Old, 5017 bool Complain, 5018 TemplateParameterListEqualKind Kind, 5019 SourceLocation TemplateArgLoc 5020 = SourceLocation()); 5021 5022 bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); 5023 5024 /// \brief Called when the parser has parsed a C++ typename 5025 /// specifier, e.g., "typename T::type". 5026 /// 5027 /// \param S The scope in which this typename type occurs. 5028 /// \param TypenameLoc the location of the 'typename' keyword 5029 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 5030 /// \param II the identifier we're retrieving (e.g., 'type' in the example). 5031 /// \param IdLoc the location of the identifier. 5032 TypeResult 5033 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 5034 const CXXScopeSpec &SS, const IdentifierInfo &II, 5035 SourceLocation IdLoc); 5036 5037 /// \brief Called when the parser has parsed a C++ typename 5038 /// specifier that ends in a template-id, e.g., 5039 /// "typename MetaFun::template apply<T1, T2>". 5040 /// 5041 /// \param S The scope in which this typename type occurs. 5042 /// \param TypenameLoc the location of the 'typename' keyword 5043 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 5044 /// \param TemplateLoc the location of the 'template' keyword, if any. 5045 /// \param TemplateName The template name. 5046 /// \param TemplateNameLoc The location of the template name. 5047 /// \param LAngleLoc The location of the opening angle bracket ('<'). 5048 /// \param TemplateArgs The template arguments. 5049 /// \param RAngleLoc The location of the closing angle bracket ('>'). 5050 TypeResult 5051 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 5052 const CXXScopeSpec &SS, 5053 SourceLocation TemplateLoc, 5054 TemplateTy TemplateName, 5055 SourceLocation TemplateNameLoc, 5056 SourceLocation LAngleLoc, 5057 ASTTemplateArgsPtr TemplateArgs, 5058 SourceLocation RAngleLoc); 5059 5060 QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, 5061 SourceLocation KeywordLoc, 5062 NestedNameSpecifierLoc QualifierLoc, 5063 const IdentifierInfo &II, 5064 SourceLocation IILoc); 5065 5066 TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, 5067 SourceLocation Loc, 5068 DeclarationName Name); 5069 bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS); 5070 5071 ExprResult RebuildExprInCurrentInstantiation(Expr *E); 5072 bool RebuildTemplateParamsInCurrentInstantiation( 5073 TemplateParameterList *Params); 5074 5075 std::string 5076 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 5077 const TemplateArgumentList &Args); 5078 5079 std::string 5080 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 5081 const TemplateArgument *Args, 5082 unsigned NumArgs); 5083 5084 //===--------------------------------------------------------------------===// 5085 // C++ Variadic Templates (C++0x [temp.variadic]) 5086 //===--------------------------------------------------------------------===// 5087 5088 /// \brief The context in which an unexpanded parameter pack is 5089 /// being diagnosed. 5090 /// 5091 /// Note that the values of this enumeration line up with the first 5092 /// argument to the \c err_unexpanded_parameter_pack diagnostic. 5093 enum UnexpandedParameterPackContext { 5094 /// \brief An arbitrary expression. 5095 UPPC_Expression = 0, 5096 5097 /// \brief The base type of a class type. 5098 UPPC_BaseType, 5099 5100 /// \brief The type of an arbitrary declaration. 5101 UPPC_DeclarationType, 5102 5103 /// \brief The type of a data member. 5104 UPPC_DataMemberType, 5105 5106 /// \brief The size of a bit-field. 5107 UPPC_BitFieldWidth, 5108 5109 /// \brief The expression in a static assertion. 5110 UPPC_StaticAssertExpression, 5111 5112 /// \brief The fixed underlying type of an enumeration. 5113 UPPC_FixedUnderlyingType, 5114 5115 /// \brief The enumerator value. 5116 UPPC_EnumeratorValue, 5117 5118 /// \brief A using declaration. 5119 UPPC_UsingDeclaration, 5120 5121 /// \brief A friend declaration. 5122 UPPC_FriendDeclaration, 5123 5124 /// \brief A declaration qualifier. 5125 UPPC_DeclarationQualifier, 5126 5127 /// \brief An initializer. 5128 UPPC_Initializer, 5129 5130 /// \brief A default argument. 5131 UPPC_DefaultArgument, 5132 5133 /// \brief The type of a non-type template parameter. 5134 UPPC_NonTypeTemplateParameterType, 5135 5136 /// \brief The type of an exception. 5137 UPPC_ExceptionType, 5138 5139 /// \brief Partial specialization. 5140 UPPC_PartialSpecialization, 5141 5142 /// \brief Microsoft __if_exists. 5143 UPPC_IfExists, 5144 5145 /// \brief Microsoft __if_not_exists. 5146 UPPC_IfNotExists, 5147 5148 /// \brief Lambda expression. 5149 UPPC_Lambda, 5150 5151 /// \brief Block expression, 5152 UPPC_Block 5153}; 5154 5155 /// \brief Diagnose unexpanded parameter packs. 5156 /// 5157 /// \param Loc The location at which we should emit the diagnostic. 5158 /// 5159 /// \param UPPC The context in which we are diagnosing unexpanded 5160 /// parameter packs. 5161 /// 5162 /// \param Unexpanded the set of unexpanded parameter packs. 5163 /// 5164 /// \returns true if an error occurred, false otherwise. 5165 bool DiagnoseUnexpandedParameterPacks(SourceLocation Loc, 5166 UnexpandedParameterPackContext UPPC, 5167 ArrayRef<UnexpandedParameterPack> Unexpanded); 5168 5169 /// \brief If the given type contains an unexpanded parameter pack, 5170 /// diagnose the error. 5171 /// 5172 /// \param Loc The source location where a diagnostc should be emitted. 5173 /// 5174 /// \param T The type that is being checked for unexpanded parameter 5175 /// packs. 5176 /// 5177 /// \returns true if an error occurred, false otherwise. 5178 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, 5179 UnexpandedParameterPackContext UPPC); 5180 5181 /// \brief If the given expression contains an unexpanded parameter 5182 /// pack, diagnose the error. 5183 /// 5184 /// \param E The expression that is being checked for unexpanded 5185 /// parameter packs. 5186 /// 5187 /// \returns true if an error occurred, false otherwise. 5188 bool DiagnoseUnexpandedParameterPack(Expr *E, 5189 UnexpandedParameterPackContext UPPC = UPPC_Expression); 5190 5191 /// \brief If the given nested-name-specifier contains an unexpanded 5192 /// parameter pack, diagnose the error. 5193 /// 5194 /// \param SS The nested-name-specifier that is being checked for 5195 /// unexpanded parameter packs. 5196 /// 5197 /// \returns true if an error occurred, false otherwise. 5198 bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS, 5199 UnexpandedParameterPackContext UPPC); 5200 5201 /// \brief If the given name contains an unexpanded parameter pack, 5202 /// diagnose the error. 5203 /// 5204 /// \param NameInfo The name (with source location information) that 5205 /// is being checked for unexpanded parameter packs. 5206 /// 5207 /// \returns true if an error occurred, false otherwise. 5208 bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo, 5209 UnexpandedParameterPackContext UPPC); 5210 5211 /// \brief If the given template name contains an unexpanded parameter pack, 5212 /// diagnose the error. 5213 /// 5214 /// \param Loc The location of the template name. 5215 /// 5216 /// \param Template The template name that is being checked for unexpanded 5217 /// parameter packs. 5218 /// 5219 /// \returns true if an error occurred, false otherwise. 5220 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, 5221 TemplateName Template, 5222 UnexpandedParameterPackContext UPPC); 5223 5224 /// \brief If the given template argument contains an unexpanded parameter 5225 /// pack, diagnose the error. 5226 /// 5227 /// \param Arg The template argument that is being checked for unexpanded 5228 /// parameter packs. 5229 /// 5230 /// \returns true if an error occurred, false otherwise. 5231 bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg, 5232 UnexpandedParameterPackContext UPPC); 5233 5234 /// \brief Collect the set of unexpanded parameter packs within the given 5235 /// template argument. 5236 /// 5237 /// \param Arg The template argument that will be traversed to find 5238 /// unexpanded parameter packs. 5239 void collectUnexpandedParameterPacks(TemplateArgument Arg, 5240 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 5241 5242 /// \brief Collect the set of unexpanded parameter packs within the given 5243 /// template argument. 5244 /// 5245 /// \param Arg The template argument that will be traversed to find 5246 /// unexpanded parameter packs. 5247 void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg, 5248 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 5249 5250 /// \brief Collect the set of unexpanded parameter packs within the given 5251 /// type. 5252 /// 5253 /// \param T The type that will be traversed to find 5254 /// unexpanded parameter packs. 5255 void collectUnexpandedParameterPacks(QualType T, 5256 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 5257 5258 /// \brief Collect the set of unexpanded parameter packs within the given 5259 /// type. 5260 /// 5261 /// \param TL The type that will be traversed to find 5262 /// unexpanded parameter packs. 5263 void collectUnexpandedParameterPacks(TypeLoc TL, 5264 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 5265 5266 /// \brief Collect the set of unexpanded parameter packs within the given 5267 /// nested-name-specifier. 5268 /// 5269 /// \param SS The nested-name-specifier that will be traversed to find 5270 /// unexpanded parameter packs. 5271 void collectUnexpandedParameterPacks(CXXScopeSpec &SS, 5272 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 5273 5274 /// \brief Collect the set of unexpanded parameter packs within the given 5275 /// name. 5276 /// 5277 /// \param NameInfo The name that will be traversed to find 5278 /// unexpanded parameter packs. 5279 void collectUnexpandedParameterPacks(const DeclarationNameInfo &NameInfo, 5280 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 5281 5282 /// \brief Invoked when parsing a template argument followed by an 5283 /// ellipsis, which creates a pack expansion. 5284 /// 5285 /// \param Arg The template argument preceding the ellipsis, which 5286 /// may already be invalid. 5287 /// 5288 /// \param EllipsisLoc The location of the ellipsis. 5289 ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, 5290 SourceLocation EllipsisLoc); 5291 5292 /// \brief Invoked when parsing a type followed by an ellipsis, which 5293 /// creates a pack expansion. 5294 /// 5295 /// \param Type The type preceding the ellipsis, which will become 5296 /// the pattern of the pack expansion. 5297 /// 5298 /// \param EllipsisLoc The location of the ellipsis. 5299 TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc); 5300 5301 /// \brief Construct a pack expansion type from the pattern of the pack 5302 /// expansion. 5303 TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern, 5304 SourceLocation EllipsisLoc, 5305 llvm::Optional<unsigned> NumExpansions); 5306 5307 /// \brief Construct a pack expansion type from the pattern of the pack 5308 /// expansion. 5309 QualType CheckPackExpansion(QualType Pattern, 5310 SourceRange PatternRange, 5311 SourceLocation EllipsisLoc, 5312 llvm::Optional<unsigned> NumExpansions); 5313 5314 /// \brief Invoked when parsing an expression followed by an ellipsis, which 5315 /// creates a pack expansion. 5316 /// 5317 /// \param Pattern The expression preceding the ellipsis, which will become 5318 /// the pattern of the pack expansion. 5319 /// 5320 /// \param EllipsisLoc The location of the ellipsis. 5321 ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc); 5322 5323 /// \brief Invoked when parsing an expression followed by an ellipsis, which 5324 /// creates a pack expansion. 5325 /// 5326 /// \param Pattern The expression preceding the ellipsis, which will become 5327 /// the pattern of the pack expansion. 5328 /// 5329 /// \param EllipsisLoc The location of the ellipsis. 5330 ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, 5331 llvm::Optional<unsigned> NumExpansions); 5332 5333 /// \brief Determine whether we could expand a pack expansion with the 5334 /// given set of parameter packs into separate arguments by repeatedly 5335 /// transforming the pattern. 5336 /// 5337 /// \param EllipsisLoc The location of the ellipsis that identifies the 5338 /// pack expansion. 5339 /// 5340 /// \param PatternRange The source range that covers the entire pattern of 5341 /// the pack expansion. 5342 /// 5343 /// \param Unexpanded The set of unexpanded parameter packs within the 5344 /// pattern. 5345 /// 5346 /// \param ShouldExpand Will be set to \c true if the transformer should 5347 /// expand the corresponding pack expansions into separate arguments. When 5348 /// set, \c NumExpansions must also be set. 5349 /// 5350 /// \param RetainExpansion Whether the caller should add an unexpanded 5351 /// pack expansion after all of the expanded arguments. This is used 5352 /// when extending explicitly-specified template argument packs per 5353 /// C++0x [temp.arg.explicit]p9. 5354 /// 5355 /// \param NumExpansions The number of separate arguments that will be in 5356 /// the expanded form of the corresponding pack expansion. This is both an 5357 /// input and an output parameter, which can be set by the caller if the 5358 /// number of expansions is known a priori (e.g., due to a prior substitution) 5359 /// and will be set by the callee when the number of expansions is known. 5360 /// The callee must set this value when \c ShouldExpand is \c true; it may 5361 /// set this value in other cases. 5362 /// 5363 /// \returns true if an error occurred (e.g., because the parameter packs 5364 /// are to be instantiated with arguments of different lengths), false 5365 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) 5366 /// must be set. 5367 bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc, 5368 SourceRange PatternRange, 5369 ArrayRef<UnexpandedParameterPack> Unexpanded, 5370 const MultiLevelTemplateArgumentList &TemplateArgs, 5371 bool &ShouldExpand, 5372 bool &RetainExpansion, 5373 llvm::Optional<unsigned> &NumExpansions); 5374 5375 /// \brief Determine the number of arguments in the given pack expansion 5376 /// type. 5377 /// 5378 /// This routine assumes that the number of arguments in the expansion is 5379 /// consistent across all of the unexpanded parameter packs in its pattern. 5380 /// 5381 /// Returns an empty Optional if the type can't be expanded. 5382 llvm::Optional<unsigned> getNumArgumentsInExpansion(QualType T, 5383 const MultiLevelTemplateArgumentList &TemplateArgs); 5384 5385 /// \brief Determine whether the given declarator contains any unexpanded 5386 /// parameter packs. 5387 /// 5388 /// This routine is used by the parser to disambiguate function declarators 5389 /// with an ellipsis prior to the ')', e.g., 5390 /// 5391 /// \code 5392 /// void f(T...); 5393 /// \endcode 5394 /// 5395 /// To determine whether we have an (unnamed) function parameter pack or 5396 /// a variadic function. 5397 /// 5398 /// \returns true if the declarator contains any unexpanded parameter packs, 5399 /// false otherwise. 5400 bool containsUnexpandedParameterPacks(Declarator &D); 5401 5402 //===--------------------------------------------------------------------===// 5403 // C++ Template Argument Deduction (C++ [temp.deduct]) 5404 //===--------------------------------------------------------------------===// 5405 5406 /// \brief Describes the result of template argument deduction. 5407 /// 5408 /// The TemplateDeductionResult enumeration describes the result of 5409 /// template argument deduction, as returned from 5410 /// DeduceTemplateArguments(). The separate TemplateDeductionInfo 5411 /// structure provides additional information about the results of 5412 /// template argument deduction, e.g., the deduced template argument 5413 /// list (if successful) or the specific template parameters or 5414 /// deduced arguments that were involved in the failure. 5415 enum TemplateDeductionResult { 5416 /// \brief Template argument deduction was successful. 5417 TDK_Success = 0, 5418 /// \brief The declaration was invalid; do nothing. 5419 TDK_Invalid, 5420 /// \brief Template argument deduction exceeded the maximum template 5421 /// instantiation depth (which has already been diagnosed). 5422 TDK_InstantiationDepth, 5423 /// \brief Template argument deduction did not deduce a value 5424 /// for every template parameter. 5425 TDK_Incomplete, 5426 /// \brief Template argument deduction produced inconsistent 5427 /// deduced values for the given template parameter. 5428 TDK_Inconsistent, 5429 /// \brief Template argument deduction failed due to inconsistent 5430 /// cv-qualifiers on a template parameter type that would 5431 /// otherwise be deduced, e.g., we tried to deduce T in "const T" 5432 /// but were given a non-const "X". 5433 TDK_Underqualified, 5434 /// \brief Substitution of the deduced template argument values 5435 /// resulted in an error. 5436 TDK_SubstitutionFailure, 5437 /// \brief Substitution of the deduced template argument values 5438 /// into a non-deduced context produced a type or value that 5439 /// produces a type that does not match the original template 5440 /// arguments provided. 5441 TDK_NonDeducedMismatch, 5442 /// \brief When performing template argument deduction for a function 5443 /// template, there were too many call arguments. 5444 TDK_TooManyArguments, 5445 /// \brief When performing template argument deduction for a function 5446 /// template, there were too few call arguments. 5447 TDK_TooFewArguments, 5448 /// \brief The explicitly-specified template arguments were not valid 5449 /// template arguments for the given template. 5450 TDK_InvalidExplicitArguments, 5451 /// \brief The arguments included an overloaded function name that could 5452 /// not be resolved to a suitable function. 5453 TDK_FailedOverloadResolution 5454 }; 5455 5456 TemplateDeductionResult 5457 DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, 5458 const TemplateArgumentList &TemplateArgs, 5459 sema::TemplateDeductionInfo &Info); 5460 5461 TemplateDeductionResult 5462 SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5463 TemplateArgumentListInfo &ExplicitTemplateArgs, 5464 SmallVectorImpl<DeducedTemplateArgument> &Deduced, 5465 SmallVectorImpl<QualType> &ParamTypes, 5466 QualType *FunctionType, 5467 sema::TemplateDeductionInfo &Info); 5468 5469 /// brief A function argument from which we performed template argument 5470 // deduction for a call. 5471 struct OriginalCallArg { 5472 OriginalCallArg(QualType OriginalParamType, 5473 unsigned ArgIdx, 5474 QualType OriginalArgType) 5475 : OriginalParamType(OriginalParamType), ArgIdx(ArgIdx), 5476 OriginalArgType(OriginalArgType) { } 5477 5478 QualType OriginalParamType; 5479 unsigned ArgIdx; 5480 QualType OriginalArgType; 5481 }; 5482 5483 TemplateDeductionResult 5484 FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, 5485 SmallVectorImpl<DeducedTemplateArgument> &Deduced, 5486 unsigned NumExplicitlySpecified, 5487 FunctionDecl *&Specialization, 5488 sema::TemplateDeductionInfo &Info, 5489 SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = 0); 5490 5491 TemplateDeductionResult 5492 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5493 TemplateArgumentListInfo *ExplicitTemplateArgs, 5494 ArrayRef<Expr *> Args, 5495 FunctionDecl *&Specialization, 5496 sema::TemplateDeductionInfo &Info); 5497 5498 TemplateDeductionResult 5499 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5500 TemplateArgumentListInfo *ExplicitTemplateArgs, 5501 QualType ArgFunctionType, 5502 FunctionDecl *&Specialization, 5503 sema::TemplateDeductionInfo &Info); 5504 5505 TemplateDeductionResult 5506 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5507 QualType ToType, 5508 CXXConversionDecl *&Specialization, 5509 sema::TemplateDeductionInfo &Info); 5510 5511 TemplateDeductionResult 5512 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5513 TemplateArgumentListInfo *ExplicitTemplateArgs, 5514 FunctionDecl *&Specialization, 5515 sema::TemplateDeductionInfo &Info); 5516 5517 /// \brief Result type of DeduceAutoType. 5518 enum DeduceAutoResult { 5519 DAR_Succeeded, 5520 DAR_Failed, 5521 DAR_FailedAlreadyDiagnosed 5522 }; 5523 5524 DeduceAutoResult DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer, 5525 TypeSourceInfo *&Result); 5526 void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init); 5527 5528 FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1, 5529 FunctionTemplateDecl *FT2, 5530 SourceLocation Loc, 5531 TemplatePartialOrderingContext TPOC, 5532 unsigned NumCallArguments); 5533 UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin, 5534 UnresolvedSetIterator SEnd, 5535 TemplatePartialOrderingContext TPOC, 5536 unsigned NumCallArguments, 5537 SourceLocation Loc, 5538 const PartialDiagnostic &NoneDiag, 5539 const PartialDiagnostic &AmbigDiag, 5540 const PartialDiagnostic &CandidateDiag, 5541 bool Complain = true, 5542 QualType TargetType = QualType()); 5543 5544 ClassTemplatePartialSpecializationDecl * 5545 getMoreSpecializedPartialSpecialization( 5546 ClassTemplatePartialSpecializationDecl *PS1, 5547 ClassTemplatePartialSpecializationDecl *PS2, 5548 SourceLocation Loc); 5549 5550 void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, 5551 bool OnlyDeduced, 5552 unsigned Depth, 5553 llvm::SmallBitVector &Used); 5554 void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate, 5555 llvm::SmallBitVector &Deduced) { 5556 return MarkDeducedTemplateParameters(Context, FunctionTemplate, Deduced); 5557 } 5558 static void MarkDeducedTemplateParameters(ASTContext &Ctx, 5559 FunctionTemplateDecl *FunctionTemplate, 5560 llvm::SmallBitVector &Deduced); 5561 5562 //===--------------------------------------------------------------------===// 5563 // C++ Template Instantiation 5564 // 5565 5566 MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D, 5567 const TemplateArgumentList *Innermost = 0, 5568 bool RelativeToPrimary = false, 5569 const FunctionDecl *Pattern = 0); 5570 5571 /// \brief A template instantiation that is currently in progress. 5572 struct ActiveTemplateInstantiation { 5573 /// \brief The kind of template instantiation we are performing 5574 enum InstantiationKind { 5575 /// We are instantiating a template declaration. The entity is 5576 /// the declaration we're instantiating (e.g., a CXXRecordDecl). 5577 TemplateInstantiation, 5578 5579 /// We are instantiating a default argument for a template 5580 /// parameter. The Entity is the template, and 5581 /// TemplateArgs/NumTemplateArguments provides the template 5582 /// arguments as specified. 5583 /// FIXME: Use a TemplateArgumentList 5584 DefaultTemplateArgumentInstantiation, 5585 5586 /// We are instantiating a default argument for a function. 5587 /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs 5588 /// provides the template arguments as specified. 5589 DefaultFunctionArgumentInstantiation, 5590 5591 /// We are substituting explicit template arguments provided for 5592 /// a function template. The entity is a FunctionTemplateDecl. 5593 ExplicitTemplateArgumentSubstitution, 5594 5595 /// We are substituting template argument determined as part of 5596 /// template argument deduction for either a class template 5597 /// partial specialization or a function template. The 5598 /// Entity is either a ClassTemplatePartialSpecializationDecl or 5599 /// a FunctionTemplateDecl. 5600 DeducedTemplateArgumentSubstitution, 5601 5602 /// We are substituting prior template arguments into a new 5603 /// template parameter. The template parameter itself is either a 5604 /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl. 5605 PriorTemplateArgumentSubstitution, 5606 5607 /// We are checking the validity of a default template argument that 5608 /// has been used when naming a template-id. 5609 DefaultTemplateArgumentChecking, 5610 5611 /// We are instantiating the exception specification for a function 5612 /// template which was deferred until it was needed. 5613 ExceptionSpecInstantiation 5614 } Kind; 5615 5616 /// \brief The point of instantiation within the source code. 5617 SourceLocation PointOfInstantiation; 5618 5619 /// \brief The template (or partial specialization) in which we are 5620 /// performing the instantiation, for substitutions of prior template 5621 /// arguments. 5622 NamedDecl *Template; 5623 5624 /// \brief The entity that is being instantiated. 5625 Decl *Entity; 5626 5627 /// \brief The list of template arguments we are substituting, if they 5628 /// are not part of the entity. 5629 const TemplateArgument *TemplateArgs; 5630 5631 /// \brief The number of template arguments in TemplateArgs. 5632 unsigned NumTemplateArgs; 5633 5634 /// \brief The template deduction info object associated with the 5635 /// substitution or checking of explicit or deduced template arguments. 5636 sema::TemplateDeductionInfo *DeductionInfo; 5637 5638 /// \brief The source range that covers the construct that cause 5639 /// the instantiation, e.g., the template-id that causes a class 5640 /// template instantiation. 5641 SourceRange InstantiationRange; 5642 5643 ActiveTemplateInstantiation() 5644 : Kind(TemplateInstantiation), Template(0), Entity(0), TemplateArgs(0), 5645 NumTemplateArgs(0), DeductionInfo(0) {} 5646 5647 /// \brief Determines whether this template is an actual instantiation 5648 /// that should be counted toward the maximum instantiation depth. 5649 bool isInstantiationRecord() const; 5650 5651 friend bool operator==(const ActiveTemplateInstantiation &X, 5652 const ActiveTemplateInstantiation &Y) { 5653 if (X.Kind != Y.Kind) 5654 return false; 5655 5656 if (X.Entity != Y.Entity) 5657 return false; 5658 5659 switch (X.Kind) { 5660 case TemplateInstantiation: 5661 case ExceptionSpecInstantiation: 5662 return true; 5663 5664 case PriorTemplateArgumentSubstitution: 5665 case DefaultTemplateArgumentChecking: 5666 if (X.Template != Y.Template) 5667 return false; 5668 5669 // Fall through 5670 5671 case DefaultTemplateArgumentInstantiation: 5672 case ExplicitTemplateArgumentSubstitution: 5673 case DeducedTemplateArgumentSubstitution: 5674 case DefaultFunctionArgumentInstantiation: 5675 return X.TemplateArgs == Y.TemplateArgs; 5676 5677 } 5678 5679 llvm_unreachable("Invalid InstantiationKind!"); 5680 } 5681 5682 friend bool operator!=(const ActiveTemplateInstantiation &X, 5683 const ActiveTemplateInstantiation &Y) { 5684 return !(X == Y); 5685 } 5686 }; 5687 5688 /// \brief List of active template instantiations. 5689 /// 5690 /// This vector is treated as a stack. As one template instantiation 5691 /// requires another template instantiation, additional 5692 /// instantiations are pushed onto the stack up to a 5693 /// user-configurable limit LangOptions::InstantiationDepth. 5694 SmallVector<ActiveTemplateInstantiation, 16> 5695 ActiveTemplateInstantiations; 5696 5697 /// \brief Whether we are in a SFINAE context that is not associated with 5698 /// template instantiation. 5699 /// 5700 /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside 5701 /// of a template instantiation or template argument deduction. 5702 bool InNonInstantiationSFINAEContext; 5703 5704 /// \brief The number of ActiveTemplateInstantiation entries in 5705 /// \c ActiveTemplateInstantiations that are not actual instantiations and, 5706 /// therefore, should not be counted as part of the instantiation depth. 5707 unsigned NonInstantiationEntries; 5708 5709 /// \brief The last template from which a template instantiation 5710 /// error or warning was produced. 5711 /// 5712 /// This value is used to suppress printing of redundant template 5713 /// instantiation backtraces when there are multiple errors in the 5714 /// same instantiation. FIXME: Does this belong in Sema? It's tough 5715 /// to implement it anywhere else. 5716 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext; 5717 5718 /// \brief The current index into pack expansion arguments that will be 5719 /// used for substitution of parameter packs. 5720 /// 5721 /// The pack expansion index will be -1 to indicate that parameter packs 5722 /// should be instantiated as themselves. Otherwise, the index specifies 5723 /// which argument within the parameter pack will be used for substitution. 5724 int ArgumentPackSubstitutionIndex; 5725 5726 /// \brief RAII object used to change the argument pack substitution index 5727 /// within a \c Sema object. 5728 /// 5729 /// See \c ArgumentPackSubstitutionIndex for more information. 5730 class ArgumentPackSubstitutionIndexRAII { 5731 Sema &Self; 5732 int OldSubstitutionIndex; 5733 5734 public: 5735 ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex) 5736 : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) { 5737 Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex; 5738 } 5739 5740 ~ArgumentPackSubstitutionIndexRAII() { 5741 Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex; 5742 } 5743 }; 5744 5745 friend class ArgumentPackSubstitutionRAII; 5746 5747 /// \brief The stack of calls expression undergoing template instantiation. 5748 /// 5749 /// The top of this stack is used by a fixit instantiating unresolved 5750 /// function calls to fix the AST to match the textual change it prints. 5751 SmallVector<CallExpr *, 8> CallsUndergoingInstantiation; 5752 5753 /// \brief For each declaration that involved template argument deduction, the 5754 /// set of diagnostics that were suppressed during that template argument 5755 /// deduction. 5756 /// 5757 /// FIXME: Serialize this structure to the AST file. 5758 llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1> > 5759 SuppressedDiagnostics; 5760 5761 /// \brief A stack object to be created when performing template 5762 /// instantiation. 5763 /// 5764 /// Construction of an object of type \c InstantiatingTemplate 5765 /// pushes the current instantiation onto the stack of active 5766 /// instantiations. If the size of this stack exceeds the maximum 5767 /// number of recursive template instantiations, construction 5768 /// produces an error and evaluates true. 5769 /// 5770 /// Destruction of this object will pop the named instantiation off 5771 /// the stack. 5772 struct InstantiatingTemplate { 5773 /// \brief Note that we are instantiating a class template, 5774 /// function template, or a member thereof. 5775 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5776 Decl *Entity, 5777 SourceRange InstantiationRange = SourceRange()); 5778 5779 struct ExceptionSpecification {}; 5780 /// \brief Note that we are instantiating an exception specification 5781 /// of a function template. 5782 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5783 FunctionDecl *Entity, ExceptionSpecification, 5784 SourceRange InstantiationRange = SourceRange()); 5785 5786 /// \brief Note that we are instantiating a default argument in a 5787 /// template-id. 5788 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5789 TemplateDecl *Template, 5790 ArrayRef<TemplateArgument> TemplateArgs, 5791 SourceRange InstantiationRange = SourceRange()); 5792 5793 /// \brief Note that we are instantiating a default argument in a 5794 /// template-id. 5795 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5796 FunctionTemplateDecl *FunctionTemplate, 5797 ArrayRef<TemplateArgument> TemplateArgs, 5798 ActiveTemplateInstantiation::InstantiationKind Kind, 5799 sema::TemplateDeductionInfo &DeductionInfo, 5800 SourceRange InstantiationRange = SourceRange()); 5801 5802 /// \brief Note that we are instantiating as part of template 5803 /// argument deduction for a class template partial 5804 /// specialization. 5805 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5806 ClassTemplatePartialSpecializationDecl *PartialSpec, 5807 ArrayRef<TemplateArgument> TemplateArgs, 5808 sema::TemplateDeductionInfo &DeductionInfo, 5809 SourceRange InstantiationRange = SourceRange()); 5810 5811 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5812 ParmVarDecl *Param, 5813 ArrayRef<TemplateArgument> TemplateArgs, 5814 SourceRange InstantiationRange = SourceRange()); 5815 5816 /// \brief Note that we are substituting prior template arguments into a 5817 /// non-type or template template parameter. 5818 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5819 NamedDecl *Template, 5820 NonTypeTemplateParmDecl *Param, 5821 ArrayRef<TemplateArgument> TemplateArgs, 5822 SourceRange InstantiationRange); 5823 5824 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5825 NamedDecl *Template, 5826 TemplateTemplateParmDecl *Param, 5827 ArrayRef<TemplateArgument> TemplateArgs, 5828 SourceRange InstantiationRange); 5829 5830 /// \brief Note that we are checking the default template argument 5831 /// against the template parameter for a given template-id. 5832 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5833 TemplateDecl *Template, 5834 NamedDecl *Param, 5835 ArrayRef<TemplateArgument> TemplateArgs, 5836 SourceRange InstantiationRange); 5837 5838 5839 /// \brief Note that we have finished instantiating this template. 5840 void Clear(); 5841 5842 ~InstantiatingTemplate() { Clear(); } 5843 5844 /// \brief Determines whether we have exceeded the maximum 5845 /// recursive template instantiations. 5846 operator bool() const { return Invalid; } 5847 5848 private: 5849 Sema &SemaRef; 5850 bool Invalid; 5851 bool SavedInNonInstantiationSFINAEContext; 5852 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation, 5853 SourceRange InstantiationRange); 5854 5855 InstantiatingTemplate(const InstantiatingTemplate&) LLVM_DELETED_FUNCTION; 5856 5857 InstantiatingTemplate& 5858 operator=(const InstantiatingTemplate&) LLVM_DELETED_FUNCTION; 5859 }; 5860 5861 void PrintInstantiationStack(); 5862 5863 /// \brief Determines whether we are currently in a context where 5864 /// template argument substitution failures are not considered 5865 /// errors. 5866 /// 5867 /// \returns An empty \c llvm::Optional if we're not in a SFINAE context. 5868 /// Otherwise, contains a pointer that, if non-NULL, contains the nearest 5869 /// template-deduction context object, which can be used to capture 5870 /// diagnostics that will be suppressed. 5871 llvm::Optional<sema::TemplateDeductionInfo *> isSFINAEContext() const; 5872 5873 /// \brief Determines whether we are currently in a context that 5874 /// is not evaluated as per C++ [expr] p5. 5875 bool isUnevaluatedContext() const { 5876 assert(!ExprEvalContexts.empty() && 5877 "Must be in an expression evaluation context"); 5878 return ExprEvalContexts.back().Context == Sema::Unevaluated; 5879 } 5880 5881 /// \brief RAII class used to determine whether SFINAE has 5882 /// trapped any errors that occur during template argument 5883 /// deduction.` 5884 class SFINAETrap { 5885 Sema &SemaRef; 5886 unsigned PrevSFINAEErrors; 5887 bool PrevInNonInstantiationSFINAEContext; 5888 bool PrevAccessCheckingSFINAE; 5889 5890 public: 5891 explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false) 5892 : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors), 5893 PrevInNonInstantiationSFINAEContext( 5894 SemaRef.InNonInstantiationSFINAEContext), 5895 PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE) 5896 { 5897 if (!SemaRef.isSFINAEContext()) 5898 SemaRef.InNonInstantiationSFINAEContext = true; 5899 SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE; 5900 } 5901 5902 ~SFINAETrap() { 5903 SemaRef.NumSFINAEErrors = PrevSFINAEErrors; 5904 SemaRef.InNonInstantiationSFINAEContext 5905 = PrevInNonInstantiationSFINAEContext; 5906 SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE; 5907 } 5908 5909 /// \brief Determine whether any SFINAE errors have been trapped. 5910 bool hasErrorOccurred() const { 5911 return SemaRef.NumSFINAEErrors > PrevSFINAEErrors; 5912 } 5913 }; 5914 5915 /// \brief The current instantiation scope used to store local 5916 /// variables. 5917 LocalInstantiationScope *CurrentInstantiationScope; 5918 5919 /// \brief The number of typos corrected by CorrectTypo. 5920 unsigned TyposCorrected; 5921 5922 typedef llvm::DenseMap<IdentifierInfo *, TypoCorrection> 5923 UnqualifiedTyposCorrectedMap; 5924 5925 /// \brief A cache containing the results of typo correction for unqualified 5926 /// name lookup. 5927 /// 5928 /// The string is the string that we corrected to (which may be empty, if 5929 /// there was no correction), while the boolean will be true when the 5930 /// string represents a keyword. 5931 UnqualifiedTyposCorrectedMap UnqualifiedTyposCorrected; 5932 5933 /// \brief Worker object for performing CFG-based warnings. 5934 sema::AnalysisBasedWarnings AnalysisWarnings; 5935 5936 /// \brief An entity for which implicit template instantiation is required. 5937 /// 5938 /// The source location associated with the declaration is the first place in 5939 /// the source code where the declaration was "used". It is not necessarily 5940 /// the point of instantiation (which will be either before or after the 5941 /// namespace-scope declaration that triggered this implicit instantiation), 5942 /// However, it is the location that diagnostics should generally refer to, 5943 /// because users will need to know what code triggered the instantiation. 5944 typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation; 5945 5946 /// \brief The queue of implicit template instantiations that are required 5947 /// but have not yet been performed. 5948 std::deque<PendingImplicitInstantiation> PendingInstantiations; 5949 5950 /// \brief The queue of implicit template instantiations that are required 5951 /// and must be performed within the current local scope. 5952 /// 5953 /// This queue is only used for member functions of local classes in 5954 /// templates, which must be instantiated in the same scope as their 5955 /// enclosing function, so that they can reference function-local 5956 /// types, static variables, enumerators, etc. 5957 std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations; 5958 5959 void PerformPendingInstantiations(bool LocalOnly = false); 5960 5961 TypeSourceInfo *SubstType(TypeSourceInfo *T, 5962 const MultiLevelTemplateArgumentList &TemplateArgs, 5963 SourceLocation Loc, DeclarationName Entity); 5964 5965 QualType SubstType(QualType T, 5966 const MultiLevelTemplateArgumentList &TemplateArgs, 5967 SourceLocation Loc, DeclarationName Entity); 5968 5969 TypeSourceInfo *SubstType(TypeLoc TL, 5970 const MultiLevelTemplateArgumentList &TemplateArgs, 5971 SourceLocation Loc, DeclarationName Entity); 5972 5973 TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T, 5974 const MultiLevelTemplateArgumentList &TemplateArgs, 5975 SourceLocation Loc, 5976 DeclarationName Entity, 5977 CXXRecordDecl *ThisContext, 5978 unsigned ThisTypeQuals); 5979 ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D, 5980 const MultiLevelTemplateArgumentList &TemplateArgs, 5981 int indexAdjustment, 5982 llvm::Optional<unsigned> NumExpansions, 5983 bool ExpectParameterPack); 5984 bool SubstParmTypes(SourceLocation Loc, 5985 ParmVarDecl **Params, unsigned NumParams, 5986 const MultiLevelTemplateArgumentList &TemplateArgs, 5987 SmallVectorImpl<QualType> &ParamTypes, 5988 SmallVectorImpl<ParmVarDecl *> *OutParams = 0); 5989 ExprResult SubstExpr(Expr *E, 5990 const MultiLevelTemplateArgumentList &TemplateArgs); 5991 5992 /// \brief Substitute the given template arguments into a list of 5993 /// expressions, expanding pack expansions if required. 5994 /// 5995 /// \param Exprs The list of expressions to substitute into. 5996 /// 5997 /// \param NumExprs The number of expressions in \p Exprs. 5998 /// 5999 /// \param IsCall Whether this is some form of call, in which case 6000 /// default arguments will be dropped. 6001 /// 6002 /// \param TemplateArgs The set of template arguments to substitute. 6003 /// 6004 /// \param Outputs Will receive all of the substituted arguments. 6005 /// 6006 /// \returns true if an error occurred, false otherwise. 6007 bool SubstExprs(Expr **Exprs, unsigned NumExprs, bool IsCall, 6008 const MultiLevelTemplateArgumentList &TemplateArgs, 6009 SmallVectorImpl<Expr *> &Outputs); 6010 6011 StmtResult SubstStmt(Stmt *S, 6012 const MultiLevelTemplateArgumentList &TemplateArgs); 6013 6014 Decl *SubstDecl(Decl *D, DeclContext *Owner, 6015 const MultiLevelTemplateArgumentList &TemplateArgs); 6016 6017 ExprResult SubstInitializer(Expr *E, 6018 const MultiLevelTemplateArgumentList &TemplateArgs, 6019 bool CXXDirectInit); 6020 6021 bool 6022 SubstBaseSpecifiers(CXXRecordDecl *Instantiation, 6023 CXXRecordDecl *Pattern, 6024 const MultiLevelTemplateArgumentList &TemplateArgs); 6025 6026 bool 6027 InstantiateClass(SourceLocation PointOfInstantiation, 6028 CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, 6029 const MultiLevelTemplateArgumentList &TemplateArgs, 6030 TemplateSpecializationKind TSK, 6031 bool Complain = true); 6032 6033 bool InstantiateEnum(SourceLocation PointOfInstantiation, 6034 EnumDecl *Instantiation, EnumDecl *Pattern, 6035 const MultiLevelTemplateArgumentList &TemplateArgs, 6036 TemplateSpecializationKind TSK); 6037 6038 struct LateInstantiatedAttribute { 6039 const Attr *TmplAttr; 6040 LocalInstantiationScope *Scope; 6041 Decl *NewDecl; 6042 6043 LateInstantiatedAttribute(const Attr *A, LocalInstantiationScope *S, 6044 Decl *D) 6045 : TmplAttr(A), Scope(S), NewDecl(D) 6046 { } 6047 }; 6048 typedef SmallVector<LateInstantiatedAttribute, 16> LateInstantiatedAttrVec; 6049 6050 void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, 6051 const Decl *Pattern, Decl *Inst, 6052 LateInstantiatedAttrVec *LateAttrs = 0, 6053 LocalInstantiationScope *OuterMostScope = 0); 6054 6055 bool 6056 InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, 6057 ClassTemplateSpecializationDecl *ClassTemplateSpec, 6058 TemplateSpecializationKind TSK, 6059 bool Complain = true); 6060 6061 void InstantiateClassMembers(SourceLocation PointOfInstantiation, 6062 CXXRecordDecl *Instantiation, 6063 const MultiLevelTemplateArgumentList &TemplateArgs, 6064 TemplateSpecializationKind TSK); 6065 6066 void InstantiateClassTemplateSpecializationMembers( 6067 SourceLocation PointOfInstantiation, 6068 ClassTemplateSpecializationDecl *ClassTemplateSpec, 6069 TemplateSpecializationKind TSK); 6070 6071 NestedNameSpecifierLoc 6072 SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, 6073 const MultiLevelTemplateArgumentList &TemplateArgs); 6074 6075 DeclarationNameInfo 6076 SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, 6077 const MultiLevelTemplateArgumentList &TemplateArgs); 6078 TemplateName 6079 SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, 6080 SourceLocation Loc, 6081 const MultiLevelTemplateArgumentList &TemplateArgs); 6082 bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, 6083 TemplateArgumentListInfo &Result, 6084 const MultiLevelTemplateArgumentList &TemplateArgs); 6085 6086 void InstantiateExceptionSpec(SourceLocation PointOfInstantiation, 6087 FunctionDecl *Function); 6088 void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, 6089 FunctionDecl *Function, 6090 bool Recursive = false, 6091 bool DefinitionRequired = false); 6092 void InstantiateStaticDataMemberDefinition( 6093 SourceLocation PointOfInstantiation, 6094 VarDecl *Var, 6095 bool Recursive = false, 6096 bool DefinitionRequired = false); 6097 6098 void InstantiateMemInitializers(CXXConstructorDecl *New, 6099 const CXXConstructorDecl *Tmpl, 6100 const MultiLevelTemplateArgumentList &TemplateArgs); 6101 6102 NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, 6103 const MultiLevelTemplateArgumentList &TemplateArgs); 6104 DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, 6105 const MultiLevelTemplateArgumentList &TemplateArgs); 6106 6107 // Objective-C declarations. 6108 enum ObjCContainerKind { 6109 OCK_None = -1, 6110 OCK_Interface = 0, 6111 OCK_Protocol, 6112 OCK_Category, 6113 OCK_ClassExtension, 6114 OCK_Implementation, 6115 OCK_CategoryImplementation 6116 }; 6117 ObjCContainerKind getObjCContainerKind() const; 6118 6119 Decl *ActOnStartClassInterface(SourceLocation AtInterfaceLoc, 6120 IdentifierInfo *ClassName, 6121 SourceLocation ClassLoc, 6122 IdentifierInfo *SuperName, 6123 SourceLocation SuperLoc, 6124 Decl * const *ProtoRefs, 6125 unsigned NumProtoRefs, 6126 const SourceLocation *ProtoLocs, 6127 SourceLocation EndProtoLoc, 6128 AttributeList *AttrList); 6129 6130 Decl *ActOnCompatibilityAlias( 6131 SourceLocation AtCompatibilityAliasLoc, 6132 IdentifierInfo *AliasName, SourceLocation AliasLocation, 6133 IdentifierInfo *ClassName, SourceLocation ClassLocation); 6134 6135 bool CheckForwardProtocolDeclarationForCircularDependency( 6136 IdentifierInfo *PName, 6137 SourceLocation &PLoc, SourceLocation PrevLoc, 6138 const ObjCList<ObjCProtocolDecl> &PList); 6139 6140 Decl *ActOnStartProtocolInterface( 6141 SourceLocation AtProtoInterfaceLoc, 6142 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, 6143 Decl * const *ProtoRefNames, unsigned NumProtoRefs, 6144 const SourceLocation *ProtoLocs, 6145 SourceLocation EndProtoLoc, 6146 AttributeList *AttrList); 6147 6148 Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, 6149 IdentifierInfo *ClassName, 6150 SourceLocation ClassLoc, 6151 IdentifierInfo *CategoryName, 6152 SourceLocation CategoryLoc, 6153 Decl * const *ProtoRefs, 6154 unsigned NumProtoRefs, 6155 const SourceLocation *ProtoLocs, 6156 SourceLocation EndProtoLoc); 6157 6158 Decl *ActOnStartClassImplementation( 6159 SourceLocation AtClassImplLoc, 6160 IdentifierInfo *ClassName, SourceLocation ClassLoc, 6161 IdentifierInfo *SuperClassname, 6162 SourceLocation SuperClassLoc); 6163 6164 Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc, 6165 IdentifierInfo *ClassName, 6166 SourceLocation ClassLoc, 6167 IdentifierInfo *CatName, 6168 SourceLocation CatLoc); 6169 6170 DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl, 6171 ArrayRef<Decl *> Decls); 6172 6173 DeclGroupPtrTy ActOnForwardClassDeclaration(SourceLocation Loc, 6174 IdentifierInfo **IdentList, 6175 SourceLocation *IdentLocs, 6176 unsigned NumElts); 6177 6178 DeclGroupPtrTy ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc, 6179 const IdentifierLocPair *IdentList, 6180 unsigned NumElts, 6181 AttributeList *attrList); 6182 6183 void FindProtocolDeclaration(bool WarnOnDeclarations, 6184 const IdentifierLocPair *ProtocolId, 6185 unsigned NumProtocols, 6186 SmallVectorImpl<Decl *> &Protocols); 6187 6188 /// Ensure attributes are consistent with type. 6189 /// \param [in, out] Attributes The attributes to check; they will 6190 /// be modified to be consistent with \p PropertyTy. 6191 void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, 6192 SourceLocation Loc, 6193 unsigned &Attributes, 6194 bool propertyInPrimaryClass); 6195 6196 /// Process the specified property declaration and create decls for the 6197 /// setters and getters as needed. 6198 /// \param property The property declaration being processed 6199 /// \param CD The semantic container for the property 6200 /// \param redeclaredProperty Declaration for property if redeclared 6201 /// in class extension. 6202 /// \param lexicalDC Container for redeclaredProperty. 6203 void ProcessPropertyDecl(ObjCPropertyDecl *property, 6204 ObjCContainerDecl *CD, 6205 ObjCPropertyDecl *redeclaredProperty = 0, 6206 ObjCContainerDecl *lexicalDC = 0); 6207 6208 6209 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, 6210 ObjCPropertyDecl *SuperProperty, 6211 const IdentifierInfo *Name); 6212 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl); 6213 6214 6215 void CompareProperties(Decl *CDecl, Decl *MergeProtocols); 6216 6217 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, 6218 ObjCInterfaceDecl *ID); 6219 6220 void MatchOneProtocolPropertiesInClass(Decl *CDecl, 6221 ObjCProtocolDecl *PDecl); 6222 6223 Decl *ActOnAtEnd(Scope *S, SourceRange AtEnd, 6224 Decl **allMethods = 0, unsigned allNum = 0, 6225 Decl **allProperties = 0, unsigned pNum = 0, 6226 DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0); 6227 6228 Decl *ActOnProperty(Scope *S, SourceLocation AtLoc, 6229 SourceLocation LParenLoc, 6230 FieldDeclarator &FD, ObjCDeclSpec &ODS, 6231 Selector GetterSel, Selector SetterSel, 6232 bool *OverridingProperty, 6233 tok::ObjCKeywordKind MethodImplKind, 6234 DeclContext *lexicalDC = 0); 6235 6236 Decl *ActOnPropertyImplDecl(Scope *S, 6237 SourceLocation AtLoc, 6238 SourceLocation PropertyLoc, 6239 bool ImplKind, 6240 IdentifierInfo *PropertyId, 6241 IdentifierInfo *PropertyIvar, 6242 SourceLocation PropertyIvarLoc); 6243 6244 enum ObjCSpecialMethodKind { 6245 OSMK_None, 6246 OSMK_Alloc, 6247 OSMK_New, 6248 OSMK_Copy, 6249 OSMK_RetainingInit, 6250 OSMK_NonRetainingInit 6251 }; 6252 6253 struct ObjCArgInfo { 6254 IdentifierInfo *Name; 6255 SourceLocation NameLoc; 6256 // The Type is null if no type was specified, and the DeclSpec is invalid 6257 // in this case. 6258 ParsedType Type; 6259 ObjCDeclSpec DeclSpec; 6260 6261 /// ArgAttrs - Attribute list for this argument. 6262 AttributeList *ArgAttrs; 6263 }; 6264 6265 Decl *ActOnMethodDeclaration( 6266 Scope *S, 6267 SourceLocation BeginLoc, // location of the + or -. 6268 SourceLocation EndLoc, // location of the ; or {. 6269 tok::TokenKind MethodType, 6270 ObjCDeclSpec &ReturnQT, ParsedType ReturnType, 6271 ArrayRef<SourceLocation> SelectorLocs, Selector Sel, 6272 // optional arguments. The number of types/arguments is obtained 6273 // from the Sel.getNumArgs(). 6274 ObjCArgInfo *ArgInfo, 6275 DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args 6276 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind, 6277 bool isVariadic, bool MethodDefinition); 6278 6279 ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel, 6280 const ObjCObjectPointerType *OPT, 6281 bool IsInstance); 6282 ObjCMethodDecl *LookupMethodInObjectType(Selector Sel, QualType Ty, 6283 bool IsInstance); 6284 6285 bool inferObjCARCLifetime(ValueDecl *decl); 6286 6287 ExprResult 6288 HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, 6289 Expr *BaseExpr, 6290 SourceLocation OpLoc, 6291 DeclarationName MemberName, 6292 SourceLocation MemberLoc, 6293 SourceLocation SuperLoc, QualType SuperType, 6294 bool Super); 6295 6296 ExprResult 6297 ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, 6298 IdentifierInfo &propertyName, 6299 SourceLocation receiverNameLoc, 6300 SourceLocation propertyNameLoc); 6301 6302 ObjCMethodDecl *tryCaptureObjCSelf(SourceLocation Loc); 6303 6304 /// \brief Describes the kind of message expression indicated by a message 6305 /// send that starts with an identifier. 6306 enum ObjCMessageKind { 6307 /// \brief The message is sent to 'super'. 6308 ObjCSuperMessage, 6309 /// \brief The message is an instance message. 6310 ObjCInstanceMessage, 6311 /// \brief The message is a class message, and the identifier is a type 6312 /// name. 6313 ObjCClassMessage 6314 }; 6315 6316 ObjCMessageKind getObjCMessageKind(Scope *S, 6317 IdentifierInfo *Name, 6318 SourceLocation NameLoc, 6319 bool IsSuper, 6320 bool HasTrailingDot, 6321 ParsedType &ReceiverType); 6322 6323 ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, 6324 Selector Sel, 6325 SourceLocation LBracLoc, 6326 ArrayRef<SourceLocation> SelectorLocs, 6327 SourceLocation RBracLoc, 6328 MultiExprArg Args); 6329 6330 ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, 6331 QualType ReceiverType, 6332 SourceLocation SuperLoc, 6333 Selector Sel, 6334 ObjCMethodDecl *Method, 6335 SourceLocation LBracLoc, 6336 ArrayRef<SourceLocation> SelectorLocs, 6337 SourceLocation RBracLoc, 6338 MultiExprArg Args, 6339 bool isImplicit = false); 6340 6341 ExprResult BuildClassMessageImplicit(QualType ReceiverType, 6342 bool isSuperReceiver, 6343 SourceLocation Loc, 6344 Selector Sel, 6345 ObjCMethodDecl *Method, 6346 MultiExprArg Args); 6347 6348 ExprResult ActOnClassMessage(Scope *S, 6349 ParsedType Receiver, 6350 Selector Sel, 6351 SourceLocation LBracLoc, 6352 ArrayRef<SourceLocation> SelectorLocs, 6353 SourceLocation RBracLoc, 6354 MultiExprArg Args); 6355 6356 ExprResult BuildInstanceMessage(Expr *Receiver, 6357 QualType ReceiverType, 6358 SourceLocation SuperLoc, 6359 Selector Sel, 6360 ObjCMethodDecl *Method, 6361 SourceLocation LBracLoc, 6362 ArrayRef<SourceLocation> SelectorLocs, 6363 SourceLocation RBracLoc, 6364 MultiExprArg Args, 6365 bool isImplicit = false); 6366 6367 ExprResult BuildInstanceMessageImplicit(Expr *Receiver, 6368 QualType ReceiverType, 6369 SourceLocation Loc, 6370 Selector Sel, 6371 ObjCMethodDecl *Method, 6372 MultiExprArg Args); 6373 6374 ExprResult ActOnInstanceMessage(Scope *S, 6375 Expr *Receiver, 6376 Selector Sel, 6377 SourceLocation LBracLoc, 6378 ArrayRef<SourceLocation> SelectorLocs, 6379 SourceLocation RBracLoc, 6380 MultiExprArg Args); 6381 6382 ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, 6383 ObjCBridgeCastKind Kind, 6384 SourceLocation BridgeKeywordLoc, 6385 TypeSourceInfo *TSInfo, 6386 Expr *SubExpr); 6387 6388 ExprResult ActOnObjCBridgedCast(Scope *S, 6389 SourceLocation LParenLoc, 6390 ObjCBridgeCastKind Kind, 6391 SourceLocation BridgeKeywordLoc, 6392 ParsedType Type, 6393 SourceLocation RParenLoc, 6394 Expr *SubExpr); 6395 6396 bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall); 6397 6398 /// \brief Check whether the given new method is a valid override of the 6399 /// given overridden method, and set any properties that should be inherited. 6400 void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod, 6401 const ObjCMethodDecl *Overridden); 6402 6403 /// \brief Describes the compatibility of a result type with its method. 6404 enum ResultTypeCompatibilityKind { 6405 RTC_Compatible, 6406 RTC_Incompatible, 6407 RTC_Unknown 6408 }; 6409 6410 void CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod, 6411 ObjCInterfaceDecl *CurrentClass, 6412 ResultTypeCompatibilityKind RTC); 6413 6414 enum PragmaOptionsAlignKind { 6415 POAK_Native, // #pragma options align=native 6416 POAK_Natural, // #pragma options align=natural 6417 POAK_Packed, // #pragma options align=packed 6418 POAK_Power, // #pragma options align=power 6419 POAK_Mac68k, // #pragma options align=mac68k 6420 POAK_Reset // #pragma options align=reset 6421 }; 6422 6423 /// ActOnPragmaOptionsAlign - Called on well formed \#pragma options align. 6424 void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, 6425 SourceLocation PragmaLoc); 6426 6427 enum PragmaPackKind { 6428 PPK_Default, // #pragma pack([n]) 6429 PPK_Show, // #pragma pack(show), only supported by MSVC. 6430 PPK_Push, // #pragma pack(push, [identifier], [n]) 6431 PPK_Pop // #pragma pack(pop, [identifier], [n]) 6432 }; 6433 6434 enum PragmaMSStructKind { 6435 PMSST_OFF, // #pragms ms_struct off 6436 PMSST_ON // #pragms ms_struct on 6437 }; 6438 6439 /// ActOnPragmaPack - Called on well formed \#pragma pack(...). 6440 void ActOnPragmaPack(PragmaPackKind Kind, 6441 IdentifierInfo *Name, 6442 Expr *Alignment, 6443 SourceLocation PragmaLoc, 6444 SourceLocation LParenLoc, 6445 SourceLocation RParenLoc); 6446 6447 /// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off]. 6448 void ActOnPragmaMSStruct(PragmaMSStructKind Kind); 6449 6450 /// ActOnPragmaUnused - Called on well-formed '\#pragma unused'. 6451 void ActOnPragmaUnused(const Token &Identifier, 6452 Scope *curScope, 6453 SourceLocation PragmaLoc); 6454 6455 /// ActOnPragmaVisibility - Called on well formed \#pragma GCC visibility... . 6456 void ActOnPragmaVisibility(const IdentifierInfo* VisType, 6457 SourceLocation PragmaLoc); 6458 6459 NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II, 6460 SourceLocation Loc); 6461 void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W); 6462 6463 /// ActOnPragmaWeakID - Called on well formed \#pragma weak ident. 6464 void ActOnPragmaWeakID(IdentifierInfo* WeakName, 6465 SourceLocation PragmaLoc, 6466 SourceLocation WeakNameLoc); 6467 6468 /// ActOnPragmaRedefineExtname - Called on well formed 6469 /// \#pragma redefine_extname oldname newname. 6470 void ActOnPragmaRedefineExtname(IdentifierInfo* WeakName, 6471 IdentifierInfo* AliasName, 6472 SourceLocation PragmaLoc, 6473 SourceLocation WeakNameLoc, 6474 SourceLocation AliasNameLoc); 6475 6476 /// ActOnPragmaWeakAlias - Called on well formed \#pragma weak ident = ident. 6477 void ActOnPragmaWeakAlias(IdentifierInfo* WeakName, 6478 IdentifierInfo* AliasName, 6479 SourceLocation PragmaLoc, 6480 SourceLocation WeakNameLoc, 6481 SourceLocation AliasNameLoc); 6482 6483 /// ActOnPragmaFPContract - Called on well formed 6484 /// \#pragma {STDC,OPENCL} FP_CONTRACT 6485 void ActOnPragmaFPContract(tok::OnOffSwitch OOS); 6486 6487 /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to 6488 /// a the record decl, to handle '\#pragma pack' and '\#pragma options align'. 6489 void AddAlignmentAttributesForRecord(RecordDecl *RD); 6490 6491 /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record. 6492 void AddMsStructLayoutForRecord(RecordDecl *RD); 6493 6494 /// FreePackedContext - Deallocate and null out PackContext. 6495 void FreePackedContext(); 6496 6497 /// PushNamespaceVisibilityAttr - Note that we've entered a 6498 /// namespace with a visibility attribute. 6499 void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, 6500 SourceLocation Loc); 6501 6502 /// AddPushedVisibilityAttribute - If '\#pragma GCC visibility' was used, 6503 /// add an appropriate visibility attribute. 6504 void AddPushedVisibilityAttribute(Decl *RD); 6505 6506 /// PopPragmaVisibility - Pop the top element of the visibility stack; used 6507 /// for '\#pragma GCC visibility' and visibility attributes on namespaces. 6508 void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc); 6509 6510 /// FreeVisContext - Deallocate and null out VisContext. 6511 void FreeVisContext(); 6512 6513 /// AddCFAuditedAttribute - Check whether we're currently within 6514 /// '\#pragma clang arc_cf_code_audited' and, if so, consider adding 6515 /// the appropriate attribute. 6516 void AddCFAuditedAttribute(Decl *D); 6517 6518 /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. 6519 void AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E, 6520 bool isDeclSpec); 6521 void AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *T, 6522 bool isDeclSpec); 6523 6524 /// \brief The kind of conversion being performed. 6525 enum CheckedConversionKind { 6526 /// \brief An implicit conversion. 6527 CCK_ImplicitConversion, 6528 /// \brief A C-style cast. 6529 CCK_CStyleCast, 6530 /// \brief A functional-style cast. 6531 CCK_FunctionalCast, 6532 /// \brief A cast other than a C-style cast. 6533 CCK_OtherCast 6534 }; 6535 6536 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit 6537 /// cast. If there is already an implicit cast, merge into the existing one. 6538 /// If isLvalue, the result of the cast is an lvalue. 6539 ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, 6540 ExprValueKind VK = VK_RValue, 6541 const CXXCastPath *BasePath = 0, 6542 CheckedConversionKind CCK 6543 = CCK_ImplicitConversion); 6544 6545 /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding 6546 /// to the conversion from scalar type ScalarTy to the Boolean type. 6547 static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy); 6548 6549 /// IgnoredValueConversions - Given that an expression's result is 6550 /// syntactically ignored, perform any conversions that are 6551 /// required. 6552 ExprResult IgnoredValueConversions(Expr *E); 6553 6554 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts 6555 // functions and arrays to their respective pointers (C99 6.3.2.1). 6556 ExprResult UsualUnaryConversions(Expr *E); 6557 6558 // DefaultFunctionArrayConversion - converts functions and arrays 6559 // to their respective pointers (C99 6.3.2.1). 6560 ExprResult DefaultFunctionArrayConversion(Expr *E); 6561 6562 // DefaultFunctionArrayLvalueConversion - converts functions and 6563 // arrays to their respective pointers and performs the 6564 // lvalue-to-rvalue conversion. 6565 ExprResult DefaultFunctionArrayLvalueConversion(Expr *E); 6566 6567 // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on 6568 // the operand. This is DefaultFunctionArrayLvalueConversion, 6569 // except that it assumes the operand isn't of function or array 6570 // type. 6571 ExprResult DefaultLvalueConversion(Expr *E); 6572 6573 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that 6574 // do not have a prototype. Integer promotions are performed on each 6575 // argument, and arguments that have type float are promoted to double. 6576 ExprResult DefaultArgumentPromotion(Expr *E); 6577 6578 // Used for emitting the right warning by DefaultVariadicArgumentPromotion 6579 enum VariadicCallType { 6580 VariadicFunction, 6581 VariadicBlock, 6582 VariadicMethod, 6583 VariadicConstructor, 6584 VariadicDoesNotApply 6585 }; 6586 6587 VariadicCallType getVariadicCallType(FunctionDecl *FDecl, 6588 const FunctionProtoType *Proto, 6589 Expr *Fn); 6590 6591 // Used for determining in which context a type is allowed to be passed to a 6592 // vararg function. 6593 enum VarArgKind { 6594 VAK_Valid, 6595 VAK_ValidInCXX11, 6596 VAK_Invalid 6597 }; 6598 6599 // Determines which VarArgKind fits an expression. 6600 VarArgKind isValidVarArgType(const QualType &Ty); 6601 6602 /// GatherArgumentsForCall - Collector argument expressions for various 6603 /// form of call prototypes. 6604 bool GatherArgumentsForCall(SourceLocation CallLoc, 6605 FunctionDecl *FDecl, 6606 const FunctionProtoType *Proto, 6607 unsigned FirstProtoArg, 6608 Expr **Args, unsigned NumArgs, 6609 SmallVector<Expr *, 8> &AllArgs, 6610 VariadicCallType CallType = VariadicDoesNotApply, 6611 bool AllowExplicit = false); 6612 6613 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but 6614 // will create a runtime trap if the resulting type is not a POD type. 6615 ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, 6616 FunctionDecl *FDecl); 6617 6618 /// Checks to see if the given expression is a valid argument to a variadic 6619 /// function, issuing a diagnostic and returning NULL if not. 6620 bool variadicArgumentPODCheck(const Expr *E, VariadicCallType CT); 6621 6622 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's 6623 // operands and then handles various conversions that are common to binary 6624 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this 6625 // routine returns the first non-arithmetic type found. The client is 6626 // responsible for emitting appropriate error diagnostics. 6627 QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS, 6628 bool IsCompAssign = false); 6629 6630 /// AssignConvertType - All of the 'assignment' semantic checks return this 6631 /// enum to indicate whether the assignment was allowed. These checks are 6632 /// done for simple assignments, as well as initialization, return from 6633 /// function, argument passing, etc. The query is phrased in terms of a 6634 /// source and destination type. 6635 enum AssignConvertType { 6636 /// Compatible - the types are compatible according to the standard. 6637 Compatible, 6638 6639 /// PointerToInt - The assignment converts a pointer to an int, which we 6640 /// accept as an extension. 6641 PointerToInt, 6642 6643 /// IntToPointer - The assignment converts an int to a pointer, which we 6644 /// accept as an extension. 6645 IntToPointer, 6646 6647 /// FunctionVoidPointer - The assignment is between a function pointer and 6648 /// void*, which the standard doesn't allow, but we accept as an extension. 6649 FunctionVoidPointer, 6650 6651 /// IncompatiblePointer - The assignment is between two pointers types that 6652 /// are not compatible, but we accept them as an extension. 6653 IncompatiblePointer, 6654 6655 /// IncompatiblePointer - The assignment is between two pointers types which 6656 /// point to integers which have a different sign, but are otherwise 6657 /// identical. This is a subset of the above, but broken out because it's by 6658 /// far the most common case of incompatible pointers. 6659 IncompatiblePointerSign, 6660 6661 /// CompatiblePointerDiscardsQualifiers - The assignment discards 6662 /// c/v/r qualifiers, which we accept as an extension. 6663 CompatiblePointerDiscardsQualifiers, 6664 6665 /// IncompatiblePointerDiscardsQualifiers - The assignment 6666 /// discards qualifiers that we don't permit to be discarded, 6667 /// like address spaces. 6668 IncompatiblePointerDiscardsQualifiers, 6669 6670 /// IncompatibleNestedPointerQualifiers - The assignment is between two 6671 /// nested pointer types, and the qualifiers other than the first two 6672 /// levels differ e.g. char ** -> const char **, but we accept them as an 6673 /// extension. 6674 IncompatibleNestedPointerQualifiers, 6675 6676 /// IncompatibleVectors - The assignment is between two vector types that 6677 /// have the same size, which we accept as an extension. 6678 IncompatibleVectors, 6679 6680 /// IntToBlockPointer - The assignment converts an int to a block 6681 /// pointer. We disallow this. 6682 IntToBlockPointer, 6683 6684 /// IncompatibleBlockPointer - The assignment is between two block 6685 /// pointers types that are not compatible. 6686 IncompatibleBlockPointer, 6687 6688 /// IncompatibleObjCQualifiedId - The assignment is between a qualified 6689 /// id type and something else (that is incompatible with it). For example, 6690 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. 6691 IncompatibleObjCQualifiedId, 6692 6693 /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an 6694 /// object with __weak qualifier. 6695 IncompatibleObjCWeakRef, 6696 6697 /// Incompatible - We reject this conversion outright, it is invalid to 6698 /// represent it in the AST. 6699 Incompatible 6700 }; 6701 6702 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the 6703 /// assignment conversion type specified by ConvTy. This returns true if the 6704 /// conversion was invalid or false if the conversion was accepted. 6705 bool DiagnoseAssignmentResult(AssignConvertType ConvTy, 6706 SourceLocation Loc, 6707 QualType DstType, QualType SrcType, 6708 Expr *SrcExpr, AssignmentAction Action, 6709 bool *Complained = 0); 6710 6711 /// DiagnoseAssignmentEnum - Warn if assignment to enum is a constant 6712 /// integer not in the range of enum values. 6713 void DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, 6714 Expr *SrcExpr); 6715 6716 /// CheckAssignmentConstraints - Perform type checking for assignment, 6717 /// argument passing, variable initialization, and function return values. 6718 /// C99 6.5.16. 6719 AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, 6720 QualType LHSType, 6721 QualType RHSType); 6722 6723 /// Check assignment constraints and prepare for a conversion of the 6724 /// RHS to the LHS type. 6725 AssignConvertType CheckAssignmentConstraints(QualType LHSType, 6726 ExprResult &RHS, 6727 CastKind &Kind); 6728 6729 // CheckSingleAssignmentConstraints - Currently used by 6730 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking, 6731 // this routine performs the default function/array converions. 6732 AssignConvertType CheckSingleAssignmentConstraints(QualType LHSType, 6733 ExprResult &RHS, 6734 bool Diagnose = true); 6735 6736 // \brief If the lhs type is a transparent union, check whether we 6737 // can initialize the transparent union with the given expression. 6738 AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType, 6739 ExprResult &RHS); 6740 6741 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); 6742 6743 bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType); 6744 6745 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6746 AssignmentAction Action, 6747 bool AllowExplicit = false); 6748 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6749 AssignmentAction Action, 6750 bool AllowExplicit, 6751 ImplicitConversionSequence& ICS); 6752 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6753 const ImplicitConversionSequence& ICS, 6754 AssignmentAction Action, 6755 CheckedConversionKind CCK 6756 = CCK_ImplicitConversion); 6757 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6758 const StandardConversionSequence& SCS, 6759 AssignmentAction Action, 6760 CheckedConversionKind CCK); 6761 6762 /// the following "Check" methods will return a valid/converted QualType 6763 /// or a null QualType (indicating an error diagnostic was issued). 6764 6765 /// type checking binary operators (subroutines of CreateBuiltinBinOp). 6766 QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS, 6767 ExprResult &RHS); 6768 QualType CheckPointerToMemberOperands( // C++ 5.5 6769 ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK, 6770 SourceLocation OpLoc, bool isIndirect); 6771 QualType CheckMultiplyDivideOperands( // C99 6.5.5 6772 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign, 6773 bool IsDivide); 6774 QualType CheckRemainderOperands( // C99 6.5.5 6775 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, 6776 bool IsCompAssign = false); 6777 QualType CheckAdditionOperands( // C99 6.5.6 6778 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc, 6779 QualType* CompLHSTy = 0); 6780 QualType CheckSubtractionOperands( // C99 6.5.6 6781 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, 6782 QualType* CompLHSTy = 0); 6783 QualType CheckShiftOperands( // C99 6.5.7 6784 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc, 6785 bool IsCompAssign = false); 6786 QualType CheckCompareOperands( // C99 6.5.8/9 6787 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned OpaqueOpc, 6788 bool isRelational); 6789 QualType CheckBitwiseOperands( // C99 6.5.[10...12] 6790 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, 6791 bool IsCompAssign = false); 6792 QualType CheckLogicalOperands( // C99 6.5.[13,14] 6793 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc); 6794 // CheckAssignmentOperands is used for both simple and compound assignment. 6795 // For simple assignment, pass both expressions and a null converted type. 6796 // For compound assignment, pass both expressions and the converted type. 6797 QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] 6798 Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType); 6799 6800 ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc, 6801 UnaryOperatorKind Opcode, Expr *Op); 6802 ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc, 6803 BinaryOperatorKind Opcode, 6804 Expr *LHS, Expr *RHS); 6805 ExprResult checkPseudoObjectRValue(Expr *E); 6806 Expr *recreateSyntacticForm(PseudoObjectExpr *E); 6807 6808 QualType CheckConditionalOperands( // C99 6.5.15 6809 ExprResult &Cond, ExprResult &LHS, ExprResult &RHS, 6810 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation QuestionLoc); 6811 QualType CXXCheckConditionalOperands( // C++ 5.16 6812 ExprResult &cond, ExprResult &lhs, ExprResult &rhs, 6813 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc); 6814 QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2, 6815 bool *NonStandardCompositeType = 0); 6816 QualType FindCompositePointerType(SourceLocation Loc, 6817 ExprResult &E1, ExprResult &E2, 6818 bool *NonStandardCompositeType = 0) { 6819 Expr *E1Tmp = E1.take(), *E2Tmp = E2.take(); 6820 QualType Composite = FindCompositePointerType(Loc, E1Tmp, E2Tmp, 6821 NonStandardCompositeType); 6822 E1 = Owned(E1Tmp); 6823 E2 = Owned(E2Tmp); 6824 return Composite; 6825 } 6826 6827 QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS, 6828 SourceLocation QuestionLoc); 6829 6830 bool DiagnoseConditionalForNull(Expr *LHSExpr, Expr *RHSExpr, 6831 SourceLocation QuestionLoc); 6832 6833 /// type checking for vector binary operators. 6834 QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS, 6835 SourceLocation Loc, bool IsCompAssign); 6836 QualType GetSignedVectorType(QualType V); 6837 QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS, 6838 SourceLocation Loc, bool isRelational); 6839 QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS, 6840 SourceLocation Loc); 6841 6842 /// type checking declaration initializers (C99 6.7.8) 6843 bool CheckForConstantInitializer(Expr *e, QualType t); 6844 6845 // type checking C++ declaration initializers (C++ [dcl.init]). 6846 6847 /// ReferenceCompareResult - Expresses the result of comparing two 6848 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the 6849 /// purposes of initialization by reference (C++ [dcl.init.ref]p4). 6850 enum ReferenceCompareResult { 6851 /// Ref_Incompatible - The two types are incompatible, so direct 6852 /// reference binding is not possible. 6853 Ref_Incompatible = 0, 6854 /// Ref_Related - The two types are reference-related, which means 6855 /// that their unqualified forms (T1 and T2) are either the same 6856 /// or T1 is a base class of T2. 6857 Ref_Related, 6858 /// Ref_Compatible_With_Added_Qualification - The two types are 6859 /// reference-compatible with added qualification, meaning that 6860 /// they are reference-compatible and the qualifiers on T1 (cv1) 6861 /// are greater than the qualifiers on T2 (cv2). 6862 Ref_Compatible_With_Added_Qualification, 6863 /// Ref_Compatible - The two types are reference-compatible and 6864 /// have equivalent qualifiers (cv1 == cv2). 6865 Ref_Compatible 6866 }; 6867 6868 ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc, 6869 QualType T1, QualType T2, 6870 bool &DerivedToBase, 6871 bool &ObjCConversion, 6872 bool &ObjCLifetimeConversion); 6873 6874 ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType, 6875 Expr *CastExpr, CastKind &CastKind, 6876 ExprValueKind &VK, CXXCastPath &Path); 6877 6878 /// \brief Force an expression with unknown-type to an expression of the 6879 /// given type. 6880 ExprResult forceUnknownAnyToType(Expr *E, QualType ToType); 6881 6882 /// \brief Handle an expression that's being passed to an 6883 /// __unknown_anytype parameter. 6884 /// 6885 /// \return the effective parameter type to use, or null if the 6886 /// argument is invalid. 6887 QualType checkUnknownAnyArg(Expr *&result); 6888 6889 // CheckVectorCast - check type constraints for vectors. 6890 // Since vectors are an extension, there are no C standard reference for this. 6891 // We allow casting between vectors and integer datatypes of the same size. 6892 // returns true if the cast is invalid 6893 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, 6894 CastKind &Kind); 6895 6896 // CheckExtVectorCast - check type constraints for extended vectors. 6897 // Since vectors are an extension, there are no C standard reference for this. 6898 // We allow casting between vectors and integer datatypes of the same size, 6899 // or vectors and the element type of that vector. 6900 // returns the cast expr 6901 ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr, 6902 CastKind &Kind); 6903 6904 ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, 6905 SourceLocation LParenLoc, 6906 Expr *CastExpr, 6907 SourceLocation RParenLoc); 6908 6909 enum ARCConversionResult { ACR_okay, ACR_unbridged }; 6910 6911 /// \brief Checks for invalid conversions and casts between 6912 /// retainable pointers and other pointer kinds. 6913 ARCConversionResult CheckObjCARCConversion(SourceRange castRange, 6914 QualType castType, Expr *&op, 6915 CheckedConversionKind CCK); 6916 6917 Expr *stripARCUnbridgedCast(Expr *e); 6918 void diagnoseARCUnbridgedCast(Expr *e); 6919 6920 bool CheckObjCARCUnavailableWeakConversion(QualType castType, 6921 QualType ExprType); 6922 6923 /// checkRetainCycles - Check whether an Objective-C message send 6924 /// might create an obvious retain cycle. 6925 void checkRetainCycles(ObjCMessageExpr *msg); 6926 void checkRetainCycles(Expr *receiver, Expr *argument); 6927 void checkRetainCycles(VarDecl *Var, Expr *Init); 6928 6929 /// checkUnsafeAssigns - Check whether +1 expr is being assigned 6930 /// to weak/__unsafe_unretained type. 6931 bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS); 6932 6933 /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned 6934 /// to weak/__unsafe_unretained expression. 6935 void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS); 6936 6937 /// CheckMessageArgumentTypes - Check types in an Obj-C message send. 6938 /// \param Method - May be null. 6939 /// \param [out] ReturnType - The return type of the send. 6940 /// \return true iff there were any incompatible types. 6941 bool CheckMessageArgumentTypes(QualType ReceiverType, 6942 Expr **Args, unsigned NumArgs, Selector Sel, 6943 ArrayRef<SourceLocation> SelectorLocs, 6944 ObjCMethodDecl *Method, bool isClassMessage, 6945 bool isSuperMessage, 6946 SourceLocation lbrac, SourceLocation rbrac, 6947 QualType &ReturnType, ExprValueKind &VK); 6948 6949 /// \brief Determine the result of a message send expression based on 6950 /// the type of the receiver, the method expected to receive the message, 6951 /// and the form of the message send. 6952 QualType getMessageSendResultType(QualType ReceiverType, 6953 ObjCMethodDecl *Method, 6954 bool isClassMessage, bool isSuperMessage); 6955 6956 /// \brief If the given expression involves a message send to a method 6957 /// with a related result type, emit a note describing what happened. 6958 void EmitRelatedResultTypeNote(const Expr *E); 6959 6960 /// CheckBooleanCondition - Diagnose problems involving the use of 6961 /// the given expression as a boolean condition (e.g. in an if 6962 /// statement). Also performs the standard function and array 6963 /// decays, possibly changing the input variable. 6964 /// 6965 /// \param Loc - A location associated with the condition, e.g. the 6966 /// 'if' keyword. 6967 /// \return true iff there were any errors 6968 ExprResult CheckBooleanCondition(Expr *E, SourceLocation Loc); 6969 6970 ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc, 6971 Expr *SubExpr); 6972 6973 /// DiagnoseAssignmentAsCondition - Given that an expression is 6974 /// being used as a boolean condition, warn if it's an assignment. 6975 void DiagnoseAssignmentAsCondition(Expr *E); 6976 6977 /// \brief Redundant parentheses over an equality comparison can indicate 6978 /// that the user intended an assignment used as condition. 6979 void DiagnoseEqualityWithExtraParens(ParenExpr *ParenE); 6980 6981 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. 6982 ExprResult CheckCXXBooleanCondition(Expr *CondExpr); 6983 6984 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have 6985 /// the specified width and sign. If an overflow occurs, detect it and emit 6986 /// the specified diagnostic. 6987 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, 6988 unsigned NewWidth, bool NewSign, 6989 SourceLocation Loc, unsigned DiagID); 6990 6991 /// Checks that the Objective-C declaration is declared in the global scope. 6992 /// Emits an error and marks the declaration as invalid if it's not declared 6993 /// in the global scope. 6994 bool CheckObjCDeclScope(Decl *D); 6995 6996 /// \brief Abstract base class used for diagnosing integer constant 6997 /// expression violations. 6998 class VerifyICEDiagnoser { 6999 public: 7000 bool Suppress; 7001 7002 VerifyICEDiagnoser(bool Suppress = false) : Suppress(Suppress) { } 7003 7004 virtual void diagnoseNotICE(Sema &S, SourceLocation Loc, SourceRange SR) =0; 7005 virtual void diagnoseFold(Sema &S, SourceLocation Loc, SourceRange SR); 7006 virtual ~VerifyICEDiagnoser() { } 7007 }; 7008 7009 /// VerifyIntegerConstantExpression - Verifies that an expression is an ICE, 7010 /// and reports the appropriate diagnostics. Returns false on success. 7011 /// Can optionally return the value of the expression. 7012 ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, 7013 VerifyICEDiagnoser &Diagnoser, 7014 bool AllowFold = true); 7015 ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, 7016 unsigned DiagID, 7017 bool AllowFold = true); 7018 ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result=0); 7019 7020 /// VerifyBitField - verifies that a bit field expression is an ICE and has 7021 /// the correct width, and that the field type is valid. 7022 /// Returns false on success. 7023 /// Can optionally return whether the bit-field is of width 0 7024 ExprResult VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, 7025 QualType FieldTy, Expr *BitWidth, 7026 bool *ZeroWidth = 0); 7027 7028 enum CUDAFunctionTarget { 7029 CFT_Device, 7030 CFT_Global, 7031 CFT_Host, 7032 CFT_HostDevice 7033 }; 7034 7035 CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D); 7036 7037 bool CheckCUDATarget(CUDAFunctionTarget CallerTarget, 7038 CUDAFunctionTarget CalleeTarget); 7039 7040 bool CheckCUDATarget(const FunctionDecl *Caller, const FunctionDecl *Callee) { 7041 return CheckCUDATarget(IdentifyCUDATarget(Caller), 7042 IdentifyCUDATarget(Callee)); 7043 } 7044 7045 /// \name Code completion 7046 //@{ 7047 /// \brief Describes the context in which code completion occurs. 7048 enum ParserCompletionContext { 7049 /// \brief Code completion occurs at top-level or namespace context. 7050 PCC_Namespace, 7051 /// \brief Code completion occurs within a class, struct, or union. 7052 PCC_Class, 7053 /// \brief Code completion occurs within an Objective-C interface, protocol, 7054 /// or category. 7055 PCC_ObjCInterface, 7056 /// \brief Code completion occurs within an Objective-C implementation or 7057 /// category implementation 7058 PCC_ObjCImplementation, 7059 /// \brief Code completion occurs within the list of instance variables 7060 /// in an Objective-C interface, protocol, category, or implementation. 7061 PCC_ObjCInstanceVariableList, 7062 /// \brief Code completion occurs following one or more template 7063 /// headers. 7064 PCC_Template, 7065 /// \brief Code completion occurs following one or more template 7066 /// headers within a class. 7067 PCC_MemberTemplate, 7068 /// \brief Code completion occurs within an expression. 7069 PCC_Expression, 7070 /// \brief Code completion occurs within a statement, which may 7071 /// also be an expression or a declaration. 7072 PCC_Statement, 7073 /// \brief Code completion occurs at the beginning of the 7074 /// initialization statement (or expression) in a for loop. 7075 PCC_ForInit, 7076 /// \brief Code completion occurs within the condition of an if, 7077 /// while, switch, or for statement. 7078 PCC_Condition, 7079 /// \brief Code completion occurs within the body of a function on a 7080 /// recovery path, where we do not have a specific handle on our position 7081 /// in the grammar. 7082 PCC_RecoveryInFunction, 7083 /// \brief Code completion occurs where only a type is permitted. 7084 PCC_Type, 7085 /// \brief Code completion occurs in a parenthesized expression, which 7086 /// might also be a type cast. 7087 PCC_ParenthesizedExpression, 7088 /// \brief Code completion occurs within a sequence of declaration 7089 /// specifiers within a function, method, or block. 7090 PCC_LocalDeclarationSpecifiers 7091 }; 7092 7093 void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path); 7094 void CodeCompleteOrdinaryName(Scope *S, 7095 ParserCompletionContext CompletionContext); 7096 void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, 7097 bool AllowNonIdentifiers, 7098 bool AllowNestedNameSpecifiers); 7099 7100 struct CodeCompleteExpressionData; 7101 void CodeCompleteExpression(Scope *S, 7102 const CodeCompleteExpressionData &Data); 7103 void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, 7104 SourceLocation OpLoc, 7105 bool IsArrow); 7106 void CodeCompletePostfixExpression(Scope *S, ExprResult LHS); 7107 void CodeCompleteTag(Scope *S, unsigned TagSpec); 7108 void CodeCompleteTypeQualifiers(DeclSpec &DS); 7109 void CodeCompleteCase(Scope *S); 7110 void CodeCompleteCall(Scope *S, Expr *Fn, ArrayRef<Expr *> Args); 7111 void CodeCompleteInitializer(Scope *S, Decl *D); 7112 void CodeCompleteReturn(Scope *S); 7113 void CodeCompleteAfterIf(Scope *S); 7114 void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS); 7115 7116 void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, 7117 bool EnteringContext); 7118 void CodeCompleteUsing(Scope *S); 7119 void CodeCompleteUsingDirective(Scope *S); 7120 void CodeCompleteNamespaceDecl(Scope *S); 7121 void CodeCompleteNamespaceAliasDecl(Scope *S); 7122 void CodeCompleteOperatorName(Scope *S); 7123 void CodeCompleteConstructorInitializer(Decl *Constructor, 7124 CXXCtorInitializer** Initializers, 7125 unsigned NumInitializers); 7126 void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, 7127 bool AfterAmpersand); 7128 7129 void CodeCompleteObjCAtDirective(Scope *S); 7130 void CodeCompleteObjCAtVisibility(Scope *S); 7131 void CodeCompleteObjCAtStatement(Scope *S); 7132 void CodeCompleteObjCAtExpression(Scope *S); 7133 void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS); 7134 void CodeCompleteObjCPropertyGetter(Scope *S); 7135 void CodeCompleteObjCPropertySetter(Scope *S); 7136 void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, 7137 bool IsParameter); 7138 void CodeCompleteObjCMessageReceiver(Scope *S); 7139 void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, 7140 IdentifierInfo **SelIdents, 7141 unsigned NumSelIdents, 7142 bool AtArgumentExpression); 7143 void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, 7144 IdentifierInfo **SelIdents, 7145 unsigned NumSelIdents, 7146 bool AtArgumentExpression, 7147 bool IsSuper = false); 7148 void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, 7149 IdentifierInfo **SelIdents, 7150 unsigned NumSelIdents, 7151 bool AtArgumentExpression, 7152 ObjCInterfaceDecl *Super = 0); 7153 void CodeCompleteObjCForCollection(Scope *S, 7154 DeclGroupPtrTy IterationVar); 7155 void CodeCompleteObjCSelector(Scope *S, 7156 IdentifierInfo **SelIdents, 7157 unsigned NumSelIdents); 7158 void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols, 7159 unsigned NumProtocols); 7160 void CodeCompleteObjCProtocolDecl(Scope *S); 7161 void CodeCompleteObjCInterfaceDecl(Scope *S); 7162 void CodeCompleteObjCSuperclass(Scope *S, 7163 IdentifierInfo *ClassName, 7164 SourceLocation ClassNameLoc); 7165 void CodeCompleteObjCImplementationDecl(Scope *S); 7166 void CodeCompleteObjCInterfaceCategory(Scope *S, 7167 IdentifierInfo *ClassName, 7168 SourceLocation ClassNameLoc); 7169 void CodeCompleteObjCImplementationCategory(Scope *S, 7170 IdentifierInfo *ClassName, 7171 SourceLocation ClassNameLoc); 7172 void CodeCompleteObjCPropertyDefinition(Scope *S); 7173 void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, 7174 IdentifierInfo *PropertyName); 7175 void CodeCompleteObjCMethodDecl(Scope *S, 7176 bool IsInstanceMethod, 7177 ParsedType ReturnType); 7178 void CodeCompleteObjCMethodDeclSelector(Scope *S, 7179 bool IsInstanceMethod, 7180 bool AtParameterName, 7181 ParsedType ReturnType, 7182 IdentifierInfo **SelIdents, 7183 unsigned NumSelIdents); 7184 void CodeCompletePreprocessorDirective(bool InConditional); 7185 void CodeCompleteInPreprocessorConditionalExclusion(Scope *S); 7186 void CodeCompletePreprocessorMacroName(bool IsDefinition); 7187 void CodeCompletePreprocessorExpression(); 7188 void CodeCompletePreprocessorMacroArgument(Scope *S, 7189 IdentifierInfo *Macro, 7190 MacroInfo *MacroInfo, 7191 unsigned Argument); 7192 void CodeCompleteNaturalLanguage(); 7193 void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, 7194 CodeCompletionTUInfo &CCTUInfo, 7195 SmallVectorImpl<CodeCompletionResult> &Results); 7196 //@} 7197 7198 //===--------------------------------------------------------------------===// 7199 // Extra semantic analysis beyond the C type system 7200 7201public: 7202 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, 7203 unsigned ByteNo) const; 7204 7205private: 7206 void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr, 7207 const ArraySubscriptExpr *ASE=0, 7208 bool AllowOnePastEnd=true, bool IndexNegated=false); 7209 void CheckArrayAccess(const Expr *E); 7210 // Used to grab the relevant information from a FormatAttr and a 7211 // FunctionDeclaration. 7212 struct FormatStringInfo { 7213 unsigned FormatIdx; 7214 unsigned FirstDataArg; 7215 bool HasVAListArg; 7216 }; 7217 7218 bool getFormatStringInfo(const FormatAttr *Format, bool IsCXXMember, 7219 FormatStringInfo *FSI); 7220 bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall, 7221 const FunctionProtoType *Proto); 7222 bool CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation loc, 7223 Expr **Args, unsigned NumArgs); 7224 bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall, 7225 const FunctionProtoType *Proto); 7226 void CheckConstructorCall(FunctionDecl *FDecl, 7227 ArrayRef<const Expr *> Args, 7228 const FunctionProtoType *Proto, 7229 SourceLocation Loc); 7230 7231 void checkCall(NamedDecl *FDecl, ArrayRef<const Expr *> Args, 7232 unsigned NumProtoArgs, bool IsMemberFunction, 7233 SourceLocation Loc, SourceRange Range, 7234 VariadicCallType CallType); 7235 7236 7237 bool CheckObjCString(Expr *Arg); 7238 7239 ExprResult CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 7240 bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 7241 bool CheckMipsBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 7242 7243 bool SemaBuiltinVAStart(CallExpr *TheCall); 7244 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall); 7245 bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs); 7246 7247public: 7248 // Used by C++ template instantiation. 7249 ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); 7250 7251private: 7252 bool SemaBuiltinPrefetch(CallExpr *TheCall); 7253 bool SemaBuiltinObjectSize(CallExpr *TheCall); 7254 bool SemaBuiltinLongjmp(CallExpr *TheCall); 7255 ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult); 7256 ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult, 7257 AtomicExpr::AtomicOp Op); 7258 bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum, 7259 llvm::APSInt &Result); 7260 7261 enum FormatStringType { 7262 FST_Scanf, 7263 FST_Printf, 7264 FST_NSString, 7265 FST_Strftime, 7266 FST_Strfmon, 7267 FST_Kprintf, 7268 FST_Unknown 7269 }; 7270 static FormatStringType GetFormatStringType(const FormatAttr *Format); 7271 7272 enum StringLiteralCheckType { 7273 SLCT_NotALiteral, 7274 SLCT_UncheckedLiteral, 7275 SLCT_CheckedLiteral 7276 }; 7277 7278 StringLiteralCheckType checkFormatStringExpr(const Expr *E, 7279 ArrayRef<const Expr *> Args, 7280 bool HasVAListArg, 7281 unsigned format_idx, 7282 unsigned firstDataArg, 7283 FormatStringType Type, 7284 VariadicCallType CallType, 7285 bool inFunctionCall = true); 7286 7287 void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr, 7288 ArrayRef<const Expr *> Args, bool HasVAListArg, 7289 unsigned format_idx, unsigned firstDataArg, 7290 FormatStringType Type, bool inFunctionCall, 7291 VariadicCallType CallType); 7292 7293 bool CheckFormatArguments(const FormatAttr *Format, 7294 ArrayRef<const Expr *> Args, 7295 bool IsCXXMember, 7296 VariadicCallType CallType, 7297 SourceLocation Loc, SourceRange Range); 7298 bool CheckFormatArguments(ArrayRef<const Expr *> Args, 7299 bool HasVAListArg, unsigned format_idx, 7300 unsigned firstDataArg, FormatStringType Type, 7301 VariadicCallType CallType, 7302 SourceLocation Loc, SourceRange range); 7303 7304 void CheckNonNullArguments(const NonNullAttr *NonNull, 7305 const Expr * const *ExprArgs, 7306 SourceLocation CallSiteLoc); 7307 7308 void CheckMemaccessArguments(const CallExpr *Call, 7309 unsigned BId, 7310 IdentifierInfo *FnName); 7311 7312 void CheckStrlcpycatArguments(const CallExpr *Call, 7313 IdentifierInfo *FnName); 7314 7315 void CheckStrncatArguments(const CallExpr *Call, 7316 IdentifierInfo *FnName); 7317 7318 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, 7319 SourceLocation ReturnLoc); 7320 void CheckFloatComparison(SourceLocation Loc, Expr* LHS, Expr* RHS); 7321 void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation()); 7322 7323 void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field, 7324 Expr *Init); 7325 7326public: 7327 /// \brief Register a magic integral constant to be used as a type tag. 7328 void RegisterTypeTagForDatatype(const IdentifierInfo *ArgumentKind, 7329 uint64_t MagicValue, QualType Type, 7330 bool LayoutCompatible, bool MustBeNull); 7331 7332 struct TypeTagData { 7333 TypeTagData() {} 7334 7335 TypeTagData(QualType Type, bool LayoutCompatible, bool MustBeNull) : 7336 Type(Type), LayoutCompatible(LayoutCompatible), 7337 MustBeNull(MustBeNull) 7338 {} 7339 7340 QualType Type; 7341 7342 /// If true, \c Type should be compared with other expression's types for 7343 /// layout-compatibility. 7344 unsigned LayoutCompatible : 1; 7345 unsigned MustBeNull : 1; 7346 }; 7347 7348 /// A pair of ArgumentKind identifier and magic value. This uniquely 7349 /// identifies the magic value. 7350 typedef std::pair<const IdentifierInfo *, uint64_t> TypeTagMagicValue; 7351 7352private: 7353 /// \brief A map from magic value to type information. 7354 OwningPtr<llvm::DenseMap<TypeTagMagicValue, TypeTagData> > 7355 TypeTagForDatatypeMagicValues; 7356 7357 /// \brief Peform checks on a call of a function with argument_with_type_tag 7358 /// or pointer_with_type_tag attributes. 7359 void CheckArgumentWithTypeTag(const ArgumentWithTypeTagAttr *Attr, 7360 const Expr * const *ExprArgs); 7361 7362 /// \brief The parser's current scope. 7363 /// 7364 /// The parser maintains this state here. 7365 Scope *CurScope; 7366 7367protected: 7368 friend class Parser; 7369 friend class InitializationSequence; 7370 friend class ASTReader; 7371 friend class ASTWriter; 7372 7373public: 7374 /// \brief Retrieve the parser's current scope. 7375 /// 7376 /// This routine must only be used when it is certain that semantic analysis 7377 /// and the parser are in precisely the same context, which is not the case 7378 /// when, e.g., we are performing any kind of template instantiation. 7379 /// Therefore, the only safe places to use this scope are in the parser 7380 /// itself and in routines directly invoked from the parser and *never* from 7381 /// template substitution or instantiation. 7382 Scope *getCurScope() const { return CurScope; } 7383 7384 Decl *getObjCDeclContext() const; 7385 7386 DeclContext *getCurLexicalContext() const { 7387 return OriginalLexicalContext ? OriginalLexicalContext : CurContext; 7388 } 7389 7390 AvailabilityResult getCurContextAvailability() const; 7391 7392 const DeclContext *getCurObjCLexicalContext() const { 7393 const DeclContext *DC = getCurLexicalContext(); 7394 // A category implicitly has the attribute of the interface. 7395 if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(DC)) 7396 DC = CatD->getClassInterface(); 7397 return DC; 7398 } 7399}; 7400 7401/// \brief RAII object that enters a new expression evaluation context. 7402class EnterExpressionEvaluationContext { 7403 Sema &Actions; 7404 7405public: 7406 EnterExpressionEvaluationContext(Sema &Actions, 7407 Sema::ExpressionEvaluationContext NewContext, 7408 Decl *LambdaContextDecl = 0, 7409 bool IsDecltype = false) 7410 : Actions(Actions) { 7411 Actions.PushExpressionEvaluationContext(NewContext, LambdaContextDecl, 7412 IsDecltype); 7413 } 7414 EnterExpressionEvaluationContext(Sema &Actions, 7415 Sema::ExpressionEvaluationContext NewContext, 7416 Sema::ReuseLambdaContextDecl_t, 7417 bool IsDecltype = false) 7418 : Actions(Actions) { 7419 Actions.PushExpressionEvaluationContext(NewContext, 7420 Sema::ReuseLambdaContextDecl, 7421 IsDecltype); 7422 } 7423 7424 ~EnterExpressionEvaluationContext() { 7425 Actions.PopExpressionEvaluationContext(); 7426 } 7427}; 7428 7429} // end namespace clang 7430 7431#endif 7432