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