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