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