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