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