1 //===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the Sema class, which performs semantic analysis and
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_SEMA_SEMA_H
16 #define LLVM_CLANG_SEMA_SEMA_H
18 #include "clang/Sema/Ownership.h"
19 #include "clang/Sema/AnalysisBasedWarnings.h"
20 #include "clang/Sema/IdentifierResolver.h"
21 #include "clang/Sema/ObjCMethodList.h"
22 #include "clang/Sema/DeclSpec.h"
23 #include "clang/Sema/ExternalSemaSource.h"
24 #include "clang/Sema/LocInfoType.h"
25 #include "clang/Sema/MultiInitializer.h"
26 #include "clang/Sema/TypoCorrection.h"
27 #include "clang/Sema/Weak.h"
28 #include "clang/AST/Expr.h"
29 #include "clang/AST/DeclarationName.h"
30 #include "clang/AST/ExternalASTSource.h"
31 #include "clang/AST/TypeLoc.h"
32 #include "clang/Basic/Specifiers.h"
33 #include "clang/Basic/TemplateKinds.h"
34 #include "clang/Basic/TypeTraits.h"
35 #include "clang/Basic/ExpressionTraits.h"
36 #include "llvm/ADT/ArrayRef.h"
37 #include "llvm/ADT/OwningPtr.h"
38 #include "llvm/ADT/SmallPtrSet.h"
39 #include "llvm/ADT/SmallVector.h"
45 template <typename ValueT> struct DenseMapInfo;
46 template <typename ValueT, typename ValueInfoT> class DenseSet;
53 class ASTMutationListener;
61 typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath;
62 class CXXConstructorDecl;
63 class CXXConversionDecl;
64 class CXXDestructorDecl;
65 class CXXFieldCollector;
66 class CXXMemberCallExpr;
72 class ClassTemplateDecl;
73 class ClassTemplatePartialSpecializationDecl;
74 class ClassTemplateSpecializationDecl;
75 class CodeCompleteConsumer;
76 class CodeCompletionAllocator;
77 class CodeCompletionResult;
83 class DeducedTemplateArgument;
84 class DependentDiagnostic;
85 class DesignatedInitExpr;
87 class EnumConstantDecl;
90 class ExternalSemaSource;
94 class FunctionProtoType;
95 class FunctionTemplateDecl;
96 class ImplicitConversionSequence;
98 class InitializationKind;
99 class InitializationSequence;
100 class InitializedEntity;
101 class IntegerLiteral;
104 class LocalInstantiationScope;
107 class MultiLevelTemplateArgumentList;
110 class ObjCCategoryDecl;
111 class ObjCCategoryImplDecl;
112 class ObjCCompatibleAliasDecl;
113 class ObjCContainerDecl;
115 class ObjCImplementationDecl;
116 class ObjCInterfaceDecl;
118 template <class T> class ObjCList;
119 class ObjCMessageExpr;
120 class ObjCMethodDecl;
121 class ObjCPropertyDecl;
122 class ObjCProtocolDecl;
123 class OverloadCandidateSet;
128 class PseudoDestructorTypeStorage;
130 class StandardConversionSequence;
134 class TargetAttributesSema;
135 class TemplateArgument;
136 class TemplateArgumentList;
137 class TemplateArgumentLoc;
139 class TemplateParameterList;
140 class TemplatePartialOrderingContext;
141 class TemplateTemplateParmDecl;
145 class TypedefNameDecl;
148 class UnresolvedLookupExpr;
149 class UnresolvedMemberExpr;
150 class UnresolvedSetImpl;
151 class UnresolvedSetIterator;
153 class UsingShadowDecl;
156 class VisibilityAttr;
157 class VisibleDeclConsumer;
158 class IndirectFieldDecl;
161 class AccessedEntity;
162 class BlockScopeInfo;
163 class DelayedDiagnostic;
164 class FunctionScopeInfo;
165 class TemplateDeductionInfo;
168 // FIXME: No way to easily map from TemplateTypeParmTypes to
169 // TemplateTypeParmDecls, so we have this horrible PointerUnion.
170 typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType*, NamedDecl*>,
171 SourceLocation> UnexpandedParameterPack;
173 /// Sema - This implements semantic analysis and AST building for C.
175 Sema(const Sema&); // DO NOT IMPLEMENT
176 void operator=(const Sema&); // DO NOT IMPLEMENT
177 mutable const TargetAttributesSema* TheTargetAttributesSema;
179 typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
180 typedef OpaquePtr<TemplateName> TemplateTy;
181 typedef OpaquePtr<QualType> TypeTy;
183 OpenCLOptions OpenCLFeatures;
184 FPOptions FPFeatures;
186 const LangOptions &LangOpts;
189 ASTConsumer &Consumer;
190 DiagnosticsEngine &Diags;
191 SourceManager &SourceMgr;
193 /// \brief Flag indicating whether or not to collect detailed statistics.
196 /// \brief Source of additional semantic information.
197 ExternalSemaSource *ExternalSource;
199 /// \brief Code-completion consumer.
200 CodeCompleteConsumer *CodeCompleter;
202 /// CurContext - This is the current declaration context of parsing.
203 DeclContext *CurContext;
205 /// \brief Generally null except when we temporarily switch decl contexts,
206 /// like in \see ActOnObjCTemporaryExitContainerContext.
207 DeclContext *OriginalLexicalContext;
209 /// VAListTagName - The declaration name corresponding to __va_list_tag.
210 /// This is used as part of a hack to omit that class from ADL results.
211 DeclarationName VAListTagName;
213 /// PackContext - Manages the stack for #pragma pack. An alignment
214 /// of 0 indicates default alignment.
215 void *PackContext; // Really a "PragmaPackStack*"
217 bool MSStructPragmaOn; // True when #pragma ms_struct on
219 /// VisContext - Manages the stack for #pragma GCC visibility.
220 void *VisContext; // Really a "PragmaVisStack*"
222 /// ExprNeedsCleanups - True if the current evaluation context
223 /// requires cleanups to be run at its conclusion.
224 bool ExprNeedsCleanups;
226 /// \brief Stack containing information about each of the nested
227 /// function, block, and method scopes that are currently active.
229 /// This array is never empty. Clients should ignore the first
230 /// element, which is used to cache a single FunctionScopeInfo
231 /// that's used to parse every top-level function.
232 SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes;
234 /// ExprTemporaries - This is the stack of temporaries that are created by
235 /// the current full expression.
236 SmallVector<CXXTemporary*, 8> ExprTemporaries;
238 typedef LazyVector<TypedefNameDecl *, ExternalSemaSource,
239 &ExternalSemaSource::ReadExtVectorDecls, 2, 2>
242 /// ExtVectorDecls - This is a list all the extended vector types. This allows
243 /// us to associate a raw vector type with one of the ext_vector type names.
244 /// This is only necessary for issuing pretty diagnostics.
245 ExtVectorDeclsType ExtVectorDecls;
247 /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
248 llvm::OwningPtr<CXXFieldCollector> FieldCollector;
250 typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy;
252 /// PureVirtualClassDiagSet - a set of class declarations which we have
253 /// emitted a list of pure virtual functions. Used to prevent emitting the
254 /// same list more than once.
255 llvm::OwningPtr<RecordDeclSetTy> PureVirtualClassDiagSet;
257 /// ParsingInitForAutoVars - a set of declarations with auto types for which
258 /// we are currently parsing the initializer.
259 llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars;
261 /// \brief A mapping from external names to the most recent
262 /// locally-scoped external declaration with that name.
264 /// This map contains external declarations introduced in local
269 /// void foo(int, int);
273 /// Here, the name "foo" will be associated with the declaration on
274 /// "foo" within f. This name is not visible outside of
275 /// "f". However, we still find it in two cases:
277 /// - If we are declaring another external with the name "foo", we
278 /// can find "foo" as a previous declaration, so that the types
279 /// of this external declaration can be checked for
282 /// - If we would implicitly declare "foo" (e.g., due to a call to
283 /// "foo" in C when no prototype or definition is visible), then
284 /// we find this declaration of "foo" and complain that it is
286 llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternalDecls;
288 /// \brief Look for a locally scoped external declaration by the given name.
289 llvm::DenseMap<DeclarationName, NamedDecl *>::iterator
290 findLocallyScopedExternalDecl(DeclarationName Name);
292 typedef LazyVector<VarDecl *, ExternalSemaSource,
293 &ExternalSemaSource::ReadTentativeDefinitions, 2, 2>
294 TentativeDefinitionsType;
296 /// \brief All the tentative definitions encountered in the TU.
297 TentativeDefinitionsType TentativeDefinitions;
299 typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource,
300 &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2>
301 UnusedFileScopedDeclsType;
303 /// \brief The set of file scoped decls seen so far that have not been used
304 /// and must warn if not used. Only contains the first declaration.
305 UnusedFileScopedDeclsType UnusedFileScopedDecls;
307 typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource,
308 &ExternalSemaSource::ReadDelegatingConstructors, 2, 2>
309 DelegatingCtorDeclsType;
311 /// \brief All the delegating constructors seen so far in the file, used for
312 /// cycle detection at the end of the TU.
313 DelegatingCtorDeclsType DelegatingCtorDecls;
315 /// \brief All the overriding destructors seen during a class definition
316 /// (there could be multiple due to nested classes) that had their exception
317 /// spec checks delayed, plus the overridden destructor.
318 SmallVector<std::pair<const CXXDestructorDecl*,
319 const CXXDestructorDecl*>, 2>
320 DelayedDestructorExceptionSpecChecks;
322 /// \brief Callback to the parser to parse templated functions when needed.
323 typedef void LateTemplateParserCB(void *P, const FunctionDecl *FD);
324 LateTemplateParserCB *LateTemplateParser;
327 void SetLateTemplateParser(LateTemplateParserCB *LTP, void *P) {
328 LateTemplateParser = LTP;
332 class DelayedDiagnostics;
334 class ParsingDeclState {
335 unsigned SavedStackSize;
336 friend class Sema::DelayedDiagnostics;
339 class ProcessingContextState {
340 unsigned SavedParsingDepth;
341 unsigned SavedActiveStackBase;
342 friend class Sema::DelayedDiagnostics;
345 /// A class which encapsulates the logic for delaying diagnostics
346 /// during parsing and other processing.
347 class DelayedDiagnostics {
348 /// \brief The stack of diagnostics that were delayed due to being
349 /// produced during the parsing of a declaration.
350 sema::DelayedDiagnostic *Stack;
352 /// \brief The number of objects on the delayed-diagnostics stack.
355 /// \brief The current capacity of the delayed-diagnostics stack.
356 unsigned StackCapacity;
358 /// \brief The index of the first "active" delayed diagnostic in
359 /// the stack. When parsing class definitions, we ignore active
360 /// delayed diagnostics from the surrounding context.
361 unsigned ActiveStackBase;
363 /// \brief The depth of the declarations we're currently parsing.
364 /// This gets saved and reset whenever we enter a class definition.
365 unsigned ParsingDepth;
368 DelayedDiagnostics() : Stack(0), StackSize(0), StackCapacity(0),
369 ActiveStackBase(0), ParsingDepth(0) {}
371 ~DelayedDiagnostics() {
372 delete[] reinterpret_cast<char*>(Stack);
375 /// Adds a delayed diagnostic.
376 void add(const sema::DelayedDiagnostic &diag);
378 /// Determines whether diagnostics should be delayed.
379 bool shouldDelayDiagnostics() { return ParsingDepth > 0; }
381 /// Observe that we've started parsing a declaration. Access and
382 /// deprecation diagnostics will be delayed; when the declaration
383 /// is completed, all active delayed diagnostics will be evaluated
384 /// in its context, and then active diagnostics stack will be
385 /// popped down to the saved depth.
386 ParsingDeclState pushParsingDecl() {
389 ParsingDeclState state;
390 state.SavedStackSize = StackSize;
394 /// Observe that we're completed parsing a declaration.
395 static void popParsingDecl(Sema &S, ParsingDeclState state, Decl *decl);
397 /// Observe that we've started processing a different context, the
398 /// contents of which are semantically separate from the
399 /// declarations it may lexically appear in. This sets aside the
400 /// current stack of active diagnostics and starts afresh.
401 ProcessingContextState pushContext() {
402 assert(StackSize >= ActiveStackBase);
404 ProcessingContextState state;
405 state.SavedParsingDepth = ParsingDepth;
406 state.SavedActiveStackBase = ActiveStackBase;
408 ActiveStackBase = StackSize;
414 /// Observe that we've stopped processing a context. This
415 /// restores the previous stack of active diagnostics.
416 void popContext(ProcessingContextState state) {
417 assert(ActiveStackBase == StackSize);
418 assert(ParsingDepth == 0);
419 ActiveStackBase = state.SavedActiveStackBase;
420 ParsingDepth = state.SavedParsingDepth;
422 } DelayedDiagnostics;
424 /// A RAII object to temporarily push a declaration context.
428 DeclContext *SavedContext;
429 ProcessingContextState SavedContextState;
432 ContextRAII(Sema &S, DeclContext *ContextToPush)
433 : S(S), SavedContext(S.CurContext),
434 SavedContextState(S.DelayedDiagnostics.pushContext())
436 assert(ContextToPush && "pushing null context");
437 S.CurContext = ContextToPush;
441 if (!SavedContext) return;
442 S.CurContext = SavedContext;
443 S.DelayedDiagnostics.popContext(SavedContextState);
452 /// WeakUndeclaredIdentifiers - Identifiers contained in
453 /// #pragma weak before declared. rare. may alias another
454 /// identifier, declared or undeclared
455 llvm::DenseMap<IdentifierInfo*,WeakInfo> WeakUndeclaredIdentifiers;
457 /// \brief Load weak undeclared identifiers from the external source.
458 void LoadExternalWeakUndeclaredIdentifiers();
460 /// WeakTopLevelDecl - Translation-unit scoped declarations generated by
461 /// #pragma weak during processing of other Decls.
462 /// I couldn't figure out a clean way to generate these in-line, so
463 /// we store them here and handle separately -- which is a hack.
464 /// It would be best to refactor this.
465 SmallVector<Decl*,2> WeakTopLevelDecl;
467 IdentifierResolver IdResolver;
469 /// Translation Unit Scope - useful to Objective-C actions that need
470 /// to lookup file scope declarations in the "ordinary" C decl namespace.
471 /// For example, user-defined classes, built-in "id" type, etc.
474 /// \brief The C++ "std" namespace, where the standard library resides.
475 LazyDeclPtr StdNamespace;
477 /// \brief The C++ "std::bad_alloc" class, which is defined by the C++
478 /// standard library.
479 LazyDeclPtr StdBadAlloc;
481 /// \brief The C++ "type_info" declaration, which is defined in <typeinfo>.
482 RecordDecl *CXXTypeInfoDecl;
484 /// \brief The MSVC "_GUID" struct, which is defined in MSVC header files.
485 RecordDecl *MSVCGuidDecl;
487 /// A flag to remember whether the implicit forms of operator new and delete
488 /// have been declared.
489 bool GlobalNewDeleteDeclared;
492 /// A flag that is set when parsing a -dealloc method and no [super dealloc]
493 /// call was found yet.
494 bool ObjCShouldCallSuperDealloc;
495 /// A flag that is set when parsing a -finalize method and no [super finalize]
496 /// call was found yet.
497 bool ObjCShouldCallSuperFinalize;
499 /// \brief The set of declarations that have been referenced within
500 /// a potentially evaluated expression.
501 typedef SmallVector<std::pair<SourceLocation, Decl *>, 10>
502 PotentiallyReferencedDecls;
504 /// \brief A set of diagnostics that may be emitted.
505 typedef SmallVector<std::pair<SourceLocation, PartialDiagnostic>, 10>
506 PotentiallyEmittedDiagnostics;
508 /// \brief Describes how the expressions currently being parsed are
509 /// evaluated at run-time, if at all.
510 enum ExpressionEvaluationContext {
511 /// \brief The current expression and its subexpressions occur within an
512 /// unevaluated operand (C++0x [expr]p8), such as a constant expression
513 /// or the subexpression of \c sizeof, where the type or the value of the
514 /// expression may be significant but no code will be generated to evaluate
515 /// the value of the expression at run time.
518 /// \brief The current expression is potentially evaluated at run time,
519 /// which means that code may be generated to evaluate the value of the
520 /// expression at run time.
521 PotentiallyEvaluated,
523 /// \brief The current expression may be potentially evaluated or it may
524 /// be unevaluated, but it is impossible to tell from the lexical context.
525 /// This evaluation context is used primary for the operand of the C++
526 /// \c typeid expression, whose argument is potentially evaluated only when
527 /// it is an lvalue of polymorphic class type (C++ [basic.def.odr]p2).
528 PotentiallyPotentiallyEvaluated,
530 /// \brief The current expression is potentially evaluated, but any
531 /// declarations referenced inside that expression are only used if
532 /// in fact the current expression is used.
534 /// This value is used when parsing default function arguments, for which
535 /// we would like to provide diagnostics (e.g., passing non-POD arguments
536 /// through varargs) but do not want to mark declarations as "referenced"
537 /// until the default argument is used.
538 PotentiallyEvaluatedIfUsed
541 /// \brief Data structure used to record current or nested
542 /// expression evaluation contexts.
543 struct ExpressionEvaluationContextRecord {
544 /// \brief The expression evaluation context.
545 ExpressionEvaluationContext Context;
547 /// \brief Whether the enclosing context needed a cleanup.
548 bool ParentNeedsCleanups;
550 /// \brief The number of temporaries that were active when we
551 /// entered this expression evaluation context.
552 unsigned NumTemporaries;
554 /// \brief The set of declarations referenced within a
555 /// potentially potentially-evaluated context.
557 /// When leaving a potentially potentially-evaluated context, each
558 /// of these elements will be as referenced if the corresponding
559 /// potentially potentially evaluated expression is potentially
561 PotentiallyReferencedDecls *PotentiallyReferenced;
563 /// \brief The set of diagnostics to emit should this potentially
564 /// potentially-evaluated context become evaluated.
565 PotentiallyEmittedDiagnostics *PotentiallyDiagnosed;
567 ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context,
568 unsigned NumTemporaries,
569 bool ParentNeedsCleanups)
570 : Context(Context), ParentNeedsCleanups(ParentNeedsCleanups),
571 NumTemporaries(NumTemporaries),
572 PotentiallyReferenced(0), PotentiallyDiagnosed(0) { }
574 void addReferencedDecl(SourceLocation Loc, Decl *Decl) {
575 if (!PotentiallyReferenced)
576 PotentiallyReferenced = new PotentiallyReferencedDecls;
577 PotentiallyReferenced->push_back(std::make_pair(Loc, Decl));
580 void addDiagnostic(SourceLocation Loc, const PartialDiagnostic &PD) {
581 if (!PotentiallyDiagnosed)
582 PotentiallyDiagnosed = new PotentiallyEmittedDiagnostics;
583 PotentiallyDiagnosed->push_back(std::make_pair(Loc, PD));
587 delete PotentiallyReferenced;
588 delete PotentiallyDiagnosed;
589 PotentiallyReferenced = 0;
590 PotentiallyDiagnosed = 0;
594 /// A stack of expression evaluation contexts.
595 SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts;
597 /// SpecialMemberOverloadResult - The overloading result for a special member
600 /// This is basically a wrapper around PointerIntPair. The lowest bit of the
601 /// integer is used to determine whether we have a parameter qualification
602 /// match, the second-lowest is whether we had success in resolving the
603 /// overload to a unique non-deleted function.
605 /// The ConstParamMatch bit represents whether, when looking up a copy
606 /// constructor or assignment operator, we found a potential copy
607 /// constructor/assignment operator whose first parameter is const-qualified.
608 /// This is used for determining parameter types of other objects and is
609 /// utterly meaningless on other types of special members.
610 class SpecialMemberOverloadResult : public llvm::FastFoldingSetNode {
611 llvm::PointerIntPair<CXXMethodDecl*, 2> Pair;
613 SpecialMemberOverloadResult(const llvm::FoldingSetNodeID &ID)
614 : FastFoldingSetNode(ID)
617 CXXMethodDecl *getMethod() const { return Pair.getPointer(); }
618 void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); }
620 bool hasSuccess() const { return Pair.getInt() & 0x1; }
621 void setSuccess(bool B) {
622 Pair.setInt(unsigned(B) | hasConstParamMatch() << 1);
625 bool hasConstParamMatch() const { return Pair.getInt() & 0x2; }
626 void setConstParamMatch(bool B) {
627 Pair.setInt(B << 1 | unsigned(hasSuccess()));
631 /// \brief A cache of special member function overload resolution results
633 llvm::FoldingSet<SpecialMemberOverloadResult> SpecialMemberCache;
635 /// \brief The kind of translation unit we are processing.
637 /// When we're processing a complete translation unit, Sema will perform
638 /// end-of-translation-unit semantic tasks (such as creating
639 /// initializers for tentative definitions in C) once parsing has
640 /// completed. Modules and precompiled headers perform different kinds of
642 TranslationUnitKind TUKind;
644 llvm::BumpPtrAllocator BumpAlloc;
646 /// \brief The number of SFINAE diagnostics that have been trapped.
647 unsigned NumSFINAEErrors;
649 typedef llvm::DenseMap<ParmVarDecl *, SmallVector<ParmVarDecl *, 1> >
650 UnparsedDefaultArgInstantiationsMap;
652 /// \brief A mapping from parameters with unparsed default arguments to the
653 /// set of instantiations of each parameter.
655 /// This mapping is a temporary data structure used when parsing
656 /// nested class templates or nested classes of class templates,
657 /// where we might end up instantiating an inner class before the
658 /// default arguments of its methods have been parsed.
659 UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations;
661 // Contains the locations of the beginning of unparsed default
662 // argument locations.
663 llvm::DenseMap<ParmVarDecl *,SourceLocation> UnparsedDefaultArgLocs;
665 /// UndefinedInternals - all the used, undefined objects with
666 /// internal linkage in this translation unit.
667 llvm::DenseMap<NamedDecl*, SourceLocation> UndefinedInternals;
669 typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods;
670 typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool;
672 /// Method Pool - allows efficient lookup when typechecking messages to "id".
673 /// We need to maintain a list, since selectors can have differing signatures
674 /// across classes. In Cocoa, this happens to be extremely uncommon (only 1%
675 /// of selectors are "overloaded").
676 GlobalMethodPool MethodPool;
678 /// Method selectors used in a @selector expression. Used for implementation
680 llvm::DenseMap<Selector, SourceLocation> ReferencedSelectors;
682 GlobalMethodPool::iterator ReadMethodPool(Selector Sel);
684 /// Private Helper predicate to check for 'self'.
685 bool isSelfExpr(Expr *RExpr);
687 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
688 TranslationUnitKind TUKind = TU_Complete,
689 CodeCompleteConsumer *CompletionConsumer = 0);
692 /// \brief Perform initialization that occurs after the parser has been
693 /// initialized but before it parses anything.
696 const LangOptions &getLangOptions() const { return LangOpts; }
697 OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; }
698 FPOptions &getFPOptions() { return FPFeatures; }
700 DiagnosticsEngine &getDiagnostics() const { return Diags; }
701 SourceManager &getSourceManager() const { return SourceMgr; }
702 const TargetAttributesSema &getTargetAttributesSema() const;
703 Preprocessor &getPreprocessor() const { return PP; }
704 ASTContext &getASTContext() const { return Context; }
705 ASTConsumer &getASTConsumer() const { return Consumer; }
706 ASTMutationListener *getASTMutationListener() const;
708 void PrintStats() const;
710 /// \brief Helper class that creates diagnostics with optional
711 /// template instantiation stacks.
713 /// This class provides a wrapper around the basic DiagnosticBuilder
714 /// class that emits diagnostics. SemaDiagnosticBuilder is
715 /// responsible for emitting the diagnostic (as DiagnosticBuilder
716 /// does) and, if the diagnostic comes from inside a template
717 /// instantiation, printing the template instantiation stack as
719 class SemaDiagnosticBuilder : public DiagnosticBuilder {
724 SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID)
725 : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { }
727 explicit SemaDiagnosticBuilder(Sema &SemaRef)
728 : DiagnosticBuilder(DiagnosticBuilder::Suppress), SemaRef(SemaRef) { }
730 ~SemaDiagnosticBuilder();
733 /// \brief Emit a diagnostic.
734 SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
736 /// \brief Emit a partial diagnostic.
737 SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic& PD);
739 /// \brief Build a partial diagnostic.
740 PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h
742 bool findMacroSpelling(SourceLocation &loc, StringRef name);
744 ExprResult Owned(Expr* E) { return E; }
745 ExprResult Owned(ExprResult R) { return R; }
746 StmtResult Owned(Stmt* S) { return S; }
748 void ActOnEndOfTranslationUnit();
750 void CheckDelegatingCtorCycles();
752 Scope *getScopeForContext(DeclContext *Ctx);
754 void PushFunctionScope();
755 void PushBlockScope(Scope *BlockScope, BlockDecl *Block);
756 void PopFunctionOrBlockScope(const sema::AnalysisBasedWarnings::Policy *WP =0,
757 const Decl *D = 0, const BlockExpr *blkExpr = 0);
759 sema::FunctionScopeInfo *getCurFunction() const {
760 return FunctionScopes.back();
763 bool hasAnyUnrecoverableErrorsInThisFunction() const;
765 /// \brief Retrieve the current block, if any.
766 sema::BlockScopeInfo *getCurBlock();
768 /// WeakTopLevelDeclDecls - access to #pragma weak-generated Decls
769 SmallVector<Decl*,2> &WeakTopLevelDecls() { return WeakTopLevelDecl; }
771 //===--------------------------------------------------------------------===//
772 // Type Analysis / Processing: SemaType.cpp.
775 QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs);
776 QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVR) {
777 return BuildQualifiedType(T, Loc, Qualifiers::fromCVRMask(CVR));
779 QualType BuildPointerType(QualType T,
780 SourceLocation Loc, DeclarationName Entity);
781 QualType BuildReferenceType(QualType T, bool LValueRef,
782 SourceLocation Loc, DeclarationName Entity);
783 QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
784 Expr *ArraySize, unsigned Quals,
785 SourceRange Brackets, DeclarationName Entity);
786 QualType BuildExtVectorType(QualType T, Expr *ArraySize,
787 SourceLocation AttrLoc);
788 QualType BuildFunctionType(QualType T,
789 QualType *ParamTypes, unsigned NumParamTypes,
790 bool Variadic, unsigned Quals,
791 RefQualifierKind RefQualifier,
792 SourceLocation Loc, DeclarationName Entity,
793 FunctionType::ExtInfo Info);
794 QualType BuildMemberPointerType(QualType T, QualType Class,
796 DeclarationName Entity);
797 QualType BuildBlockPointerType(QualType T,
798 SourceLocation Loc, DeclarationName Entity);
799 QualType BuildParenType(QualType T);
800 QualType BuildAtomicType(QualType T, SourceLocation Loc);
802 TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S);
803 TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy);
804 TypeSourceInfo *GetTypeSourceInfoForDeclarator(Declarator &D, QualType T,
805 TypeSourceInfo *ReturnTypeInfo);
806 /// \brief Package the given type and TSI into a ParsedType.
807 ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo);
808 DeclarationNameInfo GetNameForDeclarator(Declarator &D);
809 DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name);
810 static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo = 0);
811 bool CheckSpecifiedExceptionType(QualType T, const SourceRange &Range);
812 bool CheckDistantExceptionSpec(QualType T);
813 bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New);
814 bool CheckEquivalentExceptionSpec(
815 const FunctionProtoType *Old, SourceLocation OldLoc,
816 const FunctionProtoType *New, SourceLocation NewLoc);
817 bool CheckEquivalentExceptionSpec(
818 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
819 const FunctionProtoType *Old, SourceLocation OldLoc,
820 const FunctionProtoType *New, SourceLocation NewLoc,
821 bool *MissingExceptionSpecification = 0,
822 bool *MissingEmptyExceptionSpecification = 0,
823 bool AllowNoexceptAllMatchWithNoSpec = false,
824 bool IsOperatorNew = false);
825 bool CheckExceptionSpecSubset(
826 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
827 const FunctionProtoType *Superset, SourceLocation SuperLoc,
828 const FunctionProtoType *Subset, SourceLocation SubLoc);
829 bool CheckParamExceptionSpec(const PartialDiagnostic & NoteID,
830 const FunctionProtoType *Target, SourceLocation TargetLoc,
831 const FunctionProtoType *Source, SourceLocation SourceLoc);
833 TypeResult ActOnTypeName(Scope *S, Declarator &D);
835 /// \brief The parser has parsed the context-sensitive type 'instancetype'
836 /// in an Objective-C message declaration. Return the appropriate type.
837 ParsedType ActOnObjCInstanceType(SourceLocation Loc);
839 bool RequireCompleteType(SourceLocation Loc, QualType T,
840 const PartialDiagnostic &PD,
841 std::pair<SourceLocation, PartialDiagnostic> Note);
842 bool RequireCompleteType(SourceLocation Loc, QualType T,
843 const PartialDiagnostic &PD);
844 bool RequireCompleteType(SourceLocation Loc, QualType T,
846 bool RequireCompleteExprType(Expr *E, const PartialDiagnostic &PD,
847 std::pair<SourceLocation,
848 PartialDiagnostic> Note);
850 bool RequireLiteralType(SourceLocation Loc, QualType T,
851 const PartialDiagnostic &PD,
852 bool AllowIncompleteType = false);
854 QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
855 const CXXScopeSpec &SS, QualType T);
857 QualType BuildTypeofExprType(Expr *E, SourceLocation Loc);
858 QualType BuildDecltypeType(Expr *E, SourceLocation Loc);
859 QualType BuildUnaryTransformType(QualType BaseType,
860 UnaryTransformType::UTTKind UKind,
863 //===--------------------------------------------------------------------===//
864 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
867 DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = 0);
869 void DiagnoseUseOfUnimplementedSelectors();
871 ParsedType getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
872 Scope *S, CXXScopeSpec *SS = 0,
873 bool isClassName = false,
874 bool HasTrailingDot = false,
875 ParsedType ObjectType = ParsedType(),
876 bool WantNontrivialTypeSourceInfo = false,
877 IdentifierInfo **CorrectedII = 0);
878 TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S);
879 bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S);
880 bool DiagnoseUnknownTypeName(const IdentifierInfo &II,
881 SourceLocation IILoc,
884 ParsedType &SuggestedType);
886 /// \brief Describes the result of the name lookup and resolution performed
887 /// by \c ClassifyName().
888 enum NameClassificationKind {
894 NC_NestedNameSpecifier,
899 class NameClassification {
900 NameClassificationKind Kind;
902 TemplateName Template;
904 const IdentifierInfo *Keyword;
906 explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {}
909 NameClassification(ExprResult Expr) : Kind(NC_Expression), Expr(Expr) {}
911 NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {}
913 NameClassification(const IdentifierInfo *Keyword)
914 : Kind(NC_Keyword), Keyword(Keyword) { }
916 static NameClassification Error() {
917 return NameClassification(NC_Error);
920 static NameClassification Unknown() {
921 return NameClassification(NC_Unknown);
924 static NameClassification NestedNameSpecifier() {
925 return NameClassification(NC_NestedNameSpecifier);
928 static NameClassification TypeTemplate(TemplateName Name) {
929 NameClassification Result(NC_TypeTemplate);
930 Result.Template = Name;
934 static NameClassification FunctionTemplate(TemplateName Name) {
935 NameClassification Result(NC_FunctionTemplate);
936 Result.Template = Name;
940 NameClassificationKind getKind() const { return Kind; }
942 ParsedType getType() const {
943 assert(Kind == NC_Type);
947 ExprResult getExpression() const {
948 assert(Kind == NC_Expression);
952 TemplateName getTemplateName() const {
953 assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate);
957 TemplateNameKind getTemplateNameKind() const {
958 assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate);
959 return Kind == NC_TypeTemplate? TNK_Type_template : TNK_Function_template;
963 /// \brief Perform name lookup on the given name, classifying it based on
964 /// the results of name lookup and the following token.
966 /// This routine is used by the parser to resolve identifiers and help direct
967 /// parsing. When the identifier cannot be found, this routine will attempt
968 /// to correct the typo and classify based on the resulting name.
970 /// \param S The scope in which we're performing name lookup.
972 /// \param SS The nested-name-specifier that precedes the name.
974 /// \param Name The identifier. If typo correction finds an alternative name,
975 /// this pointer parameter will be updated accordingly.
977 /// \param NameLoc The location of the identifier.
979 /// \param NextToken The token following the identifier. Used to help
980 /// disambiguate the name.
981 NameClassification ClassifyName(Scope *S,
983 IdentifierInfo *&Name,
984 SourceLocation NameLoc,
985 const Token &NextToken);
987 Decl *ActOnDeclarator(Scope *S, Declarator &D);
989 Decl *HandleDeclarator(Scope *S, Declarator &D,
990 MultiTemplateParamsArg TemplateParameterLists);
991 void RegisterLocallyScopedExternCDecl(NamedDecl *ND,
992 const LookupResult &Previous,
994 bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info);
995 void DiagnoseFunctionSpecifiers(Declarator& D);
996 void CheckShadow(Scope *S, VarDecl *D, const LookupResult& R);
997 void CheckShadow(Scope *S, VarDecl *D);
998 void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange);
999 void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D);
1000 NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
1001 TypeSourceInfo *TInfo,
1002 LookupResult &Previous);
1003 NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D,
1004 LookupResult &Previous, bool &Redeclaration);
1005 NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
1006 TypeSourceInfo *TInfo,
1007 LookupResult &Previous,
1008 MultiTemplateParamsArg TemplateParamLists);
1009 // Returns true if the variable declaration is a redeclaration
1010 bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous);
1011 void CheckCompleteVariableDeclaration(VarDecl *var);
1012 NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
1013 TypeSourceInfo *TInfo,
1014 LookupResult &Previous,
1015 MultiTemplateParamsArg TemplateParamLists,
1017 bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD);
1019 /// \brief The kind of constexpr declaration checking we are performing.
1021 /// The kind affects which diagnostics (if any) are emitted if the function
1022 /// does not satisfy the requirements of a constexpr function declaration.
1023 enum CheckConstexprKind {
1024 /// \brief Check a constexpr function declaration, and produce errors if it
1025 /// does not satisfy the requirements.
1027 /// \brief Check a constexpr function template instantiation.
1029 /// \brief Produce notes explaining why an instantiation was not constexpr.
1030 CCK_NoteNonConstexprInstantiation
1032 bool CheckConstexprFunctionDecl(const FunctionDecl *FD, CheckConstexprKind CCK);
1033 bool CheckConstexprFunctionBody(const FunctionDecl *FD, Stmt *Body);
1035 void DiagnoseHiddenVirtualMethods(CXXRecordDecl *DC, CXXMethodDecl *MD);
1036 // Returns true if the function declaration is a redeclaration
1037 bool CheckFunctionDeclaration(Scope *S,
1038 FunctionDecl *NewFD, LookupResult &Previous,
1039 bool IsExplicitSpecialization);
1040 void CheckMain(FunctionDecl *FD, const DeclSpec &D);
1041 Decl *ActOnParamDeclarator(Scope *S, Declarator &D);
1042 ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC,
1045 ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc,
1046 SourceLocation NameLoc, IdentifierInfo *Name,
1047 QualType T, TypeSourceInfo *TSInfo,
1048 StorageClass SC, StorageClass SCAsWritten);
1049 void ActOnParamDefaultArgument(Decl *param,
1050 SourceLocation EqualLoc,
1052 void ActOnParamUnparsedDefaultArgument(Decl *param,
1053 SourceLocation EqualLoc,
1054 SourceLocation ArgLoc);
1055 void ActOnParamDefaultArgumentError(Decl *param);
1056 bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg,
1057 SourceLocation EqualLoc);
1059 void CheckSelfReference(Decl *OrigDecl, Expr *E);
1060 void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit,
1061 bool TypeMayContainAuto);
1062 void ActOnUninitializedDecl(Decl *dcl, bool TypeMayContainAuto);
1063 void ActOnInitializerError(Decl *Dcl);
1064 void ActOnCXXForRangeDecl(Decl *D);
1065 void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc);
1066 void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc);
1067 void FinalizeDeclaration(Decl *D);
1068 DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS,
1071 DeclGroupPtrTy BuildDeclaratorGroup(Decl **Group, unsigned NumDecls,
1072 bool TypeMayContainAuto = true);
1073 void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
1074 SourceLocation LocAfterDecls);
1075 void CheckForFunctionRedefinition(FunctionDecl *FD);
1076 Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
1077 Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D);
1078 void ActOnStartOfObjCMethodDef(Scope *S, Decl *D);
1080 void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope);
1081 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body);
1082 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation);
1084 /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an
1085 /// attribute for which parsing is delayed.
1086 void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs);
1088 /// \brief Diagnose any unused parameters in the given sequence of
1089 /// ParmVarDecl pointers.
1090 void DiagnoseUnusedParameters(ParmVarDecl * const *Begin,
1091 ParmVarDecl * const *End);
1093 /// \brief Diagnose whether the size of parameters or return value of a
1094 /// function or obj-c method definition is pass-by-value and larger than a
1095 /// specified threshold.
1096 void DiagnoseSizeOfParametersAndReturnValue(ParmVarDecl * const *Begin,
1097 ParmVarDecl * const *End,
1101 void DiagnoseInvalidJumps(Stmt *Body);
1102 Decl *ActOnFileScopeAsmDecl(Expr *expr,
1103 SourceLocation AsmLoc,
1104 SourceLocation RParenLoc);
1106 /// \brief The parser has processed a module import declaration.
1108 /// \param ImportLoc The location of the '__import_module__' keyword.
1110 /// \param ModuleName The name of the module.
1112 /// \param ModuleNameLoc The location of the module name.
1113 DeclResult ActOnModuleImport(SourceLocation ImportLoc,
1114 IdentifierInfo &ModuleName,
1115 SourceLocation ModuleNameLoc);
1117 /// \brief Diagnose that \p New is a module-private redeclaration of
1119 void diagnoseModulePrivateRedeclaration(NamedDecl *New, NamedDecl *Old,
1120 SourceLocation ModulePrivateKeyword
1121 = SourceLocation());
1123 /// \brief Retrieve a suitable printing policy.
1124 PrintingPolicy getPrintingPolicy() const;
1127 void ActOnPopScope(SourceLocation Loc, Scope *S);
1128 void ActOnTranslationUnitScope(Scope *S);
1130 Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
1132 Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
1134 MultiTemplateParamsArg TemplateParams);
1136 StmtResult ActOnVlaStmt(const DeclSpec &DS);
1138 Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
1140 RecordDecl *Record);
1142 Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS,
1143 RecordDecl *Record);
1145 bool isAcceptableTagRedeclaration(const TagDecl *Previous,
1146 TagTypeKind NewTag, bool isDefinition,
1147 SourceLocation NewTagLoc,
1148 const IdentifierInfo &Name);
1151 TUK_Reference, // Reference to a tag: 'struct foo *X;'
1152 TUK_Declaration, // Fwd decl of a tag: 'struct foo;'
1153 TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;'
1154 TUK_Friend // Friend declaration: 'friend struct foo;'
1157 Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
1158 SourceLocation KWLoc, CXXScopeSpec &SS,
1159 IdentifierInfo *Name, SourceLocation NameLoc,
1160 AttributeList *Attr, AccessSpecifier AS,
1161 SourceLocation ModulePrivateLoc,
1162 MultiTemplateParamsArg TemplateParameterLists,
1163 bool &OwnedDecl, bool &IsDependent, bool ScopedEnum,
1164 bool ScopedEnumUsesClassTag, TypeResult UnderlyingType);
1166 Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc,
1167 unsigned TagSpec, SourceLocation TagLoc,
1169 IdentifierInfo *Name, SourceLocation NameLoc,
1170 AttributeList *Attr,
1171 MultiTemplateParamsArg TempParamLists);
1173 TypeResult ActOnDependentTag(Scope *S,
1176 const CXXScopeSpec &SS,
1177 IdentifierInfo *Name,
1178 SourceLocation TagLoc,
1179 SourceLocation NameLoc);
1181 void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart,
1182 IdentifierInfo *ClassName,
1183 SmallVectorImpl<Decl *> &Decls);
1184 Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart,
1185 Declarator &D, Expr *BitfieldWidth);
1187 FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
1188 Declarator &D, Expr *BitfieldWidth, bool HasInit,
1189 AccessSpecifier AS);
1191 FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T,
1192 TypeSourceInfo *TInfo,
1193 RecordDecl *Record, SourceLocation Loc,
1194 bool Mutable, Expr *BitfieldWidth, bool HasInit,
1195 SourceLocation TSSL,
1196 AccessSpecifier AS, NamedDecl *PrevDecl,
1199 enum CXXSpecialMember {
1200 CXXDefaultConstructor,
1208 bool CheckNontrivialField(FieldDecl *FD);
1209 void DiagnoseNontrivial(const RecordType* Record, CXXSpecialMember mem);
1210 CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD);
1211 void ActOnLastBitfield(SourceLocation DeclStart,
1212 SmallVectorImpl<Decl *> &AllIvarDecls);
1213 Decl *ActOnIvar(Scope *S, SourceLocation DeclStart,
1214 Declarator &D, Expr *BitfieldWidth,
1215 tok::ObjCKeywordKind visibility);
1217 // This is used for both record definitions and ObjC interface declarations.
1218 void ActOnFields(Scope* S, SourceLocation RecLoc, Decl *TagDecl,
1219 llvm::ArrayRef<Decl *> Fields,
1220 SourceLocation LBrac, SourceLocation RBrac,
1221 AttributeList *AttrList);
1223 /// ActOnTagStartDefinition - Invoked when we have entered the
1224 /// scope of a tag's definition (e.g., for an enumeration, class,
1225 /// struct, or union).
1226 void ActOnTagStartDefinition(Scope *S, Decl *TagDecl);
1228 Decl *ActOnObjCContainerStartDefinition(Decl *IDecl);
1230 /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a
1231 /// C++ record definition's base-specifiers clause and are starting its
1232 /// member declarations.
1233 void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl,
1234 SourceLocation FinalLoc,
1235 SourceLocation LBraceLoc);
1237 /// ActOnTagFinishDefinition - Invoked once we have finished parsing
1238 /// the definition of a tag (enumeration, class, struct, or union).
1239 void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl,
1240 SourceLocation RBraceLoc);
1242 void ActOnObjCContainerFinishDefinition();
1244 /// \brief Invoked when we must temporarily exit the objective-c container
1245 /// scope for parsing/looking-up C constructs.
1247 /// Must be followed by a call to \see ActOnObjCReenterContainerContext
1248 void ActOnObjCTemporaryExitContainerContext();
1249 void ActOnObjCReenterContainerContext();
1251 /// ActOnTagDefinitionError - Invoked when there was an unrecoverable
1252 /// error parsing the definition of a tag.
1253 void ActOnTagDefinitionError(Scope *S, Decl *TagDecl);
1255 EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum,
1256 EnumConstantDecl *LastEnumConst,
1257 SourceLocation IdLoc,
1261 Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant,
1262 SourceLocation IdLoc, IdentifierInfo *Id,
1263 AttributeList *Attrs,
1264 SourceLocation EqualLoc, Expr *Val);
1265 void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc,
1266 SourceLocation RBraceLoc, Decl *EnumDecl,
1267 Decl **Elements, unsigned NumElements,
1268 Scope *S, AttributeList *Attr);
1270 DeclContext *getContainingDC(DeclContext *DC);
1272 /// Set the current declaration context until it gets popped.
1273 void PushDeclContext(Scope *S, DeclContext *DC);
1274 void PopDeclContext();
1276 /// EnterDeclaratorContext - Used when we must lookup names in the context
1277 /// of a declarator's nested name specifier.
1278 void EnterDeclaratorContext(Scope *S, DeclContext *DC);
1279 void ExitDeclaratorContext(Scope *S);
1281 /// Push the parameters of D, which must be a function, into scope.
1282 void ActOnReenterFunctionContext(Scope* S, Decl* D);
1283 void ActOnExitFunctionContext() { PopDeclContext(); }
1285 DeclContext *getFunctionLevelDeclContext();
1287 /// getCurFunctionDecl - If inside of a function body, this returns a pointer
1288 /// to the function decl for the function being parsed. If we're currently
1289 /// in a 'block', this returns the containing context.
1290 FunctionDecl *getCurFunctionDecl();
1292 /// getCurMethodDecl - If inside of a method body, this returns a pointer to
1293 /// the method decl for the method being parsed. If we're currently
1294 /// in a 'block', this returns the containing context.
1295 ObjCMethodDecl *getCurMethodDecl();
1297 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
1298 /// or C function we're in, otherwise return null. If we're currently
1299 /// in a 'block', this returns the containing context.
1300 NamedDecl *getCurFunctionOrMethodDecl();
1302 /// Add this decl to the scope shadowed decl chains.
1303 void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true);
1305 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
1306 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
1307 /// true if 'D' belongs to the given declaration context.
1309 /// \param ExplicitInstantiationOrSpecialization When true, we are checking
1310 /// whether the declaration is in scope for the purposes of explicit template
1311 /// instantiation or specialization. The default is false.
1312 bool isDeclInScope(NamedDecl *&D, DeclContext *Ctx, Scope *S = 0,
1313 bool ExplicitInstantiationOrSpecialization = false);
1315 /// Finds the scope corresponding to the given decl context, if it
1316 /// happens to be an enclosing scope. Otherwise return NULL.
1317 static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC);
1319 /// Subroutines of ActOnDeclarator().
1320 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
1321 TypeSourceInfo *TInfo);
1322 void MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls);
1323 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old);
1324 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old);
1325 void mergeObjCMethodDecls(ObjCMethodDecl *New, const ObjCMethodDecl *Old);
1326 void MergeVarDecl(VarDecl *New, LookupResult &OldDecls);
1327 void MergeVarDeclTypes(VarDecl *New, VarDecl *Old);
1328 void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old);
1329 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
1331 // AssignmentAction - This is used by all the assignment diagnostic functions
1332 // to represent what is actually causing the operation
1333 enum AssignmentAction {
1343 /// C++ Overloading.
1345 /// This is a legitimate overload: the existing declarations are
1346 /// functions or function templates with different signatures.
1349 /// This is not an overload because the signature exactly matches
1350 /// an existing declaration.
1353 /// This is not an overload because the lookup results contain a
1357 OverloadKind CheckOverload(Scope *S,
1359 const LookupResult &OldDecls,
1360 NamedDecl *&OldDecl,
1361 bool IsForUsingDecl);
1362 bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl);
1364 /// \brief Checks availability of the function depending on the current
1365 /// function context.Inside an unavailable function,unavailability is ignored.
1367 /// \returns true if \arg FD is unavailable and current context is inside
1368 /// an available function, false otherwise.
1369 bool isFunctionConsideredUnavailable(FunctionDecl *FD);
1371 ImplicitConversionSequence
1372 TryImplicitConversion(Expr *From, QualType ToType,
1373 bool SuppressUserConversions,
1375 bool InOverloadResolution,
1377 bool AllowObjCWritebackConversion);
1379 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
1380 bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
1381 bool IsComplexPromotion(QualType FromType, QualType ToType);
1382 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
1383 bool InOverloadResolution,
1384 QualType& ConvertedType, bool &IncompatibleObjC);
1385 bool isObjCPointerConversion(QualType FromType, QualType ToType,
1386 QualType& ConvertedType, bool &IncompatibleObjC);
1387 bool isObjCWritebackConversion(QualType FromType, QualType ToType,
1388 QualType &ConvertedType);
1389 bool IsBlockPointerConversion(QualType FromType, QualType ToType,
1390 QualType& ConvertedType);
1391 bool FunctionArgTypesAreEqual(const FunctionProtoType *OldType,
1392 const FunctionProtoType *NewType);
1394 CastKind PrepareCastToObjCObjectPointer(ExprResult &E);
1395 bool CheckPointerConversion(Expr *From, QualType ToType,
1397 CXXCastPath& BasePath,
1398 bool IgnoreBaseAccess);
1399 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
1400 bool InOverloadResolution,
1401 QualType &ConvertedType);
1402 bool CheckMemberPointerConversion(Expr *From, QualType ToType,
1404 CXXCastPath &BasePath,
1405 bool IgnoreBaseAccess);
1406 bool IsQualificationConversion(QualType FromType, QualType ToType,
1407 bool CStyle, bool &ObjCLifetimeConversion);
1408 bool IsNoReturnConversion(QualType FromType, QualType ToType,
1409 QualType &ResultTy);
1410 bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType);
1413 ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
1414 const VarDecl *NRVOCandidate,
1415 QualType ResultType,
1417 bool AllowNRVO = true);
1419 bool CanPerformCopyInitialization(const InitializedEntity &Entity,
1421 ExprResult PerformCopyInitialization(const InitializedEntity &Entity,
1422 SourceLocation EqualLoc,
1424 bool TopLevelOfInitList = false);
1425 ExprResult PerformObjectArgumentInitialization(Expr *From,
1426 NestedNameSpecifier *Qualifier,
1427 NamedDecl *FoundDecl,
1428 CXXMethodDecl *Method);
1430 ExprResult PerformContextuallyConvertToBool(Expr *From);
1431 ExprResult PerformContextuallyConvertToObjCPointer(Expr *From);
1434 ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *FromE,
1435 const PartialDiagnostic &NotIntDiag,
1436 const PartialDiagnostic &IncompleteDiag,
1437 const PartialDiagnostic &ExplicitConvDiag,
1438 const PartialDiagnostic &ExplicitConvNote,
1439 const PartialDiagnostic &AmbigDiag,
1440 const PartialDiagnostic &AmbigNote,
1441 const PartialDiagnostic &ConvDiag);
1443 ExprResult PerformObjectMemberConversion(Expr *From,
1444 NestedNameSpecifier *Qualifier,
1445 NamedDecl *FoundDecl,
1448 // Members have to be NamespaceDecl* or TranslationUnitDecl*.
1449 // TODO: make this is a typesafe union.
1450 typedef llvm::SmallPtrSet<DeclContext *, 16> AssociatedNamespaceSet;
1451 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet;
1453 void AddOverloadCandidate(NamedDecl *Function,
1454 DeclAccessPair FoundDecl,
1455 Expr **Args, unsigned NumArgs,
1456 OverloadCandidateSet &CandidateSet);
1458 void AddOverloadCandidate(FunctionDecl *Function,
1459 DeclAccessPair FoundDecl,
1460 Expr **Args, unsigned NumArgs,
1461 OverloadCandidateSet& CandidateSet,
1462 bool SuppressUserConversions = false,
1463 bool PartialOverloading = false);
1464 void AddFunctionCandidates(const UnresolvedSetImpl &Functions,
1465 Expr **Args, unsigned NumArgs,
1466 OverloadCandidateSet& CandidateSet,
1467 bool SuppressUserConversions = false);
1468 void AddMethodCandidate(DeclAccessPair FoundDecl,
1469 QualType ObjectType,
1470 Expr::Classification ObjectClassification,
1471 Expr **Args, unsigned NumArgs,
1472 OverloadCandidateSet& CandidateSet,
1473 bool SuppressUserConversion = false);
1474 void AddMethodCandidate(CXXMethodDecl *Method,
1475 DeclAccessPair FoundDecl,
1476 CXXRecordDecl *ActingContext, QualType ObjectType,
1477 Expr::Classification ObjectClassification,
1478 Expr **Args, unsigned NumArgs,
1479 OverloadCandidateSet& CandidateSet,
1480 bool SuppressUserConversions = false);
1481 void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl,
1482 DeclAccessPair FoundDecl,
1483 CXXRecordDecl *ActingContext,
1484 TemplateArgumentListInfo *ExplicitTemplateArgs,
1485 QualType ObjectType,
1486 Expr::Classification ObjectClassification,
1487 Expr **Args, unsigned NumArgs,
1488 OverloadCandidateSet& CandidateSet,
1489 bool SuppressUserConversions = false);
1490 void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate,
1491 DeclAccessPair FoundDecl,
1492 TemplateArgumentListInfo *ExplicitTemplateArgs,
1493 Expr **Args, unsigned NumArgs,
1494 OverloadCandidateSet& CandidateSet,
1495 bool SuppressUserConversions = false);
1496 void AddConversionCandidate(CXXConversionDecl *Conversion,
1497 DeclAccessPair FoundDecl,
1498 CXXRecordDecl *ActingContext,
1499 Expr *From, QualType ToType,
1500 OverloadCandidateSet& CandidateSet);
1501 void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate,
1502 DeclAccessPair FoundDecl,
1503 CXXRecordDecl *ActingContext,
1504 Expr *From, QualType ToType,
1505 OverloadCandidateSet &CandidateSet);
1506 void AddSurrogateCandidate(CXXConversionDecl *Conversion,
1507 DeclAccessPair FoundDecl,
1508 CXXRecordDecl *ActingContext,
1509 const FunctionProtoType *Proto,
1510 Expr *Object, Expr **Args, unsigned NumArgs,
1511 OverloadCandidateSet& CandidateSet);
1512 void AddMemberOperatorCandidates(OverloadedOperatorKind Op,
1513 SourceLocation OpLoc,
1514 Expr **Args, unsigned NumArgs,
1515 OverloadCandidateSet& CandidateSet,
1516 SourceRange OpRange = SourceRange());
1517 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
1518 Expr **Args, unsigned NumArgs,
1519 OverloadCandidateSet& CandidateSet,
1520 bool IsAssignmentOperator = false,
1521 unsigned NumContextualBoolArguments = 0);
1522 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
1523 SourceLocation OpLoc,
1524 Expr **Args, unsigned NumArgs,
1525 OverloadCandidateSet& CandidateSet);
1526 void AddArgumentDependentLookupCandidates(DeclarationName Name,
1528 Expr **Args, unsigned NumArgs,
1529 TemplateArgumentListInfo *ExplicitTemplateArgs,
1530 OverloadCandidateSet& CandidateSet,
1531 bool PartialOverloading = false,
1532 bool StdNamespaceIsAssociated = false);
1534 // Emit as a 'note' the specific overload candidate
1535 void NoteOverloadCandidate(FunctionDecl *Fn);
1537 // Emit as a series of 'note's all template and non-templates
1538 // identified by the expression Expr
1539 void NoteAllOverloadCandidates(Expr* E);
1541 // [PossiblyAFunctionType] --> [Return]
1542 // NonFunctionType --> NonFunctionType
1544 // R (*)(A) --> R (A)
1545 // R (&)(A) --> R (A)
1546 // R (S::*)(A) --> R (A)
1547 QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType);
1549 FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, QualType TargetType,
1551 DeclAccessPair &Found);
1553 FunctionDecl *ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl,
1554 bool Complain = false,
1555 DeclAccessPair* Found = 0);
1557 bool ResolveAndFixSingleFunctionTemplateSpecialization(
1558 ExprResult &SrcExpr,
1559 bool DoFunctionPointerConverion = false,
1560 bool Complain = false,
1561 const SourceRange& OpRangeForComplaining = SourceRange(),
1562 QualType DestTypeForComplaining = QualType(),
1563 unsigned DiagIDForComplaining = 0);
1566 Expr *FixOverloadedFunctionReference(Expr *E,
1567 DeclAccessPair FoundDecl,
1569 ExprResult FixOverloadedFunctionReference(ExprResult,
1570 DeclAccessPair FoundDecl,
1573 void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE,
1574 Expr **Args, unsigned NumArgs,
1575 OverloadCandidateSet &CandidateSet,
1576 bool PartialOverloading = false);
1578 ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn,
1579 UnresolvedLookupExpr *ULE,
1580 SourceLocation LParenLoc,
1581 Expr **Args, unsigned NumArgs,
1582 SourceLocation RParenLoc,
1585 ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc,
1587 const UnresolvedSetImpl &Fns,
1590 ExprResult CreateOverloadedBinOp(SourceLocation OpLoc,
1592 const UnresolvedSetImpl &Fns,
1593 Expr *LHS, Expr *RHS);
1595 ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
1596 SourceLocation RLoc,
1597 Expr *Base,Expr *Idx);
1600 BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
1601 SourceLocation LParenLoc, Expr **Args,
1602 unsigned NumArgs, SourceLocation RParenLoc);
1604 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
1605 Expr **Args, unsigned NumArgs,
1606 SourceLocation RParenLoc);
1608 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base,
1609 SourceLocation OpLoc);
1611 /// CheckCallReturnType - Checks that a call expression's return type is
1612 /// complete. Returns true on failure. The location passed in is the location
1613 /// that best represents the call.
1614 bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc,
1615 CallExpr *CE, FunctionDecl *FD);
1617 /// Helpers for dealing with blocks and functions.
1618 bool CheckParmsForFunctionDef(ParmVarDecl **Param, ParmVarDecl **ParamEnd,
1619 bool CheckParameterNames);
1620 void CheckCXXDefaultArguments(FunctionDecl *FD);
1621 void CheckExtraCXXDefaultArguments(Declarator &D);
1622 Scope *getNonFieldDeclScope(Scope *S);
1624 /// \name Name lookup
1626 /// These routines provide name lookup that is used during semantic
1627 /// analysis to resolve the various kinds of names (identifiers,
1628 /// overloaded operator names, constructor names, etc.) into zero or
1629 /// more declarations within a particular scope. The major entry
1630 /// points are LookupName, which performs unqualified name lookup,
1631 /// and LookupQualifiedName, which performs qualified name lookup.
1633 /// All name lookup is performed based on some specific criteria,
1634 /// which specify what names will be visible to name lookup and how
1635 /// far name lookup should work. These criteria are important both
1636 /// for capturing language semantics (certain lookups will ignore
1637 /// certain names, for example) and for performance, since name
1638 /// lookup is often a bottleneck in the compilation of C++. Name
1639 /// lookup criteria is specified via the LookupCriteria enumeration.
1641 /// The results of name lookup can vary based on the kind of name
1642 /// lookup performed, the current language, and the translation
1643 /// unit. In C, for example, name lookup will either return nothing
1644 /// (no entity found) or a single declaration. In C++, name lookup
1645 /// can additionally refer to a set of overloaded functions or
1646 /// result in an ambiguity. All of the possible results of name
1647 /// lookup are captured by the LookupResult class, which provides
1648 /// the ability to distinguish among them.
1651 /// @brief Describes the kind of name lookup to perform.
1652 enum LookupNameKind {
1653 /// Ordinary name lookup, which finds ordinary names (functions,
1654 /// variables, typedefs, etc.) in C and most kinds of names
1655 /// (functions, variables, members, types, etc.) in C++.
1656 LookupOrdinaryName = 0,
1657 /// Tag name lookup, which finds the names of enums, classes,
1658 /// structs, and unions.
1660 /// Label name lookup.
1662 /// Member name lookup, which finds the names of
1663 /// class/struct/union members.
1665 /// Look up of an operator name (e.g., operator+) for use with
1666 /// operator overloading. This lookup is similar to ordinary name
1667 /// lookup, but will ignore any declarations that are class members.
1669 /// Look up of a name that precedes the '::' scope resolution
1670 /// operator in C++. This lookup completely ignores operator, object,
1671 /// function, and enumerator names (C++ [basic.lookup.qual]p1).
1672 LookupNestedNameSpecifierName,
1673 /// Look up a namespace name within a C++ using directive or
1674 /// namespace alias definition, ignoring non-namespace names (C++
1675 /// [basic.lookup.udir]p1).
1676 LookupNamespaceName,
1677 /// Look up all declarations in a scope with the given name,
1678 /// including resolved using declarations. This is appropriate
1679 /// for checking redeclarations for a using declaration.
1680 LookupUsingDeclName,
1681 /// Look up an ordinary name that is going to be redeclared as a
1682 /// name with linkage. This lookup ignores any declarations that
1683 /// are outside of the current scope unless they have linkage. See
1684 /// C99 6.2.2p4-5 and C++ [basic.link]p6.
1685 LookupRedeclarationWithLinkage,
1686 /// Look up the name of an Objective-C protocol.
1687 LookupObjCProtocolName,
1688 /// Look up implicit 'self' parameter of an objective-c method.
1689 LookupObjCImplicitSelfParam,
1690 /// \brief Look up any declaration with any name.
1694 /// \brief Specifies whether (or how) name lookup is being performed for a
1695 /// redeclaration (vs. a reference).
1696 enum RedeclarationKind {
1697 /// \brief The lookup is a reference to this name that is not for the
1698 /// purpose of redeclaring the name.
1699 NotForRedeclaration = 0,
1700 /// \brief The lookup results will be used for redeclaration of a name,
1701 /// if an entity by that name already exists.
1706 bool CppLookupName(LookupResult &R, Scope *S);
1708 SpecialMemberOverloadResult *LookupSpecialMember(CXXRecordDecl *D,
1709 CXXSpecialMember SM,
1716 // \brief The set of known/encountered (unique, canonicalized) NamespaceDecls.
1718 // The boolean value will be true to indicate that the namespace was loaded
1719 // from an AST/PCH file, or false otherwise.
1720 llvm::DenseMap<NamespaceDecl*, bool> KnownNamespaces;
1722 /// \brief Whether we have already loaded known namespaces from an extenal
1724 bool LoadedExternalKnownNamespaces;
1727 /// \brief Look up a name, looking for a single declaration. Return
1728 /// null if the results were absent, ambiguous, or overloaded.
1730 /// It is preferable to use the elaborated form and explicitly handle
1731 /// ambiguity and overloaded.
1732 NamedDecl *LookupSingleName(Scope *S, DeclarationName Name,
1734 LookupNameKind NameKind,
1735 RedeclarationKind Redecl
1736 = NotForRedeclaration);
1737 bool LookupName(LookupResult &R, Scope *S,
1738 bool AllowBuiltinCreation = false);
1739 bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
1740 bool InUnqualifiedLookup = false);
1741 bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS,
1742 bool AllowBuiltinCreation = false,
1743 bool EnteringContext = false);
1744 ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc);
1746 void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
1747 QualType T1, QualType T2,
1748 UnresolvedSetImpl &Functions);
1750 LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc,
1751 SourceLocation GnuLabelLoc = SourceLocation());
1753 DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class);
1754 CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class);
1755 CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class,
1757 bool *ConstParam = 0);
1758 CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals,
1759 bool RValueThis, unsigned ThisQuals,
1760 bool *ConstParam = 0);
1761 CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class);
1762 CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, bool RValueThis,
1763 unsigned ThisQuals);
1764 CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class);
1766 void ArgumentDependentLookup(DeclarationName Name, bool Operator,
1767 Expr **Args, unsigned NumArgs,
1768 ADLResult &Functions,
1769 bool StdNamespaceIsAssociated = false);
1771 void LookupVisibleDecls(Scope *S, LookupNameKind Kind,
1772 VisibleDeclConsumer &Consumer,
1773 bool IncludeGlobalScope = true);
1774 void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind,
1775 VisibleDeclConsumer &Consumer,
1776 bool IncludeGlobalScope = true);
1778 /// \brief The context in which typo-correction occurs.
1780 /// The typo-correction context affects which keywords (if any) are
1781 /// considered when trying to correct for typos.
1782 enum CorrectTypoContext {
1783 /// \brief An unknown context, where any keyword might be valid.
1785 /// \brief A context where no keywords are used (e.g. we expect an actual
1788 /// \brief A context where we're correcting a type name.
1790 /// \brief An expression context.
1792 /// \brief A type cast, or anything else that can be followed by a '<'.
1794 /// \brief A member lookup context.
1796 /// \brief An Objective-C ivar lookup context (e.g., self->ivar).
1798 /// \brief An Objective-C property lookup context (e.g., self.prop).
1799 CTC_ObjCPropertyLookup,
1800 /// \brief The receiver of an Objective-C message send within an
1801 /// Objective-C method where 'super' is a valid keyword.
1802 CTC_ObjCMessageReceiver
1805 TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
1806 Sema::LookupNameKind LookupKind,
1807 Scope *S, CXXScopeSpec *SS,
1808 DeclContext *MemberContext = NULL,
1809 bool EnteringContext = false,
1810 CorrectTypoContext CTC = CTC_Unknown,
1811 const ObjCObjectPointerType *OPT = NULL);
1813 void FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs,
1814 AssociatedNamespaceSet &AssociatedNamespaces,
1815 AssociatedClassSet &AssociatedClasses);
1817 void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S,
1818 bool ConsiderLinkage,
1819 bool ExplicitInstantiationOrSpecialization);
1821 bool DiagnoseAmbiguousLookup(LookupResult &Result);
1824 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id,
1825 SourceLocation IdLoc,
1826 bool TypoCorrection = false);
1827 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
1828 Scope *S, bool ForRedeclaration,
1829 SourceLocation Loc);
1830 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
1832 void AddKnownFunctionAttributes(FunctionDecl *FD);
1834 // More parsing and symbol table subroutines.
1836 // Decl attributes - this routine is the top level dispatcher.
1837 void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD,
1838 bool NonInheritable = true, bool Inheritable = true);
1839 void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL,
1840 bool NonInheritable = true, bool Inheritable = true);
1841 bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl,
1842 const AttributeList *AttrList);
1844 void checkUnusedDeclAttributes(Declarator &D);
1846 bool CheckRegparmAttr(const AttributeList &attr, unsigned &value);
1847 bool CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC);
1848 bool CheckNoReturnAttr(const AttributeList &attr);
1850 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
1851 bool &IncompleteImpl, unsigned DiagID);
1852 void WarnConflictingTypedMethods(ObjCMethodDecl *Method,
1853 ObjCMethodDecl *MethodDecl,
1854 bool IsProtocolMethodDecl);
1856 void CheckConflictingOverridingMethod(ObjCMethodDecl *Method,
1857 ObjCMethodDecl *Overridden,
1858 bool IsProtocolMethodDecl);
1860 /// WarnExactTypedMethods - This routine issues a warning if method
1861 /// implementation declaration matches exactly that of its declaration.
1862 void WarnExactTypedMethods(ObjCMethodDecl *Method,
1863 ObjCMethodDecl *MethodDecl,
1864 bool IsProtocolMethodDecl);
1866 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl,
1867 ObjCInterfaceDecl *IDecl);
1869 typedef llvm::DenseSet<Selector, llvm::DenseMapInfo<Selector> > SelectorSet;
1870 typedef llvm::DenseMap<Selector, ObjCMethodDecl*> ProtocolsMethodsMap;
1872 /// CheckProtocolMethodDefs - This routine checks unimplemented
1873 /// methods declared in protocol, and those referenced by it.
1874 /// \param IDecl - Used for checking for methods which may have been
1876 void CheckProtocolMethodDefs(SourceLocation ImpLoc,
1877 ObjCProtocolDecl *PDecl,
1878 bool& IncompleteImpl,
1879 const SelectorSet &InsMap,
1880 const SelectorSet &ClsMap,
1881 ObjCContainerDecl *CDecl);
1883 /// CheckImplementationIvars - This routine checks if the instance variables
1884 /// listed in the implelementation match those listed in the interface.
1885 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
1886 ObjCIvarDecl **Fields, unsigned nIvars,
1887 SourceLocation Loc);
1889 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
1890 /// remains unimplemented in the class or category @implementation.
1891 void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl,
1892 ObjCContainerDecl* IDecl,
1893 bool IncompleteImpl = false);
1895 /// DiagnoseUnimplementedProperties - This routine warns on those properties
1896 /// which must be implemented by this implementation.
1897 void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl,
1898 ObjCContainerDecl *CDecl,
1899 const SelectorSet &InsMap);
1901 /// DefaultSynthesizeProperties - This routine default synthesizes all
1902 /// properties which must be synthesized in class's @implementation.
1903 void DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl,
1904 ObjCInterfaceDecl *IDecl);
1905 void DefaultSynthesizeProperties(Scope *S, Decl *D);
1907 /// CollectImmediateProperties - This routine collects all properties in
1908 /// the class and its conforming protocols; but not those it its super class.
1909 void CollectImmediateProperties(ObjCContainerDecl *CDecl,
1910 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap,
1911 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& SuperPropMap);
1914 /// LookupPropertyDecl - Looks up a property in the current class and all
1916 ObjCPropertyDecl *LookupPropertyDecl(const ObjCContainerDecl *CDecl,
1917 IdentifierInfo *II);
1919 /// Called by ActOnProperty to handle @property declarations in
1920 //// class extensions.
1921 Decl *HandlePropertyInClassExtension(Scope *S,
1922 SourceLocation AtLoc,
1923 FieldDeclarator &FD,
1926 const bool isAssign,
1927 const bool isReadWrite,
1928 const unsigned Attributes,
1929 bool *isOverridingProperty,
1931 tok::ObjCKeywordKind MethodImplKind);
1933 /// Called by ActOnProperty and HandlePropertyInClassExtension to
1934 /// handle creating the ObjcPropertyDecl for a category or @interface.
1935 ObjCPropertyDecl *CreatePropertyDecl(Scope *S,
1936 ObjCContainerDecl *CDecl,
1937 SourceLocation AtLoc,
1938 FieldDeclarator &FD,
1941 const bool isAssign,
1942 const bool isReadWrite,
1943 const unsigned Attributes,
1945 tok::ObjCKeywordKind MethodImplKind,
1946 DeclContext *lexicalDC = 0);
1948 /// AtomicPropertySetterGetterRules - This routine enforces the rule (via
1949 /// warning) when atomic property has one but not the other user-declared
1950 /// setter or getter.
1951 void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl,
1952 ObjCContainerDecl* IDecl);
1954 void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D);
1956 void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID);
1958 enum MethodMatchStrategy {
1963 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
1964 /// true, or false, accordingly.
1965 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
1966 const ObjCMethodDecl *PrevMethod,
1967 MethodMatchStrategy strategy = MMS_strict);
1969 /// MatchAllMethodDeclarations - Check methods declaraed in interface or
1970 /// or protocol against those declared in their implementations.
1971 void MatchAllMethodDeclarations(const SelectorSet &InsMap,
1972 const SelectorSet &ClsMap,
1973 SelectorSet &InsMapSeen,
1974 SelectorSet &ClsMapSeen,
1975 ObjCImplDecl* IMPDecl,
1976 ObjCContainerDecl* IDecl,
1977 bool &IncompleteImpl,
1978 bool ImmediateClass,
1979 bool WarnExactMatch=false);
1981 /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in
1982 /// category matches with those implemented in its primary class and
1983 /// warns each time an exact match is found.
1984 void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP);
1987 /// AddMethodToGlobalPool - Add an instance or factory method to the global
1988 /// pool. See descriptoin of AddInstanceMethodToGlobalPool.
1989 void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance);
1991 /// LookupMethodInGlobalPool - Returns the instance or factory method and
1992 /// optionally warns if there are multiple signatures.
1993 ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R,
1994 bool receiverIdOrClass,
1995 bool warn, bool instance);
1998 /// AddInstanceMethodToGlobalPool - All instance methods in a translation
1999 /// unit are added to a global pool. This allows us to efficiently associate
2000 /// a selector with a method declaraation for purposes of typechecking
2001 /// messages sent to "id" (where the class of the object is unknown).
2002 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
2003 AddMethodToGlobalPool(Method, impl, /*instance*/true);
2006 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
2007 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
2008 AddMethodToGlobalPool(Method, impl, /*instance*/false);
2011 /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global
2013 void AddAnyMethodToGlobalPool(Decl *D);
2015 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
2016 /// there are multiple signatures.
2017 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R,
2018 bool receiverIdOrClass=false,
2020 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
2021 warn, /*instance*/true);
2024 /// LookupFactoryMethodInGlobalPool - Returns the method and warns if
2025 /// there are multiple signatures.
2026 ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R,
2027 bool receiverIdOrClass=false,
2029 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
2030 warn, /*instance*/false);
2033 /// LookupImplementedMethodInGlobalPool - Returns the method which has an
2035 ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel);
2037 /// CollectIvarsToConstructOrDestruct - Collect those ivars which require
2039 void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI,
2040 SmallVectorImpl<ObjCIvarDecl*> &Ivars);
2042 //===--------------------------------------------------------------------===//
2043 // Statement Parsing Callbacks: SemaStmt.cpp.
2047 FullExprArg(Sema &actions) : E(0) { }
2049 // FIXME: The const_cast here is ugly. RValue references would make this
2050 // much nicer (or we could duplicate a bunch of the move semantics
2051 // emulation code from Ownership.h).
2052 FullExprArg(const FullExprArg& Other) : E(Other.E) {}
2054 ExprResult release() {
2058 Expr *get() const { return E; }
2060 Expr *operator->() {
2065 // FIXME: No need to make the entire Sema class a friend when it's just
2066 // Sema::MakeFullExpr that needs access to the constructor below.
2069 explicit FullExprArg(Expr *expr) : E(expr) {}
2074 FullExprArg MakeFullExpr(Expr *Arg) {
2075 return FullExprArg(ActOnFinishFullExpr(Arg).release());
2078 StmtResult ActOnExprStmt(FullExprArg Expr);
2080 StmtResult ActOnNullStmt(SourceLocation SemiLoc,
2081 bool HasLeadingEmptyMacro = false);
2082 StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
2085 StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl,
2086 SourceLocation StartLoc,
2087 SourceLocation EndLoc);
2088 void ActOnForEachDeclStmt(DeclGroupPtrTy Decl);
2089 StmtResult ActOnForEachLValueExpr(Expr *E);
2090 StmtResult ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal,
2091 SourceLocation DotDotDotLoc, Expr *RHSVal,
2092 SourceLocation ColonLoc);
2093 void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt);
2095 StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
2096 SourceLocation ColonLoc,
2097 Stmt *SubStmt, Scope *CurScope);
2098 StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl,
2099 SourceLocation ColonLoc, Stmt *SubStmt);
2101 StmtResult ActOnIfStmt(SourceLocation IfLoc,
2102 FullExprArg CondVal, Decl *CondVar,
2104 SourceLocation ElseLoc, Stmt *ElseVal);
2105 StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc,
2108 StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
2109 Stmt *Switch, Stmt *Body);
2110 StmtResult ActOnWhileStmt(SourceLocation WhileLoc,
2112 Decl *CondVar, Stmt *Body);
2113 StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body,
2114 SourceLocation WhileLoc,
2115 SourceLocation CondLParen, Expr *Cond,
2116 SourceLocation CondRParen);
2118 StmtResult ActOnForStmt(SourceLocation ForLoc,
2119 SourceLocation LParenLoc,
2120 Stmt *First, FullExprArg Second,
2123 SourceLocation RParenLoc,
2125 ExprResult ActOnObjCForCollectionOperand(SourceLocation forLoc,
2127 StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
2128 SourceLocation LParenLoc,
2129 Stmt *First, Expr *Second,
2130 SourceLocation RParenLoc, Stmt *Body);
2131 StmtResult ActOnCXXForRangeStmt(SourceLocation ForLoc,
2132 SourceLocation LParenLoc, Stmt *LoopVar,
2133 SourceLocation ColonLoc, Expr *Collection,
2134 SourceLocation RParenLoc);
2135 StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc,
2136 SourceLocation ColonLoc,
2137 Stmt *RangeDecl, Stmt *BeginEndDecl,
2138 Expr *Cond, Expr *Inc,
2140 SourceLocation RParenLoc);
2141 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body);
2143 StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
2144 SourceLocation LabelLoc,
2145 LabelDecl *TheDecl);
2146 StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
2147 SourceLocation StarLoc,
2149 StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope);
2150 StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
2152 const VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E,
2153 bool AllowFunctionParameters);
2155 StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
2156 StmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
2158 StmtResult ActOnAsmStmt(SourceLocation AsmLoc,
2159 bool IsSimple, bool IsVolatile,
2160 unsigned NumOutputs, unsigned NumInputs,
2161 IdentifierInfo **Names,
2162 MultiExprArg Constraints,
2165 MultiExprArg Clobbers,
2166 SourceLocation RParenLoc,
2167 bool MSAsm = false);
2170 VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType,
2171 SourceLocation StartLoc,
2172 SourceLocation IdLoc, IdentifierInfo *Id,
2173 bool Invalid = false);
2175 Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D);
2177 StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen,
2178 Decl *Parm, Stmt *Body);
2180 StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body);
2182 StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try,
2183 MultiStmtArg Catch, Stmt *Finally);
2185 StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw);
2186 StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw,
2188 ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc,
2190 StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
2194 StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body);
2196 VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo,
2197 SourceLocation StartLoc,
2198 SourceLocation IdLoc,
2199 IdentifierInfo *Id);
2201 Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D);
2203 StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
2204 Decl *ExDecl, Stmt *HandlerBlock);
2205 StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
2206 MultiStmtArg Handlers);
2208 StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ?
2209 SourceLocation TryLoc,
2213 StmtResult ActOnSEHExceptBlock(SourceLocation Loc,
2217 StmtResult ActOnSEHFinallyBlock(SourceLocation Loc,
2220 void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock);
2222 bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const;
2224 /// \brief If it's a file scoped decl that must warn if not used, keep track
2226 void MarkUnusedFileScopedDecl(const DeclaratorDecl *D);
2228 /// DiagnoseUnusedExprResult - If the statement passed in is an expression
2229 /// whose result is unused, warn.
2230 void DiagnoseUnusedExprResult(const Stmt *S);
2231 void DiagnoseUnusedDecl(const NamedDecl *ND);
2233 ParsingDeclState PushParsingDeclaration() {
2234 return DelayedDiagnostics.pushParsingDecl();
2236 void PopParsingDeclaration(ParsingDeclState state, Decl *decl) {
2237 DelayedDiagnostics::popParsingDecl(*this, state, decl);
2240 typedef ProcessingContextState ParsingClassState;
2241 ParsingClassState PushParsingClass() {
2242 return DelayedDiagnostics.pushContext();
2244 void PopParsingClass(ParsingClassState state) {
2245 DelayedDiagnostics.popContext(state);
2248 void EmitDeprecationWarning(NamedDecl *D, StringRef Message,
2250 const ObjCInterfaceDecl *UnknownObjCClass=0);
2252 void HandleDelayedDeprecationCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
2254 bool makeUnavailableInSystemHeader(SourceLocation loc,
2257 //===--------------------------------------------------------------------===//
2258 // Expression Parsing Callbacks: SemaExpr.cpp.
2260 bool CanUseDecl(NamedDecl *D);
2261 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
2262 const ObjCInterfaceDecl *UnknownObjCClass=0);
2263 std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD);
2264 bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
2265 ObjCMethodDecl *Getter,
2266 SourceLocation Loc);
2267 void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
2268 Expr **Args, unsigned NumArgs);
2270 void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext);
2272 void PopExpressionEvaluationContext();
2274 void DiscardCleanupsInEvaluationContext();
2276 void MarkDeclarationReferenced(SourceLocation Loc, Decl *D);
2277 void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T);
2278 void MarkDeclarationsReferencedInExpr(Expr *E);
2280 /// \brief Try to recover by turning the given expression into a
2281 /// call. Returns true if recovery was attempted or an error was
2282 /// emitted; this may also leave the ExprResult invalid.
2283 bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD,
2284 bool ForceComplain = false,
2285 bool (*IsPlausibleResult)(QualType) = 0);
2287 /// \brief Figure out if an expression could be turned into a call.
2288 bool isExprCallable(const Expr &E, QualType &ZeroArgCallReturnTy,
2289 UnresolvedSetImpl &NonTemplateOverloads);
2291 /// \brief Conditionally issue a diagnostic based on the current
2292 /// evaluation context.
2294 /// \param stmt - If stmt is non-null, delay reporting the diagnostic until
2295 /// the function body is parsed, and then do a basic reachability analysis to
2296 /// determine if the statement is reachable. If it is unreachable, the
2297 /// diagnostic will not be emitted.
2298 bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement,
2299 const PartialDiagnostic &PD);
2301 // Primary Expressions.
2302 SourceRange getExprRange(Expr *E) const;
2304 ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, UnqualifiedId &Id,
2305 bool HasTrailingLParen, bool IsAddressOfOperand);
2307 void DecomposeUnqualifiedId(const UnqualifiedId &Id,
2308 TemplateArgumentListInfo &Buffer,
2309 DeclarationNameInfo &NameInfo,
2310 const TemplateArgumentListInfo *&TemplateArgs);
2312 bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
2313 CorrectTypoContext CTC = CTC_Unknown,
2314 TemplateArgumentListInfo *ExplicitTemplateArgs = 0,
2315 Expr **Args = 0, unsigned NumArgs = 0);
2317 ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S,
2319 bool AllowBuiltinCreation=false);
2321 ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS,
2322 const DeclarationNameInfo &NameInfo,
2323 bool isAddressOfOperand,
2324 const TemplateArgumentListInfo *TemplateArgs);
2326 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
2329 const CXXScopeSpec *SS = 0);
2330 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
2332 const DeclarationNameInfo &NameInfo,
2333 const CXXScopeSpec *SS = 0);
2335 BuildAnonymousStructUnionMemberReference(const CXXScopeSpec &SS,
2336 SourceLocation nameLoc,
2337 IndirectFieldDecl *indirectField,
2338 Expr *baseObjectExpr = 0,
2339 SourceLocation opLoc = SourceLocation());
2340 ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
2342 const TemplateArgumentListInfo *TemplateArgs);
2343 ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS,
2345 const TemplateArgumentListInfo *TemplateArgs,
2346 bool IsDefiniteInstance);
2347 bool UseArgumentDependentLookup(const CXXScopeSpec &SS,
2348 const LookupResult &R,
2349 bool HasTrailingLParen);
2351 ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS,
2352 const DeclarationNameInfo &NameInfo);
2353 ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
2354 const DeclarationNameInfo &NameInfo,
2355 const TemplateArgumentListInfo *TemplateArgs);
2357 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
2360 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
2361 const DeclarationNameInfo &NameInfo,
2364 ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
2365 ExprResult ActOnNumericConstant(const Token &Tok);
2366 ExprResult ActOnCharacterConstant(const Token &Tok);
2367 ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E);
2368 ExprResult ActOnParenOrParenListExpr(SourceLocation L,
2372 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
2373 /// fragments (e.g. "foo" "bar" L"baz").
2374 ExprResult ActOnStringLiteral(const Token *StringToks,
2375 unsigned NumStringToks);
2377 ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc,
2378 SourceLocation DefaultLoc,
2379 SourceLocation RParenLoc,
2380 Expr *ControllingExpr,
2381 MultiTypeArg ArgTypes,
2382 MultiExprArg ArgExprs);
2383 ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc,
2384 SourceLocation DefaultLoc,
2385 SourceLocation RParenLoc,
2386 Expr *ControllingExpr,
2387 TypeSourceInfo **Types,
2389 unsigned NumAssocs);
2391 // Binary/Unary Operators. 'Tok' is the token for the operator.
2392 ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc,
2394 ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc,
2395 UnaryOperatorKind Opc, Expr *Input);
2396 ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
2397 tok::TokenKind Op, Expr *Input);
2399 ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo,
2400 SourceLocation OpLoc,
2401 UnaryExprOrTypeTrait ExprKind,
2403 ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc,
2404 UnaryExprOrTypeTrait ExprKind);
2406 ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc,
2407 UnaryExprOrTypeTrait ExprKind,
2408 bool IsType, void *TyOrEx,
2409 const SourceRange &ArgRange);
2411 ExprResult CheckPlaceholderExpr(Expr *E);
2412 bool CheckVecStepExpr(Expr *E);
2414 bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind);
2415 bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc,
2416 SourceRange ExprRange,
2417 UnaryExprOrTypeTrait ExprKind);
2418 ExprResult ActOnSizeofParameterPackExpr(Scope *S,
2419 SourceLocation OpLoc,
2420 IdentifierInfo &Name,
2421 SourceLocation NameLoc,
2422 SourceLocation RParenLoc);
2423 ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
2424 tok::TokenKind Kind, Expr *Input);
2426 ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc,
2427 Expr *Idx, SourceLocation RLoc);
2428 ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc,
2429 Expr *Idx, SourceLocation RLoc);
2431 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
2432 SourceLocation OpLoc, bool IsArrow,
2434 NamedDecl *FirstQualifierInScope,
2435 const DeclarationNameInfo &NameInfo,
2436 const TemplateArgumentListInfo *TemplateArgs);
2438 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
2439 SourceLocation OpLoc, bool IsArrow,
2440 const CXXScopeSpec &SS,
2441 NamedDecl *FirstQualifierInScope,
2443 const TemplateArgumentListInfo *TemplateArgs,
2444 bool SuppressQualifierCheck = false);
2446 ExprResult LookupMemberExpr(LookupResult &R, ExprResult &Base,
2447 bool &IsArrow, SourceLocation OpLoc,
2450 bool HasTemplateArgs);
2452 bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType,
2453 const CXXScopeSpec &SS,
2454 const LookupResult &R);
2456 ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType,
2457 bool IsArrow, SourceLocation OpLoc,
2458 const CXXScopeSpec &SS,
2459 NamedDecl *FirstQualifierInScope,
2460 const DeclarationNameInfo &NameInfo,
2461 const TemplateArgumentListInfo *TemplateArgs);
2463 ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base,
2464 SourceLocation OpLoc,
2465 tok::TokenKind OpKind,
2467 UnqualifiedId &Member,
2469 bool HasTrailingLParen);
2471 void ActOnDefaultCtorInitializers(Decl *CDtorDecl);
2472 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
2473 FunctionDecl *FDecl,
2474 const FunctionProtoType *Proto,
2475 Expr **Args, unsigned NumArgs,
2476 SourceLocation RParenLoc,
2477 bool ExecConfig = false);
2479 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
2480 /// This provides the location of the left/right parens and a list of comma
2482 ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc,
2483 MultiExprArg ArgExprs, SourceLocation RParenLoc,
2484 Expr *ExecConfig = 0, bool IsExecConfig = false);
2485 ExprResult BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl,
2486 SourceLocation LParenLoc,
2487 Expr **Args, unsigned NumArgs,
2488 SourceLocation RParenLoc,
2490 bool IsExecConfig = false);
2492 ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc,
2493 MultiExprArg ExecConfig,
2494 SourceLocation GGGLoc);
2496 ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc,
2497 Declarator &D, ParsedType &Ty,
2498 SourceLocation RParenLoc, Expr *CastExpr);
2499 ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc,
2501 SourceLocation RParenLoc,
2503 CastKind PrepareScalarCast(ExprResult &src, QualType destType);
2505 /// \brief Build an altivec or OpenCL literal.
2506 ExprResult BuildVectorLiteral(SourceLocation LParenLoc,
2507 SourceLocation RParenLoc, Expr *E,
2508 TypeSourceInfo *TInfo);
2510 ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME);
2512 ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
2514 SourceLocation RParenLoc,
2517 ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc,
2518 TypeSourceInfo *TInfo,
2519 SourceLocation RParenLoc,
2522 ExprResult ActOnInitList(SourceLocation LBraceLoc,
2523 MultiExprArg InitArgList,
2524 SourceLocation RBraceLoc);
2526 ExprResult ActOnDesignatedInitializer(Designation &Desig,
2531 ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
2532 tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr);
2533 ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc,
2534 BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr);
2535 ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc,
2536 Expr *LHSExpr, Expr *RHSExpr);
2538 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
2539 /// in the case of a the GNU conditional expr extension.
2540 ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
2541 SourceLocation ColonLoc,
2542 Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr);
2544 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
2545 ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
2546 LabelDecl *TheDecl);
2548 ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt,
2549 SourceLocation RPLoc); // "({..})"
2551 // __builtin_offsetof(type, identifier(.identifier|[expr])*)
2552 struct OffsetOfComponent {
2553 SourceLocation LocStart, LocEnd;
2554 bool isBrackets; // true if [expr], false if .ident
2556 IdentifierInfo *IdentInfo;
2561 /// __builtin_offsetof(type, a.b[123][456].c)
2562 ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc,
2563 TypeSourceInfo *TInfo,
2564 OffsetOfComponent *CompPtr,
2565 unsigned NumComponents,
2566 SourceLocation RParenLoc);
2567 ExprResult ActOnBuiltinOffsetOf(Scope *S,
2568 SourceLocation BuiltinLoc,
2569 SourceLocation TypeLoc,
2570 ParsedType ParsedArgTy,
2571 OffsetOfComponent *CompPtr,
2572 unsigned NumComponents,
2573 SourceLocation RParenLoc);
2575 // __builtin_choose_expr(constExpr, expr1, expr2)
2576 ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
2577 Expr *CondExpr, Expr *LHSExpr,
2578 Expr *RHSExpr, SourceLocation RPLoc);
2580 // __builtin_va_arg(expr, type)
2581 ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty,
2582 SourceLocation RPLoc);
2583 ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E,
2584 TypeSourceInfo *TInfo, SourceLocation RPLoc);
2587 ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
2589 bool CheckCaseExpression(Expr *E);
2591 bool CheckMicrosoftIfExistsSymbol(CXXScopeSpec &SS, UnqualifiedId &Name);
2593 //===------------------------- "Block" Extension ------------------------===//
2595 /// ActOnBlockStart - This callback is invoked when a block literal is
2597 void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
2599 /// ActOnBlockArguments - This callback allows processing of block arguments.
2600 /// If there are no arguments, this is still invoked.
2601 void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope);
2603 /// ActOnBlockError - If there is an error parsing a block, this callback
2604 /// is invoked to pop the information about the block from the action impl.
2605 void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
2607 /// ActOnBlockStmtExpr - This is called when the body of a block statement
2608 /// literal was successfully completed. ^(int x){...}
2609 ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body,
2612 //===---------------------------- OpenCL Features -----------------------===//
2614 /// __builtin_astype(...)
2615 ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy,
2616 SourceLocation BuiltinLoc,
2617 SourceLocation RParenLoc);
2619 //===---------------------------- C++ Features --------------------------===//
2621 // Act on C++ namespaces
2622 Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc,
2623 SourceLocation NamespaceLoc,
2624 SourceLocation IdentLoc,
2625 IdentifierInfo *Ident,
2626 SourceLocation LBrace,
2627 AttributeList *AttrList);
2628 void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace);
2630 NamespaceDecl *getStdNamespace() const;
2631 NamespaceDecl *getOrCreateStdNamespace();
2633 CXXRecordDecl *getStdBadAlloc() const;
2635 Decl *ActOnUsingDirective(Scope *CurScope,
2636 SourceLocation UsingLoc,
2637 SourceLocation NamespcLoc,
2639 SourceLocation IdentLoc,
2640 IdentifierInfo *NamespcName,
2641 AttributeList *AttrList);
2643 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
2645 Decl *ActOnNamespaceAliasDef(Scope *CurScope,
2646 SourceLocation NamespaceLoc,
2647 SourceLocation AliasLoc,
2648 IdentifierInfo *Alias,
2650 SourceLocation IdentLoc,
2651 IdentifierInfo *Ident);
2653 void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow);
2654 bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target,
2655 const LookupResult &PreviousDecls);
2656 UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD,
2659 bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc,
2661 const CXXScopeSpec &SS,
2662 SourceLocation NameLoc,
2663 const LookupResult &Previous);
2664 bool CheckUsingDeclQualifier(SourceLocation UsingLoc,
2665 const CXXScopeSpec &SS,
2666 SourceLocation NameLoc);
2668 NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS,
2669 SourceLocation UsingLoc,
2671 const DeclarationNameInfo &NameInfo,
2672 AttributeList *AttrList,
2673 bool IsInstantiation,
2675 SourceLocation TypenameLoc);
2677 bool CheckInheritedConstructorUsingDecl(UsingDecl *UD);
2679 Decl *ActOnUsingDeclaration(Scope *CurScope,
2681 bool HasUsingKeyword,
2682 SourceLocation UsingLoc,
2684 UnqualifiedId &Name,
2685 AttributeList *AttrList,
2687 SourceLocation TypenameLoc);
2688 Decl *ActOnAliasDeclaration(Scope *CurScope,
2690 MultiTemplateParamsArg TemplateParams,
2691 SourceLocation UsingLoc,
2692 UnqualifiedId &Name,
2695 /// AddCXXDirectInitializerToDecl - This action is called immediately after
2696 /// ActOnDeclarator, when a C++ direct initializer is present.
2697 /// e.g: "int x(1);"
2698 void AddCXXDirectInitializerToDecl(Decl *Dcl,
2699 SourceLocation LParenLoc,
2701 SourceLocation RParenLoc,
2702 bool TypeMayContainAuto);
2704 /// InitializeVarWithConstructor - Creates an CXXConstructExpr
2705 /// and sets it as the initializer for the the passed in VarDecl.
2706 bool InitializeVarWithConstructor(VarDecl *VD,
2707 CXXConstructorDecl *Constructor,
2709 bool HadMultipleCandidates);
2711 /// BuildCXXConstructExpr - Creates a complete call to a constructor,
2712 /// including handling of its default argument expressions.
2714 /// \param ConstructKind - a CXXConstructExpr::ConstructionKind
2716 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
2717 CXXConstructorDecl *Constructor, MultiExprArg Exprs,
2718 bool HadMultipleCandidates, bool RequiresZeroInit,
2719 unsigned ConstructKind, SourceRange ParenRange);
2721 // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if
2722 // the constructor can be elidable?
2724 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
2725 CXXConstructorDecl *Constructor, bool Elidable,
2726 MultiExprArg Exprs, bool HadMultipleCandidates,
2727 bool RequiresZeroInit, unsigned ConstructKind,
2728 SourceRange ParenRange);
2730 /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating
2731 /// the default expr if needed.
2732 ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc,
2734 ParmVarDecl *Param);
2736 /// FinalizeVarWithDestructor - Prepare for calling destructor on the
2737 /// constructed variable.
2738 void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType);
2740 /// \brief Helper class that collects exception specifications for
2741 /// implicitly-declared special member functions.
2742 class ImplicitExceptionSpecification {
2743 // Pointer to allow copying
2744 ASTContext *Context;
2745 // We order exception specifications thus:
2746 // noexcept is the most restrictive, but is only used in C++0x.
2747 // throw() comes next.
2748 // Then a throw(collected exceptions)
2749 // Finally no specification.
2750 // throw(...) is used instead if any called function uses it.
2752 // If this exception specification cannot be known yet (for instance,
2753 // because this is the exception specification for a defaulted default
2754 // constructor and we haven't finished parsing the deferred parts of the
2755 // class yet), the C++0x standard does not specify how to behave. We
2756 // record this as an 'unknown' exception specification, which overrules
2757 // any other specification (even 'none', to keep this rule simple).
2758 ExceptionSpecificationType ComputedEST;
2759 llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen;
2760 SmallVector<QualType, 4> Exceptions;
2762 void ClearExceptions() {
2763 ExceptionsSeen.clear();
2768 explicit ImplicitExceptionSpecification(ASTContext &Context)
2769 : Context(&Context), ComputedEST(EST_BasicNoexcept) {
2770 if (!Context.getLangOptions().CPlusPlus0x)
2771 ComputedEST = EST_DynamicNone;
2774 /// \brief Get the computed exception specification type.
2775 ExceptionSpecificationType getExceptionSpecType() const {
2776 assert(ComputedEST != EST_ComputedNoexcept &&
2777 "noexcept(expr) should not be a possible result");
2781 /// \brief The number of exceptions in the exception specification.
2782 unsigned size() const { return Exceptions.size(); }
2784 /// \brief The set of exceptions in the exception specification.
2785 const QualType *data() const { return Exceptions.data(); }
2787 /// \brief Integrate another called method into the collected data.
2788 void CalledDecl(CXXMethodDecl *Method);
2790 /// \brief Integrate an invoked expression into the collected data.
2791 void CalledExpr(Expr *E);
2793 /// \brief Specify that the exception specification can't be detemined yet.
2796 ComputedEST = EST_Delayed;
2799 FunctionProtoType::ExtProtoInfo getEPI() const {
2800 FunctionProtoType::ExtProtoInfo EPI;
2801 EPI.ExceptionSpecType = getExceptionSpecType();
2802 EPI.NumExceptions = size();
2803 EPI.Exceptions = data();
2808 /// \brief Determine what sort of exception specification a defaulted
2809 /// copy constructor of a class will have.
2810 ImplicitExceptionSpecification
2811 ComputeDefaultedDefaultCtorExceptionSpec(CXXRecordDecl *ClassDecl);
2813 /// \brief Determine what sort of exception specification a defaulted
2814 /// default constructor of a class will have, and whether the parameter
2816 std::pair<ImplicitExceptionSpecification, bool>
2817 ComputeDefaultedCopyCtorExceptionSpecAndConst(CXXRecordDecl *ClassDecl);
2819 /// \brief Determine what sort of exception specification a defautled
2820 /// copy assignment operator of a class will have, and whether the
2821 /// parameter will be const.
2822 std::pair<ImplicitExceptionSpecification, bool>
2823 ComputeDefaultedCopyAssignmentExceptionSpecAndConst(CXXRecordDecl *ClassDecl);
2825 /// \brief Determine what sort of exception specification a defaulted move
2826 /// constructor of a class will have.
2827 ImplicitExceptionSpecification
2828 ComputeDefaultedMoveCtorExceptionSpec(CXXRecordDecl *ClassDecl);
2830 /// \brief Determine what sort of exception specification a defaulted move
2831 /// assignment operator of a class will have.
2832 ImplicitExceptionSpecification
2833 ComputeDefaultedMoveAssignmentExceptionSpec(CXXRecordDecl *ClassDecl);
2835 /// \brief Determine what sort of exception specification a defaulted
2836 /// destructor of a class will have.
2837 ImplicitExceptionSpecification
2838 ComputeDefaultedDtorExceptionSpec(CXXRecordDecl *ClassDecl);
2840 /// \brief Determine if a special member function should have a deleted
2841 /// definition when it is defaulted.
2842 bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM);
2844 /// \brief Determine if a defaulted copy assignment operator ought to be
2846 bool ShouldDeleteCopyAssignmentOperator(CXXMethodDecl *MD);
2848 /// \brief Determine if a defaulted move assignment operator ought to be
2850 bool ShouldDeleteMoveAssignmentOperator(CXXMethodDecl *MD);
2852 /// \brief Determine if a defaulted destructor ought to be deleted.
2853 bool ShouldDeleteDestructor(CXXDestructorDecl *DD);
2855 /// \brief Declare the implicit default constructor for the given class.
2857 /// \param ClassDecl The class declaration into which the implicit
2858 /// default constructor will be added.
2860 /// \returns The implicitly-declared default constructor.
2861 CXXConstructorDecl *DeclareImplicitDefaultConstructor(
2862 CXXRecordDecl *ClassDecl);
2864 /// DefineImplicitDefaultConstructor - Checks for feasibility of
2865 /// defining this constructor as the default constructor.
2866 void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
2867 CXXConstructorDecl *Constructor);
2869 /// \brief Declare the implicit destructor for the given class.
2871 /// \param ClassDecl The class declaration into which the implicit
2872 /// destructor will be added.
2874 /// \returns The implicitly-declared destructor.
2875 CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl);
2877 /// DefineImplicitDestructor - Checks for feasibility of
2878 /// defining this destructor as the default destructor.
2879 void DefineImplicitDestructor(SourceLocation CurrentLocation,
2880 CXXDestructorDecl *Destructor);
2882 /// \brief Build an exception spec for destructors that don't have one.
2884 /// C++11 says that user-defined destructors with no exception spec get one
2885 /// that looks as if the destructor was implicitly declared.
2886 void AdjustDestructorExceptionSpec(CXXRecordDecl *ClassDecl,
2887 CXXDestructorDecl *Destructor);
2889 /// \brief Declare all inherited constructors for the given class.
2891 /// \param ClassDecl The class declaration into which the inherited
2892 /// constructors will be added.
2893 void DeclareInheritedConstructors(CXXRecordDecl *ClassDecl);
2895 /// \brief Declare the implicit copy constructor for the given class.
2897 /// \param ClassDecl The class declaration into which the implicit
2898 /// copy constructor will be added.
2900 /// \returns The implicitly-declared copy constructor.
2901 CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl);
2903 /// DefineImplicitCopyConstructor - Checks for feasibility of
2904 /// defining this constructor as the copy constructor.
2905 void DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
2906 CXXConstructorDecl *Constructor);
2908 /// \brief Declare the implicit move constructor for the given class.
2910 /// \param ClassDecl The Class declaration into which the implicit
2911 /// move constructor will be added.
2913 /// \returns The implicitly-declared move constructor, or NULL if it wasn't
2915 CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl);
2917 /// DefineImplicitMoveConstructor - Checks for feasibility of
2918 /// defining this constructor as the move constructor.
2919 void DefineImplicitMoveConstructor(SourceLocation CurrentLocation,
2920 CXXConstructorDecl *Constructor);
2922 /// \brief Declare the implicit copy assignment operator for the given class.
2924 /// \param ClassDecl The class declaration into which the implicit
2925 /// copy assignment operator will be added.
2927 /// \returns The implicitly-declared copy assignment operator.
2928 CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl);
2930 /// \brief Defines an implicitly-declared copy assignment operator.
2931 void DefineImplicitCopyAssignment(SourceLocation CurrentLocation,
2932 CXXMethodDecl *MethodDecl);
2934 /// \brief Declare the implicit move assignment operator for the given class.
2936 /// \param ClassDecl The Class declaration into which the implicit
2937 /// move assignment operator will be added.
2939 /// \returns The implicitly-declared move assignment operator, or NULL if it
2940 /// wasn't declared.
2941 CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl);
2943 /// \brief Defines an implicitly-declared move assignment operator.
2944 void DefineImplicitMoveAssignment(SourceLocation CurrentLocation,
2945 CXXMethodDecl *MethodDecl);
2947 /// \brief Force the declaration of any implicitly-declared members of this
2949 void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class);
2951 /// MaybeBindToTemporary - If the passed in expression has a record type with
2952 /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise
2953 /// it simply returns the passed in expression.
2954 ExprResult MaybeBindToTemporary(Expr *E);
2956 bool CompleteConstructorCall(CXXConstructorDecl *Constructor,
2957 MultiExprArg ArgsPtr,
2959 ASTOwningVector<Expr*> &ConvertedArgs);
2961 ParsedType getDestructorName(SourceLocation TildeLoc,
2962 IdentifierInfo &II, SourceLocation NameLoc,
2963 Scope *S, CXXScopeSpec &SS,
2964 ParsedType ObjectType,
2965 bool EnteringContext);
2967 // Checks that reinterpret casts don't have undefined behavior.
2968 void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType,
2969 bool IsDereference, SourceRange Range);
2971 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
2972 ExprResult ActOnCXXNamedCast(SourceLocation OpLoc,
2973 tok::TokenKind Kind,
2974 SourceLocation LAngleBracketLoc,
2976 SourceLocation RAngleBracketLoc,
2977 SourceLocation LParenLoc,
2979 SourceLocation RParenLoc);
2981 ExprResult BuildCXXNamedCast(SourceLocation OpLoc,
2982 tok::TokenKind Kind,
2985 SourceRange AngleBrackets,
2986 SourceRange Parens);
2988 ExprResult BuildCXXTypeId(QualType TypeInfoType,
2989 SourceLocation TypeidLoc,
2990 TypeSourceInfo *Operand,
2991 SourceLocation RParenLoc);
2992 ExprResult BuildCXXTypeId(QualType TypeInfoType,
2993 SourceLocation TypeidLoc,
2995 SourceLocation RParenLoc);
2997 /// ActOnCXXTypeid - Parse typeid( something ).
2998 ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
2999 SourceLocation LParenLoc, bool isType,
3001 SourceLocation RParenLoc);
3003 ExprResult BuildCXXUuidof(QualType TypeInfoType,
3004 SourceLocation TypeidLoc,
3005 TypeSourceInfo *Operand,
3006 SourceLocation RParenLoc);
3007 ExprResult BuildCXXUuidof(QualType TypeInfoType,
3008 SourceLocation TypeidLoc,
3010 SourceLocation RParenLoc);
3012 /// ActOnCXXUuidof - Parse __uuidof( something ).
3013 ExprResult ActOnCXXUuidof(SourceLocation OpLoc,
3014 SourceLocation LParenLoc, bool isType,
3016 SourceLocation RParenLoc);
3019 //// ActOnCXXThis - Parse 'this' pointer.
3020 ExprResult ActOnCXXThis(SourceLocation loc);
3022 /// getAndCaptureCurrentThisType - Try to capture a 'this' pointer. Returns
3023 /// the type of the 'this' pointer, or a null type if this is not possible.
3024 QualType getAndCaptureCurrentThisType();
3026 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
3027 ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
3029 /// ActOnCXXNullPtrLiteral - Parse 'nullptr'.
3030 ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc);
3032 //// ActOnCXXThrow - Parse throw expressions.
3033 ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr);
3034 ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex,
3035 bool IsThrownVarInScope);
3036 ExprResult CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *E,
3037 bool IsThrownVarInScope);
3039 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
3040 /// Can be interpreted either as function-style casting ("int(x)")
3041 /// or class type construction ("ClassType(x,y,z)")
3042 /// or creation of a value-initialized type ("int()").
3043 ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep,
3044 SourceLocation LParenLoc,
3046 SourceLocation RParenLoc);
3048 ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type,
3049 SourceLocation LParenLoc,
3051 SourceLocation RParenLoc);
3053 /// ActOnCXXNew - Parsed a C++ 'new' expression.
3054 ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
3055 SourceLocation PlacementLParen,
3056 MultiExprArg PlacementArgs,
3057 SourceLocation PlacementRParen,
3058 SourceRange TypeIdParens, Declarator &D,
3059 SourceLocation ConstructorLParen,
3060 MultiExprArg ConstructorArgs,
3061 SourceLocation ConstructorRParen);
3062 ExprResult BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
3063 SourceLocation PlacementLParen,
3064 MultiExprArg PlacementArgs,
3065 SourceLocation PlacementRParen,
3066 SourceRange TypeIdParens,
3068 TypeSourceInfo *AllocTypeInfo,
3070 SourceLocation ConstructorLParen,
3071 MultiExprArg ConstructorArgs,
3072 SourceLocation ConstructorRParen,
3073 bool TypeMayContainAuto = true);
3075 bool CheckAllocatedType(QualType AllocType, SourceLocation Loc,
3077 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
3078 bool UseGlobal, QualType AllocType, bool IsArray,
3079 Expr **PlaceArgs, unsigned NumPlaceArgs,
3080 FunctionDecl *&OperatorNew,
3081 FunctionDecl *&OperatorDelete);
3082 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
3083 DeclarationName Name, Expr** Args,
3084 unsigned NumArgs, DeclContext *Ctx,
3085 bool AllowMissing, FunctionDecl *&Operator,
3086 bool Diagnose = true);
3087 void DeclareGlobalNewDelete();
3088 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
3090 bool addMallocAttr = false);
3092 bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD,
3093 DeclarationName Name, FunctionDecl* &Operator,
3094 bool Diagnose = true);
3096 /// ActOnCXXDelete - Parsed a C++ 'delete' expression
3097 ExprResult ActOnCXXDelete(SourceLocation StartLoc,
3098 bool UseGlobal, bool ArrayForm,
3101 DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D);
3102 ExprResult CheckConditionVariable(VarDecl *ConditionVar,
3103 SourceLocation StmtLoc,
3104 bool ConvertToBoolean);
3106 ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen,
3107 Expr *Operand, SourceLocation RParen);
3108 ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand,
3109 SourceLocation RParen);
3111 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
3112 /// pseudo-functions.
3113 ExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
3114 SourceLocation KWLoc,
3116 SourceLocation RParen);
3118 ExprResult BuildUnaryTypeTrait(UnaryTypeTrait OTT,
3119 SourceLocation KWLoc,
3121 SourceLocation RParen);
3123 /// ActOnBinaryTypeTrait - Parsed one of the bianry type trait support
3124 /// pseudo-functions.
3125 ExprResult ActOnBinaryTypeTrait(BinaryTypeTrait OTT,
3126 SourceLocation KWLoc,
3129 SourceLocation RParen);
3131 ExprResult BuildBinaryTypeTrait(BinaryTypeTrait BTT,
3132 SourceLocation KWLoc,
3133 TypeSourceInfo *LhsT,
3134 TypeSourceInfo *RhsT,
3135 SourceLocation RParen);
3137 /// ActOnArrayTypeTrait - Parsed one of the bianry type trait support
3138 /// pseudo-functions.
3139 ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT,
3140 SourceLocation KWLoc,
3143 SourceLocation RParen);
3145 ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT,
3146 SourceLocation KWLoc,
3147 TypeSourceInfo *TSInfo,
3149 SourceLocation RParen);
3151 /// ActOnExpressionTrait - Parsed one of the unary type trait support
3152 /// pseudo-functions.
3153 ExprResult ActOnExpressionTrait(ExpressionTrait OET,
3154 SourceLocation KWLoc,
3156 SourceLocation RParen);
3158 ExprResult BuildExpressionTrait(ExpressionTrait OET,
3159 SourceLocation KWLoc,
3161 SourceLocation RParen);
3163 ExprResult ActOnStartCXXMemberReference(Scope *S,
3165 SourceLocation OpLoc,
3166 tok::TokenKind OpKind,
3167 ParsedType &ObjectType,
3168 bool &MayBePseudoDestructor);
3170 ExprResult DiagnoseDtorReference(SourceLocation NameLoc, Expr *MemExpr);
3172 ExprResult BuildPseudoDestructorExpr(Expr *Base,
3173 SourceLocation OpLoc,
3174 tok::TokenKind OpKind,
3175 const CXXScopeSpec &SS,
3176 TypeSourceInfo *ScopeType,
3177 SourceLocation CCLoc,
3178 SourceLocation TildeLoc,
3179 PseudoDestructorTypeStorage DestroyedType,
3180 bool HasTrailingLParen);
3182 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
3183 SourceLocation OpLoc,
3184 tok::TokenKind OpKind,
3186 UnqualifiedId &FirstTypeName,
3187 SourceLocation CCLoc,
3188 SourceLocation TildeLoc,
3189 UnqualifiedId &SecondTypeName,
3190 bool HasTrailingLParen);
3192 /// MaybeCreateExprWithCleanups - If the current full-expression
3193 /// requires any cleanups, surround it with a ExprWithCleanups node.
3194 /// Otherwise, just returns the passed-in expression.
3195 Expr *MaybeCreateExprWithCleanups(Expr *SubExpr);
3196 Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt);
3197 ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr);
3199 ExprResult ActOnFinishFullExpr(Expr *Expr);
3200 StmtResult ActOnFinishFullStmt(Stmt *Stmt);
3202 // Marks SS invalid if it represents an incomplete type.
3203 bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC);
3205 DeclContext *computeDeclContext(QualType T);
3206 DeclContext *computeDeclContext(const CXXScopeSpec &SS,
3207 bool EnteringContext = false);
3208 bool isDependentScopeSpecifier(const CXXScopeSpec &SS);
3209 CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS);
3210 bool isUnknownSpecialization(const CXXScopeSpec &SS);
3212 /// \brief The parser has parsed a global nested-name-specifier '::'.
3214 /// \param S The scope in which this nested-name-specifier occurs.
3216 /// \param CCLoc The location of the '::'.
3218 /// \param SS The nested-name-specifier, which will be updated in-place
3219 /// to reflect the parsed nested-name-specifier.
3221 /// \returns true if an error occurred, false otherwise.
3222 bool ActOnCXXGlobalScopeSpecifier(Scope *S, SourceLocation CCLoc,
3225 bool isAcceptableNestedNameSpecifier(NamedDecl *SD);
3226 NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS);
3228 bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS,
3229 SourceLocation IdLoc,
3231 ParsedType ObjectType);
3233 bool BuildCXXNestedNameSpecifier(Scope *S,
3234 IdentifierInfo &Identifier,
3235 SourceLocation IdentifierLoc,
3236 SourceLocation CCLoc,
3237 QualType ObjectType,
3238 bool EnteringContext,
3240 NamedDecl *ScopeLookupResult,
3241 bool ErrorRecoveryLookup);
3243 /// \brief The parser has parsed a nested-name-specifier 'identifier::'.
3245 /// \param S The scope in which this nested-name-specifier occurs.
3247 /// \param Identifier The identifier preceding the '::'.
3249 /// \param IdentifierLoc The location of the identifier.
3251 /// \param CCLoc The location of the '::'.
3253 /// \param ObjectType The type of the object, if we're parsing
3254 /// nested-name-specifier in a member access expression.
3256 /// \param EnteringContext Whether we're entering the context nominated by
3257 /// this nested-name-specifier.
3259 /// \param SS The nested-name-specifier, which is both an input
3260 /// parameter (the nested-name-specifier before this type) and an
3261 /// output parameter (containing the full nested-name-specifier,
3262 /// including this new type).
3264 /// \returns true if an error occurred, false otherwise.
3265 bool ActOnCXXNestedNameSpecifier(Scope *S,
3266 IdentifierInfo &Identifier,
3267 SourceLocation IdentifierLoc,
3268 SourceLocation CCLoc,
3269 ParsedType ObjectType,
3270 bool EnteringContext,
3273 bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS,
3274 IdentifierInfo &Identifier,
3275 SourceLocation IdentifierLoc,
3276 SourceLocation ColonLoc,
3277 ParsedType ObjectType,
3278 bool EnteringContext);
3280 /// \brief The parser has parsed a nested-name-specifier
3281 /// 'template[opt] template-name < template-args >::'.
3283 /// \param S The scope in which this nested-name-specifier occurs.
3285 /// \param TemplateLoc The location of the 'template' keyword, if any.
3287 /// \param SS The nested-name-specifier, which is both an input
3288 /// parameter (the nested-name-specifier before this type) and an
3289 /// output parameter (containing the full nested-name-specifier,
3290 /// including this new type).
3292 /// \param TemplateLoc the location of the 'template' keyword, if any.
3293 /// \param TemplateName The template name.
3294 /// \param TemplateNameLoc The location of the template name.
3295 /// \param LAngleLoc The location of the opening angle bracket ('<').
3296 /// \param TemplateArgs The template arguments.
3297 /// \param RAngleLoc The location of the closing angle bracket ('>').
3298 /// \param CCLoc The location of the '::'.
3300 /// \param EnteringContext Whether we're entering the context of the
3301 /// nested-name-specifier.
3304 /// \returns true if an error occurred, false otherwise.
3305 bool ActOnCXXNestedNameSpecifier(Scope *S,
3306 SourceLocation TemplateLoc,
3308 TemplateTy Template,
3309 SourceLocation TemplateNameLoc,
3310 SourceLocation LAngleLoc,
3311 ASTTemplateArgsPtr TemplateArgs,
3312 SourceLocation RAngleLoc,
3313 SourceLocation CCLoc,
3314 bool EnteringContext);
3316 /// \brief Given a C++ nested-name-specifier, produce an annotation value
3317 /// that the parser can use later to reconstruct the given
3318 /// nested-name-specifier.
3320 /// \param SS A nested-name-specifier.
3322 /// \returns A pointer containing all of the information in the
3323 /// nested-name-specifier \p SS.
3324 void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS);
3326 /// \brief Given an annotation pointer for a nested-name-specifier, restore
3327 /// the nested-name-specifier structure.
3329 /// \param Annotation The annotation pointer, produced by
3330 /// \c SaveNestedNameSpecifierAnnotation().
3332 /// \param AnnotationRange The source range corresponding to the annotation.
3334 /// \param SS The nested-name-specifier that will be updated with the contents
3335 /// of the annotation pointer.
3336 void RestoreNestedNameSpecifierAnnotation(void *Annotation,
3337 SourceRange AnnotationRange,
3340 bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
3342 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
3343 /// scope or nested-name-specifier) is parsed, part of a declarator-id.
3344 /// After this method is called, according to [C++ 3.4.3p3], names should be
3345 /// looked up in the declarator-id's scope, until the declarator is parsed and
3346 /// ActOnCXXExitDeclaratorScope is called.
3347 /// The 'SS' should be a non-empty valid CXXScopeSpec.
3348 bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS);
3350 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
3351 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
3352 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
3353 /// Used to indicate that names should revert to being looked up in the
3355 void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
3357 /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an
3358 /// initializer for the declaration 'Dcl'.
3359 /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a
3360 /// static data member of class X, names should be looked up in the scope of
3362 void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl);
3364 /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an
3365 /// initializer for the declaration 'Dcl'.
3366 void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl);
3368 // ParseObjCStringLiteral - Parse Objective-C string literals.
3369 ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
3371 unsigned NumStrings);
3373 ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc,
3374 TypeSourceInfo *EncodedTypeInfo,
3375 SourceLocation RParenLoc);
3376 ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl,
3377 CXXMethodDecl *Method,
3378 bool HadMultipleCandidates);
3380 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
3381 SourceLocation EncodeLoc,
3382 SourceLocation LParenLoc,
3384 SourceLocation RParenLoc);
3386 // ParseObjCSelectorExpression - Build selector expression for @selector
3387 ExprResult ParseObjCSelectorExpression(Selector Sel,
3388 SourceLocation AtLoc,
3389 SourceLocation SelLoc,
3390 SourceLocation LParenLoc,
3391 SourceLocation RParenLoc);
3393 // ParseObjCProtocolExpression - Build protocol expression for @protocol
3394 ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
3395 SourceLocation AtLoc,
3396 SourceLocation ProtoLoc,
3397 SourceLocation LParenLoc,
3398 SourceLocation RParenLoc);
3400 //===--------------------------------------------------------------------===//
3403 Decl *ActOnStartLinkageSpecification(Scope *S,
3404 SourceLocation ExternLoc,
3405 SourceLocation LangLoc,
3407 SourceLocation LBraceLoc);
3408 Decl *ActOnFinishLinkageSpecification(Scope *S,
3410 SourceLocation RBraceLoc);
3413 //===--------------------------------------------------------------------===//
3416 bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
3417 const CXXScopeSpec *SS = 0);
3419 bool ActOnAccessSpecifier(AccessSpecifier Access,
3420 SourceLocation ASLoc,
3421 SourceLocation ColonLoc,
3422 AttributeList *Attrs = 0);
3424 Decl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
3426 MultiTemplateParamsArg TemplateParameterLists,
3427 Expr *BitfieldWidth, const VirtSpecifiers &VS,
3428 bool HasDeferredInit);
3429 void ActOnCXXInClassMemberInitializer(Decl *VarDecl, SourceLocation EqualLoc,
3432 MemInitResult ActOnMemInitializer(Decl *ConstructorD,
3435 IdentifierInfo *MemberOrBase,
3436 ParsedType TemplateTypeTy,
3437 SourceLocation IdLoc,
3438 SourceLocation LParenLoc,
3439 Expr **Args, unsigned NumArgs,
3440 SourceLocation RParenLoc,
3441 SourceLocation EllipsisLoc);
3443 MemInitResult ActOnMemInitializer(Decl *ConstructorD,
3446 IdentifierInfo *MemberOrBase,
3447 ParsedType TemplateTypeTy,
3448 SourceLocation IdLoc,
3450 SourceLocation EllipsisLoc);
3452 MemInitResult BuildMemInitializer(Decl *ConstructorD,
3455 IdentifierInfo *MemberOrBase,
3456 ParsedType TemplateTypeTy,
3457 SourceLocation IdLoc,
3458 const MultiInitializer &Init,
3459 SourceLocation EllipsisLoc);
3461 MemInitResult BuildMemberInitializer(ValueDecl *Member,
3462 const MultiInitializer &Args,
3463 SourceLocation IdLoc);
3465 MemInitResult BuildBaseInitializer(QualType BaseType,
3466 TypeSourceInfo *BaseTInfo,
3467 const MultiInitializer &Args,
3468 CXXRecordDecl *ClassDecl,
3469 SourceLocation EllipsisLoc);
3471 MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo,
3472 const MultiInitializer &Args,
3473 SourceLocation BaseLoc,
3474 CXXRecordDecl *ClassDecl);
3476 bool SetDelegatingInitializer(CXXConstructorDecl *Constructor,
3477 CXXCtorInitializer *Initializer);
3479 bool SetCtorInitializers(CXXConstructorDecl *Constructor,
3480 CXXCtorInitializer **Initializers,
3481 unsigned NumInitializers, bool AnyErrors);
3483 void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation);
3486 /// MarkBaseAndMemberDestructorsReferenced - Given a record decl,
3487 /// mark all the non-trivial destructors of its members and bases as
3489 void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
3490 CXXRecordDecl *Record);
3492 /// \brief The list of classes whose vtables have been used within
3493 /// this translation unit, and the source locations at which the
3494 /// first use occurred.
3495 typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse;
3497 /// \brief The list of vtables that are required but have not yet been
3499 SmallVector<VTableUse, 16> VTableUses;
3501 /// \brief The set of classes whose vtables have been used within
3502 /// this translation unit, and a bit that will be true if the vtable is
3503 /// required to be emitted (otherwise, it should be emitted only if needed
3504 /// by code generation).
3505 llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed;
3507 /// \brief Load any externally-stored vtable uses.
3508 void LoadExternalVTableUses();
3510 typedef LazyVector<CXXRecordDecl *, ExternalSemaSource,
3511 &ExternalSemaSource::ReadDynamicClasses, 2, 2>
3514 /// \brief A list of all of the dynamic classes in this translation
3516 DynamicClassesType DynamicClasses;
3518 /// \brief Note that the vtable for the given class was used at the
3520 void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class,
3521 bool DefinitionRequired = false);
3523 /// MarkVirtualMembersReferenced - Will mark all members of the given
3524 /// CXXRecordDecl referenced.
3525 void MarkVirtualMembersReferenced(SourceLocation Loc,
3526 const CXXRecordDecl *RD);
3528 /// \brief Define all of the vtables that have been used in this
3529 /// translation unit and reference any virtual members used by those
3532 /// \returns true if any work was done, false otherwise.
3533 bool DefineUsedVTables();
3535 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
3537 void ActOnMemInitializers(Decl *ConstructorDecl,
3538 SourceLocation ColonLoc,
3539 CXXCtorInitializer **MemInits,
3540 unsigned NumMemInits,
3543 void CheckCompletedCXXClass(CXXRecordDecl *Record);
3544 void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
3546 SourceLocation LBrac,
3547 SourceLocation RBrac,
3548 AttributeList *AttrList);
3550 void ActOnReenterTemplateScope(Scope *S, Decl *Template);
3551 void ActOnReenterDeclaratorTemplateScope(Scope *S, DeclaratorDecl *D);
3552 void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record);
3553 void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
3554 void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param);
3555 void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record);
3556 void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
3557 void ActOnFinishDelayedMemberInitializers(Decl *Record);
3558 void MarkAsLateParsedTemplate(FunctionDecl *FD, bool Flag = true);
3559 bool IsInsideALocalClassWithinATemplateFunction();
3561 Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc,
3563 Expr *AssertMessageExpr,
3564 SourceLocation RParenLoc);
3566 FriendDecl *CheckFriendTypeDecl(SourceLocation FriendLoc,
3567 TypeSourceInfo *TSInfo);
3568 Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS,
3569 MultiTemplateParamsArg TemplateParams);
3570 Decl *ActOnFriendFunctionDecl(Scope *S, Declarator &D,
3571 MultiTemplateParamsArg TemplateParams);
3573 QualType CheckConstructorDeclarator(Declarator &D, QualType R,
3575 void CheckConstructor(CXXConstructorDecl *Constructor);
3576 QualType CheckDestructorDeclarator(Declarator &D, QualType R,
3578 bool CheckDestructor(CXXDestructorDecl *Destructor);
3579 void CheckConversionDeclarator(Declarator &D, QualType &R,
3581 Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
3583 void CheckExplicitlyDefaultedMethods(CXXRecordDecl *Record);
3584 void CheckExplicitlyDefaultedDefaultConstructor(CXXConstructorDecl *Ctor);
3585 void CheckExplicitlyDefaultedCopyConstructor(CXXConstructorDecl *Ctor);
3586 void CheckExplicitlyDefaultedCopyAssignment(CXXMethodDecl *Method);
3587 void CheckExplicitlyDefaultedMoveConstructor(CXXConstructorDecl *Ctor);
3588 void CheckExplicitlyDefaultedMoveAssignment(CXXMethodDecl *Method);
3589 void CheckExplicitlyDefaultedDestructor(CXXDestructorDecl *Dtor);
3591 //===--------------------------------------------------------------------===//
3592 // C++ Derived Classes
3595 /// ActOnBaseSpecifier - Parsed a base specifier
3596 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
3597 SourceRange SpecifierRange,
3598 bool Virtual, AccessSpecifier Access,
3599 TypeSourceInfo *TInfo,
3600 SourceLocation EllipsisLoc);
3602 BaseResult ActOnBaseSpecifier(Decl *classdecl,
3603 SourceRange SpecifierRange,
3604 bool Virtual, AccessSpecifier Access,
3605 ParsedType basetype,
3606 SourceLocation BaseLoc,
3607 SourceLocation EllipsisLoc);
3609 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
3611 void ActOnBaseSpecifiers(Decl *ClassDecl, CXXBaseSpecifier **Bases,
3614 bool IsDerivedFrom(QualType Derived, QualType Base);
3615 bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths);
3617 // FIXME: I don't like this name.
3618 void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath);
3620 bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath);
3622 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
3623 SourceLocation Loc, SourceRange Range,
3624 CXXCastPath *BasePath = 0,
3625 bool IgnoreAccess = false);
3626 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
3627 unsigned InaccessibleBaseID,
3628 unsigned AmbigiousBaseConvID,
3629 SourceLocation Loc, SourceRange Range,
3630 DeclarationName Name,
3631 CXXCastPath *BasePath);
3633 std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths);
3635 /// CheckOverridingFunctionReturnType - Checks whether the return types are
3636 /// covariant, according to C++ [class.virtual]p5.
3637 bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New,
3638 const CXXMethodDecl *Old);
3640 /// CheckOverridingFunctionExceptionSpec - Checks whether the exception
3641 /// spec is a subset of base spec.
3642 bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New,
3643 const CXXMethodDecl *Old);
3645 bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange);
3647 /// CheckOverrideControl - Check C++0x override control semantics.
3648 void CheckOverrideControl(const Decl *D);
3650 /// CheckForFunctionMarkedFinal - Checks whether a virtual member function
3651 /// overrides a virtual member function marked 'final', according to
3652 /// C++0x [class.virtual]p3.
3653 bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New,
3654 const CXXMethodDecl *Old);
3657 //===--------------------------------------------------------------------===//
3658 // C++ Access Control
3668 bool SetMemberAccessSpecifier(NamedDecl *MemberDecl,
3669 NamedDecl *PrevMemberDecl,
3670 AccessSpecifier LexicalAS);
3672 AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E,
3673 DeclAccessPair FoundDecl);
3674 AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E,
3675 DeclAccessPair FoundDecl);
3676 AccessResult CheckAllocationAccess(SourceLocation OperatorLoc,
3677 SourceRange PlacementRange,
3678 CXXRecordDecl *NamingClass,
3679 DeclAccessPair FoundDecl,
3680 bool Diagnose = true);
3681 AccessResult CheckConstructorAccess(SourceLocation Loc,
3682 CXXConstructorDecl *D,
3683 const InitializedEntity &Entity,
3684 AccessSpecifier Access,
3685 bool IsCopyBindingRefToTemp = false);
3686 AccessResult CheckConstructorAccess(SourceLocation Loc,
3687 CXXConstructorDecl *D,
3688 AccessSpecifier Access,
3689 PartialDiagnostic PD);
3690 AccessResult CheckDestructorAccess(SourceLocation Loc,
3691 CXXDestructorDecl *Dtor,
3692 const PartialDiagnostic &PDiag);
3693 AccessResult CheckDirectMemberAccess(SourceLocation Loc,
3695 const PartialDiagnostic &PDiag);
3696 AccessResult CheckMemberOperatorAccess(SourceLocation Loc,
3699 DeclAccessPair FoundDecl);
3700 AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr,
3701 DeclAccessPair FoundDecl);
3702 AccessResult CheckBaseClassAccess(SourceLocation AccessLoc,
3703 QualType Base, QualType Derived,
3704 const CXXBasePath &Path,
3706 bool ForceCheck = false,
3707 bool ForceUnprivileged = false);
3708 void CheckLookupAccess(const LookupResult &R);
3709 bool IsSimplyAccessible(NamedDecl *decl, CXXRecordDecl *Class);
3711 void HandleDependentAccessCheck(const DependentDiagnostic &DD,
3712 const MultiLevelTemplateArgumentList &TemplateArgs);
3713 void PerformDependentDiagnostics(const DeclContext *Pattern,
3714 const MultiLevelTemplateArgumentList &TemplateArgs);
3716 void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
3718 /// A flag to suppress access checking.
3719 bool SuppressAccessChecking;
3721 /// \brief When true, access checking violations are treated as SFINAE
3722 /// failures rather than hard errors.
3723 bool AccessCheckingSFINAE;
3725 void ActOnStartSuppressingAccessChecks();
3726 void ActOnStopSuppressingAccessChecks();
3728 enum AbstractDiagSelID {
3732 AbstractVariableType,
3737 bool RequireNonAbstractType(SourceLocation Loc, QualType T,
3738 const PartialDiagnostic &PD);
3739 void DiagnoseAbstractType(const CXXRecordDecl *RD);
3741 bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID,
3742 AbstractDiagSelID SelID = AbstractNone);
3744 //===--------------------------------------------------------------------===//
3745 // C++ Overloaded Operators [C++ 13.5]
3748 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
3750 bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl);
3752 //===--------------------------------------------------------------------===//
3753 // C++ Templates [C++ 14]
3755 void FilterAcceptableTemplateNames(LookupResult &R);
3756 bool hasAnyAcceptableTemplateNames(LookupResult &R);
3758 void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS,
3759 QualType ObjectType, bool EnteringContext,
3760 bool &MemberOfUnknownSpecialization);
3762 TemplateNameKind isTemplateName(Scope *S,
3764 bool hasTemplateKeyword,
3765 UnqualifiedId &Name,
3766 ParsedType ObjectType,
3767 bool EnteringContext,
3768 TemplateTy &Template,
3769 bool &MemberOfUnknownSpecialization);
3771 bool DiagnoseUnknownTemplateName(const IdentifierInfo &II,
3772 SourceLocation IILoc,
3774 const CXXScopeSpec *SS,
3775 TemplateTy &SuggestedTemplate,
3776 TemplateNameKind &SuggestedKind);
3778 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
3779 TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl);
3781 Decl *ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis,
3782 SourceLocation EllipsisLoc,
3783 SourceLocation KeyLoc,
3784 IdentifierInfo *ParamName,
3785 SourceLocation ParamNameLoc,
3786 unsigned Depth, unsigned Position,
3787 SourceLocation EqualLoc,
3788 ParsedType DefaultArg);
3790 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
3791 Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
3794 SourceLocation EqualLoc,
3796 Decl *ActOnTemplateTemplateParameter(Scope *S,
3797 SourceLocation TmpLoc,
3798 TemplateParameterList *Params,
3799 SourceLocation EllipsisLoc,
3800 IdentifierInfo *ParamName,
3801 SourceLocation ParamNameLoc,
3804 SourceLocation EqualLoc,
3805 ParsedTemplateArgument DefaultArg);
3807 TemplateParameterList *
3808 ActOnTemplateParameterList(unsigned Depth,
3809 SourceLocation ExportLoc,
3810 SourceLocation TemplateLoc,
3811 SourceLocation LAngleLoc,
3812 Decl **Params, unsigned NumParams,
3813 SourceLocation RAngleLoc);
3815 /// \brief The context in which we are checking a template parameter
3817 enum TemplateParamListContext {
3819 TPC_FunctionTemplate,
3820 TPC_ClassTemplateMember,
3821 TPC_FriendFunctionTemplate,
3822 TPC_FriendFunctionTemplateDefinition,
3823 TPC_TypeAliasTemplate
3826 bool CheckTemplateParameterList(TemplateParameterList *NewParams,
3827 TemplateParameterList *OldParams,
3828 TemplateParamListContext TPC);
3829 TemplateParameterList *
3830 MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc,
3831 SourceLocation DeclLoc,
3832 const CXXScopeSpec &SS,
3833 TemplateParameterList **ParamLists,
3834 unsigned NumParamLists,
3836 bool &IsExplicitSpecialization,
3839 DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
3840 SourceLocation KWLoc, CXXScopeSpec &SS,
3841 IdentifierInfo *Name, SourceLocation NameLoc,
3842 AttributeList *Attr,
3843 TemplateParameterList *TemplateParams,
3845 SourceLocation ModulePrivateLoc,
3846 unsigned NumOuterTemplateParamLists,
3847 TemplateParameterList **OuterTemplateParamLists);
3849 void translateTemplateArguments(const ASTTemplateArgsPtr &In,
3850 TemplateArgumentListInfo &Out);
3852 void NoteAllFoundTemplates(TemplateName Name);
3854 QualType CheckTemplateIdType(TemplateName Template,
3855 SourceLocation TemplateLoc,
3856 TemplateArgumentListInfo &TemplateArgs);
3859 ActOnTemplateIdType(CXXScopeSpec &SS,
3860 TemplateTy Template, SourceLocation TemplateLoc,
3861 SourceLocation LAngleLoc,
3862 ASTTemplateArgsPtr TemplateArgs,
3863 SourceLocation RAngleLoc);
3865 /// \brief Parsed an elaborated-type-specifier that refers to a template-id,
3866 /// such as \c class T::template apply<U>.
3869 TypeResult ActOnTagTemplateIdType(TagUseKind TUK,
3870 TypeSpecifierType TagSpec,
3871 SourceLocation TagLoc,
3873 TemplateTy TemplateD,
3874 SourceLocation TemplateLoc,
3875 SourceLocation LAngleLoc,
3876 ASTTemplateArgsPtr TemplateArgsIn,
3877 SourceLocation RAngleLoc);
3880 ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS,
3883 const TemplateArgumentListInfo &TemplateArgs);
3884 ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS,
3885 const DeclarationNameInfo &NameInfo,
3886 const TemplateArgumentListInfo &TemplateArgs);
3888 TemplateNameKind ActOnDependentTemplateName(Scope *S,
3889 SourceLocation TemplateKWLoc,
3891 UnqualifiedId &Name,
3892 ParsedType ObjectType,
3893 bool EnteringContext,
3894 TemplateTy &Template);
3897 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK,
3898 SourceLocation KWLoc,
3899 SourceLocation ModulePrivateLoc,
3901 TemplateTy Template,
3902 SourceLocation TemplateNameLoc,
3903 SourceLocation LAngleLoc,
3904 ASTTemplateArgsPtr TemplateArgs,
3905 SourceLocation RAngleLoc,
3906 AttributeList *Attr,
3907 MultiTemplateParamsArg TemplateParameterLists);
3909 Decl *ActOnTemplateDeclarator(Scope *S,
3910 MultiTemplateParamsArg TemplateParameterLists,
3913 Decl *ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope,
3914 MultiTemplateParamsArg TemplateParameterLists,
3918 CheckSpecializationInstantiationRedecl(SourceLocation NewLoc,
3919 TemplateSpecializationKind NewTSK,
3920 NamedDecl *PrevDecl,
3921 TemplateSpecializationKind PrevTSK,
3922 SourceLocation PrevPtOfInstantiation,
3925 bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD,
3926 const TemplateArgumentListInfo &ExplicitTemplateArgs,
3927 LookupResult &Previous);
3929 bool CheckFunctionTemplateSpecialization(FunctionDecl *FD,
3930 TemplateArgumentListInfo *ExplicitTemplateArgs,
3931 LookupResult &Previous);
3932 bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous);
3935 ActOnExplicitInstantiation(Scope *S,
3936 SourceLocation ExternLoc,
3937 SourceLocation TemplateLoc,
3939 SourceLocation KWLoc,
3940 const CXXScopeSpec &SS,
3941 TemplateTy Template,
3942 SourceLocation TemplateNameLoc,
3943 SourceLocation LAngleLoc,
3944 ASTTemplateArgsPtr TemplateArgs,
3945 SourceLocation RAngleLoc,
3946 AttributeList *Attr);
3949 ActOnExplicitInstantiation(Scope *S,
3950 SourceLocation ExternLoc,
3951 SourceLocation TemplateLoc,
3953 SourceLocation KWLoc,
3955 IdentifierInfo *Name,
3956 SourceLocation NameLoc,
3957 AttributeList *Attr);
3959 DeclResult ActOnExplicitInstantiation(Scope *S,
3960 SourceLocation ExternLoc,
3961 SourceLocation TemplateLoc,
3965 SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template,
3966 SourceLocation TemplateLoc,
3967 SourceLocation RAngleLoc,
3969 SmallVectorImpl<TemplateArgument> &Converted);
3971 /// \brief Specifies the context in which a particular template
3972 /// argument is being checked.
3973 enum CheckTemplateArgumentKind {
3974 /// \brief The template argument was specified in the code or was
3975 /// instantiated with some deduced template arguments.
3978 /// \brief The template argument was deduced via template argument
3982 /// \brief The template argument was deduced from an array bound
3983 /// via template argument deduction.
3984 CTAK_DeducedFromArrayBound
3987 bool CheckTemplateArgument(NamedDecl *Param,
3988 const TemplateArgumentLoc &Arg,
3989 NamedDecl *Template,
3990 SourceLocation TemplateLoc,
3991 SourceLocation RAngleLoc,
3992 unsigned ArgumentPackIndex,
3993 SmallVectorImpl<TemplateArgument> &Converted,
3994 CheckTemplateArgumentKind CTAK = CTAK_Specified);
3996 /// \brief Check that the given template arguments can be be provided to
3997 /// the given template, converting the arguments along the way.
3999 /// \param Template The template to which the template arguments are being
4002 /// \param TemplateLoc The location of the template name in the source.
4004 /// \param TemplateArgs The list of template arguments. If the template is
4005 /// a template template parameter, this function may extend the set of
4006 /// template arguments to also include substituted, defaulted template
4009 /// \param PartialTemplateArgs True if the list of template arguments is
4010 /// intentionally partial, e.g., because we're checking just the initial
4011 /// set of template arguments.
4013 /// \param Converted Will receive the converted, canonicalized template
4016 /// \returns True if an error occurred, false otherwise.
4017 bool CheckTemplateArgumentList(TemplateDecl *Template,
4018 SourceLocation TemplateLoc,
4019 TemplateArgumentListInfo &TemplateArgs,
4020 bool PartialTemplateArgs,
4021 SmallVectorImpl<TemplateArgument> &Converted);
4023 bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
4024 const TemplateArgumentLoc &Arg,
4025 SmallVectorImpl<TemplateArgument> &Converted);
4027 bool CheckTemplateArgument(TemplateTypeParmDecl *Param,
4028 TypeSourceInfo *Arg);
4029 bool CheckTemplateArgumentPointerToMember(Expr *Arg,
4030 TemplateArgument &Converted);
4031 ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
4032 QualType InstantiatedParamType, Expr *Arg,
4033 TemplateArgument &Converted,
4034 CheckTemplateArgumentKind CTAK = CTAK_Specified);
4035 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param,
4036 const TemplateArgumentLoc &Arg);
4039 BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg,
4041 SourceLocation Loc);
4043 BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
4044 SourceLocation Loc);
4046 /// \brief Enumeration describing how template parameter lists are compared
4048 enum TemplateParameterListEqualKind {
4049 /// \brief We are matching the template parameter lists of two templates
4050 /// that might be redeclarations.
4053 /// template<typename T> struct X;
4054 /// template<typename T> struct X;
4058 /// \brief We are matching the template parameter lists of two template
4059 /// template parameters as part of matching the template parameter lists
4060 /// of two templates that might be redeclarations.
4063 /// template<template<int I> class TT> struct X;
4064 /// template<template<int Value> class Other> struct X;
4066 TPL_TemplateTemplateParmMatch,
4068 /// \brief We are matching the template parameter lists of a template
4069 /// template argument against the template parameter lists of a template
4070 /// template parameter.
4073 /// template<template<int Value> class Metafun> struct X;
4074 /// template<int Value> struct integer_c;
4075 /// X<integer_c> xic;
4077 TPL_TemplateTemplateArgumentMatch
4080 bool TemplateParameterListsAreEqual(TemplateParameterList *New,
4081 TemplateParameterList *Old,
4083 TemplateParameterListEqualKind Kind,
4084 SourceLocation TemplateArgLoc
4085 = SourceLocation());
4087 bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams);
4089 /// \brief Called when the parser has parsed a C++ typename
4090 /// specifier, e.g., "typename T::type".
4092 /// \param S The scope in which this typename type occurs.
4093 /// \param TypenameLoc the location of the 'typename' keyword
4094 /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
4095 /// \param II the identifier we're retrieving (e.g., 'type' in the example).
4096 /// \param IdLoc the location of the identifier.
4098 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
4099 const CXXScopeSpec &SS, const IdentifierInfo &II,
4100 SourceLocation IdLoc);
4102 /// \brief Called when the parser has parsed a C++ typename
4103 /// specifier that ends in a template-id, e.g.,
4104 /// "typename MetaFun::template apply<T1, T2>".
4106 /// \param S The scope in which this typename type occurs.
4107 /// \param TypenameLoc the location of the 'typename' keyword
4108 /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
4109 /// \param TemplateLoc the location of the 'template' keyword, if any.
4110 /// \param TemplateName The template name.
4111 /// \param TemplateNameLoc The location of the template name.
4112 /// \param LAngleLoc The location of the opening angle bracket ('<').
4113 /// \param TemplateArgs The template arguments.
4114 /// \param RAngleLoc The location of the closing angle bracket ('>').
4116 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
4117 const CXXScopeSpec &SS,
4118 SourceLocation TemplateLoc,
4119 TemplateTy Template,
4120 SourceLocation TemplateNameLoc,
4121 SourceLocation LAngleLoc,
4122 ASTTemplateArgsPtr TemplateArgs,
4123 SourceLocation RAngleLoc);
4125 QualType CheckTypenameType(ElaboratedTypeKeyword Keyword,
4126 SourceLocation KeywordLoc,
4127 NestedNameSpecifierLoc QualifierLoc,
4128 const IdentifierInfo &II,
4129 SourceLocation IILoc);
4131 TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
4133 DeclarationName Name);
4134 bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS);
4136 ExprResult RebuildExprInCurrentInstantiation(Expr *E);
4137 bool RebuildTemplateParamsInCurrentInstantiation(
4138 TemplateParameterList *Params);
4141 getTemplateArgumentBindingsText(const TemplateParameterList *Params,
4142 const TemplateArgumentList &Args);
4145 getTemplateArgumentBindingsText(const TemplateParameterList *Params,
4146 const TemplateArgument *Args,
4149 //===--------------------------------------------------------------------===//
4150 // C++ Variadic Templates (C++0x [temp.variadic])
4151 //===--------------------------------------------------------------------===//
4153 /// \brief The context in which an unexpanded parameter pack is
4154 /// being diagnosed.
4156 /// Note that the values of this enumeration line up with the first
4157 /// argument to the \c err_unexpanded_parameter_pack diagnostic.
4158 enum UnexpandedParameterPackContext {
4159 /// \brief An arbitrary expression.
4160 UPPC_Expression = 0,
4162 /// \brief The base type of a class type.
4165 /// \brief The type of an arbitrary declaration.
4166 UPPC_DeclarationType,
4168 /// \brief The type of a data member.
4169 UPPC_DataMemberType,
4171 /// \brief The size of a bit-field.
4174 /// \brief The expression in a static assertion.
4175 UPPC_StaticAssertExpression,
4177 /// \brief The fixed underlying type of an enumeration.
4178 UPPC_FixedUnderlyingType,
4180 /// \brief The enumerator value.
4181 UPPC_EnumeratorValue,
4183 /// \brief A using declaration.
4184 UPPC_UsingDeclaration,
4186 /// \brief A friend declaration.
4187 UPPC_FriendDeclaration,
4189 /// \brief A declaration qualifier.
4190 UPPC_DeclarationQualifier,
4192 /// \brief An initializer.
4195 /// \brief A default argument.
4196 UPPC_DefaultArgument,
4198 /// \brief The type of a non-type template parameter.
4199 UPPC_NonTypeTemplateParameterType,
4201 /// \brief The type of an exception.
4204 /// \brief Partial specialization.
4205 UPPC_PartialSpecialization
4208 /// \brief If the given type contains an unexpanded parameter pack,
4209 /// diagnose the error.
4211 /// \param Loc The source location where a diagnostc should be emitted.
4213 /// \param T The type that is being checked for unexpanded parameter
4216 /// \returns true if an error occurred, false otherwise.
4217 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T,
4218 UnexpandedParameterPackContext UPPC);
4220 /// \brief If the given expression contains an unexpanded parameter
4221 /// pack, diagnose the error.
4223 /// \param E The expression that is being checked for unexpanded
4224 /// parameter packs.
4226 /// \returns true if an error occurred, false otherwise.
4227 bool DiagnoseUnexpandedParameterPack(Expr *E,
4228 UnexpandedParameterPackContext UPPC = UPPC_Expression);
4230 /// \brief If the given nested-name-specifier contains an unexpanded
4231 /// parameter pack, diagnose the error.
4233 /// \param SS The nested-name-specifier that is being checked for
4234 /// unexpanded parameter packs.
4236 /// \returns true if an error occurred, false otherwise.
4237 bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS,
4238 UnexpandedParameterPackContext UPPC);
4240 /// \brief If the given name contains an unexpanded parameter pack,
4241 /// diagnose the error.
4243 /// \param NameInfo The name (with source location information) that
4244 /// is being checked for unexpanded parameter packs.
4246 /// \returns true if an error occurred, false otherwise.
4247 bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo,
4248 UnexpandedParameterPackContext UPPC);
4250 /// \brief If the given template name contains an unexpanded parameter pack,
4251 /// diagnose the error.
4253 /// \param Loc The location of the template name.
4255 /// \param Template The template name that is being checked for unexpanded
4256 /// parameter packs.
4258 /// \returns true if an error occurred, false otherwise.
4259 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc,
4260 TemplateName Template,
4261 UnexpandedParameterPackContext UPPC);
4263 /// \brief If the given template argument contains an unexpanded parameter
4264 /// pack, diagnose the error.
4266 /// \param Arg The template argument that is being checked for unexpanded
4267 /// parameter packs.
4269 /// \returns true if an error occurred, false otherwise.
4270 bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg,
4271 UnexpandedParameterPackContext UPPC);
4273 /// \brief Collect the set of unexpanded parameter packs within the given
4274 /// template argument.
4276 /// \param Arg The template argument that will be traversed to find
4277 /// unexpanded parameter packs.
4278 void collectUnexpandedParameterPacks(TemplateArgument Arg,
4279 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
4281 /// \brief Collect the set of unexpanded parameter packs within the given
4282 /// template argument.
4284 /// \param Arg The template argument that will be traversed to find
4285 /// unexpanded parameter packs.
4286 void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg,
4287 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
4289 /// \brief Collect the set of unexpanded parameter packs within the given
4292 /// \param T The type that will be traversed to find
4293 /// unexpanded parameter packs.
4294 void collectUnexpandedParameterPacks(QualType T,
4295 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
4297 /// \brief Collect the set of unexpanded parameter packs within the given
4300 /// \param TL The type that will be traversed to find
4301 /// unexpanded parameter packs.
4302 void collectUnexpandedParameterPacks(TypeLoc TL,
4303 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
4305 /// \brief Invoked when parsing a template argument followed by an
4306 /// ellipsis, which creates a pack expansion.
4308 /// \param Arg The template argument preceding the ellipsis, which
4309 /// may already be invalid.
4311 /// \param EllipsisLoc The location of the ellipsis.
4312 ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg,
4313 SourceLocation EllipsisLoc);
4315 /// \brief Invoked when parsing a type followed by an ellipsis, which
4316 /// creates a pack expansion.
4318 /// \param Type The type preceding the ellipsis, which will become
4319 /// the pattern of the pack expansion.
4321 /// \param EllipsisLoc The location of the ellipsis.
4322 TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc);
4324 /// \brief Construct a pack expansion type from the pattern of the pack
4326 TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern,
4327 SourceLocation EllipsisLoc,
4328 llvm::Optional<unsigned> NumExpansions);
4330 /// \brief Construct a pack expansion type from the pattern of the pack
4332 QualType CheckPackExpansion(QualType Pattern,
4333 SourceRange PatternRange,
4334 SourceLocation EllipsisLoc,
4335 llvm::Optional<unsigned> NumExpansions);
4337 /// \brief Invoked when parsing an expression followed by an ellipsis, which
4338 /// creates a pack expansion.
4340 /// \param Pattern The expression preceding the ellipsis, which will become
4341 /// the pattern of the pack expansion.
4343 /// \param EllipsisLoc The location of the ellipsis.
4344 ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc);
4346 /// \brief Invoked when parsing an expression followed by an ellipsis, which
4347 /// creates a pack expansion.
4349 /// \param Pattern The expression preceding the ellipsis, which will become
4350 /// the pattern of the pack expansion.
4352 /// \param EllipsisLoc The location of the ellipsis.
4353 ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
4354 llvm::Optional<unsigned> NumExpansions);
4356 /// \brief Determine whether we could expand a pack expansion with the
4357 /// given set of parameter packs into separate arguments by repeatedly
4358 /// transforming the pattern.
4360 /// \param EllipsisLoc The location of the ellipsis that identifies the
4363 /// \param PatternRange The source range that covers the entire pattern of
4364 /// the pack expansion.
4366 /// \param Unexpanded The set of unexpanded parameter packs within the
4369 /// \param NumUnexpanded The number of unexpanded parameter packs in
4372 /// \param ShouldExpand Will be set to \c true if the transformer should
4373 /// expand the corresponding pack expansions into separate arguments. When
4374 /// set, \c NumExpansions must also be set.
4376 /// \param RetainExpansion Whether the caller should add an unexpanded
4377 /// pack expansion after all of the expanded arguments. This is used
4378 /// when extending explicitly-specified template argument packs per
4379 /// C++0x [temp.arg.explicit]p9.
4381 /// \param NumExpansions The number of separate arguments that will be in
4382 /// the expanded form of the corresponding pack expansion. This is both an
4383 /// input and an output parameter, which can be set by the caller if the
4384 /// number of expansions is known a priori (e.g., due to a prior substitution)
4385 /// and will be set by the callee when the number of expansions is known.
4386 /// The callee must set this value when \c ShouldExpand is \c true; it may
4387 /// set this value in other cases.
4389 /// \returns true if an error occurred (e.g., because the parameter packs
4390 /// are to be instantiated with arguments of different lengths), false
4391 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
4393 bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc,
4394 SourceRange PatternRange,
4395 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
4396 const MultiLevelTemplateArgumentList &TemplateArgs,
4398 bool &RetainExpansion,
4399 llvm::Optional<unsigned> &NumExpansions);
4401 /// \brief Determine the number of arguments in the given pack expansion
4404 /// This routine already assumes that the pack expansion type can be
4405 /// expanded and that the number of arguments in the expansion is
4406 /// consistent across all of the unexpanded parameter packs in its pattern.
4407 unsigned getNumArgumentsInExpansion(QualType T,
4408 const MultiLevelTemplateArgumentList &TemplateArgs);
4410 /// \brief Determine whether the given declarator contains any unexpanded
4411 /// parameter packs.
4413 /// This routine is used by the parser to disambiguate function declarators
4414 /// with an ellipsis prior to the ')', e.g.,
4420 /// To determine whether we have an (unnamed) function parameter pack or
4421 /// a variadic function.
4423 /// \returns true if the declarator contains any unexpanded parameter packs,
4424 /// false otherwise.
4425 bool containsUnexpandedParameterPacks(Declarator &D);
4427 //===--------------------------------------------------------------------===//
4428 // C++ Template Argument Deduction (C++ [temp.deduct])
4429 //===--------------------------------------------------------------------===//
4431 /// \brief Describes the result of template argument deduction.
4433 /// The TemplateDeductionResult enumeration describes the result of
4434 /// template argument deduction, as returned from
4435 /// DeduceTemplateArguments(). The separate TemplateDeductionInfo
4436 /// structure provides additional information about the results of
4437 /// template argument deduction, e.g., the deduced template argument
4438 /// list (if successful) or the specific template parameters or
4439 /// deduced arguments that were involved in the failure.
4440 enum TemplateDeductionResult {
4441 /// \brief Template argument deduction was successful.
4443 /// \brief Template argument deduction exceeded the maximum template
4444 /// instantiation depth (which has already been diagnosed).
4445 TDK_InstantiationDepth,
4446 /// \brief Template argument deduction did not deduce a value
4447 /// for every template parameter.
4449 /// \brief Template argument deduction produced inconsistent
4450 /// deduced values for the given template parameter.
4452 /// \brief Template argument deduction failed due to inconsistent
4453 /// cv-qualifiers on a template parameter type that would
4454 /// otherwise be deduced, e.g., we tried to deduce T in "const T"
4455 /// but were given a non-const "X".
4457 /// \brief Substitution of the deduced template argument values
4458 /// resulted in an error.
4459 TDK_SubstitutionFailure,
4460 /// \brief Substitution of the deduced template argument values
4461 /// into a non-deduced context produced a type or value that
4462 /// produces a type that does not match the original template
4463 /// arguments provided.
4464 TDK_NonDeducedMismatch,
4465 /// \brief When performing template argument deduction for a function
4466 /// template, there were too many call arguments.
4467 TDK_TooManyArguments,
4468 /// \brief When performing template argument deduction for a function
4469 /// template, there were too few call arguments.
4470 TDK_TooFewArguments,
4471 /// \brief The explicitly-specified template arguments were not valid
4472 /// template arguments for the given template.
4473 TDK_InvalidExplicitArguments,
4474 /// \brief The arguments included an overloaded function name that could
4475 /// not be resolved to a suitable function.
4476 TDK_FailedOverloadResolution
4479 TemplateDeductionResult
4480 DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
4481 const TemplateArgumentList &TemplateArgs,
4482 sema::TemplateDeductionInfo &Info);
4484 TemplateDeductionResult
4485 SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
4486 TemplateArgumentListInfo &ExplicitTemplateArgs,
4487 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
4488 SmallVectorImpl<QualType> &ParamTypes,
4489 QualType *FunctionType,
4490 sema::TemplateDeductionInfo &Info);
4492 /// brief A function argument from which we performed template argument
4493 // deduction for a call.
4494 struct OriginalCallArg {
4495 OriginalCallArg(QualType OriginalParamType,
4497 QualType OriginalArgType)
4498 : OriginalParamType(OriginalParamType), ArgIdx(ArgIdx),
4499 OriginalArgType(OriginalArgType) { }
4501 QualType OriginalParamType;
4503 QualType OriginalArgType;
4506 TemplateDeductionResult
4507 FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate,
4508 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
4509 unsigned NumExplicitlySpecified,
4510 FunctionDecl *&Specialization,
4511 sema::TemplateDeductionInfo &Info,
4512 SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = 0);
4514 TemplateDeductionResult
4515 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
4516 TemplateArgumentListInfo *ExplicitTemplateArgs,
4517 Expr **Args, unsigned NumArgs,
4518 FunctionDecl *&Specialization,
4519 sema::TemplateDeductionInfo &Info);
4521 TemplateDeductionResult
4522 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
4523 TemplateArgumentListInfo *ExplicitTemplateArgs,
4524 QualType ArgFunctionType,
4525 FunctionDecl *&Specialization,
4526 sema::TemplateDeductionInfo &Info);
4528 TemplateDeductionResult
4529 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
4531 CXXConversionDecl *&Specialization,
4532 sema::TemplateDeductionInfo &Info);
4534 TemplateDeductionResult
4535 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
4536 TemplateArgumentListInfo *ExplicitTemplateArgs,
4537 FunctionDecl *&Specialization,
4538 sema::TemplateDeductionInfo &Info);
4540 bool DeduceAutoType(TypeSourceInfo *AutoType, Expr *Initializer,
4541 TypeSourceInfo *&Result);
4543 FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1,
4544 FunctionTemplateDecl *FT2,
4546 TemplatePartialOrderingContext TPOC,
4547 unsigned NumCallArguments);
4548 UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin,
4549 UnresolvedSetIterator SEnd,
4550 TemplatePartialOrderingContext TPOC,
4551 unsigned NumCallArguments,
4553 const PartialDiagnostic &NoneDiag,
4554 const PartialDiagnostic &AmbigDiag,
4555 const PartialDiagnostic &CandidateDiag,
4556 bool Complain = true);
4558 ClassTemplatePartialSpecializationDecl *
4559 getMoreSpecializedPartialSpecialization(
4560 ClassTemplatePartialSpecializationDecl *PS1,
4561 ClassTemplatePartialSpecializationDecl *PS2,
4562 SourceLocation Loc);
4564 void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs,
4567 SmallVectorImpl<bool> &Used);
4568 void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate,
4569 SmallVectorImpl<bool> &Deduced);
4571 //===--------------------------------------------------------------------===//
4572 // C++ Template Instantiation
4575 MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D,
4576 const TemplateArgumentList *Innermost = 0,
4577 bool RelativeToPrimary = false,
4578 const FunctionDecl *Pattern = 0);
4580 /// \brief A template instantiation that is currently in progress.
4581 struct ActiveTemplateInstantiation {
4582 /// \brief The kind of template instantiation we are performing
4583 enum InstantiationKind {
4584 /// We are instantiating a template declaration. The entity is
4585 /// the declaration we're instantiating (e.g., a CXXRecordDecl).
4586 TemplateInstantiation,
4588 /// We are instantiating a default argument for a template
4589 /// parameter. The Entity is the template, and
4590 /// TemplateArgs/NumTemplateArguments provides the template
4591 /// arguments as specified.
4592 /// FIXME: Use a TemplateArgumentList
4593 DefaultTemplateArgumentInstantiation,
4595 /// We are instantiating a default argument for a function.
4596 /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs
4597 /// provides the template arguments as specified.
4598 DefaultFunctionArgumentInstantiation,
4600 /// We are substituting explicit template arguments provided for
4601 /// a function template. The entity is a FunctionTemplateDecl.
4602 ExplicitTemplateArgumentSubstitution,
4604 /// We are substituting template argument determined as part of
4605 /// template argument deduction for either a class template
4606 /// partial specialization or a function template. The
4607 /// Entity is either a ClassTemplatePartialSpecializationDecl or
4608 /// a FunctionTemplateDecl.
4609 DeducedTemplateArgumentSubstitution,
4611 /// We are substituting prior template arguments into a new
4612 /// template parameter. The template parameter itself is either a
4613 /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl.
4614 PriorTemplateArgumentSubstitution,
4616 /// We are checking the validity of a default template argument that
4617 /// has been used when naming a template-id.
4618 DefaultTemplateArgumentChecking
4621 /// \brief The point of instantiation within the source code.
4622 SourceLocation PointOfInstantiation;
4624 /// \brief The template (or partial specialization) in which we are
4625 /// performing the instantiation, for substitutions of prior template
4627 NamedDecl *Template;
4629 /// \brief The entity that is being instantiated.
4632 /// \brief The list of template arguments we are substituting, if they
4633 /// are not part of the entity.
4634 const TemplateArgument *TemplateArgs;
4636 /// \brief The number of template arguments in TemplateArgs.
4637 unsigned NumTemplateArgs;
4639 /// \brief The template deduction info object associated with the
4640 /// substitution or checking of explicit or deduced template arguments.
4641 sema::TemplateDeductionInfo *DeductionInfo;
4643 /// \brief The source range that covers the construct that cause
4644 /// the instantiation, e.g., the template-id that causes a class
4645 /// template instantiation.
4646 SourceRange InstantiationRange;
4648 ActiveTemplateInstantiation()
4649 : Kind(TemplateInstantiation), Template(0), Entity(0), TemplateArgs(0),
4650 NumTemplateArgs(0), DeductionInfo(0) {}
4652 /// \brief Determines whether this template is an actual instantiation
4653 /// that should be counted toward the maximum instantiation depth.
4654 bool isInstantiationRecord() const;
4656 friend bool operator==(const ActiveTemplateInstantiation &X,
4657 const ActiveTemplateInstantiation &Y) {
4658 if (X.Kind != Y.Kind)
4661 if (X.Entity != Y.Entity)
4665 case TemplateInstantiation:
4668 case PriorTemplateArgumentSubstitution:
4669 case DefaultTemplateArgumentChecking:
4670 if (X.Template != Y.Template)
4675 case DefaultTemplateArgumentInstantiation:
4676 case ExplicitTemplateArgumentSubstitution:
4677 case DeducedTemplateArgumentSubstitution:
4678 case DefaultFunctionArgumentInstantiation:
4679 return X.TemplateArgs == Y.TemplateArgs;
4686 friend bool operator!=(const ActiveTemplateInstantiation &X,
4687 const ActiveTemplateInstantiation &Y) {
4692 /// \brief List of active template instantiations.
4694 /// This vector is treated as a stack. As one template instantiation
4695 /// requires another template instantiation, additional
4696 /// instantiations are pushed onto the stack up to a
4697 /// user-configurable limit LangOptions::InstantiationDepth.
4698 SmallVector<ActiveTemplateInstantiation, 16>
4699 ActiveTemplateInstantiations;
4701 /// \brief Whether we are in a SFINAE context that is not associated with
4702 /// template instantiation.
4704 /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside
4705 /// of a template instantiation or template argument deduction.
4706 bool InNonInstantiationSFINAEContext;
4708 /// \brief The number of ActiveTemplateInstantiation entries in
4709 /// \c ActiveTemplateInstantiations that are not actual instantiations and,
4710 /// therefore, should not be counted as part of the instantiation depth.
4711 unsigned NonInstantiationEntries;
4713 /// \brief The last template from which a template instantiation
4714 /// error or warning was produced.
4716 /// This value is used to suppress printing of redundant template
4717 /// instantiation backtraces when there are multiple errors in the
4718 /// same instantiation. FIXME: Does this belong in Sema? It's tough
4719 /// to implement it anywhere else.
4720 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext;
4722 /// \brief The current index into pack expansion arguments that will be
4723 /// used for substitution of parameter packs.
4725 /// The pack expansion index will be -1 to indicate that parameter packs
4726 /// should be instantiated as themselves. Otherwise, the index specifies
4727 /// which argument within the parameter pack will be used for substitution.
4728 int ArgumentPackSubstitutionIndex;
4730 /// \brief RAII object used to change the argument pack substitution index
4731 /// within a \c Sema object.
4733 /// See \c ArgumentPackSubstitutionIndex for more information.
4734 class ArgumentPackSubstitutionIndexRAII {
4736 int OldSubstitutionIndex;
4739 ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex)
4740 : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) {
4741 Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex;
4744 ~ArgumentPackSubstitutionIndexRAII() {
4745 Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex;
4749 friend class ArgumentPackSubstitutionRAII;
4751 /// \brief The stack of calls expression undergoing template instantiation.
4753 /// The top of this stack is used by a fixit instantiating unresolved
4754 /// function calls to fix the AST to match the textual change it prints.
4755 SmallVector<CallExpr *, 8> CallsUndergoingInstantiation;
4757 /// \brief For each declaration that involved template argument deduction, the
4758 /// set of diagnostics that were suppressed during that template argument
4761 /// FIXME: Serialize this structure to the AST file.
4762 llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1> >
4763 SuppressedDiagnostics;
4765 /// \brief A stack object to be created when performing template
4768 /// Construction of an object of type \c InstantiatingTemplate
4769 /// pushes the current instantiation onto the stack of active
4770 /// instantiations. If the size of this stack exceeds the maximum
4771 /// number of recursive template instantiations, construction
4772 /// produces an error and evaluates true.
4774 /// Destruction of this object will pop the named instantiation off
4776 struct InstantiatingTemplate {
4777 /// \brief Note that we are instantiating a class template,
4778 /// function template, or a member thereof.
4779 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4781 SourceRange InstantiationRange = SourceRange());
4783 /// \brief Note that we are instantiating a default argument in a
4785 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4786 TemplateDecl *Template,
4787 const TemplateArgument *TemplateArgs,
4788 unsigned NumTemplateArgs,
4789 SourceRange InstantiationRange = SourceRange());
4791 /// \brief Note that we are instantiating a default argument in a
4793 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4794 FunctionTemplateDecl *FunctionTemplate,
4795 const TemplateArgument *TemplateArgs,
4796 unsigned NumTemplateArgs,
4797 ActiveTemplateInstantiation::InstantiationKind Kind,
4798 sema::TemplateDeductionInfo &DeductionInfo,
4799 SourceRange InstantiationRange = SourceRange());
4801 /// \brief Note that we are instantiating as part of template
4802 /// argument deduction for a class template partial
4804 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4805 ClassTemplatePartialSpecializationDecl *PartialSpec,
4806 const TemplateArgument *TemplateArgs,
4807 unsigned NumTemplateArgs,
4808 sema::TemplateDeductionInfo &DeductionInfo,
4809 SourceRange InstantiationRange = SourceRange());
4811 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4813 const TemplateArgument *TemplateArgs,
4814 unsigned NumTemplateArgs,
4815 SourceRange InstantiationRange = SourceRange());
4817 /// \brief Note that we are substituting prior template arguments into a
4818 /// non-type or template template parameter.
4819 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4820 NamedDecl *Template,
4821 NonTypeTemplateParmDecl *Param,
4822 const TemplateArgument *TemplateArgs,
4823 unsigned NumTemplateArgs,
4824 SourceRange InstantiationRange);
4826 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4827 NamedDecl *Template,
4828 TemplateTemplateParmDecl *Param,
4829 const TemplateArgument *TemplateArgs,
4830 unsigned NumTemplateArgs,
4831 SourceRange InstantiationRange);
4833 /// \brief Note that we are checking the default template argument
4834 /// against the template parameter for a given template-id.
4835 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4836 TemplateDecl *Template,
4838 const TemplateArgument *TemplateArgs,
4839 unsigned NumTemplateArgs,
4840 SourceRange InstantiationRange);
4843 /// \brief Note that we have finished instantiating this template.
4846 ~InstantiatingTemplate() { Clear(); }
4848 /// \brief Determines whether we have exceeded the maximum
4849 /// recursive template instantiations.
4850 operator bool() const { return Invalid; }
4855 bool SavedInNonInstantiationSFINAEContext;
4856 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation,
4857 SourceRange InstantiationRange);
4859 InstantiatingTemplate(const InstantiatingTemplate&); // not implemented
4861 InstantiatingTemplate&
4862 operator=(const InstantiatingTemplate&); // not implemented
4865 void PrintInstantiationStack();
4867 /// \brief Determines whether we are currently in a context where
4868 /// template argument substitution failures are not considered
4871 /// \returns An empty \c llvm::Optional if we're not in a SFINAE context.
4872 /// Otherwise, contains a pointer that, if non-NULL, contains the nearest
4873 /// template-deduction context object, which can be used to capture
4874 /// diagnostics that will be suppressed.
4875 llvm::Optional<sema::TemplateDeductionInfo *> isSFINAEContext() const;
4877 /// \brief RAII class used to determine whether SFINAE has
4878 /// trapped any errors that occur during template argument
4882 unsigned PrevSFINAEErrors;
4883 bool PrevInNonInstantiationSFINAEContext;
4884 bool PrevAccessCheckingSFINAE;
4887 explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false)
4888 : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors),
4889 PrevInNonInstantiationSFINAEContext(
4890 SemaRef.InNonInstantiationSFINAEContext),
4891 PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE)
4893 if (!SemaRef.isSFINAEContext())
4894 SemaRef.InNonInstantiationSFINAEContext = true;
4895 SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE;
4899 SemaRef.NumSFINAEErrors = PrevSFINAEErrors;
4900 SemaRef.InNonInstantiationSFINAEContext
4901 = PrevInNonInstantiationSFINAEContext;
4902 SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE;
4905 /// \brief Determine whether any SFINAE errors have been trapped.
4906 bool hasErrorOccurred() const {
4907 return SemaRef.NumSFINAEErrors > PrevSFINAEErrors;
4911 /// \brief The current instantiation scope used to store local
4913 LocalInstantiationScope *CurrentInstantiationScope;
4915 /// \brief The number of typos corrected by CorrectTypo.
4916 unsigned TyposCorrected;
4918 typedef llvm::DenseMap<IdentifierInfo *, TypoCorrection>
4919 UnqualifiedTyposCorrectedMap;
4921 /// \brief A cache containing the results of typo correction for unqualified
4924 /// The string is the string that we corrected to (which may be empty, if
4925 /// there was no correction), while the boolean will be true when the
4926 /// string represents a keyword.
4927 UnqualifiedTyposCorrectedMap UnqualifiedTyposCorrected;
4929 /// \brief Worker object for performing CFG-based warnings.
4930 sema::AnalysisBasedWarnings AnalysisWarnings;
4932 /// \brief An entity for which implicit template instantiation is required.
4934 /// The source location associated with the declaration is the first place in
4935 /// the source code where the declaration was "used". It is not necessarily
4936 /// the point of instantiation (which will be either before or after the
4937 /// namespace-scope declaration that triggered this implicit instantiation),
4938 /// However, it is the location that diagnostics should generally refer to,
4939 /// because users will need to know what code triggered the instantiation.
4940 typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation;
4942 /// \brief The queue of implicit template instantiations that are required
4943 /// but have not yet been performed.
4944 std::deque<PendingImplicitInstantiation> PendingInstantiations;
4946 /// \brief The queue of implicit template instantiations that are required
4947 /// and must be performed within the current local scope.
4949 /// This queue is only used for member functions of local classes in
4950 /// templates, which must be instantiated in the same scope as their
4951 /// enclosing function, so that they can reference function-local
4952 /// types, static variables, enumerators, etc.
4953 std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations;
4955 void PerformPendingInstantiations(bool LocalOnly = false);
4957 TypeSourceInfo *SubstType(TypeSourceInfo *T,
4958 const MultiLevelTemplateArgumentList &TemplateArgs,
4959 SourceLocation Loc, DeclarationName Entity);
4961 QualType SubstType(QualType T,
4962 const MultiLevelTemplateArgumentList &TemplateArgs,
4963 SourceLocation Loc, DeclarationName Entity);
4965 TypeSourceInfo *SubstType(TypeLoc TL,
4966 const MultiLevelTemplateArgumentList &TemplateArgs,
4967 SourceLocation Loc, DeclarationName Entity);
4969 TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T,
4970 const MultiLevelTemplateArgumentList &TemplateArgs,
4972 DeclarationName Entity);
4973 ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D,
4974 const MultiLevelTemplateArgumentList &TemplateArgs,
4975 int indexAdjustment,
4976 llvm::Optional<unsigned> NumExpansions);
4977 bool SubstParmTypes(SourceLocation Loc,
4978 ParmVarDecl **Params, unsigned NumParams,
4979 const MultiLevelTemplateArgumentList &TemplateArgs,
4980 SmallVectorImpl<QualType> &ParamTypes,
4981 SmallVectorImpl<ParmVarDecl *> *OutParams = 0);
4982 ExprResult SubstExpr(Expr *E,
4983 const MultiLevelTemplateArgumentList &TemplateArgs);
4985 /// \brief Substitute the given template arguments into a list of
4986 /// expressions, expanding pack expansions if required.
4988 /// \param Exprs The list of expressions to substitute into.
4990 /// \param NumExprs The number of expressions in \p Exprs.
4992 /// \param IsCall Whether this is some form of call, in which case
4993 /// default arguments will be dropped.
4995 /// \param TemplateArgs The set of template arguments to substitute.
4997 /// \param Outputs Will receive all of the substituted arguments.
4999 /// \returns true if an error occurred, false otherwise.
5000 bool SubstExprs(Expr **Exprs, unsigned NumExprs, bool IsCall,
5001 const MultiLevelTemplateArgumentList &TemplateArgs,
5002 SmallVectorImpl<Expr *> &Outputs);
5004 StmtResult SubstStmt(Stmt *S,
5005 const MultiLevelTemplateArgumentList &TemplateArgs);
5007 Decl *SubstDecl(Decl *D, DeclContext *Owner,
5008 const MultiLevelTemplateArgumentList &TemplateArgs);
5011 SubstBaseSpecifiers(CXXRecordDecl *Instantiation,
5012 CXXRecordDecl *Pattern,
5013 const MultiLevelTemplateArgumentList &TemplateArgs);
5016 InstantiateClass(SourceLocation PointOfInstantiation,
5017 CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
5018 const MultiLevelTemplateArgumentList &TemplateArgs,
5019 TemplateSpecializationKind TSK,
5020 bool Complain = true);
5022 void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
5023 const Decl *Pattern, Decl *Inst);
5026 InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation,
5027 ClassTemplateSpecializationDecl *ClassTemplateSpec,
5028 TemplateSpecializationKind TSK,
5029 bool Complain = true);
5031 void InstantiateClassMembers(SourceLocation PointOfInstantiation,
5032 CXXRecordDecl *Instantiation,
5033 const MultiLevelTemplateArgumentList &TemplateArgs,
5034 TemplateSpecializationKind TSK);
5036 void InstantiateClassTemplateSpecializationMembers(
5037 SourceLocation PointOfInstantiation,
5038 ClassTemplateSpecializationDecl *ClassTemplateSpec,
5039 TemplateSpecializationKind TSK);
5041 NestedNameSpecifierLoc
5042 SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
5043 const MultiLevelTemplateArgumentList &TemplateArgs);
5046 SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
5047 const MultiLevelTemplateArgumentList &TemplateArgs);
5049 SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name,
5051 const MultiLevelTemplateArgumentList &TemplateArgs);
5052 bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs,
5053 TemplateArgumentListInfo &Result,
5054 const MultiLevelTemplateArgumentList &TemplateArgs);
5056 void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
5057 FunctionDecl *Function,
5058 bool Recursive = false,
5059 bool DefinitionRequired = false);
5060 void InstantiateStaticDataMemberDefinition(
5061 SourceLocation PointOfInstantiation,
5063 bool Recursive = false,
5064 bool DefinitionRequired = false);
5066 void InstantiateMemInitializers(CXXConstructorDecl *New,
5067 const CXXConstructorDecl *Tmpl,
5068 const MultiLevelTemplateArgumentList &TemplateArgs);
5069 bool InstantiateInitializer(Expr *Init,
5070 const MultiLevelTemplateArgumentList &TemplateArgs,
5071 SourceLocation &LParenLoc,
5072 ASTOwningVector<Expr*> &NewArgs,
5073 SourceLocation &RParenLoc);
5075 NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
5076 const MultiLevelTemplateArgumentList &TemplateArgs);
5077 DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC,
5078 const MultiLevelTemplateArgumentList &TemplateArgs);
5080 // Objective-C declarations.
5081 Decl *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
5082 IdentifierInfo *ClassName,
5083 SourceLocation ClassLoc,
5084 IdentifierInfo *SuperName,
5085 SourceLocation SuperLoc,
5086 Decl * const *ProtoRefs,
5087 unsigned NumProtoRefs,
5088 const SourceLocation *ProtoLocs,
5089 SourceLocation EndProtoLoc,
5090 AttributeList *AttrList);
5092 Decl *ActOnCompatiblityAlias(
5093 SourceLocation AtCompatibilityAliasLoc,
5094 IdentifierInfo *AliasName, SourceLocation AliasLocation,
5095 IdentifierInfo *ClassName, SourceLocation ClassLocation);
5097 bool CheckForwardProtocolDeclarationForCircularDependency(
5098 IdentifierInfo *PName,
5099 SourceLocation &PLoc, SourceLocation PrevLoc,
5100 const ObjCList<ObjCProtocolDecl> &PList);
5102 Decl *ActOnStartProtocolInterface(
5103 SourceLocation AtProtoInterfaceLoc,
5104 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
5105 Decl * const *ProtoRefNames, unsigned NumProtoRefs,
5106 const SourceLocation *ProtoLocs,
5107 SourceLocation EndProtoLoc,
5108 AttributeList *AttrList);
5110 Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
5111 IdentifierInfo *ClassName,
5112 SourceLocation ClassLoc,
5113 IdentifierInfo *CategoryName,
5114 SourceLocation CategoryLoc,
5115 Decl * const *ProtoRefs,
5116 unsigned NumProtoRefs,
5117 const SourceLocation *ProtoLocs,
5118 SourceLocation EndProtoLoc);
5120 Decl *ActOnStartClassImplementation(
5121 SourceLocation AtClassImplLoc,
5122 IdentifierInfo *ClassName, SourceLocation ClassLoc,
5123 IdentifierInfo *SuperClassname,
5124 SourceLocation SuperClassLoc);
5126 Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc,
5127 IdentifierInfo *ClassName,
5128 SourceLocation ClassLoc,
5129 IdentifierInfo *CatName,
5130 SourceLocation CatLoc);
5132 DeclGroupPtrTy ActOnForwardClassDeclaration(SourceLocation Loc,
5133 IdentifierInfo **IdentList,
5134 SourceLocation *IdentLocs,
5137 Decl *ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc,
5138 const IdentifierLocPair *IdentList,
5140 AttributeList *attrList);
5142 void FindProtocolDeclaration(bool WarnOnDeclarations,
5143 const IdentifierLocPair *ProtocolId,
5144 unsigned NumProtocols,
5145 SmallVectorImpl<Decl *> &Protocols);
5147 /// Ensure attributes are consistent with type.
5148 /// \param [in, out] Attributes The attributes to check; they will
5149 /// be modified to be consistent with \arg PropertyTy.
5150 void CheckObjCPropertyAttributes(Decl *PropertyPtrTy,
5152 unsigned &Attributes);
5154 /// Process the specified property declaration and create decls for the
5155 /// setters and getters as needed.
5156 /// \param property The property declaration being processed
5157 /// \param DC The semantic container for the property
5158 /// \param redeclaredProperty Declaration for property if redeclared
5159 /// in class extension.
5160 /// \param lexicalDC Container for redeclaredProperty.
5161 void ProcessPropertyDecl(ObjCPropertyDecl *property,
5162 ObjCContainerDecl *DC,
5163 ObjCPropertyDecl *redeclaredProperty = 0,
5164 ObjCContainerDecl *lexicalDC = 0);
5166 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
5167 ObjCPropertyDecl *SuperProperty,
5168 const IdentifierInfo *Name);
5169 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
5171 void CompareMethodParamsInBaseAndSuper(Decl *IDecl,
5172 ObjCMethodDecl *MethodDecl,
5175 void CompareProperties(Decl *CDecl, Decl *MergeProtocols);
5177 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
5178 ObjCInterfaceDecl *ID);
5180 void MatchOneProtocolPropertiesInClass(Decl *CDecl,
5181 ObjCProtocolDecl *PDecl);
5183 void ActOnAtEnd(Scope *S, SourceRange AtEnd,
5184 Decl **allMethods = 0, unsigned allNum = 0,
5185 Decl **allProperties = 0, unsigned pNum = 0,
5186 DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0);
5188 Decl *ActOnProperty(Scope *S, SourceLocation AtLoc,
5189 FieldDeclarator &FD, ObjCDeclSpec &ODS,
5190 Selector GetterSel, Selector SetterSel,
5191 bool *OverridingProperty,
5192 tok::ObjCKeywordKind MethodImplKind,
5193 DeclContext *lexicalDC = 0);
5195 Decl *ActOnPropertyImplDecl(Scope *S,
5196 SourceLocation AtLoc,
5197 SourceLocation PropertyLoc,
5199 IdentifierInfo *PropertyId,
5200 IdentifierInfo *PropertyIvar,
5201 SourceLocation PropertyIvarLoc);
5203 enum ObjCSpecialMethodKind {
5209 OSMK_NonRetainingInit
5212 struct ObjCArgInfo {
5213 IdentifierInfo *Name;
5214 SourceLocation NameLoc;
5215 // The Type is null if no type was specified, and the DeclSpec is invalid
5218 ObjCDeclSpec DeclSpec;
5220 /// ArgAttrs - Attribute list for this argument.
5221 AttributeList *ArgAttrs;
5224 Decl *ActOnMethodDeclaration(
5226 SourceLocation BeginLoc, // location of the + or -.
5227 SourceLocation EndLoc, // location of the ; or {.
5228 tok::TokenKind MethodType,
5229 ObjCDeclSpec &ReturnQT, ParsedType ReturnType,
5230 ArrayRef<SourceLocation> SelectorLocs, Selector Sel,
5231 // optional arguments. The number of types/arguments is obtained
5232 // from the Sel.getNumArgs().
5233 ObjCArgInfo *ArgInfo,
5234 DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args
5235 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
5236 bool isVariadic, bool MethodDefinition);
5238 // Helper method for ActOnClassMethod/ActOnInstanceMethod.
5239 // Will search "local" class/category implementations for a method decl.
5240 // Will also search in class's root looking for instance method.
5241 // Returns 0 if no method is found.
5242 ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel,
5243 ObjCInterfaceDecl *CDecl);
5244 ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel,
5245 ObjCInterfaceDecl *ClassDecl);
5246 ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel,
5247 const ObjCObjectPointerType *OPT,
5250 bool inferObjCARCLifetime(ValueDecl *decl);
5253 HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
5255 SourceLocation OpLoc,
5256 DeclarationName MemberName,
5257 SourceLocation MemberLoc,
5258 SourceLocation SuperLoc, QualType SuperType,
5262 ActOnClassPropertyRefExpr(IdentifierInfo &receiverName,
5263 IdentifierInfo &propertyName,
5264 SourceLocation receiverNameLoc,
5265 SourceLocation propertyNameLoc);
5267 ObjCMethodDecl *tryCaptureObjCSelf();
5269 /// \brief Describes the kind of message expression indicated by a message
5270 /// send that starts with an identifier.
5271 enum ObjCMessageKind {
5272 /// \brief The message is sent to 'super'.
5274 /// \brief The message is an instance message.
5275 ObjCInstanceMessage,
5276 /// \brief The message is a class message, and the identifier is a type
5281 ObjCMessageKind getObjCMessageKind(Scope *S,
5282 IdentifierInfo *Name,
5283 SourceLocation NameLoc,
5285 bool HasTrailingDot,
5286 ParsedType &ReceiverType);
5288 ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc,
5290 SourceLocation LBracLoc,
5291 ArrayRef<SourceLocation> SelectorLocs,
5292 SourceLocation RBracLoc,
5295 ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo,
5296 QualType ReceiverType,
5297 SourceLocation SuperLoc,
5299 ObjCMethodDecl *Method,
5300 SourceLocation LBracLoc,
5301 ArrayRef<SourceLocation> SelectorLocs,
5302 SourceLocation RBracLoc,
5305 ExprResult ActOnClassMessage(Scope *S,
5306 ParsedType Receiver,
5308 SourceLocation LBracLoc,
5309 ArrayRef<SourceLocation> SelectorLocs,
5310 SourceLocation RBracLoc,
5313 ExprResult BuildInstanceMessage(Expr *Receiver,
5314 QualType ReceiverType,
5315 SourceLocation SuperLoc,
5317 ObjCMethodDecl *Method,
5318 SourceLocation LBracLoc,
5319 ArrayRef<SourceLocation> SelectorLocs,
5320 SourceLocation RBracLoc,
5323 ExprResult ActOnInstanceMessage(Scope *S,
5326 SourceLocation LBracLoc,
5327 ArrayRef<SourceLocation> SelectorLocs,
5328 SourceLocation RBracLoc,
5331 ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc,
5332 ObjCBridgeCastKind Kind,
5333 SourceLocation BridgeKeywordLoc,
5334 TypeSourceInfo *TSInfo,
5337 ExprResult ActOnObjCBridgedCast(Scope *S,
5338 SourceLocation LParenLoc,
5339 ObjCBridgeCastKind Kind,
5340 SourceLocation BridgeKeywordLoc,
5342 SourceLocation RParenLoc,
5345 bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall);
5347 /// \brief Check whether the given new method is a valid override of the
5348 /// given overridden method, and set any properties that should be inherited.
5349 void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod,
5350 const ObjCMethodDecl *Overridden,
5351 bool IsImplementation);
5353 /// \brief Check whether the given method overrides any methods in its class,
5354 /// calling \c CheckObjCMethodOverride for each overridden method.
5355 bool CheckObjCMethodOverrides(ObjCMethodDecl *NewMethod, DeclContext *DC);
5357 enum PragmaOptionsAlignKind {
5358 POAK_Native, // #pragma options align=native
5359 POAK_Natural, // #pragma options align=natural
5360 POAK_Packed, // #pragma options align=packed
5361 POAK_Power, // #pragma options align=power
5362 POAK_Mac68k, // #pragma options align=mac68k
5363 POAK_Reset // #pragma options align=reset
5366 /// ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
5367 void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
5368 SourceLocation PragmaLoc,
5369 SourceLocation KindLoc);
5371 enum PragmaPackKind {
5372 PPK_Default, // #pragma pack([n])
5373 PPK_Show, // #pragma pack(show), only supported by MSVC.
5374 PPK_Push, // #pragma pack(push, [identifier], [n])
5375 PPK_Pop // #pragma pack(pop, [identifier], [n])
5378 enum PragmaMSStructKind {
5379 PMSST_OFF, // #pragms ms_struct off
5380 PMSST_ON // #pragms ms_struct on
5383 /// ActOnPragmaPack - Called on well formed #pragma pack(...).
5384 void ActOnPragmaPack(PragmaPackKind Kind,
5385 IdentifierInfo *Name,
5387 SourceLocation PragmaLoc,
5388 SourceLocation LParenLoc,
5389 SourceLocation RParenLoc);
5391 /// ActOnPragmaMSStruct - Called on well formed #pragms ms_struct [on|off].
5392 void ActOnPragmaMSStruct(PragmaMSStructKind Kind);
5394 /// ActOnPragmaUnused - Called on well-formed '#pragma unused'.
5395 void ActOnPragmaUnused(const Token &Identifier,
5397 SourceLocation PragmaLoc);
5399 /// ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
5400 void ActOnPragmaVisibility(bool IsPush, const IdentifierInfo* VisType,
5401 SourceLocation PragmaLoc);
5403 NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II,
5404 SourceLocation Loc);
5405 void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W);
5407 /// ActOnPragmaWeakID - Called on well formed #pragma weak ident.
5408 void ActOnPragmaWeakID(IdentifierInfo* WeakName,
5409 SourceLocation PragmaLoc,
5410 SourceLocation WeakNameLoc);
5412 /// ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident.
5413 void ActOnPragmaWeakAlias(IdentifierInfo* WeakName,
5414 IdentifierInfo* AliasName,
5415 SourceLocation PragmaLoc,
5416 SourceLocation WeakNameLoc,
5417 SourceLocation AliasNameLoc);
5419 /// ActOnPragmaFPContract - Called on well formed
5420 /// #pragma {STDC,OPENCL} FP_CONTRACT
5421 void ActOnPragmaFPContract(tok::OnOffSwitch OOS);
5423 /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to
5424 /// a the record decl, to handle '#pragma pack' and '#pragma options align'.
5425 void AddAlignmentAttributesForRecord(RecordDecl *RD);
5427 /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record.
5428 void AddMsStructLayoutForRecord(RecordDecl *RD);
5430 /// FreePackedContext - Deallocate and null out PackContext.
5431 void FreePackedContext();
5433 /// PushNamespaceVisibilityAttr - Note that we've entered a
5434 /// namespace with a visibility attribute.
5435 void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr);
5437 /// AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used,
5438 /// add an appropriate visibility attribute.
5439 void AddPushedVisibilityAttribute(Decl *RD);
5441 /// PopPragmaVisibility - Pop the top element of the visibility stack; used
5442 /// for '#pragma GCC visibility' and visibility attributes on namespaces.
5443 void PopPragmaVisibility();
5445 /// FreeVisContext - Deallocate and null out VisContext.
5446 void FreeVisContext();
5448 /// AddCFAuditedAttribute - Check whether we're currently within
5449 /// '#pragma clang arc_cf_code_audited' and, if so, consider adding
5450 /// the appropriate attribute.
5451 void AddCFAuditedAttribute(Decl *D);
5453 /// AddAlignedAttr - Adds an aligned attribute to a particular declaration.
5454 void AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E);
5455 void AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *T);
5457 /// \brief The kind of conversion being performed.
5458 enum CheckedConversionKind {
5459 /// \brief An implicit conversion.
5460 CCK_ImplicitConversion,
5461 /// \brief A C-style cast.
5463 /// \brief A functional-style cast.
5465 /// \brief A cast other than a C-style cast.
5469 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
5470 /// cast. If there is already an implicit cast, merge into the existing one.
5471 /// If isLvalue, the result of the cast is an lvalue.
5472 ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK,
5473 ExprValueKind VK = VK_RValue,
5474 const CXXCastPath *BasePath = 0,
5475 CheckedConversionKind CCK
5476 = CCK_ImplicitConversion);
5478 /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding
5479 /// to the conversion from scalar type ScalarTy to the Boolean type.
5480 static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy);
5482 /// IgnoredValueConversions - Given that an expression's result is
5483 /// syntactically ignored, perform any conversions that are
5485 ExprResult IgnoredValueConversions(Expr *E);
5487 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
5488 // functions and arrays to their respective pointers (C99 6.3.2.1).
5489 ExprResult UsualUnaryConversions(Expr *E);
5491 // DefaultFunctionArrayConversion - converts functions and arrays
5492 // to their respective pointers (C99 6.3.2.1).
5493 ExprResult DefaultFunctionArrayConversion(Expr *E);
5495 // DefaultFunctionArrayLvalueConversion - converts functions and
5496 // arrays to their respective pointers and performs the
5497 // lvalue-to-rvalue conversion.
5498 ExprResult DefaultFunctionArrayLvalueConversion(Expr *E);
5500 // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on
5501 // the operand. This is DefaultFunctionArrayLvalueConversion,
5502 // except that it assumes the operand isn't of function or array
5504 ExprResult DefaultLvalueConversion(Expr *E);
5506 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
5507 // do not have a prototype. Integer promotions are performed on each
5508 // argument, and arguments that have type float are promoted to double.
5509 ExprResult DefaultArgumentPromotion(Expr *E);
5511 // Used for emitting the right warning by DefaultVariadicArgumentPromotion
5512 enum VariadicCallType {
5516 VariadicConstructor,
5517 VariadicDoesNotApply
5520 /// GatherArgumentsForCall - Collector argument expressions for various
5521 /// form of call prototypes.
5522 bool GatherArgumentsForCall(SourceLocation CallLoc,
5523 FunctionDecl *FDecl,
5524 const FunctionProtoType *Proto,
5525 unsigned FirstProtoArg,
5526 Expr **Args, unsigned NumArgs,
5527 SmallVector<Expr *, 8> &AllArgs,
5528 VariadicCallType CallType = VariadicDoesNotApply);
5530 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
5531 // will warn if the resulting type is not a POD type.
5532 ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT,
5533 FunctionDecl *FDecl);
5535 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
5536 // operands and then handles various conversions that are common to binary
5537 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
5538 // routine returns the first non-arithmetic type found. The client is
5539 // responsible for emitting appropriate error diagnostics.
5540 QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS,
5541 bool IsCompAssign = false);
5543 /// AssignConvertType - All of the 'assignment' semantic checks return this
5544 /// enum to indicate whether the assignment was allowed. These checks are
5545 /// done for simple assignments, as well as initialization, return from
5546 /// function, argument passing, etc. The query is phrased in terms of a
5547 /// source and destination type.
5548 enum AssignConvertType {
5549 /// Compatible - the types are compatible according to the standard.
5552 /// PointerToInt - The assignment converts a pointer to an int, which we
5553 /// accept as an extension.
5556 /// IntToPointer - The assignment converts an int to a pointer, which we
5557 /// accept as an extension.
5560 /// FunctionVoidPointer - The assignment is between a function pointer and
5561 /// void*, which the standard doesn't allow, but we accept as an extension.
5562 FunctionVoidPointer,
5564 /// IncompatiblePointer - The assignment is between two pointers types that
5565 /// are not compatible, but we accept them as an extension.
5566 IncompatiblePointer,
5568 /// IncompatiblePointer - The assignment is between two pointers types which
5569 /// point to integers which have a different sign, but are otherwise identical.
5570 /// This is a subset of the above, but broken out because it's by far the most
5571 /// common case of incompatible pointers.
5572 IncompatiblePointerSign,
5574 /// CompatiblePointerDiscardsQualifiers - The assignment discards
5575 /// c/v/r qualifiers, which we accept as an extension.
5576 CompatiblePointerDiscardsQualifiers,
5578 /// IncompatiblePointerDiscardsQualifiers - The assignment
5579 /// discards qualifiers that we don't permit to be discarded,
5580 /// like address spaces.
5581 IncompatiblePointerDiscardsQualifiers,
5583 /// IncompatibleNestedPointerQualifiers - The assignment is between two
5584 /// nested pointer types, and the qualifiers other than the first two
5585 /// levels differ e.g. char ** -> const char **, but we accept them as an
5587 IncompatibleNestedPointerQualifiers,
5589 /// IncompatibleVectors - The assignment is between two vector types that
5590 /// have the same size, which we accept as an extension.
5591 IncompatibleVectors,
5593 /// IntToBlockPointer - The assignment converts an int to a block
5594 /// pointer. We disallow this.
5597 /// IncompatibleBlockPointer - The assignment is between two block
5598 /// pointers types that are not compatible.
5599 IncompatibleBlockPointer,
5601 /// IncompatibleObjCQualifiedId - The assignment is between a qualified
5602 /// id type and something else (that is incompatible with it). For example,
5603 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
5604 IncompatibleObjCQualifiedId,
5606 /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an
5607 /// object with __weak qualifier.
5608 IncompatibleObjCWeakRef,
5610 /// Incompatible - We reject this conversion outright, it is invalid to
5611 /// represent it in the AST.
5615 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
5616 /// assignment conversion type specified by ConvTy. This returns true if the
5617 /// conversion was invalid or false if the conversion was accepted.
5618 bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
5620 QualType DstType, QualType SrcType,
5621 Expr *SrcExpr, AssignmentAction Action,
5622 bool *Complained = 0);
5624 /// CheckAssignmentConstraints - Perform type checking for assignment,
5625 /// argument passing, variable initialization, and function return values.
5627 AssignConvertType CheckAssignmentConstraints(SourceLocation Loc,
5631 /// Check assignment constraints and prepare for a conversion of the
5632 /// RHS to the LHS type.
5633 AssignConvertType CheckAssignmentConstraints(QualType LHSType,
5637 // CheckSingleAssignmentConstraints - Currently used by
5638 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
5639 // this routine performs the default function/array converions.
5640 AssignConvertType CheckSingleAssignmentConstraints(QualType LHSType,
5642 bool Diagnose = true);
5644 // \brief If the lhs type is a transparent union, check whether we
5645 // can initialize the transparent union with the given expression.
5646 AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType,
5649 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
5651 bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType);
5653 ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
5654 AssignmentAction Action,
5655 bool AllowExplicit = false,
5656 bool Diagnose = true);
5657 ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
5658 AssignmentAction Action,
5660 ImplicitConversionSequence& ICS,
5661 bool Diagnose = true);
5662 ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
5663 const ImplicitConversionSequence& ICS,
5664 AssignmentAction Action,
5665 CheckedConversionKind CCK
5666 = CCK_ImplicitConversion);
5667 ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
5668 const StandardConversionSequence& SCS,
5669 AssignmentAction Action,
5670 CheckedConversionKind CCK);
5672 /// the following "Check" methods will return a valid/converted QualType
5673 /// or a null QualType (indicating an error diagnostic was issued).
5675 /// type checking binary operators (subroutines of CreateBuiltinBinOp).
5676 QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS,
5678 QualType CheckPointerToMemberOperands( // C++ 5.5
5679 ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK,
5680 SourceLocation OpLoc, bool isIndirect);
5681 QualType CheckMultiplyDivideOperands( // C99 6.5.5
5682 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign,
5684 QualType CheckRemainderOperands( // C99 6.5.5
5685 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
5686 bool IsCompAssign = false);
5687 QualType CheckAdditionOperands( // C99 6.5.6
5688 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
5689 QualType* CompLHSTy = 0);
5690 QualType CheckSubtractionOperands( // C99 6.5.6
5691 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
5692 QualType* CompLHSTy = 0);
5693 QualType CheckShiftOperands( // C99 6.5.7
5694 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc,
5695 bool IsCompAssign = false);
5696 QualType CheckCompareOperands( // C99 6.5.8/9
5697 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned OpaqueOpc,
5699 QualType CheckBitwiseOperands( // C99 6.5.[10...12]
5700 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
5701 bool IsCompAssign = false);
5702 QualType CheckLogicalOperands( // C99 6.5.[13,14]
5703 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc);
5704 // CheckAssignmentOperands is used for both simple and compound assignment.
5705 // For simple assignment, pass both expressions and a null converted type.
5706 // For compound assignment, pass both expressions and the converted type.
5707 QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
5708 Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType);
5710 void ConvertPropertyForLValue(ExprResult &LHS, ExprResult &RHS,
5712 ExprResult ConvertPropertyForRValue(Expr *E);
5714 QualType CheckConditionalOperands( // C99 6.5.15
5715 ExprResult &Cond, ExprResult &LHS, ExprResult &RHS,
5716 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation QuestionLoc);
5717 QualType CXXCheckConditionalOperands( // C++ 5.16
5718 ExprResult &cond, ExprResult &lhs, ExprResult &rhs,
5719 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc);
5720 QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2,
5721 bool *NonStandardCompositeType = 0);
5722 QualType FindCompositePointerType(SourceLocation Loc, ExprResult &E1, ExprResult &E2,
5723 bool *NonStandardCompositeType = 0) {
5724 Expr *E1Tmp = E1.take(), *E2Tmp = E2.take();
5725 QualType Composite = FindCompositePointerType(Loc, E1Tmp, E2Tmp, NonStandardCompositeType);
5731 QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS,
5732 SourceLocation QuestionLoc);
5734 bool DiagnoseConditionalForNull(Expr *LHSExpr, Expr *RHSExpr,
5735 SourceLocation QuestionLoc);
5737 /// type checking for vector binary operators.
5738 QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS,
5739 SourceLocation Loc, bool IsCompAssign);
5740 QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS,
5741 SourceLocation Loc, bool isRelational);
5743 /// type checking declaration initializers (C99 6.7.8)
5744 bool CheckForConstantInitializer(Expr *e, QualType t);
5746 // type checking C++ declaration initializers (C++ [dcl.init]).
5748 /// ReferenceCompareResult - Expresses the result of comparing two
5749 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
5750 /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
5751 enum ReferenceCompareResult {
5752 /// Ref_Incompatible - The two types are incompatible, so direct
5753 /// reference binding is not possible.
5754 Ref_Incompatible = 0,
5755 /// Ref_Related - The two types are reference-related, which means
5756 /// that their unqualified forms (T1 and T2) are either the same
5757 /// or T1 is a base class of T2.
5759 /// Ref_Compatible_With_Added_Qualification - The two types are
5760 /// reference-compatible with added qualification, meaning that
5761 /// they are reference-compatible and the qualifiers on T1 (cv1)
5762 /// are greater than the qualifiers on T2 (cv2).
5763 Ref_Compatible_With_Added_Qualification,
5764 /// Ref_Compatible - The two types are reference-compatible and
5765 /// have equivalent qualifiers (cv1 == cv2).
5769 ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc,
5770 QualType T1, QualType T2,
5771 bool &DerivedToBase,
5772 bool &ObjCConversion,
5773 bool &ObjCLifetimeConversion);
5775 ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType,
5776 Expr *CastExpr, CastKind &CastKind,
5777 ExprValueKind &VK, CXXCastPath &Path);
5779 // CheckVectorCast - check type constraints for vectors.
5780 // Since vectors are an extension, there are no C standard reference for this.
5781 // We allow casting between vectors and integer datatypes of the same size.
5782 // returns true if the cast is invalid
5783 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty,
5786 // CheckExtVectorCast - check type constraints for extended vectors.
5787 // Since vectors are an extension, there are no C standard reference for this.
5788 // We allow casting between vectors and integer datatypes of the same size,
5789 // or vectors and the element type of that vector.
5790 // returns the cast expr
5791 ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr,
5794 ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
5795 SourceLocation LParenLoc,
5797 SourceLocation RParenLoc);
5799 /// \brief Checks for invalid conversions and casts between
5800 /// retainable pointers and other pointer kinds.
5801 void CheckObjCARCConversion(SourceRange castRange, QualType castType,
5802 Expr *&op, CheckedConversionKind CCK);
5804 bool CheckObjCARCUnavailableWeakConversion(QualType castType,
5807 /// checkRetainCycles - Check whether an Objective-C message send
5808 /// might create an obvious retain cycle.
5809 void checkRetainCycles(ObjCMessageExpr *msg);
5810 void checkRetainCycles(Expr *receiver, Expr *argument);
5812 /// checkUnsafeAssigns - Check whether +1 expr is being assigned
5813 /// to weak/__unsafe_unretained type.
5814 bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS);
5816 /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned
5817 /// to weak/__unsafe_unretained expression.
5818 void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS);
5820 /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
5821 /// \param Method - May be null.
5822 /// \param [out] ReturnType - The return type of the send.
5823 /// \return true iff there were any incompatible types.
5824 bool CheckMessageArgumentTypes(QualType ReceiverType,
5825 Expr **Args, unsigned NumArgs, Selector Sel,
5826 ObjCMethodDecl *Method, bool isClassMessage,
5827 bool isSuperMessage,
5828 SourceLocation lbrac, SourceLocation rbrac,
5829 QualType &ReturnType, ExprValueKind &VK);
5831 /// \brief Determine the result of a message send expression based on
5832 /// the type of the receiver, the method expected to receive the message,
5833 /// and the form of the message send.
5834 QualType getMessageSendResultType(QualType ReceiverType,
5835 ObjCMethodDecl *Method,
5836 bool isClassMessage, bool isSuperMessage);
5838 /// \brief If the given expression involves a message send to a method
5839 /// with a related result type, emit a note describing what happened.
5840 void EmitRelatedResultTypeNote(const Expr *E);
5842 /// CheckBooleanCondition - Diagnose problems involving the use of
5843 /// the given expression as a boolean condition (e.g. in an if
5844 /// statement). Also performs the standard function and array
5845 /// decays, possibly changing the input variable.
5847 /// \param Loc - A location associated with the condition, e.g. the
5849 /// \return true iff there were any errors
5850 ExprResult CheckBooleanCondition(Expr *E, SourceLocation Loc);
5852 ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc,
5855 /// DiagnoseAssignmentAsCondition - Given that an expression is
5856 /// being used as a boolean condition, warn if it's an assignment.
5857 void DiagnoseAssignmentAsCondition(Expr *E);
5859 /// \brief Redundant parentheses over an equality comparison can indicate
5860 /// that the user intended an assignment used as condition.
5861 void DiagnoseEqualityWithExtraParens(ParenExpr *ParenE);
5863 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
5864 ExprResult CheckCXXBooleanCondition(Expr *CondExpr);
5866 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
5867 /// the specified width and sign. If an overflow occurs, detect it and emit
5868 /// the specified diagnostic.
5869 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
5870 unsigned NewWidth, bool NewSign,
5871 SourceLocation Loc, unsigned DiagID);
5873 /// Checks that the Objective-C declaration is declared in the global scope.
5874 /// Emits an error and marks the declaration as invalid if it's not declared
5875 /// in the global scope.
5876 bool CheckObjCDeclScope(Decl *D);
5878 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE,
5879 /// and reports the appropriate diagnostics. Returns false on success.
5880 /// Can optionally return the value of the expression.
5881 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0);
5883 /// VerifyBitField - verifies that a bit field expression is an ICE and has
5884 /// the correct width, and that the field type is valid.
5885 /// Returns false on success.
5886 /// Can optionally return whether the bit-field is of width 0
5887 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
5888 QualType FieldTy, const Expr *BitWidth,
5889 bool *ZeroWidth = 0);
5891 enum CUDAFunctionTarget {
5898 CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D);
5900 bool CheckCUDATarget(CUDAFunctionTarget CallerTarget,
5901 CUDAFunctionTarget CalleeTarget);
5903 bool CheckCUDATarget(const FunctionDecl *Caller, const FunctionDecl *Callee) {
5904 return CheckCUDATarget(IdentifyCUDATarget(Caller),
5905 IdentifyCUDATarget(Callee));
5908 /// \name Code completion
5910 /// \brief Describes the context in which code completion occurs.
5911 enum ParserCompletionContext {
5912 /// \brief Code completion occurs at top-level or namespace context.
5914 /// \brief Code completion occurs within a class, struct, or union.
5916 /// \brief Code completion occurs within an Objective-C interface, protocol,
5919 /// \brief Code completion occurs within an Objective-C implementation or
5920 /// category implementation
5921 PCC_ObjCImplementation,
5922 /// \brief Code completion occurs within the list of instance variables
5923 /// in an Objective-C interface, protocol, category, or implementation.
5924 PCC_ObjCInstanceVariableList,
5925 /// \brief Code completion occurs following one or more template
5928 /// \brief Code completion occurs following one or more template
5929 /// headers within a class.
5931 /// \brief Code completion occurs within an expression.
5933 /// \brief Code completion occurs within a statement, which may
5934 /// also be an expression or a declaration.
5936 /// \brief Code completion occurs at the beginning of the
5937 /// initialization statement (or expression) in a for loop.
5939 /// \brief Code completion occurs within the condition of an if,
5940 /// while, switch, or for statement.
5942 /// \brief Code completion occurs within the body of a function on a
5943 /// recovery path, where we do not have a specific handle on our position
5945 PCC_RecoveryInFunction,
5946 /// \brief Code completion occurs where only a type is permitted.
5948 /// \brief Code completion occurs in a parenthesized expression, which
5949 /// might also be a type cast.
5950 PCC_ParenthesizedExpression,
5951 /// \brief Code completion occurs within a sequence of declaration
5952 /// specifiers within a function, method, or block.
5953 PCC_LocalDeclarationSpecifiers
5956 void CodeCompleteOrdinaryName(Scope *S,
5957 ParserCompletionContext CompletionContext);
5958 void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS,
5959 bool AllowNonIdentifiers,
5960 bool AllowNestedNameSpecifiers);
5962 struct CodeCompleteExpressionData;
5963 void CodeCompleteExpression(Scope *S,
5964 const CodeCompleteExpressionData &Data);
5965 void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
5966 SourceLocation OpLoc,
5968 void CodeCompletePostfixExpression(Scope *S, ExprResult LHS);
5969 void CodeCompleteTag(Scope *S, unsigned TagSpec);
5970 void CodeCompleteTypeQualifiers(DeclSpec &DS);
5971 void CodeCompleteCase(Scope *S);
5972 void CodeCompleteCall(Scope *S, Expr *Fn, Expr **Args, unsigned NumArgs);
5973 void CodeCompleteInitializer(Scope *S, Decl *D);
5974 void CodeCompleteReturn(Scope *S);
5975 void CodeCompleteAfterIf(Scope *S);
5976 void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS);
5978 void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS,
5979 bool EnteringContext);
5980 void CodeCompleteUsing(Scope *S);
5981 void CodeCompleteUsingDirective(Scope *S);
5982 void CodeCompleteNamespaceDecl(Scope *S);
5983 void CodeCompleteNamespaceAliasDecl(Scope *S);
5984 void CodeCompleteOperatorName(Scope *S);
5985 void CodeCompleteConstructorInitializer(Decl *Constructor,
5986 CXXCtorInitializer** Initializers,
5987 unsigned NumInitializers);
5989 void CodeCompleteObjCAtDirective(Scope *S);
5990 void CodeCompleteObjCAtVisibility(Scope *S);
5991 void CodeCompleteObjCAtStatement(Scope *S);
5992 void CodeCompleteObjCAtExpression(Scope *S);
5993 void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS);
5994 void CodeCompleteObjCPropertyGetter(Scope *S);
5995 void CodeCompleteObjCPropertySetter(Scope *S);
5996 void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS,
5998 void CodeCompleteObjCMessageReceiver(Scope *S);
5999 void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc,
6000 IdentifierInfo **SelIdents,
6001 unsigned NumSelIdents,
6002 bool AtArgumentExpression);
6003 void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver,
6004 IdentifierInfo **SelIdents,
6005 unsigned NumSelIdents,
6006 bool AtArgumentExpression,
6007 bool IsSuper = false);
6008 void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver,
6009 IdentifierInfo **SelIdents,
6010 unsigned NumSelIdents,
6011 bool AtArgumentExpression,
6012 ObjCInterfaceDecl *Super = 0);
6013 void CodeCompleteObjCForCollection(Scope *S,
6014 DeclGroupPtrTy IterationVar);
6015 void CodeCompleteObjCSelector(Scope *S,
6016 IdentifierInfo **SelIdents,
6017 unsigned NumSelIdents);
6018 void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
6019 unsigned NumProtocols);
6020 void CodeCompleteObjCProtocolDecl(Scope *S);
6021 void CodeCompleteObjCInterfaceDecl(Scope *S);
6022 void CodeCompleteObjCSuperclass(Scope *S,
6023 IdentifierInfo *ClassName,
6024 SourceLocation ClassNameLoc);
6025 void CodeCompleteObjCImplementationDecl(Scope *S);
6026 void CodeCompleteObjCInterfaceCategory(Scope *S,
6027 IdentifierInfo *ClassName,
6028 SourceLocation ClassNameLoc);
6029 void CodeCompleteObjCImplementationCategory(Scope *S,
6030 IdentifierInfo *ClassName,
6031 SourceLocation ClassNameLoc);
6032 void CodeCompleteObjCPropertyDefinition(Scope *S);
6033 void CodeCompleteObjCPropertySynthesizeIvar(Scope *S,
6034 IdentifierInfo *PropertyName);
6035 void CodeCompleteObjCMethodDecl(Scope *S,
6036 bool IsInstanceMethod,
6037 ParsedType ReturnType);
6038 void CodeCompleteObjCMethodDeclSelector(Scope *S,
6039 bool IsInstanceMethod,
6040 bool AtParameterName,
6041 ParsedType ReturnType,
6042 IdentifierInfo **SelIdents,
6043 unsigned NumSelIdents);
6044 void CodeCompletePreprocessorDirective(bool InConditional);
6045 void CodeCompleteInPreprocessorConditionalExclusion(Scope *S);
6046 void CodeCompletePreprocessorMacroName(bool IsDefinition);
6047 void CodeCompletePreprocessorExpression();
6048 void CodeCompletePreprocessorMacroArgument(Scope *S,
6049 IdentifierInfo *Macro,
6050 MacroInfo *MacroInfo,
6052 void CodeCompleteNaturalLanguage();
6053 void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator,
6054 SmallVectorImpl<CodeCompletionResult> &Results);
6057 //===--------------------------------------------------------------------===//
6058 // Extra semantic analysis beyond the C type system
6061 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
6062 unsigned ByteNo) const;
6065 void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
6066 bool isSubscript=false, bool AllowOnePastEnd=true);
6067 void CheckArrayAccess(const Expr *E);
6068 bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall);
6069 bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall);
6071 bool CheckablePrintfAttr(const FormatAttr *Format, CallExpr *TheCall);
6072 bool CheckObjCString(Expr *Arg);
6074 ExprResult CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
6075 bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
6077 bool SemaBuiltinVAStart(CallExpr *TheCall);
6078 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
6079 bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs);
6082 // Used by C++ template instantiation.
6083 ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
6086 bool SemaBuiltinPrefetch(CallExpr *TheCall);
6087 bool SemaBuiltinObjectSize(CallExpr *TheCall);
6088 bool SemaBuiltinLongjmp(CallExpr *TheCall);
6089 ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult);
6090 ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult,
6091 AtomicExpr::AtomicOp Op);
6092 bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum,
6093 llvm::APSInt &Result);
6095 bool SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall,
6096 bool HasVAListArg, unsigned format_idx,
6097 unsigned firstDataArg, bool isPrintf);
6099 void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr,
6100 const CallExpr *TheCall, bool HasVAListArg,
6101 unsigned format_idx, unsigned firstDataArg,
6104 void CheckNonNullArguments(const NonNullAttr *NonNull,
6105 const Expr * const *ExprArgs,
6106 SourceLocation CallSiteLoc);
6108 void CheckPrintfScanfArguments(const CallExpr *TheCall, bool HasVAListArg,
6109 unsigned format_idx, unsigned firstDataArg,
6112 /// \brief Enumeration used to describe which of the memory setting or copying
6113 /// functions is being checked by \c CheckMemaccessArguments().
6114 enum CheckedMemoryFunction {
6126 void CheckMemaccessArguments(const CallExpr *Call, CheckedMemoryFunction CMF,
6127 IdentifierInfo *FnName);
6129 void CheckStrlcpycatArguments(const CallExpr *Call,
6130 IdentifierInfo *FnName);
6132 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
6133 SourceLocation ReturnLoc);
6134 void CheckFloatComparison(SourceLocation Loc, Expr* LHS, Expr* RHS);
6135 void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation());
6137 void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field,
6140 /// \brief The parser's current scope.
6142 /// The parser maintains this state here.
6146 friend class Parser;
6147 friend class InitializationSequence;
6148 friend class ASTReader;
6149 friend class ASTWriter;
6152 /// \brief Retrieve the parser's current scope.
6154 /// This routine must only be used when it is certain that semantic analysis
6155 /// and the parser are in precisely the same context, which is not the case
6156 /// when, e.g., we are performing any kind of template instantiation.
6157 /// Therefore, the only safe places to use this scope are in the parser
6158 /// itself and in routines directly invoked from the parser and *never* from
6159 /// template substitution or instantiation.
6160 Scope *getCurScope() const { return CurScope; }
6162 Decl *getObjCDeclContext() const;
6164 DeclContext *getCurLexicalContext() const {
6165 return OriginalLexicalContext ? OriginalLexicalContext : CurContext;
6168 AvailabilityResult getCurContextAvailability() const;
6171 /// \brief RAII object that enters a new expression evaluation context.
6172 class EnterExpressionEvaluationContext {
6176 EnterExpressionEvaluationContext(Sema &Actions,
6177 Sema::ExpressionEvaluationContext NewContext)
6178 : Actions(Actions) {
6179 Actions.PushExpressionEvaluationContext(NewContext);
6182 ~EnterExpressionEvaluationContext() {
6183 Actions.PopExpressionEvaluationContext();
6187 } // end namespace clang