Sema.h revision 419563768ef4929a622d7c2b066856e82901bb91
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 VisibilityAttr *mergeVisibilityAttr(Decl *D, SourceRange Range, 1682 VisibilityAttr::VisibilityType Vis); 1683 DLLImportAttr *mergeDLLImportAttr(Decl *D, SourceRange Range); 1684 DLLExportAttr *mergeDLLExportAttr(Decl *D, SourceRange Range); 1685 FormatAttr *mergeFormatAttr(Decl *D, SourceRange Range, StringRef Format, 1686 int FormatIdx, int FirstArg); 1687 SectionAttr *mergeSectionAttr(Decl *D, SourceRange Range, StringRef Name); 1688 bool mergeDeclAttribute(NamedDecl *New, InheritableAttr *Attr); 1689 1690 void mergeDeclAttributes(NamedDecl *New, Decl *Old, 1691 bool MergeDeprecation = true); 1692 void MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls); 1693 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old, Scope *S); 1694 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old, 1695 Scope *S); 1696 void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old); 1697 void MergeVarDecl(VarDecl *New, LookupResult &OldDecls); 1698 void MergeVarDeclTypes(VarDecl *New, VarDecl *Old); 1699 void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old); 1700 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S); 1701 1702 // AssignmentAction - This is used by all the assignment diagnostic functions 1703 // to represent what is actually causing the operation 1704 enum AssignmentAction { 1705 AA_Assigning, 1706 AA_Passing, 1707 AA_Returning, 1708 AA_Converting, 1709 AA_Initializing, 1710 AA_Sending, 1711 AA_Casting 1712 }; 1713 1714 /// C++ Overloading. 1715 enum OverloadKind { 1716 /// This is a legitimate overload: the existing declarations are 1717 /// functions or function templates with different signatures. 1718 Ovl_Overload, 1719 1720 /// This is not an overload because the signature exactly matches 1721 /// an existing declaration. 1722 Ovl_Match, 1723 1724 /// This is not an overload because the lookup results contain a 1725 /// non-function. 1726 Ovl_NonFunction 1727 }; 1728 OverloadKind CheckOverload(Scope *S, 1729 FunctionDecl *New, 1730 const LookupResult &OldDecls, 1731 NamedDecl *&OldDecl, 1732 bool IsForUsingDecl); 1733 bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl); 1734 1735 /// \brief Checks availability of the function depending on the current 1736 /// function context.Inside an unavailable function,unavailability is ignored. 1737 /// 1738 /// \returns true if \p FD is unavailable and current context is inside 1739 /// an available function, false otherwise. 1740 bool isFunctionConsideredUnavailable(FunctionDecl *FD); 1741 1742 ImplicitConversionSequence 1743 TryImplicitConversion(Expr *From, QualType ToType, 1744 bool SuppressUserConversions, 1745 bool AllowExplicit, 1746 bool InOverloadResolution, 1747 bool CStyle, 1748 bool AllowObjCWritebackConversion); 1749 1750 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType); 1751 bool IsFloatingPointPromotion(QualType FromType, QualType ToType); 1752 bool IsComplexPromotion(QualType FromType, QualType ToType); 1753 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType, 1754 bool InOverloadResolution, 1755 QualType& ConvertedType, bool &IncompatibleObjC); 1756 bool isObjCPointerConversion(QualType FromType, QualType ToType, 1757 QualType& ConvertedType, bool &IncompatibleObjC); 1758 bool isObjCWritebackConversion(QualType FromType, QualType ToType, 1759 QualType &ConvertedType); 1760 bool IsBlockPointerConversion(QualType FromType, QualType ToType, 1761 QualType& ConvertedType); 1762 bool FunctionArgTypesAreEqual(const FunctionProtoType *OldType, 1763 const FunctionProtoType *NewType, 1764 unsigned *ArgPos = 0); 1765 void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, 1766 QualType FromType, QualType ToType); 1767 1768 CastKind PrepareCastToObjCObjectPointer(ExprResult &E); 1769 bool CheckPointerConversion(Expr *From, QualType ToType, 1770 CastKind &Kind, 1771 CXXCastPath& BasePath, 1772 bool IgnoreBaseAccess); 1773 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType, 1774 bool InOverloadResolution, 1775 QualType &ConvertedType); 1776 bool CheckMemberPointerConversion(Expr *From, QualType ToType, 1777 CastKind &Kind, 1778 CXXCastPath &BasePath, 1779 bool IgnoreBaseAccess); 1780 bool IsQualificationConversion(QualType FromType, QualType ToType, 1781 bool CStyle, bool &ObjCLifetimeConversion); 1782 bool IsNoReturnConversion(QualType FromType, QualType ToType, 1783 QualType &ResultTy); 1784 bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType); 1785 1786 1787 ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity, 1788 const VarDecl *NRVOCandidate, 1789 QualType ResultType, 1790 Expr *Value, 1791 bool AllowNRVO = true); 1792 1793 bool CanPerformCopyInitialization(const InitializedEntity &Entity, 1794 ExprResult Init); 1795 ExprResult PerformCopyInitialization(const InitializedEntity &Entity, 1796 SourceLocation EqualLoc, 1797 ExprResult Init, 1798 bool TopLevelOfInitList = false, 1799 bool AllowExplicit = false); 1800 ExprResult PerformObjectArgumentInitialization(Expr *From, 1801 NestedNameSpecifier *Qualifier, 1802 NamedDecl *FoundDecl, 1803 CXXMethodDecl *Method); 1804 1805 ExprResult PerformContextuallyConvertToBool(Expr *From); 1806 ExprResult PerformContextuallyConvertToObjCPointer(Expr *From); 1807 1808 /// Contexts in which a converted constant expression is required. 1809 enum CCEKind { 1810 CCEK_CaseValue, ///< Expression in a case label. 1811 CCEK_Enumerator, ///< Enumerator value with fixed underlying type. 1812 CCEK_TemplateArg ///< Value of a non-type template parameter. 1813 }; 1814 ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, 1815 llvm::APSInt &Value, CCEKind CCE); 1816 1817 /// \brief Abstract base class used to diagnose problems that occur while 1818 /// trying to convert an expression to integral or enumeration type. 1819 class ICEConvertDiagnoser { 1820 public: 1821 bool Suppress; 1822 bool SuppressConversion; 1823 1824 ICEConvertDiagnoser(bool Suppress = false, 1825 bool SuppressConversion = false) 1826 : Suppress(Suppress), SuppressConversion(SuppressConversion) { } 1827 1828 /// \brief Emits a diagnostic complaining that the expression does not have 1829 /// integral or enumeration type. 1830 virtual DiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, 1831 QualType T) = 0; 1832 1833 /// \brief Emits a diagnostic when the expression has incomplete class type. 1834 virtual DiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, 1835 QualType T) = 0; 1836 1837 /// \brief Emits a diagnostic when the only matching conversion function 1838 /// is explicit. 1839 virtual DiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, 1840 QualType T, 1841 QualType ConvTy) = 0; 1842 1843 /// \brief Emits a note for the explicit conversion function. 1844 virtual DiagnosticBuilder 1845 noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; 1846 1847 /// \brief Emits a diagnostic when there are multiple possible conversion 1848 /// functions. 1849 virtual DiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, 1850 QualType T) = 0; 1851 1852 /// \brief Emits a note for one of the candidate conversions. 1853 virtual DiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, 1854 QualType ConvTy) = 0; 1855 1856 /// \brief Emits a diagnostic when we picked a conversion function 1857 /// (for cases when we are not allowed to pick a conversion function). 1858 virtual DiagnosticBuilder diagnoseConversion(Sema &S, SourceLocation Loc, 1859 QualType T, 1860 QualType ConvTy) = 0; 1861 1862 virtual ~ICEConvertDiagnoser() {} 1863 }; 1864 1865 ExprResult 1866 ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *FromE, 1867 ICEConvertDiagnoser &Diagnoser, 1868 bool AllowScopedEnumerations); 1869 1870 enum ObjCSubscriptKind { 1871 OS_Array, 1872 OS_Dictionary, 1873 OS_Error 1874 }; 1875 ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE); 1876 1877 // Note that LK_String is intentionally after the other literals, as 1878 // this is used for diagnostics logic. 1879 enum ObjCLiteralKind { 1880 LK_Array, 1881 LK_Dictionary, 1882 LK_Numeric, 1883 LK_Boxed, 1884 LK_String, 1885 LK_Block, 1886 LK_None 1887 }; 1888 ObjCLiteralKind CheckLiteralKind(Expr *FromE); 1889 1890 ExprResult PerformObjectMemberConversion(Expr *From, 1891 NestedNameSpecifier *Qualifier, 1892 NamedDecl *FoundDecl, 1893 NamedDecl *Member); 1894 1895 // Members have to be NamespaceDecl* or TranslationUnitDecl*. 1896 // TODO: make this is a typesafe union. 1897 typedef llvm::SmallPtrSet<DeclContext *, 16> AssociatedNamespaceSet; 1898 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet; 1899 1900 void AddOverloadCandidate(FunctionDecl *Function, 1901 DeclAccessPair FoundDecl, 1902 ArrayRef<Expr *> Args, 1903 OverloadCandidateSet& CandidateSet, 1904 bool SuppressUserConversions = false, 1905 bool PartialOverloading = false, 1906 bool AllowExplicit = false); 1907 void AddFunctionCandidates(const UnresolvedSetImpl &Functions, 1908 ArrayRef<Expr *> Args, 1909 OverloadCandidateSet& CandidateSet, 1910 bool SuppressUserConversions = false, 1911 TemplateArgumentListInfo *ExplicitTemplateArgs = 0); 1912 void AddMethodCandidate(DeclAccessPair FoundDecl, 1913 QualType ObjectType, 1914 Expr::Classification ObjectClassification, 1915 Expr **Args, unsigned NumArgs, 1916 OverloadCandidateSet& CandidateSet, 1917 bool SuppressUserConversion = false); 1918 void AddMethodCandidate(CXXMethodDecl *Method, 1919 DeclAccessPair FoundDecl, 1920 CXXRecordDecl *ActingContext, QualType ObjectType, 1921 Expr::Classification ObjectClassification, 1922 ArrayRef<Expr *> Args, 1923 OverloadCandidateSet& CandidateSet, 1924 bool SuppressUserConversions = false); 1925 void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, 1926 DeclAccessPair FoundDecl, 1927 CXXRecordDecl *ActingContext, 1928 TemplateArgumentListInfo *ExplicitTemplateArgs, 1929 QualType ObjectType, 1930 Expr::Classification ObjectClassification, 1931 ArrayRef<Expr *> Args, 1932 OverloadCandidateSet& CandidateSet, 1933 bool SuppressUserConversions = false); 1934 void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate, 1935 DeclAccessPair FoundDecl, 1936 TemplateArgumentListInfo *ExplicitTemplateArgs, 1937 ArrayRef<Expr *> Args, 1938 OverloadCandidateSet& CandidateSet, 1939 bool SuppressUserConversions = false); 1940 void AddConversionCandidate(CXXConversionDecl *Conversion, 1941 DeclAccessPair FoundDecl, 1942 CXXRecordDecl *ActingContext, 1943 Expr *From, QualType ToType, 1944 OverloadCandidateSet& CandidateSet); 1945 void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate, 1946 DeclAccessPair FoundDecl, 1947 CXXRecordDecl *ActingContext, 1948 Expr *From, QualType ToType, 1949 OverloadCandidateSet &CandidateSet); 1950 void AddSurrogateCandidate(CXXConversionDecl *Conversion, 1951 DeclAccessPair FoundDecl, 1952 CXXRecordDecl *ActingContext, 1953 const FunctionProtoType *Proto, 1954 Expr *Object, ArrayRef<Expr *> Args, 1955 OverloadCandidateSet& CandidateSet); 1956 void AddMemberOperatorCandidates(OverloadedOperatorKind Op, 1957 SourceLocation OpLoc, 1958 Expr **Args, unsigned NumArgs, 1959 OverloadCandidateSet& CandidateSet, 1960 SourceRange OpRange = SourceRange()); 1961 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys, 1962 Expr **Args, unsigned NumArgs, 1963 OverloadCandidateSet& CandidateSet, 1964 bool IsAssignmentOperator = false, 1965 unsigned NumContextualBoolArguments = 0); 1966 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, 1967 SourceLocation OpLoc, 1968 Expr **Args, unsigned NumArgs, 1969 OverloadCandidateSet& CandidateSet); 1970 void AddArgumentDependentLookupCandidates(DeclarationName Name, 1971 bool Operator, SourceLocation Loc, 1972 ArrayRef<Expr *> Args, 1973 TemplateArgumentListInfo *ExplicitTemplateArgs, 1974 OverloadCandidateSet& CandidateSet, 1975 bool PartialOverloading = false); 1976 1977 // Emit as a 'note' the specific overload candidate 1978 void NoteOverloadCandidate(FunctionDecl *Fn, QualType DestType = QualType()); 1979 1980 // Emit as a series of 'note's all template and non-templates 1981 // identified by the expression Expr 1982 void NoteAllOverloadCandidates(Expr* E, QualType DestType = QualType()); 1983 1984 // [PossiblyAFunctionType] --> [Return] 1985 // NonFunctionType --> NonFunctionType 1986 // R (A) --> R(A) 1987 // R (*)(A) --> R (A) 1988 // R (&)(A) --> R (A) 1989 // R (S::*)(A) --> R (A) 1990 QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType); 1991 1992 FunctionDecl * 1993 ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, 1994 QualType TargetType, 1995 bool Complain, 1996 DeclAccessPair &Found, 1997 bool *pHadMultipleCandidates = 0); 1998 1999 FunctionDecl *ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl, 2000 bool Complain = false, 2001 DeclAccessPair* Found = 0); 2002 2003 bool ResolveAndFixSingleFunctionTemplateSpecialization( 2004 ExprResult &SrcExpr, 2005 bool DoFunctionPointerConverion = false, 2006 bool Complain = false, 2007 const SourceRange& OpRangeForComplaining = SourceRange(), 2008 QualType DestTypeForComplaining = QualType(), 2009 unsigned DiagIDForComplaining = 0); 2010 2011 2012 Expr *FixOverloadedFunctionReference(Expr *E, 2013 DeclAccessPair FoundDecl, 2014 FunctionDecl *Fn); 2015 ExprResult FixOverloadedFunctionReference(ExprResult, 2016 DeclAccessPair FoundDecl, 2017 FunctionDecl *Fn); 2018 2019 void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE, 2020 ArrayRef<Expr *> Args, 2021 OverloadCandidateSet &CandidateSet, 2022 bool PartialOverloading = false); 2023 2024 // An enum used to represent the different possible results of building a 2025 // range-based for loop. 2026 enum ForRangeStatus { 2027 FRS_Success, 2028 FRS_NoViableFunction, 2029 FRS_DiagnosticIssued 2030 }; 2031 2032 // An enum to represent whether something is dealing with a call to begin() 2033 // or a call to end() in a range-based for loop. 2034 enum BeginEndFunction { 2035 BEF_begin, 2036 BEF_end 2037 }; 2038 2039 ForRangeStatus BuildForRangeBeginEndCall(Scope *S, SourceLocation Loc, 2040 SourceLocation RangeLoc, 2041 VarDecl *Decl, 2042 BeginEndFunction BEF, 2043 const DeclarationNameInfo &NameInfo, 2044 LookupResult &MemberLookup, 2045 OverloadCandidateSet *CandidateSet, 2046 Expr *Range, ExprResult *CallExpr); 2047 2048 ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn, 2049 UnresolvedLookupExpr *ULE, 2050 SourceLocation LParenLoc, 2051 Expr **Args, unsigned NumArgs, 2052 SourceLocation RParenLoc, 2053 Expr *ExecConfig, 2054 bool AllowTypoCorrection=true); 2055 2056 bool buildOverloadedCallSet(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE, 2057 Expr **Args, unsigned NumArgs, 2058 SourceLocation RParenLoc, 2059 OverloadCandidateSet *CandidateSet, 2060 ExprResult *Result); 2061 2062 ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, 2063 unsigned Opc, 2064 const UnresolvedSetImpl &Fns, 2065 Expr *input); 2066 2067 ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, 2068 unsigned Opc, 2069 const UnresolvedSetImpl &Fns, 2070 Expr *LHS, Expr *RHS); 2071 2072 ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, 2073 SourceLocation RLoc, 2074 Expr *Base,Expr *Idx); 2075 2076 ExprResult 2077 BuildCallToMemberFunction(Scope *S, Expr *MemExpr, 2078 SourceLocation LParenLoc, Expr **Args, 2079 unsigned NumArgs, SourceLocation RParenLoc); 2080 ExprResult 2081 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc, 2082 Expr **Args, unsigned NumArgs, 2083 SourceLocation RParenLoc); 2084 2085 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, 2086 SourceLocation OpLoc); 2087 2088 /// CheckCallReturnType - Checks that a call expression's return type is 2089 /// complete. Returns true on failure. The location passed in is the location 2090 /// that best represents the call. 2091 bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc, 2092 CallExpr *CE, FunctionDecl *FD); 2093 2094 /// Helpers for dealing with blocks and functions. 2095 bool CheckParmsForFunctionDef(ParmVarDecl **Param, ParmVarDecl **ParamEnd, 2096 bool CheckParameterNames); 2097 void CheckCXXDefaultArguments(FunctionDecl *FD); 2098 void CheckExtraCXXDefaultArguments(Declarator &D); 2099 Scope *getNonFieldDeclScope(Scope *S); 2100 2101 /// \name Name lookup 2102 /// 2103 /// These routines provide name lookup that is used during semantic 2104 /// analysis to resolve the various kinds of names (identifiers, 2105 /// overloaded operator names, constructor names, etc.) into zero or 2106 /// more declarations within a particular scope. The major entry 2107 /// points are LookupName, which performs unqualified name lookup, 2108 /// and LookupQualifiedName, which performs qualified name lookup. 2109 /// 2110 /// All name lookup is performed based on some specific criteria, 2111 /// which specify what names will be visible to name lookup and how 2112 /// far name lookup should work. These criteria are important both 2113 /// for capturing language semantics (certain lookups will ignore 2114 /// certain names, for example) and for performance, since name 2115 /// lookup is often a bottleneck in the compilation of C++. Name 2116 /// lookup criteria is specified via the LookupCriteria enumeration. 2117 /// 2118 /// The results of name lookup can vary based on the kind of name 2119 /// lookup performed, the current language, and the translation 2120 /// unit. In C, for example, name lookup will either return nothing 2121 /// (no entity found) or a single declaration. In C++, name lookup 2122 /// can additionally refer to a set of overloaded functions or 2123 /// result in an ambiguity. All of the possible results of name 2124 /// lookup are captured by the LookupResult class, which provides 2125 /// the ability to distinguish among them. 2126 //@{ 2127 2128 /// @brief Describes the kind of name lookup to perform. 2129 enum LookupNameKind { 2130 /// Ordinary name lookup, which finds ordinary names (functions, 2131 /// variables, typedefs, etc.) in C and most kinds of names 2132 /// (functions, variables, members, types, etc.) in C++. 2133 LookupOrdinaryName = 0, 2134 /// Tag name lookup, which finds the names of enums, classes, 2135 /// structs, and unions. 2136 LookupTagName, 2137 /// Label name lookup. 2138 LookupLabel, 2139 /// Member name lookup, which finds the names of 2140 /// class/struct/union members. 2141 LookupMemberName, 2142 /// Look up of an operator name (e.g., operator+) for use with 2143 /// operator overloading. This lookup is similar to ordinary name 2144 /// lookup, but will ignore any declarations that are class members. 2145 LookupOperatorName, 2146 /// Look up of a name that precedes the '::' scope resolution 2147 /// operator in C++. This lookup completely ignores operator, object, 2148 /// function, and enumerator names (C++ [basic.lookup.qual]p1). 2149 LookupNestedNameSpecifierName, 2150 /// Look up a namespace name within a C++ using directive or 2151 /// namespace alias definition, ignoring non-namespace names (C++ 2152 /// [basic.lookup.udir]p1). 2153 LookupNamespaceName, 2154 /// Look up all declarations in a scope with the given name, 2155 /// including resolved using declarations. This is appropriate 2156 /// for checking redeclarations for a using declaration. 2157 LookupUsingDeclName, 2158 /// Look up an ordinary name that is going to be redeclared as a 2159 /// name with linkage. This lookup ignores any declarations that 2160 /// are outside of the current scope unless they have linkage. See 2161 /// C99 6.2.2p4-5 and C++ [basic.link]p6. 2162 LookupRedeclarationWithLinkage, 2163 /// Look up the name of an Objective-C protocol. 2164 LookupObjCProtocolName, 2165 /// Look up implicit 'self' parameter of an objective-c method. 2166 LookupObjCImplicitSelfParam, 2167 /// \brief Look up any declaration with any name. 2168 LookupAnyName 2169 }; 2170 2171 /// \brief Specifies whether (or how) name lookup is being performed for a 2172 /// redeclaration (vs. a reference). 2173 enum RedeclarationKind { 2174 /// \brief The lookup is a reference to this name that is not for the 2175 /// purpose of redeclaring the name. 2176 NotForRedeclaration = 0, 2177 /// \brief The lookup results will be used for redeclaration of a name, 2178 /// if an entity by that name already exists. 2179 ForRedeclaration 2180 }; 2181 2182 /// \brief The possible outcomes of name lookup for a literal operator. 2183 enum LiteralOperatorLookupResult { 2184 /// \brief The lookup resulted in an error. 2185 LOLR_Error, 2186 /// \brief The lookup found a single 'cooked' literal operator, which 2187 /// expects a normal literal to be built and passed to it. 2188 LOLR_Cooked, 2189 /// \brief The lookup found a single 'raw' literal operator, which expects 2190 /// a string literal containing the spelling of the literal token. 2191 LOLR_Raw, 2192 /// \brief The lookup found an overload set of literal operator templates, 2193 /// which expect the characters of the spelling of the literal token to be 2194 /// passed as a non-type template argument pack. 2195 LOLR_Template 2196 }; 2197 2198 SpecialMemberOverloadResult *LookupSpecialMember(CXXRecordDecl *D, 2199 CXXSpecialMember SM, 2200 bool ConstArg, 2201 bool VolatileArg, 2202 bool RValueThis, 2203 bool ConstThis, 2204 bool VolatileThis); 2205 2206private: 2207 bool CppLookupName(LookupResult &R, Scope *S); 2208 2209 // \brief The set of known/encountered (unique, canonicalized) NamespaceDecls. 2210 // 2211 // The boolean value will be true to indicate that the namespace was loaded 2212 // from an AST/PCH file, or false otherwise. 2213 llvm::DenseMap<NamespaceDecl*, bool> KnownNamespaces; 2214 2215 /// \brief Whether we have already loaded known namespaces from an extenal 2216 /// source. 2217 bool LoadedExternalKnownNamespaces; 2218 2219public: 2220 /// \brief Look up a name, looking for a single declaration. Return 2221 /// null if the results were absent, ambiguous, or overloaded. 2222 /// 2223 /// It is preferable to use the elaborated form and explicitly handle 2224 /// ambiguity and overloaded. 2225 NamedDecl *LookupSingleName(Scope *S, DeclarationName Name, 2226 SourceLocation Loc, 2227 LookupNameKind NameKind, 2228 RedeclarationKind Redecl 2229 = NotForRedeclaration); 2230 bool LookupName(LookupResult &R, Scope *S, 2231 bool AllowBuiltinCreation = false); 2232 bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, 2233 bool InUnqualifiedLookup = false); 2234 bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, 2235 bool AllowBuiltinCreation = false, 2236 bool EnteringContext = false); 2237 ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc, 2238 RedeclarationKind Redecl 2239 = NotForRedeclaration); 2240 2241 void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, 2242 QualType T1, QualType T2, 2243 UnresolvedSetImpl &Functions); 2244 2245 LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, 2246 SourceLocation GnuLabelLoc = SourceLocation()); 2247 2248 DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class); 2249 CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class); 2250 CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class, 2251 unsigned Quals); 2252 CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals, 2253 bool RValueThis, unsigned ThisQuals); 2254 CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class, 2255 unsigned Quals); 2256 CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals, 2257 bool RValueThis, unsigned ThisQuals); 2258 CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class); 2259 2260 LiteralOperatorLookupResult LookupLiteralOperator(Scope *S, LookupResult &R, 2261 ArrayRef<QualType> ArgTys, 2262 bool AllowRawAndTemplate); 2263 bool isKnownName(StringRef name); 2264 2265 void ArgumentDependentLookup(DeclarationName Name, bool Operator, 2266 SourceLocation Loc, 2267 ArrayRef<Expr *> Args, 2268 ADLResult &Functions); 2269 2270 void LookupVisibleDecls(Scope *S, LookupNameKind Kind, 2271 VisibleDeclConsumer &Consumer, 2272 bool IncludeGlobalScope = true); 2273 void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind, 2274 VisibleDeclConsumer &Consumer, 2275 bool IncludeGlobalScope = true); 2276 2277 TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, 2278 Sema::LookupNameKind LookupKind, 2279 Scope *S, CXXScopeSpec *SS, 2280 CorrectionCandidateCallback &CCC, 2281 DeclContext *MemberContext = 0, 2282 bool EnteringContext = false, 2283 const ObjCObjectPointerType *OPT = 0); 2284 2285 void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc, 2286 ArrayRef<Expr *> Args, 2287 AssociatedNamespaceSet &AssociatedNamespaces, 2288 AssociatedClassSet &AssociatedClasses); 2289 2290 void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S, 2291 bool ConsiderLinkage, 2292 bool ExplicitInstantiationOrSpecialization); 2293 2294 bool DiagnoseAmbiguousLookup(LookupResult &Result); 2295 //@} 2296 2297 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id, 2298 SourceLocation IdLoc, 2299 bool TypoCorrection = false); 2300 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, 2301 Scope *S, bool ForRedeclaration, 2302 SourceLocation Loc); 2303 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, 2304 Scope *S); 2305 void AddKnownFunctionAttributes(FunctionDecl *FD); 2306 2307 // More parsing and symbol table subroutines. 2308 2309 // Decl attributes - this routine is the top level dispatcher. 2310 void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD, 2311 bool NonInheritable = true, bool Inheritable = true); 2312 void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL, 2313 bool NonInheritable = true, bool Inheritable = true); 2314 bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl, 2315 const AttributeList *AttrList); 2316 2317 void checkUnusedDeclAttributes(Declarator &D); 2318 2319 bool CheckRegparmAttr(const AttributeList &attr, unsigned &value); 2320 bool CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC, 2321 const FunctionDecl *FD = 0); 2322 bool CheckNoReturnAttr(const AttributeList &attr); 2323 2324 /// \brief Stmt attributes - this routine is the top level dispatcher. 2325 StmtResult ProcessStmtAttributes(Stmt *Stmt, AttributeList *Attrs, 2326 SourceRange Range); 2327 2328 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method, 2329 bool &IncompleteImpl, unsigned DiagID); 2330 void WarnConflictingTypedMethods(ObjCMethodDecl *Method, 2331 ObjCMethodDecl *MethodDecl, 2332 bool IsProtocolMethodDecl); 2333 2334 void CheckConflictingOverridingMethod(ObjCMethodDecl *Method, 2335 ObjCMethodDecl *Overridden, 2336 bool IsProtocolMethodDecl); 2337 2338 /// WarnExactTypedMethods - This routine issues a warning if method 2339 /// implementation declaration matches exactly that of its declaration. 2340 void WarnExactTypedMethods(ObjCMethodDecl *Method, 2341 ObjCMethodDecl *MethodDecl, 2342 bool IsProtocolMethodDecl); 2343 2344 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl, 2345 ObjCInterfaceDecl *IDecl); 2346 2347 typedef llvm::SmallPtrSet<Selector, 8> SelectorSet; 2348 typedef llvm::DenseMap<Selector, ObjCMethodDecl*> ProtocolsMethodsMap; 2349 2350 /// CheckProtocolMethodDefs - This routine checks unimplemented 2351 /// methods declared in protocol, and those referenced by it. 2352 void CheckProtocolMethodDefs(SourceLocation ImpLoc, 2353 ObjCProtocolDecl *PDecl, 2354 bool& IncompleteImpl, 2355 const SelectorSet &InsMap, 2356 const SelectorSet &ClsMap, 2357 ObjCContainerDecl *CDecl); 2358 2359 /// CheckImplementationIvars - This routine checks if the instance variables 2360 /// listed in the implelementation match those listed in the interface. 2361 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, 2362 ObjCIvarDecl **Fields, unsigned nIvars, 2363 SourceLocation Loc); 2364 2365 /// ImplMethodsVsClassMethods - This is main routine to warn if any method 2366 /// remains unimplemented in the class or category \@implementation. 2367 void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl, 2368 ObjCContainerDecl* IDecl, 2369 bool IncompleteImpl = false); 2370 2371 /// DiagnoseUnimplementedProperties - This routine warns on those properties 2372 /// which must be implemented by this implementation. 2373 void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl, 2374 ObjCContainerDecl *CDecl, 2375 const SelectorSet &InsMap); 2376 2377 /// DefaultSynthesizeProperties - This routine default synthesizes all 2378 /// properties which must be synthesized in the class's \@implementation. 2379 void DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl, 2380 ObjCInterfaceDecl *IDecl); 2381 void DefaultSynthesizeProperties(Scope *S, Decl *D); 2382 2383 /// CollectImmediateProperties - This routine collects all properties in 2384 /// the class and its conforming protocols; but not those it its super class. 2385 void CollectImmediateProperties(ObjCContainerDecl *CDecl, 2386 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap, 2387 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& SuperPropMap); 2388 2389 /// Called by ActOnProperty to handle \@property declarations in 2390 /// class extensions. 2391 Decl *HandlePropertyInClassExtension(Scope *S, 2392 SourceLocation AtLoc, 2393 SourceLocation LParenLoc, 2394 FieldDeclarator &FD, 2395 Selector GetterSel, 2396 Selector SetterSel, 2397 const bool isAssign, 2398 const bool isReadWrite, 2399 const unsigned Attributes, 2400 const unsigned AttributesAsWritten, 2401 bool *isOverridingProperty, 2402 TypeSourceInfo *T, 2403 tok::ObjCKeywordKind MethodImplKind); 2404 2405 /// Called by ActOnProperty and HandlePropertyInClassExtension to 2406 /// handle creating the ObjcPropertyDecl for a category or \@interface. 2407 ObjCPropertyDecl *CreatePropertyDecl(Scope *S, 2408 ObjCContainerDecl *CDecl, 2409 SourceLocation AtLoc, 2410 SourceLocation LParenLoc, 2411 FieldDeclarator &FD, 2412 Selector GetterSel, 2413 Selector SetterSel, 2414 const bool isAssign, 2415 const bool isReadWrite, 2416 const unsigned Attributes, 2417 const unsigned AttributesAsWritten, 2418 TypeSourceInfo *T, 2419 tok::ObjCKeywordKind MethodImplKind, 2420 DeclContext *lexicalDC = 0); 2421 2422 /// AtomicPropertySetterGetterRules - This routine enforces the rule (via 2423 /// warning) when atomic property has one but not the other user-declared 2424 /// setter or getter. 2425 void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl, 2426 ObjCContainerDecl* IDecl); 2427 2428 void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D); 2429 2430 void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID); 2431 2432 enum MethodMatchStrategy { 2433 MMS_loose, 2434 MMS_strict 2435 }; 2436 2437 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns 2438 /// true, or false, accordingly. 2439 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, 2440 const ObjCMethodDecl *PrevMethod, 2441 MethodMatchStrategy strategy = MMS_strict); 2442 2443 /// MatchAllMethodDeclarations - Check methods declaraed in interface or 2444 /// or protocol against those declared in their implementations. 2445 void MatchAllMethodDeclarations(const SelectorSet &InsMap, 2446 const SelectorSet &ClsMap, 2447 SelectorSet &InsMapSeen, 2448 SelectorSet &ClsMapSeen, 2449 ObjCImplDecl* IMPDecl, 2450 ObjCContainerDecl* IDecl, 2451 bool &IncompleteImpl, 2452 bool ImmediateClass, 2453 bool WarnCategoryMethodImpl=false); 2454 2455 /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in 2456 /// category matches with those implemented in its primary class and 2457 /// warns each time an exact match is found. 2458 void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP); 2459 2460 /// \brief Add the given method to the list of globally-known methods. 2461 void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method); 2462 2463private: 2464 /// AddMethodToGlobalPool - Add an instance or factory method to the global 2465 /// pool. See descriptoin of AddInstanceMethodToGlobalPool. 2466 void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance); 2467 2468 /// LookupMethodInGlobalPool - Returns the instance or factory method and 2469 /// optionally warns if there are multiple signatures. 2470 ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R, 2471 bool receiverIdOrClass, 2472 bool warn, bool instance); 2473 2474public: 2475 /// AddInstanceMethodToGlobalPool - All instance methods in a translation 2476 /// unit are added to a global pool. This allows us to efficiently associate 2477 /// a selector with a method declaraation for purposes of typechecking 2478 /// messages sent to "id" (where the class of the object is unknown). 2479 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { 2480 AddMethodToGlobalPool(Method, impl, /*instance*/true); 2481 } 2482 2483 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods. 2484 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { 2485 AddMethodToGlobalPool(Method, impl, /*instance*/false); 2486 } 2487 2488 /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global 2489 /// pool. 2490 void AddAnyMethodToGlobalPool(Decl *D); 2491 2492 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if 2493 /// there are multiple signatures. 2494 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, 2495 bool receiverIdOrClass=false, 2496 bool warn=true) { 2497 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, 2498 warn, /*instance*/true); 2499 } 2500 2501 /// LookupFactoryMethodInGlobalPool - Returns the method and warns if 2502 /// there are multiple signatures. 2503 ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R, 2504 bool receiverIdOrClass=false, 2505 bool warn=true) { 2506 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, 2507 warn, /*instance*/false); 2508 } 2509 2510 /// LookupImplementedMethodInGlobalPool - Returns the method which has an 2511 /// implementation. 2512 ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel); 2513 2514 /// CollectIvarsToConstructOrDestruct - Collect those ivars which require 2515 /// initialization. 2516 void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI, 2517 SmallVectorImpl<ObjCIvarDecl*> &Ivars); 2518 2519 //===--------------------------------------------------------------------===// 2520 // Statement Parsing Callbacks: SemaStmt.cpp. 2521public: 2522 class FullExprArg { 2523 public: 2524 FullExprArg(Sema &actions) : E(0) { } 2525 2526 // FIXME: The const_cast here is ugly. RValue references would make this 2527 // much nicer (or we could duplicate a bunch of the move semantics 2528 // emulation code from Ownership.h). 2529 FullExprArg(const FullExprArg& Other) : E(Other.E) {} 2530 2531 ExprResult release() { 2532 return E; 2533 } 2534 2535 Expr *get() const { return E; } 2536 2537 Expr *operator->() { 2538 return E; 2539 } 2540 2541 private: 2542 // FIXME: No need to make the entire Sema class a friend when it's just 2543 // Sema::MakeFullExpr that needs access to the constructor below. 2544 friend class Sema; 2545 2546 explicit FullExprArg(Expr *expr) : E(expr) {} 2547 2548 Expr *E; 2549 }; 2550 2551 FullExprArg MakeFullExpr(Expr *Arg) { 2552 return MakeFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation()); 2553 } 2554 FullExprArg MakeFullExpr(Expr *Arg, SourceLocation CC) { 2555 return FullExprArg(ActOnFinishFullExpr(Arg, CC).release()); 2556 } 2557 FullExprArg MakeFullDiscardedValueExpr(Expr *Arg) { 2558 ExprResult FE = 2559 ActOnFinishFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation(), 2560 /*DiscardedValue*/ true); 2561 return FullExprArg(FE.release()); 2562 } 2563 2564 StmtResult ActOnExprStmt(ExprResult Arg); 2565 2566 StmtResult ActOnNullStmt(SourceLocation SemiLoc, 2567 bool HasLeadingEmptyMacro = false); 2568 2569 void ActOnStartOfCompoundStmt(); 2570 void ActOnFinishOfCompoundStmt(); 2571 StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, 2572 MultiStmtArg Elts, 2573 bool isStmtExpr); 2574 2575 /// \brief A RAII object to enter scope of a compound statement. 2576 class CompoundScopeRAII { 2577 public: 2578 CompoundScopeRAII(Sema &S): S(S) { 2579 S.ActOnStartOfCompoundStmt(); 2580 } 2581 2582 ~CompoundScopeRAII() { 2583 S.ActOnFinishOfCompoundStmt(); 2584 } 2585 2586 private: 2587 Sema &S; 2588 }; 2589 2590 StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, 2591 SourceLocation StartLoc, 2592 SourceLocation EndLoc); 2593 void ActOnForEachDeclStmt(DeclGroupPtrTy Decl); 2594 StmtResult ActOnForEachLValueExpr(Expr *E); 2595 StmtResult ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal, 2596 SourceLocation DotDotDotLoc, Expr *RHSVal, 2597 SourceLocation ColonLoc); 2598 void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt); 2599 2600 StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, 2601 SourceLocation ColonLoc, 2602 Stmt *SubStmt, Scope *CurScope); 2603 StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, 2604 SourceLocation ColonLoc, Stmt *SubStmt); 2605 2606 StmtResult ActOnAttributedStmt(SourceLocation AttrLoc, 2607 ArrayRef<const Attr*> Attrs, 2608 Stmt *SubStmt); 2609 2610 StmtResult ActOnIfStmt(SourceLocation IfLoc, 2611 FullExprArg CondVal, Decl *CondVar, 2612 Stmt *ThenVal, 2613 SourceLocation ElseLoc, Stmt *ElseVal); 2614 StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, 2615 Expr *Cond, 2616 Decl *CondVar); 2617 StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, 2618 Stmt *Switch, Stmt *Body); 2619 StmtResult ActOnWhileStmt(SourceLocation WhileLoc, 2620 FullExprArg Cond, 2621 Decl *CondVar, Stmt *Body); 2622 StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, 2623 SourceLocation WhileLoc, 2624 SourceLocation CondLParen, Expr *Cond, 2625 SourceLocation CondRParen); 2626 2627 StmtResult ActOnForStmt(SourceLocation ForLoc, 2628 SourceLocation LParenLoc, 2629 Stmt *First, FullExprArg Second, 2630 Decl *SecondVar, 2631 FullExprArg Third, 2632 SourceLocation RParenLoc, 2633 Stmt *Body); 2634 ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc, 2635 Expr *collection); 2636 StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, 2637 Stmt *First, Expr *collection, 2638 SourceLocation RParenLoc); 2639 StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body); 2640 2641 enum BuildForRangeKind { 2642 /// Initial building of a for-range statement. 2643 BFRK_Build, 2644 /// Instantiation or recovery rebuild of a for-range statement. Don't 2645 /// attempt any typo-correction. 2646 BFRK_Rebuild, 2647 /// Determining whether a for-range statement could be built. Avoid any 2648 /// unnecessary or irreversible actions. 2649 BFRK_Check 2650 }; 2651 2652 StmtResult ActOnCXXForRangeStmt(SourceLocation ForLoc, Stmt *LoopVar, 2653 SourceLocation ColonLoc, Expr *Collection, 2654 SourceLocation RParenLoc, 2655 BuildForRangeKind Kind); 2656 StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, 2657 SourceLocation ColonLoc, 2658 Stmt *RangeDecl, Stmt *BeginEndDecl, 2659 Expr *Cond, Expr *Inc, 2660 Stmt *LoopVarDecl, 2661 SourceLocation RParenLoc, 2662 BuildForRangeKind Kind); 2663 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body); 2664 2665 StmtResult ActOnGotoStmt(SourceLocation GotoLoc, 2666 SourceLocation LabelLoc, 2667 LabelDecl *TheDecl); 2668 StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, 2669 SourceLocation StarLoc, 2670 Expr *DestExp); 2671 StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope); 2672 StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope); 2673 2674 const VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E, 2675 bool AllowFunctionParameters); 2676 2677 StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp); 2678 StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp); 2679 2680 StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, 2681 bool IsVolatile, unsigned NumOutputs, 2682 unsigned NumInputs, IdentifierInfo **Names, 2683 MultiExprArg Constraints, MultiExprArg Exprs, 2684 Expr *AsmString, MultiExprArg Clobbers, 2685 SourceLocation RParenLoc); 2686 2687 NamedDecl *LookupInlineAsmIdentifier(StringRef Name, SourceLocation Loc, 2688 unsigned &Size, bool &IsVarDecl); 2689 bool LookupInlineAsmField(StringRef Base, StringRef Member, 2690 unsigned &Offset, SourceLocation AsmLoc); 2691 StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, 2692 ArrayRef<Token> AsmToks, SourceLocation EndLoc); 2693 2694 VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType, 2695 SourceLocation StartLoc, 2696 SourceLocation IdLoc, IdentifierInfo *Id, 2697 bool Invalid = false); 2698 2699 Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D); 2700 2701 StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, 2702 Decl *Parm, Stmt *Body); 2703 2704 StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body); 2705 2706 StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, 2707 MultiStmtArg Catch, Stmt *Finally); 2708 2709 StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw); 2710 StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, 2711 Scope *CurScope); 2712 ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, 2713 Expr *operand); 2714 StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, 2715 Expr *SynchExpr, 2716 Stmt *SynchBody); 2717 2718 StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body); 2719 2720 VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo, 2721 SourceLocation StartLoc, 2722 SourceLocation IdLoc, 2723 IdentifierInfo *Id); 2724 2725 Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D); 2726 2727 StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, 2728 Decl *ExDecl, Stmt *HandlerBlock); 2729 StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, 2730 MultiStmtArg Handlers); 2731 2732 StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ? 2733 SourceLocation TryLoc, 2734 Stmt *TryBlock, 2735 Stmt *Handler); 2736 2737 StmtResult ActOnSEHExceptBlock(SourceLocation Loc, 2738 Expr *FilterExpr, 2739 Stmt *Block); 2740 2741 StmtResult ActOnSEHFinallyBlock(SourceLocation Loc, 2742 Stmt *Block); 2743 2744 void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock); 2745 2746 bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const; 2747 2748 /// \brief If it's a file scoped decl that must warn if not used, keep track 2749 /// of it. 2750 void MarkUnusedFileScopedDecl(const DeclaratorDecl *D); 2751 2752 /// DiagnoseUnusedExprResult - If the statement passed in is an expression 2753 /// whose result is unused, warn. 2754 void DiagnoseUnusedExprResult(const Stmt *S); 2755 void DiagnoseUnusedDecl(const NamedDecl *ND); 2756 2757 /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null 2758 /// statement as a \p Body, and it is located on the same line. 2759 /// 2760 /// This helps prevent bugs due to typos, such as: 2761 /// if (condition); 2762 /// do_stuff(); 2763 void DiagnoseEmptyStmtBody(SourceLocation StmtLoc, 2764 const Stmt *Body, 2765 unsigned DiagID); 2766 2767 /// Warn if a for/while loop statement \p S, which is followed by 2768 /// \p PossibleBody, has a suspicious null statement as a body. 2769 void DiagnoseEmptyLoopBody(const Stmt *S, 2770 const Stmt *PossibleBody); 2771 2772 ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool) { 2773 return DelayedDiagnostics.push(pool); 2774 } 2775 void PopParsingDeclaration(ParsingDeclState state, Decl *decl); 2776 2777 typedef ProcessingContextState ParsingClassState; 2778 ParsingClassState PushParsingClass() { 2779 return DelayedDiagnostics.pushUndelayed(); 2780 } 2781 void PopParsingClass(ParsingClassState state) { 2782 DelayedDiagnostics.popUndelayed(state); 2783 } 2784 2785 void redelayDiagnostics(sema::DelayedDiagnosticPool &pool); 2786 2787 void EmitDeprecationWarning(NamedDecl *D, StringRef Message, 2788 SourceLocation Loc, 2789 const ObjCInterfaceDecl *UnknownObjCClass, 2790 const ObjCPropertyDecl *ObjCProperty); 2791 2792 void HandleDelayedDeprecationCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); 2793 2794 bool makeUnavailableInSystemHeader(SourceLocation loc, 2795 StringRef message); 2796 2797 //===--------------------------------------------------------------------===// 2798 // Expression Parsing Callbacks: SemaExpr.cpp. 2799 2800 bool CanUseDecl(NamedDecl *D); 2801 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, 2802 const ObjCInterfaceDecl *UnknownObjCClass=0); 2803 void NoteDeletedFunction(FunctionDecl *FD); 2804 std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD); 2805 bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, 2806 ObjCMethodDecl *Getter, 2807 SourceLocation Loc); 2808 void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, 2809 Expr **Args, unsigned NumArgs); 2810 2811 void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext, 2812 Decl *LambdaContextDecl = 0, 2813 bool IsDecltype = false); 2814 enum ReuseLambdaContextDecl_t { ReuseLambdaContextDecl }; 2815 void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext, 2816 ReuseLambdaContextDecl_t, 2817 bool IsDecltype = false); 2818 void PopExpressionEvaluationContext(); 2819 2820 void DiscardCleanupsInEvaluationContext(); 2821 2822 ExprResult TransformToPotentiallyEvaluated(Expr *E); 2823 ExprResult HandleExprEvaluationContextForTypeof(Expr *E); 2824 2825 ExprResult ActOnConstantExpression(ExprResult Res); 2826 2827 // Functions for marking a declaration referenced. These functions also 2828 // contain the relevant logic for marking if a reference to a function or 2829 // variable is an odr-use (in the C++11 sense). There are separate variants 2830 // for expressions referring to a decl; these exist because odr-use marking 2831 // needs to be delayed for some constant variables when we build one of the 2832 // named expressions. 2833 void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D); 2834 void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func); 2835 void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var); 2836 void MarkDeclRefReferenced(DeclRefExpr *E); 2837 void MarkMemberReferenced(MemberExpr *E); 2838 2839 void UpdateMarkingForLValueToRValue(Expr *E); 2840 void CleanupVarDeclMarking(); 2841 2842 enum TryCaptureKind { 2843 TryCapture_Implicit, TryCapture_ExplicitByVal, TryCapture_ExplicitByRef 2844 }; 2845 2846 /// \brief Try to capture the given variable. 2847 /// 2848 /// \param Var The variable to capture. 2849 /// 2850 /// \param Loc The location at which the capture occurs. 2851 /// 2852 /// \param Kind The kind of capture, which may be implicit (for either a 2853 /// block or a lambda), or explicit by-value or by-reference (for a lambda). 2854 /// 2855 /// \param EllipsisLoc The location of the ellipsis, if one is provided in 2856 /// an explicit lambda capture. 2857 /// 2858 /// \param BuildAndDiagnose Whether we are actually supposed to add the 2859 /// captures or diagnose errors. If false, this routine merely check whether 2860 /// the capture can occur without performing the capture itself or complaining 2861 /// if the variable cannot be captured. 2862 /// 2863 /// \param CaptureType Will be set to the type of the field used to capture 2864 /// this variable in the innermost block or lambda. Only valid when the 2865 /// variable can be captured. 2866 /// 2867 /// \param DeclRefType Will be set to the type of a reference to the capture 2868 /// from within the current scope. Only valid when the variable can be 2869 /// captured. 2870 /// 2871 /// \returns true if an error occurred (i.e., the variable cannot be 2872 /// captured) and false if the capture succeeded. 2873 bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, TryCaptureKind Kind, 2874 SourceLocation EllipsisLoc, bool BuildAndDiagnose, 2875 QualType &CaptureType, 2876 QualType &DeclRefType); 2877 2878 /// \brief Try to capture the given variable. 2879 bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, 2880 TryCaptureKind Kind = TryCapture_Implicit, 2881 SourceLocation EllipsisLoc = SourceLocation()); 2882 2883 /// \brief Given a variable, determine the type that a reference to that 2884 /// variable will have in the given scope. 2885 QualType getCapturedDeclRefType(VarDecl *Var, SourceLocation Loc); 2886 2887 void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T); 2888 void MarkDeclarationsReferencedInExpr(Expr *E, 2889 bool SkipLocalVariables = false); 2890 2891 /// \brief Try to recover by turning the given expression into a 2892 /// call. Returns true if recovery was attempted or an error was 2893 /// emitted; this may also leave the ExprResult invalid. 2894 bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD, 2895 bool ForceComplain = false, 2896 bool (*IsPlausibleResult)(QualType) = 0); 2897 2898 /// \brief Figure out if an expression could be turned into a call. 2899 bool isExprCallable(const Expr &E, QualType &ZeroArgCallReturnTy, 2900 UnresolvedSetImpl &NonTemplateOverloads); 2901 2902 /// \brief Conditionally issue a diagnostic based on the current 2903 /// evaluation context. 2904 /// 2905 /// \param Statement If Statement is non-null, delay reporting the 2906 /// diagnostic until the function body is parsed, and then do a basic 2907 /// reachability analysis to determine if the statement is reachable. 2908 /// If it is unreachable, the diagnostic will not be emitted. 2909 bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, 2910 const PartialDiagnostic &PD); 2911 2912 // Primary Expressions. 2913 SourceRange getExprRange(Expr *E) const; 2914 2915 ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, 2916 SourceLocation TemplateKWLoc, 2917 UnqualifiedId &Id, 2918 bool HasTrailingLParen, bool IsAddressOfOperand, 2919 CorrectionCandidateCallback *CCC = 0); 2920 2921 void DecomposeUnqualifiedId(const UnqualifiedId &Id, 2922 TemplateArgumentListInfo &Buffer, 2923 DeclarationNameInfo &NameInfo, 2924 const TemplateArgumentListInfo *&TemplateArgs); 2925 2926 bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, 2927 CorrectionCandidateCallback &CCC, 2928 TemplateArgumentListInfo *ExplicitTemplateArgs = 0, 2929 ArrayRef<Expr *> Args = ArrayRef<Expr *>()); 2930 2931 ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S, 2932 IdentifierInfo *II, 2933 bool AllowBuiltinCreation=false); 2934 2935 ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS, 2936 SourceLocation TemplateKWLoc, 2937 const DeclarationNameInfo &NameInfo, 2938 bool isAddressOfOperand, 2939 const TemplateArgumentListInfo *TemplateArgs); 2940 2941 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty, 2942 ExprValueKind VK, 2943 SourceLocation Loc, 2944 const CXXScopeSpec *SS = 0); 2945 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty, 2946 ExprValueKind VK, 2947 const DeclarationNameInfo &NameInfo, 2948 const CXXScopeSpec *SS = 0); 2949 ExprResult 2950 BuildAnonymousStructUnionMemberReference(const CXXScopeSpec &SS, 2951 SourceLocation nameLoc, 2952 IndirectFieldDecl *indirectField, 2953 Expr *baseObjectExpr = 0, 2954 SourceLocation opLoc = SourceLocation()); 2955 ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS, 2956 SourceLocation TemplateKWLoc, 2957 LookupResult &R, 2958 const TemplateArgumentListInfo *TemplateArgs); 2959 ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS, 2960 SourceLocation TemplateKWLoc, 2961 LookupResult &R, 2962 const TemplateArgumentListInfo *TemplateArgs, 2963 bool IsDefiniteInstance); 2964 bool UseArgumentDependentLookup(const CXXScopeSpec &SS, 2965 const LookupResult &R, 2966 bool HasTrailingLParen); 2967 2968 ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, 2969 const DeclarationNameInfo &NameInfo, 2970 bool IsAddressOfOperand); 2971 ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS, 2972 SourceLocation TemplateKWLoc, 2973 const DeclarationNameInfo &NameInfo, 2974 const TemplateArgumentListInfo *TemplateArgs); 2975 2976 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, 2977 LookupResult &R, 2978 bool NeedsADL); 2979 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, 2980 const DeclarationNameInfo &NameInfo, 2981 NamedDecl *D); 2982 2983 ExprResult BuildLiteralOperatorCall(LookupResult &R, 2984 DeclarationNameInfo &SuffixInfo, 2985 ArrayRef<Expr*> Args, 2986 SourceLocation LitEndLoc, 2987 TemplateArgumentListInfo *ExplicitTemplateArgs = 0); 2988 2989 ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind); 2990 ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val); 2991 ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = 0); 2992 ExprResult ActOnCharacterConstant(const Token &Tok, Scope *UDLScope = 0); 2993 ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E); 2994 ExprResult ActOnParenListExpr(SourceLocation L, 2995 SourceLocation R, 2996 MultiExprArg Val); 2997 2998 /// ActOnStringLiteral - The specified tokens were lexed as pasted string 2999 /// fragments (e.g. "foo" "bar" L"baz"). 3000 ExprResult ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks, 3001 Scope *UDLScope = 0); 3002 3003 ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc, 3004 SourceLocation DefaultLoc, 3005 SourceLocation RParenLoc, 3006 Expr *ControllingExpr, 3007 MultiTypeArg ArgTypes, 3008 MultiExprArg ArgExprs); 3009 ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, 3010 SourceLocation DefaultLoc, 3011 SourceLocation RParenLoc, 3012 Expr *ControllingExpr, 3013 TypeSourceInfo **Types, 3014 Expr **Exprs, 3015 unsigned NumAssocs); 3016 3017 // Binary/Unary Operators. 'Tok' is the token for the operator. 3018 ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, 3019 Expr *InputExpr); 3020 ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, 3021 UnaryOperatorKind Opc, Expr *Input); 3022 ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, 3023 tok::TokenKind Op, Expr *Input); 3024 3025 ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, 3026 SourceLocation OpLoc, 3027 UnaryExprOrTypeTrait ExprKind, 3028 SourceRange R); 3029 ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc, 3030 UnaryExprOrTypeTrait ExprKind); 3031 ExprResult 3032 ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, 3033 UnaryExprOrTypeTrait ExprKind, 3034 bool IsType, void *TyOrEx, 3035 const SourceRange &ArgRange); 3036 3037 ExprResult CheckPlaceholderExpr(Expr *E); 3038 bool CheckVecStepExpr(Expr *E); 3039 3040 bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind); 3041 bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc, 3042 SourceRange ExprRange, 3043 UnaryExprOrTypeTrait ExprKind); 3044 ExprResult ActOnSizeofParameterPackExpr(Scope *S, 3045 SourceLocation OpLoc, 3046 IdentifierInfo &Name, 3047 SourceLocation NameLoc, 3048 SourceLocation RParenLoc); 3049 ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, 3050 tok::TokenKind Kind, Expr *Input); 3051 3052 ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, 3053 Expr *Idx, SourceLocation RLoc); 3054 ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, 3055 Expr *Idx, SourceLocation RLoc); 3056 3057 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, 3058 SourceLocation OpLoc, bool IsArrow, 3059 CXXScopeSpec &SS, 3060 SourceLocation TemplateKWLoc, 3061 NamedDecl *FirstQualifierInScope, 3062 const DeclarationNameInfo &NameInfo, 3063 const TemplateArgumentListInfo *TemplateArgs); 3064 3065 // This struct is for use by ActOnMemberAccess to allow 3066 // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after 3067 // changing the access operator from a '.' to a '->' (to see if that is the 3068 // change needed to fix an error about an unknown member, e.g. when the class 3069 // defines a custom operator->). 3070 struct ActOnMemberAccessExtraArgs { 3071 Scope *S; 3072 UnqualifiedId &Id; 3073 Decl *ObjCImpDecl; 3074 bool HasTrailingLParen; 3075 }; 3076 3077 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, 3078 SourceLocation OpLoc, bool IsArrow, 3079 const CXXScopeSpec &SS, 3080 SourceLocation TemplateKWLoc, 3081 NamedDecl *FirstQualifierInScope, 3082 LookupResult &R, 3083 const TemplateArgumentListInfo *TemplateArgs, 3084 bool SuppressQualifierCheck = false, 3085 ActOnMemberAccessExtraArgs *ExtraArgs = 0); 3086 3087 ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow); 3088 ExprResult LookupMemberExpr(LookupResult &R, ExprResult &Base, 3089 bool &IsArrow, SourceLocation OpLoc, 3090 CXXScopeSpec &SS, 3091 Decl *ObjCImpDecl, 3092 bool HasTemplateArgs); 3093 3094 bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType, 3095 const CXXScopeSpec &SS, 3096 const LookupResult &R); 3097 3098 ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType, 3099 bool IsArrow, SourceLocation OpLoc, 3100 const CXXScopeSpec &SS, 3101 SourceLocation TemplateKWLoc, 3102 NamedDecl *FirstQualifierInScope, 3103 const DeclarationNameInfo &NameInfo, 3104 const TemplateArgumentListInfo *TemplateArgs); 3105 3106 ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, 3107 SourceLocation OpLoc, 3108 tok::TokenKind OpKind, 3109 CXXScopeSpec &SS, 3110 SourceLocation TemplateKWLoc, 3111 UnqualifiedId &Member, 3112 Decl *ObjCImpDecl, 3113 bool HasTrailingLParen); 3114 3115 void ActOnDefaultCtorInitializers(Decl *CDtorDecl); 3116 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, 3117 FunctionDecl *FDecl, 3118 const FunctionProtoType *Proto, 3119 Expr **Args, unsigned NumArgs, 3120 SourceLocation RParenLoc, 3121 bool ExecConfig = false); 3122 void CheckStaticArrayArgument(SourceLocation CallLoc, 3123 ParmVarDecl *Param, 3124 const Expr *ArgExpr); 3125 3126 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. 3127 /// This provides the location of the left/right parens and a list of comma 3128 /// locations. 3129 ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, 3130 MultiExprArg ArgExprs, SourceLocation RParenLoc, 3131 Expr *ExecConfig = 0, bool IsExecConfig = false); 3132 ExprResult BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, 3133 SourceLocation LParenLoc, 3134 Expr **Args, unsigned NumArgs, 3135 SourceLocation RParenLoc, 3136 Expr *Config = 0, 3137 bool IsExecConfig = false); 3138 3139 ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc, 3140 MultiExprArg ExecConfig, 3141 SourceLocation GGGLoc); 3142 3143 ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, 3144 Declarator &D, ParsedType &Ty, 3145 SourceLocation RParenLoc, Expr *CastExpr); 3146 ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, 3147 TypeSourceInfo *Ty, 3148 SourceLocation RParenLoc, 3149 Expr *Op); 3150 CastKind PrepareScalarCast(ExprResult &src, QualType destType); 3151 3152 /// \brief Build an altivec or OpenCL literal. 3153 ExprResult BuildVectorLiteral(SourceLocation LParenLoc, 3154 SourceLocation RParenLoc, Expr *E, 3155 TypeSourceInfo *TInfo); 3156 3157 ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME); 3158 3159 ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, 3160 ParsedType Ty, 3161 SourceLocation RParenLoc, 3162 Expr *InitExpr); 3163 3164 ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, 3165 TypeSourceInfo *TInfo, 3166 SourceLocation RParenLoc, 3167 Expr *LiteralExpr); 3168 3169 ExprResult ActOnInitList(SourceLocation LBraceLoc, 3170 MultiExprArg InitArgList, 3171 SourceLocation RBraceLoc); 3172 3173 ExprResult ActOnDesignatedInitializer(Designation &Desig, 3174 SourceLocation Loc, 3175 bool GNUSyntax, 3176 ExprResult Init); 3177 3178 ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, 3179 tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr); 3180 ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, 3181 BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr); 3182 ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, 3183 Expr *LHSExpr, Expr *RHSExpr); 3184 3185 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null 3186 /// in the case of a the GNU conditional expr extension. 3187 ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, 3188 SourceLocation ColonLoc, 3189 Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr); 3190 3191 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". 3192 ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, 3193 LabelDecl *TheDecl); 3194 3195 void ActOnStartStmtExpr(); 3196 ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, 3197 SourceLocation RPLoc); // "({..})" 3198 void ActOnStmtExprError(); 3199 3200 // __builtin_offsetof(type, identifier(.identifier|[expr])*) 3201 struct OffsetOfComponent { 3202 SourceLocation LocStart, LocEnd; 3203 bool isBrackets; // true if [expr], false if .ident 3204 union { 3205 IdentifierInfo *IdentInfo; 3206 Expr *E; 3207 } U; 3208 }; 3209 3210 /// __builtin_offsetof(type, a.b[123][456].c) 3211 ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, 3212 TypeSourceInfo *TInfo, 3213 OffsetOfComponent *CompPtr, 3214 unsigned NumComponents, 3215 SourceLocation RParenLoc); 3216 ExprResult ActOnBuiltinOffsetOf(Scope *S, 3217 SourceLocation BuiltinLoc, 3218 SourceLocation TypeLoc, 3219 ParsedType ParsedArgTy, 3220 OffsetOfComponent *CompPtr, 3221 unsigned NumComponents, 3222 SourceLocation RParenLoc); 3223 3224 // __builtin_choose_expr(constExpr, expr1, expr2) 3225 ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, 3226 Expr *CondExpr, Expr *LHSExpr, 3227 Expr *RHSExpr, SourceLocation RPLoc); 3228 3229 // __builtin_va_arg(expr, type) 3230 ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty, 3231 SourceLocation RPLoc); 3232 ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, 3233 TypeSourceInfo *TInfo, SourceLocation RPLoc); 3234 3235 // __null 3236 ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); 3237 3238 bool CheckCaseExpression(Expr *E); 3239 3240 /// \brief Describes the result of an "if-exists" condition check. 3241 enum IfExistsResult { 3242 /// \brief The symbol exists. 3243 IER_Exists, 3244 3245 /// \brief The symbol does not exist. 3246 IER_DoesNotExist, 3247 3248 /// \brief The name is a dependent name, so the results will differ 3249 /// from one instantiation to the next. 3250 IER_Dependent, 3251 3252 /// \brief An error occurred. 3253 IER_Error 3254 }; 3255 3256 IfExistsResult 3257 CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS, 3258 const DeclarationNameInfo &TargetNameInfo); 3259 3260 IfExistsResult 3261 CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc, 3262 bool IsIfExists, CXXScopeSpec &SS, 3263 UnqualifiedId &Name); 3264 3265 StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, 3266 bool IsIfExists, 3267 NestedNameSpecifierLoc QualifierLoc, 3268 DeclarationNameInfo NameInfo, 3269 Stmt *Nested); 3270 StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, 3271 bool IsIfExists, 3272 CXXScopeSpec &SS, UnqualifiedId &Name, 3273 Stmt *Nested); 3274 3275 //===------------------------- "Block" Extension ------------------------===// 3276 3277 /// ActOnBlockStart - This callback is invoked when a block literal is 3278 /// started. 3279 void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); 3280 3281 /// ActOnBlockArguments - This callback allows processing of block arguments. 3282 /// If there are no arguments, this is still invoked. 3283 void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo, 3284 Scope *CurScope); 3285 3286 /// ActOnBlockError - If there is an error parsing a block, this callback 3287 /// is invoked to pop the information about the block from the action impl. 3288 void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); 3289 3290 /// ActOnBlockStmtExpr - This is called when the body of a block statement 3291 /// literal was successfully completed. ^(int x){...} 3292 ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, 3293 Scope *CurScope); 3294 3295 //===---------------------------- OpenCL Features -----------------------===// 3296 3297 /// __builtin_astype(...) 3298 ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy, 3299 SourceLocation BuiltinLoc, 3300 SourceLocation RParenLoc); 3301 3302 //===---------------------------- C++ Features --------------------------===// 3303 3304 // Act on C++ namespaces 3305 Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc, 3306 SourceLocation NamespaceLoc, 3307 SourceLocation IdentLoc, 3308 IdentifierInfo *Ident, 3309 SourceLocation LBrace, 3310 AttributeList *AttrList); 3311 void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace); 3312 3313 NamespaceDecl *getStdNamespace() const; 3314 NamespaceDecl *getOrCreateStdNamespace(); 3315 3316 CXXRecordDecl *getStdBadAlloc() const; 3317 3318 /// \brief Tests whether Ty is an instance of std::initializer_list and, if 3319 /// it is and Element is not NULL, assigns the element type to Element. 3320 bool isStdInitializerList(QualType Ty, QualType *Element); 3321 3322 /// \brief Looks for the std::initializer_list template and instantiates it 3323 /// with Element, or emits an error if it's not found. 3324 /// 3325 /// \returns The instantiated template, or null on error. 3326 QualType BuildStdInitializerList(QualType Element, SourceLocation Loc); 3327 3328 /// \brief Determine whether Ctor is an initializer-list constructor, as 3329 /// defined in [dcl.init.list]p2. 3330 bool isInitListConstructor(const CXXConstructorDecl *Ctor); 3331 3332 Decl *ActOnUsingDirective(Scope *CurScope, 3333 SourceLocation UsingLoc, 3334 SourceLocation NamespcLoc, 3335 CXXScopeSpec &SS, 3336 SourceLocation IdentLoc, 3337 IdentifierInfo *NamespcName, 3338 AttributeList *AttrList); 3339 3340 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); 3341 3342 Decl *ActOnNamespaceAliasDef(Scope *CurScope, 3343 SourceLocation NamespaceLoc, 3344 SourceLocation AliasLoc, 3345 IdentifierInfo *Alias, 3346 CXXScopeSpec &SS, 3347 SourceLocation IdentLoc, 3348 IdentifierInfo *Ident); 3349 3350 void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow); 3351 bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target, 3352 const LookupResult &PreviousDecls); 3353 UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD, 3354 NamedDecl *Target); 3355 3356 bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc, 3357 bool isTypeName, 3358 const CXXScopeSpec &SS, 3359 SourceLocation NameLoc, 3360 const LookupResult &Previous); 3361 bool CheckUsingDeclQualifier(SourceLocation UsingLoc, 3362 const CXXScopeSpec &SS, 3363 SourceLocation NameLoc); 3364 3365 NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS, 3366 SourceLocation UsingLoc, 3367 CXXScopeSpec &SS, 3368 const DeclarationNameInfo &NameInfo, 3369 AttributeList *AttrList, 3370 bool IsInstantiation, 3371 bool IsTypeName, 3372 SourceLocation TypenameLoc); 3373 3374 bool CheckInheritingConstructorUsingDecl(UsingDecl *UD); 3375 3376 Decl *ActOnUsingDeclaration(Scope *CurScope, 3377 AccessSpecifier AS, 3378 bool HasUsingKeyword, 3379 SourceLocation UsingLoc, 3380 CXXScopeSpec &SS, 3381 UnqualifiedId &Name, 3382 AttributeList *AttrList, 3383 bool IsTypeName, 3384 SourceLocation TypenameLoc); 3385 Decl *ActOnAliasDeclaration(Scope *CurScope, 3386 AccessSpecifier AS, 3387 MultiTemplateParamsArg TemplateParams, 3388 SourceLocation UsingLoc, 3389 UnqualifiedId &Name, 3390 TypeResult Type); 3391 3392 /// BuildCXXConstructExpr - Creates a complete call to a constructor, 3393 /// including handling of its default argument expressions. 3394 /// 3395 /// \param ConstructKind - a CXXConstructExpr::ConstructionKind 3396 ExprResult 3397 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, 3398 CXXConstructorDecl *Constructor, MultiExprArg Exprs, 3399 bool HadMultipleCandidates, bool IsListInitialization, 3400 bool RequiresZeroInit, unsigned ConstructKind, 3401 SourceRange ParenRange); 3402 3403 // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if 3404 // the constructor can be elidable? 3405 ExprResult 3406 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, 3407 CXXConstructorDecl *Constructor, bool Elidable, 3408 MultiExprArg Exprs, bool HadMultipleCandidates, 3409 bool IsListInitialization, bool RequiresZeroInit, 3410 unsigned ConstructKind, SourceRange ParenRange); 3411 3412 /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating 3413 /// the default expr if needed. 3414 ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, 3415 FunctionDecl *FD, 3416 ParmVarDecl *Param); 3417 3418 /// FinalizeVarWithDestructor - Prepare for calling destructor on the 3419 /// constructed variable. 3420 void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType); 3421 3422 /// \brief Helper class that collects exception specifications for 3423 /// implicitly-declared special member functions. 3424 class ImplicitExceptionSpecification { 3425 // Pointer to allow copying 3426 Sema *Self; 3427 // We order exception specifications thus: 3428 // noexcept is the most restrictive, but is only used in C++11. 3429 // throw() comes next. 3430 // Then a throw(collected exceptions) 3431 // Finally no specification, which is expressed as noexcept(false). 3432 // throw(...) is used instead if any called function uses it. 3433 ExceptionSpecificationType ComputedEST; 3434 llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen; 3435 SmallVector<QualType, 4> Exceptions; 3436 3437 void ClearExceptions() { 3438 ExceptionsSeen.clear(); 3439 Exceptions.clear(); 3440 } 3441 3442 public: 3443 explicit ImplicitExceptionSpecification(Sema &Self) 3444 : Self(&Self), ComputedEST(EST_BasicNoexcept) { 3445 if (!Self.getLangOpts().CPlusPlus11) 3446 ComputedEST = EST_DynamicNone; 3447 } 3448 3449 /// \brief Get the computed exception specification type. 3450 ExceptionSpecificationType getExceptionSpecType() const { 3451 assert(ComputedEST != EST_ComputedNoexcept && 3452 "noexcept(expr) should not be a possible result"); 3453 return ComputedEST; 3454 } 3455 3456 /// \brief The number of exceptions in the exception specification. 3457 unsigned size() const { return Exceptions.size(); } 3458 3459 /// \brief The set of exceptions in the exception specification. 3460 const QualType *data() const { return Exceptions.data(); } 3461 3462 /// \brief Integrate another called method into the collected data. 3463 void CalledDecl(SourceLocation CallLoc, CXXMethodDecl *Method); 3464 3465 /// \brief Integrate an invoked expression into the collected data. 3466 void CalledExpr(Expr *E); 3467 3468 /// \brief Overwrite an EPI's exception specification with this 3469 /// computed exception specification. 3470 void getEPI(FunctionProtoType::ExtProtoInfo &EPI) const { 3471 EPI.ExceptionSpecType = getExceptionSpecType(); 3472 if (EPI.ExceptionSpecType == EST_Dynamic) { 3473 EPI.NumExceptions = size(); 3474 EPI.Exceptions = data(); 3475 } else if (EPI.ExceptionSpecType == EST_None) { 3476 /// C++11 [except.spec]p14: 3477 /// The exception-specification is noexcept(false) if the set of 3478 /// potential exceptions of the special member function contains "any" 3479 EPI.ExceptionSpecType = EST_ComputedNoexcept; 3480 EPI.NoexceptExpr = Self->ActOnCXXBoolLiteral(SourceLocation(), 3481 tok::kw_false).take(); 3482 } 3483 } 3484 FunctionProtoType::ExtProtoInfo getEPI() const { 3485 FunctionProtoType::ExtProtoInfo EPI; 3486 getEPI(EPI); 3487 return EPI; 3488 } 3489 }; 3490 3491 /// \brief Determine what sort of exception specification a defaulted 3492 /// copy constructor of a class will have. 3493 ImplicitExceptionSpecification 3494 ComputeDefaultedDefaultCtorExceptionSpec(SourceLocation Loc, 3495 CXXMethodDecl *MD); 3496 3497 /// \brief Determine what sort of exception specification a defaulted 3498 /// default constructor of a class will have, and whether the parameter 3499 /// will be const. 3500 ImplicitExceptionSpecification 3501 ComputeDefaultedCopyCtorExceptionSpec(CXXMethodDecl *MD); 3502 3503 /// \brief Determine what sort of exception specification a defautled 3504 /// copy assignment operator of a class will have, and whether the 3505 /// parameter will be const. 3506 ImplicitExceptionSpecification 3507 ComputeDefaultedCopyAssignmentExceptionSpec(CXXMethodDecl *MD); 3508 3509 /// \brief Determine what sort of exception specification a defaulted move 3510 /// constructor of a class will have. 3511 ImplicitExceptionSpecification 3512 ComputeDefaultedMoveCtorExceptionSpec(CXXMethodDecl *MD); 3513 3514 /// \brief Determine what sort of exception specification a defaulted move 3515 /// assignment operator of a class will have. 3516 ImplicitExceptionSpecification 3517 ComputeDefaultedMoveAssignmentExceptionSpec(CXXMethodDecl *MD); 3518 3519 /// \brief Determine what sort of exception specification a defaulted 3520 /// destructor of a class will have. 3521 ImplicitExceptionSpecification 3522 ComputeDefaultedDtorExceptionSpec(CXXMethodDecl *MD); 3523 3524 /// \brief Evaluate the implicit exception specification for a defaulted 3525 /// special member function. 3526 void EvaluateImplicitExceptionSpec(SourceLocation Loc, CXXMethodDecl *MD); 3527 3528 /// \brief Check the given exception-specification and update the 3529 /// extended prototype information with the results. 3530 void checkExceptionSpecification(ExceptionSpecificationType EST, 3531 ArrayRef<ParsedType> DynamicExceptions, 3532 ArrayRef<SourceRange> DynamicExceptionRanges, 3533 Expr *NoexceptExpr, 3534 SmallVectorImpl<QualType> &Exceptions, 3535 FunctionProtoType::ExtProtoInfo &EPI); 3536 3537 /// \brief Determine if a special member function should have a deleted 3538 /// definition when it is defaulted. 3539 bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM, 3540 bool Diagnose = false); 3541 3542 /// \brief Declare the implicit default constructor for the given class. 3543 /// 3544 /// \param ClassDecl The class declaration into which the implicit 3545 /// default constructor will be added. 3546 /// 3547 /// \returns The implicitly-declared default constructor. 3548 CXXConstructorDecl *DeclareImplicitDefaultConstructor( 3549 CXXRecordDecl *ClassDecl); 3550 3551 /// DefineImplicitDefaultConstructor - Checks for feasibility of 3552 /// defining this constructor as the default constructor. 3553 void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, 3554 CXXConstructorDecl *Constructor); 3555 3556 /// \brief Declare the implicit destructor for the given class. 3557 /// 3558 /// \param ClassDecl The class declaration into which the implicit 3559 /// destructor will be added. 3560 /// 3561 /// \returns The implicitly-declared destructor. 3562 CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl); 3563 3564 /// DefineImplicitDestructor - Checks for feasibility of 3565 /// defining this destructor as the default destructor. 3566 void DefineImplicitDestructor(SourceLocation CurrentLocation, 3567 CXXDestructorDecl *Destructor); 3568 3569 /// \brief Build an exception spec for destructors that don't have one. 3570 /// 3571 /// C++11 says that user-defined destructors with no exception spec get one 3572 /// that looks as if the destructor was implicitly declared. 3573 void AdjustDestructorExceptionSpec(CXXRecordDecl *ClassDecl, 3574 CXXDestructorDecl *Destructor); 3575 3576 /// \brief Declare all inherited constructors for the given class. 3577 /// 3578 /// \param ClassDecl The class declaration into which the inherited 3579 /// constructors will be added. 3580 void DeclareInheritedConstructors(CXXRecordDecl *ClassDecl); 3581 3582 /// \brief Declare the implicit copy constructor for the given class. 3583 /// 3584 /// \param ClassDecl The class declaration into which the implicit 3585 /// copy constructor will be added. 3586 /// 3587 /// \returns The implicitly-declared copy constructor. 3588 CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl); 3589 3590 /// DefineImplicitCopyConstructor - Checks for feasibility of 3591 /// defining this constructor as the copy constructor. 3592 void DefineImplicitCopyConstructor(SourceLocation CurrentLocation, 3593 CXXConstructorDecl *Constructor); 3594 3595 /// \brief Declare the implicit move constructor for the given class. 3596 /// 3597 /// \param ClassDecl The Class declaration into which the implicit 3598 /// move constructor will be added. 3599 /// 3600 /// \returns The implicitly-declared move constructor, or NULL if it wasn't 3601 /// declared. 3602 CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl); 3603 3604 /// DefineImplicitMoveConstructor - Checks for feasibility of 3605 /// defining this constructor as the move constructor. 3606 void DefineImplicitMoveConstructor(SourceLocation CurrentLocation, 3607 CXXConstructorDecl *Constructor); 3608 3609 /// \brief Declare the implicit copy assignment operator for the given class. 3610 /// 3611 /// \param ClassDecl The class declaration into which the implicit 3612 /// copy assignment operator will be added. 3613 /// 3614 /// \returns The implicitly-declared copy assignment operator. 3615 CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl); 3616 3617 /// \brief Defines an implicitly-declared copy assignment operator. 3618 void DefineImplicitCopyAssignment(SourceLocation CurrentLocation, 3619 CXXMethodDecl *MethodDecl); 3620 3621 /// \brief Declare the implicit move assignment operator for the given class. 3622 /// 3623 /// \param ClassDecl The Class declaration into which the implicit 3624 /// move assignment operator will be added. 3625 /// 3626 /// \returns The implicitly-declared move assignment operator, or NULL if it 3627 /// wasn't declared. 3628 CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl); 3629 3630 /// \brief Defines an implicitly-declared move assignment operator. 3631 void DefineImplicitMoveAssignment(SourceLocation CurrentLocation, 3632 CXXMethodDecl *MethodDecl); 3633 3634 /// \brief Force the declaration of any implicitly-declared members of this 3635 /// class. 3636 void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class); 3637 3638 /// \brief Determine whether the given function is an implicitly-deleted 3639 /// special member function. 3640 bool isImplicitlyDeleted(FunctionDecl *FD); 3641 3642 /// \brief Check whether 'this' shows up in the type of a static member 3643 /// function after the (naturally empty) cv-qualifier-seq would be. 3644 /// 3645 /// \returns true if an error occurred. 3646 bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method); 3647 3648 /// \brief Whether this' shows up in the exception specification of a static 3649 /// member function. 3650 bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method); 3651 3652 /// \brief Check whether 'this' shows up in the attributes of the given 3653 /// static member function. 3654 /// 3655 /// \returns true if an error occurred. 3656 bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method); 3657 3658 /// MaybeBindToTemporary - If the passed in expression has a record type with 3659 /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise 3660 /// it simply returns the passed in expression. 3661 ExprResult MaybeBindToTemporary(Expr *E); 3662 3663 bool CompleteConstructorCall(CXXConstructorDecl *Constructor, 3664 MultiExprArg ArgsPtr, 3665 SourceLocation Loc, 3666 SmallVectorImpl<Expr*> &ConvertedArgs, 3667 bool AllowExplicit = false); 3668 3669 ParsedType getDestructorName(SourceLocation TildeLoc, 3670 IdentifierInfo &II, SourceLocation NameLoc, 3671 Scope *S, CXXScopeSpec &SS, 3672 ParsedType ObjectType, 3673 bool EnteringContext); 3674 3675 ParsedType getDestructorType(const DeclSpec& DS, ParsedType ObjectType); 3676 3677 // Checks that reinterpret casts don't have undefined behavior. 3678 void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, 3679 bool IsDereference, SourceRange Range); 3680 3681 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's. 3682 ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, 3683 tok::TokenKind Kind, 3684 SourceLocation LAngleBracketLoc, 3685 Declarator &D, 3686 SourceLocation RAngleBracketLoc, 3687 SourceLocation LParenLoc, 3688 Expr *E, 3689 SourceLocation RParenLoc); 3690 3691 ExprResult BuildCXXNamedCast(SourceLocation OpLoc, 3692 tok::TokenKind Kind, 3693 TypeSourceInfo *Ty, 3694 Expr *E, 3695 SourceRange AngleBrackets, 3696 SourceRange Parens); 3697 3698 ExprResult BuildCXXTypeId(QualType TypeInfoType, 3699 SourceLocation TypeidLoc, 3700 TypeSourceInfo *Operand, 3701 SourceLocation RParenLoc); 3702 ExprResult BuildCXXTypeId(QualType TypeInfoType, 3703 SourceLocation TypeidLoc, 3704 Expr *Operand, 3705 SourceLocation RParenLoc); 3706 3707 /// ActOnCXXTypeid - Parse typeid( something ). 3708 ExprResult ActOnCXXTypeid(SourceLocation OpLoc, 3709 SourceLocation LParenLoc, bool isType, 3710 void *TyOrExpr, 3711 SourceLocation RParenLoc); 3712 3713 ExprResult BuildCXXUuidof(QualType TypeInfoType, 3714 SourceLocation TypeidLoc, 3715 TypeSourceInfo *Operand, 3716 SourceLocation RParenLoc); 3717 ExprResult BuildCXXUuidof(QualType TypeInfoType, 3718 SourceLocation TypeidLoc, 3719 Expr *Operand, 3720 SourceLocation RParenLoc); 3721 3722 /// ActOnCXXUuidof - Parse __uuidof( something ). 3723 ExprResult ActOnCXXUuidof(SourceLocation OpLoc, 3724 SourceLocation LParenLoc, bool isType, 3725 void *TyOrExpr, 3726 SourceLocation RParenLoc); 3727 3728 3729 //// ActOnCXXThis - Parse 'this' pointer. 3730 ExprResult ActOnCXXThis(SourceLocation loc); 3731 3732 /// \brief Try to retrieve the type of the 'this' pointer. 3733 /// 3734 /// \returns The type of 'this', if possible. Otherwise, returns a NULL type. 3735 QualType getCurrentThisType(); 3736 3737 /// \brief When non-NULL, the C++ 'this' expression is allowed despite the 3738 /// current context not being a non-static member function. In such cases, 3739 /// this provides the type used for 'this'. 3740 QualType CXXThisTypeOverride; 3741 3742 /// \brief RAII object used to temporarily allow the C++ 'this' expression 3743 /// to be used, with the given qualifiers on the current class type. 3744 class CXXThisScopeRAII { 3745 Sema &S; 3746 QualType OldCXXThisTypeOverride; 3747 bool Enabled; 3748 3749 public: 3750 /// \brief Introduce a new scope where 'this' may be allowed (when enabled), 3751 /// using the given declaration (which is either a class template or a 3752 /// class) along with the given qualifiers. 3753 /// along with the qualifiers placed on '*this'. 3754 CXXThisScopeRAII(Sema &S, Decl *ContextDecl, unsigned CXXThisTypeQuals, 3755 bool Enabled = true); 3756 3757 ~CXXThisScopeRAII(); 3758 }; 3759 3760 /// \brief Make sure the value of 'this' is actually available in the current 3761 /// context, if it is a potentially evaluated context. 3762 /// 3763 /// \param Loc The location at which the capture of 'this' occurs. 3764 /// 3765 /// \param Explicit Whether 'this' is explicitly captured in a lambda 3766 /// capture list. 3767 void CheckCXXThisCapture(SourceLocation Loc, bool Explicit = false); 3768 3769 /// \brief Determine whether the given type is the type of *this that is used 3770 /// outside of the body of a member function for a type that is currently 3771 /// being defined. 3772 bool isThisOutsideMemberFunctionBody(QualType BaseType); 3773 3774 /// ActOnCXXBoolLiteral - Parse {true,false} literals. 3775 ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); 3776 3777 3778 /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals. 3779 ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); 3780 3781 /// ActOnCXXNullPtrLiteral - Parse 'nullptr'. 3782 ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc); 3783 3784 //// ActOnCXXThrow - Parse throw expressions. 3785 ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr); 3786 ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, 3787 bool IsThrownVarInScope); 3788 ExprResult CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *E, 3789 bool IsThrownVarInScope); 3790 3791 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. 3792 /// Can be interpreted either as function-style casting ("int(x)") 3793 /// or class type construction ("ClassType(x,y,z)") 3794 /// or creation of a value-initialized type ("int()"). 3795 ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep, 3796 SourceLocation LParenLoc, 3797 MultiExprArg Exprs, 3798 SourceLocation RParenLoc); 3799 3800 ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, 3801 SourceLocation LParenLoc, 3802 MultiExprArg Exprs, 3803 SourceLocation RParenLoc); 3804 3805 /// ActOnCXXNew - Parsed a C++ 'new' expression. 3806 ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, 3807 SourceLocation PlacementLParen, 3808 MultiExprArg PlacementArgs, 3809 SourceLocation PlacementRParen, 3810 SourceRange TypeIdParens, Declarator &D, 3811 Expr *Initializer); 3812 ExprResult BuildCXXNew(SourceRange Range, bool UseGlobal, 3813 SourceLocation PlacementLParen, 3814 MultiExprArg PlacementArgs, 3815 SourceLocation PlacementRParen, 3816 SourceRange TypeIdParens, 3817 QualType AllocType, 3818 TypeSourceInfo *AllocTypeInfo, 3819 Expr *ArraySize, 3820 SourceRange DirectInitRange, 3821 Expr *Initializer, 3822 bool TypeMayContainAuto = true); 3823 3824 bool CheckAllocatedType(QualType AllocType, SourceLocation Loc, 3825 SourceRange R); 3826 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, 3827 bool UseGlobal, QualType AllocType, bool IsArray, 3828 Expr **PlaceArgs, unsigned NumPlaceArgs, 3829 FunctionDecl *&OperatorNew, 3830 FunctionDecl *&OperatorDelete); 3831 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range, 3832 DeclarationName Name, Expr** Args, 3833 unsigned NumArgs, DeclContext *Ctx, 3834 bool AllowMissing, FunctionDecl *&Operator, 3835 bool Diagnose = true); 3836 void DeclareGlobalNewDelete(); 3837 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, 3838 QualType Argument, 3839 bool addMallocAttr = false); 3840 3841 bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, 3842 DeclarationName Name, FunctionDecl* &Operator, 3843 bool Diagnose = true); 3844 3845 /// ActOnCXXDelete - Parsed a C++ 'delete' expression 3846 ExprResult ActOnCXXDelete(SourceLocation StartLoc, 3847 bool UseGlobal, bool ArrayForm, 3848 Expr *Operand); 3849 3850 DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D); 3851 ExprResult CheckConditionVariable(VarDecl *ConditionVar, 3852 SourceLocation StmtLoc, 3853 bool ConvertToBoolean); 3854 3855 ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen, 3856 Expr *Operand, SourceLocation RParen); 3857 ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, 3858 SourceLocation RParen); 3859 3860 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support 3861 /// pseudo-functions. 3862 ExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT, 3863 SourceLocation KWLoc, 3864 ParsedType Ty, 3865 SourceLocation RParen); 3866 3867 ExprResult BuildUnaryTypeTrait(UnaryTypeTrait OTT, 3868 SourceLocation KWLoc, 3869 TypeSourceInfo *T, 3870 SourceLocation RParen); 3871 3872 /// ActOnBinaryTypeTrait - Parsed one of the bianry type trait support 3873 /// pseudo-functions. 3874 ExprResult ActOnBinaryTypeTrait(BinaryTypeTrait OTT, 3875 SourceLocation KWLoc, 3876 ParsedType LhsTy, 3877 ParsedType RhsTy, 3878 SourceLocation RParen); 3879 3880 ExprResult BuildBinaryTypeTrait(BinaryTypeTrait BTT, 3881 SourceLocation KWLoc, 3882 TypeSourceInfo *LhsT, 3883 TypeSourceInfo *RhsT, 3884 SourceLocation RParen); 3885 3886 /// \brief Parsed one of the type trait support pseudo-functions. 3887 ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc, 3888 ArrayRef<ParsedType> Args, 3889 SourceLocation RParenLoc); 3890 ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, 3891 ArrayRef<TypeSourceInfo *> Args, 3892 SourceLocation RParenLoc); 3893 3894 /// ActOnArrayTypeTrait - Parsed one of the bianry type trait support 3895 /// pseudo-functions. 3896 ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT, 3897 SourceLocation KWLoc, 3898 ParsedType LhsTy, 3899 Expr *DimExpr, 3900 SourceLocation RParen); 3901 3902 ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, 3903 SourceLocation KWLoc, 3904 TypeSourceInfo *TSInfo, 3905 Expr *DimExpr, 3906 SourceLocation RParen); 3907 3908 /// ActOnExpressionTrait - Parsed one of the unary type trait support 3909 /// pseudo-functions. 3910 ExprResult ActOnExpressionTrait(ExpressionTrait OET, 3911 SourceLocation KWLoc, 3912 Expr *Queried, 3913 SourceLocation RParen); 3914 3915 ExprResult BuildExpressionTrait(ExpressionTrait OET, 3916 SourceLocation KWLoc, 3917 Expr *Queried, 3918 SourceLocation RParen); 3919 3920 ExprResult ActOnStartCXXMemberReference(Scope *S, 3921 Expr *Base, 3922 SourceLocation OpLoc, 3923 tok::TokenKind OpKind, 3924 ParsedType &ObjectType, 3925 bool &MayBePseudoDestructor); 3926 3927 ExprResult DiagnoseDtorReference(SourceLocation NameLoc, Expr *MemExpr); 3928 3929 ExprResult BuildPseudoDestructorExpr(Expr *Base, 3930 SourceLocation OpLoc, 3931 tok::TokenKind OpKind, 3932 const CXXScopeSpec &SS, 3933 TypeSourceInfo *ScopeType, 3934 SourceLocation CCLoc, 3935 SourceLocation TildeLoc, 3936 PseudoDestructorTypeStorage DestroyedType, 3937 bool HasTrailingLParen); 3938 3939 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, 3940 SourceLocation OpLoc, 3941 tok::TokenKind OpKind, 3942 CXXScopeSpec &SS, 3943 UnqualifiedId &FirstTypeName, 3944 SourceLocation CCLoc, 3945 SourceLocation TildeLoc, 3946 UnqualifiedId &SecondTypeName, 3947 bool HasTrailingLParen); 3948 3949 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, 3950 SourceLocation OpLoc, 3951 tok::TokenKind OpKind, 3952 SourceLocation TildeLoc, 3953 const DeclSpec& DS, 3954 bool HasTrailingLParen); 3955 3956 /// MaybeCreateExprWithCleanups - If the current full-expression 3957 /// requires any cleanups, surround it with a ExprWithCleanups node. 3958 /// Otherwise, just returns the passed-in expression. 3959 Expr *MaybeCreateExprWithCleanups(Expr *SubExpr); 3960 Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt); 3961 ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr); 3962 3963 ExprResult ActOnFinishFullExpr(Expr *Expr) { 3964 return ActOnFinishFullExpr(Expr, Expr ? Expr->getExprLoc() 3965 : SourceLocation()); 3966 } 3967 ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC, 3968 bool DiscardedValue = false); 3969 StmtResult ActOnFinishFullStmt(Stmt *Stmt); 3970 3971 // Marks SS invalid if it represents an incomplete type. 3972 bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC); 3973 3974 DeclContext *computeDeclContext(QualType T); 3975 DeclContext *computeDeclContext(const CXXScopeSpec &SS, 3976 bool EnteringContext = false); 3977 bool isDependentScopeSpecifier(const CXXScopeSpec &SS); 3978 CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS); 3979 bool isUnknownSpecialization(const CXXScopeSpec &SS); 3980 3981 /// \brief The parser has parsed a global nested-name-specifier '::'. 3982 /// 3983 /// \param S The scope in which this nested-name-specifier occurs. 3984 /// 3985 /// \param CCLoc The location of the '::'. 3986 /// 3987 /// \param SS The nested-name-specifier, which will be updated in-place 3988 /// to reflect the parsed nested-name-specifier. 3989 /// 3990 /// \returns true if an error occurred, false otherwise. 3991 bool ActOnCXXGlobalScopeSpecifier(Scope *S, SourceLocation CCLoc, 3992 CXXScopeSpec &SS); 3993 3994 bool isAcceptableNestedNameSpecifier(NamedDecl *SD); 3995 NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS); 3996 3997 bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS, 3998 SourceLocation IdLoc, 3999 IdentifierInfo &II, 4000 ParsedType ObjectType); 4001 4002 bool BuildCXXNestedNameSpecifier(Scope *S, 4003 IdentifierInfo &Identifier, 4004 SourceLocation IdentifierLoc, 4005 SourceLocation CCLoc, 4006 QualType ObjectType, 4007 bool EnteringContext, 4008 CXXScopeSpec &SS, 4009 NamedDecl *ScopeLookupResult, 4010 bool ErrorRecoveryLookup); 4011 4012 /// \brief The parser has parsed a nested-name-specifier 'identifier::'. 4013 /// 4014 /// \param S The scope in which this nested-name-specifier occurs. 4015 /// 4016 /// \param Identifier The identifier preceding the '::'. 4017 /// 4018 /// \param IdentifierLoc The location of the identifier. 4019 /// 4020 /// \param CCLoc The location of the '::'. 4021 /// 4022 /// \param ObjectType The type of the object, if we're parsing 4023 /// nested-name-specifier in a member access expression. 4024 /// 4025 /// \param EnteringContext Whether we're entering the context nominated by 4026 /// this nested-name-specifier. 4027 /// 4028 /// \param SS The nested-name-specifier, which is both an input 4029 /// parameter (the nested-name-specifier before this type) and an 4030 /// output parameter (containing the full nested-name-specifier, 4031 /// including this new type). 4032 /// 4033 /// \returns true if an error occurred, false otherwise. 4034 bool ActOnCXXNestedNameSpecifier(Scope *S, 4035 IdentifierInfo &Identifier, 4036 SourceLocation IdentifierLoc, 4037 SourceLocation CCLoc, 4038 ParsedType ObjectType, 4039 bool EnteringContext, 4040 CXXScopeSpec &SS); 4041 4042 ExprResult ActOnDecltypeExpression(Expr *E); 4043 4044 bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, 4045 const DeclSpec &DS, 4046 SourceLocation ColonColonLoc); 4047 4048 bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, 4049 IdentifierInfo &Identifier, 4050 SourceLocation IdentifierLoc, 4051 SourceLocation ColonLoc, 4052 ParsedType ObjectType, 4053 bool EnteringContext); 4054 4055 /// \brief The parser has parsed a nested-name-specifier 4056 /// 'template[opt] template-name < template-args >::'. 4057 /// 4058 /// \param S The scope in which this nested-name-specifier occurs. 4059 /// 4060 /// \param SS The nested-name-specifier, which is both an input 4061 /// parameter (the nested-name-specifier before this type) and an 4062 /// output parameter (containing the full nested-name-specifier, 4063 /// including this new type). 4064 /// 4065 /// \param TemplateKWLoc the location of the 'template' keyword, if any. 4066 /// \param TemplateName the template name. 4067 /// \param TemplateNameLoc The location of the template name. 4068 /// \param LAngleLoc The location of the opening angle bracket ('<'). 4069 /// \param TemplateArgs The template arguments. 4070 /// \param RAngleLoc The location of the closing angle bracket ('>'). 4071 /// \param CCLoc The location of the '::'. 4072 /// 4073 /// \param EnteringContext Whether we're entering the context of the 4074 /// nested-name-specifier. 4075 /// 4076 /// 4077 /// \returns true if an error occurred, false otherwise. 4078 bool ActOnCXXNestedNameSpecifier(Scope *S, 4079 CXXScopeSpec &SS, 4080 SourceLocation TemplateKWLoc, 4081 TemplateTy TemplateName, 4082 SourceLocation TemplateNameLoc, 4083 SourceLocation LAngleLoc, 4084 ASTTemplateArgsPtr TemplateArgs, 4085 SourceLocation RAngleLoc, 4086 SourceLocation CCLoc, 4087 bool EnteringContext); 4088 4089 /// \brief Given a C++ nested-name-specifier, produce an annotation value 4090 /// that the parser can use later to reconstruct the given 4091 /// nested-name-specifier. 4092 /// 4093 /// \param SS A nested-name-specifier. 4094 /// 4095 /// \returns A pointer containing all of the information in the 4096 /// nested-name-specifier \p SS. 4097 void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS); 4098 4099 /// \brief Given an annotation pointer for a nested-name-specifier, restore 4100 /// the nested-name-specifier structure. 4101 /// 4102 /// \param Annotation The annotation pointer, produced by 4103 /// \c SaveNestedNameSpecifierAnnotation(). 4104 /// 4105 /// \param AnnotationRange The source range corresponding to the annotation. 4106 /// 4107 /// \param SS The nested-name-specifier that will be updated with the contents 4108 /// of the annotation pointer. 4109 void RestoreNestedNameSpecifierAnnotation(void *Annotation, 4110 SourceRange AnnotationRange, 4111 CXXScopeSpec &SS); 4112 4113 bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); 4114 4115 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global 4116 /// scope or nested-name-specifier) is parsed, part of a declarator-id. 4117 /// After this method is called, according to [C++ 3.4.3p3], names should be 4118 /// looked up in the declarator-id's scope, until the declarator is parsed and 4119 /// ActOnCXXExitDeclaratorScope is called. 4120 /// The 'SS' should be a non-empty valid CXXScopeSpec. 4121 bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS); 4122 4123 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously 4124 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same 4125 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. 4126 /// Used to indicate that names should revert to being looked up in the 4127 /// defining scope. 4128 void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); 4129 4130 /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an 4131 /// initializer for the declaration 'Dcl'. 4132 /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a 4133 /// static data member of class X, names should be looked up in the scope of 4134 /// class X. 4135 void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl); 4136 4137 /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an 4138 /// initializer for the declaration 'Dcl'. 4139 void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl); 4140 4141 /// \brief Create a new lambda closure type. 4142 CXXRecordDecl *createLambdaClosureType(SourceRange IntroducerRange, 4143 TypeSourceInfo *Info, 4144 bool KnownDependent); 4145 4146 /// \brief Start the definition of a lambda expression. 4147 CXXMethodDecl *startLambdaDefinition(CXXRecordDecl *Class, 4148 SourceRange IntroducerRange, 4149 TypeSourceInfo *MethodType, 4150 SourceLocation EndLoc, 4151 ArrayRef<ParmVarDecl *> Params); 4152 4153 /// \brief Introduce the scope for a lambda expression. 4154 sema::LambdaScopeInfo *enterLambdaScope(CXXMethodDecl *CallOperator, 4155 SourceRange IntroducerRange, 4156 LambdaCaptureDefault CaptureDefault, 4157 bool ExplicitParams, 4158 bool ExplicitResultType, 4159 bool Mutable); 4160 4161 /// \brief Note that we have finished the explicit captures for the 4162 /// given lambda. 4163 void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI); 4164 4165 /// \brief Introduce the lambda parameters into scope. 4166 void addLambdaParameters(CXXMethodDecl *CallOperator, Scope *CurScope); 4167 4168 /// \brief Deduce a block or lambda's return type based on the return 4169 /// statements present in the body. 4170 void deduceClosureReturnType(sema::CapturingScopeInfo &CSI); 4171 4172 /// ActOnStartOfLambdaDefinition - This is called just before we start 4173 /// parsing the body of a lambda; it analyzes the explicit captures and 4174 /// arguments, and sets up various data-structures for the body of the 4175 /// lambda. 4176 void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, 4177 Declarator &ParamInfo, Scope *CurScope); 4178 4179 /// ActOnLambdaError - If there is an error parsing a lambda, this callback 4180 /// is invoked to pop the information about the lambda. 4181 void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope, 4182 bool IsInstantiation = false); 4183 4184 /// ActOnLambdaExpr - This is called when the body of a lambda expression 4185 /// was successfully completed. 4186 ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body, 4187 Scope *CurScope, 4188 bool IsInstantiation = false); 4189 4190 /// \brief Define the "body" of the conversion from a lambda object to a 4191 /// function pointer. 4192 /// 4193 /// This routine doesn't actually define a sensible body; rather, it fills 4194 /// in the initialization expression needed to copy the lambda object into 4195 /// the block, and IR generation actually generates the real body of the 4196 /// block pointer conversion. 4197 void DefineImplicitLambdaToFunctionPointerConversion( 4198 SourceLocation CurrentLoc, CXXConversionDecl *Conv); 4199 4200 /// \brief Define the "body" of the conversion from a lambda object to a 4201 /// block pointer. 4202 /// 4203 /// This routine doesn't actually define a sensible body; rather, it fills 4204 /// in the initialization expression needed to copy the lambda object into 4205 /// the block, and IR generation actually generates the real body of the 4206 /// block pointer conversion. 4207 void DefineImplicitLambdaToBlockPointerConversion(SourceLocation CurrentLoc, 4208 CXXConversionDecl *Conv); 4209 4210 ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, 4211 SourceLocation ConvLocation, 4212 CXXConversionDecl *Conv, 4213 Expr *Src); 4214 4215 // ParseObjCStringLiteral - Parse Objective-C string literals. 4216 ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, 4217 Expr **Strings, 4218 unsigned NumStrings); 4219 4220 ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S); 4221 4222 /// BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the 4223 /// numeric literal expression. Type of the expression will be "NSNumber *" 4224 /// or "id" if NSNumber is unavailable. 4225 ExprResult BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number); 4226 ExprResult ActOnObjCBoolLiteral(SourceLocation AtLoc, SourceLocation ValueLoc, 4227 bool Value); 4228 ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements); 4229 4230 /// BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the 4231 /// '@' prefixed parenthesized expression. The type of the expression will 4232 /// either be "NSNumber *" or "NSString *" depending on the type of 4233 /// ValueType, which is allowed to be a built-in numeric type or 4234 /// "char *" or "const char *". 4235 ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr); 4236 4237 ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, 4238 Expr *IndexExpr, 4239 ObjCMethodDecl *getterMethod, 4240 ObjCMethodDecl *setterMethod); 4241 4242 ExprResult BuildObjCDictionaryLiteral(SourceRange SR, 4243 ObjCDictionaryElement *Elements, 4244 unsigned NumElements); 4245 4246 ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, 4247 TypeSourceInfo *EncodedTypeInfo, 4248 SourceLocation RParenLoc); 4249 ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, 4250 CXXConversionDecl *Method, 4251 bool HadMultipleCandidates); 4252 4253 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, 4254 SourceLocation EncodeLoc, 4255 SourceLocation LParenLoc, 4256 ParsedType Ty, 4257 SourceLocation RParenLoc); 4258 4259 /// ParseObjCSelectorExpression - Build selector expression for \@selector 4260 ExprResult ParseObjCSelectorExpression(Selector Sel, 4261 SourceLocation AtLoc, 4262 SourceLocation SelLoc, 4263 SourceLocation LParenLoc, 4264 SourceLocation RParenLoc); 4265 4266 /// ParseObjCProtocolExpression - Build protocol expression for \@protocol 4267 ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName, 4268 SourceLocation AtLoc, 4269 SourceLocation ProtoLoc, 4270 SourceLocation LParenLoc, 4271 SourceLocation ProtoIdLoc, 4272 SourceLocation RParenLoc); 4273 4274 //===--------------------------------------------------------------------===// 4275 // C++ Declarations 4276 // 4277 Decl *ActOnStartLinkageSpecification(Scope *S, 4278 SourceLocation ExternLoc, 4279 SourceLocation LangLoc, 4280 StringRef Lang, 4281 SourceLocation LBraceLoc); 4282 Decl *ActOnFinishLinkageSpecification(Scope *S, 4283 Decl *LinkageSpec, 4284 SourceLocation RBraceLoc); 4285 4286 4287 //===--------------------------------------------------------------------===// 4288 // C++ Classes 4289 // 4290 bool isCurrentClassName(const IdentifierInfo &II, Scope *S, 4291 const CXXScopeSpec *SS = 0); 4292 4293 bool ActOnAccessSpecifier(AccessSpecifier Access, 4294 SourceLocation ASLoc, 4295 SourceLocation ColonLoc, 4296 AttributeList *Attrs = 0); 4297 4298 NamedDecl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, 4299 Declarator &D, 4300 MultiTemplateParamsArg TemplateParameterLists, 4301 Expr *BitfieldWidth, const VirtSpecifiers &VS, 4302 InClassInitStyle InitStyle); 4303 void ActOnCXXInClassMemberInitializer(Decl *VarDecl, SourceLocation EqualLoc, 4304 Expr *Init); 4305 4306 MemInitResult ActOnMemInitializer(Decl *ConstructorD, 4307 Scope *S, 4308 CXXScopeSpec &SS, 4309 IdentifierInfo *MemberOrBase, 4310 ParsedType TemplateTypeTy, 4311 const DeclSpec &DS, 4312 SourceLocation IdLoc, 4313 SourceLocation LParenLoc, 4314 Expr **Args, unsigned NumArgs, 4315 SourceLocation RParenLoc, 4316 SourceLocation EllipsisLoc); 4317 4318 MemInitResult ActOnMemInitializer(Decl *ConstructorD, 4319 Scope *S, 4320 CXXScopeSpec &SS, 4321 IdentifierInfo *MemberOrBase, 4322 ParsedType TemplateTypeTy, 4323 const DeclSpec &DS, 4324 SourceLocation IdLoc, 4325 Expr *InitList, 4326 SourceLocation EllipsisLoc); 4327 4328 MemInitResult BuildMemInitializer(Decl *ConstructorD, 4329 Scope *S, 4330 CXXScopeSpec &SS, 4331 IdentifierInfo *MemberOrBase, 4332 ParsedType TemplateTypeTy, 4333 const DeclSpec &DS, 4334 SourceLocation IdLoc, 4335 Expr *Init, 4336 SourceLocation EllipsisLoc); 4337 4338 MemInitResult BuildMemberInitializer(ValueDecl *Member, 4339 Expr *Init, 4340 SourceLocation IdLoc); 4341 4342 MemInitResult BuildBaseInitializer(QualType BaseType, 4343 TypeSourceInfo *BaseTInfo, 4344 Expr *Init, 4345 CXXRecordDecl *ClassDecl, 4346 SourceLocation EllipsisLoc); 4347 4348 MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo, 4349 Expr *Init, 4350 CXXRecordDecl *ClassDecl); 4351 4352 bool SetDelegatingInitializer(CXXConstructorDecl *Constructor, 4353 CXXCtorInitializer *Initializer); 4354 4355 bool SetCtorInitializers(CXXConstructorDecl *Constructor, 4356 CXXCtorInitializer **Initializers, 4357 unsigned NumInitializers, bool AnyErrors); 4358 4359 void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation); 4360 4361 4362 /// MarkBaseAndMemberDestructorsReferenced - Given a record decl, 4363 /// mark all the non-trivial destructors of its members and bases as 4364 /// referenced. 4365 void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc, 4366 CXXRecordDecl *Record); 4367 4368 /// \brief The list of classes whose vtables have been used within 4369 /// this translation unit, and the source locations at which the 4370 /// first use occurred. 4371 typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse; 4372 4373 /// \brief The list of vtables that are required but have not yet been 4374 /// materialized. 4375 SmallVector<VTableUse, 16> VTableUses; 4376 4377 /// \brief The set of classes whose vtables have been used within 4378 /// this translation unit, and a bit that will be true if the vtable is 4379 /// required to be emitted (otherwise, it should be emitted only if needed 4380 /// by code generation). 4381 llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed; 4382 4383 /// \brief Load any externally-stored vtable uses. 4384 void LoadExternalVTableUses(); 4385 4386 typedef LazyVector<CXXRecordDecl *, ExternalSemaSource, 4387 &ExternalSemaSource::ReadDynamicClasses, 2, 2> 4388 DynamicClassesType; 4389 4390 /// \brief A list of all of the dynamic classes in this translation 4391 /// unit. 4392 DynamicClassesType DynamicClasses; 4393 4394 /// \brief Note that the vtable for the given class was used at the 4395 /// given location. 4396 void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, 4397 bool DefinitionRequired = false); 4398 4399 /// \brief Mark the exception specifications of all virtual member functions 4400 /// in the given class as needed. 4401 void MarkVirtualMemberExceptionSpecsNeeded(SourceLocation Loc, 4402 const CXXRecordDecl *RD); 4403 4404 /// MarkVirtualMembersReferenced - Will mark all members of the given 4405 /// CXXRecordDecl referenced. 4406 void MarkVirtualMembersReferenced(SourceLocation Loc, 4407 const CXXRecordDecl *RD); 4408 4409 /// \brief Define all of the vtables that have been used in this 4410 /// translation unit and reference any virtual members used by those 4411 /// vtables. 4412 /// 4413 /// \returns true if any work was done, false otherwise. 4414 bool DefineUsedVTables(); 4415 4416 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); 4417 4418 void ActOnMemInitializers(Decl *ConstructorDecl, 4419 SourceLocation ColonLoc, 4420 CXXCtorInitializer **MemInits, 4421 unsigned NumMemInits, 4422 bool AnyErrors); 4423 4424 void CheckCompletedCXXClass(CXXRecordDecl *Record); 4425 void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, 4426 Decl *TagDecl, 4427 SourceLocation LBrac, 4428 SourceLocation RBrac, 4429 AttributeList *AttrList); 4430 void ActOnFinishCXXMemberDecls(); 4431 4432 void ActOnReenterTemplateScope(Scope *S, Decl *Template); 4433 void ActOnReenterDeclaratorTemplateScope(Scope *S, DeclaratorDecl *D); 4434 void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record); 4435 void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 4436 void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param); 4437 void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record); 4438 void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 4439 void ActOnFinishDelayedMemberInitializers(Decl *Record); 4440 void MarkAsLateParsedTemplate(FunctionDecl *FD, bool Flag = true); 4441 bool IsInsideALocalClassWithinATemplateFunction(); 4442 4443 Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, 4444 Expr *AssertExpr, 4445 Expr *AssertMessageExpr, 4446 SourceLocation RParenLoc); 4447 Decl *BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc, 4448 Expr *AssertExpr, 4449 StringLiteral *AssertMessageExpr, 4450 SourceLocation RParenLoc, 4451 bool Failed); 4452 4453 FriendDecl *CheckFriendTypeDecl(SourceLocation LocStart, 4454 SourceLocation FriendLoc, 4455 TypeSourceInfo *TSInfo); 4456 Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS, 4457 MultiTemplateParamsArg TemplateParams); 4458 NamedDecl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, 4459 MultiTemplateParamsArg TemplateParams); 4460 4461 QualType CheckConstructorDeclarator(Declarator &D, QualType R, 4462 StorageClass& SC); 4463 void CheckConstructor(CXXConstructorDecl *Constructor); 4464 QualType CheckDestructorDeclarator(Declarator &D, QualType R, 4465 StorageClass& SC); 4466 bool CheckDestructor(CXXDestructorDecl *Destructor); 4467 void CheckConversionDeclarator(Declarator &D, QualType &R, 4468 StorageClass& SC); 4469 Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion); 4470 4471 void CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD); 4472 void CheckExplicitlyDefaultedMemberExceptionSpec(CXXMethodDecl *MD, 4473 const FunctionProtoType *T); 4474 void CheckDelayedExplicitlyDefaultedMemberExceptionSpecs(); 4475 4476 //===--------------------------------------------------------------------===// 4477 // C++ Derived Classes 4478 // 4479 4480 /// ActOnBaseSpecifier - Parsed a base specifier 4481 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, 4482 SourceRange SpecifierRange, 4483 bool Virtual, AccessSpecifier Access, 4484 TypeSourceInfo *TInfo, 4485 SourceLocation EllipsisLoc); 4486 4487 BaseResult ActOnBaseSpecifier(Decl *classdecl, 4488 SourceRange SpecifierRange, 4489 bool Virtual, AccessSpecifier Access, 4490 ParsedType basetype, 4491 SourceLocation BaseLoc, 4492 SourceLocation EllipsisLoc); 4493 4494 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases, 4495 unsigned NumBases); 4496 void ActOnBaseSpecifiers(Decl *ClassDecl, CXXBaseSpecifier **Bases, 4497 unsigned NumBases); 4498 4499 bool IsDerivedFrom(QualType Derived, QualType Base); 4500 bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths); 4501 4502 // FIXME: I don't like this name. 4503 void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath); 4504 4505 bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath); 4506 4507 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 4508 SourceLocation Loc, SourceRange Range, 4509 CXXCastPath *BasePath = 0, 4510 bool IgnoreAccess = false); 4511 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 4512 unsigned InaccessibleBaseID, 4513 unsigned AmbigiousBaseConvID, 4514 SourceLocation Loc, SourceRange Range, 4515 DeclarationName Name, 4516 CXXCastPath *BasePath); 4517 4518 std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths); 4519 4520 bool CheckOverridingFunctionAttributes(const CXXMethodDecl *New, 4521 const CXXMethodDecl *Old); 4522 4523 /// CheckOverridingFunctionReturnType - Checks whether the return types are 4524 /// covariant, according to C++ [class.virtual]p5. 4525 bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, 4526 const CXXMethodDecl *Old); 4527 4528 /// CheckOverridingFunctionExceptionSpec - Checks whether the exception 4529 /// spec is a subset of base spec. 4530 bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, 4531 const CXXMethodDecl *Old); 4532 4533 bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange); 4534 4535 /// CheckOverrideControl - Check C++11 override control semantics. 4536 void CheckOverrideControl(Decl *D); 4537 4538 /// CheckForFunctionMarkedFinal - Checks whether a virtual member function 4539 /// overrides a virtual member function marked 'final', according to 4540 /// C++11 [class.virtual]p4. 4541 bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New, 4542 const CXXMethodDecl *Old); 4543 4544 4545 //===--------------------------------------------------------------------===// 4546 // C++ Access Control 4547 // 4548 4549 enum AccessResult { 4550 AR_accessible, 4551 AR_inaccessible, 4552 AR_dependent, 4553 AR_delayed 4554 }; 4555 4556 bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, 4557 NamedDecl *PrevMemberDecl, 4558 AccessSpecifier LexicalAS); 4559 4560 AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E, 4561 DeclAccessPair FoundDecl); 4562 AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E, 4563 DeclAccessPair FoundDecl); 4564 AccessResult CheckAllocationAccess(SourceLocation OperatorLoc, 4565 SourceRange PlacementRange, 4566 CXXRecordDecl *NamingClass, 4567 DeclAccessPair FoundDecl, 4568 bool Diagnose = true); 4569 AccessResult CheckConstructorAccess(SourceLocation Loc, 4570 CXXConstructorDecl *D, 4571 const InitializedEntity &Entity, 4572 AccessSpecifier Access, 4573 bool IsCopyBindingRefToTemp = false); 4574 AccessResult CheckConstructorAccess(SourceLocation Loc, 4575 CXXConstructorDecl *D, 4576 const InitializedEntity &Entity, 4577 AccessSpecifier Access, 4578 const PartialDiagnostic &PDiag); 4579 AccessResult CheckDestructorAccess(SourceLocation Loc, 4580 CXXDestructorDecl *Dtor, 4581 const PartialDiagnostic &PDiag, 4582 QualType objectType = QualType()); 4583 AccessResult CheckFriendAccess(NamedDecl *D); 4584 AccessResult CheckMemberOperatorAccess(SourceLocation Loc, 4585 Expr *ObjectExpr, 4586 Expr *ArgExpr, 4587 DeclAccessPair FoundDecl); 4588 AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, 4589 DeclAccessPair FoundDecl); 4590 AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, 4591 QualType Base, QualType Derived, 4592 const CXXBasePath &Path, 4593 unsigned DiagID, 4594 bool ForceCheck = false, 4595 bool ForceUnprivileged = false); 4596 void CheckLookupAccess(const LookupResult &R); 4597 bool IsSimplyAccessible(NamedDecl *decl, DeclContext *Ctx); 4598 bool isSpecialMemberAccessibleForDeletion(CXXMethodDecl *decl, 4599 AccessSpecifier access, 4600 QualType objectType); 4601 4602 void HandleDependentAccessCheck(const DependentDiagnostic &DD, 4603 const MultiLevelTemplateArgumentList &TemplateArgs); 4604 void PerformDependentDiagnostics(const DeclContext *Pattern, 4605 const MultiLevelTemplateArgumentList &TemplateArgs); 4606 4607 void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); 4608 4609 /// \brief When true, access checking violations are treated as SFINAE 4610 /// failures rather than hard errors. 4611 bool AccessCheckingSFINAE; 4612 4613 enum AbstractDiagSelID { 4614 AbstractNone = -1, 4615 AbstractReturnType, 4616 AbstractParamType, 4617 AbstractVariableType, 4618 AbstractFieldType, 4619 AbstractIvarType, 4620 AbstractArrayType 4621 }; 4622 4623 bool RequireNonAbstractType(SourceLocation Loc, QualType T, 4624 TypeDiagnoser &Diagnoser); 4625 template<typename T1> 4626 bool RequireNonAbstractType(SourceLocation Loc, QualType T, 4627 unsigned DiagID, 4628 const T1 &Arg1) { 4629 BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1); 4630 return RequireNonAbstractType(Loc, T, Diagnoser); 4631 } 4632 4633 template<typename T1, typename T2> 4634 bool RequireNonAbstractType(SourceLocation Loc, QualType T, 4635 unsigned DiagID, 4636 const T1 &Arg1, const T2 &Arg2) { 4637 BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2); 4638 return RequireNonAbstractType(Loc, T, Diagnoser); 4639 } 4640 4641 template<typename T1, typename T2, typename T3> 4642 bool RequireNonAbstractType(SourceLocation Loc, QualType T, 4643 unsigned DiagID, 4644 const T1 &Arg1, const T2 &Arg2, const T3 &Arg3) { 4645 BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2, Arg3); 4646 return RequireNonAbstractType(Loc, T, Diagnoser); 4647 } 4648 4649 void DiagnoseAbstractType(const CXXRecordDecl *RD); 4650 4651 bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, 4652 AbstractDiagSelID SelID = AbstractNone); 4653 4654 //===--------------------------------------------------------------------===// 4655 // C++ Overloaded Operators [C++ 13.5] 4656 // 4657 4658 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); 4659 4660 bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl); 4661 4662 //===--------------------------------------------------------------------===// 4663 // C++ Templates [C++ 14] 4664 // 4665 void FilterAcceptableTemplateNames(LookupResult &R, 4666 bool AllowFunctionTemplates = true); 4667 bool hasAnyAcceptableTemplateNames(LookupResult &R, 4668 bool AllowFunctionTemplates = true); 4669 4670 void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS, 4671 QualType ObjectType, bool EnteringContext, 4672 bool &MemberOfUnknownSpecialization); 4673 4674 TemplateNameKind isTemplateName(Scope *S, 4675 CXXScopeSpec &SS, 4676 bool hasTemplateKeyword, 4677 UnqualifiedId &Name, 4678 ParsedType ObjectType, 4679 bool EnteringContext, 4680 TemplateTy &Template, 4681 bool &MemberOfUnknownSpecialization); 4682 4683 bool DiagnoseUnknownTemplateName(const IdentifierInfo &II, 4684 SourceLocation IILoc, 4685 Scope *S, 4686 const CXXScopeSpec *SS, 4687 TemplateTy &SuggestedTemplate, 4688 TemplateNameKind &SuggestedKind); 4689 4690 void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); 4691 TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl); 4692 4693 Decl *ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis, 4694 SourceLocation EllipsisLoc, 4695 SourceLocation KeyLoc, 4696 IdentifierInfo *ParamName, 4697 SourceLocation ParamNameLoc, 4698 unsigned Depth, unsigned Position, 4699 SourceLocation EqualLoc, 4700 ParsedType DefaultArg); 4701 4702 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); 4703 Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, 4704 unsigned Depth, 4705 unsigned Position, 4706 SourceLocation EqualLoc, 4707 Expr *DefaultArg); 4708 Decl *ActOnTemplateTemplateParameter(Scope *S, 4709 SourceLocation TmpLoc, 4710 TemplateParameterList *Params, 4711 SourceLocation EllipsisLoc, 4712 IdentifierInfo *ParamName, 4713 SourceLocation ParamNameLoc, 4714 unsigned Depth, 4715 unsigned Position, 4716 SourceLocation EqualLoc, 4717 ParsedTemplateArgument DefaultArg); 4718 4719 TemplateParameterList * 4720 ActOnTemplateParameterList(unsigned Depth, 4721 SourceLocation ExportLoc, 4722 SourceLocation TemplateLoc, 4723 SourceLocation LAngleLoc, 4724 Decl **Params, unsigned NumParams, 4725 SourceLocation RAngleLoc); 4726 4727 /// \brief The context in which we are checking a template parameter 4728 /// list. 4729 enum TemplateParamListContext { 4730 TPC_ClassTemplate, 4731 TPC_FunctionTemplate, 4732 TPC_ClassTemplateMember, 4733 TPC_FriendFunctionTemplate, 4734 TPC_FriendFunctionTemplateDefinition, 4735 TPC_TypeAliasTemplate 4736 }; 4737 4738 bool CheckTemplateParameterList(TemplateParameterList *NewParams, 4739 TemplateParameterList *OldParams, 4740 TemplateParamListContext TPC); 4741 TemplateParameterList * 4742 MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, 4743 SourceLocation DeclLoc, 4744 const CXXScopeSpec &SS, 4745 TemplateParameterList **ParamLists, 4746 unsigned NumParamLists, 4747 bool IsFriend, 4748 bool &IsExplicitSpecialization, 4749 bool &Invalid); 4750 4751 DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, 4752 SourceLocation KWLoc, CXXScopeSpec &SS, 4753 IdentifierInfo *Name, SourceLocation NameLoc, 4754 AttributeList *Attr, 4755 TemplateParameterList *TemplateParams, 4756 AccessSpecifier AS, 4757 SourceLocation ModulePrivateLoc, 4758 unsigned NumOuterTemplateParamLists, 4759 TemplateParameterList **OuterTemplateParamLists); 4760 4761 void translateTemplateArguments(const ASTTemplateArgsPtr &In, 4762 TemplateArgumentListInfo &Out); 4763 4764 void NoteAllFoundTemplates(TemplateName Name); 4765 4766 QualType CheckTemplateIdType(TemplateName Template, 4767 SourceLocation TemplateLoc, 4768 TemplateArgumentListInfo &TemplateArgs); 4769 4770 TypeResult 4771 ActOnTemplateIdType(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, 4772 TemplateTy Template, SourceLocation TemplateLoc, 4773 SourceLocation LAngleLoc, 4774 ASTTemplateArgsPtr TemplateArgs, 4775 SourceLocation RAngleLoc, 4776 bool IsCtorOrDtorName = false); 4777 4778 /// \brief Parsed an elaborated-type-specifier that refers to a template-id, 4779 /// such as \c class T::template apply<U>. 4780 TypeResult ActOnTagTemplateIdType(TagUseKind TUK, 4781 TypeSpecifierType TagSpec, 4782 SourceLocation TagLoc, 4783 CXXScopeSpec &SS, 4784 SourceLocation TemplateKWLoc, 4785 TemplateTy TemplateD, 4786 SourceLocation TemplateLoc, 4787 SourceLocation LAngleLoc, 4788 ASTTemplateArgsPtr TemplateArgsIn, 4789 SourceLocation RAngleLoc); 4790 4791 4792 ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, 4793 SourceLocation TemplateKWLoc, 4794 LookupResult &R, 4795 bool RequiresADL, 4796 const TemplateArgumentListInfo *TemplateArgs); 4797 4798 ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, 4799 SourceLocation TemplateKWLoc, 4800 const DeclarationNameInfo &NameInfo, 4801 const TemplateArgumentListInfo *TemplateArgs); 4802 4803 TemplateNameKind ActOnDependentTemplateName(Scope *S, 4804 CXXScopeSpec &SS, 4805 SourceLocation TemplateKWLoc, 4806 UnqualifiedId &Name, 4807 ParsedType ObjectType, 4808 bool EnteringContext, 4809 TemplateTy &Template); 4810 4811 DeclResult 4812 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK, 4813 SourceLocation KWLoc, 4814 SourceLocation ModulePrivateLoc, 4815 CXXScopeSpec &SS, 4816 TemplateTy Template, 4817 SourceLocation TemplateNameLoc, 4818 SourceLocation LAngleLoc, 4819 ASTTemplateArgsPtr TemplateArgs, 4820 SourceLocation RAngleLoc, 4821 AttributeList *Attr, 4822 MultiTemplateParamsArg TemplateParameterLists); 4823 4824 Decl *ActOnTemplateDeclarator(Scope *S, 4825 MultiTemplateParamsArg TemplateParameterLists, 4826 Declarator &D); 4827 4828 Decl *ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope, 4829 MultiTemplateParamsArg TemplateParameterLists, 4830 Declarator &D); 4831 4832 bool 4833 CheckSpecializationInstantiationRedecl(SourceLocation NewLoc, 4834 TemplateSpecializationKind NewTSK, 4835 NamedDecl *PrevDecl, 4836 TemplateSpecializationKind PrevTSK, 4837 SourceLocation PrevPtOfInstantiation, 4838 bool &SuppressNew); 4839 4840 bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD, 4841 const TemplateArgumentListInfo &ExplicitTemplateArgs, 4842 LookupResult &Previous); 4843 4844 bool CheckFunctionTemplateSpecialization(FunctionDecl *FD, 4845 TemplateArgumentListInfo *ExplicitTemplateArgs, 4846 LookupResult &Previous); 4847 bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous); 4848 4849 DeclResult 4850 ActOnExplicitInstantiation(Scope *S, 4851 SourceLocation ExternLoc, 4852 SourceLocation TemplateLoc, 4853 unsigned TagSpec, 4854 SourceLocation KWLoc, 4855 const CXXScopeSpec &SS, 4856 TemplateTy Template, 4857 SourceLocation TemplateNameLoc, 4858 SourceLocation LAngleLoc, 4859 ASTTemplateArgsPtr TemplateArgs, 4860 SourceLocation RAngleLoc, 4861 AttributeList *Attr); 4862 4863 DeclResult 4864 ActOnExplicitInstantiation(Scope *S, 4865 SourceLocation ExternLoc, 4866 SourceLocation TemplateLoc, 4867 unsigned TagSpec, 4868 SourceLocation KWLoc, 4869 CXXScopeSpec &SS, 4870 IdentifierInfo *Name, 4871 SourceLocation NameLoc, 4872 AttributeList *Attr); 4873 4874 DeclResult ActOnExplicitInstantiation(Scope *S, 4875 SourceLocation ExternLoc, 4876 SourceLocation TemplateLoc, 4877 Declarator &D); 4878 4879 TemplateArgumentLoc 4880 SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, 4881 SourceLocation TemplateLoc, 4882 SourceLocation RAngleLoc, 4883 Decl *Param, 4884 SmallVectorImpl<TemplateArgument> &Converted); 4885 4886 /// \brief Specifies the context in which a particular template 4887 /// argument is being checked. 4888 enum CheckTemplateArgumentKind { 4889 /// \brief The template argument was specified in the code or was 4890 /// instantiated with some deduced template arguments. 4891 CTAK_Specified, 4892 4893 /// \brief The template argument was deduced via template argument 4894 /// deduction. 4895 CTAK_Deduced, 4896 4897 /// \brief The template argument was deduced from an array bound 4898 /// via template argument deduction. 4899 CTAK_DeducedFromArrayBound 4900 }; 4901 4902 bool CheckTemplateArgument(NamedDecl *Param, 4903 const TemplateArgumentLoc &Arg, 4904 NamedDecl *Template, 4905 SourceLocation TemplateLoc, 4906 SourceLocation RAngleLoc, 4907 unsigned ArgumentPackIndex, 4908 SmallVectorImpl<TemplateArgument> &Converted, 4909 CheckTemplateArgumentKind CTAK = CTAK_Specified); 4910 4911 /// \brief Check that the given template arguments can be be provided to 4912 /// the given template, converting the arguments along the way. 4913 /// 4914 /// \param Template The template to which the template arguments are being 4915 /// provided. 4916 /// 4917 /// \param TemplateLoc The location of the template name in the source. 4918 /// 4919 /// \param TemplateArgs The list of template arguments. If the template is 4920 /// a template template parameter, this function may extend the set of 4921 /// template arguments to also include substituted, defaulted template 4922 /// arguments. 4923 /// 4924 /// \param PartialTemplateArgs True if the list of template arguments is 4925 /// intentionally partial, e.g., because we're checking just the initial 4926 /// set of template arguments. 4927 /// 4928 /// \param Converted Will receive the converted, canonicalized template 4929 /// arguments. 4930 /// 4931 /// 4932 /// \param ExpansionIntoFixedList If non-NULL, will be set true to indicate 4933 /// when the template arguments contain a pack expansion that is being 4934 /// expanded into a fixed parameter list. 4935 /// 4936 /// \returns True if an error occurred, false otherwise. 4937 bool CheckTemplateArgumentList(TemplateDecl *Template, 4938 SourceLocation TemplateLoc, 4939 TemplateArgumentListInfo &TemplateArgs, 4940 bool PartialTemplateArgs, 4941 SmallVectorImpl<TemplateArgument> &Converted, 4942 bool *ExpansionIntoFixedList = 0); 4943 4944 bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param, 4945 const TemplateArgumentLoc &Arg, 4946 SmallVectorImpl<TemplateArgument> &Converted); 4947 4948 bool CheckTemplateArgument(TemplateTypeParmDecl *Param, 4949 TypeSourceInfo *Arg); 4950 ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param, 4951 QualType InstantiatedParamType, Expr *Arg, 4952 TemplateArgument &Converted, 4953 CheckTemplateArgumentKind CTAK = CTAK_Specified); 4954 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, 4955 const TemplateArgumentLoc &Arg, 4956 unsigned ArgumentPackIndex); 4957 4958 ExprResult 4959 BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, 4960 QualType ParamType, 4961 SourceLocation Loc); 4962 ExprResult 4963 BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, 4964 SourceLocation Loc); 4965 4966 /// \brief Enumeration describing how template parameter lists are compared 4967 /// for equality. 4968 enum TemplateParameterListEqualKind { 4969 /// \brief We are matching the template parameter lists of two templates 4970 /// that might be redeclarations. 4971 /// 4972 /// \code 4973 /// template<typename T> struct X; 4974 /// template<typename T> struct X; 4975 /// \endcode 4976 TPL_TemplateMatch, 4977 4978 /// \brief We are matching the template parameter lists of two template 4979 /// template parameters as part of matching the template parameter lists 4980 /// of two templates that might be redeclarations. 4981 /// 4982 /// \code 4983 /// template<template<int I> class TT> struct X; 4984 /// template<template<int Value> class Other> struct X; 4985 /// \endcode 4986 TPL_TemplateTemplateParmMatch, 4987 4988 /// \brief We are matching the template parameter lists of a template 4989 /// template argument against the template parameter lists of a template 4990 /// template parameter. 4991 /// 4992 /// \code 4993 /// template<template<int Value> class Metafun> struct X; 4994 /// template<int Value> struct integer_c; 4995 /// X<integer_c> xic; 4996 /// \endcode 4997 TPL_TemplateTemplateArgumentMatch 4998 }; 4999 5000 bool TemplateParameterListsAreEqual(TemplateParameterList *New, 5001 TemplateParameterList *Old, 5002 bool Complain, 5003 TemplateParameterListEqualKind Kind, 5004 SourceLocation TemplateArgLoc 5005 = SourceLocation()); 5006 5007 bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); 5008 5009 /// \brief Called when the parser has parsed a C++ typename 5010 /// specifier, e.g., "typename T::type". 5011 /// 5012 /// \param S The scope in which this typename type occurs. 5013 /// \param TypenameLoc the location of the 'typename' keyword 5014 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 5015 /// \param II the identifier we're retrieving (e.g., 'type' in the example). 5016 /// \param IdLoc the location of the identifier. 5017 TypeResult 5018 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 5019 const CXXScopeSpec &SS, const IdentifierInfo &II, 5020 SourceLocation IdLoc); 5021 5022 /// \brief Called when the parser has parsed a C++ typename 5023 /// specifier that ends in a template-id, e.g., 5024 /// "typename MetaFun::template apply<T1, T2>". 5025 /// 5026 /// \param S The scope in which this typename type occurs. 5027 /// \param TypenameLoc the location of the 'typename' keyword 5028 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 5029 /// \param TemplateLoc the location of the 'template' keyword, if any. 5030 /// \param TemplateName The template name. 5031 /// \param TemplateNameLoc The location of the template name. 5032 /// \param LAngleLoc The location of the opening angle bracket ('<'). 5033 /// \param TemplateArgs The template arguments. 5034 /// \param RAngleLoc The location of the closing angle bracket ('>'). 5035 TypeResult 5036 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 5037 const CXXScopeSpec &SS, 5038 SourceLocation TemplateLoc, 5039 TemplateTy TemplateName, 5040 SourceLocation TemplateNameLoc, 5041 SourceLocation LAngleLoc, 5042 ASTTemplateArgsPtr TemplateArgs, 5043 SourceLocation RAngleLoc); 5044 5045 QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, 5046 SourceLocation KeywordLoc, 5047 NestedNameSpecifierLoc QualifierLoc, 5048 const IdentifierInfo &II, 5049 SourceLocation IILoc); 5050 5051 TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, 5052 SourceLocation Loc, 5053 DeclarationName Name); 5054 bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS); 5055 5056 ExprResult RebuildExprInCurrentInstantiation(Expr *E); 5057 bool RebuildTemplateParamsInCurrentInstantiation( 5058 TemplateParameterList *Params); 5059 5060 std::string 5061 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 5062 const TemplateArgumentList &Args); 5063 5064 std::string 5065 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 5066 const TemplateArgument *Args, 5067 unsigned NumArgs); 5068 5069 //===--------------------------------------------------------------------===// 5070 // C++ Variadic Templates (C++0x [temp.variadic]) 5071 //===--------------------------------------------------------------------===// 5072 5073 /// \brief The context in which an unexpanded parameter pack is 5074 /// being diagnosed. 5075 /// 5076 /// Note that the values of this enumeration line up with the first 5077 /// argument to the \c err_unexpanded_parameter_pack diagnostic. 5078 enum UnexpandedParameterPackContext { 5079 /// \brief An arbitrary expression. 5080 UPPC_Expression = 0, 5081 5082 /// \brief The base type of a class type. 5083 UPPC_BaseType, 5084 5085 /// \brief The type of an arbitrary declaration. 5086 UPPC_DeclarationType, 5087 5088 /// \brief The type of a data member. 5089 UPPC_DataMemberType, 5090 5091 /// \brief The size of a bit-field. 5092 UPPC_BitFieldWidth, 5093 5094 /// \brief The expression in a static assertion. 5095 UPPC_StaticAssertExpression, 5096 5097 /// \brief The fixed underlying type of an enumeration. 5098 UPPC_FixedUnderlyingType, 5099 5100 /// \brief The enumerator value. 5101 UPPC_EnumeratorValue, 5102 5103 /// \brief A using declaration. 5104 UPPC_UsingDeclaration, 5105 5106 /// \brief A friend declaration. 5107 UPPC_FriendDeclaration, 5108 5109 /// \brief A declaration qualifier. 5110 UPPC_DeclarationQualifier, 5111 5112 /// \brief An initializer. 5113 UPPC_Initializer, 5114 5115 /// \brief A default argument. 5116 UPPC_DefaultArgument, 5117 5118 /// \brief The type of a non-type template parameter. 5119 UPPC_NonTypeTemplateParameterType, 5120 5121 /// \brief The type of an exception. 5122 UPPC_ExceptionType, 5123 5124 /// \brief Partial specialization. 5125 UPPC_PartialSpecialization, 5126 5127 /// \brief Microsoft __if_exists. 5128 UPPC_IfExists, 5129 5130 /// \brief Microsoft __if_not_exists. 5131 UPPC_IfNotExists, 5132 5133 /// \brief Lambda expression. 5134 UPPC_Lambda, 5135 5136 /// \brief Block expression, 5137 UPPC_Block 5138}; 5139 5140 /// \brief Diagnose unexpanded parameter packs. 5141 /// 5142 /// \param Loc The location at which we should emit the diagnostic. 5143 /// 5144 /// \param UPPC The context in which we are diagnosing unexpanded 5145 /// parameter packs. 5146 /// 5147 /// \param Unexpanded the set of unexpanded parameter packs. 5148 /// 5149 /// \returns true if an error occurred, false otherwise. 5150 bool DiagnoseUnexpandedParameterPacks(SourceLocation Loc, 5151 UnexpandedParameterPackContext UPPC, 5152 ArrayRef<UnexpandedParameterPack> Unexpanded); 5153 5154 /// \brief If the given type contains an unexpanded parameter pack, 5155 /// diagnose the error. 5156 /// 5157 /// \param Loc The source location where a diagnostc should be emitted. 5158 /// 5159 /// \param T The type that is being checked for unexpanded parameter 5160 /// packs. 5161 /// 5162 /// \returns true if an error occurred, false otherwise. 5163 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, 5164 UnexpandedParameterPackContext UPPC); 5165 5166 /// \brief If the given expression contains an unexpanded parameter 5167 /// pack, diagnose the error. 5168 /// 5169 /// \param E The expression that is being checked for unexpanded 5170 /// parameter packs. 5171 /// 5172 /// \returns true if an error occurred, false otherwise. 5173 bool DiagnoseUnexpandedParameterPack(Expr *E, 5174 UnexpandedParameterPackContext UPPC = UPPC_Expression); 5175 5176 /// \brief If the given nested-name-specifier contains an unexpanded 5177 /// parameter pack, diagnose the error. 5178 /// 5179 /// \param SS The nested-name-specifier that is being checked for 5180 /// unexpanded parameter packs. 5181 /// 5182 /// \returns true if an error occurred, false otherwise. 5183 bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS, 5184 UnexpandedParameterPackContext UPPC); 5185 5186 /// \brief If the given name contains an unexpanded parameter pack, 5187 /// diagnose the error. 5188 /// 5189 /// \param NameInfo The name (with source location information) that 5190 /// is being checked for unexpanded parameter packs. 5191 /// 5192 /// \returns true if an error occurred, false otherwise. 5193 bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo, 5194 UnexpandedParameterPackContext UPPC); 5195 5196 /// \brief If the given template name contains an unexpanded parameter pack, 5197 /// diagnose the error. 5198 /// 5199 /// \param Loc The location of the template name. 5200 /// 5201 /// \param Template The template name that is being checked for unexpanded 5202 /// parameter packs. 5203 /// 5204 /// \returns true if an error occurred, false otherwise. 5205 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, 5206 TemplateName Template, 5207 UnexpandedParameterPackContext UPPC); 5208 5209 /// \brief If the given template argument contains an unexpanded parameter 5210 /// pack, diagnose the error. 5211 /// 5212 /// \param Arg The template argument that is being checked for unexpanded 5213 /// parameter packs. 5214 /// 5215 /// \returns true if an error occurred, false otherwise. 5216 bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg, 5217 UnexpandedParameterPackContext UPPC); 5218 5219 /// \brief Collect the set of unexpanded parameter packs within the given 5220 /// template argument. 5221 /// 5222 /// \param Arg The template argument that will be traversed to find 5223 /// unexpanded parameter packs. 5224 void collectUnexpandedParameterPacks(TemplateArgument Arg, 5225 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 5226 5227 /// \brief Collect the set of unexpanded parameter packs within the given 5228 /// template argument. 5229 /// 5230 /// \param Arg The template argument that will be traversed to find 5231 /// unexpanded parameter packs. 5232 void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg, 5233 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 5234 5235 /// \brief Collect the set of unexpanded parameter packs within the given 5236 /// type. 5237 /// 5238 /// \param T The type that will be traversed to find 5239 /// unexpanded parameter packs. 5240 void collectUnexpandedParameterPacks(QualType T, 5241 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 5242 5243 /// \brief Collect the set of unexpanded parameter packs within the given 5244 /// type. 5245 /// 5246 /// \param TL The type that will be traversed to find 5247 /// unexpanded parameter packs. 5248 void collectUnexpandedParameterPacks(TypeLoc TL, 5249 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 5250 5251 /// \brief Collect the set of unexpanded parameter packs within the given 5252 /// nested-name-specifier. 5253 /// 5254 /// \param SS The nested-name-specifier that will be traversed to find 5255 /// unexpanded parameter packs. 5256 void collectUnexpandedParameterPacks(CXXScopeSpec &SS, 5257 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 5258 5259 /// \brief Collect the set of unexpanded parameter packs within the given 5260 /// name. 5261 /// 5262 /// \param NameInfo The name that will be traversed to find 5263 /// unexpanded parameter packs. 5264 void collectUnexpandedParameterPacks(const DeclarationNameInfo &NameInfo, 5265 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 5266 5267 /// \brief Invoked when parsing a template argument followed by an 5268 /// ellipsis, which creates a pack expansion. 5269 /// 5270 /// \param Arg The template argument preceding the ellipsis, which 5271 /// may already be invalid. 5272 /// 5273 /// \param EllipsisLoc The location of the ellipsis. 5274 ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, 5275 SourceLocation EllipsisLoc); 5276 5277 /// \brief Invoked when parsing a type followed by an ellipsis, which 5278 /// creates a pack expansion. 5279 /// 5280 /// \param Type The type preceding the ellipsis, which will become 5281 /// the pattern of the pack expansion. 5282 /// 5283 /// \param EllipsisLoc The location of the ellipsis. 5284 TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc); 5285 5286 /// \brief Construct a pack expansion type from the pattern of the pack 5287 /// expansion. 5288 TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern, 5289 SourceLocation EllipsisLoc, 5290 llvm::Optional<unsigned> NumExpansions); 5291 5292 /// \brief Construct a pack expansion type from the pattern of the pack 5293 /// expansion. 5294 QualType CheckPackExpansion(QualType Pattern, 5295 SourceRange PatternRange, 5296 SourceLocation EllipsisLoc, 5297 llvm::Optional<unsigned> NumExpansions); 5298 5299 /// \brief Invoked when parsing an expression followed by an ellipsis, which 5300 /// creates a pack expansion. 5301 /// 5302 /// \param Pattern The expression preceding the ellipsis, which will become 5303 /// the pattern of the pack expansion. 5304 /// 5305 /// \param EllipsisLoc The location of the ellipsis. 5306 ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc); 5307 5308 /// \brief Invoked when parsing an expression followed by an ellipsis, which 5309 /// creates a pack expansion. 5310 /// 5311 /// \param Pattern The expression preceding the ellipsis, which will become 5312 /// the pattern of the pack expansion. 5313 /// 5314 /// \param EllipsisLoc The location of the ellipsis. 5315 ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, 5316 llvm::Optional<unsigned> NumExpansions); 5317 5318 /// \brief Determine whether we could expand a pack expansion with the 5319 /// given set of parameter packs into separate arguments by repeatedly 5320 /// transforming the pattern. 5321 /// 5322 /// \param EllipsisLoc The location of the ellipsis that identifies the 5323 /// pack expansion. 5324 /// 5325 /// \param PatternRange The source range that covers the entire pattern of 5326 /// the pack expansion. 5327 /// 5328 /// \param Unexpanded The set of unexpanded parameter packs within the 5329 /// pattern. 5330 /// 5331 /// \param ShouldExpand Will be set to \c true if the transformer should 5332 /// expand the corresponding pack expansions into separate arguments. When 5333 /// set, \c NumExpansions must also be set. 5334 /// 5335 /// \param RetainExpansion Whether the caller should add an unexpanded 5336 /// pack expansion after all of the expanded arguments. This is used 5337 /// when extending explicitly-specified template argument packs per 5338 /// C++0x [temp.arg.explicit]p9. 5339 /// 5340 /// \param NumExpansions The number of separate arguments that will be in 5341 /// the expanded form of the corresponding pack expansion. This is both an 5342 /// input and an output parameter, which can be set by the caller if the 5343 /// number of expansions is known a priori (e.g., due to a prior substitution) 5344 /// and will be set by the callee when the number of expansions is known. 5345 /// The callee must set this value when \c ShouldExpand is \c true; it may 5346 /// set this value in other cases. 5347 /// 5348 /// \returns true if an error occurred (e.g., because the parameter packs 5349 /// are to be instantiated with arguments of different lengths), false 5350 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) 5351 /// must be set. 5352 bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc, 5353 SourceRange PatternRange, 5354 ArrayRef<UnexpandedParameterPack> Unexpanded, 5355 const MultiLevelTemplateArgumentList &TemplateArgs, 5356 bool &ShouldExpand, 5357 bool &RetainExpansion, 5358 llvm::Optional<unsigned> &NumExpansions); 5359 5360 /// \brief Determine the number of arguments in the given pack expansion 5361 /// type. 5362 /// 5363 /// This routine assumes that the number of arguments in the expansion is 5364 /// consistent across all of the unexpanded parameter packs in its pattern. 5365 /// 5366 /// Returns an empty Optional if the type can't be expanded. 5367 llvm::Optional<unsigned> getNumArgumentsInExpansion(QualType T, 5368 const MultiLevelTemplateArgumentList &TemplateArgs); 5369 5370 /// \brief Determine whether the given declarator contains any unexpanded 5371 /// parameter packs. 5372 /// 5373 /// This routine is used by the parser to disambiguate function declarators 5374 /// with an ellipsis prior to the ')', e.g., 5375 /// 5376 /// \code 5377 /// void f(T...); 5378 /// \endcode 5379 /// 5380 /// To determine whether we have an (unnamed) function parameter pack or 5381 /// a variadic function. 5382 /// 5383 /// \returns true if the declarator contains any unexpanded parameter packs, 5384 /// false otherwise. 5385 bool containsUnexpandedParameterPacks(Declarator &D); 5386 5387 //===--------------------------------------------------------------------===// 5388 // C++ Template Argument Deduction (C++ [temp.deduct]) 5389 //===--------------------------------------------------------------------===// 5390 5391 /// \brief Describes the result of template argument deduction. 5392 /// 5393 /// The TemplateDeductionResult enumeration describes the result of 5394 /// template argument deduction, as returned from 5395 /// DeduceTemplateArguments(). The separate TemplateDeductionInfo 5396 /// structure provides additional information about the results of 5397 /// template argument deduction, e.g., the deduced template argument 5398 /// list (if successful) or the specific template parameters or 5399 /// deduced arguments that were involved in the failure. 5400 enum TemplateDeductionResult { 5401 /// \brief Template argument deduction was successful. 5402 TDK_Success = 0, 5403 /// \brief The declaration was invalid; do nothing. 5404 TDK_Invalid, 5405 /// \brief Template argument deduction exceeded the maximum template 5406 /// instantiation depth (which has already been diagnosed). 5407 TDK_InstantiationDepth, 5408 /// \brief Template argument deduction did not deduce a value 5409 /// for every template parameter. 5410 TDK_Incomplete, 5411 /// \brief Template argument deduction produced inconsistent 5412 /// deduced values for the given template parameter. 5413 TDK_Inconsistent, 5414 /// \brief Template argument deduction failed due to inconsistent 5415 /// cv-qualifiers on a template parameter type that would 5416 /// otherwise be deduced, e.g., we tried to deduce T in "const T" 5417 /// but were given a non-const "X". 5418 TDK_Underqualified, 5419 /// \brief Substitution of the deduced template argument values 5420 /// resulted in an error. 5421 TDK_SubstitutionFailure, 5422 /// \brief Substitution of the deduced template argument values 5423 /// into a non-deduced context produced a type or value that 5424 /// produces a type that does not match the original template 5425 /// arguments provided. 5426 TDK_NonDeducedMismatch, 5427 /// \brief When performing template argument deduction for a function 5428 /// template, there were too many call arguments. 5429 TDK_TooManyArguments, 5430 /// \brief When performing template argument deduction for a function 5431 /// template, there were too few call arguments. 5432 TDK_TooFewArguments, 5433 /// \brief The explicitly-specified template arguments were not valid 5434 /// template arguments for the given template. 5435 TDK_InvalidExplicitArguments, 5436 /// \brief The arguments included an overloaded function name that could 5437 /// not be resolved to a suitable function. 5438 TDK_FailedOverloadResolution 5439 }; 5440 5441 TemplateDeductionResult 5442 DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, 5443 const TemplateArgumentList &TemplateArgs, 5444 sema::TemplateDeductionInfo &Info); 5445 5446 TemplateDeductionResult 5447 SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5448 TemplateArgumentListInfo &ExplicitTemplateArgs, 5449 SmallVectorImpl<DeducedTemplateArgument> &Deduced, 5450 SmallVectorImpl<QualType> &ParamTypes, 5451 QualType *FunctionType, 5452 sema::TemplateDeductionInfo &Info); 5453 5454 /// brief A function argument from which we performed template argument 5455 // deduction for a call. 5456 struct OriginalCallArg { 5457 OriginalCallArg(QualType OriginalParamType, 5458 unsigned ArgIdx, 5459 QualType OriginalArgType) 5460 : OriginalParamType(OriginalParamType), ArgIdx(ArgIdx), 5461 OriginalArgType(OriginalArgType) { } 5462 5463 QualType OriginalParamType; 5464 unsigned ArgIdx; 5465 QualType OriginalArgType; 5466 }; 5467 5468 TemplateDeductionResult 5469 FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, 5470 SmallVectorImpl<DeducedTemplateArgument> &Deduced, 5471 unsigned NumExplicitlySpecified, 5472 FunctionDecl *&Specialization, 5473 sema::TemplateDeductionInfo &Info, 5474 SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = 0); 5475 5476 TemplateDeductionResult 5477 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5478 TemplateArgumentListInfo *ExplicitTemplateArgs, 5479 ArrayRef<Expr *> Args, 5480 FunctionDecl *&Specialization, 5481 sema::TemplateDeductionInfo &Info); 5482 5483 TemplateDeductionResult 5484 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5485 TemplateArgumentListInfo *ExplicitTemplateArgs, 5486 QualType ArgFunctionType, 5487 FunctionDecl *&Specialization, 5488 sema::TemplateDeductionInfo &Info); 5489 5490 TemplateDeductionResult 5491 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5492 QualType ToType, 5493 CXXConversionDecl *&Specialization, 5494 sema::TemplateDeductionInfo &Info); 5495 5496 TemplateDeductionResult 5497 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5498 TemplateArgumentListInfo *ExplicitTemplateArgs, 5499 FunctionDecl *&Specialization, 5500 sema::TemplateDeductionInfo &Info); 5501 5502 /// \brief Result type of DeduceAutoType. 5503 enum DeduceAutoResult { 5504 DAR_Succeeded, 5505 DAR_Failed, 5506 DAR_FailedAlreadyDiagnosed 5507 }; 5508 5509 DeduceAutoResult DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer, 5510 TypeSourceInfo *&Result); 5511 void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init); 5512 5513 FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1, 5514 FunctionTemplateDecl *FT2, 5515 SourceLocation Loc, 5516 TemplatePartialOrderingContext TPOC, 5517 unsigned NumCallArguments); 5518 UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin, 5519 UnresolvedSetIterator SEnd, 5520 TemplatePartialOrderingContext TPOC, 5521 unsigned NumCallArguments, 5522 SourceLocation Loc, 5523 const PartialDiagnostic &NoneDiag, 5524 const PartialDiagnostic &AmbigDiag, 5525 const PartialDiagnostic &CandidateDiag, 5526 bool Complain = true, 5527 QualType TargetType = QualType()); 5528 5529 ClassTemplatePartialSpecializationDecl * 5530 getMoreSpecializedPartialSpecialization( 5531 ClassTemplatePartialSpecializationDecl *PS1, 5532 ClassTemplatePartialSpecializationDecl *PS2, 5533 SourceLocation Loc); 5534 5535 void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, 5536 bool OnlyDeduced, 5537 unsigned Depth, 5538 llvm::SmallBitVector &Used); 5539 void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate, 5540 llvm::SmallBitVector &Deduced) { 5541 return MarkDeducedTemplateParameters(Context, FunctionTemplate, Deduced); 5542 } 5543 static void MarkDeducedTemplateParameters(ASTContext &Ctx, 5544 FunctionTemplateDecl *FunctionTemplate, 5545 llvm::SmallBitVector &Deduced); 5546 5547 //===--------------------------------------------------------------------===// 5548 // C++ Template Instantiation 5549 // 5550 5551 MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D, 5552 const TemplateArgumentList *Innermost = 0, 5553 bool RelativeToPrimary = false, 5554 const FunctionDecl *Pattern = 0); 5555 5556 /// \brief A template instantiation that is currently in progress. 5557 struct ActiveTemplateInstantiation { 5558 /// \brief The kind of template instantiation we are performing 5559 enum InstantiationKind { 5560 /// We are instantiating a template declaration. The entity is 5561 /// the declaration we're instantiating (e.g., a CXXRecordDecl). 5562 TemplateInstantiation, 5563 5564 /// We are instantiating a default argument for a template 5565 /// parameter. The Entity is the template, and 5566 /// TemplateArgs/NumTemplateArguments provides the template 5567 /// arguments as specified. 5568 /// FIXME: Use a TemplateArgumentList 5569 DefaultTemplateArgumentInstantiation, 5570 5571 /// We are instantiating a default argument for a function. 5572 /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs 5573 /// provides the template arguments as specified. 5574 DefaultFunctionArgumentInstantiation, 5575 5576 /// We are substituting explicit template arguments provided for 5577 /// a function template. The entity is a FunctionTemplateDecl. 5578 ExplicitTemplateArgumentSubstitution, 5579 5580 /// We are substituting template argument determined as part of 5581 /// template argument deduction for either a class template 5582 /// partial specialization or a function template. The 5583 /// Entity is either a ClassTemplatePartialSpecializationDecl or 5584 /// a FunctionTemplateDecl. 5585 DeducedTemplateArgumentSubstitution, 5586 5587 /// We are substituting prior template arguments into a new 5588 /// template parameter. The template parameter itself is either a 5589 /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl. 5590 PriorTemplateArgumentSubstitution, 5591 5592 /// We are checking the validity of a default template argument that 5593 /// has been used when naming a template-id. 5594 DefaultTemplateArgumentChecking, 5595 5596 /// We are instantiating the exception specification for a function 5597 /// template which was deferred until it was needed. 5598 ExceptionSpecInstantiation 5599 } Kind; 5600 5601 /// \brief The point of instantiation within the source code. 5602 SourceLocation PointOfInstantiation; 5603 5604 /// \brief The template (or partial specialization) in which we are 5605 /// performing the instantiation, for substitutions of prior template 5606 /// arguments. 5607 NamedDecl *Template; 5608 5609 /// \brief The entity that is being instantiated. 5610 Decl *Entity; 5611 5612 /// \brief The list of template arguments we are substituting, if they 5613 /// are not part of the entity. 5614 const TemplateArgument *TemplateArgs; 5615 5616 /// \brief The number of template arguments in TemplateArgs. 5617 unsigned NumTemplateArgs; 5618 5619 /// \brief The template deduction info object associated with the 5620 /// substitution or checking of explicit or deduced template arguments. 5621 sema::TemplateDeductionInfo *DeductionInfo; 5622 5623 /// \brief The source range that covers the construct that cause 5624 /// the instantiation, e.g., the template-id that causes a class 5625 /// template instantiation. 5626 SourceRange InstantiationRange; 5627 5628 ActiveTemplateInstantiation() 5629 : Kind(TemplateInstantiation), Template(0), Entity(0), TemplateArgs(0), 5630 NumTemplateArgs(0), DeductionInfo(0) {} 5631 5632 /// \brief Determines whether this template is an actual instantiation 5633 /// that should be counted toward the maximum instantiation depth. 5634 bool isInstantiationRecord() const; 5635 5636 friend bool operator==(const ActiveTemplateInstantiation &X, 5637 const ActiveTemplateInstantiation &Y) { 5638 if (X.Kind != Y.Kind) 5639 return false; 5640 5641 if (X.Entity != Y.Entity) 5642 return false; 5643 5644 switch (X.Kind) { 5645 case TemplateInstantiation: 5646 case ExceptionSpecInstantiation: 5647 return true; 5648 5649 case PriorTemplateArgumentSubstitution: 5650 case DefaultTemplateArgumentChecking: 5651 if (X.Template != Y.Template) 5652 return false; 5653 5654 // Fall through 5655 5656 case DefaultTemplateArgumentInstantiation: 5657 case ExplicitTemplateArgumentSubstitution: 5658 case DeducedTemplateArgumentSubstitution: 5659 case DefaultFunctionArgumentInstantiation: 5660 return X.TemplateArgs == Y.TemplateArgs; 5661 5662 } 5663 5664 llvm_unreachable("Invalid InstantiationKind!"); 5665 } 5666 5667 friend bool operator!=(const ActiveTemplateInstantiation &X, 5668 const ActiveTemplateInstantiation &Y) { 5669 return !(X == Y); 5670 } 5671 }; 5672 5673 /// \brief List of active template instantiations. 5674 /// 5675 /// This vector is treated as a stack. As one template instantiation 5676 /// requires another template instantiation, additional 5677 /// instantiations are pushed onto the stack up to a 5678 /// user-configurable limit LangOptions::InstantiationDepth. 5679 SmallVector<ActiveTemplateInstantiation, 16> 5680 ActiveTemplateInstantiations; 5681 5682 /// \brief Whether we are in a SFINAE context that is not associated with 5683 /// template instantiation. 5684 /// 5685 /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside 5686 /// of a template instantiation or template argument deduction. 5687 bool InNonInstantiationSFINAEContext; 5688 5689 /// \brief The number of ActiveTemplateInstantiation entries in 5690 /// \c ActiveTemplateInstantiations that are not actual instantiations and, 5691 /// therefore, should not be counted as part of the instantiation depth. 5692 unsigned NonInstantiationEntries; 5693 5694 /// \brief The last template from which a template instantiation 5695 /// error or warning was produced. 5696 /// 5697 /// This value is used to suppress printing of redundant template 5698 /// instantiation backtraces when there are multiple errors in the 5699 /// same instantiation. FIXME: Does this belong in Sema? It's tough 5700 /// to implement it anywhere else. 5701 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext; 5702 5703 /// \brief The current index into pack expansion arguments that will be 5704 /// used for substitution of parameter packs. 5705 /// 5706 /// The pack expansion index will be -1 to indicate that parameter packs 5707 /// should be instantiated as themselves. Otherwise, the index specifies 5708 /// which argument within the parameter pack will be used for substitution. 5709 int ArgumentPackSubstitutionIndex; 5710 5711 /// \brief RAII object used to change the argument pack substitution index 5712 /// within a \c Sema object. 5713 /// 5714 /// See \c ArgumentPackSubstitutionIndex for more information. 5715 class ArgumentPackSubstitutionIndexRAII { 5716 Sema &Self; 5717 int OldSubstitutionIndex; 5718 5719 public: 5720 ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex) 5721 : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) { 5722 Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex; 5723 } 5724 5725 ~ArgumentPackSubstitutionIndexRAII() { 5726 Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex; 5727 } 5728 }; 5729 5730 friend class ArgumentPackSubstitutionRAII; 5731 5732 /// \brief The stack of calls expression undergoing template instantiation. 5733 /// 5734 /// The top of this stack is used by a fixit instantiating unresolved 5735 /// function calls to fix the AST to match the textual change it prints. 5736 SmallVector<CallExpr *, 8> CallsUndergoingInstantiation; 5737 5738 /// \brief For each declaration that involved template argument deduction, the 5739 /// set of diagnostics that were suppressed during that template argument 5740 /// deduction. 5741 /// 5742 /// FIXME: Serialize this structure to the AST file. 5743 llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1> > 5744 SuppressedDiagnostics; 5745 5746 /// \brief A stack object to be created when performing template 5747 /// instantiation. 5748 /// 5749 /// Construction of an object of type \c InstantiatingTemplate 5750 /// pushes the current instantiation onto the stack of active 5751 /// instantiations. If the size of this stack exceeds the maximum 5752 /// number of recursive template instantiations, construction 5753 /// produces an error and evaluates true. 5754 /// 5755 /// Destruction of this object will pop the named instantiation off 5756 /// the stack. 5757 struct InstantiatingTemplate { 5758 /// \brief Note that we are instantiating a class template, 5759 /// function template, or a member thereof. 5760 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5761 Decl *Entity, 5762 SourceRange InstantiationRange = SourceRange()); 5763 5764 struct ExceptionSpecification {}; 5765 /// \brief Note that we are instantiating an exception specification 5766 /// of a function template. 5767 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5768 FunctionDecl *Entity, ExceptionSpecification, 5769 SourceRange InstantiationRange = SourceRange()); 5770 5771 /// \brief Note that we are instantiating a default argument in a 5772 /// template-id. 5773 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5774 TemplateDecl *Template, 5775 ArrayRef<TemplateArgument> TemplateArgs, 5776 SourceRange InstantiationRange = SourceRange()); 5777 5778 /// \brief Note that we are instantiating a default argument in a 5779 /// template-id. 5780 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5781 FunctionTemplateDecl *FunctionTemplate, 5782 ArrayRef<TemplateArgument> TemplateArgs, 5783 ActiveTemplateInstantiation::InstantiationKind Kind, 5784 sema::TemplateDeductionInfo &DeductionInfo, 5785 SourceRange InstantiationRange = SourceRange()); 5786 5787 /// \brief Note that we are instantiating as part of template 5788 /// argument deduction for a class template partial 5789 /// specialization. 5790 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5791 ClassTemplatePartialSpecializationDecl *PartialSpec, 5792 ArrayRef<TemplateArgument> TemplateArgs, 5793 sema::TemplateDeductionInfo &DeductionInfo, 5794 SourceRange InstantiationRange = SourceRange()); 5795 5796 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5797 ParmVarDecl *Param, 5798 ArrayRef<TemplateArgument> TemplateArgs, 5799 SourceRange InstantiationRange = SourceRange()); 5800 5801 /// \brief Note that we are substituting prior template arguments into a 5802 /// non-type or template template parameter. 5803 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5804 NamedDecl *Template, 5805 NonTypeTemplateParmDecl *Param, 5806 ArrayRef<TemplateArgument> TemplateArgs, 5807 SourceRange InstantiationRange); 5808 5809 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5810 NamedDecl *Template, 5811 TemplateTemplateParmDecl *Param, 5812 ArrayRef<TemplateArgument> TemplateArgs, 5813 SourceRange InstantiationRange); 5814 5815 /// \brief Note that we are checking the default template argument 5816 /// against the template parameter for a given template-id. 5817 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5818 TemplateDecl *Template, 5819 NamedDecl *Param, 5820 ArrayRef<TemplateArgument> TemplateArgs, 5821 SourceRange InstantiationRange); 5822 5823 5824 /// \brief Note that we have finished instantiating this template. 5825 void Clear(); 5826 5827 ~InstantiatingTemplate() { Clear(); } 5828 5829 /// \brief Determines whether we have exceeded the maximum 5830 /// recursive template instantiations. 5831 operator bool() const { return Invalid; } 5832 5833 private: 5834 Sema &SemaRef; 5835 bool Invalid; 5836 bool SavedInNonInstantiationSFINAEContext; 5837 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation, 5838 SourceRange InstantiationRange); 5839 5840 InstantiatingTemplate(const InstantiatingTemplate&) LLVM_DELETED_FUNCTION; 5841 5842 InstantiatingTemplate& 5843 operator=(const InstantiatingTemplate&) LLVM_DELETED_FUNCTION; 5844 }; 5845 5846 void PrintInstantiationStack(); 5847 5848 /// \brief Determines whether we are currently in a context where 5849 /// template argument substitution failures are not considered 5850 /// errors. 5851 /// 5852 /// \returns An empty \c llvm::Optional if we're not in a SFINAE context. 5853 /// Otherwise, contains a pointer that, if non-NULL, contains the nearest 5854 /// template-deduction context object, which can be used to capture 5855 /// diagnostics that will be suppressed. 5856 llvm::Optional<sema::TemplateDeductionInfo *> isSFINAEContext() const; 5857 5858 /// \brief Determines whether we are currently in a context that 5859 /// is not evaluated as per C++ [expr] p5. 5860 bool isUnevaluatedContext() const { 5861 assert(!ExprEvalContexts.empty() && 5862 "Must be in an expression evaluation context"); 5863 return ExprEvalContexts.back().Context == Sema::Unevaluated; 5864 } 5865 5866 /// \brief RAII class used to determine whether SFINAE has 5867 /// trapped any errors that occur during template argument 5868 /// deduction.` 5869 class SFINAETrap { 5870 Sema &SemaRef; 5871 unsigned PrevSFINAEErrors; 5872 bool PrevInNonInstantiationSFINAEContext; 5873 bool PrevAccessCheckingSFINAE; 5874 5875 public: 5876 explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false) 5877 : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors), 5878 PrevInNonInstantiationSFINAEContext( 5879 SemaRef.InNonInstantiationSFINAEContext), 5880 PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE) 5881 { 5882 if (!SemaRef.isSFINAEContext()) 5883 SemaRef.InNonInstantiationSFINAEContext = true; 5884 SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE; 5885 } 5886 5887 ~SFINAETrap() { 5888 SemaRef.NumSFINAEErrors = PrevSFINAEErrors; 5889 SemaRef.InNonInstantiationSFINAEContext 5890 = PrevInNonInstantiationSFINAEContext; 5891 SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE; 5892 } 5893 5894 /// \brief Determine whether any SFINAE errors have been trapped. 5895 bool hasErrorOccurred() const { 5896 return SemaRef.NumSFINAEErrors > PrevSFINAEErrors; 5897 } 5898 }; 5899 5900 /// \brief The current instantiation scope used to store local 5901 /// variables. 5902 LocalInstantiationScope *CurrentInstantiationScope; 5903 5904 /// \brief The number of typos corrected by CorrectTypo. 5905 unsigned TyposCorrected; 5906 5907 typedef llvm::DenseMap<IdentifierInfo *, TypoCorrection> 5908 UnqualifiedTyposCorrectedMap; 5909 5910 /// \brief A cache containing the results of typo correction for unqualified 5911 /// name lookup. 5912 /// 5913 /// The string is the string that we corrected to (which may be empty, if 5914 /// there was no correction), while the boolean will be true when the 5915 /// string represents a keyword. 5916 UnqualifiedTyposCorrectedMap UnqualifiedTyposCorrected; 5917 5918 /// \brief Worker object for performing CFG-based warnings. 5919 sema::AnalysisBasedWarnings AnalysisWarnings; 5920 5921 /// \brief An entity for which implicit template instantiation is required. 5922 /// 5923 /// The source location associated with the declaration is the first place in 5924 /// the source code where the declaration was "used". It is not necessarily 5925 /// the point of instantiation (which will be either before or after the 5926 /// namespace-scope declaration that triggered this implicit instantiation), 5927 /// However, it is the location that diagnostics should generally refer to, 5928 /// because users will need to know what code triggered the instantiation. 5929 typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation; 5930 5931 /// \brief The queue of implicit template instantiations that are required 5932 /// but have not yet been performed. 5933 std::deque<PendingImplicitInstantiation> PendingInstantiations; 5934 5935 /// \brief The queue of implicit template instantiations that are required 5936 /// and must be performed within the current local scope. 5937 /// 5938 /// This queue is only used for member functions of local classes in 5939 /// templates, which must be instantiated in the same scope as their 5940 /// enclosing function, so that they can reference function-local 5941 /// types, static variables, enumerators, etc. 5942 std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations; 5943 5944 void PerformPendingInstantiations(bool LocalOnly = false); 5945 5946 TypeSourceInfo *SubstType(TypeSourceInfo *T, 5947 const MultiLevelTemplateArgumentList &TemplateArgs, 5948 SourceLocation Loc, DeclarationName Entity); 5949 5950 QualType SubstType(QualType T, 5951 const MultiLevelTemplateArgumentList &TemplateArgs, 5952 SourceLocation Loc, DeclarationName Entity); 5953 5954 TypeSourceInfo *SubstType(TypeLoc TL, 5955 const MultiLevelTemplateArgumentList &TemplateArgs, 5956 SourceLocation Loc, DeclarationName Entity); 5957 5958 TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T, 5959 const MultiLevelTemplateArgumentList &TemplateArgs, 5960 SourceLocation Loc, 5961 DeclarationName Entity, 5962 CXXRecordDecl *ThisContext, 5963 unsigned ThisTypeQuals); 5964 ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D, 5965 const MultiLevelTemplateArgumentList &TemplateArgs, 5966 int indexAdjustment, 5967 llvm::Optional<unsigned> NumExpansions, 5968 bool ExpectParameterPack); 5969 bool SubstParmTypes(SourceLocation Loc, 5970 ParmVarDecl **Params, unsigned NumParams, 5971 const MultiLevelTemplateArgumentList &TemplateArgs, 5972 SmallVectorImpl<QualType> &ParamTypes, 5973 SmallVectorImpl<ParmVarDecl *> *OutParams = 0); 5974 ExprResult SubstExpr(Expr *E, 5975 const MultiLevelTemplateArgumentList &TemplateArgs); 5976 5977 /// \brief Substitute the given template arguments into a list of 5978 /// expressions, expanding pack expansions if required. 5979 /// 5980 /// \param Exprs The list of expressions to substitute into. 5981 /// 5982 /// \param NumExprs The number of expressions in \p Exprs. 5983 /// 5984 /// \param IsCall Whether this is some form of call, in which case 5985 /// default arguments will be dropped. 5986 /// 5987 /// \param TemplateArgs The set of template arguments to substitute. 5988 /// 5989 /// \param Outputs Will receive all of the substituted arguments. 5990 /// 5991 /// \returns true if an error occurred, false otherwise. 5992 bool SubstExprs(Expr **Exprs, unsigned NumExprs, bool IsCall, 5993 const MultiLevelTemplateArgumentList &TemplateArgs, 5994 SmallVectorImpl<Expr *> &Outputs); 5995 5996 StmtResult SubstStmt(Stmt *S, 5997 const MultiLevelTemplateArgumentList &TemplateArgs); 5998 5999 Decl *SubstDecl(Decl *D, DeclContext *Owner, 6000 const MultiLevelTemplateArgumentList &TemplateArgs); 6001 6002 ExprResult SubstInitializer(Expr *E, 6003 const MultiLevelTemplateArgumentList &TemplateArgs, 6004 bool CXXDirectInit); 6005 6006 bool 6007 SubstBaseSpecifiers(CXXRecordDecl *Instantiation, 6008 CXXRecordDecl *Pattern, 6009 const MultiLevelTemplateArgumentList &TemplateArgs); 6010 6011 bool 6012 InstantiateClass(SourceLocation PointOfInstantiation, 6013 CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, 6014 const MultiLevelTemplateArgumentList &TemplateArgs, 6015 TemplateSpecializationKind TSK, 6016 bool Complain = true); 6017 6018 bool InstantiateEnum(SourceLocation PointOfInstantiation, 6019 EnumDecl *Instantiation, EnumDecl *Pattern, 6020 const MultiLevelTemplateArgumentList &TemplateArgs, 6021 TemplateSpecializationKind TSK); 6022 6023 struct LateInstantiatedAttribute { 6024 const Attr *TmplAttr; 6025 LocalInstantiationScope *Scope; 6026 Decl *NewDecl; 6027 6028 LateInstantiatedAttribute(const Attr *A, LocalInstantiationScope *S, 6029 Decl *D) 6030 : TmplAttr(A), Scope(S), NewDecl(D) 6031 { } 6032 }; 6033 typedef SmallVector<LateInstantiatedAttribute, 16> LateInstantiatedAttrVec; 6034 6035 void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, 6036 const Decl *Pattern, Decl *Inst, 6037 LateInstantiatedAttrVec *LateAttrs = 0, 6038 LocalInstantiationScope *OuterMostScope = 0); 6039 6040 bool 6041 InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, 6042 ClassTemplateSpecializationDecl *ClassTemplateSpec, 6043 TemplateSpecializationKind TSK, 6044 bool Complain = true); 6045 6046 void InstantiateClassMembers(SourceLocation PointOfInstantiation, 6047 CXXRecordDecl *Instantiation, 6048 const MultiLevelTemplateArgumentList &TemplateArgs, 6049 TemplateSpecializationKind TSK); 6050 6051 void InstantiateClassTemplateSpecializationMembers( 6052 SourceLocation PointOfInstantiation, 6053 ClassTemplateSpecializationDecl *ClassTemplateSpec, 6054 TemplateSpecializationKind TSK); 6055 6056 NestedNameSpecifierLoc 6057 SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, 6058 const MultiLevelTemplateArgumentList &TemplateArgs); 6059 6060 DeclarationNameInfo 6061 SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, 6062 const MultiLevelTemplateArgumentList &TemplateArgs); 6063 TemplateName 6064 SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, 6065 SourceLocation Loc, 6066 const MultiLevelTemplateArgumentList &TemplateArgs); 6067 bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, 6068 TemplateArgumentListInfo &Result, 6069 const MultiLevelTemplateArgumentList &TemplateArgs); 6070 6071 void InstantiateExceptionSpec(SourceLocation PointOfInstantiation, 6072 FunctionDecl *Function); 6073 void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, 6074 FunctionDecl *Function, 6075 bool Recursive = false, 6076 bool DefinitionRequired = false); 6077 void InstantiateStaticDataMemberDefinition( 6078 SourceLocation PointOfInstantiation, 6079 VarDecl *Var, 6080 bool Recursive = false, 6081 bool DefinitionRequired = false); 6082 6083 void InstantiateMemInitializers(CXXConstructorDecl *New, 6084 const CXXConstructorDecl *Tmpl, 6085 const MultiLevelTemplateArgumentList &TemplateArgs); 6086 6087 NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, 6088 const MultiLevelTemplateArgumentList &TemplateArgs); 6089 DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, 6090 const MultiLevelTemplateArgumentList &TemplateArgs); 6091 6092 // Objective-C declarations. 6093 enum ObjCContainerKind { 6094 OCK_None = -1, 6095 OCK_Interface = 0, 6096 OCK_Protocol, 6097 OCK_Category, 6098 OCK_ClassExtension, 6099 OCK_Implementation, 6100 OCK_CategoryImplementation 6101 }; 6102 ObjCContainerKind getObjCContainerKind() const; 6103 6104 Decl *ActOnStartClassInterface(SourceLocation AtInterfaceLoc, 6105 IdentifierInfo *ClassName, 6106 SourceLocation ClassLoc, 6107 IdentifierInfo *SuperName, 6108 SourceLocation SuperLoc, 6109 Decl * const *ProtoRefs, 6110 unsigned NumProtoRefs, 6111 const SourceLocation *ProtoLocs, 6112 SourceLocation EndProtoLoc, 6113 AttributeList *AttrList); 6114 6115 Decl *ActOnCompatibilityAlias( 6116 SourceLocation AtCompatibilityAliasLoc, 6117 IdentifierInfo *AliasName, SourceLocation AliasLocation, 6118 IdentifierInfo *ClassName, SourceLocation ClassLocation); 6119 6120 bool CheckForwardProtocolDeclarationForCircularDependency( 6121 IdentifierInfo *PName, 6122 SourceLocation &PLoc, SourceLocation PrevLoc, 6123 const ObjCList<ObjCProtocolDecl> &PList); 6124 6125 Decl *ActOnStartProtocolInterface( 6126 SourceLocation AtProtoInterfaceLoc, 6127 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, 6128 Decl * const *ProtoRefNames, unsigned NumProtoRefs, 6129 const SourceLocation *ProtoLocs, 6130 SourceLocation EndProtoLoc, 6131 AttributeList *AttrList); 6132 6133 Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, 6134 IdentifierInfo *ClassName, 6135 SourceLocation ClassLoc, 6136 IdentifierInfo *CategoryName, 6137 SourceLocation CategoryLoc, 6138 Decl * const *ProtoRefs, 6139 unsigned NumProtoRefs, 6140 const SourceLocation *ProtoLocs, 6141 SourceLocation EndProtoLoc); 6142 6143 Decl *ActOnStartClassImplementation( 6144 SourceLocation AtClassImplLoc, 6145 IdentifierInfo *ClassName, SourceLocation ClassLoc, 6146 IdentifierInfo *SuperClassname, 6147 SourceLocation SuperClassLoc); 6148 6149 Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc, 6150 IdentifierInfo *ClassName, 6151 SourceLocation ClassLoc, 6152 IdentifierInfo *CatName, 6153 SourceLocation CatLoc); 6154 6155 DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl, 6156 ArrayRef<Decl *> Decls); 6157 6158 DeclGroupPtrTy ActOnForwardClassDeclaration(SourceLocation Loc, 6159 IdentifierInfo **IdentList, 6160 SourceLocation *IdentLocs, 6161 unsigned NumElts); 6162 6163 DeclGroupPtrTy ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc, 6164 const IdentifierLocPair *IdentList, 6165 unsigned NumElts, 6166 AttributeList *attrList); 6167 6168 void FindProtocolDeclaration(bool WarnOnDeclarations, 6169 const IdentifierLocPair *ProtocolId, 6170 unsigned NumProtocols, 6171 SmallVectorImpl<Decl *> &Protocols); 6172 6173 /// Ensure attributes are consistent with type. 6174 /// \param [in, out] Attributes The attributes to check; they will 6175 /// be modified to be consistent with \p PropertyTy. 6176 void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, 6177 SourceLocation Loc, 6178 unsigned &Attributes, 6179 bool propertyInPrimaryClass); 6180 6181 /// Process the specified property declaration and create decls for the 6182 /// setters and getters as needed. 6183 /// \param property The property declaration being processed 6184 /// \param CD The semantic container for the property 6185 /// \param redeclaredProperty Declaration for property if redeclared 6186 /// in class extension. 6187 /// \param lexicalDC Container for redeclaredProperty. 6188 void ProcessPropertyDecl(ObjCPropertyDecl *property, 6189 ObjCContainerDecl *CD, 6190 ObjCPropertyDecl *redeclaredProperty = 0, 6191 ObjCContainerDecl *lexicalDC = 0); 6192 6193 6194 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, 6195 ObjCPropertyDecl *SuperProperty, 6196 const IdentifierInfo *Name); 6197 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl); 6198 6199 6200 void CompareProperties(Decl *CDecl, Decl *MergeProtocols); 6201 6202 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, 6203 ObjCInterfaceDecl *ID); 6204 6205 void MatchOneProtocolPropertiesInClass(Decl *CDecl, 6206 ObjCProtocolDecl *PDecl); 6207 6208 Decl *ActOnAtEnd(Scope *S, SourceRange AtEnd, 6209 Decl **allMethods = 0, unsigned allNum = 0, 6210 Decl **allProperties = 0, unsigned pNum = 0, 6211 DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0); 6212 6213 Decl *ActOnProperty(Scope *S, SourceLocation AtLoc, 6214 SourceLocation LParenLoc, 6215 FieldDeclarator &FD, ObjCDeclSpec &ODS, 6216 Selector GetterSel, Selector SetterSel, 6217 bool *OverridingProperty, 6218 tok::ObjCKeywordKind MethodImplKind, 6219 DeclContext *lexicalDC = 0); 6220 6221 Decl *ActOnPropertyImplDecl(Scope *S, 6222 SourceLocation AtLoc, 6223 SourceLocation PropertyLoc, 6224 bool ImplKind, 6225 IdentifierInfo *PropertyId, 6226 IdentifierInfo *PropertyIvar, 6227 SourceLocation PropertyIvarLoc); 6228 6229 enum ObjCSpecialMethodKind { 6230 OSMK_None, 6231 OSMK_Alloc, 6232 OSMK_New, 6233 OSMK_Copy, 6234 OSMK_RetainingInit, 6235 OSMK_NonRetainingInit 6236 }; 6237 6238 struct ObjCArgInfo { 6239 IdentifierInfo *Name; 6240 SourceLocation NameLoc; 6241 // The Type is null if no type was specified, and the DeclSpec is invalid 6242 // in this case. 6243 ParsedType Type; 6244 ObjCDeclSpec DeclSpec; 6245 6246 /// ArgAttrs - Attribute list for this argument. 6247 AttributeList *ArgAttrs; 6248 }; 6249 6250 Decl *ActOnMethodDeclaration( 6251 Scope *S, 6252 SourceLocation BeginLoc, // location of the + or -. 6253 SourceLocation EndLoc, // location of the ; or {. 6254 tok::TokenKind MethodType, 6255 ObjCDeclSpec &ReturnQT, ParsedType ReturnType, 6256 ArrayRef<SourceLocation> SelectorLocs, Selector Sel, 6257 // optional arguments. The number of types/arguments is obtained 6258 // from the Sel.getNumArgs(). 6259 ObjCArgInfo *ArgInfo, 6260 DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args 6261 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind, 6262 bool isVariadic, bool MethodDefinition); 6263 6264 ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel, 6265 const ObjCObjectPointerType *OPT, 6266 bool IsInstance); 6267 ObjCMethodDecl *LookupMethodInObjectType(Selector Sel, QualType Ty, 6268 bool IsInstance); 6269 6270 bool inferObjCARCLifetime(ValueDecl *decl); 6271 6272 ExprResult 6273 HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, 6274 Expr *BaseExpr, 6275 SourceLocation OpLoc, 6276 DeclarationName MemberName, 6277 SourceLocation MemberLoc, 6278 SourceLocation SuperLoc, QualType SuperType, 6279 bool Super); 6280 6281 ExprResult 6282 ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, 6283 IdentifierInfo &propertyName, 6284 SourceLocation receiverNameLoc, 6285 SourceLocation propertyNameLoc); 6286 6287 ObjCMethodDecl *tryCaptureObjCSelf(SourceLocation Loc); 6288 6289 /// \brief Describes the kind of message expression indicated by a message 6290 /// send that starts with an identifier. 6291 enum ObjCMessageKind { 6292 /// \brief The message is sent to 'super'. 6293 ObjCSuperMessage, 6294 /// \brief The message is an instance message. 6295 ObjCInstanceMessage, 6296 /// \brief The message is a class message, and the identifier is a type 6297 /// name. 6298 ObjCClassMessage 6299 }; 6300 6301 ObjCMessageKind getObjCMessageKind(Scope *S, 6302 IdentifierInfo *Name, 6303 SourceLocation NameLoc, 6304 bool IsSuper, 6305 bool HasTrailingDot, 6306 ParsedType &ReceiverType); 6307 6308 ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, 6309 Selector Sel, 6310 SourceLocation LBracLoc, 6311 ArrayRef<SourceLocation> SelectorLocs, 6312 SourceLocation RBracLoc, 6313 MultiExprArg Args); 6314 6315 ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, 6316 QualType ReceiverType, 6317 SourceLocation SuperLoc, 6318 Selector Sel, 6319 ObjCMethodDecl *Method, 6320 SourceLocation LBracLoc, 6321 ArrayRef<SourceLocation> SelectorLocs, 6322 SourceLocation RBracLoc, 6323 MultiExprArg Args, 6324 bool isImplicit = false); 6325 6326 ExprResult BuildClassMessageImplicit(QualType ReceiverType, 6327 bool isSuperReceiver, 6328 SourceLocation Loc, 6329 Selector Sel, 6330 ObjCMethodDecl *Method, 6331 MultiExprArg Args); 6332 6333 ExprResult ActOnClassMessage(Scope *S, 6334 ParsedType Receiver, 6335 Selector Sel, 6336 SourceLocation LBracLoc, 6337 ArrayRef<SourceLocation> SelectorLocs, 6338 SourceLocation RBracLoc, 6339 MultiExprArg Args); 6340 6341 ExprResult BuildInstanceMessage(Expr *Receiver, 6342 QualType ReceiverType, 6343 SourceLocation SuperLoc, 6344 Selector Sel, 6345 ObjCMethodDecl *Method, 6346 SourceLocation LBracLoc, 6347 ArrayRef<SourceLocation> SelectorLocs, 6348 SourceLocation RBracLoc, 6349 MultiExprArg Args, 6350 bool isImplicit = false); 6351 6352 ExprResult BuildInstanceMessageImplicit(Expr *Receiver, 6353 QualType ReceiverType, 6354 SourceLocation Loc, 6355 Selector Sel, 6356 ObjCMethodDecl *Method, 6357 MultiExprArg Args); 6358 6359 ExprResult ActOnInstanceMessage(Scope *S, 6360 Expr *Receiver, 6361 Selector Sel, 6362 SourceLocation LBracLoc, 6363 ArrayRef<SourceLocation> SelectorLocs, 6364 SourceLocation RBracLoc, 6365 MultiExprArg Args); 6366 6367 ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, 6368 ObjCBridgeCastKind Kind, 6369 SourceLocation BridgeKeywordLoc, 6370 TypeSourceInfo *TSInfo, 6371 Expr *SubExpr); 6372 6373 ExprResult ActOnObjCBridgedCast(Scope *S, 6374 SourceLocation LParenLoc, 6375 ObjCBridgeCastKind Kind, 6376 SourceLocation BridgeKeywordLoc, 6377 ParsedType Type, 6378 SourceLocation RParenLoc, 6379 Expr *SubExpr); 6380 6381 bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall); 6382 6383 /// \brief Check whether the given new method is a valid override of the 6384 /// given overridden method, and set any properties that should be inherited. 6385 void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod, 6386 const ObjCMethodDecl *Overridden, 6387 bool IsImplementation); 6388 6389 /// \brief Describes the compatibility of a result type with its method. 6390 enum ResultTypeCompatibilityKind { 6391 RTC_Compatible, 6392 RTC_Incompatible, 6393 RTC_Unknown 6394 }; 6395 6396 void CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod, 6397 ObjCInterfaceDecl *CurrentClass, 6398 ResultTypeCompatibilityKind RTC); 6399 6400 enum PragmaOptionsAlignKind { 6401 POAK_Native, // #pragma options align=native 6402 POAK_Natural, // #pragma options align=natural 6403 POAK_Packed, // #pragma options align=packed 6404 POAK_Power, // #pragma options align=power 6405 POAK_Mac68k, // #pragma options align=mac68k 6406 POAK_Reset // #pragma options align=reset 6407 }; 6408 6409 /// ActOnPragmaOptionsAlign - Called on well formed \#pragma options align. 6410 void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, 6411 SourceLocation PragmaLoc); 6412 6413 enum PragmaPackKind { 6414 PPK_Default, // #pragma pack([n]) 6415 PPK_Show, // #pragma pack(show), only supported by MSVC. 6416 PPK_Push, // #pragma pack(push, [identifier], [n]) 6417 PPK_Pop // #pragma pack(pop, [identifier], [n]) 6418 }; 6419 6420 enum PragmaMSStructKind { 6421 PMSST_OFF, // #pragms ms_struct off 6422 PMSST_ON // #pragms ms_struct on 6423 }; 6424 6425 /// ActOnPragmaPack - Called on well formed \#pragma pack(...). 6426 void ActOnPragmaPack(PragmaPackKind Kind, 6427 IdentifierInfo *Name, 6428 Expr *Alignment, 6429 SourceLocation PragmaLoc, 6430 SourceLocation LParenLoc, 6431 SourceLocation RParenLoc); 6432 6433 /// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off]. 6434 void ActOnPragmaMSStruct(PragmaMSStructKind Kind); 6435 6436 /// ActOnPragmaUnused - Called on well-formed '\#pragma unused'. 6437 void ActOnPragmaUnused(const Token &Identifier, 6438 Scope *curScope, 6439 SourceLocation PragmaLoc); 6440 6441 /// ActOnPragmaVisibility - Called on well formed \#pragma GCC visibility... . 6442 void ActOnPragmaVisibility(const IdentifierInfo* VisType, 6443 SourceLocation PragmaLoc); 6444 6445 NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II, 6446 SourceLocation Loc); 6447 void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W); 6448 6449 /// ActOnPragmaWeakID - Called on well formed \#pragma weak ident. 6450 void ActOnPragmaWeakID(IdentifierInfo* WeakName, 6451 SourceLocation PragmaLoc, 6452 SourceLocation WeakNameLoc); 6453 6454 /// ActOnPragmaRedefineExtname - Called on well formed 6455 /// \#pragma redefine_extname oldname newname. 6456 void ActOnPragmaRedefineExtname(IdentifierInfo* WeakName, 6457 IdentifierInfo* AliasName, 6458 SourceLocation PragmaLoc, 6459 SourceLocation WeakNameLoc, 6460 SourceLocation AliasNameLoc); 6461 6462 /// ActOnPragmaWeakAlias - Called on well formed \#pragma weak ident = ident. 6463 void ActOnPragmaWeakAlias(IdentifierInfo* WeakName, 6464 IdentifierInfo* AliasName, 6465 SourceLocation PragmaLoc, 6466 SourceLocation WeakNameLoc, 6467 SourceLocation AliasNameLoc); 6468 6469 /// ActOnPragmaFPContract - Called on well formed 6470 /// \#pragma {STDC,OPENCL} FP_CONTRACT 6471 void ActOnPragmaFPContract(tok::OnOffSwitch OOS); 6472 6473 /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to 6474 /// a the record decl, to handle '\#pragma pack' and '\#pragma options align'. 6475 void AddAlignmentAttributesForRecord(RecordDecl *RD); 6476 6477 /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record. 6478 void AddMsStructLayoutForRecord(RecordDecl *RD); 6479 6480 /// FreePackedContext - Deallocate and null out PackContext. 6481 void FreePackedContext(); 6482 6483 /// PushNamespaceVisibilityAttr - Note that we've entered a 6484 /// namespace with a visibility attribute. 6485 void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, 6486 SourceLocation Loc); 6487 6488 /// AddPushedVisibilityAttribute - If '\#pragma GCC visibility' was used, 6489 /// add an appropriate visibility attribute. 6490 void AddPushedVisibilityAttribute(Decl *RD); 6491 6492 /// PopPragmaVisibility - Pop the top element of the visibility stack; used 6493 /// for '\#pragma GCC visibility' and visibility attributes on namespaces. 6494 void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc); 6495 6496 /// FreeVisContext - Deallocate and null out VisContext. 6497 void FreeVisContext(); 6498 6499 /// AddCFAuditedAttribute - Check whether we're currently within 6500 /// '\#pragma clang arc_cf_code_audited' and, if so, consider adding 6501 /// the appropriate attribute. 6502 void AddCFAuditedAttribute(Decl *D); 6503 6504 /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. 6505 void AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E, 6506 bool isDeclSpec); 6507 void AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *T, 6508 bool isDeclSpec); 6509 6510 /// \brief The kind of conversion being performed. 6511 enum CheckedConversionKind { 6512 /// \brief An implicit conversion. 6513 CCK_ImplicitConversion, 6514 /// \brief A C-style cast. 6515 CCK_CStyleCast, 6516 /// \brief A functional-style cast. 6517 CCK_FunctionalCast, 6518 /// \brief A cast other than a C-style cast. 6519 CCK_OtherCast 6520 }; 6521 6522 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit 6523 /// cast. If there is already an implicit cast, merge into the existing one. 6524 /// If isLvalue, the result of the cast is an lvalue. 6525 ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, 6526 ExprValueKind VK = VK_RValue, 6527 const CXXCastPath *BasePath = 0, 6528 CheckedConversionKind CCK 6529 = CCK_ImplicitConversion); 6530 6531 /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding 6532 /// to the conversion from scalar type ScalarTy to the Boolean type. 6533 static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy); 6534 6535 /// IgnoredValueConversions - Given that an expression's result is 6536 /// syntactically ignored, perform any conversions that are 6537 /// required. 6538 ExprResult IgnoredValueConversions(Expr *E); 6539 6540 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts 6541 // functions and arrays to their respective pointers (C99 6.3.2.1). 6542 ExprResult UsualUnaryConversions(Expr *E); 6543 6544 // DefaultFunctionArrayConversion - converts functions and arrays 6545 // to their respective pointers (C99 6.3.2.1). 6546 ExprResult DefaultFunctionArrayConversion(Expr *E); 6547 6548 // DefaultFunctionArrayLvalueConversion - converts functions and 6549 // arrays to their respective pointers and performs the 6550 // lvalue-to-rvalue conversion. 6551 ExprResult DefaultFunctionArrayLvalueConversion(Expr *E); 6552 6553 // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on 6554 // the operand. This is DefaultFunctionArrayLvalueConversion, 6555 // except that it assumes the operand isn't of function or array 6556 // type. 6557 ExprResult DefaultLvalueConversion(Expr *E); 6558 6559 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that 6560 // do not have a prototype. Integer promotions are performed on each 6561 // argument, and arguments that have type float are promoted to double. 6562 ExprResult DefaultArgumentPromotion(Expr *E); 6563 6564 // Used for emitting the right warning by DefaultVariadicArgumentPromotion 6565 enum VariadicCallType { 6566 VariadicFunction, 6567 VariadicBlock, 6568 VariadicMethod, 6569 VariadicConstructor, 6570 VariadicDoesNotApply 6571 }; 6572 6573 VariadicCallType getVariadicCallType(FunctionDecl *FDecl, 6574 const FunctionProtoType *Proto, 6575 Expr *Fn); 6576 6577 // Used for determining in which context a type is allowed to be passed to a 6578 // vararg function. 6579 enum VarArgKind { 6580 VAK_Valid, 6581 VAK_ValidInCXX11, 6582 VAK_Invalid 6583 }; 6584 6585 // Determines which VarArgKind fits an expression. 6586 VarArgKind isValidVarArgType(const QualType &Ty); 6587 6588 /// GatherArgumentsForCall - Collector argument expressions for various 6589 /// form of call prototypes. 6590 bool GatherArgumentsForCall(SourceLocation CallLoc, 6591 FunctionDecl *FDecl, 6592 const FunctionProtoType *Proto, 6593 unsigned FirstProtoArg, 6594 Expr **Args, unsigned NumArgs, 6595 SmallVector<Expr *, 8> &AllArgs, 6596 VariadicCallType CallType = VariadicDoesNotApply, 6597 bool AllowExplicit = false); 6598 6599 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but 6600 // will create a runtime trap if the resulting type is not a POD type. 6601 ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, 6602 FunctionDecl *FDecl); 6603 6604 /// Checks to see if the given expression is a valid argument to a variadic 6605 /// function, issuing a diagnostic and returning NULL if not. 6606 bool variadicArgumentPODCheck(const Expr *E, VariadicCallType CT); 6607 6608 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's 6609 // operands and then handles various conversions that are common to binary 6610 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this 6611 // routine returns the first non-arithmetic type found. The client is 6612 // responsible for emitting appropriate error diagnostics. 6613 QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS, 6614 bool IsCompAssign = false); 6615 6616 /// AssignConvertType - All of the 'assignment' semantic checks return this 6617 /// enum to indicate whether the assignment was allowed. These checks are 6618 /// done for simple assignments, as well as initialization, return from 6619 /// function, argument passing, etc. The query is phrased in terms of a 6620 /// source and destination type. 6621 enum AssignConvertType { 6622 /// Compatible - the types are compatible according to the standard. 6623 Compatible, 6624 6625 /// PointerToInt - The assignment converts a pointer to an int, which we 6626 /// accept as an extension. 6627 PointerToInt, 6628 6629 /// IntToPointer - The assignment converts an int to a pointer, which we 6630 /// accept as an extension. 6631 IntToPointer, 6632 6633 /// FunctionVoidPointer - The assignment is between a function pointer and 6634 /// void*, which the standard doesn't allow, but we accept as an extension. 6635 FunctionVoidPointer, 6636 6637 /// IncompatiblePointer - The assignment is between two pointers types that 6638 /// are not compatible, but we accept them as an extension. 6639 IncompatiblePointer, 6640 6641 /// IncompatiblePointer - The assignment is between two pointers types which 6642 /// point to integers which have a different sign, but are otherwise 6643 /// identical. This is a subset of the above, but broken out because it's by 6644 /// far the most common case of incompatible pointers. 6645 IncompatiblePointerSign, 6646 6647 /// CompatiblePointerDiscardsQualifiers - The assignment discards 6648 /// c/v/r qualifiers, which we accept as an extension. 6649 CompatiblePointerDiscardsQualifiers, 6650 6651 /// IncompatiblePointerDiscardsQualifiers - The assignment 6652 /// discards qualifiers that we don't permit to be discarded, 6653 /// like address spaces. 6654 IncompatiblePointerDiscardsQualifiers, 6655 6656 /// IncompatibleNestedPointerQualifiers - The assignment is between two 6657 /// nested pointer types, and the qualifiers other than the first two 6658 /// levels differ e.g. char ** -> const char **, but we accept them as an 6659 /// extension. 6660 IncompatibleNestedPointerQualifiers, 6661 6662 /// IncompatibleVectors - The assignment is between two vector types that 6663 /// have the same size, which we accept as an extension. 6664 IncompatibleVectors, 6665 6666 /// IntToBlockPointer - The assignment converts an int to a block 6667 /// pointer. We disallow this. 6668 IntToBlockPointer, 6669 6670 /// IncompatibleBlockPointer - The assignment is between two block 6671 /// pointers types that are not compatible. 6672 IncompatibleBlockPointer, 6673 6674 /// IncompatibleObjCQualifiedId - The assignment is between a qualified 6675 /// id type and something else (that is incompatible with it). For example, 6676 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. 6677 IncompatibleObjCQualifiedId, 6678 6679 /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an 6680 /// object with __weak qualifier. 6681 IncompatibleObjCWeakRef, 6682 6683 /// Incompatible - We reject this conversion outright, it is invalid to 6684 /// represent it in the AST. 6685 Incompatible 6686 }; 6687 6688 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the 6689 /// assignment conversion type specified by ConvTy. This returns true if the 6690 /// conversion was invalid or false if the conversion was accepted. 6691 bool DiagnoseAssignmentResult(AssignConvertType ConvTy, 6692 SourceLocation Loc, 6693 QualType DstType, QualType SrcType, 6694 Expr *SrcExpr, AssignmentAction Action, 6695 bool *Complained = 0); 6696 6697 /// DiagnoseAssignmentEnum - Warn if assignment to enum is a constant 6698 /// integer not in the range of enum values. 6699 void DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, 6700 Expr *SrcExpr); 6701 6702 /// CheckAssignmentConstraints - Perform type checking for assignment, 6703 /// argument passing, variable initialization, and function return values. 6704 /// C99 6.5.16. 6705 AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, 6706 QualType LHSType, 6707 QualType RHSType); 6708 6709 /// Check assignment constraints and prepare for a conversion of the 6710 /// RHS to the LHS type. 6711 AssignConvertType CheckAssignmentConstraints(QualType LHSType, 6712 ExprResult &RHS, 6713 CastKind &Kind); 6714 6715 // CheckSingleAssignmentConstraints - Currently used by 6716 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking, 6717 // this routine performs the default function/array converions. 6718 AssignConvertType CheckSingleAssignmentConstraints(QualType LHSType, 6719 ExprResult &RHS, 6720 bool Diagnose = true); 6721 6722 // \brief If the lhs type is a transparent union, check whether we 6723 // can initialize the transparent union with the given expression. 6724 AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType, 6725 ExprResult &RHS); 6726 6727 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); 6728 6729 bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType); 6730 6731 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6732 AssignmentAction Action, 6733 bool AllowExplicit = false); 6734 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6735 AssignmentAction Action, 6736 bool AllowExplicit, 6737 ImplicitConversionSequence& ICS); 6738 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6739 const ImplicitConversionSequence& ICS, 6740 AssignmentAction Action, 6741 CheckedConversionKind CCK 6742 = CCK_ImplicitConversion); 6743 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6744 const StandardConversionSequence& SCS, 6745 AssignmentAction Action, 6746 CheckedConversionKind CCK); 6747 6748 /// the following "Check" methods will return a valid/converted QualType 6749 /// or a null QualType (indicating an error diagnostic was issued). 6750 6751 /// type checking binary operators (subroutines of CreateBuiltinBinOp). 6752 QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS, 6753 ExprResult &RHS); 6754 QualType CheckPointerToMemberOperands( // C++ 5.5 6755 ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK, 6756 SourceLocation OpLoc, bool isIndirect); 6757 QualType CheckMultiplyDivideOperands( // C99 6.5.5 6758 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign, 6759 bool IsDivide); 6760 QualType CheckRemainderOperands( // C99 6.5.5 6761 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, 6762 bool IsCompAssign = false); 6763 QualType CheckAdditionOperands( // C99 6.5.6 6764 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc, 6765 QualType* CompLHSTy = 0); 6766 QualType CheckSubtractionOperands( // C99 6.5.6 6767 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, 6768 QualType* CompLHSTy = 0); 6769 QualType CheckShiftOperands( // C99 6.5.7 6770 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc, 6771 bool IsCompAssign = false); 6772 QualType CheckCompareOperands( // C99 6.5.8/9 6773 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned OpaqueOpc, 6774 bool isRelational); 6775 QualType CheckBitwiseOperands( // C99 6.5.[10...12] 6776 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, 6777 bool IsCompAssign = false); 6778 QualType CheckLogicalOperands( // C99 6.5.[13,14] 6779 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc); 6780 // CheckAssignmentOperands is used for both simple and compound assignment. 6781 // For simple assignment, pass both expressions and a null converted type. 6782 // For compound assignment, pass both expressions and the converted type. 6783 QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] 6784 Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType); 6785 6786 ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc, 6787 UnaryOperatorKind Opcode, Expr *Op); 6788 ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc, 6789 BinaryOperatorKind Opcode, 6790 Expr *LHS, Expr *RHS); 6791 ExprResult checkPseudoObjectRValue(Expr *E); 6792 Expr *recreateSyntacticForm(PseudoObjectExpr *E); 6793 6794 QualType CheckConditionalOperands( // C99 6.5.15 6795 ExprResult &Cond, ExprResult &LHS, ExprResult &RHS, 6796 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation QuestionLoc); 6797 QualType CXXCheckConditionalOperands( // C++ 5.16 6798 ExprResult &cond, ExprResult &lhs, ExprResult &rhs, 6799 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc); 6800 QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2, 6801 bool *NonStandardCompositeType = 0); 6802 QualType FindCompositePointerType(SourceLocation Loc, 6803 ExprResult &E1, ExprResult &E2, 6804 bool *NonStandardCompositeType = 0) { 6805 Expr *E1Tmp = E1.take(), *E2Tmp = E2.take(); 6806 QualType Composite = FindCompositePointerType(Loc, E1Tmp, E2Tmp, 6807 NonStandardCompositeType); 6808 E1 = Owned(E1Tmp); 6809 E2 = Owned(E2Tmp); 6810 return Composite; 6811 } 6812 6813 QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS, 6814 SourceLocation QuestionLoc); 6815 6816 bool DiagnoseConditionalForNull(Expr *LHSExpr, Expr *RHSExpr, 6817 SourceLocation QuestionLoc); 6818 6819 /// type checking for vector binary operators. 6820 QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS, 6821 SourceLocation Loc, bool IsCompAssign); 6822 QualType GetSignedVectorType(QualType V); 6823 QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS, 6824 SourceLocation Loc, bool isRelational); 6825 QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS, 6826 SourceLocation Loc); 6827 6828 /// type checking declaration initializers (C99 6.7.8) 6829 bool CheckForConstantInitializer(Expr *e, QualType t); 6830 6831 // type checking C++ declaration initializers (C++ [dcl.init]). 6832 6833 /// ReferenceCompareResult - Expresses the result of comparing two 6834 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the 6835 /// purposes of initialization by reference (C++ [dcl.init.ref]p4). 6836 enum ReferenceCompareResult { 6837 /// Ref_Incompatible - The two types are incompatible, so direct 6838 /// reference binding is not possible. 6839 Ref_Incompatible = 0, 6840 /// Ref_Related - The two types are reference-related, which means 6841 /// that their unqualified forms (T1 and T2) are either the same 6842 /// or T1 is a base class of T2. 6843 Ref_Related, 6844 /// Ref_Compatible_With_Added_Qualification - The two types are 6845 /// reference-compatible with added qualification, meaning that 6846 /// they are reference-compatible and the qualifiers on T1 (cv1) 6847 /// are greater than the qualifiers on T2 (cv2). 6848 Ref_Compatible_With_Added_Qualification, 6849 /// Ref_Compatible - The two types are reference-compatible and 6850 /// have equivalent qualifiers (cv1 == cv2). 6851 Ref_Compatible 6852 }; 6853 6854 ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc, 6855 QualType T1, QualType T2, 6856 bool &DerivedToBase, 6857 bool &ObjCConversion, 6858 bool &ObjCLifetimeConversion); 6859 6860 ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType, 6861 Expr *CastExpr, CastKind &CastKind, 6862 ExprValueKind &VK, CXXCastPath &Path); 6863 6864 /// \brief Force an expression with unknown-type to an expression of the 6865 /// given type. 6866 ExprResult forceUnknownAnyToType(Expr *E, QualType ToType); 6867 6868 /// \brief Handle an expression that's being passed to an 6869 /// __unknown_anytype parameter. 6870 /// 6871 /// \return the effective parameter type to use, or null if the 6872 /// argument is invalid. 6873 QualType checkUnknownAnyArg(Expr *&result); 6874 6875 // CheckVectorCast - check type constraints for vectors. 6876 // Since vectors are an extension, there are no C standard reference for this. 6877 // We allow casting between vectors and integer datatypes of the same size. 6878 // returns true if the cast is invalid 6879 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, 6880 CastKind &Kind); 6881 6882 // CheckExtVectorCast - check type constraints for extended vectors. 6883 // Since vectors are an extension, there are no C standard reference for this. 6884 // We allow casting between vectors and integer datatypes of the same size, 6885 // or vectors and the element type of that vector. 6886 // returns the cast expr 6887 ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr, 6888 CastKind &Kind); 6889 6890 ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, 6891 SourceLocation LParenLoc, 6892 Expr *CastExpr, 6893 SourceLocation RParenLoc); 6894 6895 enum ARCConversionResult { ACR_okay, ACR_unbridged }; 6896 6897 /// \brief Checks for invalid conversions and casts between 6898 /// retainable pointers and other pointer kinds. 6899 ARCConversionResult CheckObjCARCConversion(SourceRange castRange, 6900 QualType castType, Expr *&op, 6901 CheckedConversionKind CCK); 6902 6903 Expr *stripARCUnbridgedCast(Expr *e); 6904 void diagnoseARCUnbridgedCast(Expr *e); 6905 6906 bool CheckObjCARCUnavailableWeakConversion(QualType castType, 6907 QualType ExprType); 6908 6909 /// checkRetainCycles - Check whether an Objective-C message send 6910 /// might create an obvious retain cycle. 6911 void checkRetainCycles(ObjCMessageExpr *msg); 6912 void checkRetainCycles(Expr *receiver, Expr *argument); 6913 void checkRetainCycles(VarDecl *Var, Expr *Init); 6914 6915 /// checkUnsafeAssigns - Check whether +1 expr is being assigned 6916 /// to weak/__unsafe_unretained type. 6917 bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS); 6918 6919 /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned 6920 /// to weak/__unsafe_unretained expression. 6921 void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS); 6922 6923 /// CheckMessageArgumentTypes - Check types in an Obj-C message send. 6924 /// \param Method - May be null. 6925 /// \param [out] ReturnType - The return type of the send. 6926 /// \return true iff there were any incompatible types. 6927 bool CheckMessageArgumentTypes(QualType ReceiverType, 6928 Expr **Args, unsigned NumArgs, Selector Sel, 6929 ArrayRef<SourceLocation> SelectorLocs, 6930 ObjCMethodDecl *Method, bool isClassMessage, 6931 bool isSuperMessage, 6932 SourceLocation lbrac, SourceLocation rbrac, 6933 QualType &ReturnType, ExprValueKind &VK); 6934 6935 /// \brief Determine the result of a message send expression based on 6936 /// the type of the receiver, the method expected to receive the message, 6937 /// and the form of the message send. 6938 QualType getMessageSendResultType(QualType ReceiverType, 6939 ObjCMethodDecl *Method, 6940 bool isClassMessage, bool isSuperMessage); 6941 6942 /// \brief If the given expression involves a message send to a method 6943 /// with a related result type, emit a note describing what happened. 6944 void EmitRelatedResultTypeNote(const Expr *E); 6945 6946 /// CheckBooleanCondition - Diagnose problems involving the use of 6947 /// the given expression as a boolean condition (e.g. in an if 6948 /// statement). Also performs the standard function and array 6949 /// decays, possibly changing the input variable. 6950 /// 6951 /// \param Loc - A location associated with the condition, e.g. the 6952 /// 'if' keyword. 6953 /// \return true iff there were any errors 6954 ExprResult CheckBooleanCondition(Expr *E, SourceLocation Loc); 6955 6956 ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc, 6957 Expr *SubExpr); 6958 6959 /// DiagnoseAssignmentAsCondition - Given that an expression is 6960 /// being used as a boolean condition, warn if it's an assignment. 6961 void DiagnoseAssignmentAsCondition(Expr *E); 6962 6963 /// \brief Redundant parentheses over an equality comparison can indicate 6964 /// that the user intended an assignment used as condition. 6965 void DiagnoseEqualityWithExtraParens(ParenExpr *ParenE); 6966 6967 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. 6968 ExprResult CheckCXXBooleanCondition(Expr *CondExpr); 6969 6970 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have 6971 /// the specified width and sign. If an overflow occurs, detect it and emit 6972 /// the specified diagnostic. 6973 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, 6974 unsigned NewWidth, bool NewSign, 6975 SourceLocation Loc, unsigned DiagID); 6976 6977 /// Checks that the Objective-C declaration is declared in the global scope. 6978 /// Emits an error and marks the declaration as invalid if it's not declared 6979 /// in the global scope. 6980 bool CheckObjCDeclScope(Decl *D); 6981 6982 /// \brief Abstract base class used for diagnosing integer constant 6983 /// expression violations. 6984 class VerifyICEDiagnoser { 6985 public: 6986 bool Suppress; 6987 6988 VerifyICEDiagnoser(bool Suppress = false) : Suppress(Suppress) { } 6989 6990 virtual void diagnoseNotICE(Sema &S, SourceLocation Loc, SourceRange SR) =0; 6991 virtual void diagnoseFold(Sema &S, SourceLocation Loc, SourceRange SR); 6992 virtual ~VerifyICEDiagnoser() { } 6993 }; 6994 6995 /// VerifyIntegerConstantExpression - Verifies that an expression is an ICE, 6996 /// and reports the appropriate diagnostics. Returns false on success. 6997 /// Can optionally return the value of the expression. 6998 ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, 6999 VerifyICEDiagnoser &Diagnoser, 7000 bool AllowFold = true); 7001 ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, 7002 unsigned DiagID, 7003 bool AllowFold = true); 7004 ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result=0); 7005 7006 /// VerifyBitField - verifies that a bit field expression is an ICE and has 7007 /// the correct width, and that the field type is valid. 7008 /// Returns false on success. 7009 /// Can optionally return whether the bit-field is of width 0 7010 ExprResult VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, 7011 QualType FieldTy, Expr *BitWidth, 7012 bool *ZeroWidth = 0); 7013 7014 enum CUDAFunctionTarget { 7015 CFT_Device, 7016 CFT_Global, 7017 CFT_Host, 7018 CFT_HostDevice 7019 }; 7020 7021 CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D); 7022 7023 bool CheckCUDATarget(CUDAFunctionTarget CallerTarget, 7024 CUDAFunctionTarget CalleeTarget); 7025 7026 bool CheckCUDATarget(const FunctionDecl *Caller, const FunctionDecl *Callee) { 7027 return CheckCUDATarget(IdentifyCUDATarget(Caller), 7028 IdentifyCUDATarget(Callee)); 7029 } 7030 7031 /// \name Code completion 7032 //@{ 7033 /// \brief Describes the context in which code completion occurs. 7034 enum ParserCompletionContext { 7035 /// \brief Code completion occurs at top-level or namespace context. 7036 PCC_Namespace, 7037 /// \brief Code completion occurs within a class, struct, or union. 7038 PCC_Class, 7039 /// \brief Code completion occurs within an Objective-C interface, protocol, 7040 /// or category. 7041 PCC_ObjCInterface, 7042 /// \brief Code completion occurs within an Objective-C implementation or 7043 /// category implementation 7044 PCC_ObjCImplementation, 7045 /// \brief Code completion occurs within the list of instance variables 7046 /// in an Objective-C interface, protocol, category, or implementation. 7047 PCC_ObjCInstanceVariableList, 7048 /// \brief Code completion occurs following one or more template 7049 /// headers. 7050 PCC_Template, 7051 /// \brief Code completion occurs following one or more template 7052 /// headers within a class. 7053 PCC_MemberTemplate, 7054 /// \brief Code completion occurs within an expression. 7055 PCC_Expression, 7056 /// \brief Code completion occurs within a statement, which may 7057 /// also be an expression or a declaration. 7058 PCC_Statement, 7059 /// \brief Code completion occurs at the beginning of the 7060 /// initialization statement (or expression) in a for loop. 7061 PCC_ForInit, 7062 /// \brief Code completion occurs within the condition of an if, 7063 /// while, switch, or for statement. 7064 PCC_Condition, 7065 /// \brief Code completion occurs within the body of a function on a 7066 /// recovery path, where we do not have a specific handle on our position 7067 /// in the grammar. 7068 PCC_RecoveryInFunction, 7069 /// \brief Code completion occurs where only a type is permitted. 7070 PCC_Type, 7071 /// \brief Code completion occurs in a parenthesized expression, which 7072 /// might also be a type cast. 7073 PCC_ParenthesizedExpression, 7074 /// \brief Code completion occurs within a sequence of declaration 7075 /// specifiers within a function, method, or block. 7076 PCC_LocalDeclarationSpecifiers 7077 }; 7078 7079 void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path); 7080 void CodeCompleteOrdinaryName(Scope *S, 7081 ParserCompletionContext CompletionContext); 7082 void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, 7083 bool AllowNonIdentifiers, 7084 bool AllowNestedNameSpecifiers); 7085 7086 struct CodeCompleteExpressionData; 7087 void CodeCompleteExpression(Scope *S, 7088 const CodeCompleteExpressionData &Data); 7089 void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, 7090 SourceLocation OpLoc, 7091 bool IsArrow); 7092 void CodeCompletePostfixExpression(Scope *S, ExprResult LHS); 7093 void CodeCompleteTag(Scope *S, unsigned TagSpec); 7094 void CodeCompleteTypeQualifiers(DeclSpec &DS); 7095 void CodeCompleteCase(Scope *S); 7096 void CodeCompleteCall(Scope *S, Expr *Fn, ArrayRef<Expr *> Args); 7097 void CodeCompleteInitializer(Scope *S, Decl *D); 7098 void CodeCompleteReturn(Scope *S); 7099 void CodeCompleteAfterIf(Scope *S); 7100 void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS); 7101 7102 void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, 7103 bool EnteringContext); 7104 void CodeCompleteUsing(Scope *S); 7105 void CodeCompleteUsingDirective(Scope *S); 7106 void CodeCompleteNamespaceDecl(Scope *S); 7107 void CodeCompleteNamespaceAliasDecl(Scope *S); 7108 void CodeCompleteOperatorName(Scope *S); 7109 void CodeCompleteConstructorInitializer(Decl *Constructor, 7110 CXXCtorInitializer** Initializers, 7111 unsigned NumInitializers); 7112 void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, 7113 bool AfterAmpersand); 7114 7115 void CodeCompleteObjCAtDirective(Scope *S); 7116 void CodeCompleteObjCAtVisibility(Scope *S); 7117 void CodeCompleteObjCAtStatement(Scope *S); 7118 void CodeCompleteObjCAtExpression(Scope *S); 7119 void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS); 7120 void CodeCompleteObjCPropertyGetter(Scope *S); 7121 void CodeCompleteObjCPropertySetter(Scope *S); 7122 void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, 7123 bool IsParameter); 7124 void CodeCompleteObjCMessageReceiver(Scope *S); 7125 void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, 7126 IdentifierInfo **SelIdents, 7127 unsigned NumSelIdents, 7128 bool AtArgumentExpression); 7129 void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, 7130 IdentifierInfo **SelIdents, 7131 unsigned NumSelIdents, 7132 bool AtArgumentExpression, 7133 bool IsSuper = false); 7134 void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, 7135 IdentifierInfo **SelIdents, 7136 unsigned NumSelIdents, 7137 bool AtArgumentExpression, 7138 ObjCInterfaceDecl *Super = 0); 7139 void CodeCompleteObjCForCollection(Scope *S, 7140 DeclGroupPtrTy IterationVar); 7141 void CodeCompleteObjCSelector(Scope *S, 7142 IdentifierInfo **SelIdents, 7143 unsigned NumSelIdents); 7144 void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols, 7145 unsigned NumProtocols); 7146 void CodeCompleteObjCProtocolDecl(Scope *S); 7147 void CodeCompleteObjCInterfaceDecl(Scope *S); 7148 void CodeCompleteObjCSuperclass(Scope *S, 7149 IdentifierInfo *ClassName, 7150 SourceLocation ClassNameLoc); 7151 void CodeCompleteObjCImplementationDecl(Scope *S); 7152 void CodeCompleteObjCInterfaceCategory(Scope *S, 7153 IdentifierInfo *ClassName, 7154 SourceLocation ClassNameLoc); 7155 void CodeCompleteObjCImplementationCategory(Scope *S, 7156 IdentifierInfo *ClassName, 7157 SourceLocation ClassNameLoc); 7158 void CodeCompleteObjCPropertyDefinition(Scope *S); 7159 void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, 7160 IdentifierInfo *PropertyName); 7161 void CodeCompleteObjCMethodDecl(Scope *S, 7162 bool IsInstanceMethod, 7163 ParsedType ReturnType); 7164 void CodeCompleteObjCMethodDeclSelector(Scope *S, 7165 bool IsInstanceMethod, 7166 bool AtParameterName, 7167 ParsedType ReturnType, 7168 IdentifierInfo **SelIdents, 7169 unsigned NumSelIdents); 7170 void CodeCompletePreprocessorDirective(bool InConditional); 7171 void CodeCompleteInPreprocessorConditionalExclusion(Scope *S); 7172 void CodeCompletePreprocessorMacroName(bool IsDefinition); 7173 void CodeCompletePreprocessorExpression(); 7174 void CodeCompletePreprocessorMacroArgument(Scope *S, 7175 IdentifierInfo *Macro, 7176 MacroInfo *MacroInfo, 7177 unsigned Argument); 7178 void CodeCompleteNaturalLanguage(); 7179 void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, 7180 CodeCompletionTUInfo &CCTUInfo, 7181 SmallVectorImpl<CodeCompletionResult> &Results); 7182 //@} 7183 7184 //===--------------------------------------------------------------------===// 7185 // Extra semantic analysis beyond the C type system 7186 7187public: 7188 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, 7189 unsigned ByteNo) const; 7190 7191private: 7192 void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr, 7193 const ArraySubscriptExpr *ASE=0, 7194 bool AllowOnePastEnd=true, bool IndexNegated=false); 7195 void CheckArrayAccess(const Expr *E); 7196 // Used to grab the relevant information from a FormatAttr and a 7197 // FunctionDeclaration. 7198 struct FormatStringInfo { 7199 unsigned FormatIdx; 7200 unsigned FirstDataArg; 7201 bool HasVAListArg; 7202 }; 7203 7204 bool getFormatStringInfo(const FormatAttr *Format, bool IsCXXMember, 7205 FormatStringInfo *FSI); 7206 bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall, 7207 const FunctionProtoType *Proto); 7208 bool CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation loc, 7209 Expr **Args, unsigned NumArgs); 7210 bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall, 7211 const FunctionProtoType *Proto); 7212 void CheckConstructorCall(FunctionDecl *FDecl, 7213 ArrayRef<const Expr *> Args, 7214 const FunctionProtoType *Proto, 7215 SourceLocation Loc); 7216 7217 void checkCall(NamedDecl *FDecl, ArrayRef<const Expr *> Args, 7218 unsigned NumProtoArgs, bool IsMemberFunction, 7219 SourceLocation Loc, SourceRange Range, 7220 VariadicCallType CallType); 7221 7222 7223 bool CheckObjCString(Expr *Arg); 7224 7225 ExprResult CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 7226 bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 7227 bool CheckMipsBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 7228 7229 bool SemaBuiltinVAStart(CallExpr *TheCall); 7230 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall); 7231 bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs); 7232 7233public: 7234 // Used by C++ template instantiation. 7235 ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); 7236 7237private: 7238 bool SemaBuiltinPrefetch(CallExpr *TheCall); 7239 bool SemaBuiltinObjectSize(CallExpr *TheCall); 7240 bool SemaBuiltinLongjmp(CallExpr *TheCall); 7241 ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult); 7242 ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult, 7243 AtomicExpr::AtomicOp Op); 7244 bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum, 7245 llvm::APSInt &Result); 7246 7247 enum FormatStringType { 7248 FST_Scanf, 7249 FST_Printf, 7250 FST_NSString, 7251 FST_Strftime, 7252 FST_Strfmon, 7253 FST_Kprintf, 7254 FST_Unknown 7255 }; 7256 static FormatStringType GetFormatStringType(const FormatAttr *Format); 7257 7258 enum StringLiteralCheckType { 7259 SLCT_NotALiteral, 7260 SLCT_UncheckedLiteral, 7261 SLCT_CheckedLiteral 7262 }; 7263 7264 StringLiteralCheckType checkFormatStringExpr(const Expr *E, 7265 ArrayRef<const Expr *> Args, 7266 bool HasVAListArg, 7267 unsigned format_idx, 7268 unsigned firstDataArg, 7269 FormatStringType Type, 7270 VariadicCallType CallType, 7271 bool inFunctionCall = true); 7272 7273 void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr, 7274 ArrayRef<const Expr *> Args, bool HasVAListArg, 7275 unsigned format_idx, unsigned firstDataArg, 7276 FormatStringType Type, bool inFunctionCall, 7277 VariadicCallType CallType); 7278 7279 bool CheckFormatArguments(const FormatAttr *Format, 7280 ArrayRef<const Expr *> Args, 7281 bool IsCXXMember, 7282 VariadicCallType CallType, 7283 SourceLocation Loc, SourceRange Range); 7284 bool CheckFormatArguments(ArrayRef<const Expr *> Args, 7285 bool HasVAListArg, unsigned format_idx, 7286 unsigned firstDataArg, FormatStringType Type, 7287 VariadicCallType CallType, 7288 SourceLocation Loc, SourceRange range); 7289 7290 void CheckNonNullArguments(const NonNullAttr *NonNull, 7291 const Expr * const *ExprArgs, 7292 SourceLocation CallSiteLoc); 7293 7294 void CheckMemaccessArguments(const CallExpr *Call, 7295 unsigned BId, 7296 IdentifierInfo *FnName); 7297 7298 void CheckStrlcpycatArguments(const CallExpr *Call, 7299 IdentifierInfo *FnName); 7300 7301 void CheckStrncatArguments(const CallExpr *Call, 7302 IdentifierInfo *FnName); 7303 7304 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, 7305 SourceLocation ReturnLoc); 7306 void CheckFloatComparison(SourceLocation Loc, Expr* LHS, Expr* RHS); 7307 void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation()); 7308 7309 void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field, 7310 Expr *Init); 7311 7312public: 7313 /// \brief Register a magic integral constant to be used as a type tag. 7314 void RegisterTypeTagForDatatype(const IdentifierInfo *ArgumentKind, 7315 uint64_t MagicValue, QualType Type, 7316 bool LayoutCompatible, bool MustBeNull); 7317 7318 struct TypeTagData { 7319 TypeTagData() {} 7320 7321 TypeTagData(QualType Type, bool LayoutCompatible, bool MustBeNull) : 7322 Type(Type), LayoutCompatible(LayoutCompatible), 7323 MustBeNull(MustBeNull) 7324 {} 7325 7326 QualType Type; 7327 7328 /// If true, \c Type should be compared with other expression's types for 7329 /// layout-compatibility. 7330 unsigned LayoutCompatible : 1; 7331 unsigned MustBeNull : 1; 7332 }; 7333 7334 /// A pair of ArgumentKind identifier and magic value. This uniquely 7335 /// identifies the magic value. 7336 typedef std::pair<const IdentifierInfo *, uint64_t> TypeTagMagicValue; 7337 7338private: 7339 /// \brief A map from magic value to type information. 7340 OwningPtr<llvm::DenseMap<TypeTagMagicValue, TypeTagData> > 7341 TypeTagForDatatypeMagicValues; 7342 7343 /// \brief Peform checks on a call of a function with argument_with_type_tag 7344 /// or pointer_with_type_tag attributes. 7345 void CheckArgumentWithTypeTag(const ArgumentWithTypeTagAttr *Attr, 7346 const Expr * const *ExprArgs); 7347 7348 /// \brief The parser's current scope. 7349 /// 7350 /// The parser maintains this state here. 7351 Scope *CurScope; 7352 7353protected: 7354 friend class Parser; 7355 friend class InitializationSequence; 7356 friend class ASTReader; 7357 friend class ASTWriter; 7358 7359public: 7360 /// \brief Retrieve the parser's current scope. 7361 /// 7362 /// This routine must only be used when it is certain that semantic analysis 7363 /// and the parser are in precisely the same context, which is not the case 7364 /// when, e.g., we are performing any kind of template instantiation. 7365 /// Therefore, the only safe places to use this scope are in the parser 7366 /// itself and in routines directly invoked from the parser and *never* from 7367 /// template substitution or instantiation. 7368 Scope *getCurScope() const { return CurScope; } 7369 7370 Decl *getObjCDeclContext() const; 7371 7372 DeclContext *getCurLexicalContext() const { 7373 return OriginalLexicalContext ? OriginalLexicalContext : CurContext; 7374 } 7375 7376 AvailabilityResult getCurContextAvailability() const; 7377 7378 const DeclContext *getCurObjCLexicalContext() const { 7379 const DeclContext *DC = getCurLexicalContext(); 7380 // A category implicitly has the attribute of the interface. 7381 if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(DC)) 7382 DC = CatD->getClassInterface(); 7383 return DC; 7384 } 7385}; 7386 7387/// \brief RAII object that enters a new expression evaluation context. 7388class EnterExpressionEvaluationContext { 7389 Sema &Actions; 7390 7391public: 7392 EnterExpressionEvaluationContext(Sema &Actions, 7393 Sema::ExpressionEvaluationContext NewContext, 7394 Decl *LambdaContextDecl = 0, 7395 bool IsDecltype = false) 7396 : Actions(Actions) { 7397 Actions.PushExpressionEvaluationContext(NewContext, LambdaContextDecl, 7398 IsDecltype); 7399 } 7400 EnterExpressionEvaluationContext(Sema &Actions, 7401 Sema::ExpressionEvaluationContext NewContext, 7402 Sema::ReuseLambdaContextDecl_t, 7403 bool IsDecltype = false) 7404 : Actions(Actions) { 7405 Actions.PushExpressionEvaluationContext(NewContext, 7406 Sema::ReuseLambdaContextDecl, 7407 IsDecltype); 7408 } 7409 7410 ~EnterExpressionEvaluationContext() { 7411 Actions.PopExpressionEvaluationContext(); 7412 } 7413}; 7414 7415} // end namespace clang 7416 7417#endif 7418