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/LocInfoType.h"
24 #include "clang/Sema/TypoCorrection.h"
25 #include "clang/AST/Expr.h"
26 #include "clang/AST/DeclarationName.h"
27 #include "clang/AST/ExternalASTSource.h"
28 #include "clang/AST/TypeLoc.h"
29 #include "clang/Basic/Specifiers.h"
30 #include "clang/Basic/TemplateKinds.h"
31 #include "clang/Basic/TypeTraits.h"
32 #include "clang/Basic/ExpressionTraits.h"
33 #include "llvm/ADT/OwningPtr.h"
34 #include "llvm/ADT/SmallPtrSet.h"
35 #include "llvm/ADT/SmallVector.h"
41 template <typename ValueT> struct DenseMapInfo;
42 template <typename ValueT, typename ValueInfoT> class DenseSet;
49 class ASTMutationListener;
57 typedef llvm::SmallVector<CXXBaseSpecifier*, 4> CXXCastPath;
58 class CXXConstructorDecl;
59 class CXXConversionDecl;
60 class CXXDestructorDecl;
61 class CXXFieldCollector;
62 class CXXMemberCallExpr;
68 class ClassTemplateDecl;
69 class ClassTemplatePartialSpecializationDecl;
70 class ClassTemplateSpecializationDecl;
71 class CodeCompleteConsumer;
72 class CodeCompletionAllocator;
73 class CodeCompletionResult;
79 class DeducedTemplateArgument;
80 class DependentDiagnostic;
81 class DesignatedInitExpr;
83 class EnumConstantDecl;
86 class ExternalSemaSource;
90 class FunctionProtoType;
91 class FunctionTemplateDecl;
92 class ImplicitConversionSequence;
94 class InitializationKind;
95 class InitializationSequence;
96 class InitializedEntity;
100 class LocalInstantiationScope;
103 class MultiLevelTemplateArgumentList;
106 class ObjCCategoryDecl;
107 class ObjCCategoryImplDecl;
108 class ObjCCompatibleAliasDecl;
109 class ObjCContainerDecl;
111 class ObjCImplementationDecl;
112 class ObjCInterfaceDecl;
114 template <class T> class ObjCList;
115 class ObjCMessageExpr;
116 class ObjCMethodDecl;
117 class ObjCPropertyDecl;
118 class ObjCProtocolDecl;
119 class OverloadCandidateSet;
124 class PseudoDestructorTypeStorage;
126 class StandardConversionSequence;
130 class TargetAttributesSema;
131 class TemplateArgument;
132 class TemplateArgumentList;
133 class TemplateArgumentLoc;
135 class TemplateParameterList;
136 class TemplatePartialOrderingContext;
137 class TemplateTemplateParmDecl;
141 class TypedefNameDecl;
144 class UnresolvedLookupExpr;
145 class UnresolvedMemberExpr;
146 class UnresolvedSetImpl;
147 class UnresolvedSetIterator;
149 class UsingShadowDecl;
152 class VisibilityAttr;
153 class VisibleDeclConsumer;
154 class IndirectFieldDecl;
157 class AccessedEntity;
158 class BlockScopeInfo;
159 class DelayedDiagnostic;
160 class FunctionScopeInfo;
161 class TemplateDeductionInfo;
164 // FIXME: No way to easily map from TemplateTypeParmTypes to
165 // TemplateTypeParmDecls, so we have this horrible PointerUnion.
166 typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType*, NamedDecl*>,
167 SourceLocation> UnexpandedParameterPack;
169 /// Sema - This implements semantic analysis and AST building for C.
171 Sema(const Sema&); // DO NOT IMPLEMENT
172 void operator=(const Sema&); // DO NOT IMPLEMENT
173 mutable const TargetAttributesSema* TheTargetAttributesSema;
175 typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
176 typedef OpaquePtr<TemplateName> TemplateTy;
177 typedef OpaquePtr<QualType> TypeTy;
179 typedef CXXBaseSpecifier BaseTy;
180 typedef CXXCtorInitializer MemInitTy;
183 typedef TemplateParameterList TemplateParamsTy;
184 typedef NestedNameSpecifier CXXScopeTy;
186 OpenCLOptions OpenCLFeatures;
187 FPOptions FPFeatures;
189 const LangOptions &LangOpts;
192 ASTConsumer &Consumer;
194 SourceManager &SourceMgr;
196 /// \brief Flag indicating whether or not to collect detailed statistics.
199 /// \brief Source of additional semantic information.
200 ExternalSemaSource *ExternalSource;
202 /// \brief Code-completion consumer.
203 CodeCompleteConsumer *CodeCompleter;
205 /// CurContext - This is the current declaration context of parsing.
206 DeclContext *CurContext;
208 /// VAListTagName - The declaration name corresponding to __va_list_tag.
209 /// This is used as part of a hack to omit that class from ADL results.
210 DeclarationName VAListTagName;
212 /// PackContext - Manages the stack for #pragma pack. An alignment
213 /// of 0 indicates default alignment.
214 void *PackContext; // Really a "PragmaPackStack*"
216 bool MSStructPragmaOn; // True when #pragma ms_struct on
218 /// VisContext - Manages the stack for #pragma GCC visibility.
219 void *VisContext; // Really a "PragmaVisStack*"
221 /// ExprNeedsCleanups - True if the current evaluation context
222 /// requires cleanups to be run at its conclusion.
223 bool ExprNeedsCleanups;
225 /// \brief Stack containing information about each of the nested
226 /// function, block, and method scopes that are currently active.
228 /// This array is never empty. Clients should ignore the first
229 /// element, which is used to cache a single FunctionScopeInfo
230 /// that's used to parse every top-level function.
231 llvm::SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes;
233 /// ExprTemporaries - This is the stack of temporaries that are created by
234 /// the current full expression.
235 llvm::SmallVector<CXXTemporary*, 8> ExprTemporaries;
237 /// ExtVectorDecls - This is a list all the extended vector types. This allows
238 /// us to associate a raw vector type with one of the ext_vector type names.
239 /// This is only necessary for issuing pretty diagnostics.
240 llvm::SmallVector<TypedefNameDecl*, 24> ExtVectorDecls;
242 /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
243 llvm::OwningPtr<CXXFieldCollector> FieldCollector;
245 typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy;
247 /// PureVirtualClassDiagSet - a set of class declarations which we have
248 /// emitted a list of pure virtual functions. Used to prevent emitting the
249 /// same list more than once.
250 llvm::OwningPtr<RecordDeclSetTy> PureVirtualClassDiagSet;
252 /// ParsingInitForAutoVars - a set of declarations with auto types for which
253 /// we are currently parsing the initializer.
254 llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars;
256 /// \brief A mapping from external names to the most recent
257 /// locally-scoped external declaration with that name.
259 /// This map contains external declarations introduced in local
264 /// void foo(int, int);
268 /// Here, the name "foo" will be associated with the declaration on
269 /// "foo" within f. This name is not visible outside of
270 /// "f". However, we still find it in two cases:
272 /// - If we are declaring another external with the name "foo", we
273 /// can find "foo" as a previous declaration, so that the types
274 /// of this external declaration can be checked for
277 /// - If we would implicitly declare "foo" (e.g., due to a call to
278 /// "foo" in C when no prototype or definition is visible), then
279 /// we find this declaration of "foo" and complain that it is
281 llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternalDecls;
283 /// \brief All the tentative definitions encountered in the TU.
284 llvm::SmallVector<VarDecl *, 2> TentativeDefinitions;
286 /// \brief The set of file scoped decls seen so far that have not been used
287 /// and must warn if not used. Only contains the first declaration.
288 llvm::SmallVector<const DeclaratorDecl*, 4> UnusedFileScopedDecls;
290 /// \brief All the delegating constructors seen so far in the file, used for
291 /// cycle detection at the end of the TU.
292 llvm::SmallVector<CXXConstructorDecl*, 4> DelegatingCtorDecls;
294 /// \brief All the overriding destructors seen during a class definition
295 /// (there could be multiple due to nested classes) that had their exception
296 /// spec checks delayed, plus the overridden destructor.
297 llvm::SmallVector<std::pair<const CXXDestructorDecl*,
298 const CXXDestructorDecl*>, 2>
299 DelayedDestructorExceptionSpecChecks;
301 /// \brief Callback to the parser to parse templated functions when needed.
302 typedef void LateTemplateParserCB(void *P, const FunctionDecl *FD);
303 LateTemplateParserCB *LateTemplateParser;
306 void SetLateTemplateParser(LateTemplateParserCB *LTP, void *P) {
307 LateTemplateParser = LTP;
311 class DelayedDiagnostics;
313 class ParsingDeclState {
314 unsigned SavedStackSize;
315 friend class Sema::DelayedDiagnostics;
318 class ProcessingContextState {
319 unsigned SavedParsingDepth;
320 unsigned SavedActiveStackBase;
321 friend class Sema::DelayedDiagnostics;
324 /// A class which encapsulates the logic for delaying diagnostics
325 /// during parsing and other processing.
326 class DelayedDiagnostics {
327 /// \brief The stack of diagnostics that were delayed due to being
328 /// produced during the parsing of a declaration.
329 sema::DelayedDiagnostic *Stack;
331 /// \brief The number of objects on the delayed-diagnostics stack.
334 /// \brief The current capacity of the delayed-diagnostics stack.
335 unsigned StackCapacity;
337 /// \brief The index of the first "active" delayed diagnostic in
338 /// the stack. When parsing class definitions, we ignore active
339 /// delayed diagnostics from the surrounding context.
340 unsigned ActiveStackBase;
342 /// \brief The depth of the declarations we're currently parsing.
343 /// This gets saved and reset whenever we enter a class definition.
344 unsigned ParsingDepth;
347 DelayedDiagnostics() : Stack(0), StackSize(0), StackCapacity(0),
348 ActiveStackBase(0), ParsingDepth(0) {}
350 ~DelayedDiagnostics() {
351 delete[] reinterpret_cast<char*>(Stack);
354 /// Adds a delayed diagnostic.
355 void add(const sema::DelayedDiagnostic &diag);
357 /// Determines whether diagnostics should be delayed.
358 bool shouldDelayDiagnostics() { return ParsingDepth > 0; }
360 /// Observe that we've started parsing a declaration. Access and
361 /// deprecation diagnostics will be delayed; when the declaration
362 /// is completed, all active delayed diagnostics will be evaluated
363 /// in its context, and then active diagnostics stack will be
364 /// popped down to the saved depth.
365 ParsingDeclState pushParsingDecl() {
368 ParsingDeclState state;
369 state.SavedStackSize = StackSize;
373 /// Observe that we're completed parsing a declaration.
374 static void popParsingDecl(Sema &S, ParsingDeclState state, Decl *decl);
376 /// Observe that we've started processing a different context, the
377 /// contents of which are semantically separate from the
378 /// declarations it may lexically appear in. This sets aside the
379 /// current stack of active diagnostics and starts afresh.
380 ProcessingContextState pushContext() {
381 assert(StackSize >= ActiveStackBase);
383 ProcessingContextState state;
384 state.SavedParsingDepth = ParsingDepth;
385 state.SavedActiveStackBase = ActiveStackBase;
387 ActiveStackBase = StackSize;
393 /// Observe that we've stopped processing a context. This
394 /// restores the previous stack of active diagnostics.
395 void popContext(ProcessingContextState state) {
396 assert(ActiveStackBase == StackSize);
397 assert(ParsingDepth == 0);
398 ActiveStackBase = state.SavedActiveStackBase;
399 ParsingDepth = state.SavedParsingDepth;
401 } DelayedDiagnostics;
403 /// A RAII object to temporarily push a declaration context.
407 DeclContext *SavedContext;
408 ProcessingContextState SavedContextState;
411 ContextRAII(Sema &S, DeclContext *ContextToPush)
412 : S(S), SavedContext(S.CurContext),
413 SavedContextState(S.DelayedDiagnostics.pushContext())
415 assert(ContextToPush && "pushing null context");
416 S.CurContext = ContextToPush;
420 if (!SavedContext) return;
421 S.CurContext = SavedContext;
422 S.DelayedDiagnostics.popContext(SavedContextState);
431 /// WeakUndeclaredIdentifiers - Identifiers contained in
432 /// #pragma weak before declared. rare. may alias another
433 /// identifier, declared or undeclared
435 IdentifierInfo *alias; // alias (optional)
436 SourceLocation loc; // for diagnostics
437 bool used; // identifier later declared?
440 : alias(0), loc(SourceLocation()), used(false) {}
441 WeakInfo(IdentifierInfo *Alias, SourceLocation Loc)
442 : alias(Alias), loc(Loc), used(false) {}
443 inline IdentifierInfo * getAlias() const { return alias; }
444 inline SourceLocation getLocation() const { return loc; }
445 void setUsed(bool Used=true) { used = Used; }
446 inline bool getUsed() { return used; }
447 bool operator==(WeakInfo RHS) const {
448 return alias == RHS.getAlias() && loc == RHS.getLocation();
450 bool operator!=(WeakInfo RHS) const { return !(*this == RHS); }
452 llvm::DenseMap<IdentifierInfo*,WeakInfo> WeakUndeclaredIdentifiers;
454 /// WeakTopLevelDecl - Translation-unit scoped declarations generated by
455 /// #pragma weak during processing of other Decls.
456 /// I couldn't figure out a clean way to generate these in-line, so
457 /// we store them here and handle separately -- which is a hack.
458 /// It would be best to refactor this.
459 llvm::SmallVector<Decl*,2> WeakTopLevelDecl;
461 IdentifierResolver IdResolver;
463 /// Translation Unit Scope - useful to Objective-C actions that need
464 /// to lookup file scope declarations in the "ordinary" C decl namespace.
465 /// For example, user-defined classes, built-in "id" type, etc.
468 /// \brief The C++ "std" namespace, where the standard library resides.
469 LazyDeclPtr StdNamespace;
471 /// \brief The C++ "std::bad_alloc" class, which is defined by the C++
472 /// standard library.
473 LazyDeclPtr StdBadAlloc;
475 /// \brief The C++ "type_info" declaration, which is defined in <typeinfo>.
476 RecordDecl *CXXTypeInfoDecl;
478 /// \brief The MSVC "_GUID" struct, which is defined in MSVC header files.
479 RecordDecl *MSVCGuidDecl;
481 /// A flag to remember whether the implicit forms of operator new and delete
482 /// have been declared.
483 bool GlobalNewDeleteDeclared;
485 /// \brief The set of declarations that have been referenced within
486 /// a potentially evaluated expression.
487 typedef llvm::SmallVector<std::pair<SourceLocation, Decl *>, 10>
488 PotentiallyReferencedDecls;
490 /// \brief A set of diagnostics that may be emitted.
491 typedef llvm::SmallVector<std::pair<SourceLocation, PartialDiagnostic>, 10>
492 PotentiallyEmittedDiagnostics;
494 /// \brief Describes how the expressions currently being parsed are
495 /// evaluated at run-time, if at all.
496 enum ExpressionEvaluationContext {
497 /// \brief The current expression and its subexpressions occur within an
498 /// unevaluated operand (C++0x [expr]p8), such as a constant expression
499 /// or the subexpression of \c sizeof, where the type or the value of the
500 /// expression may be significant but no code will be generated to evaluate
501 /// the value of the expression at run time.
504 /// \brief The current expression is potentially evaluated at run time,
505 /// which means that code may be generated to evaluate the value of the
506 /// expression at run time.
507 PotentiallyEvaluated,
509 /// \brief The current expression may be potentially evaluated or it may
510 /// be unevaluated, but it is impossible to tell from the lexical context.
511 /// This evaluation context is used primary for the operand of the C++
512 /// \c typeid expression, whose argument is potentially evaluated only when
513 /// it is an lvalue of polymorphic class type (C++ [basic.def.odr]p2).
514 PotentiallyPotentiallyEvaluated,
516 /// \brief The current expression is potentially evaluated, but any
517 /// declarations referenced inside that expression are only used if
518 /// in fact the current expression is used.
520 /// This value is used when parsing default function arguments, for which
521 /// we would like to provide diagnostics (e.g., passing non-POD arguments
522 /// through varargs) but do not want to mark declarations as "referenced"
523 /// until the default argument is used.
524 PotentiallyEvaluatedIfUsed
527 /// \brief Data structure used to record current or nested
528 /// expression evaluation contexts.
529 struct ExpressionEvaluationContextRecord {
530 /// \brief The expression evaluation context.
531 ExpressionEvaluationContext Context;
533 /// \brief Whether the enclosing context needed a cleanup.
534 bool ParentNeedsCleanups;
536 /// \brief The number of temporaries that were active when we
537 /// entered this expression evaluation context.
538 unsigned NumTemporaries;
540 /// \brief The set of declarations referenced within a
541 /// potentially potentially-evaluated context.
543 /// When leaving a potentially potentially-evaluated context, each
544 /// of these elements will be as referenced if the corresponding
545 /// potentially potentially evaluated expression is potentially
547 PotentiallyReferencedDecls *PotentiallyReferenced;
549 /// \brief The set of diagnostics to emit should this potentially
550 /// potentially-evaluated context become evaluated.
551 PotentiallyEmittedDiagnostics *PotentiallyDiagnosed;
553 ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context,
554 unsigned NumTemporaries,
555 bool ParentNeedsCleanups)
556 : Context(Context), ParentNeedsCleanups(ParentNeedsCleanups),
557 NumTemporaries(NumTemporaries),
558 PotentiallyReferenced(0), PotentiallyDiagnosed(0) { }
560 void addReferencedDecl(SourceLocation Loc, Decl *Decl) {
561 if (!PotentiallyReferenced)
562 PotentiallyReferenced = new PotentiallyReferencedDecls;
563 PotentiallyReferenced->push_back(std::make_pair(Loc, Decl));
566 void addDiagnostic(SourceLocation Loc, const PartialDiagnostic &PD) {
567 if (!PotentiallyDiagnosed)
568 PotentiallyDiagnosed = new PotentiallyEmittedDiagnostics;
569 PotentiallyDiagnosed->push_back(std::make_pair(Loc, PD));
573 delete PotentiallyReferenced;
574 delete PotentiallyDiagnosed;
575 PotentiallyReferenced = 0;
576 PotentiallyDiagnosed = 0;
580 /// A stack of expression evaluation contexts.
581 llvm::SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts;
583 /// SpecialMemberOverloadResult - The overloading result for a special member
586 /// This is basically a wrapper around PointerIntPair. The lowest bit of the
587 /// integer is used to determine whether we have a parameter qualification
588 /// match, the second-lowest is whether we had success in resolving the
589 /// overload to a unique non-deleted function.
591 /// The ConstParamMatch bit represents whether, when looking up a copy
592 /// constructor or assignment operator, we found a potential copy
593 /// constructor/assignment operator whose first parameter is const-qualified.
594 /// This is used for determining parameter types of other objects and is
595 /// utterly meaningless on other types of special members.
596 class SpecialMemberOverloadResult : public llvm::FastFoldingSetNode {
597 llvm::PointerIntPair<CXXMethodDecl*, 2> Pair;
599 SpecialMemberOverloadResult(const llvm::FoldingSetNodeID &ID)
600 : FastFoldingSetNode(ID)
603 CXXMethodDecl *getMethod() const { return Pair.getPointer(); }
604 void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); }
606 bool hasSuccess() const { return Pair.getInt() & 0x1; }
607 void setSuccess(bool B) {
608 Pair.setInt(unsigned(B) | hasConstParamMatch() << 1);
611 bool hasConstParamMatch() const { return Pair.getInt() & 0x2; }
612 void setConstParamMatch(bool B) {
613 Pair.setInt(B << 1 | unsigned(hasSuccess()));
617 /// \brief A cache of special member function overload resolution results
619 llvm::FoldingSet<SpecialMemberOverloadResult> SpecialMemberCache;
621 /// \brief Whether the code handled by Sema should be considered a
622 /// complete translation unit or not.
624 /// When true (which is generally the case), Sema will perform
625 /// end-of-translation-unit semantic tasks (such as creating
626 /// initializers for tentative definitions in C) once parsing has
627 /// completed. This flag will be false when building PCH files,
628 /// since a PCH file is by definition not a complete translation
630 bool CompleteTranslationUnit;
632 llvm::BumpPtrAllocator BumpAlloc;
634 /// \brief The number of SFINAE diagnostics that have been trapped.
635 unsigned NumSFINAEErrors;
637 typedef llvm::DenseMap<ParmVarDecl *, llvm::SmallVector<ParmVarDecl *, 1> >
638 UnparsedDefaultArgInstantiationsMap;
640 /// \brief A mapping from parameters with unparsed default arguments to the
641 /// set of instantiations of each parameter.
643 /// This mapping is a temporary data structure used when parsing
644 /// nested class templates or nested classes of class templates,
645 /// where we might end up instantiating an inner class before the
646 /// default arguments of its methods have been parsed.
647 UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations;
649 // Contains the locations of the beginning of unparsed default
650 // argument locations.
651 llvm::DenseMap<ParmVarDecl *,SourceLocation> UnparsedDefaultArgLocs;
653 /// UndefinedInternals - all the used, undefined objects with
654 /// internal linkage in this translation unit.
655 llvm::DenseMap<NamedDecl*, SourceLocation> UndefinedInternals;
657 typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods;
658 typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool;
660 /// Method Pool - allows efficient lookup when typechecking messages to "id".
661 /// We need to maintain a list, since selectors can have differing signatures
662 /// across classes. In Cocoa, this happens to be extremely uncommon (only 1%
663 /// of selectors are "overloaded").
664 GlobalMethodPool MethodPool;
666 /// Method selectors used in a @selector expression. Used for implementation
668 llvm::DenseMap<Selector, SourceLocation> ReferencedSelectors;
670 GlobalMethodPool::iterator ReadMethodPool(Selector Sel);
672 /// Private Helper predicate to check for 'self'.
673 bool isSelfExpr(Expr *RExpr);
675 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
676 bool CompleteTranslationUnit = true,
677 CodeCompleteConsumer *CompletionConsumer = 0);
680 /// \brief Perform initialization that occurs after the parser has been
681 /// initialized but before it parses anything.
684 const LangOptions &getLangOptions() const { return LangOpts; }
685 OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; }
686 FPOptions &getFPOptions() { return FPFeatures; }
688 Diagnostic &getDiagnostics() const { return Diags; }
689 SourceManager &getSourceManager() const { return SourceMgr; }
690 const TargetAttributesSema &getTargetAttributesSema() const;
691 Preprocessor &getPreprocessor() const { return PP; }
692 ASTContext &getASTContext() const { return Context; }
693 ASTConsumer &getASTConsumer() const { return Consumer; }
694 ASTMutationListener *getASTMutationListener() const;
696 void PrintStats() const;
698 /// \brief Helper class that creates diagnostics with optional
699 /// template instantiation stacks.
701 /// This class provides a wrapper around the basic DiagnosticBuilder
702 /// class that emits diagnostics. SemaDiagnosticBuilder is
703 /// responsible for emitting the diagnostic (as DiagnosticBuilder
704 /// does) and, if the diagnostic comes from inside a template
705 /// instantiation, printing the template instantiation stack as
707 class SemaDiagnosticBuilder : public DiagnosticBuilder {
712 SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID)
713 : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { }
715 explicit SemaDiagnosticBuilder(Sema &SemaRef)
716 : DiagnosticBuilder(DiagnosticBuilder::Suppress), SemaRef(SemaRef) { }
718 ~SemaDiagnosticBuilder();
721 /// \brief Emit a diagnostic.
722 SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
724 /// \brief Emit a partial diagnostic.
725 SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic& PD);
727 /// \brief Build a partial diagnostic.
728 PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h
730 bool findMacroSpelling(SourceLocation &loc, llvm::StringRef name);
732 ExprResult Owned(Expr* E) { return E; }
733 ExprResult Owned(ExprResult R) { return R; }
734 StmtResult Owned(Stmt* S) { return S; }
736 void ActOnEndOfTranslationUnit();
738 void CheckDelegatingCtorCycles();
740 Scope *getScopeForContext(DeclContext *Ctx);
742 void PushFunctionScope();
743 void PushBlockScope(Scope *BlockScope, BlockDecl *Block);
744 void PopFunctionOrBlockScope(const sema::AnalysisBasedWarnings::Policy *WP =0,
745 const Decl *D = 0, const BlockExpr *blkExpr = 0);
747 sema::FunctionScopeInfo *getCurFunction() const {
748 return FunctionScopes.back();
751 bool hasAnyUnrecoverableErrorsInThisFunction() const;
753 /// \brief Retrieve the current block, if any.
754 sema::BlockScopeInfo *getCurBlock();
756 /// WeakTopLevelDeclDecls - access to #pragma weak-generated Decls
757 llvm::SmallVector<Decl*,2> &WeakTopLevelDecls() { return WeakTopLevelDecl; }
759 //===--------------------------------------------------------------------===//
760 // Type Analysis / Processing: SemaType.cpp.
763 QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs);
764 QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVR) {
765 return BuildQualifiedType(T, Loc, Qualifiers::fromCVRMask(CVR));
767 QualType BuildPointerType(QualType T,
768 SourceLocation Loc, DeclarationName Entity);
769 QualType BuildReferenceType(QualType T, bool LValueRef,
770 SourceLocation Loc, DeclarationName Entity);
771 QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
772 Expr *ArraySize, unsigned Quals,
773 SourceRange Brackets, DeclarationName Entity);
774 QualType BuildExtVectorType(QualType T, Expr *ArraySize,
775 SourceLocation AttrLoc);
776 QualType BuildFunctionType(QualType T,
777 QualType *ParamTypes, unsigned NumParamTypes,
778 bool Variadic, unsigned Quals,
779 RefQualifierKind RefQualifier,
780 SourceLocation Loc, DeclarationName Entity,
781 FunctionType::ExtInfo Info);
782 QualType BuildMemberPointerType(QualType T, QualType Class,
784 DeclarationName Entity);
785 QualType BuildBlockPointerType(QualType T,
786 SourceLocation Loc, DeclarationName Entity);
787 QualType BuildParenType(QualType T);
789 TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S);
790 TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy);
791 TypeSourceInfo *GetTypeSourceInfoForDeclarator(Declarator &D, QualType T,
792 TypeSourceInfo *ReturnTypeInfo);
793 /// \brief Package the given type and TSI into a ParsedType.
794 ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo);
795 DeclarationNameInfo GetNameForDeclarator(Declarator &D);
796 DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name);
797 static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo = 0);
798 bool CheckSpecifiedExceptionType(QualType T, const SourceRange &Range);
799 bool CheckDistantExceptionSpec(QualType T);
800 bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New);
801 bool CheckEquivalentExceptionSpec(
802 const FunctionProtoType *Old, SourceLocation OldLoc,
803 const FunctionProtoType *New, SourceLocation NewLoc);
804 bool CheckEquivalentExceptionSpec(
805 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
806 const FunctionProtoType *Old, SourceLocation OldLoc,
807 const FunctionProtoType *New, SourceLocation NewLoc,
808 bool *MissingExceptionSpecification = 0,
809 bool *MissingEmptyExceptionSpecification = 0,
810 bool AllowNoexceptAllMatchWithNoSpec = false,
811 bool IsOperatorNew = false);
812 bool CheckExceptionSpecSubset(
813 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
814 const FunctionProtoType *Superset, SourceLocation SuperLoc,
815 const FunctionProtoType *Subset, SourceLocation SubLoc);
816 bool CheckParamExceptionSpec(const PartialDiagnostic & NoteID,
817 const FunctionProtoType *Target, SourceLocation TargetLoc,
818 const FunctionProtoType *Source, SourceLocation SourceLoc);
820 TypeResult ActOnTypeName(Scope *S, Declarator &D);
822 bool RequireCompleteType(SourceLocation Loc, QualType T,
823 const PartialDiagnostic &PD,
824 std::pair<SourceLocation, PartialDiagnostic> Note);
825 bool RequireCompleteType(SourceLocation Loc, QualType T,
826 const PartialDiagnostic &PD);
827 bool RequireCompleteType(SourceLocation Loc, QualType T,
829 bool RequireCompleteExprType(Expr *E, const PartialDiagnostic &PD,
830 std::pair<SourceLocation,
831 PartialDiagnostic> Note);
834 QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
835 const CXXScopeSpec &SS, QualType T);
837 QualType BuildTypeofExprType(Expr *E, SourceLocation Loc);
838 QualType BuildDecltypeType(Expr *E, SourceLocation Loc);
839 QualType BuildUnaryTransformType(QualType BaseType,
840 UnaryTransformType::UTTKind UKind,
843 //===--------------------------------------------------------------------===//
844 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
847 DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = 0);
849 void DiagnoseUseOfUnimplementedSelectors();
851 ParsedType getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
852 Scope *S, CXXScopeSpec *SS = 0,
853 bool isClassName = false,
854 bool HasTrailingDot = false,
855 ParsedType ObjectType = ParsedType(),
856 bool WantNontrivialTypeSourceInfo = false);
857 TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S);
858 bool isMicrosoftMissingTypename(const CXXScopeSpec *SS);
859 bool DiagnoseUnknownTypeName(const IdentifierInfo &II,
860 SourceLocation IILoc,
863 ParsedType &SuggestedType);
865 /// \brief Describes the result of the name lookup and resolution performed
866 /// by \c ClassifyName().
867 enum NameClassificationKind {
873 NC_NestedNameSpecifier,
878 class NameClassification {
879 NameClassificationKind Kind;
881 TemplateName Template;
883 const IdentifierInfo *Keyword;
885 explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {}
888 NameClassification(ExprResult Expr) : Kind(NC_Expression), Expr(Expr) {}
890 NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {}
892 NameClassification(const IdentifierInfo *Keyword)
893 : Kind(NC_Keyword), Keyword(Keyword) { }
895 static NameClassification Error() {
896 return NameClassification(NC_Error);
899 static NameClassification Unknown() {
900 return NameClassification(NC_Unknown);
903 static NameClassification NestedNameSpecifier() {
904 return NameClassification(NC_NestedNameSpecifier);
907 static NameClassification TypeTemplate(TemplateName Name) {
908 NameClassification Result(NC_TypeTemplate);
909 Result.Template = Name;
913 static NameClassification FunctionTemplate(TemplateName Name) {
914 NameClassification Result(NC_FunctionTemplate);
915 Result.Template = Name;
919 NameClassificationKind getKind() const { return Kind; }
921 ParsedType getType() const {
922 assert(Kind == NC_Type);
926 ExprResult getExpression() const {
927 assert(Kind == NC_Expression);
931 TemplateName getTemplateName() const {
932 assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate);
936 TemplateNameKind getTemplateNameKind() const {
937 assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate);
938 return Kind == NC_TypeTemplate? TNK_Type_template : TNK_Function_template;
942 /// \brief Perform name lookup on the given name, classifying it based on
943 /// the results of name lookup and the following token.
945 /// This routine is used by the parser to resolve identifiers and help direct
946 /// parsing. When the identifier cannot be found, this routine will attempt
947 /// to correct the typo and classify based on the resulting name.
949 /// \param S The scope in which we're performing name lookup.
951 /// \param SS The nested-name-specifier that precedes the name.
953 /// \param Name The identifier. If typo correction finds an alternative name,
954 /// this pointer parameter will be updated accordingly.
956 /// \param NameLoc The location of the identifier.
958 /// \param NextToken The token following the identifier. Used to help
959 /// disambiguate the name.
960 NameClassification ClassifyName(Scope *S,
962 IdentifierInfo *&Name,
963 SourceLocation NameLoc,
964 const Token &NextToken);
966 Decl *ActOnDeclarator(Scope *S, Declarator &D);
968 Decl *HandleDeclarator(Scope *S, Declarator &D,
969 MultiTemplateParamsArg TemplateParameterLists,
970 bool IsFunctionDefinition);
971 void RegisterLocallyScopedExternCDecl(NamedDecl *ND,
972 const LookupResult &Previous,
974 bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info);
975 void DiagnoseFunctionSpecifiers(Declarator& D);
976 void CheckShadow(Scope *S, VarDecl *D, const LookupResult& R);
977 void CheckShadow(Scope *S, VarDecl *D);
978 void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange);
979 void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D);
980 NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
981 QualType R, TypeSourceInfo *TInfo,
982 LookupResult &Previous, bool &Redeclaration);
983 NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D,
984 LookupResult &Previous, bool &Redeclaration);
985 NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
986 QualType R, TypeSourceInfo *TInfo,
987 LookupResult &Previous,
988 MultiTemplateParamsArg TemplateParamLists,
989 bool &Redeclaration);
990 void CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous,
991 bool &Redeclaration);
992 void CheckCompleteVariableDeclaration(VarDecl *var);
993 NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
994 QualType R, TypeSourceInfo *TInfo,
995 LookupResult &Previous,
996 MultiTemplateParamsArg TemplateParamLists,
997 bool IsFunctionDefinition,
998 bool &Redeclaration);
999 bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD);
1000 void DiagnoseHiddenVirtualMethods(CXXRecordDecl *DC, CXXMethodDecl *MD);
1001 void CheckFunctionDeclaration(Scope *S,
1002 FunctionDecl *NewFD, LookupResult &Previous,
1003 bool IsExplicitSpecialization,
1004 bool &Redeclaration);
1005 void CheckMain(FunctionDecl *FD);
1006 Decl *ActOnParamDeclarator(Scope *S, Declarator &D);
1007 ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC,
1010 ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc,
1011 SourceLocation NameLoc, IdentifierInfo *Name,
1012 QualType T, TypeSourceInfo *TSInfo,
1013 StorageClass SC, StorageClass SCAsWritten);
1014 void ActOnParamDefaultArgument(Decl *param,
1015 SourceLocation EqualLoc,
1017 void ActOnParamUnparsedDefaultArgument(Decl *param,
1018 SourceLocation EqualLoc,
1019 SourceLocation ArgLoc);
1020 void ActOnParamDefaultArgumentError(Decl *param);
1021 bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg,
1022 SourceLocation EqualLoc);
1024 void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit,
1025 bool TypeMayContainAuto);
1026 void ActOnUninitializedDecl(Decl *dcl, bool TypeMayContainAuto);
1027 void ActOnInitializerError(Decl *Dcl);
1028 void ActOnCXXForRangeDecl(Decl *D);
1029 void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc);
1030 void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc);
1031 void FinalizeDeclaration(Decl *D);
1032 DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS,
1035 DeclGroupPtrTy BuildDeclaratorGroup(Decl **Group, unsigned NumDecls,
1036 bool TypeMayContainAuto = true);
1037 void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
1038 SourceLocation LocAfterDecls);
1039 void CheckForFunctionRedefinition(FunctionDecl *FD);
1040 Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
1041 Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D);
1042 void ActOnStartOfObjCMethodDef(Scope *S, Decl *D);
1044 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body);
1045 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation);
1047 /// \brief Diagnose any unused parameters in the given sequence of
1048 /// ParmVarDecl pointers.
1049 void DiagnoseUnusedParameters(ParmVarDecl * const *Begin,
1050 ParmVarDecl * const *End);
1052 /// \brief Diagnose whether the size of parameters or return value of a
1053 /// function or obj-c method definition is pass-by-value and larger than a
1054 /// specified threshold.
1055 void DiagnoseSizeOfParametersAndReturnValue(ParmVarDecl * const *Begin,
1056 ParmVarDecl * const *End,
1060 void DiagnoseInvalidJumps(Stmt *Body);
1061 Decl *ActOnFileScopeAsmDecl(Expr *expr,
1062 SourceLocation AsmLoc,
1063 SourceLocation RParenLoc);
1066 void ActOnPopScope(SourceLocation Loc, Scope *S);
1067 void ActOnTranslationUnitScope(Scope *S);
1069 Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
1071 Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
1073 MultiTemplateParamsArg TemplateParams);
1075 StmtResult ActOnVlaStmt(const DeclSpec &DS);
1077 Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
1079 RecordDecl *Record);
1081 Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS,
1082 RecordDecl *Record);
1084 bool isAcceptableTagRedeclaration(const TagDecl *Previous,
1085 TagTypeKind NewTag, bool isDefinition,
1086 SourceLocation NewTagLoc,
1087 const IdentifierInfo &Name);
1090 TUK_Reference, // Reference to a tag: 'struct foo *X;'
1091 TUK_Declaration, // Fwd decl of a tag: 'struct foo;'
1092 TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;'
1093 TUK_Friend // Friend declaration: 'friend struct foo;'
1096 Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
1097 SourceLocation KWLoc, CXXScopeSpec &SS,
1098 IdentifierInfo *Name, SourceLocation NameLoc,
1099 AttributeList *Attr, AccessSpecifier AS,
1100 MultiTemplateParamsArg TemplateParameterLists,
1101 bool &OwnedDecl, bool &IsDependent, bool ScopedEnum,
1102 bool ScopedEnumUsesClassTag, TypeResult UnderlyingType);
1104 Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc,
1105 unsigned TagSpec, SourceLocation TagLoc,
1107 IdentifierInfo *Name, SourceLocation NameLoc,
1108 AttributeList *Attr,
1109 MultiTemplateParamsArg TempParamLists);
1111 TypeResult ActOnDependentTag(Scope *S,
1114 const CXXScopeSpec &SS,
1115 IdentifierInfo *Name,
1116 SourceLocation TagLoc,
1117 SourceLocation NameLoc);
1119 void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart,
1120 IdentifierInfo *ClassName,
1121 llvm::SmallVectorImpl<Decl *> &Decls);
1122 Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart,
1123 Declarator &D, Expr *BitfieldWidth);
1125 FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
1126 Declarator &D, Expr *BitfieldWidth, bool HasInit,
1127 AccessSpecifier AS);
1129 FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T,
1130 TypeSourceInfo *TInfo,
1131 RecordDecl *Record, SourceLocation Loc,
1132 bool Mutable, Expr *BitfieldWidth, bool HasInit,
1133 SourceLocation TSSL,
1134 AccessSpecifier AS, NamedDecl *PrevDecl,
1137 enum CXXSpecialMember {
1138 CXXDefaultConstructor,
1146 bool CheckNontrivialField(FieldDecl *FD);
1147 void DiagnoseNontrivial(const RecordType* Record, CXXSpecialMember mem);
1148 CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD);
1149 void ActOnLastBitfield(SourceLocation DeclStart, Decl *IntfDecl,
1150 llvm::SmallVectorImpl<Decl *> &AllIvarDecls);
1151 Decl *ActOnIvar(Scope *S, SourceLocation DeclStart, Decl *IntfDecl,
1152 Declarator &D, Expr *BitfieldWidth,
1153 tok::ObjCKeywordKind visibility);
1155 // This is used for both record definitions and ObjC interface declarations.
1156 void ActOnFields(Scope* S, SourceLocation RecLoc, Decl *TagDecl,
1157 Decl **Fields, unsigned NumFields,
1158 SourceLocation LBrac, SourceLocation RBrac,
1159 AttributeList *AttrList);
1161 /// ActOnTagStartDefinition - Invoked when we have entered the
1162 /// scope of a tag's definition (e.g., for an enumeration, class,
1163 /// struct, or union).
1164 void ActOnTagStartDefinition(Scope *S, Decl *TagDecl);
1166 /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a
1167 /// C++ record definition's base-specifiers clause and are starting its
1168 /// member declarations.
1169 void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl,
1170 SourceLocation FinalLoc,
1171 SourceLocation LBraceLoc);
1173 /// ActOnTagFinishDefinition - Invoked once we have finished parsing
1174 /// the definition of a tag (enumeration, class, struct, or union).
1175 void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl,
1176 SourceLocation RBraceLoc);
1178 /// ActOnTagDefinitionError - Invoked when there was an unrecoverable
1179 /// error parsing the definition of a tag.
1180 void ActOnTagDefinitionError(Scope *S, Decl *TagDecl);
1182 EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum,
1183 EnumConstantDecl *LastEnumConst,
1184 SourceLocation IdLoc,
1188 Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant,
1189 SourceLocation IdLoc, IdentifierInfo *Id,
1190 AttributeList *Attrs,
1191 SourceLocation EqualLoc, Expr *Val);
1192 void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc,
1193 SourceLocation RBraceLoc, Decl *EnumDecl,
1194 Decl **Elements, unsigned NumElements,
1195 Scope *S, AttributeList *Attr);
1197 DeclContext *getContainingDC(DeclContext *DC);
1199 /// Set the current declaration context until it gets popped.
1200 void PushDeclContext(Scope *S, DeclContext *DC);
1201 void PopDeclContext();
1203 /// EnterDeclaratorContext - Used when we must lookup names in the context
1204 /// of a declarator's nested name specifier.
1205 void EnterDeclaratorContext(Scope *S, DeclContext *DC);
1206 void ExitDeclaratorContext(Scope *S);
1208 DeclContext *getFunctionLevelDeclContext();
1210 /// getCurFunctionDecl - If inside of a function body, this returns a pointer
1211 /// to the function decl for the function being parsed. If we're currently
1212 /// in a 'block', this returns the containing context.
1213 FunctionDecl *getCurFunctionDecl();
1215 /// getCurMethodDecl - If inside of a method body, this returns a pointer to
1216 /// the method decl for the method being parsed. If we're currently
1217 /// in a 'block', this returns the containing context.
1218 ObjCMethodDecl *getCurMethodDecl();
1220 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
1221 /// or C function we're in, otherwise return null. If we're currently
1222 /// in a 'block', this returns the containing context.
1223 NamedDecl *getCurFunctionOrMethodDecl();
1225 /// Add this decl to the scope shadowed decl chains.
1226 void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true);
1228 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
1229 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
1230 /// true if 'D' belongs to the given declaration context.
1232 /// \param ExplicitInstantiationOrSpecialization When true, we are checking
1233 /// whether the declaration is in scope for the purposes of explicit template
1234 /// instantiation or specialization. The default is false.
1235 bool isDeclInScope(NamedDecl *&D, DeclContext *Ctx, Scope *S = 0,
1236 bool ExplicitInstantiationOrSpecialization = false);
1238 /// Finds the scope corresponding to the given decl context, if it
1239 /// happens to be an enclosing scope. Otherwise return NULL.
1240 static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC);
1242 /// Subroutines of ActOnDeclarator().
1243 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
1244 TypeSourceInfo *TInfo);
1245 void MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls);
1246 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old);
1247 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old);
1248 void mergeObjCMethodDecls(ObjCMethodDecl *New, const ObjCMethodDecl *Old);
1249 void MergeVarDecl(VarDecl *New, LookupResult &OldDecls);
1250 void MergeVarDeclTypes(VarDecl *New, VarDecl *Old);
1251 void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old);
1252 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
1254 // AssignmentAction - This is used by all the assignment diagnostic functions
1255 // to represent what is actually causing the operation
1256 enum AssignmentAction {
1266 /// C++ Overloading.
1268 /// This is a legitimate overload: the existing declarations are
1269 /// functions or function templates with different signatures.
1272 /// This is not an overload because the signature exactly matches
1273 /// an existing declaration.
1276 /// This is not an overload because the lookup results contain a
1280 OverloadKind CheckOverload(Scope *S,
1282 const LookupResult &OldDecls,
1283 NamedDecl *&OldDecl,
1284 bool IsForUsingDecl);
1285 bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl);
1287 /// \brief Checks availability of the function depending on the current
1288 /// function context.Inside an unavailable function,unavailability is ignored.
1290 /// \returns true if \arg FD is unavailable and current context is inside
1291 /// an available function, false otherwise.
1292 bool isFunctionConsideredUnavailable(FunctionDecl *FD);
1294 ImplicitConversionSequence
1295 TryImplicitConversion(Expr *From, QualType ToType,
1296 bool SuppressUserConversions,
1298 bool InOverloadResolution,
1300 bool AllowObjCWritebackConversion);
1302 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
1303 bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
1304 bool IsComplexPromotion(QualType FromType, QualType ToType);
1305 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
1306 bool InOverloadResolution,
1307 QualType& ConvertedType, bool &IncompatibleObjC);
1308 bool isObjCPointerConversion(QualType FromType, QualType ToType,
1309 QualType& ConvertedType, bool &IncompatibleObjC);
1310 bool isObjCWritebackConversion(QualType FromType, QualType ToType,
1311 QualType &ConvertedType);
1312 bool IsBlockPointerConversion(QualType FromType, QualType ToType,
1313 QualType& ConvertedType);
1314 bool FunctionArgTypesAreEqual(const FunctionProtoType *OldType,
1315 const FunctionProtoType *NewType);
1317 bool CheckPointerConversion(Expr *From, QualType ToType,
1319 CXXCastPath& BasePath,
1320 bool IgnoreBaseAccess);
1321 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
1322 bool InOverloadResolution,
1323 QualType &ConvertedType);
1324 bool CheckMemberPointerConversion(Expr *From, QualType ToType,
1326 CXXCastPath &BasePath,
1327 bool IgnoreBaseAccess);
1328 bool IsQualificationConversion(QualType FromType, QualType ToType,
1329 bool CStyle, bool &ObjCLifetimeConversion);
1330 bool IsNoReturnConversion(QualType FromType, QualType ToType,
1331 QualType &ResultTy);
1332 bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType);
1335 ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
1336 const VarDecl *NRVOCandidate,
1337 QualType ResultType,
1339 bool AllowNRVO = true);
1341 bool CanPerformCopyInitialization(const InitializedEntity &Entity,
1343 ExprResult PerformCopyInitialization(const InitializedEntity &Entity,
1344 SourceLocation EqualLoc,
1346 ExprResult PerformObjectArgumentInitialization(Expr *From,
1347 NestedNameSpecifier *Qualifier,
1348 NamedDecl *FoundDecl,
1349 CXXMethodDecl *Method);
1351 ExprResult PerformContextuallyConvertToBool(Expr *From);
1352 ExprResult PerformContextuallyConvertToObjCId(Expr *From);
1355 ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *FromE,
1356 const PartialDiagnostic &NotIntDiag,
1357 const PartialDiagnostic &IncompleteDiag,
1358 const PartialDiagnostic &ExplicitConvDiag,
1359 const PartialDiagnostic &ExplicitConvNote,
1360 const PartialDiagnostic &AmbigDiag,
1361 const PartialDiagnostic &AmbigNote,
1362 const PartialDiagnostic &ConvDiag);
1364 ExprResult PerformObjectMemberConversion(Expr *From,
1365 NestedNameSpecifier *Qualifier,
1366 NamedDecl *FoundDecl,
1369 // Members have to be NamespaceDecl* or TranslationUnitDecl*.
1370 // TODO: make this is a typesafe union.
1371 typedef llvm::SmallPtrSet<DeclContext *, 16> AssociatedNamespaceSet;
1372 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet;
1374 void AddOverloadCandidate(NamedDecl *Function,
1375 DeclAccessPair FoundDecl,
1376 Expr **Args, unsigned NumArgs,
1377 OverloadCandidateSet &CandidateSet);
1379 void AddOverloadCandidate(FunctionDecl *Function,
1380 DeclAccessPair FoundDecl,
1381 Expr **Args, unsigned NumArgs,
1382 OverloadCandidateSet& CandidateSet,
1383 bool SuppressUserConversions = false,
1384 bool PartialOverloading = false);
1385 void AddFunctionCandidates(const UnresolvedSetImpl &Functions,
1386 Expr **Args, unsigned NumArgs,
1387 OverloadCandidateSet& CandidateSet,
1388 bool SuppressUserConversions = false);
1389 void AddMethodCandidate(DeclAccessPair FoundDecl,
1390 QualType ObjectType,
1391 Expr::Classification ObjectClassification,
1392 Expr **Args, unsigned NumArgs,
1393 OverloadCandidateSet& CandidateSet,
1394 bool SuppressUserConversion = false);
1395 void AddMethodCandidate(CXXMethodDecl *Method,
1396 DeclAccessPair FoundDecl,
1397 CXXRecordDecl *ActingContext, QualType ObjectType,
1398 Expr::Classification ObjectClassification,
1399 Expr **Args, unsigned NumArgs,
1400 OverloadCandidateSet& CandidateSet,
1401 bool SuppressUserConversions = false);
1402 void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl,
1403 DeclAccessPair FoundDecl,
1404 CXXRecordDecl *ActingContext,
1405 TemplateArgumentListInfo *ExplicitTemplateArgs,
1406 QualType ObjectType,
1407 Expr::Classification ObjectClassification,
1408 Expr **Args, unsigned NumArgs,
1409 OverloadCandidateSet& CandidateSet,
1410 bool SuppressUserConversions = false);
1411 void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate,
1412 DeclAccessPair FoundDecl,
1413 TemplateArgumentListInfo *ExplicitTemplateArgs,
1414 Expr **Args, unsigned NumArgs,
1415 OverloadCandidateSet& CandidateSet,
1416 bool SuppressUserConversions = false);
1417 void AddConversionCandidate(CXXConversionDecl *Conversion,
1418 DeclAccessPair FoundDecl,
1419 CXXRecordDecl *ActingContext,
1420 Expr *From, QualType ToType,
1421 OverloadCandidateSet& CandidateSet);
1422 void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate,
1423 DeclAccessPair FoundDecl,
1424 CXXRecordDecl *ActingContext,
1425 Expr *From, QualType ToType,
1426 OverloadCandidateSet &CandidateSet);
1427 void AddSurrogateCandidate(CXXConversionDecl *Conversion,
1428 DeclAccessPair FoundDecl,
1429 CXXRecordDecl *ActingContext,
1430 const FunctionProtoType *Proto,
1431 Expr *Object, Expr **Args, unsigned NumArgs,
1432 OverloadCandidateSet& CandidateSet);
1433 void AddMemberOperatorCandidates(OverloadedOperatorKind Op,
1434 SourceLocation OpLoc,
1435 Expr **Args, unsigned NumArgs,
1436 OverloadCandidateSet& CandidateSet,
1437 SourceRange OpRange = SourceRange());
1438 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
1439 Expr **Args, unsigned NumArgs,
1440 OverloadCandidateSet& CandidateSet,
1441 bool IsAssignmentOperator = false,
1442 unsigned NumContextualBoolArguments = 0);
1443 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
1444 SourceLocation OpLoc,
1445 Expr **Args, unsigned NumArgs,
1446 OverloadCandidateSet& CandidateSet);
1447 void AddArgumentDependentLookupCandidates(DeclarationName Name,
1449 Expr **Args, unsigned NumArgs,
1450 TemplateArgumentListInfo *ExplicitTemplateArgs,
1451 OverloadCandidateSet& CandidateSet,
1452 bool PartialOverloading = false,
1453 bool StdNamespaceIsAssociated = false);
1455 // Emit as a 'note' the specific overload candidate
1456 void NoteOverloadCandidate(FunctionDecl *Fn);
1458 // Emit as a series of 'note's all template and non-templates
1459 // identified by the expression Expr
1460 void NoteAllOverloadCandidates(Expr* E);
1462 // [PossiblyAFunctionType] --> [Return]
1463 // NonFunctionType --> NonFunctionType
1465 // R (*)(A) --> R (A)
1466 // R (&)(A) --> R (A)
1467 // R (S::*)(A) --> R (A)
1468 QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType);
1470 FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, QualType TargetType,
1472 DeclAccessPair &Found);
1474 FunctionDecl *ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl,
1475 bool Complain = false,
1476 DeclAccessPair* Found = 0);
1478 ExprResult ResolveAndFixSingleFunctionTemplateSpecialization(
1479 Expr *SrcExpr, bool DoFunctionPointerConverion = false,
1480 bool Complain = false,
1481 const SourceRange& OpRangeForComplaining = SourceRange(),
1482 QualType DestTypeForComplaining = QualType(),
1483 unsigned DiagIDForComplaining = 0);
1486 Expr *FixOverloadedFunctionReference(Expr *E,
1487 DeclAccessPair FoundDecl,
1489 ExprResult FixOverloadedFunctionReference(ExprResult,
1490 DeclAccessPair FoundDecl,
1493 void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE,
1494 Expr **Args, unsigned NumArgs,
1495 OverloadCandidateSet &CandidateSet,
1496 bool PartialOverloading = false);
1498 ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn,
1499 UnresolvedLookupExpr *ULE,
1500 SourceLocation LParenLoc,
1501 Expr **Args, unsigned NumArgs,
1502 SourceLocation RParenLoc,
1505 ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc,
1507 const UnresolvedSetImpl &Fns,
1510 ExprResult CreateOverloadedBinOp(SourceLocation OpLoc,
1512 const UnresolvedSetImpl &Fns,
1513 Expr *LHS, Expr *RHS);
1515 ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
1516 SourceLocation RLoc,
1517 Expr *Base,Expr *Idx);
1520 BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
1521 SourceLocation LParenLoc, Expr **Args,
1522 unsigned NumArgs, SourceLocation RParenLoc);
1524 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
1525 Expr **Args, unsigned NumArgs,
1526 SourceLocation RParenLoc);
1528 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base,
1529 SourceLocation OpLoc);
1531 /// CheckCallReturnType - Checks that a call expression's return type is
1532 /// complete. Returns true on failure. The location passed in is the location
1533 /// that best represents the call.
1534 bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc,
1535 CallExpr *CE, FunctionDecl *FD);
1537 /// Helpers for dealing with blocks and functions.
1538 bool CheckParmsForFunctionDef(ParmVarDecl **Param, ParmVarDecl **ParamEnd,
1539 bool CheckParameterNames);
1540 void CheckCXXDefaultArguments(FunctionDecl *FD);
1541 void CheckExtraCXXDefaultArguments(Declarator &D);
1542 Scope *getNonFieldDeclScope(Scope *S);
1544 /// \name Name lookup
1546 /// These routines provide name lookup that is used during semantic
1547 /// analysis to resolve the various kinds of names (identifiers,
1548 /// overloaded operator names, constructor names, etc.) into zero or
1549 /// more declarations within a particular scope. The major entry
1550 /// points are LookupName, which performs unqualified name lookup,
1551 /// and LookupQualifiedName, which performs qualified name lookup.
1553 /// All name lookup is performed based on some specific criteria,
1554 /// which specify what names will be visible to name lookup and how
1555 /// far name lookup should work. These criteria are important both
1556 /// for capturing language semantics (certain lookups will ignore
1557 /// certain names, for example) and for performance, since name
1558 /// lookup is often a bottleneck in the compilation of C++. Name
1559 /// lookup criteria is specified via the LookupCriteria enumeration.
1561 /// The results of name lookup can vary based on the kind of name
1562 /// lookup performed, the current language, and the translation
1563 /// unit. In C, for example, name lookup will either return nothing
1564 /// (no entity found) or a single declaration. In C++, name lookup
1565 /// can additionally refer to a set of overloaded functions or
1566 /// result in an ambiguity. All of the possible results of name
1567 /// lookup are captured by the LookupResult class, which provides
1568 /// the ability to distinguish among them.
1571 /// @brief Describes the kind of name lookup to perform.
1572 enum LookupNameKind {
1573 /// Ordinary name lookup, which finds ordinary names (functions,
1574 /// variables, typedefs, etc.) in C and most kinds of names
1575 /// (functions, variables, members, types, etc.) in C++.
1576 LookupOrdinaryName = 0,
1577 /// Tag name lookup, which finds the names of enums, classes,
1578 /// structs, and unions.
1580 /// Label name lookup.
1582 /// Member name lookup, which finds the names of
1583 /// class/struct/union members.
1585 /// Look up of an operator name (e.g., operator+) for use with
1586 /// operator overloading. This lookup is similar to ordinary name
1587 /// lookup, but will ignore any declarations that are class members.
1589 /// Look up of a name that precedes the '::' scope resolution
1590 /// operator in C++. This lookup completely ignores operator, object,
1591 /// function, and enumerator names (C++ [basic.lookup.qual]p1).
1592 LookupNestedNameSpecifierName,
1593 /// Look up a namespace name within a C++ using directive or
1594 /// namespace alias definition, ignoring non-namespace names (C++
1595 /// [basic.lookup.udir]p1).
1596 LookupNamespaceName,
1597 /// Look up all declarations in a scope with the given name,
1598 /// including resolved using declarations. This is appropriate
1599 /// for checking redeclarations for a using declaration.
1600 LookupUsingDeclName,
1601 /// Look up an ordinary name that is going to be redeclared as a
1602 /// name with linkage. This lookup ignores any declarations that
1603 /// are outside of the current scope unless they have linkage. See
1604 /// C99 6.2.2p4-5 and C++ [basic.link]p6.
1605 LookupRedeclarationWithLinkage,
1606 /// Look up the name of an Objective-C protocol.
1607 LookupObjCProtocolName,
1608 /// Look up implicit 'self' parameter of an objective-c method.
1609 LookupObjCImplicitSelfParam,
1610 /// \brief Look up any declaration with any name.
1614 /// \brief Specifies whether (or how) name lookup is being performed for a
1615 /// redeclaration (vs. a reference).
1616 enum RedeclarationKind {
1617 /// \brief The lookup is a reference to this name that is not for the
1618 /// purpose of redeclaring the name.
1619 NotForRedeclaration = 0,
1620 /// \brief The lookup results will be used for redeclaration of a name,
1621 /// if an entity by that name already exists.
1626 bool CppLookupName(LookupResult &R, Scope *S);
1628 SpecialMemberOverloadResult *LookupSpecialMember(CXXRecordDecl *D,
1629 CXXSpecialMember SM,
1636 // \brief The set of known/encountered (unique, canonicalized) NamespaceDecls.
1638 // The boolean value will be true to indicate that the namespace was loaded
1639 // from an AST/PCH file, or false otherwise.
1640 llvm::DenseMap<NamespaceDecl*, bool> KnownNamespaces;
1642 /// \brief Whether we have already loaded known namespaces from an extenal
1644 bool LoadedExternalKnownNamespaces;
1647 /// \brief Look up a name, looking for a single declaration. Return
1648 /// null if the results were absent, ambiguous, or overloaded.
1650 /// It is preferable to use the elaborated form and explicitly handle
1651 /// ambiguity and overloaded.
1652 NamedDecl *LookupSingleName(Scope *S, DeclarationName Name,
1654 LookupNameKind NameKind,
1655 RedeclarationKind Redecl
1656 = NotForRedeclaration);
1657 bool LookupName(LookupResult &R, Scope *S,
1658 bool AllowBuiltinCreation = false);
1659 bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
1660 bool InUnqualifiedLookup = false);
1661 bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS,
1662 bool AllowBuiltinCreation = false,
1663 bool EnteringContext = false);
1664 ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc);
1666 void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
1667 QualType T1, QualType T2,
1668 UnresolvedSetImpl &Functions);
1670 LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc,
1671 SourceLocation GnuLabelLoc = SourceLocation());
1673 DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class);
1674 CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class);
1675 CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class,
1677 bool *ConstParam = 0);
1678 CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals,
1679 bool RValueThis, unsigned ThisQuals,
1680 bool *ConstParam = 0);
1681 CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class);
1683 void ArgumentDependentLookup(DeclarationName Name, bool Operator,
1684 Expr **Args, unsigned NumArgs,
1685 ADLResult &Functions,
1686 bool StdNamespaceIsAssociated = false);
1688 void LookupVisibleDecls(Scope *S, LookupNameKind Kind,
1689 VisibleDeclConsumer &Consumer,
1690 bool IncludeGlobalScope = true);
1691 void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind,
1692 VisibleDeclConsumer &Consumer,
1693 bool IncludeGlobalScope = true);
1695 /// \brief The context in which typo-correction occurs.
1697 /// The typo-correction context affects which keywords (if any) are
1698 /// considered when trying to correct for typos.
1699 enum CorrectTypoContext {
1700 /// \brief An unknown context, where any keyword might be valid.
1702 /// \brief A context where no keywords are used (e.g. we expect an actual
1705 /// \brief A context where we're correcting a type name.
1707 /// \brief An expression context.
1709 /// \brief A type cast, or anything else that can be followed by a '<'.
1711 /// \brief A member lookup context.
1713 /// \brief An Objective-C ivar lookup context (e.g., self->ivar).
1715 /// \brief An Objective-C property lookup context (e.g., self.prop).
1716 CTC_ObjCPropertyLookup,
1717 /// \brief The receiver of an Objective-C message send within an
1718 /// Objective-C method where 'super' is a valid keyword.
1719 CTC_ObjCMessageReceiver
1722 TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
1723 Sema::LookupNameKind LookupKind,
1724 Scope *S, CXXScopeSpec *SS,
1725 DeclContext *MemberContext = NULL,
1726 bool EnteringContext = false,
1727 CorrectTypoContext CTC = CTC_Unknown,
1728 const ObjCObjectPointerType *OPT = NULL);
1730 void FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs,
1731 AssociatedNamespaceSet &AssociatedNamespaces,
1732 AssociatedClassSet &AssociatedClasses);
1734 void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S,
1735 bool ConsiderLinkage,
1736 bool ExplicitInstantiationOrSpecialization);
1738 bool DiagnoseAmbiguousLookup(LookupResult &Result);
1741 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id,
1742 SourceLocation IdLoc,
1743 bool TypoCorrection = false);
1744 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
1745 Scope *S, bool ForRedeclaration,
1746 SourceLocation Loc);
1747 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
1749 void AddKnownFunctionAttributes(FunctionDecl *FD);
1751 // More parsing and symbol table subroutines.
1753 // Decl attributes - this routine is the top level dispatcher.
1754 void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD,
1755 bool NonInheritable = true, bool Inheritable = true);
1756 void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL,
1757 bool NonInheritable = true, bool Inheritable = true);
1759 bool CheckRegparmAttr(const AttributeList &attr, unsigned &value);
1760 bool CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC);
1761 bool CheckNoReturnAttr(const AttributeList &attr);
1763 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
1764 bool &IncompleteImpl, unsigned DiagID);
1765 void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod,
1766 ObjCMethodDecl *MethodDecl,
1767 bool IsProtocolMethodDecl);
1769 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl,
1770 ObjCInterfaceDecl *IDecl);
1772 typedef llvm::DenseSet<Selector, llvm::DenseMapInfo<Selector> > SelectorSet;
1774 /// CheckProtocolMethodDefs - This routine checks unimplemented
1775 /// methods declared in protocol, and those referenced by it.
1776 /// \param IDecl - Used for checking for methods which may have been
1778 void CheckProtocolMethodDefs(SourceLocation ImpLoc,
1779 ObjCProtocolDecl *PDecl,
1780 bool& IncompleteImpl,
1781 const SelectorSet &InsMap,
1782 const SelectorSet &ClsMap,
1783 ObjCContainerDecl *CDecl);
1785 /// CheckImplementationIvars - This routine checks if the instance variables
1786 /// listed in the implelementation match those listed in the interface.
1787 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
1788 ObjCIvarDecl **Fields, unsigned nIvars,
1789 SourceLocation Loc);
1791 /// \brief Determine whether we can synthesize a provisional ivar for the
1793 ObjCPropertyDecl *canSynthesizeProvisionalIvar(IdentifierInfo *II);
1795 /// \brief Determine whether we can synthesize a provisional ivar for the
1797 bool canSynthesizeProvisionalIvar(ObjCPropertyDecl *Property);
1799 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
1800 /// remains unimplemented in the class or category @implementation.
1801 void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl,
1802 ObjCContainerDecl* IDecl,
1803 bool IncompleteImpl = false);
1805 /// DiagnoseUnimplementedProperties - This routine warns on those properties
1806 /// which must be implemented by this implementation.
1807 void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl,
1808 ObjCContainerDecl *CDecl,
1809 const SelectorSet &InsMap);
1811 /// DefaultSynthesizeProperties - This routine default synthesizes all
1812 /// properties which must be synthesized in class's @implementation.
1813 void DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl,
1814 ObjCInterfaceDecl *IDecl);
1816 /// CollectImmediateProperties - This routine collects all properties in
1817 /// the class and its conforming protocols; but not those it its super class.
1818 void CollectImmediateProperties(ObjCContainerDecl *CDecl,
1819 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap,
1820 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& SuperPropMap);
1823 /// LookupPropertyDecl - Looks up a property in the current class and all
1825 ObjCPropertyDecl *LookupPropertyDecl(const ObjCContainerDecl *CDecl,
1826 IdentifierInfo *II);
1828 /// Called by ActOnProperty to handle @property declarations in
1829 //// class extensions.
1830 Decl *HandlePropertyInClassExtension(Scope *S,
1831 ObjCCategoryDecl *CDecl,
1832 SourceLocation AtLoc,
1833 FieldDeclarator &FD,
1836 const bool isAssign,
1837 const bool isReadWrite,
1838 const unsigned Attributes,
1839 bool *isOverridingProperty,
1841 tok::ObjCKeywordKind MethodImplKind);
1843 /// Called by ActOnProperty and HandlePropertyInClassExtension to
1844 /// handle creating the ObjcPropertyDecl for a category or @interface.
1845 ObjCPropertyDecl *CreatePropertyDecl(Scope *S,
1846 ObjCContainerDecl *CDecl,
1847 SourceLocation AtLoc,
1848 FieldDeclarator &FD,
1851 const bool isAssign,
1852 const bool isReadWrite,
1853 const unsigned Attributes,
1855 tok::ObjCKeywordKind MethodImplKind,
1856 DeclContext *lexicalDC = 0);
1858 /// AtomicPropertySetterGetterRules - This routine enforces the rule (via
1859 /// warning) when atomic property has one but not the other user-declared
1860 /// setter or getter.
1861 void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl,
1862 ObjCContainerDecl* IDecl);
1864 void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D);
1866 void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID);
1868 enum MethodMatchStrategy {
1873 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
1874 /// true, or false, accordingly.
1875 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
1876 const ObjCMethodDecl *PrevMethod,
1877 MethodMatchStrategy strategy = MMS_strict);
1879 /// MatchAllMethodDeclarations - Check methods declaraed in interface or
1880 /// or protocol against those declared in their implementations.
1881 void MatchAllMethodDeclarations(const SelectorSet &InsMap,
1882 const SelectorSet &ClsMap,
1883 SelectorSet &InsMapSeen,
1884 SelectorSet &ClsMapSeen,
1885 ObjCImplDecl* IMPDecl,
1886 ObjCContainerDecl* IDecl,
1887 bool &IncompleteImpl,
1888 bool ImmediateClass);
1891 /// AddMethodToGlobalPool - Add an instance or factory method to the global
1892 /// pool. See descriptoin of AddInstanceMethodToGlobalPool.
1893 void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance);
1895 /// LookupMethodInGlobalPool - Returns the instance or factory method and
1896 /// optionally warns if there are multiple signatures.
1897 ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R,
1898 bool receiverIdOrClass,
1899 bool warn, bool instance);
1902 /// AddInstanceMethodToGlobalPool - All instance methods in a translation
1903 /// unit are added to a global pool. This allows us to efficiently associate
1904 /// a selector with a method declaraation for purposes of typechecking
1905 /// messages sent to "id" (where the class of the object is unknown).
1906 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
1907 AddMethodToGlobalPool(Method, impl, /*instance*/true);
1910 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
1911 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
1912 AddMethodToGlobalPool(Method, impl, /*instance*/false);
1915 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
1916 /// there are multiple signatures.
1917 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R,
1918 bool receiverIdOrClass=false,
1920 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
1921 warn, /*instance*/true);
1924 /// LookupFactoryMethodInGlobalPool - Returns the method and warns if
1925 /// there are multiple signatures.
1926 ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R,
1927 bool receiverIdOrClass=false,
1929 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
1930 warn, /*instance*/false);
1933 /// LookupImplementedMethodInGlobalPool - Returns the method which has an
1935 ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel);
1937 /// CollectIvarsToConstructOrDestruct - Collect those ivars which require
1939 void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI,
1940 llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
1942 //===--------------------------------------------------------------------===//
1943 // Statement Parsing Callbacks: SemaStmt.cpp.
1947 FullExprArg(Sema &actions) : E(0) { }
1949 // FIXME: The const_cast here is ugly. RValue references would make this
1950 // much nicer (or we could duplicate a bunch of the move semantics
1951 // emulation code from Ownership.h).
1952 FullExprArg(const FullExprArg& Other) : E(Other.E) {}
1954 ExprResult release() {
1958 Expr *get() const { return E; }
1960 Expr *operator->() {
1965 // FIXME: No need to make the entire Sema class a friend when it's just
1966 // Sema::MakeFullExpr that needs access to the constructor below.
1969 explicit FullExprArg(Expr *expr) : E(expr) {}
1974 FullExprArg MakeFullExpr(Expr *Arg) {
1975 return FullExprArg(ActOnFinishFullExpr(Arg).release());
1978 StmtResult ActOnExprStmt(FullExprArg Expr);
1980 StmtResult ActOnNullStmt(SourceLocation SemiLoc,
1981 SourceLocation LeadingEmptyMacroLoc = SourceLocation());
1982 StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
1985 StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl,
1986 SourceLocation StartLoc,
1987 SourceLocation EndLoc);
1988 void ActOnForEachDeclStmt(DeclGroupPtrTy Decl);
1989 StmtResult ActOnForEachLValueExpr(Expr *E);
1990 StmtResult ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal,
1991 SourceLocation DotDotDotLoc, Expr *RHSVal,
1992 SourceLocation ColonLoc);
1993 void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt);
1995 StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
1996 SourceLocation ColonLoc,
1997 Stmt *SubStmt, Scope *CurScope);
1998 StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl,
1999 SourceLocation ColonLoc, Stmt *SubStmt);
2001 StmtResult ActOnIfStmt(SourceLocation IfLoc,
2002 FullExprArg CondVal, Decl *CondVar,
2004 SourceLocation ElseLoc, Stmt *ElseVal);
2005 StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc,
2008 StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
2009 Stmt *Switch, Stmt *Body);
2010 StmtResult ActOnWhileStmt(SourceLocation WhileLoc,
2012 Decl *CondVar, Stmt *Body);
2013 StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body,
2014 SourceLocation WhileLoc,
2015 SourceLocation CondLParen, Expr *Cond,
2016 SourceLocation CondRParen);
2018 StmtResult ActOnForStmt(SourceLocation ForLoc,
2019 SourceLocation LParenLoc,
2020 Stmt *First, FullExprArg Second,
2023 SourceLocation RParenLoc,
2025 StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
2026 SourceLocation LParenLoc,
2027 Stmt *First, Expr *Second,
2028 SourceLocation RParenLoc, Stmt *Body);
2029 StmtResult ActOnCXXForRangeStmt(SourceLocation ForLoc,
2030 SourceLocation LParenLoc, Stmt *LoopVar,
2031 SourceLocation ColonLoc, Expr *Collection,
2032 SourceLocation RParenLoc);
2033 StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc,
2034 SourceLocation ColonLoc,
2035 Stmt *RangeDecl, Stmt *BeginEndDecl,
2036 Expr *Cond, Expr *Inc,
2038 SourceLocation RParenLoc);
2039 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body);
2041 StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
2042 SourceLocation LabelLoc,
2043 LabelDecl *TheDecl);
2044 StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
2045 SourceLocation StarLoc,
2047 StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope);
2048 StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
2050 const VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E,
2051 bool AllowFunctionParameters);
2053 StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
2054 StmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
2056 StmtResult ActOnAsmStmt(SourceLocation AsmLoc,
2057 bool IsSimple, bool IsVolatile,
2058 unsigned NumOutputs, unsigned NumInputs,
2059 IdentifierInfo **Names,
2060 MultiExprArg Constraints,
2063 MultiExprArg Clobbers,
2064 SourceLocation RParenLoc,
2065 bool MSAsm = false);
2068 VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType,
2069 SourceLocation StartLoc,
2070 SourceLocation IdLoc, IdentifierInfo *Id,
2071 bool Invalid = false);
2073 Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D);
2075 StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen,
2076 Decl *Parm, Stmt *Body);
2078 StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body);
2080 StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try,
2081 MultiStmtArg Catch, Stmt *Finally);
2083 StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw);
2084 StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw,
2086 StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
2090 StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body);
2092 VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo,
2093 SourceLocation StartLoc,
2094 SourceLocation IdLoc,
2095 IdentifierInfo *Id);
2097 Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D);
2099 StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
2100 Decl *ExDecl, Stmt *HandlerBlock);
2101 StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
2102 MultiStmtArg Handlers);
2104 StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ?
2105 SourceLocation TryLoc,
2109 StmtResult ActOnSEHExceptBlock(SourceLocation Loc,
2113 StmtResult ActOnSEHFinallyBlock(SourceLocation Loc,
2116 void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock);
2118 bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const;
2120 /// \brief If it's a file scoped decl that must warn if not used, keep track
2122 void MarkUnusedFileScopedDecl(const DeclaratorDecl *D);
2124 /// DiagnoseUnusedExprResult - If the statement passed in is an expression
2125 /// whose result is unused, warn.
2126 void DiagnoseUnusedExprResult(const Stmt *S);
2127 void DiagnoseUnusedDecl(const NamedDecl *ND);
2129 ParsingDeclState PushParsingDeclaration() {
2130 return DelayedDiagnostics.pushParsingDecl();
2132 void PopParsingDeclaration(ParsingDeclState state, Decl *decl) {
2133 DelayedDiagnostics::popParsingDecl(*this, state, decl);
2136 typedef ProcessingContextState ParsingClassState;
2137 ParsingClassState PushParsingClass() {
2138 return DelayedDiagnostics.pushContext();
2140 void PopParsingClass(ParsingClassState state) {
2141 DelayedDiagnostics.popContext(state);
2144 void EmitDeprecationWarning(NamedDecl *D, llvm::StringRef Message,
2146 const ObjCInterfaceDecl *UnknownObjCClass=0);
2148 void HandleDelayedDeprecationCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
2150 bool makeUnavailableInSystemHeader(SourceLocation loc,
2151 llvm::StringRef message);
2153 //===--------------------------------------------------------------------===//
2154 // Expression Parsing Callbacks: SemaExpr.cpp.
2156 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
2157 const ObjCInterfaceDecl *UnknownObjCClass=0);
2158 std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD);
2159 bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
2160 ObjCMethodDecl *Getter,
2161 SourceLocation Loc);
2162 void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
2163 Expr **Args, unsigned NumArgs);
2165 void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext);
2167 void PopExpressionEvaluationContext();
2169 void DiscardCleanupsInEvaluationContext();
2171 void MarkDeclarationReferenced(SourceLocation Loc, Decl *D);
2172 void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T);
2173 void MarkDeclarationsReferencedInExpr(Expr *E);
2175 /// \brief Figure out if an expression could be turned into a call.
2176 bool isExprCallable(const Expr &E, QualType &ZeroArgCallReturnTy,
2177 UnresolvedSetImpl &NonTemplateOverloads);
2178 /// \brief Give notes for a set of overloads.
2179 void NoteOverloads(const UnresolvedSetImpl &Overloads,
2180 const SourceLocation FinalNoteLoc);
2182 /// \brief Conditionally issue a diagnostic based on the current
2183 /// evaluation context.
2185 /// \param stmt - If stmt is non-null, delay reporting the diagnostic until
2186 /// the function body is parsed, and then do a basic reachability analysis to
2187 /// determine if the statement is reachable. If it is unreachable, the
2188 /// diagnostic will not be emitted.
2189 bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *stmt,
2190 const PartialDiagnostic &PD);
2192 // Primary Expressions.
2193 SourceRange getExprRange(Expr *E) const;
2195 ObjCIvarDecl *SynthesizeProvisionalIvar(LookupResult &Lookup,
2197 SourceLocation NameLoc);
2199 ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, UnqualifiedId &Name,
2200 bool HasTrailingLParen, bool IsAddressOfOperand);
2202 void DecomposeUnqualifiedId(const UnqualifiedId &Id,
2203 TemplateArgumentListInfo &Buffer,
2204 DeclarationNameInfo &NameInfo,
2205 const TemplateArgumentListInfo *&TemplateArgs);
2207 bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
2208 CorrectTypoContext CTC = CTC_Unknown);
2210 ExprResult LookupInObjCMethod(LookupResult &R, Scope *S, IdentifierInfo *II,
2211 bool AllowBuiltinCreation=false);
2213 ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS,
2214 const DeclarationNameInfo &NameInfo,
2215 bool isAddressOfOperand,
2216 const TemplateArgumentListInfo *TemplateArgs);
2218 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
2221 const CXXScopeSpec *SS = 0);
2222 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
2224 const DeclarationNameInfo &NameInfo,
2225 const CXXScopeSpec *SS = 0);
2227 BuildAnonymousStructUnionMemberReference(const CXXScopeSpec &SS,
2228 SourceLocation nameLoc,
2229 IndirectFieldDecl *indirectField,
2230 Expr *baseObjectExpr = 0,
2231 SourceLocation opLoc = SourceLocation());
2232 ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
2234 const TemplateArgumentListInfo *TemplateArgs);
2235 ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS,
2237 const TemplateArgumentListInfo *TemplateArgs,
2238 bool IsDefiniteInstance);
2239 bool UseArgumentDependentLookup(const CXXScopeSpec &SS,
2240 const LookupResult &R,
2241 bool HasTrailingLParen);
2243 ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS,
2244 const DeclarationNameInfo &NameInfo);
2245 ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
2246 const DeclarationNameInfo &NameInfo,
2247 const TemplateArgumentListInfo *TemplateArgs);
2249 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
2252 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
2253 const DeclarationNameInfo &NameInfo,
2256 ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
2257 ExprResult ActOnNumericConstant(const Token &);
2258 ExprResult ActOnCharacterConstant(const Token &);
2259 ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *Val);
2260 ExprResult ActOnParenOrParenListExpr(SourceLocation L,
2264 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
2265 /// fragments (e.g. "foo" "bar" L"baz").
2266 ExprResult ActOnStringLiteral(const Token *Toks, unsigned NumToks);
2268 ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc,
2269 SourceLocation DefaultLoc,
2270 SourceLocation RParenLoc,
2271 Expr *ControllingExpr,
2273 MultiExprArg Exprs);
2274 ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc,
2275 SourceLocation DefaultLoc,
2276 SourceLocation RParenLoc,
2277 Expr *ControllingExpr,
2278 TypeSourceInfo **Types,
2280 unsigned NumAssocs);
2282 // Binary/Unary Operators. 'Tok' is the token for the operator.
2283 ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc,
2285 ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc,
2286 UnaryOperatorKind Opc, Expr *input);
2287 ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
2288 tok::TokenKind Op, Expr *Input);
2290 ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *T,
2291 SourceLocation OpLoc,
2292 UnaryExprOrTypeTrait ExprKind,
2294 ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc,
2295 UnaryExprOrTypeTrait ExprKind);
2297 ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc,
2298 UnaryExprOrTypeTrait ExprKind,
2299 bool isType, void *TyOrEx,
2300 const SourceRange &ArgRange);
2302 ExprResult CheckPlaceholderExpr(Expr *E);
2303 bool CheckVecStepExpr(Expr *E);
2305 bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind);
2306 bool CheckUnaryExprOrTypeTraitOperand(QualType type, SourceLocation OpLoc,
2308 UnaryExprOrTypeTrait ExprKind);
2309 ExprResult ActOnSizeofParameterPackExpr(Scope *S,
2310 SourceLocation OpLoc,
2311 IdentifierInfo &Name,
2312 SourceLocation NameLoc,
2313 SourceLocation RParenLoc);
2314 ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
2315 tok::TokenKind Kind, Expr *Input);
2317 ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc,
2318 Expr *Idx, SourceLocation RLoc);
2319 ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc,
2320 Expr *Idx, SourceLocation RLoc);
2322 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
2323 SourceLocation OpLoc, bool IsArrow,
2325 NamedDecl *FirstQualifierInScope,
2326 const DeclarationNameInfo &NameInfo,
2327 const TemplateArgumentListInfo *TemplateArgs);
2329 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
2330 SourceLocation OpLoc, bool IsArrow,
2331 const CXXScopeSpec &SS,
2332 NamedDecl *FirstQualifierInScope,
2334 const TemplateArgumentListInfo *TemplateArgs,
2335 bool SuppressQualifierCheck = false);
2337 ExprResult LookupMemberExpr(LookupResult &R, ExprResult &Base,
2338 bool &IsArrow, SourceLocation OpLoc,
2341 bool HasTemplateArgs);
2343 bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType,
2344 const CXXScopeSpec &SS,
2345 const LookupResult &R);
2347 ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType,
2348 bool IsArrow, SourceLocation OpLoc,
2349 const CXXScopeSpec &SS,
2350 NamedDecl *FirstQualifierInScope,
2351 const DeclarationNameInfo &NameInfo,
2352 const TemplateArgumentListInfo *TemplateArgs);
2354 ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base,
2355 SourceLocation OpLoc,
2356 tok::TokenKind OpKind,
2358 UnqualifiedId &Member,
2360 bool HasTrailingLParen);
2362 void ActOnDefaultCtorInitializers(Decl *CDtorDecl);
2363 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
2364 FunctionDecl *FDecl,
2365 const FunctionProtoType *Proto,
2366 Expr **Args, unsigned NumArgs,
2367 SourceLocation RParenLoc);
2369 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
2370 /// This provides the location of the left/right parens and a list of comma
2372 ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc,
2373 MultiExprArg Args, SourceLocation RParenLoc,
2374 Expr *ExecConfig = 0);
2375 ExprResult BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl,
2376 SourceLocation LParenLoc,
2377 Expr **Args, unsigned NumArgs,
2378 SourceLocation RParenLoc,
2379 Expr *ExecConfig = 0);
2381 ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc,
2382 MultiExprArg ExecConfig, SourceLocation GGGLoc);
2384 ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc,
2385 Declarator &D, ParsedType &Ty,
2386 SourceLocation RParenLoc, Expr *Op);
2387 ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc,
2389 SourceLocation RParenLoc,
2392 /// \brief Build an altivec or OpenCL literal.
2393 ExprResult BuildVectorLiteral(SourceLocation LParenLoc,
2394 SourceLocation RParenLoc, Expr *E,
2395 TypeSourceInfo *TInfo);
2397 ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME);
2399 ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
2401 SourceLocation RParenLoc,
2404 ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc,
2405 TypeSourceInfo *TInfo,
2406 SourceLocation RParenLoc,
2409 ExprResult ActOnInitList(SourceLocation LParenLoc,
2410 MultiExprArg InitList,
2411 SourceLocation RParenLoc);
2413 ExprResult ActOnDesignatedInitializer(Designation &Desig,
2418 ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
2419 tok::TokenKind Kind, Expr *LHS, Expr *RHS);
2420 ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc,
2421 BinaryOperatorKind Opc, Expr *lhs, Expr *rhs);
2422 ExprResult CreateBuiltinBinOp(SourceLocation TokLoc,
2423 BinaryOperatorKind Opc, Expr *lhs, Expr *rhs);
2425 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
2426 /// in the case of a the GNU conditional expr extension.
2427 ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
2428 SourceLocation ColonLoc,
2429 Expr *Cond, Expr *LHS, Expr *RHS);
2431 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
2432 ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
2435 ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt,
2436 SourceLocation RPLoc); // "({..})"
2438 // __builtin_offsetof(type, identifier(.identifier|[expr])*)
2439 struct OffsetOfComponent {
2440 SourceLocation LocStart, LocEnd;
2441 bool isBrackets; // true if [expr], false if .ident
2443 IdentifierInfo *IdentInfo;
2448 /// __builtin_offsetof(type, a.b[123][456].c)
2449 ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc,
2450 TypeSourceInfo *TInfo,
2451 OffsetOfComponent *CompPtr,
2452 unsigned NumComponents,
2453 SourceLocation RParenLoc);
2454 ExprResult ActOnBuiltinOffsetOf(Scope *S,
2455 SourceLocation BuiltinLoc,
2456 SourceLocation TypeLoc,
2458 OffsetOfComponent *CompPtr,
2459 unsigned NumComponents,
2460 SourceLocation RParenLoc);
2462 // __builtin_choose_expr(constExpr, expr1, expr2)
2463 ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
2464 Expr *cond, Expr *expr1,
2465 Expr *expr2, SourceLocation RPLoc);
2467 // __builtin_va_arg(expr, type)
2468 ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
2469 Expr *expr, ParsedType type,
2470 SourceLocation RPLoc);
2471 ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc,
2472 Expr *expr, TypeSourceInfo *TInfo,
2473 SourceLocation RPLoc);
2476 ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
2478 bool CheckCaseExpression(Expr *expr);
2480 bool CheckMicrosoftIfExistsSymbol(CXXScopeSpec &SS, UnqualifiedId &Name);
2482 //===------------------------- "Block" Extension ------------------------===//
2484 /// ActOnBlockStart - This callback is invoked when a block literal is
2486 void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
2488 /// ActOnBlockArguments - This callback allows processing of block arguments.
2489 /// If there are no arguments, this is still invoked.
2490 void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope);
2492 /// ActOnBlockError - If there is an error parsing a block, this callback
2493 /// is invoked to pop the information about the block from the action impl.
2494 void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
2496 /// ActOnBlockStmtExpr - This is called when the body of a block statement
2497 /// literal was successfully completed. ^(int x){...}
2498 ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc,
2499 Stmt *Body, Scope *CurScope);
2501 //===---------------------------- OpenCL Features -----------------------===//
2503 /// __builtin_astype(...)
2504 ExprResult ActOnAsTypeExpr(Expr *expr, ParsedType DestTy,
2505 SourceLocation BuiltinLoc,
2506 SourceLocation RParenLoc);
2508 //===---------------------------- C++ Features --------------------------===//
2510 // Act on C++ namespaces
2511 Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc,
2512 SourceLocation NamespaceLoc,
2513 SourceLocation IdentLoc,
2514 IdentifierInfo *Ident,
2515 SourceLocation LBrace,
2516 AttributeList *AttrList);
2517 void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace);
2519 NamespaceDecl *getStdNamespace() const;
2520 NamespaceDecl *getOrCreateStdNamespace();
2522 CXXRecordDecl *getStdBadAlloc() const;
2524 Decl *ActOnUsingDirective(Scope *CurScope,
2525 SourceLocation UsingLoc,
2526 SourceLocation NamespcLoc,
2528 SourceLocation IdentLoc,
2529 IdentifierInfo *NamespcName,
2530 AttributeList *AttrList);
2532 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
2534 Decl *ActOnNamespaceAliasDef(Scope *CurScope,
2535 SourceLocation NamespaceLoc,
2536 SourceLocation AliasLoc,
2537 IdentifierInfo *Alias,
2539 SourceLocation IdentLoc,
2540 IdentifierInfo *Ident);
2542 void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow);
2543 bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target,
2544 const LookupResult &PreviousDecls);
2545 UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD,
2548 bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc,
2550 const CXXScopeSpec &SS,
2551 SourceLocation NameLoc,
2552 const LookupResult &Previous);
2553 bool CheckUsingDeclQualifier(SourceLocation UsingLoc,
2554 const CXXScopeSpec &SS,
2555 SourceLocation NameLoc);
2557 NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS,
2558 SourceLocation UsingLoc,
2560 const DeclarationNameInfo &NameInfo,
2561 AttributeList *AttrList,
2562 bool IsInstantiation,
2564 SourceLocation TypenameLoc);
2566 bool CheckInheritedConstructorUsingDecl(UsingDecl *UD);
2568 Decl *ActOnUsingDeclaration(Scope *CurScope,
2570 bool HasUsingKeyword,
2571 SourceLocation UsingLoc,
2573 UnqualifiedId &Name,
2574 AttributeList *AttrList,
2576 SourceLocation TypenameLoc);
2577 Decl *ActOnAliasDeclaration(Scope *CurScope,
2579 MultiTemplateParamsArg TemplateParams,
2580 SourceLocation UsingLoc,
2581 UnqualifiedId &Name,
2584 /// AddCXXDirectInitializerToDecl - This action is called immediately after
2585 /// ActOnDeclarator, when a C++ direct initializer is present.
2586 /// e.g: "int x(1);"
2587 void AddCXXDirectInitializerToDecl(Decl *Dcl,
2588 SourceLocation LParenLoc,
2590 SourceLocation RParenLoc,
2591 bool TypeMayContainAuto);
2593 /// InitializeVarWithConstructor - Creates an CXXConstructExpr
2594 /// and sets it as the initializer for the the passed in VarDecl.
2595 bool InitializeVarWithConstructor(VarDecl *VD,
2596 CXXConstructorDecl *Constructor,
2597 MultiExprArg Exprs);
2599 /// BuildCXXConstructExpr - Creates a complete call to a constructor,
2600 /// including handling of its default argument expressions.
2602 /// \param ConstructKind - a CXXConstructExpr::ConstructionKind
2604 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
2605 CXXConstructorDecl *Constructor, MultiExprArg Exprs,
2606 bool RequiresZeroInit, unsigned ConstructKind,
2607 SourceRange ParenRange);
2609 // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if
2610 // the constructor can be elidable?
2612 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
2613 CXXConstructorDecl *Constructor, bool Elidable,
2614 MultiExprArg Exprs, bool RequiresZeroInit,
2615 unsigned ConstructKind,
2616 SourceRange ParenRange);
2618 /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating
2619 /// the default expr if needed.
2620 ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc,
2622 ParmVarDecl *Param);
2624 /// FinalizeVarWithDestructor - Prepare for calling destructor on the
2625 /// constructed variable.
2626 void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType);
2628 /// \brief Helper class that collects exception specifications for
2629 /// implicitly-declared special member functions.
2630 class ImplicitExceptionSpecification {
2631 // Pointer to allow copying
2632 ASTContext *Context;
2633 // We order exception specifications thus:
2634 // noexcept is the most restrictive, but is only used in C++0x.
2635 // throw() comes next.
2636 // Then a throw(collected exceptions)
2637 // Finally no specification.
2638 // throw(...) is used instead if any called function uses it.
2640 // If this exception specification cannot be known yet (for instance,
2641 // because this is the exception specification for a defaulted default
2642 // constructor and we haven't finished parsing the deferred parts of the
2643 // class yet), the C++0x standard does not specify how to behave. We
2644 // record this as an 'unknown' exception specification, which overrules
2645 // any other specification (even 'none', to keep this rule simple).
2646 ExceptionSpecificationType ComputedEST;
2647 llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen;
2648 llvm::SmallVector<QualType, 4> Exceptions;
2650 void ClearExceptions() {
2651 ExceptionsSeen.clear();
2656 explicit ImplicitExceptionSpecification(ASTContext &Context)
2657 : Context(&Context), ComputedEST(EST_BasicNoexcept) {
2658 if (!Context.getLangOptions().CPlusPlus0x)
2659 ComputedEST = EST_DynamicNone;
2662 /// \brief Get the computed exception specification type.
2663 ExceptionSpecificationType getExceptionSpecType() const {
2664 assert(ComputedEST != EST_ComputedNoexcept &&
2665 "noexcept(expr) should not be a possible result");
2669 /// \brief The number of exceptions in the exception specification.
2670 unsigned size() const { return Exceptions.size(); }
2672 /// \brief The set of exceptions in the exception specification.
2673 const QualType *data() const { return Exceptions.data(); }
2675 /// \brief Integrate another called method into the collected data.
2676 void CalledDecl(CXXMethodDecl *Method);
2678 /// \brief Integrate an invoked expression into the collected data.
2679 void CalledExpr(Expr *E);
2681 /// \brief Specify that the exception specification can't be detemined yet.
2684 ComputedEST = EST_Delayed;
2687 FunctionProtoType::ExtProtoInfo getEPI() const {
2688 FunctionProtoType::ExtProtoInfo EPI;
2689 EPI.ExceptionSpecType = getExceptionSpecType();
2690 EPI.NumExceptions = size();
2691 EPI.Exceptions = data();
2696 /// \brief Determine what sort of exception specification a defaulted
2697 /// copy constructor of a class will have.
2698 ImplicitExceptionSpecification
2699 ComputeDefaultedDefaultCtorExceptionSpec(CXXRecordDecl *ClassDecl);
2701 /// \brief Determine what sort of exception specification a defaulted
2702 /// default constructor of a class will have, and whether the parameter
2704 std::pair<ImplicitExceptionSpecification, bool>
2705 ComputeDefaultedCopyCtorExceptionSpecAndConst(CXXRecordDecl *ClassDecl);
2707 /// \brief Determine what sort of exception specification a defautled
2708 /// copy assignment operator of a class will have, and whether the
2709 /// parameter will be const.
2710 std::pair<ImplicitExceptionSpecification, bool>
2711 ComputeDefaultedCopyAssignmentExceptionSpecAndConst(CXXRecordDecl *ClassDecl);
2713 /// \brief Determine what sort of exception specification a defaulted
2714 /// destructor of a class will have.
2715 ImplicitExceptionSpecification
2716 ComputeDefaultedDtorExceptionSpec(CXXRecordDecl *ClassDecl);
2718 /// \brief Determine if a defaulted default constructor ought to be
2720 bool ShouldDeleteDefaultConstructor(CXXConstructorDecl *CD);
2722 /// \brief Determine if a defaulted copy constructor ought to be
2724 bool ShouldDeleteCopyConstructor(CXXConstructorDecl *CD);
2726 /// \brief Determine if a defaulted copy assignment operator ought to be
2728 bool ShouldDeleteCopyAssignmentOperator(CXXMethodDecl *MD);
2730 /// \brief Determine if a defaulted destructor ought to be deleted.
2731 bool ShouldDeleteDestructor(CXXDestructorDecl *DD);
2733 /// \brief Declare the implicit default constructor for the given class.
2735 /// \param ClassDecl The class declaration into which the implicit
2736 /// default constructor will be added.
2738 /// \returns The implicitly-declared default constructor.
2739 CXXConstructorDecl *DeclareImplicitDefaultConstructor(
2740 CXXRecordDecl *ClassDecl);
2742 /// DefineImplicitDefaultConstructor - Checks for feasibility of
2743 /// defining this constructor as the default constructor.
2744 void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
2745 CXXConstructorDecl *Constructor);
2747 /// \brief Declare the implicit destructor for the given class.
2749 /// \param ClassDecl The class declaration into which the implicit
2750 /// destructor will be added.
2752 /// \returns The implicitly-declared destructor.
2753 CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl);
2755 /// DefineImplicitDestructor - Checks for feasibility of
2756 /// defining this destructor as the default destructor.
2757 void DefineImplicitDestructor(SourceLocation CurrentLocation,
2758 CXXDestructorDecl *Destructor);
2760 /// \brief Build an exception spec for destructors that don't have one.
2762 /// C++11 says that user-defined destructors with no exception spec get one
2763 /// that looks as if the destructor was implicitly declared.
2764 void AdjustDestructorExceptionSpec(CXXRecordDecl *ClassDecl,
2765 CXXDestructorDecl *Destructor);
2767 /// \brief Declare all inherited constructors for the given class.
2769 /// \param ClassDecl The class declaration into which the inherited
2770 /// constructors will be added.
2771 void DeclareInheritedConstructors(CXXRecordDecl *ClassDecl);
2773 /// \brief Declare the implicit copy constructor for the given class.
2775 /// \param S The scope of the class, which may be NULL if this is a
2776 /// template instantiation.
2778 /// \param ClassDecl The class declaration into which the implicit
2779 /// copy constructor will be added.
2781 /// \returns The implicitly-declared copy constructor.
2782 CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl);
2784 /// DefineImplicitCopyConstructor - Checks for feasibility of
2785 /// defining this constructor as the copy constructor.
2786 void DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
2787 CXXConstructorDecl *Constructor);
2789 /// \brief Declare the implicit copy assignment operator for the given class.
2791 /// \param S The scope of the class, which may be NULL if this is a
2792 /// template instantiation.
2794 /// \param ClassDecl The class declaration into which the implicit
2795 /// copy-assignment operator will be added.
2797 /// \returns The implicitly-declared copy assignment operator.
2798 CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl);
2800 /// \brief Defined an implicitly-declared copy assignment operator.
2801 void DefineImplicitCopyAssignment(SourceLocation CurrentLocation,
2802 CXXMethodDecl *MethodDecl);
2804 /// \brief Force the declaration of any implicitly-declared members of this
2806 void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class);
2808 /// MaybeBindToTemporary - If the passed in expression has a record type with
2809 /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise
2810 /// it simply returns the passed in expression.
2811 ExprResult MaybeBindToTemporary(Expr *E);
2813 bool CompleteConstructorCall(CXXConstructorDecl *Constructor,
2814 MultiExprArg ArgsPtr,
2816 ASTOwningVector<Expr*> &ConvertedArgs);
2818 ParsedType getDestructorName(SourceLocation TildeLoc,
2819 IdentifierInfo &II, SourceLocation NameLoc,
2820 Scope *S, CXXScopeSpec &SS,
2821 ParsedType ObjectType,
2822 bool EnteringContext);
2824 // Checks that reinterpret casts don't have undefined behavior.
2825 void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType,
2826 bool IsDereference, SourceRange Range);
2828 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
2829 ExprResult ActOnCXXNamedCast(SourceLocation OpLoc,
2830 tok::TokenKind Kind,
2831 SourceLocation LAngleBracketLoc,
2833 SourceLocation RAngleBracketLoc,
2834 SourceLocation LParenLoc,
2836 SourceLocation RParenLoc);
2838 ExprResult BuildCXXNamedCast(SourceLocation OpLoc,
2839 tok::TokenKind Kind,
2842 SourceRange AngleBrackets,
2843 SourceRange Parens);
2845 ExprResult BuildCXXTypeId(QualType TypeInfoType,
2846 SourceLocation TypeidLoc,
2847 TypeSourceInfo *Operand,
2848 SourceLocation RParenLoc);
2849 ExprResult BuildCXXTypeId(QualType TypeInfoType,
2850 SourceLocation TypeidLoc,
2852 SourceLocation RParenLoc);
2854 /// ActOnCXXTypeid - Parse typeid( something ).
2855 ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
2856 SourceLocation LParenLoc, bool isType,
2858 SourceLocation RParenLoc);
2860 ExprResult BuildCXXUuidof(QualType TypeInfoType,
2861 SourceLocation TypeidLoc,
2862 TypeSourceInfo *Operand,
2863 SourceLocation RParenLoc);
2864 ExprResult BuildCXXUuidof(QualType TypeInfoType,
2865 SourceLocation TypeidLoc,
2867 SourceLocation RParenLoc);
2869 /// ActOnCXXUuidof - Parse __uuidof( something ).
2870 ExprResult ActOnCXXUuidof(SourceLocation OpLoc,
2871 SourceLocation LParenLoc, bool isType,
2873 SourceLocation RParenLoc);
2876 //// ActOnCXXThis - Parse 'this' pointer.
2877 ExprResult ActOnCXXThis(SourceLocation loc);
2879 /// getAndCaptureCurrentThisType - Try to capture a 'this' pointer. Returns
2880 /// the type of the 'this' pointer, or a null type if this is not possible.
2881 QualType getAndCaptureCurrentThisType();
2883 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
2884 ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
2886 /// ActOnCXXNullPtrLiteral - Parse 'nullptr'.
2887 ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc);
2889 //// ActOnCXXThrow - Parse throw expressions.
2890 ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr);
2891 ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex,
2892 bool IsThrownVarInScope);
2893 ExprResult CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *E,
2894 bool IsThrownVarInScope);
2896 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
2897 /// Can be interpreted either as function-style casting ("int(x)")
2898 /// or class type construction ("ClassType(x,y,z)")
2899 /// or creation of a value-initialized type ("int()").
2900 ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep,
2901 SourceLocation LParenLoc,
2903 SourceLocation RParenLoc);
2905 ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type,
2906 SourceLocation LParenLoc,
2908 SourceLocation RParenLoc);
2910 /// ActOnCXXNew - Parsed a C++ 'new' expression.
2911 ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
2912 SourceLocation PlacementLParen,
2913 MultiExprArg PlacementArgs,
2914 SourceLocation PlacementRParen,
2915 SourceRange TypeIdParens, Declarator &D,
2916 SourceLocation ConstructorLParen,
2917 MultiExprArg ConstructorArgs,
2918 SourceLocation ConstructorRParen);
2919 ExprResult BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
2920 SourceLocation PlacementLParen,
2921 MultiExprArg PlacementArgs,
2922 SourceLocation PlacementRParen,
2923 SourceRange TypeIdParens,
2925 TypeSourceInfo *AllocTypeInfo,
2927 SourceLocation ConstructorLParen,
2928 MultiExprArg ConstructorArgs,
2929 SourceLocation ConstructorRParen,
2930 bool TypeMayContainAuto = true);
2932 bool CheckAllocatedType(QualType AllocType, SourceLocation Loc,
2934 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
2935 bool UseGlobal, QualType AllocType, bool IsArray,
2936 Expr **PlaceArgs, unsigned NumPlaceArgs,
2937 FunctionDecl *&OperatorNew,
2938 FunctionDecl *&OperatorDelete);
2939 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
2940 DeclarationName Name, Expr** Args,
2941 unsigned NumArgs, DeclContext *Ctx,
2942 bool AllowMissing, FunctionDecl *&Operator,
2943 bool Diagnose = true);
2944 void DeclareGlobalNewDelete();
2945 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
2947 bool addMallocAttr = false);
2949 bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD,
2950 DeclarationName Name, FunctionDecl* &Operator,
2951 bool Diagnose = true);
2953 /// ActOnCXXDelete - Parsed a C++ 'delete' expression
2954 ExprResult ActOnCXXDelete(SourceLocation StartLoc,
2955 bool UseGlobal, bool ArrayForm,
2958 DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D);
2959 ExprResult CheckConditionVariable(VarDecl *ConditionVar,
2960 SourceLocation StmtLoc,
2961 bool ConvertToBoolean);
2963 ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen,
2964 Expr *Operand, SourceLocation RParen);
2965 ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand,
2966 SourceLocation RParen);
2968 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
2969 /// pseudo-functions.
2970 ExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
2971 SourceLocation KWLoc,
2973 SourceLocation RParen);
2975 ExprResult BuildUnaryTypeTrait(UnaryTypeTrait OTT,
2976 SourceLocation KWLoc,
2978 SourceLocation RParen);
2980 /// ActOnBinaryTypeTrait - Parsed one of the bianry type trait support
2981 /// pseudo-functions.
2982 ExprResult ActOnBinaryTypeTrait(BinaryTypeTrait OTT,
2983 SourceLocation KWLoc,
2986 SourceLocation RParen);
2988 ExprResult BuildBinaryTypeTrait(BinaryTypeTrait BTT,
2989 SourceLocation KWLoc,
2990 TypeSourceInfo *LhsT,
2991 TypeSourceInfo *RhsT,
2992 SourceLocation RParen);
2994 /// ActOnArrayTypeTrait - Parsed one of the bianry type trait support
2995 /// pseudo-functions.
2996 ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT,
2997 SourceLocation KWLoc,
3000 SourceLocation RParen);
3002 ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT,
3003 SourceLocation KWLoc,
3004 TypeSourceInfo *TSInfo,
3006 SourceLocation RParen);
3008 /// ActOnExpressionTrait - Parsed one of the unary type trait support
3009 /// pseudo-functions.
3010 ExprResult ActOnExpressionTrait(ExpressionTrait OET,
3011 SourceLocation KWLoc,
3013 SourceLocation RParen);
3015 ExprResult BuildExpressionTrait(ExpressionTrait OET,
3016 SourceLocation KWLoc,
3018 SourceLocation RParen);
3020 ExprResult ActOnStartCXXMemberReference(Scope *S,
3022 SourceLocation OpLoc,
3023 tok::TokenKind OpKind,
3024 ParsedType &ObjectType,
3025 bool &MayBePseudoDestructor);
3027 ExprResult DiagnoseDtorReference(SourceLocation NameLoc, Expr *MemExpr);
3029 ExprResult BuildPseudoDestructorExpr(Expr *Base,
3030 SourceLocation OpLoc,
3031 tok::TokenKind OpKind,
3032 const CXXScopeSpec &SS,
3033 TypeSourceInfo *ScopeType,
3034 SourceLocation CCLoc,
3035 SourceLocation TildeLoc,
3036 PseudoDestructorTypeStorage DestroyedType,
3037 bool HasTrailingLParen);
3039 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
3040 SourceLocation OpLoc,
3041 tok::TokenKind OpKind,
3043 UnqualifiedId &FirstTypeName,
3044 SourceLocation CCLoc,
3045 SourceLocation TildeLoc,
3046 UnqualifiedId &SecondTypeName,
3047 bool HasTrailingLParen);
3049 /// MaybeCreateExprWithCleanups - If the current full-expression
3050 /// requires any cleanups, surround it with a ExprWithCleanups node.
3051 /// Otherwise, just returns the passed-in expression.
3052 Expr *MaybeCreateExprWithCleanups(Expr *SubExpr);
3053 Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt);
3054 ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr);
3056 ExprResult ActOnFinishFullExpr(Expr *Expr);
3057 StmtResult ActOnFinishFullStmt(Stmt *Stmt);
3059 // Marks SS invalid if it represents an incomplete type.
3060 bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC);
3062 DeclContext *computeDeclContext(QualType T);
3063 DeclContext *computeDeclContext(const CXXScopeSpec &SS,
3064 bool EnteringContext = false);
3065 bool isDependentScopeSpecifier(const CXXScopeSpec &SS);
3066 CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS);
3067 bool isUnknownSpecialization(const CXXScopeSpec &SS);
3069 /// \brief The parser has parsed a global nested-name-specifier '::'.
3071 /// \param S The scope in which this nested-name-specifier occurs.
3073 /// \param CCLoc The location of the '::'.
3075 /// \param SS The nested-name-specifier, which will be updated in-place
3076 /// to reflect the parsed nested-name-specifier.
3078 /// \returns true if an error occurred, false otherwise.
3079 bool ActOnCXXGlobalScopeSpecifier(Scope *S, SourceLocation CCLoc,
3082 bool isAcceptableNestedNameSpecifier(NamedDecl *SD);
3083 NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS);
3085 bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS,
3086 SourceLocation IdLoc,
3088 ParsedType ObjectType);
3090 bool BuildCXXNestedNameSpecifier(Scope *S,
3091 IdentifierInfo &Identifier,
3092 SourceLocation IdentifierLoc,
3093 SourceLocation CCLoc,
3094 QualType ObjectType,
3095 bool EnteringContext,
3097 NamedDecl *ScopeLookupResult,
3098 bool ErrorRecoveryLookup);
3100 /// \brief The parser has parsed a nested-name-specifier 'identifier::'.
3102 /// \param S The scope in which this nested-name-specifier occurs.
3104 /// \param Identifier The identifier preceding the '::'.
3106 /// \param IdentifierLoc The location of the identifier.
3108 /// \param CCLoc The location of the '::'.
3110 /// \param ObjectType The type of the object, if we're parsing
3111 /// nested-name-specifier in a member access expression.
3113 /// \param EnteringContext Whether we're entering the context nominated by
3114 /// this nested-name-specifier.
3116 /// \param SS The nested-name-specifier, which is both an input
3117 /// parameter (the nested-name-specifier before this type) and an
3118 /// output parameter (containing the full nested-name-specifier,
3119 /// including this new type).
3121 /// \returns true if an error occurred, false otherwise.
3122 bool ActOnCXXNestedNameSpecifier(Scope *S,
3123 IdentifierInfo &Identifier,
3124 SourceLocation IdentifierLoc,
3125 SourceLocation CCLoc,
3126 ParsedType ObjectType,
3127 bool EnteringContext,
3130 bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS,
3131 IdentifierInfo &Identifier,
3132 SourceLocation IdentifierLoc,
3133 SourceLocation ColonLoc,
3134 ParsedType ObjectType,
3135 bool EnteringContext);
3137 /// \brief The parser has parsed a nested-name-specifier
3138 /// 'template[opt] template-name < template-args >::'.
3140 /// \param S The scope in which this nested-name-specifier occurs.
3142 /// \param TemplateLoc The location of the 'template' keyword, if any.
3144 /// \param SS The nested-name-specifier, which is both an input
3145 /// parameter (the nested-name-specifier before this type) and an
3146 /// output parameter (containing the full nested-name-specifier,
3147 /// including this new type).
3149 /// \param TemplateLoc the location of the 'template' keyword, if any.
3150 /// \param TemplateName The template name.
3151 /// \param TemplateNameLoc The location of the template name.
3152 /// \param LAngleLoc The location of the opening angle bracket ('<').
3153 /// \param TemplateArgs The template arguments.
3154 /// \param RAngleLoc The location of the closing angle bracket ('>').
3155 /// \param CCLoc The location of the '::'.
3157 /// \param EnteringContext Whether we're entering the context of the
3158 /// nested-name-specifier.
3161 /// \returns true if an error occurred, false otherwise.
3162 bool ActOnCXXNestedNameSpecifier(Scope *S,
3163 SourceLocation TemplateLoc,
3165 TemplateTy Template,
3166 SourceLocation TemplateNameLoc,
3167 SourceLocation LAngleLoc,
3168 ASTTemplateArgsPtr TemplateArgs,
3169 SourceLocation RAngleLoc,
3170 SourceLocation CCLoc,
3171 bool EnteringContext);
3173 /// \brief Given a C++ nested-name-specifier, produce an annotation value
3174 /// that the parser can use later to reconstruct the given
3175 /// nested-name-specifier.
3177 /// \param SS A nested-name-specifier.
3179 /// \returns A pointer containing all of the information in the
3180 /// nested-name-specifier \p SS.
3181 void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS);
3183 /// \brief Given an annotation pointer for a nested-name-specifier, restore
3184 /// the nested-name-specifier structure.
3186 /// \param Annotation The annotation pointer, produced by
3187 /// \c SaveNestedNameSpecifierAnnotation().
3189 /// \param AnnotationRange The source range corresponding to the annotation.
3191 /// \param SS The nested-name-specifier that will be updated with the contents
3192 /// of the annotation pointer.
3193 void RestoreNestedNameSpecifierAnnotation(void *Annotation,
3194 SourceRange AnnotationRange,
3197 bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
3199 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
3200 /// scope or nested-name-specifier) is parsed, part of a declarator-id.
3201 /// After this method is called, according to [C++ 3.4.3p3], names should be
3202 /// looked up in the declarator-id's scope, until the declarator is parsed and
3203 /// ActOnCXXExitDeclaratorScope is called.
3204 /// The 'SS' should be a non-empty valid CXXScopeSpec.
3205 bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS);
3207 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
3208 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
3209 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
3210 /// Used to indicate that names should revert to being looked up in the
3212 void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
3214 /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an
3215 /// initializer for the declaration 'Dcl'.
3216 /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a
3217 /// static data member of class X, names should be looked up in the scope of
3219 void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl);
3221 /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an
3222 /// initializer for the declaration 'Dcl'.
3223 void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl);
3225 // ParseObjCStringLiteral - Parse Objective-C string literals.
3226 ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
3228 unsigned NumStrings);
3230 ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc,
3231 TypeSourceInfo *EncodedTypeInfo,
3232 SourceLocation RParenLoc);
3233 ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl,
3234 CXXMethodDecl *Method);
3236 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
3237 SourceLocation EncodeLoc,
3238 SourceLocation LParenLoc,
3240 SourceLocation RParenLoc);
3242 // ParseObjCSelectorExpression - Build selector expression for @selector
3243 ExprResult ParseObjCSelectorExpression(Selector Sel,
3244 SourceLocation AtLoc,
3245 SourceLocation SelLoc,
3246 SourceLocation LParenLoc,
3247 SourceLocation RParenLoc);
3249 // ParseObjCProtocolExpression - Build protocol expression for @protocol
3250 ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
3251 SourceLocation AtLoc,
3252 SourceLocation ProtoLoc,
3253 SourceLocation LParenLoc,
3254 SourceLocation RParenLoc);
3256 //===--------------------------------------------------------------------===//
3259 Decl *ActOnStartLinkageSpecification(Scope *S,
3260 SourceLocation ExternLoc,
3261 SourceLocation LangLoc,
3262 llvm::StringRef Lang,
3263 SourceLocation LBraceLoc);
3264 Decl *ActOnFinishLinkageSpecification(Scope *S,
3266 SourceLocation RBraceLoc);
3269 //===--------------------------------------------------------------------===//
3272 bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
3273 const CXXScopeSpec *SS = 0);
3275 Decl *ActOnAccessSpecifier(AccessSpecifier Access,
3276 SourceLocation ASLoc,
3277 SourceLocation ColonLoc);
3279 Decl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
3281 MultiTemplateParamsArg TemplateParameterLists,
3282 Expr *BitfieldWidth, const VirtSpecifiers &VS,
3283 Expr *Init, bool HasDeferredInit,
3285 void ActOnCXXInClassMemberInitializer(Decl *VarDecl, SourceLocation EqualLoc,
3288 MemInitResult ActOnMemInitializer(Decl *ConstructorD,
3291 IdentifierInfo *MemberOrBase,
3292 ParsedType TemplateTypeTy,
3293 SourceLocation IdLoc,
3294 SourceLocation LParenLoc,
3295 Expr **Args, unsigned NumArgs,
3296 SourceLocation RParenLoc,
3297 SourceLocation EllipsisLoc);
3299 MemInitResult BuildMemberInitializer(ValueDecl *Member, Expr **Args,
3300 unsigned NumArgs, SourceLocation IdLoc,
3301 SourceLocation LParenLoc,
3302 SourceLocation RParenLoc);
3304 MemInitResult BuildBaseInitializer(QualType BaseType,
3305 TypeSourceInfo *BaseTInfo,
3306 Expr **Args, unsigned NumArgs,
3307 SourceLocation LParenLoc,
3308 SourceLocation RParenLoc,
3309 CXXRecordDecl *ClassDecl,
3310 SourceLocation EllipsisLoc);
3312 MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo,
3313 Expr **Args, unsigned NumArgs,
3314 SourceLocation BaseLoc,
3315 SourceLocation RParenLoc,
3316 SourceLocation LParenLoc,
3317 CXXRecordDecl *ClassDecl);
3319 bool SetDelegatingInitializer(CXXConstructorDecl *Constructor,
3320 CXXCtorInitializer *Initializer);
3322 bool SetCtorInitializers(CXXConstructorDecl *Constructor,
3323 CXXCtorInitializer **Initializers,
3324 unsigned NumInitializers, bool AnyErrors);
3326 void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation);
3329 /// MarkBaseAndMemberDestructorsReferenced - Given a record decl,
3330 /// mark all the non-trivial destructors of its members and bases as
3332 void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
3333 CXXRecordDecl *Record);
3335 /// \brief The list of classes whose vtables have been used within
3336 /// this translation unit, and the source locations at which the
3337 /// first use occurred.
3338 typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse;
3340 /// \brief The list of vtables that are required but have not yet been
3342 llvm::SmallVector<VTableUse, 16> VTableUses;
3344 /// \brief The set of classes whose vtables have been used within
3345 /// this translation unit, and a bit that will be true if the vtable is
3346 /// required to be emitted (otherwise, it should be emitted only if needed
3347 /// by code generation).
3348 llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed;
3350 /// \brief A list of all of the dynamic classes in this translation
3352 llvm::SmallVector<CXXRecordDecl *, 16> DynamicClasses;
3354 /// \brief Note that the vtable for the given class was used at the
3356 void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class,
3357 bool DefinitionRequired = false);
3359 /// MarkVirtualMembersReferenced - Will mark all members of the given
3360 /// CXXRecordDecl referenced.
3361 void MarkVirtualMembersReferenced(SourceLocation Loc,
3362 const CXXRecordDecl *RD);
3364 /// \brief Define all of the vtables that have been used in this
3365 /// translation unit and reference any virtual members used by those
3368 /// \returns true if any work was done, false otherwise.
3369 bool DefineUsedVTables();
3371 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
3373 void ActOnMemInitializers(Decl *ConstructorDecl,
3374 SourceLocation ColonLoc,
3375 MemInitTy **MemInits, unsigned NumMemInits,
3378 void CheckCompletedCXXClass(CXXRecordDecl *Record);
3379 void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
3381 SourceLocation LBrac,
3382 SourceLocation RBrac,
3383 AttributeList *AttrList);
3385 void ActOnReenterTemplateScope(Scope *S, Decl *Template);
3386 void ActOnReenterDeclaratorTemplateScope(Scope *S, DeclaratorDecl *D);
3387 void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record);
3388 void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
3389 void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param);
3390 void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record);
3391 void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
3392 void ActOnFinishDelayedMemberInitializers(Decl *Record);
3393 void MarkAsLateParsedTemplate(FunctionDecl *FD, bool Flag = true);
3394 bool IsInsideALocalClassWithinATemplateFunction();
3396 Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc,
3398 Expr *AssertMessageExpr,
3399 SourceLocation RParenLoc);
3401 FriendDecl *CheckFriendTypeDecl(SourceLocation FriendLoc,
3402 TypeSourceInfo *TSInfo);
3403 Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS,
3404 MultiTemplateParamsArg TemplateParams);
3405 Decl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, bool IsDefinition,
3406 MultiTemplateParamsArg TemplateParams);
3408 QualType CheckConstructorDeclarator(Declarator &D, QualType R,
3410 void CheckConstructor(CXXConstructorDecl *Constructor);
3411 QualType CheckDestructorDeclarator(Declarator &D, QualType R,
3413 bool CheckDestructor(CXXDestructorDecl *Destructor);
3414 void CheckConversionDeclarator(Declarator &D, QualType &R,
3416 Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
3418 void CheckExplicitlyDefaultedMethods(CXXRecordDecl *Record);
3419 void CheckExplicitlyDefaultedDefaultConstructor(CXXConstructorDecl *Ctor);
3420 void CheckExplicitlyDefaultedCopyConstructor(CXXConstructorDecl *Ctor);
3421 void CheckExplicitlyDefaultedCopyAssignment(CXXMethodDecl *Method);
3422 void CheckExplicitlyDefaultedDestructor(CXXDestructorDecl *Dtor);
3424 //===--------------------------------------------------------------------===//
3425 // C++ Derived Classes
3428 /// ActOnBaseSpecifier - Parsed a base specifier
3429 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
3430 SourceRange SpecifierRange,
3431 bool Virtual, AccessSpecifier Access,
3432 TypeSourceInfo *TInfo,
3433 SourceLocation EllipsisLoc);
3435 BaseResult ActOnBaseSpecifier(Decl *classdecl,
3436 SourceRange SpecifierRange,
3437 bool Virtual, AccessSpecifier Access,
3438 ParsedType basetype,
3439 SourceLocation BaseLoc,
3440 SourceLocation EllipsisLoc);
3442 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
3444 void ActOnBaseSpecifiers(Decl *ClassDecl, BaseTy **Bases, unsigned NumBases);
3446 bool IsDerivedFrom(QualType Derived, QualType Base);
3447 bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths);
3449 // FIXME: I don't like this name.
3450 void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath);
3452 bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath);
3454 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
3455 SourceLocation Loc, SourceRange Range,
3456 CXXCastPath *BasePath = 0,
3457 bool IgnoreAccess = false);
3458 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
3459 unsigned InaccessibleBaseID,
3460 unsigned AmbigiousBaseConvID,
3461 SourceLocation Loc, SourceRange Range,
3462 DeclarationName Name,
3463 CXXCastPath *BasePath);
3465 std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths);
3467 /// CheckOverridingFunctionReturnType - Checks whether the return types are
3468 /// covariant, according to C++ [class.virtual]p5.
3469 bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New,
3470 const CXXMethodDecl *Old);
3472 /// CheckOverridingFunctionExceptionSpec - Checks whether the exception
3473 /// spec is a subset of base spec.
3474 bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New,
3475 const CXXMethodDecl *Old);
3477 bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange);
3479 /// CheckOverrideControl - Check C++0x override control semantics.
3480 void CheckOverrideControl(const Decl *D);
3482 /// CheckForFunctionMarkedFinal - Checks whether a virtual member function
3483 /// overrides a virtual member function marked 'final', according to
3484 /// C++0x [class.virtual]p3.
3485 bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New,
3486 const CXXMethodDecl *Old);
3489 //===--------------------------------------------------------------------===//
3490 // C++ Access Control
3500 bool SetMemberAccessSpecifier(NamedDecl *MemberDecl,
3501 NamedDecl *PrevMemberDecl,
3502 AccessSpecifier LexicalAS);
3504 AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E,
3505 DeclAccessPair FoundDecl);
3506 AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E,
3507 DeclAccessPair FoundDecl);
3508 AccessResult CheckAllocationAccess(SourceLocation OperatorLoc,
3509 SourceRange PlacementRange,
3510 CXXRecordDecl *NamingClass,
3511 DeclAccessPair FoundDecl,
3512 bool Diagnose = true);
3513 AccessResult CheckConstructorAccess(SourceLocation Loc,
3514 CXXConstructorDecl *D,
3515 const InitializedEntity &Entity,
3516 AccessSpecifier Access,
3517 bool IsCopyBindingRefToTemp = false);
3518 AccessResult CheckConstructorAccess(SourceLocation Loc,
3519 CXXConstructorDecl *D,
3520 AccessSpecifier Access,
3521 PartialDiagnostic PD);
3522 AccessResult CheckDestructorAccess(SourceLocation Loc,
3523 CXXDestructorDecl *Dtor,
3524 const PartialDiagnostic &PDiag);
3525 AccessResult CheckDirectMemberAccess(SourceLocation Loc,
3527 const PartialDiagnostic &PDiag);
3528 AccessResult CheckMemberOperatorAccess(SourceLocation Loc,
3531 DeclAccessPair FoundDecl);
3532 AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr,
3533 DeclAccessPair FoundDecl);
3534 AccessResult CheckBaseClassAccess(SourceLocation AccessLoc,
3535 QualType Base, QualType Derived,
3536 const CXXBasePath &Path,
3538 bool ForceCheck = false,
3539 bool ForceUnprivileged = false);
3540 void CheckLookupAccess(const LookupResult &R);
3542 void HandleDependentAccessCheck(const DependentDiagnostic &DD,
3543 const MultiLevelTemplateArgumentList &TemplateArgs);
3544 void PerformDependentDiagnostics(const DeclContext *Pattern,
3545 const MultiLevelTemplateArgumentList &TemplateArgs);
3547 void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
3549 /// A flag to suppress access checking.
3550 bool SuppressAccessChecking;
3552 /// \brief When true, access checking violations are treated as SFINAE
3553 /// failures rather than hard errors.
3554 bool AccessCheckingSFINAE;
3556 void ActOnStartSuppressingAccessChecks();
3557 void ActOnStopSuppressingAccessChecks();
3559 enum AbstractDiagSelID {
3563 AbstractVariableType,
3568 bool RequireNonAbstractType(SourceLocation Loc, QualType T,
3569 const PartialDiagnostic &PD);
3570 void DiagnoseAbstractType(const CXXRecordDecl *RD);
3572 bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID,
3573 AbstractDiagSelID SelID = AbstractNone);
3575 //===--------------------------------------------------------------------===//
3576 // C++ Overloaded Operators [C++ 13.5]
3579 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
3581 bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl);
3583 //===--------------------------------------------------------------------===//
3584 // C++ Templates [C++ 14]
3586 void FilterAcceptableTemplateNames(LookupResult &R);
3587 bool hasAnyAcceptableTemplateNames(LookupResult &R);
3589 void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS,
3590 QualType ObjectType, bool EnteringContext,
3591 bool &MemberOfUnknownSpecialization);
3593 TemplateNameKind isTemplateName(Scope *S,
3595 bool hasTemplateKeyword,
3596 UnqualifiedId &Name,
3597 ParsedType ObjectType,
3598 bool EnteringContext,
3599 TemplateTy &Template,
3600 bool &MemberOfUnknownSpecialization);
3602 bool DiagnoseUnknownTemplateName(const IdentifierInfo &II,
3603 SourceLocation IILoc,
3605 const CXXScopeSpec *SS,
3606 TemplateTy &SuggestedTemplate,
3607 TemplateNameKind &SuggestedKind);
3609 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
3610 TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl);
3612 Decl *ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis,
3613 SourceLocation EllipsisLoc,
3614 SourceLocation KeyLoc,
3615 IdentifierInfo *ParamName,
3616 SourceLocation ParamNameLoc,
3617 unsigned Depth, unsigned Position,
3618 SourceLocation EqualLoc,
3619 ParsedType DefaultArg);
3621 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
3622 Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
3625 SourceLocation EqualLoc,
3627 Decl *ActOnTemplateTemplateParameter(Scope *S,
3628 SourceLocation TmpLoc,
3629 TemplateParamsTy *Params,
3630 SourceLocation EllipsisLoc,
3631 IdentifierInfo *ParamName,
3632 SourceLocation ParamNameLoc,
3635 SourceLocation EqualLoc,
3636 ParsedTemplateArgument DefaultArg);
3639 ActOnTemplateParameterList(unsigned Depth,
3640 SourceLocation ExportLoc,
3641 SourceLocation TemplateLoc,
3642 SourceLocation LAngleLoc,
3643 Decl **Params, unsigned NumParams,
3644 SourceLocation RAngleLoc);
3646 /// \brief The context in which we are checking a template parameter
3648 enum TemplateParamListContext {
3650 TPC_FunctionTemplate,
3651 TPC_ClassTemplateMember,
3652 TPC_FriendFunctionTemplate,
3653 TPC_FriendFunctionTemplateDefinition,
3654 TPC_TypeAliasTemplate
3657 bool CheckTemplateParameterList(TemplateParameterList *NewParams,
3658 TemplateParameterList *OldParams,
3659 TemplateParamListContext TPC);
3660 TemplateParameterList *
3661 MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc,
3662 SourceLocation DeclLoc,
3663 const CXXScopeSpec &SS,
3664 TemplateParameterList **ParamLists,
3665 unsigned NumParamLists,
3667 bool &IsExplicitSpecialization,
3670 DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
3671 SourceLocation KWLoc, CXXScopeSpec &SS,
3672 IdentifierInfo *Name, SourceLocation NameLoc,
3673 AttributeList *Attr,
3674 TemplateParameterList *TemplateParams,
3676 unsigned NumOuterTemplateParamLists,
3677 TemplateParameterList **OuterTemplateParamLists);
3679 void translateTemplateArguments(const ASTTemplateArgsPtr &In,
3680 TemplateArgumentListInfo &Out);
3682 void NoteAllFoundTemplates(TemplateName Name);
3684 QualType CheckTemplateIdType(TemplateName Template,
3685 SourceLocation TemplateLoc,
3686 TemplateArgumentListInfo &TemplateArgs);
3689 ActOnTemplateIdType(CXXScopeSpec &SS,
3690 TemplateTy Template, SourceLocation TemplateLoc,
3691 SourceLocation LAngleLoc,
3692 ASTTemplateArgsPtr TemplateArgs,
3693 SourceLocation RAngleLoc);
3695 /// \brief Parsed an elaborated-type-specifier that refers to a template-id,
3696 /// such as \c class T::template apply<U>.
3699 TypeResult ActOnTagTemplateIdType(TagUseKind TUK,
3700 TypeSpecifierType TagSpec,
3701 SourceLocation TagLoc,
3703 TemplateTy TemplateD,
3704 SourceLocation TemplateLoc,
3705 SourceLocation LAngleLoc,
3706 ASTTemplateArgsPtr TemplateArgsIn,
3707 SourceLocation RAngleLoc);
3710 ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS,
3713 const TemplateArgumentListInfo &TemplateArgs);
3714 ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS,
3715 const DeclarationNameInfo &NameInfo,
3716 const TemplateArgumentListInfo &TemplateArgs);
3718 TemplateNameKind ActOnDependentTemplateName(Scope *S,
3719 SourceLocation TemplateKWLoc,
3721 UnqualifiedId &Name,
3722 ParsedType ObjectType,
3723 bool EnteringContext,
3724 TemplateTy &Template);
3727 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK,
3728 SourceLocation KWLoc,
3730 TemplateTy Template,
3731 SourceLocation TemplateNameLoc,
3732 SourceLocation LAngleLoc,
3733 ASTTemplateArgsPtr TemplateArgs,
3734 SourceLocation RAngleLoc,
3735 AttributeList *Attr,
3736 MultiTemplateParamsArg TemplateParameterLists);
3738 Decl *ActOnTemplateDeclarator(Scope *S,
3739 MultiTemplateParamsArg TemplateParameterLists,
3742 Decl *ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope,
3743 MultiTemplateParamsArg TemplateParameterLists,
3747 CheckSpecializationInstantiationRedecl(SourceLocation NewLoc,
3748 TemplateSpecializationKind NewTSK,
3749 NamedDecl *PrevDecl,
3750 TemplateSpecializationKind PrevTSK,
3751 SourceLocation PrevPtOfInstantiation,
3754 bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD,
3755 const TemplateArgumentListInfo &ExplicitTemplateArgs,
3756 LookupResult &Previous);
3758 bool CheckFunctionTemplateSpecialization(FunctionDecl *FD,
3759 TemplateArgumentListInfo *ExplicitTemplateArgs,
3760 LookupResult &Previous);
3761 bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous);
3764 ActOnExplicitInstantiation(Scope *S,
3765 SourceLocation ExternLoc,
3766 SourceLocation TemplateLoc,
3768 SourceLocation KWLoc,
3769 const CXXScopeSpec &SS,
3770 TemplateTy Template,
3771 SourceLocation TemplateNameLoc,
3772 SourceLocation LAngleLoc,
3773 ASTTemplateArgsPtr TemplateArgs,
3774 SourceLocation RAngleLoc,
3775 AttributeList *Attr);
3778 ActOnExplicitInstantiation(Scope *S,
3779 SourceLocation ExternLoc,
3780 SourceLocation TemplateLoc,
3782 SourceLocation KWLoc,
3784 IdentifierInfo *Name,
3785 SourceLocation NameLoc,
3786 AttributeList *Attr);
3788 DeclResult ActOnExplicitInstantiation(Scope *S,
3789 SourceLocation ExternLoc,
3790 SourceLocation TemplateLoc,
3794 SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template,
3795 SourceLocation TemplateLoc,
3796 SourceLocation RAngleLoc,
3798 llvm::SmallVectorImpl<TemplateArgument> &Converted);
3800 /// \brief Specifies the context in which a particular template
3801 /// argument is being checked.
3802 enum CheckTemplateArgumentKind {
3803 /// \brief The template argument was specified in the code or was
3804 /// instantiated with some deduced template arguments.
3807 /// \brief The template argument was deduced via template argument
3811 /// \brief The template argument was deduced from an array bound
3812 /// via template argument deduction.
3813 CTAK_DeducedFromArrayBound
3816 bool CheckTemplateArgument(NamedDecl *Param,
3817 const TemplateArgumentLoc &Arg,
3818 NamedDecl *Template,
3819 SourceLocation TemplateLoc,
3820 SourceLocation RAngleLoc,
3821 unsigned ArgumentPackIndex,
3822 llvm::SmallVectorImpl<TemplateArgument> &Converted,
3823 CheckTemplateArgumentKind CTAK = CTAK_Specified);
3825 /// \brief Check that the given template arguments can be be provided to
3826 /// the given template, converting the arguments along the way.
3828 /// \param Template The template to which the template arguments are being
3831 /// \param TemplateLoc The location of the template name in the source.
3833 /// \param TemplateArgs The list of template arguments. If the template is
3834 /// a template template parameter, this function may extend the set of
3835 /// template arguments to also include substituted, defaulted template
3838 /// \param PartialTemplateArgs True if the list of template arguments is
3839 /// intentionally partial, e.g., because we're checking just the initial
3840 /// set of template arguments.
3842 /// \param Converted Will receive the converted, canonicalized template
3845 /// \returns True if an error occurred, false otherwise.
3846 bool CheckTemplateArgumentList(TemplateDecl *Template,
3847 SourceLocation TemplateLoc,
3848 TemplateArgumentListInfo &TemplateArgs,
3849 bool PartialTemplateArgs,
3850 llvm::SmallVectorImpl<TemplateArgument> &Converted);
3852 bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
3853 const TemplateArgumentLoc &Arg,
3854 llvm::SmallVectorImpl<TemplateArgument> &Converted);
3856 bool CheckTemplateArgument(TemplateTypeParmDecl *Param,
3857 TypeSourceInfo *Arg);
3858 bool CheckTemplateArgumentPointerToMember(Expr *Arg,
3859 TemplateArgument &Converted);
3860 ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
3861 QualType InstantiatedParamType, Expr *Arg,
3862 TemplateArgument &Converted,
3863 CheckTemplateArgumentKind CTAK = CTAK_Specified);
3864 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param,
3865 const TemplateArgumentLoc &Arg);
3868 BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg,
3870 SourceLocation Loc);
3872 BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
3873 SourceLocation Loc);
3875 /// \brief Enumeration describing how template parameter lists are compared
3877 enum TemplateParameterListEqualKind {
3878 /// \brief We are matching the template parameter lists of two templates
3879 /// that might be redeclarations.
3882 /// template<typename T> struct X;
3883 /// template<typename T> struct X;
3887 /// \brief We are matching the template parameter lists of two template
3888 /// template parameters as part of matching the template parameter lists
3889 /// of two templates that might be redeclarations.
3892 /// template<template<int I> class TT> struct X;
3893 /// template<template<int Value> class Other> struct X;
3895 TPL_TemplateTemplateParmMatch,
3897 /// \brief We are matching the template parameter lists of a template
3898 /// template argument against the template parameter lists of a template
3899 /// template parameter.
3902 /// template<template<int Value> class Metafun> struct X;
3903 /// template<int Value> struct integer_c;
3904 /// X<integer_c> xic;
3906 TPL_TemplateTemplateArgumentMatch
3909 bool TemplateParameterListsAreEqual(TemplateParameterList *New,
3910 TemplateParameterList *Old,
3912 TemplateParameterListEqualKind Kind,
3913 SourceLocation TemplateArgLoc
3914 = SourceLocation());
3916 bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams);
3918 /// \brief Called when the parser has parsed a C++ typename
3919 /// specifier, e.g., "typename T::type".
3921 /// \param S The scope in which this typename type occurs.
3922 /// \param TypenameLoc the location of the 'typename' keyword
3923 /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
3924 /// \param II the identifier we're retrieving (e.g., 'type' in the example).
3925 /// \param IdLoc the location of the identifier.
3927 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
3928 const CXXScopeSpec &SS, const IdentifierInfo &II,
3929 SourceLocation IdLoc);
3931 /// \brief Called when the parser has parsed a C++ typename
3932 /// specifier that ends in a template-id, e.g.,
3933 /// "typename MetaFun::template apply<T1, T2>".
3935 /// \param S The scope in which this typename type occurs.
3936 /// \param TypenameLoc the location of the 'typename' keyword
3937 /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
3938 /// \param TemplateLoc the location of the 'template' keyword, if any.
3939 /// \param TemplateName The template name.
3940 /// \param TemplateNameLoc The location of the template name.
3941 /// \param LAngleLoc The location of the opening angle bracket ('<').
3942 /// \param TemplateArgs The template arguments.
3943 /// \param RAngleLoc The location of the closing angle bracket ('>').
3945 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
3946 const CXXScopeSpec &SS,
3947 SourceLocation TemplateLoc,
3948 TemplateTy Template,
3949 SourceLocation TemplateNameLoc,
3950 SourceLocation LAngleLoc,
3951 ASTTemplateArgsPtr TemplateArgs,
3952 SourceLocation RAngleLoc);
3954 QualType CheckTypenameType(ElaboratedTypeKeyword Keyword,
3955 SourceLocation KeywordLoc,
3956 NestedNameSpecifierLoc QualifierLoc,
3957 const IdentifierInfo &II,
3958 SourceLocation IILoc);
3960 TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
3962 DeclarationName Name);
3963 bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS);
3965 ExprResult RebuildExprInCurrentInstantiation(Expr *E);
3968 getTemplateArgumentBindingsText(const TemplateParameterList *Params,
3969 const TemplateArgumentList &Args);
3972 getTemplateArgumentBindingsText(const TemplateParameterList *Params,
3973 const TemplateArgument *Args,
3976 //===--------------------------------------------------------------------===//
3977 // C++ Variadic Templates (C++0x [temp.variadic])
3978 //===--------------------------------------------------------------------===//
3980 /// \brief The context in which an unexpanded parameter pack is
3981 /// being diagnosed.
3983 /// Note that the values of this enumeration line up with the first
3984 /// argument to the \c err_unexpanded_parameter_pack diagnostic.
3985 enum UnexpandedParameterPackContext {
3986 /// \brief An arbitrary expression.
3987 UPPC_Expression = 0,
3989 /// \brief The base type of a class type.
3992 /// \brief The type of an arbitrary declaration.
3993 UPPC_DeclarationType,
3995 /// \brief The type of a data member.
3996 UPPC_DataMemberType,
3998 /// \brief The size of a bit-field.
4001 /// \brief The expression in a static assertion.
4002 UPPC_StaticAssertExpression,
4004 /// \brief The fixed underlying type of an enumeration.
4005 UPPC_FixedUnderlyingType,
4007 /// \brief The enumerator value.
4008 UPPC_EnumeratorValue,
4010 /// \brief A using declaration.
4011 UPPC_UsingDeclaration,
4013 /// \brief A friend declaration.
4014 UPPC_FriendDeclaration,
4016 /// \brief A declaration qualifier.
4017 UPPC_DeclarationQualifier,
4019 /// \brief An initializer.
4022 /// \brief A default argument.
4023 UPPC_DefaultArgument,
4025 /// \brief The type of a non-type template parameter.
4026 UPPC_NonTypeTemplateParameterType,
4028 /// \brief The type of an exception.
4031 /// \brief Partial specialization.
4032 UPPC_PartialSpecialization
4035 /// \brief If the given type contains an unexpanded parameter pack,
4036 /// diagnose the error.
4038 /// \param Loc The source location where a diagnostc should be emitted.
4040 /// \param T The type that is being checked for unexpanded parameter
4043 /// \returns true if an error occurred, false otherwise.
4044 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T,
4045 UnexpandedParameterPackContext UPPC);
4047 /// \brief If the given expression contains an unexpanded parameter
4048 /// pack, diagnose the error.
4050 /// \param E The expression that is being checked for unexpanded
4051 /// parameter packs.
4053 /// \returns true if an error occurred, false otherwise.
4054 bool DiagnoseUnexpandedParameterPack(Expr *E,
4055 UnexpandedParameterPackContext UPPC = UPPC_Expression);
4057 /// \brief If the given nested-name-specifier contains an unexpanded
4058 /// parameter pack, diagnose the error.
4060 /// \param SS The nested-name-specifier that is being checked for
4061 /// unexpanded parameter packs.
4063 /// \returns true if an error occurred, false otherwise.
4064 bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS,
4065 UnexpandedParameterPackContext UPPC);
4067 /// \brief If the given name contains an unexpanded parameter pack,
4068 /// diagnose the error.
4070 /// \param NameInfo The name (with source location information) that
4071 /// is being checked for unexpanded parameter packs.
4073 /// \returns true if an error occurred, false otherwise.
4074 bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo,
4075 UnexpandedParameterPackContext UPPC);
4077 /// \brief If the given template name contains an unexpanded parameter pack,
4078 /// diagnose the error.
4080 /// \param Loc The location of the template name.
4082 /// \param Template The template name that is being checked for unexpanded
4083 /// parameter packs.
4085 /// \returns true if an error occurred, false otherwise.
4086 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc,
4087 TemplateName Template,
4088 UnexpandedParameterPackContext UPPC);
4090 /// \brief If the given template argument contains an unexpanded parameter
4091 /// pack, diagnose the error.
4093 /// \param Arg The template argument that is being checked for unexpanded
4094 /// parameter packs.
4096 /// \returns true if an error occurred, false otherwise.
4097 bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg,
4098 UnexpandedParameterPackContext UPPC);
4100 /// \brief Collect the set of unexpanded parameter packs within the given
4101 /// template argument.
4103 /// \param Arg The template argument that will be traversed to find
4104 /// unexpanded parameter packs.
4105 void collectUnexpandedParameterPacks(TemplateArgument Arg,
4106 llvm::SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
4108 /// \brief Collect the set of unexpanded parameter packs within the given
4109 /// template argument.
4111 /// \param Arg The template argument that will be traversed to find
4112 /// unexpanded parameter packs.
4113 void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg,
4114 llvm::SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
4116 /// \brief Collect the set of unexpanded parameter packs within the given
4119 /// \param T The type that will be traversed to find
4120 /// unexpanded parameter packs.
4121 void collectUnexpandedParameterPacks(QualType T,
4122 llvm::SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
4124 /// \brief Collect the set of unexpanded parameter packs within the given
4127 /// \param TL The type that will be traversed to find
4128 /// unexpanded parameter packs.
4129 void collectUnexpandedParameterPacks(TypeLoc TL,
4130 llvm::SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
4132 /// \brief Invoked when parsing a template argument followed by an
4133 /// ellipsis, which creates a pack expansion.
4135 /// \param Arg The template argument preceding the ellipsis, which
4136 /// may already be invalid.
4138 /// \param EllipsisLoc The location of the ellipsis.
4139 ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg,
4140 SourceLocation EllipsisLoc);
4142 /// \brief Invoked when parsing a type followed by an ellipsis, which
4143 /// creates a pack expansion.
4145 /// \param Type The type preceding the ellipsis, which will become
4146 /// the pattern of the pack expansion.
4148 /// \param EllipsisLoc The location of the ellipsis.
4149 TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc);
4151 /// \brief Construct a pack expansion type from the pattern of the pack
4153 TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern,
4154 SourceLocation EllipsisLoc,
4155 llvm::Optional<unsigned> NumExpansions);
4157 /// \brief Construct a pack expansion type from the pattern of the pack
4159 QualType CheckPackExpansion(QualType Pattern,
4160 SourceRange PatternRange,
4161 SourceLocation EllipsisLoc,
4162 llvm::Optional<unsigned> NumExpansions);
4164 /// \brief Invoked when parsing an expression followed by an ellipsis, which
4165 /// creates a pack expansion.
4167 /// \param Pattern The expression preceding the ellipsis, which will become
4168 /// the pattern of the pack expansion.
4170 /// \param EllipsisLoc The location of the ellipsis.
4171 ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc);
4173 /// \brief Invoked when parsing an expression followed by an ellipsis, which
4174 /// creates a pack expansion.
4176 /// \param Pattern The expression preceding the ellipsis, which will become
4177 /// the pattern of the pack expansion.
4179 /// \param EllipsisLoc The location of the ellipsis.
4180 ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
4181 llvm::Optional<unsigned> NumExpansions);
4183 /// \brief Determine whether we could expand a pack expansion with the
4184 /// given set of parameter packs into separate arguments by repeatedly
4185 /// transforming the pattern.
4187 /// \param EllipsisLoc The location of the ellipsis that identifies the
4190 /// \param PatternRange The source range that covers the entire pattern of
4191 /// the pack expansion.
4193 /// \param Unexpanded The set of unexpanded parameter packs within the
4196 /// \param NumUnexpanded The number of unexpanded parameter packs in
4199 /// \param ShouldExpand Will be set to \c true if the transformer should
4200 /// expand the corresponding pack expansions into separate arguments. When
4201 /// set, \c NumExpansions must also be set.
4203 /// \param RetainExpansion Whether the caller should add an unexpanded
4204 /// pack expansion after all of the expanded arguments. This is used
4205 /// when extending explicitly-specified template argument packs per
4206 /// C++0x [temp.arg.explicit]p9.
4208 /// \param NumExpansions The number of separate arguments that will be in
4209 /// the expanded form of the corresponding pack expansion. This is both an
4210 /// input and an output parameter, which can be set by the caller if the
4211 /// number of expansions is known a priori (e.g., due to a prior substitution)
4212 /// and will be set by the callee when the number of expansions is known.
4213 /// The callee must set this value when \c ShouldExpand is \c true; it may
4214 /// set this value in other cases.
4216 /// \returns true if an error occurred (e.g., because the parameter packs
4217 /// are to be instantiated with arguments of different lengths), false
4218 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
4220 bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc,
4221 SourceRange PatternRange,
4222 const UnexpandedParameterPack *Unexpanded,
4223 unsigned NumUnexpanded,
4224 const MultiLevelTemplateArgumentList &TemplateArgs,
4226 bool &RetainExpansion,
4227 llvm::Optional<unsigned> &NumExpansions);
4229 /// \brief Determine the number of arguments in the given pack expansion
4232 /// This routine already assumes that the pack expansion type can be
4233 /// expanded and that the number of arguments in the expansion is
4234 /// consistent across all of the unexpanded parameter packs in its pattern.
4235 unsigned getNumArgumentsInExpansion(QualType T,
4236 const MultiLevelTemplateArgumentList &TemplateArgs);
4238 /// \brief Determine whether the given declarator contains any unexpanded
4239 /// parameter packs.
4241 /// This routine is used by the parser to disambiguate function declarators
4242 /// with an ellipsis prior to the ')', e.g.,
4248 /// To determine whether we have an (unnamed) function parameter pack or
4249 /// a variadic function.
4251 /// \returns true if the declarator contains any unexpanded parameter packs,
4252 /// false otherwise.
4253 bool containsUnexpandedParameterPacks(Declarator &D);
4255 //===--------------------------------------------------------------------===//
4256 // C++ Template Argument Deduction (C++ [temp.deduct])
4257 //===--------------------------------------------------------------------===//
4259 /// \brief Describes the result of template argument deduction.
4261 /// The TemplateDeductionResult enumeration describes the result of
4262 /// template argument deduction, as returned from
4263 /// DeduceTemplateArguments(). The separate TemplateDeductionInfo
4264 /// structure provides additional information about the results of
4265 /// template argument deduction, e.g., the deduced template argument
4266 /// list (if successful) or the specific template parameters or
4267 /// deduced arguments that were involved in the failure.
4268 enum TemplateDeductionResult {
4269 /// \brief Template argument deduction was successful.
4271 /// \brief Template argument deduction exceeded the maximum template
4272 /// instantiation depth (which has already been diagnosed).
4273 TDK_InstantiationDepth,
4274 /// \brief Template argument deduction did not deduce a value
4275 /// for every template parameter.
4277 /// \brief Template argument deduction produced inconsistent
4278 /// deduced values for the given template parameter.
4280 /// \brief Template argument deduction failed due to inconsistent
4281 /// cv-qualifiers on a template parameter type that would
4282 /// otherwise be deduced, e.g., we tried to deduce T in "const T"
4283 /// but were given a non-const "X".
4285 /// \brief Substitution of the deduced template argument values
4286 /// resulted in an error.
4287 TDK_SubstitutionFailure,
4288 /// \brief Substitution of the deduced template argument values
4289 /// into a non-deduced context produced a type or value that
4290 /// produces a type that does not match the original template
4291 /// arguments provided.
4292 TDK_NonDeducedMismatch,
4293 /// \brief When performing template argument deduction for a function
4294 /// template, there were too many call arguments.
4295 TDK_TooManyArguments,
4296 /// \brief When performing template argument deduction for a function
4297 /// template, there were too few call arguments.
4298 TDK_TooFewArguments,
4299 /// \brief The explicitly-specified template arguments were not valid
4300 /// template arguments for the given template.
4301 TDK_InvalidExplicitArguments,
4302 /// \brief The arguments included an overloaded function name that could
4303 /// not be resolved to a suitable function.
4304 TDK_FailedOverloadResolution
4307 TemplateDeductionResult
4308 DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
4309 const TemplateArgumentList &TemplateArgs,
4310 sema::TemplateDeductionInfo &Info);
4312 TemplateDeductionResult
4313 SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
4314 TemplateArgumentListInfo &ExplicitTemplateArgs,
4315 llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced,
4316 llvm::SmallVectorImpl<QualType> &ParamTypes,
4317 QualType *FunctionType,
4318 sema::TemplateDeductionInfo &Info);
4320 /// brief A function argument from which we performed template argument
4321 // deduction for a call.
4322 struct OriginalCallArg {
4323 OriginalCallArg(QualType OriginalParamType,
4325 QualType OriginalArgType)
4326 : OriginalParamType(OriginalParamType), ArgIdx(ArgIdx),
4327 OriginalArgType(OriginalArgType) { }
4329 QualType OriginalParamType;
4331 QualType OriginalArgType;
4334 TemplateDeductionResult
4335 FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate,
4336 llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced,
4337 unsigned NumExplicitlySpecified,
4338 FunctionDecl *&Specialization,
4339 sema::TemplateDeductionInfo &Info,
4340 llvm::SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = 0);
4342 TemplateDeductionResult
4343 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
4344 TemplateArgumentListInfo *ExplicitTemplateArgs,
4345 Expr **Args, unsigned NumArgs,
4346 FunctionDecl *&Specialization,
4347 sema::TemplateDeductionInfo &Info);
4349 TemplateDeductionResult
4350 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
4351 TemplateArgumentListInfo *ExplicitTemplateArgs,
4352 QualType ArgFunctionType,
4353 FunctionDecl *&Specialization,
4354 sema::TemplateDeductionInfo &Info);
4356 TemplateDeductionResult
4357 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
4359 CXXConversionDecl *&Specialization,
4360 sema::TemplateDeductionInfo &Info);
4362 TemplateDeductionResult
4363 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
4364 TemplateArgumentListInfo *ExplicitTemplateArgs,
4365 FunctionDecl *&Specialization,
4366 sema::TemplateDeductionInfo &Info);
4368 bool DeduceAutoType(TypeSourceInfo *AutoType, Expr *Initializer,
4369 TypeSourceInfo *&Result);
4371 FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1,
4372 FunctionTemplateDecl *FT2,
4374 TemplatePartialOrderingContext TPOC,
4375 unsigned NumCallArguments);
4376 UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin,
4377 UnresolvedSetIterator SEnd,
4378 TemplatePartialOrderingContext TPOC,
4379 unsigned NumCallArguments,
4381 const PartialDiagnostic &NoneDiag,
4382 const PartialDiagnostic &AmbigDiag,
4383 const PartialDiagnostic &CandidateDiag,
4384 bool Complain = true);
4386 ClassTemplatePartialSpecializationDecl *
4387 getMoreSpecializedPartialSpecialization(
4388 ClassTemplatePartialSpecializationDecl *PS1,
4389 ClassTemplatePartialSpecializationDecl *PS2,
4390 SourceLocation Loc);
4392 void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs,
4395 llvm::SmallVectorImpl<bool> &Used);
4396 void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate,
4397 llvm::SmallVectorImpl<bool> &Deduced);
4399 //===--------------------------------------------------------------------===//
4400 // C++ Template Instantiation
4403 MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D,
4404 const TemplateArgumentList *Innermost = 0,
4405 bool RelativeToPrimary = false,
4406 const FunctionDecl *Pattern = 0);
4408 /// \brief A template instantiation that is currently in progress.
4409 struct ActiveTemplateInstantiation {
4410 /// \brief The kind of template instantiation we are performing
4411 enum InstantiationKind {
4412 /// We are instantiating a template declaration. The entity is
4413 /// the declaration we're instantiating (e.g., a CXXRecordDecl).
4414 TemplateInstantiation,
4416 /// We are instantiating a default argument for a template
4417 /// parameter. The Entity is the template, and
4418 /// TemplateArgs/NumTemplateArguments provides the template
4419 /// arguments as specified.
4420 /// FIXME: Use a TemplateArgumentList
4421 DefaultTemplateArgumentInstantiation,
4423 /// We are instantiating a default argument for a function.
4424 /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs
4425 /// provides the template arguments as specified.
4426 DefaultFunctionArgumentInstantiation,
4428 /// We are substituting explicit template arguments provided for
4429 /// a function template. The entity is a FunctionTemplateDecl.
4430 ExplicitTemplateArgumentSubstitution,
4432 /// We are substituting template argument determined as part of
4433 /// template argument deduction for either a class template
4434 /// partial specialization or a function template. The
4435 /// Entity is either a ClassTemplatePartialSpecializationDecl or
4436 /// a FunctionTemplateDecl.
4437 DeducedTemplateArgumentSubstitution,
4439 /// We are substituting prior template arguments into a new
4440 /// template parameter. The template parameter itself is either a
4441 /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl.
4442 PriorTemplateArgumentSubstitution,
4444 /// We are checking the validity of a default template argument that
4445 /// has been used when naming a template-id.
4446 DefaultTemplateArgumentChecking
4449 /// \brief The point of instantiation within the source code.
4450 SourceLocation PointOfInstantiation;
4452 /// \brief The template (or partial specialization) in which we are
4453 /// performing the instantiation, for substitutions of prior template
4455 NamedDecl *Template;
4457 /// \brief The entity that is being instantiated.
4460 /// \brief The list of template arguments we are substituting, if they
4461 /// are not part of the entity.
4462 const TemplateArgument *TemplateArgs;
4464 /// \brief The number of template arguments in TemplateArgs.
4465 unsigned NumTemplateArgs;
4467 /// \brief The template deduction info object associated with the
4468 /// substitution or checking of explicit or deduced template arguments.
4469 sema::TemplateDeductionInfo *DeductionInfo;
4471 /// \brief The source range that covers the construct that cause
4472 /// the instantiation, e.g., the template-id that causes a class
4473 /// template instantiation.
4474 SourceRange InstantiationRange;
4476 ActiveTemplateInstantiation()
4477 : Kind(TemplateInstantiation), Template(0), Entity(0), TemplateArgs(0),
4478 NumTemplateArgs(0), DeductionInfo(0) {}
4480 /// \brief Determines whether this template is an actual instantiation
4481 /// that should be counted toward the maximum instantiation depth.
4482 bool isInstantiationRecord() const;
4484 friend bool operator==(const ActiveTemplateInstantiation &X,
4485 const ActiveTemplateInstantiation &Y) {
4486 if (X.Kind != Y.Kind)
4489 if (X.Entity != Y.Entity)
4493 case TemplateInstantiation:
4496 case PriorTemplateArgumentSubstitution:
4497 case DefaultTemplateArgumentChecking:
4498 if (X.Template != Y.Template)
4503 case DefaultTemplateArgumentInstantiation:
4504 case ExplicitTemplateArgumentSubstitution:
4505 case DeducedTemplateArgumentSubstitution:
4506 case DefaultFunctionArgumentInstantiation:
4507 return X.TemplateArgs == Y.TemplateArgs;
4514 friend bool operator!=(const ActiveTemplateInstantiation &X,
4515 const ActiveTemplateInstantiation &Y) {
4520 /// \brief List of active template instantiations.
4522 /// This vector is treated as a stack. As one template instantiation
4523 /// requires another template instantiation, additional
4524 /// instantiations are pushed onto the stack up to a
4525 /// user-configurable limit LangOptions::InstantiationDepth.
4526 llvm::SmallVector<ActiveTemplateInstantiation, 16>
4527 ActiveTemplateInstantiations;
4529 /// \brief Whether we are in a SFINAE context that is not associated with
4530 /// template instantiation.
4532 /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside
4533 /// of a template instantiation or template argument deduction.
4534 bool InNonInstantiationSFINAEContext;
4536 /// \brief The number of ActiveTemplateInstantiation entries in
4537 /// \c ActiveTemplateInstantiations that are not actual instantiations and,
4538 /// therefore, should not be counted as part of the instantiation depth.
4539 unsigned NonInstantiationEntries;
4541 /// \brief The last template from which a template instantiation
4542 /// error or warning was produced.
4544 /// This value is used to suppress printing of redundant template
4545 /// instantiation backtraces when there are multiple errors in the
4546 /// same instantiation. FIXME: Does this belong in Sema? It's tough
4547 /// to implement it anywhere else.
4548 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext;
4550 /// \brief The current index into pack expansion arguments that will be
4551 /// used for substitution of parameter packs.
4553 /// The pack expansion index will be -1 to indicate that parameter packs
4554 /// should be instantiated as themselves. Otherwise, the index specifies
4555 /// which argument within the parameter pack will be used for substitution.
4556 int ArgumentPackSubstitutionIndex;
4558 /// \brief RAII object used to change the argument pack substitution index
4559 /// within a \c Sema object.
4561 /// See \c ArgumentPackSubstitutionIndex for more information.
4562 class ArgumentPackSubstitutionIndexRAII {
4564 int OldSubstitutionIndex;
4567 ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex)
4568 : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) {
4569 Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex;
4572 ~ArgumentPackSubstitutionIndexRAII() {
4573 Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex;
4577 friend class ArgumentPackSubstitutionRAII;
4579 /// \brief The stack of calls expression undergoing template instantiation.
4581 /// The top of this stack is used by a fixit instantiating unresolved
4582 /// function calls to fix the AST to match the textual change it prints.
4583 llvm::SmallVector<CallExpr *, 8> CallsUndergoingInstantiation;
4585 /// \brief For each declaration that involved template argument deduction, the
4586 /// set of diagnostics that were suppressed during that template argument
4589 /// FIXME: Serialize this structure to the AST file.
4590 llvm::DenseMap<Decl *, llvm::SmallVector<PartialDiagnosticAt, 1> >
4591 SuppressedDiagnostics;
4593 /// \brief A stack object to be created when performing template
4596 /// Construction of an object of type \c InstantiatingTemplate
4597 /// pushes the current instantiation onto the stack of active
4598 /// instantiations. If the size of this stack exceeds the maximum
4599 /// number of recursive template instantiations, construction
4600 /// produces an error and evaluates true.
4602 /// Destruction of this object will pop the named instantiation off
4604 struct InstantiatingTemplate {
4605 /// \brief Note that we are instantiating a class template,
4606 /// function template, or a member thereof.
4607 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4609 SourceRange InstantiationRange = SourceRange());
4611 /// \brief Note that we are instantiating a default argument in a
4613 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4614 TemplateDecl *Template,
4615 const TemplateArgument *TemplateArgs,
4616 unsigned NumTemplateArgs,
4617 SourceRange InstantiationRange = SourceRange());
4619 /// \brief Note that we are instantiating a default argument in a
4621 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4622 FunctionTemplateDecl *FunctionTemplate,
4623 const TemplateArgument *TemplateArgs,
4624 unsigned NumTemplateArgs,
4625 ActiveTemplateInstantiation::InstantiationKind Kind,
4626 sema::TemplateDeductionInfo &DeductionInfo,
4627 SourceRange InstantiationRange = SourceRange());
4629 /// \brief Note that we are instantiating as part of template
4630 /// argument deduction for a class template partial
4632 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4633 ClassTemplatePartialSpecializationDecl *PartialSpec,
4634 const TemplateArgument *TemplateArgs,
4635 unsigned NumTemplateArgs,
4636 sema::TemplateDeductionInfo &DeductionInfo,
4637 SourceRange InstantiationRange = SourceRange());
4639 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4641 const TemplateArgument *TemplateArgs,
4642 unsigned NumTemplateArgs,
4643 SourceRange InstantiationRange = SourceRange());
4645 /// \brief Note that we are substituting prior template arguments into a
4646 /// non-type or template template parameter.
4647 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4648 NamedDecl *Template,
4649 NonTypeTemplateParmDecl *Param,
4650 const TemplateArgument *TemplateArgs,
4651 unsigned NumTemplateArgs,
4652 SourceRange InstantiationRange);
4654 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4655 NamedDecl *Template,
4656 TemplateTemplateParmDecl *Param,
4657 const TemplateArgument *TemplateArgs,
4658 unsigned NumTemplateArgs,
4659 SourceRange InstantiationRange);
4661 /// \brief Note that we are checking the default template argument
4662 /// against the template parameter for a given template-id.
4663 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4664 TemplateDecl *Template,
4666 const TemplateArgument *TemplateArgs,
4667 unsigned NumTemplateArgs,
4668 SourceRange InstantiationRange);
4671 /// \brief Note that we have finished instantiating this template.
4674 ~InstantiatingTemplate() { Clear(); }
4676 /// \brief Determines whether we have exceeded the maximum
4677 /// recursive template instantiations.
4678 operator bool() const { return Invalid; }
4683 bool SavedInNonInstantiationSFINAEContext;
4684 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation,
4685 SourceRange InstantiationRange);
4687 InstantiatingTemplate(const InstantiatingTemplate&); // not implemented
4689 InstantiatingTemplate&
4690 operator=(const InstantiatingTemplate&); // not implemented
4693 void PrintInstantiationStack();
4695 /// \brief Determines whether we are currently in a context where
4696 /// template argument substitution failures are not considered
4699 /// \returns An empty \c llvm::Optional if we're not in a SFINAE context.
4700 /// Otherwise, contains a pointer that, if non-NULL, contains the nearest
4701 /// template-deduction context object, which can be used to capture
4702 /// diagnostics that will be suppressed.
4703 llvm::Optional<sema::TemplateDeductionInfo *> isSFINAEContext() const;
4705 /// \brief RAII class used to determine whether SFINAE has
4706 /// trapped any errors that occur during template argument
4710 unsigned PrevSFINAEErrors;
4711 bool PrevInNonInstantiationSFINAEContext;
4712 bool PrevAccessCheckingSFINAE;
4715 explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false)
4716 : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors),
4717 PrevInNonInstantiationSFINAEContext(
4718 SemaRef.InNonInstantiationSFINAEContext),
4719 PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE)
4721 if (!SemaRef.isSFINAEContext())
4722 SemaRef.InNonInstantiationSFINAEContext = true;
4723 SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE;
4727 SemaRef.NumSFINAEErrors = PrevSFINAEErrors;
4728 SemaRef.InNonInstantiationSFINAEContext
4729 = PrevInNonInstantiationSFINAEContext;
4730 SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE;
4733 /// \brief Determine whether any SFINAE errors have been trapped.
4734 bool hasErrorOccurred() const {
4735 return SemaRef.NumSFINAEErrors > PrevSFINAEErrors;
4739 /// \brief The current instantiation scope used to store local
4741 LocalInstantiationScope *CurrentInstantiationScope;
4743 /// \brief The number of typos corrected by CorrectTypo.
4744 unsigned TyposCorrected;
4746 typedef llvm::DenseMap<IdentifierInfo *, TypoCorrection>
4747 UnqualifiedTyposCorrectedMap;
4749 /// \brief A cache containing the results of typo correction for unqualified
4752 /// The string is the string that we corrected to (which may be empty, if
4753 /// there was no correction), while the boolean will be true when the
4754 /// string represents a keyword.
4755 UnqualifiedTyposCorrectedMap UnqualifiedTyposCorrected;
4757 /// \brief Worker object for performing CFG-based warnings.
4758 sema::AnalysisBasedWarnings AnalysisWarnings;
4760 /// \brief An entity for which implicit template instantiation is required.
4762 /// The source location associated with the declaration is the first place in
4763 /// the source code where the declaration was "used". It is not necessarily
4764 /// the point of instantiation (which will be either before or after the
4765 /// namespace-scope declaration that triggered this implicit instantiation),
4766 /// However, it is the location that diagnostics should generally refer to,
4767 /// because users will need to know what code triggered the instantiation.
4768 typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation;
4770 /// \brief The queue of implicit template instantiations that are required
4771 /// but have not yet been performed.
4772 std::deque<PendingImplicitInstantiation> PendingInstantiations;
4774 /// \brief The queue of implicit template instantiations that are required
4775 /// and must be performed within the current local scope.
4777 /// This queue is only used for member functions of local classes in
4778 /// templates, which must be instantiated in the same scope as their
4779 /// enclosing function, so that they can reference function-local
4780 /// types, static variables, enumerators, etc.
4781 std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations;
4783 void PerformPendingInstantiations(bool LocalOnly = false);
4785 TypeSourceInfo *SubstType(TypeSourceInfo *T,
4786 const MultiLevelTemplateArgumentList &TemplateArgs,
4787 SourceLocation Loc, DeclarationName Entity);
4789 QualType SubstType(QualType T,
4790 const MultiLevelTemplateArgumentList &TemplateArgs,
4791 SourceLocation Loc, DeclarationName Entity);
4793 TypeSourceInfo *SubstType(TypeLoc TL,
4794 const MultiLevelTemplateArgumentList &TemplateArgs,
4795 SourceLocation Loc, DeclarationName Entity);
4797 TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T,
4798 const MultiLevelTemplateArgumentList &TemplateArgs,
4800 DeclarationName Entity);
4801 ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D,
4802 const MultiLevelTemplateArgumentList &TemplateArgs,
4803 int indexAdjustment,
4804 llvm::Optional<unsigned> NumExpansions);
4805 bool SubstParmTypes(SourceLocation Loc,
4806 ParmVarDecl **Params, unsigned NumParams,
4807 const MultiLevelTemplateArgumentList &TemplateArgs,
4808 llvm::SmallVectorImpl<QualType> &ParamTypes,
4809 llvm::SmallVectorImpl<ParmVarDecl *> *OutParams = 0);
4810 ExprResult SubstExpr(Expr *E,
4811 const MultiLevelTemplateArgumentList &TemplateArgs);
4813 /// \brief Substitute the given template arguments into a list of
4814 /// expressions, expanding pack expansions if required.
4816 /// \param Exprs The list of expressions to substitute into.
4818 /// \param NumExprs The number of expressions in \p Exprs.
4820 /// \param IsCall Whether this is some form of call, in which case
4821 /// default arguments will be dropped.
4823 /// \param TemplateArgs The set of template arguments to substitute.
4825 /// \param Outputs Will receive all of the substituted arguments.
4827 /// \returns true if an error occurred, false otherwise.
4828 bool SubstExprs(Expr **Exprs, unsigned NumExprs, bool IsCall,
4829 const MultiLevelTemplateArgumentList &TemplateArgs,
4830 llvm::SmallVectorImpl<Expr *> &Outputs);
4832 StmtResult SubstStmt(Stmt *S,
4833 const MultiLevelTemplateArgumentList &TemplateArgs);
4835 Decl *SubstDecl(Decl *D, DeclContext *Owner,
4836 const MultiLevelTemplateArgumentList &TemplateArgs);
4839 SubstBaseSpecifiers(CXXRecordDecl *Instantiation,
4840 CXXRecordDecl *Pattern,
4841 const MultiLevelTemplateArgumentList &TemplateArgs);
4844 InstantiateClass(SourceLocation PointOfInstantiation,
4845 CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
4846 const MultiLevelTemplateArgumentList &TemplateArgs,
4847 TemplateSpecializationKind TSK,
4848 bool Complain = true);
4850 void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
4851 const Decl *Pattern, Decl *Inst);
4854 InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation,
4855 ClassTemplateSpecializationDecl *ClassTemplateSpec,
4856 TemplateSpecializationKind TSK,
4857 bool Complain = true);
4859 void InstantiateClassMembers(SourceLocation PointOfInstantiation,
4860 CXXRecordDecl *Instantiation,
4861 const MultiLevelTemplateArgumentList &TemplateArgs,
4862 TemplateSpecializationKind TSK);
4864 void InstantiateClassTemplateSpecializationMembers(
4865 SourceLocation PointOfInstantiation,
4866 ClassTemplateSpecializationDecl *ClassTemplateSpec,
4867 TemplateSpecializationKind TSK);
4869 NestedNameSpecifierLoc
4870 SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
4871 const MultiLevelTemplateArgumentList &TemplateArgs);
4874 SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
4875 const MultiLevelTemplateArgumentList &TemplateArgs);
4877 SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name,
4879 const MultiLevelTemplateArgumentList &TemplateArgs);
4880 bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs,
4881 TemplateArgumentListInfo &Result,
4882 const MultiLevelTemplateArgumentList &TemplateArgs);
4884 void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
4885 FunctionDecl *Function,
4886 bool Recursive = false,
4887 bool DefinitionRequired = false);
4888 void InstantiateStaticDataMemberDefinition(
4889 SourceLocation PointOfInstantiation,
4891 bool Recursive = false,
4892 bool DefinitionRequired = false);
4894 void InstantiateMemInitializers(CXXConstructorDecl *New,
4895 const CXXConstructorDecl *Tmpl,
4896 const MultiLevelTemplateArgumentList &TemplateArgs);
4898 NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
4899 const MultiLevelTemplateArgumentList &TemplateArgs);
4900 DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC,
4901 const MultiLevelTemplateArgumentList &TemplateArgs);
4903 // Objective-C declarations.
4904 Decl *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
4905 IdentifierInfo *ClassName,
4906 SourceLocation ClassLoc,
4907 IdentifierInfo *SuperName,
4908 SourceLocation SuperLoc,
4909 Decl * const *ProtoRefs,
4910 unsigned NumProtoRefs,
4911 const SourceLocation *ProtoLocs,
4912 SourceLocation EndProtoLoc,
4913 AttributeList *AttrList);
4915 Decl *ActOnCompatiblityAlias(
4916 SourceLocation AtCompatibilityAliasLoc,
4917 IdentifierInfo *AliasName, SourceLocation AliasLocation,
4918 IdentifierInfo *ClassName, SourceLocation ClassLocation);
4920 bool CheckForwardProtocolDeclarationForCircularDependency(
4921 IdentifierInfo *PName,
4922 SourceLocation &PLoc, SourceLocation PrevLoc,
4923 const ObjCList<ObjCProtocolDecl> &PList);
4925 Decl *ActOnStartProtocolInterface(
4926 SourceLocation AtProtoInterfaceLoc,
4927 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
4928 Decl * const *ProtoRefNames, unsigned NumProtoRefs,
4929 const SourceLocation *ProtoLocs,
4930 SourceLocation EndProtoLoc,
4931 AttributeList *AttrList);
4933 Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
4934 IdentifierInfo *ClassName,
4935 SourceLocation ClassLoc,
4936 IdentifierInfo *CategoryName,
4937 SourceLocation CategoryLoc,
4938 Decl * const *ProtoRefs,
4939 unsigned NumProtoRefs,
4940 const SourceLocation *ProtoLocs,
4941 SourceLocation EndProtoLoc);
4943 Decl *ActOnStartClassImplementation(
4944 SourceLocation AtClassImplLoc,
4945 IdentifierInfo *ClassName, SourceLocation ClassLoc,
4946 IdentifierInfo *SuperClassname,
4947 SourceLocation SuperClassLoc);
4949 Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc,
4950 IdentifierInfo *ClassName,
4951 SourceLocation ClassLoc,
4952 IdentifierInfo *CatName,
4953 SourceLocation CatLoc);
4955 Decl *ActOnForwardClassDeclaration(SourceLocation Loc,
4956 IdentifierInfo **IdentList,
4957 SourceLocation *IdentLocs,
4960 Decl *ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc,
4961 const IdentifierLocPair *IdentList,
4963 AttributeList *attrList);
4965 void FindProtocolDeclaration(bool WarnOnDeclarations,
4966 const IdentifierLocPair *ProtocolId,
4967 unsigned NumProtocols,
4968 llvm::SmallVectorImpl<Decl *> &Protocols);
4970 /// Ensure attributes are consistent with type.
4971 /// \param [in, out] Attributes The attributes to check; they will
4972 /// be modified to be consistent with \arg PropertyTy.
4973 void CheckObjCPropertyAttributes(Decl *PropertyPtrTy,
4975 unsigned &Attributes);
4977 /// Process the specified property declaration and create decls for the
4978 /// setters and getters as needed.
4979 /// \param property The property declaration being processed
4980 /// \param DC The semantic container for the property
4981 /// \param redeclaredProperty Declaration for property if redeclared
4982 /// in class extension.
4983 /// \param lexicalDC Container for redeclaredProperty.
4984 void ProcessPropertyDecl(ObjCPropertyDecl *property,
4985 ObjCContainerDecl *DC,
4986 ObjCPropertyDecl *redeclaredProperty = 0,
4987 ObjCContainerDecl *lexicalDC = 0);
4989 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
4990 ObjCPropertyDecl *SuperProperty,
4991 const IdentifierInfo *Name);
4992 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
4994 void CompareMethodParamsInBaseAndSuper(Decl *IDecl,
4995 ObjCMethodDecl *MethodDecl,
4998 void CompareProperties(Decl *CDecl, Decl *MergeProtocols);
5000 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
5001 ObjCInterfaceDecl *ID);
5003 void MatchOneProtocolPropertiesInClass(Decl *CDecl,
5004 ObjCProtocolDecl *PDecl);
5006 void ActOnAtEnd(Scope *S, SourceRange AtEnd, Decl *classDecl,
5007 Decl **allMethods = 0, unsigned allNum = 0,
5008 Decl **allProperties = 0, unsigned pNum = 0,
5009 DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0);
5011 Decl *ActOnProperty(Scope *S, SourceLocation AtLoc,
5012 FieldDeclarator &FD, ObjCDeclSpec &ODS,
5013 Selector GetterSel, Selector SetterSel,
5014 Decl *ClassCategory,
5015 bool *OverridingProperty,
5016 tok::ObjCKeywordKind MethodImplKind,
5017 DeclContext *lexicalDC = 0);
5019 Decl *ActOnPropertyImplDecl(Scope *S,
5020 SourceLocation AtLoc,
5021 SourceLocation PropertyLoc,
5022 bool ImplKind,Decl *ClassImplDecl,
5023 IdentifierInfo *PropertyId,
5024 IdentifierInfo *PropertyIvar,
5025 SourceLocation PropertyIvarLoc);
5027 enum ObjCSpecialMethodKind {
5033 OSMK_NonRetainingInit
5036 struct ObjCArgInfo {
5037 IdentifierInfo *Name;
5038 SourceLocation NameLoc;
5039 // The Type is null if no type was specified, and the DeclSpec is invalid
5042 ObjCDeclSpec DeclSpec;
5044 /// ArgAttrs - Attribute list for this argument.
5045 AttributeList *ArgAttrs;
5048 Decl *ActOnMethodDeclaration(
5050 SourceLocation BeginLoc, // location of the + or -.
5051 SourceLocation EndLoc, // location of the ; or {.
5052 tok::TokenKind MethodType,
5053 Decl *ClassDecl, ObjCDeclSpec &ReturnQT, ParsedType ReturnType,
5054 SourceLocation SelectorStartLoc, Selector Sel,
5055 // optional arguments. The number of types/arguments is obtained
5056 // from the Sel.getNumArgs().
5057 ObjCArgInfo *ArgInfo,
5058 DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args
5059 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
5060 bool isVariadic, bool MethodDefinition);
5062 // Helper method for ActOnClassMethod/ActOnInstanceMethod.
5063 // Will search "local" class/category implementations for a method decl.
5064 // Will also search in class's root looking for instance method.
5065 // Returns 0 if no method is found.
5066 ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel,
5067 ObjCInterfaceDecl *CDecl);
5068 ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel,
5069 ObjCInterfaceDecl *ClassDecl);
5070 ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel,
5071 const ObjCObjectPointerType *OPT,
5074 bool inferObjCARCLifetime(ValueDecl *decl);
5077 HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
5079 SourceLocation OpLoc,
5080 DeclarationName MemberName,
5081 SourceLocation MemberLoc,
5082 SourceLocation SuperLoc, QualType SuperType,
5086 ActOnClassPropertyRefExpr(IdentifierInfo &receiverName,
5087 IdentifierInfo &propertyName,
5088 SourceLocation receiverNameLoc,
5089 SourceLocation propertyNameLoc);
5091 ObjCMethodDecl *tryCaptureObjCSelf();
5093 /// \brief Describes the kind of message expression indicated by a message
5094 /// send that starts with an identifier.
5095 enum ObjCMessageKind {
5096 /// \brief The message is sent to 'super'.
5098 /// \brief The message is an instance message.
5099 ObjCInstanceMessage,
5100 /// \brief The message is a class message, and the identifier is a type
5105 ObjCMessageKind getObjCMessageKind(Scope *S,
5106 IdentifierInfo *Name,
5107 SourceLocation NameLoc,
5109 bool HasTrailingDot,
5110 ParsedType &ReceiverType);
5112 ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc,
5114 SourceLocation LBracLoc,
5115 SourceLocation SelectorLoc,
5116 SourceLocation RBracLoc,
5119 ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo,
5120 QualType ReceiverType,
5121 SourceLocation SuperLoc,
5123 ObjCMethodDecl *Method,
5124 SourceLocation LBracLoc,
5125 SourceLocation SelectorLoc,
5126 SourceLocation RBracLoc,
5129 ExprResult ActOnClassMessage(Scope *S,
5130 ParsedType Receiver,
5132 SourceLocation LBracLoc,
5133 SourceLocation SelectorLoc,
5134 SourceLocation RBracLoc,
5137 ExprResult BuildInstanceMessage(Expr *Receiver,
5138 QualType ReceiverType,
5139 SourceLocation SuperLoc,
5141 ObjCMethodDecl *Method,
5142 SourceLocation LBracLoc,
5143 SourceLocation SelectorLoc,
5144 SourceLocation RBracLoc,
5147 ExprResult ActOnInstanceMessage(Scope *S,
5150 SourceLocation LBracLoc,
5151 SourceLocation SelectorLoc,
5152 SourceLocation RBracLoc,
5155 ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc,
5156 ObjCBridgeCastKind Kind,
5157 SourceLocation BridgeKeywordLoc,
5158 TypeSourceInfo *TSInfo,
5161 ExprResult ActOnObjCBridgedCast(Scope *S,
5162 SourceLocation LParenLoc,
5163 ObjCBridgeCastKind Kind,
5164 SourceLocation BridgeKeywordLoc,
5166 SourceLocation RParenLoc,
5169 bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall);
5171 /// \brief Check whether the given new method is a valid override of the
5172 /// given overridden method, and set any properties that should be inherited.
5174 /// \returns True if an error occurred.
5175 bool CheckObjCMethodOverride(ObjCMethodDecl *NewMethod,
5176 const ObjCMethodDecl *Overridden,
5177 bool IsImplementation);
5179 /// \brief Check whether the given method overrides any methods in its class,
5180 /// calling \c CheckObjCMethodOverride for each overridden method.
5181 bool CheckObjCMethodOverrides(ObjCMethodDecl *NewMethod, DeclContext *DC);
5183 enum PragmaOptionsAlignKind {
5184 POAK_Native, // #pragma options align=native
5185 POAK_Natural, // #pragma options align=natural
5186 POAK_Packed, // #pragma options align=packed
5187 POAK_Power, // #pragma options align=power
5188 POAK_Mac68k, // #pragma options align=mac68k
5189 POAK_Reset // #pragma options align=reset
5192 /// ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
5193 void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
5194 SourceLocation PragmaLoc,
5195 SourceLocation KindLoc);
5197 enum PragmaPackKind {
5198 PPK_Default, // #pragma pack([n])
5199 PPK_Show, // #pragma pack(show), only supported by MSVC.
5200 PPK_Push, // #pragma pack(push, [identifier], [n])
5201 PPK_Pop // #pragma pack(pop, [identifier], [n])
5204 enum PragmaMSStructKind {
5205 PMSST_OFF, // #pragms ms_struct off
5206 PMSST_ON // #pragms ms_struct on
5209 /// ActOnPragmaPack - Called on well formed #pragma pack(...).
5210 void ActOnPragmaPack(PragmaPackKind Kind,
5211 IdentifierInfo *Name,
5213 SourceLocation PragmaLoc,
5214 SourceLocation LParenLoc,
5215 SourceLocation RParenLoc);
5217 /// ActOnPragmaMSStruct - Called on well formed #pragms ms_struct [on|off].
5218 void ActOnPragmaMSStruct(PragmaMSStructKind Kind);
5220 /// ActOnPragmaUnused - Called on well-formed '#pragma unused'.
5221 void ActOnPragmaUnused(const Token &Identifier,
5223 SourceLocation PragmaLoc);
5225 /// ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
5226 void ActOnPragmaVisibility(bool IsPush, const IdentifierInfo* VisType,
5227 SourceLocation PragmaLoc);
5229 NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II);
5230 void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W);
5232 /// ActOnPragmaWeakID - Called on well formed #pragma weak ident.
5233 void ActOnPragmaWeakID(IdentifierInfo* WeakName,
5234 SourceLocation PragmaLoc,
5235 SourceLocation WeakNameLoc);
5237 /// ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident.
5238 void ActOnPragmaWeakAlias(IdentifierInfo* WeakName,
5239 IdentifierInfo* AliasName,
5240 SourceLocation PragmaLoc,
5241 SourceLocation WeakNameLoc,
5242 SourceLocation AliasNameLoc);
5244 /// ActOnPragmaFPContract - Called on well formed
5245 /// #pragma {STDC,OPENCL} FP_CONTRACT
5246 void ActOnPragmaFPContract(tok::OnOffSwitch OOS);
5248 /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to
5249 /// a the record decl, to handle '#pragma pack' and '#pragma options align'.
5250 void AddAlignmentAttributesForRecord(RecordDecl *RD);
5252 /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record.
5253 void AddMsStructLayoutForRecord(RecordDecl *RD);
5255 /// FreePackedContext - Deallocate and null out PackContext.
5256 void FreePackedContext();
5258 /// PushNamespaceVisibilityAttr - Note that we've entered a
5259 /// namespace with a visibility attribute.
5260 void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr);
5262 /// AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used,
5263 /// add an appropriate visibility attribute.
5264 void AddPushedVisibilityAttribute(Decl *RD);
5266 /// PopPragmaVisibility - Pop the top element of the visibility stack; used
5267 /// for '#pragma GCC visibility' and visibility attributes on namespaces.
5268 void PopPragmaVisibility();
5270 /// FreeVisContext - Deallocate and null out VisContext.
5271 void FreeVisContext();
5273 /// AddAlignedAttr - Adds an aligned attribute to a particular declaration.
5274 void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, Expr *E);
5275 void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, TypeSourceInfo *T);
5277 /// CastCategory - Get the correct forwarded implicit cast result category
5278 /// from the inner expression.
5279 ExprValueKind CastCategory(Expr *E);
5281 /// \brief The kind of conversion being performed.
5282 enum CheckedConversionKind {
5283 /// \brief An implicit conversion.
5284 CCK_ImplicitConversion,
5285 /// \brief A C-style cast.
5287 /// \brief A functional-style cast.
5289 /// \brief A cast other than a C-style cast.
5293 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
5294 /// cast. If there is already an implicit cast, merge into the existing one.
5295 /// If isLvalue, the result of the cast is an lvalue.
5296 ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK,
5297 ExprValueKind VK = VK_RValue,
5298 const CXXCastPath *BasePath = 0,
5299 CheckedConversionKind CCK
5300 = CCK_ImplicitConversion);
5302 /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding
5303 /// to the conversion from scalar type ScalarTy to the Boolean type.
5304 static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy);
5306 /// IgnoredValueConversions - Given that an expression's result is
5307 /// syntactically ignored, perform any conversions that are
5309 ExprResult IgnoredValueConversions(Expr *E);
5311 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
5312 // functions and arrays to their respective pointers (C99 6.3.2.1).
5313 ExprResult UsualUnaryConversions(Expr *E);
5315 // DefaultFunctionArrayConversion - converts functions and arrays
5316 // to their respective pointers (C99 6.3.2.1).
5317 ExprResult DefaultFunctionArrayConversion(Expr *E);
5319 // DefaultFunctionArrayLvalueConversion - converts functions and
5320 // arrays to their respective pointers and performs the
5321 // lvalue-to-rvalue conversion.
5322 ExprResult DefaultFunctionArrayLvalueConversion(Expr *E);
5324 // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on
5325 // the operand. This is DefaultFunctionArrayLvalueConversion,
5326 // except that it assumes the operand isn't of function or array
5328 ExprResult DefaultLvalueConversion(Expr *E);
5330 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
5331 // do not have a prototype. Integer promotions are performed on each
5332 // argument, and arguments that have type float are promoted to double.
5333 ExprResult DefaultArgumentPromotion(Expr *E);
5335 // Used for emitting the right warning by DefaultVariadicArgumentPromotion
5336 enum VariadicCallType {
5340 VariadicConstructor,
5341 VariadicDoesNotApply
5344 /// GatherArgumentsForCall - Collector argument expressions for various
5345 /// form of call prototypes.
5346 bool GatherArgumentsForCall(SourceLocation CallLoc,
5347 FunctionDecl *FDecl,
5348 const FunctionProtoType *Proto,
5349 unsigned FirstProtoArg,
5350 Expr **Args, unsigned NumArgs,
5351 llvm::SmallVector<Expr *, 8> &AllArgs,
5352 VariadicCallType CallType = VariadicDoesNotApply);
5354 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
5355 // will warn if the resulting type is not a POD type.
5356 ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT,
5357 FunctionDecl *FDecl);
5359 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
5360 // operands and then handles various conversions that are common to binary
5361 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
5362 // routine returns the first non-arithmetic type found. The client is
5363 // responsible for emitting appropriate error diagnostics.
5364 QualType UsualArithmeticConversions(ExprResult &lExpr, ExprResult &rExpr,
5365 bool isCompAssign = false);
5367 /// AssignConvertType - All of the 'assignment' semantic checks return this
5368 /// enum to indicate whether the assignment was allowed. These checks are
5369 /// done for simple assignments, as well as initialization, return from
5370 /// function, argument passing, etc. The query is phrased in terms of a
5371 /// source and destination type.
5372 enum AssignConvertType {
5373 /// Compatible - the types are compatible according to the standard.
5376 /// PointerToInt - The assignment converts a pointer to an int, which we
5377 /// accept as an extension.
5380 /// IntToPointer - The assignment converts an int to a pointer, which we
5381 /// accept as an extension.
5384 /// FunctionVoidPointer - The assignment is between a function pointer and
5385 /// void*, which the standard doesn't allow, but we accept as an extension.
5386 FunctionVoidPointer,
5388 /// IncompatiblePointer - The assignment is between two pointers types that
5389 /// are not compatible, but we accept them as an extension.
5390 IncompatiblePointer,
5392 /// IncompatiblePointer - The assignment is between two pointers types which
5393 /// point to integers which have a different sign, but are otherwise identical.
5394 /// This is a subset of the above, but broken out because it's by far the most
5395 /// common case of incompatible pointers.
5396 IncompatiblePointerSign,
5398 /// CompatiblePointerDiscardsQualifiers - The assignment discards
5399 /// c/v/r qualifiers, which we accept as an extension.
5400 CompatiblePointerDiscardsQualifiers,
5402 /// IncompatiblePointerDiscardsQualifiers - The assignment
5403 /// discards qualifiers that we don't permit to be discarded,
5404 /// like address spaces.
5405 IncompatiblePointerDiscardsQualifiers,
5407 /// IncompatibleNestedPointerQualifiers - The assignment is between two
5408 /// nested pointer types, and the qualifiers other than the first two
5409 /// levels differ e.g. char ** -> const char **, but we accept them as an
5411 IncompatibleNestedPointerQualifiers,
5413 /// IncompatibleVectors - The assignment is between two vector types that
5414 /// have the same size, which we accept as an extension.
5415 IncompatibleVectors,
5417 /// IntToBlockPointer - The assignment converts an int to a block
5418 /// pointer. We disallow this.
5421 /// IncompatibleBlockPointer - The assignment is between two block
5422 /// pointers types that are not compatible.
5423 IncompatibleBlockPointer,
5425 /// IncompatibleObjCQualifiedId - The assignment is between a qualified
5426 /// id type and something else (that is incompatible with it). For example,
5427 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
5428 IncompatibleObjCQualifiedId,
5430 /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an
5431 /// object with __weak qualifier.
5432 IncompatibleObjCWeakRef,
5434 /// Incompatible - We reject this conversion outright, it is invalid to
5435 /// represent it in the AST.
5439 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
5440 /// assignment conversion type specified by ConvTy. This returns true if the
5441 /// conversion was invalid or false if the conversion was accepted.
5442 bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
5444 QualType DstType, QualType SrcType,
5445 Expr *SrcExpr, AssignmentAction Action,
5446 bool *Complained = 0);
5448 /// CheckAssignmentConstraints - Perform type checking for assignment,
5449 /// argument passing, variable initialization, and function return values.
5451 AssignConvertType CheckAssignmentConstraints(SourceLocation Loc,
5452 QualType lhs, QualType rhs);
5454 /// Check assignment constraints and prepare for a conversion of the
5455 /// RHS to the LHS type.
5456 AssignConvertType CheckAssignmentConstraints(QualType lhs, ExprResult &rhs,
5459 // CheckSingleAssignmentConstraints - Currently used by
5460 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
5461 // this routine performs the default function/array converions.
5462 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs,
5463 ExprResult &rExprRes);
5465 // \brief If the lhs type is a transparent union, check whether we
5466 // can initialize the transparent union with the given expression.
5467 AssignConvertType CheckTransparentUnionArgumentConstraints(QualType lhs,
5470 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
5472 bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType);
5474 ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
5475 AssignmentAction Action,
5476 bool AllowExplicit = false);
5477 ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
5478 AssignmentAction Action,
5480 ImplicitConversionSequence& ICS);
5481 ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
5482 const ImplicitConversionSequence& ICS,
5483 AssignmentAction Action,
5484 CheckedConversionKind CCK
5485 = CCK_ImplicitConversion);
5486 ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
5487 const StandardConversionSequence& SCS,
5488 AssignmentAction Action,
5489 CheckedConversionKind CCK);
5491 /// the following "Check" methods will return a valid/converted QualType
5492 /// or a null QualType (indicating an error diagnostic was issued).
5494 /// type checking binary operators (subroutines of CreateBuiltinBinOp).
5495 QualType InvalidOperands(SourceLocation l, ExprResult &lex, ExprResult &rex);
5496 QualType CheckPointerToMemberOperands( // C++ 5.5
5497 ExprResult &lex, ExprResult &rex, ExprValueKind &VK,
5498 SourceLocation OpLoc, bool isIndirect);
5499 QualType CheckMultiplyDivideOperands( // C99 6.5.5
5500 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, bool isCompAssign,
5502 QualType CheckRemainderOperands( // C99 6.5.5
5503 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, bool isCompAssign = false);
5504 QualType CheckAdditionOperands( // C99 6.5.6
5505 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, QualType* CompLHSTy = 0);
5506 QualType CheckSubtractionOperands( // C99 6.5.6
5507 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, QualType* CompLHSTy = 0);
5508 QualType CheckShiftOperands( // C99 6.5.7
5509 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, unsigned Opc,
5510 bool isCompAssign = false);
5511 QualType CheckCompareOperands( // C99 6.5.8/9
5512 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, unsigned Opc,
5514 QualType CheckBitwiseOperands( // C99 6.5.[10...12]
5515 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, bool isCompAssign = false);
5516 QualType CheckLogicalOperands( // C99 6.5.[13,14]
5517 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, unsigned Opc);
5518 // CheckAssignmentOperands is used for both simple and compound assignment.
5519 // For simple assignment, pass both expressions and a null converted type.
5520 // For compound assignment, pass both expressions and the converted type.
5521 QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
5522 Expr *lex, ExprResult &rex, SourceLocation OpLoc, QualType convertedType);
5524 void ConvertPropertyForLValue(ExprResult &LHS, ExprResult &RHS, QualType& LHSTy);
5525 ExprResult ConvertPropertyForRValue(Expr *E);
5527 QualType CheckConditionalOperands( // C99 6.5.15
5528 ExprResult &cond, ExprResult &lhs, ExprResult &rhs,
5529 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc);
5530 QualType CXXCheckConditionalOperands( // C++ 5.16
5531 ExprResult &cond, ExprResult &lhs, ExprResult &rhs,
5532 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc);
5533 QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2,
5534 bool *NonStandardCompositeType = 0);
5535 QualType FindCompositePointerType(SourceLocation Loc, ExprResult &E1, ExprResult &E2,
5536 bool *NonStandardCompositeType = 0) {
5537 Expr *E1Tmp = E1.take(), *E2Tmp = E2.take();
5538 QualType Composite = FindCompositePointerType(Loc, E1Tmp, E2Tmp, NonStandardCompositeType);
5544 QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS,
5545 SourceLocation questionLoc);
5547 bool DiagnoseConditionalForNull(Expr *LHS, Expr *RHS,
5548 SourceLocation QuestionLoc);
5550 /// type checking for vector binary operators.
5551 QualType CheckVectorOperands(ExprResult &lex, ExprResult &rex,
5552 SourceLocation Loc, bool isCompAssign);
5553 QualType CheckVectorCompareOperands(ExprResult &lex, ExprResult &rx,
5554 SourceLocation l, bool isRel);
5556 /// type checking declaration initializers (C99 6.7.8)
5557 bool CheckInitList(const InitializedEntity &Entity,
5558 InitListExpr *&InitList, QualType &DeclType);
5559 bool CheckForConstantInitializer(Expr *e, QualType t);
5561 // type checking C++ declaration initializers (C++ [dcl.init]).
5563 /// ReferenceCompareResult - Expresses the result of comparing two
5564 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
5565 /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
5566 enum ReferenceCompareResult {
5567 /// Ref_Incompatible - The two types are incompatible, so direct
5568 /// reference binding is not possible.
5569 Ref_Incompatible = 0,
5570 /// Ref_Related - The two types are reference-related, which means
5571 /// that their unqualified forms (T1 and T2) are either the same
5572 /// or T1 is a base class of T2.
5574 /// Ref_Compatible_With_Added_Qualification - The two types are
5575 /// reference-compatible with added qualification, meaning that
5576 /// they are reference-compatible and the qualifiers on T1 (cv1)
5577 /// are greater than the qualifiers on T2 (cv2).
5578 Ref_Compatible_With_Added_Qualification,
5579 /// Ref_Compatible - The two types are reference-compatible and
5580 /// have equivalent qualifiers (cv1 == cv2).
5584 ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc,
5585 QualType T1, QualType T2,
5586 bool &DerivedToBase,
5587 bool &ObjCConversion,
5588 bool &ObjCLifetimeConversion);
5590 /// CheckCastTypes - Check type constraints for casting between types under
5591 /// C semantics, or forward to CXXCheckCStyleCast in C++.
5592 ExprResult CheckCastTypes(SourceLocation CastStartLoc, SourceRange TyRange,
5593 QualType CastTy, Expr *CastExpr, CastKind &Kind,
5594 ExprValueKind &VK, CXXCastPath &BasePath,
5595 bool FunctionalStyle = false);
5597 ExprResult checkUnknownAnyCast(SourceRange TyRange, QualType castType,
5598 Expr *castExpr, CastKind &castKind,
5599 ExprValueKind &valueKind, CXXCastPath &BasePath);
5601 // CheckVectorCast - check type constraints for vectors.
5602 // Since vectors are an extension, there are no C standard reference for this.
5603 // We allow casting between vectors and integer datatypes of the same size.
5604 // returns true if the cast is invalid
5605 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty,
5608 // CheckExtVectorCast - check type constraints for extended vectors.
5609 // Since vectors are an extension, there are no C standard reference for this.
5610 // We allow casting between vectors and integer datatypes of the same size,
5611 // or vectors and the element type of that vector.
5612 // returns the cast expr
5613 ExprResult CheckExtVectorCast(SourceRange R, QualType VectorTy, Expr *CastExpr,
5616 /// CXXCheckCStyleCast - Check constraints of a C-style or function-style
5617 /// cast under C++ semantics.
5618 ExprResult CXXCheckCStyleCast(SourceRange R, QualType CastTy, ExprValueKind &VK,
5619 Expr *CastExpr, CastKind &Kind,
5620 CXXCastPath &BasePath, bool FunctionalStyle);
5622 /// \brief Checks for valid expressions which can be cast to an ObjC
5623 /// pointer without needing a bridge cast.
5624 bool ValidObjCARCNoBridgeCastExpr(Expr *&Exp, QualType castType);
5626 /// \brief Checks for invalid conversions and casts between
5627 /// retainable pointers and other pointer kinds.
5628 void CheckObjCARCConversion(SourceRange castRange, QualType castType,
5629 Expr *&op, CheckedConversionKind CCK);
5631 bool CheckObjCARCUnavailableWeakConversion(QualType castType,
5634 /// checkRetainCycles - Check whether an Objective-C message send
5635 /// might create an obvious retain cycle.
5636 void checkRetainCycles(ObjCMessageExpr *msg);
5637 void checkRetainCycles(Expr *receiver, Expr *argument);
5639 /// checkUnsafeAssigns - Check whether +1 expr is being assigned
5640 /// to weak/__unsafe_unretained type.
5641 bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS);
5643 /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned
5644 /// to weak/__unsafe_unretained expression.
5645 void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS);
5647 /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
5648 /// \param Method - May be null.
5649 /// \param [out] ReturnType - The return type of the send.
5650 /// \return true iff there were any incompatible types.
5651 bool CheckMessageArgumentTypes(QualType ReceiverType,
5652 Expr **Args, unsigned NumArgs, Selector Sel,
5653 ObjCMethodDecl *Method, bool isClassMessage,
5654 bool isSuperMessage,
5655 SourceLocation lbrac, SourceLocation rbrac,
5656 QualType &ReturnType, ExprValueKind &VK);
5658 /// \brief Determine the result of a message send expression based on
5659 /// the type of the receiver, the method expected to receive the message,
5660 /// and the form of the message send.
5661 QualType getMessageSendResultType(QualType ReceiverType,
5662 ObjCMethodDecl *Method,
5663 bool isClassMessage, bool isSuperMessage);
5665 /// \brief If the given expression involves a message send to a method
5666 /// with a related result type, emit a note describing what happened.
5667 void EmitRelatedResultTypeNote(const Expr *E);
5669 /// CheckBooleanCondition - Diagnose problems involving the use of
5670 /// the given expression as a boolean condition (e.g. in an if
5671 /// statement). Also performs the standard function and array
5672 /// decays, possibly changing the input variable.
5674 /// \param Loc - A location associated with the condition, e.g. the
5676 /// \return true iff there were any errors
5677 ExprResult CheckBooleanCondition(Expr *CondExpr, SourceLocation Loc);
5679 ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc,
5682 /// DiagnoseAssignmentAsCondition - Given that an expression is
5683 /// being used as a boolean condition, warn if it's an assignment.
5684 void DiagnoseAssignmentAsCondition(Expr *E);
5686 /// \brief Redundant parentheses over an equality comparison can indicate
5687 /// that the user intended an assignment used as condition.
5688 void DiagnoseEqualityWithExtraParens(ParenExpr *parenE);
5690 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
5691 ExprResult CheckCXXBooleanCondition(Expr *CondExpr);
5693 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
5694 /// the specified width and sign. If an overflow occurs, detect it and emit
5695 /// the specified diagnostic.
5696 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
5697 unsigned NewWidth, bool NewSign,
5698 SourceLocation Loc, unsigned DiagID);
5700 /// Checks that the Objective-C declaration is declared in the global scope.
5701 /// Emits an error and marks the declaration as invalid if it's not declared
5702 /// in the global scope.
5703 bool CheckObjCDeclScope(Decl *D);
5705 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE,
5706 /// and reports the appropriate diagnostics. Returns false on success.
5707 /// Can optionally return the value of the expression.
5708 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0);
5710 /// VerifyBitField - verifies that a bit field expression is an ICE and has
5711 /// the correct width, and that the field type is valid.
5712 /// Returns false on success.
5713 /// Can optionally return whether the bit-field is of width 0
5714 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
5715 QualType FieldTy, const Expr *BitWidth,
5716 bool *ZeroWidth = 0);
5718 /// \name Code completion
5720 /// \brief Describes the context in which code completion occurs.
5721 enum ParserCompletionContext {
5722 /// \brief Code completion occurs at top-level or namespace context.
5724 /// \brief Code completion occurs within a class, struct, or union.
5726 /// \brief Code completion occurs within an Objective-C interface, protocol,
5729 /// \brief Code completion occurs within an Objective-C implementation or
5730 /// category implementation
5731 PCC_ObjCImplementation,
5732 /// \brief Code completion occurs within the list of instance variables
5733 /// in an Objective-C interface, protocol, category, or implementation.
5734 PCC_ObjCInstanceVariableList,
5735 /// \brief Code completion occurs following one or more template
5738 /// \brief Code completion occurs following one or more template
5739 /// headers within a class.
5741 /// \brief Code completion occurs within an expression.
5743 /// \brief Code completion occurs within a statement, which may
5744 /// also be an expression or a declaration.
5746 /// \brief Code completion occurs at the beginning of the
5747 /// initialization statement (or expression) in a for loop.
5749 /// \brief Code completion occurs within the condition of an if,
5750 /// while, switch, or for statement.
5752 /// \brief Code completion occurs within the body of a function on a
5753 /// recovery path, where we do not have a specific handle on our position
5755 PCC_RecoveryInFunction,
5756 /// \brief Code completion occurs where only a type is permitted.
5758 /// \brief Code completion occurs in a parenthesized expression, which
5759 /// might also be a type cast.
5760 PCC_ParenthesizedExpression,
5761 /// \brief Code completion occurs within a sequence of declaration
5762 /// specifiers within a function, method, or block.
5763 PCC_LocalDeclarationSpecifiers
5766 void CodeCompleteOrdinaryName(Scope *S,
5767 ParserCompletionContext CompletionContext);
5768 void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS,
5769 bool AllowNonIdentifiers,
5770 bool AllowNestedNameSpecifiers);
5772 struct CodeCompleteExpressionData;
5773 void CodeCompleteExpression(Scope *S,
5774 const CodeCompleteExpressionData &Data);
5775 void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
5776 SourceLocation OpLoc,
5778 void CodeCompletePostfixExpression(Scope *S, ExprResult LHS);
5779 void CodeCompleteTag(Scope *S, unsigned TagSpec);
5780 void CodeCompleteTypeQualifiers(DeclSpec &DS);
5781 void CodeCompleteCase(Scope *S);
5782 void CodeCompleteCall(Scope *S, Expr *Fn, Expr **Args, unsigned NumArgs);
5783 void CodeCompleteInitializer(Scope *S, Decl *D);
5784 void CodeCompleteReturn(Scope *S);
5785 void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS);
5787 void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS,
5788 bool EnteringContext);
5789 void CodeCompleteUsing(Scope *S);
5790 void CodeCompleteUsingDirective(Scope *S);
5791 void CodeCompleteNamespaceDecl(Scope *S);
5792 void CodeCompleteNamespaceAliasDecl(Scope *S);
5793 void CodeCompleteOperatorName(Scope *S);
5794 void CodeCompleteConstructorInitializer(Decl *Constructor,
5795 CXXCtorInitializer** Initializers,
5796 unsigned NumInitializers);
5798 void CodeCompleteObjCAtDirective(Scope *S, Decl *ObjCImpDecl,
5800 void CodeCompleteObjCAtVisibility(Scope *S);
5801 void CodeCompleteObjCAtStatement(Scope *S);
5802 void CodeCompleteObjCAtExpression(Scope *S);
5803 void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS);
5804 void CodeCompleteObjCPropertyGetter(Scope *S, Decl *ClassDecl);
5805 void CodeCompleteObjCPropertySetter(Scope *S, Decl *ClassDecl);
5806 void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS,
5808 void CodeCompleteObjCMessageReceiver(Scope *S);
5809 void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc,
5810 IdentifierInfo **SelIdents,
5811 unsigned NumSelIdents,
5812 bool AtArgumentExpression);
5813 void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver,
5814 IdentifierInfo **SelIdents,
5815 unsigned NumSelIdents,
5816 bool AtArgumentExpression,
5817 bool IsSuper = false);
5818 void CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver,
5819 IdentifierInfo **SelIdents,
5820 unsigned NumSelIdents,
5821 bool AtArgumentExpression,
5822 ObjCInterfaceDecl *Super = 0);
5823 void CodeCompleteObjCForCollection(Scope *S,
5824 DeclGroupPtrTy IterationVar);
5825 void CodeCompleteObjCSelector(Scope *S,
5826 IdentifierInfo **SelIdents,
5827 unsigned NumSelIdents);
5828 void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
5829 unsigned NumProtocols);
5830 void CodeCompleteObjCProtocolDecl(Scope *S);
5831 void CodeCompleteObjCInterfaceDecl(Scope *S);
5832 void CodeCompleteObjCSuperclass(Scope *S,
5833 IdentifierInfo *ClassName,
5834 SourceLocation ClassNameLoc);
5835 void CodeCompleteObjCImplementationDecl(Scope *S);
5836 void CodeCompleteObjCInterfaceCategory(Scope *S,
5837 IdentifierInfo *ClassName,
5838 SourceLocation ClassNameLoc);
5839 void CodeCompleteObjCImplementationCategory(Scope *S,
5840 IdentifierInfo *ClassName,
5841 SourceLocation ClassNameLoc);
5842 void CodeCompleteObjCPropertyDefinition(Scope *S, Decl *ObjCImpDecl);
5843 void CodeCompleteObjCPropertySynthesizeIvar(Scope *S,
5844 IdentifierInfo *PropertyName,
5846 void CodeCompleteObjCMethodDecl(Scope *S,
5847 bool IsInstanceMethod,
5848 ParsedType ReturnType,
5850 void CodeCompleteObjCMethodDeclSelector(Scope *S,
5851 bool IsInstanceMethod,
5852 bool AtParameterName,
5853 ParsedType ReturnType,
5854 IdentifierInfo **SelIdents,
5855 unsigned NumSelIdents);
5856 void CodeCompletePreprocessorDirective(bool InConditional);
5857 void CodeCompleteInPreprocessorConditionalExclusion(Scope *S);
5858 void CodeCompletePreprocessorMacroName(bool IsDefinition);
5859 void CodeCompletePreprocessorExpression();
5860 void CodeCompletePreprocessorMacroArgument(Scope *S,
5861 IdentifierInfo *Macro,
5862 MacroInfo *MacroInfo,
5864 void CodeCompleteNaturalLanguage();
5865 void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator,
5866 llvm::SmallVectorImpl<CodeCompletionResult> &Results);
5869 //===--------------------------------------------------------------------===//
5870 // Extra semantic analysis beyond the C type system
5873 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
5874 unsigned ByteNo) const;
5877 void CheckArrayAccess(const Expr *E);
5878 bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall);
5879 bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall);
5881 bool CheckablePrintfAttr(const FormatAttr *Format, CallExpr *TheCall);
5882 bool CheckObjCString(Expr *Arg);
5884 ExprResult CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
5885 bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
5887 bool SemaBuiltinVAStart(CallExpr *TheCall);
5888 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
5889 bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs);
5892 // Used by C++ template instantiation.
5893 ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
5896 bool SemaBuiltinPrefetch(CallExpr *TheCall);
5897 bool SemaBuiltinObjectSize(CallExpr *TheCall);
5898 bool SemaBuiltinLongjmp(CallExpr *TheCall);
5899 ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult);
5900 bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum,
5901 llvm::APSInt &Result);
5903 bool SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall,
5904 bool HasVAListArg, unsigned format_idx,
5905 unsigned firstDataArg, bool isPrintf);
5907 void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr,
5908 const CallExpr *TheCall, bool HasVAListArg,
5909 unsigned format_idx, unsigned firstDataArg,
5912 void CheckNonNullArguments(const NonNullAttr *NonNull,
5913 const Expr * const *ExprArgs,
5914 SourceLocation CallSiteLoc);
5916 void CheckPrintfScanfArguments(const CallExpr *TheCall, bool HasVAListArg,
5917 unsigned format_idx, unsigned firstDataArg,
5920 /// \brief Enumeration used to describe which of the memory setting or copying
5921 /// functions is being checked by \c CheckMemsetcpymoveArguments().
5922 enum CheckedMemoryFunction {
5928 void CheckMemsetcpymoveArguments(const CallExpr *Call,
5929 CheckedMemoryFunction CMF,
5930 IdentifierInfo *FnName);
5932 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
5933 SourceLocation ReturnLoc);
5934 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
5935 void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation());
5937 void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field,
5940 /// \brief The parser's current scope.
5942 /// The parser maintains this state here.
5946 friend class Parser;
5947 friend class InitializationSequence;
5948 friend class ASTReader;
5949 friend class ASTWriter;
5952 /// \brief Retrieve the parser's current scope.
5954 /// This routine must only be used when it is certain that semantic analysis
5955 /// and the parser are in precisely the same context, which is not the case
5956 /// when, e.g., we are performing any kind of template instantiation.
5957 /// Therefore, the only safe places to use this scope are in the parser
5958 /// itself and in routines directly invoked from the parser and *never* from
5959 /// template substitution or instantiation.
5960 Scope *getCurScope() const { return CurScope; }
5963 /// \brief RAII object that enters a new expression evaluation context.
5964 class EnterExpressionEvaluationContext {
5968 EnterExpressionEvaluationContext(Sema &Actions,
5969 Sema::ExpressionEvaluationContext NewContext)
5970 : Actions(Actions) {
5971 Actions.PushExpressionEvaluationContext(NewContext);
5974 ~EnterExpressionEvaluationContext() {
5975 Actions.PopExpressionEvaluationContext();
5979 } // end namespace clang