clang  9.0.0svn
Sema.h
Go to the documentation of this file.
1 //===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the Sema class, which performs semantic analysis and
11 // builds ASTs.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_SEMA_SEMA_H
16 #define LLVM_CLANG_SEMA_SEMA_H
17 
18 #include "clang/AST/Attr.h"
19 #include "clang/AST/Availability.h"
21 #include "clang/AST/DeclTemplate.h"
23 #include "clang/AST/Expr.h"
24 #include "clang/AST/ExprCXX.h"
25 #include "clang/AST/ExprObjC.h"
27 #include "clang/AST/LocInfoType.h"
29 #include "clang/AST/NSAPI.h"
31 #include "clang/AST/StmtCXX.h"
32 #include "clang/AST/TypeLoc.h"
33 #include "clang/AST/TypeOrdering.h"
35 #include "clang/Basic/Module.h"
38 #include "clang/Basic/Specifiers.h"
40 #include "clang/Basic/TypeTraits.h"
42 #include "clang/Sema/CleanupInfo.h"
43 #include "clang/Sema/DeclSpec.h"
47 #include "clang/Sema/Ownership.h"
48 #include "clang/Sema/Scope.h"
50 #include "clang/Sema/Weak.h"
51 #include "llvm/ADT/ArrayRef.h"
52 #include "llvm/ADT/Optional.h"
53 #include "llvm/ADT/SetVector.h"
54 #include "llvm/ADT/SmallBitVector.h"
55 #include "llvm/ADT/SmallPtrSet.h"
56 #include "llvm/ADT/SmallVector.h"
57 #include "llvm/ADT/TinyPtrVector.h"
58 #include <deque>
59 #include <memory>
60 #include <string>
61 #include <vector>
62 
63 namespace llvm {
64  class APSInt;
65  template <typename ValueT> struct DenseMapInfo;
66  template <typename ValueT, typename ValueInfoT> class DenseSet;
67  class SmallBitVector;
68  struct InlineAsmIdentifierInfo;
69 }
70 
71 namespace clang {
72  class ADLResult;
73  class ASTConsumer;
74  class ASTContext;
75  class ASTMutationListener;
76  class ASTReader;
77  class ASTWriter;
78  class ArrayType;
79  class ParsedAttr;
80  class BindingDecl;
81  class BlockDecl;
82  class CapturedDecl;
83  class CXXBasePath;
84  class CXXBasePaths;
85  class CXXBindTemporaryExpr;
87  class CXXConstructorDecl;
88  class CXXConversionDecl;
89  class CXXDeleteExpr;
90  class CXXDestructorDecl;
91  class CXXFieldCollector;
92  class CXXMemberCallExpr;
93  class CXXMethodDecl;
94  class CXXScopeSpec;
95  class CXXTemporary;
96  class CXXTryStmt;
97  class CallExpr;
98  class ClassTemplateDecl;
99  class ClassTemplatePartialSpecializationDecl;
100  class ClassTemplateSpecializationDecl;
101  class VarTemplatePartialSpecializationDecl;
102  class CodeCompleteConsumer;
103  class CodeCompletionAllocator;
104  class CodeCompletionTUInfo;
105  class CodeCompletionResult;
106  class CoroutineBodyStmt;
107  class Decl;
108  class DeclAccessPair;
109  class DeclContext;
110  class DeclRefExpr;
111  class DeclaratorDecl;
112  class DeducedTemplateArgument;
113  class DependentDiagnostic;
114  class DesignatedInitExpr;
115  class Designation;
116  class EnableIfAttr;
117  class EnumConstantDecl;
118  class Expr;
119  class ExtVectorType;
120  class FormatAttr;
121  class FriendDecl;
122  class FunctionDecl;
123  class FunctionProtoType;
124  class FunctionTemplateDecl;
125  class ImplicitConversionSequence;
127  class InitListExpr;
128  class InitializationKind;
129  class InitializationSequence;
130  class InitializedEntity;
131  class IntegerLiteral;
132  class LabelStmt;
133  class LambdaExpr;
134  class LangOptions;
135  class LocalInstantiationScope;
136  class LookupResult;
137  class MacroInfo;
139  class ModuleLoader;
140  class MultiLevelTemplateArgumentList;
141  class NamedDecl;
142  class ObjCCategoryDecl;
143  class ObjCCategoryImplDecl;
144  class ObjCCompatibleAliasDecl;
145  class ObjCContainerDecl;
146  class ObjCImplDecl;
147  class ObjCImplementationDecl;
148  class ObjCInterfaceDecl;
149  class ObjCIvarDecl;
150  template <class T> class ObjCList;
151  class ObjCMessageExpr;
152  class ObjCMethodDecl;
153  class ObjCPropertyDecl;
154  class ObjCProtocolDecl;
155  class OMPThreadPrivateDecl;
156  class OMPRequiresDecl;
157  class OMPDeclareReductionDecl;
158  class OMPDeclareSimdDecl;
159  class OMPClause;
160  struct OverloadCandidate;
161  class OverloadCandidateSet;
162  class OverloadExpr;
163  class ParenListExpr;
164  class ParmVarDecl;
165  class Preprocessor;
166  class PseudoDestructorTypeStorage;
167  class PseudoObjectExpr;
168  class QualType;
169  class StandardConversionSequence;
170  class Stmt;
171  class StringLiteral;
172  class SwitchStmt;
173  class TemplateArgument;
174  class TemplateArgumentList;
175  class TemplateArgumentLoc;
176  class TemplateDecl;
177  class TemplateInstantiationCallback;
178  class TemplateParameterList;
179  class TemplatePartialOrderingContext;
180  class TemplateTemplateParmDecl;
181  class Token;
182  class TypeAliasDecl;
183  class TypedefDecl;
184  class TypedefNameDecl;
185  class TypeLoc;
186  class TypoCorrectionConsumer;
187  class UnqualifiedId;
188  class UnresolvedLookupExpr;
189  class UnresolvedMemberExpr;
190  class UnresolvedSetImpl;
191  class UnresolvedSetIterator;
192  class UsingDecl;
193  class UsingShadowDecl;
194  class ValueDecl;
195  class VarDecl;
196  class VarTemplateSpecializationDecl;
197  class VisibilityAttr;
198  class VisibleDeclConsumer;
199  class IndirectFieldDecl;
200  struct DeductionFailureInfo;
201  class TemplateSpecCandidateSet;
202 
203 namespace sema {
204  class AccessedEntity;
205  class BlockScopeInfo;
206  class Capture;
207  class CapturedRegionScopeInfo;
208  class CapturingScopeInfo;
209  class CompoundScopeInfo;
210  class DelayedDiagnostic;
211  class DelayedDiagnosticPool;
212  class FunctionScopeInfo;
213  class LambdaScopeInfo;
214  class PossiblyUnreachableDiag;
215  class SemaPPCallbacks;
216  class TemplateDeductionInfo;
217 }
218 
219 namespace threadSafety {
220  class BeforeSet;
221  void threadSafetyCleanup(BeforeSet* Cache);
222 }
223 
224 // FIXME: No way to easily map from TemplateTypeParmTypes to
225 // TemplateTypeParmDecls, so we have this horrible PointerUnion.
226 typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType*, NamedDecl*>,
228 
229 /// Describes whether we've seen any nullability information for the given
230 /// file.
232  /// The first pointer declarator (of any pointer kind) in the file that does
233  /// not have a corresponding nullability annotation.
235 
236  /// The end location for the first pointer declarator in the file. Used for
237  /// placing fix-its.
239 
240  /// Which kind of pointer declarator we saw.
241  uint8_t PointerKind;
242 
243  /// Whether we saw any type nullability annotations in the given file.
244  bool SawTypeNullability = false;
245 };
246 
247 /// A mapping from file IDs to a record of whether we've seen nullability
248 /// information in that file.
250  /// A mapping from file IDs to the nullability information for each file ID.
251  llvm::DenseMap<FileID, FileNullability> Map;
252 
253  /// A single-element cache based on the file ID.
254  struct {
257  } Cache;
258 
259 public:
261  // Check the single-element cache.
262  if (file == Cache.File)
263  return Cache.Nullability;
264 
265  // It's not in the single-element cache; flush the cache if we have one.
266  if (!Cache.File.isInvalid()) {
267  Map[Cache.File] = Cache.Nullability;
268  }
269 
270  // Pull this entry into the cache.
271  Cache.File = file;
272  Cache.Nullability = Map[file];
273  return Cache.Nullability;
274  }
275 };
276 
277 /// Sema - This implements semantic analysis and AST building for C.
278 class Sema {
279  Sema(const Sema &) = delete;
280  void operator=(const Sema &) = delete;
281 
282  ///Source of additional semantic information.
283  ExternalSemaSource *ExternalSource;
284 
285  ///Whether Sema has generated a multiplexer and has to delete it.
286  bool isMultiplexExternalSource;
287 
288  static bool mightHaveNonExternalLinkage(const DeclaratorDecl *FD);
289 
290  bool isVisibleSlow(const NamedDecl *D);
291 
292  /// Determine whether two declarations should be linked together, given that
293  /// the old declaration might not be visible and the new declaration might
294  /// not have external linkage.
295  bool shouldLinkPossiblyHiddenDecl(const NamedDecl *Old,
296  const NamedDecl *New) {
297  if (isVisible(Old))
298  return true;
299  // See comment in below overload for why it's safe to compute the linkage
300  // of the new declaration here.
301  if (New->isExternallyDeclarable()) {
302  assert(Old->isExternallyDeclarable() &&
303  "should not have found a non-externally-declarable previous decl");
304  return true;
305  }
306  return false;
307  }
308  bool shouldLinkPossiblyHiddenDecl(LookupResult &Old, const NamedDecl *New);
309 
310  void setupImplicitSpecialMemberType(CXXMethodDecl *SpecialMem,
311  QualType ResultTy,
312  ArrayRef<QualType> Args);
313 
314 public:
318 
321 
328 
329  /// Flag indicating whether or not to collect detailed statistics.
331 
332  /// Code-completion consumer.
334 
335  /// CurContext - This is the current declaration context of parsing.
337 
338  /// Generally null except when we temporarily switch decl contexts,
339  /// like in \see ActOnObjCTemporaryExitContainerContext.
341 
342  /// VAListTagName - The declaration name corresponding to __va_list_tag.
343  /// This is used as part of a hack to omit that class from ADL results.
345 
346  bool MSStructPragmaOn; // True when \#pragma ms_struct on
347 
348  /// Controls member pointer representation format under the MS ABI.
351 
352  /// Stack of active SEH __finally scopes. Can be empty.
354 
355  /// Source location for newly created implicit MSInheritanceAttrs
357 
358  /// pragma clang section kind
360  PCSK_Invalid = 0,
361  PCSK_BSS = 1,
362  PCSK_Data = 2,
363  PCSK_Rodata = 3,
364  PCSK_Text = 4
365  };
366 
368  PCSA_Set = 0,
369  PCSA_Clear = 1
370  };
371 
373  std::string SectionName;
374  bool Valid = false;
376 
377  void Act(SourceLocation PragmaLocation,
379  StringLiteral* Name);
380  };
381 
386 
388  PSK_Reset = 0x0, // #pragma ()
389  PSK_Set = 0x1, // #pragma (value)
390  PSK_Push = 0x2, // #pragma (push[, id])
391  PSK_Pop = 0x4, // #pragma (pop[, id])
392  PSK_Show = 0x8, // #pragma (show) -- only for "pack"!
393  PSK_Push_Set = PSK_Push | PSK_Set, // #pragma (push[, id], value)
394  PSK_Pop_Set = PSK_Pop | PSK_Set, // #pragma (pop[, id], value)
395  };
396 
397  template<typename ValueType>
398  struct PragmaStack {
399  struct Slot {
400  llvm::StringRef StackSlotLabel;
401  ValueType Value;
404  Slot(llvm::StringRef StackSlotLabel, ValueType Value,
405  SourceLocation PragmaLocation, SourceLocation PragmaPushLocation)
406  : StackSlotLabel(StackSlotLabel), Value(Value),
407  PragmaLocation(PragmaLocation),
408  PragmaPushLocation(PragmaPushLocation) {}
409  };
410  void Act(SourceLocation PragmaLocation,
411  PragmaMsStackAction Action,
412  llvm::StringRef StackSlotLabel,
413  ValueType Value);
414 
415  // MSVC seems to add artificial slots to #pragma stacks on entering a C++
416  // method body to restore the stacks on exit, so it works like this:
417  //
418  // struct S {
419  // #pragma <name>(push, InternalPragmaSlot, <current_pragma_value>)
420  // void Method {}
421  // #pragma <name>(pop, InternalPragmaSlot)
422  // };
423  //
424  // It works even with #pragma vtordisp, although MSVC doesn't support
425  // #pragma vtordisp(push [, id], n)
426  // syntax.
427  //
428  // Push / pop a named sentinel slot.
429  void SentinelAction(PragmaMsStackAction Action, StringRef Label) {
430  assert((Action == PSK_Push || Action == PSK_Pop) &&
431  "Can only push / pop #pragma stack sentinels!");
432  Act(CurrentPragmaLocation, Action, Label, CurrentValue);
433  }
434 
435  // Constructors.
436  explicit PragmaStack(const ValueType &Default)
437  : DefaultValue(Default), CurrentValue(Default) {}
438 
439  bool hasValue() const { return CurrentValue != DefaultValue; }
440 
442  ValueType DefaultValue; // Value used for PSK_Reset action.
443  ValueType CurrentValue;
445  };
446  // FIXME: We should serialize / deserialize these if they occur in a PCH (but
447  // we shouldn't do so if they're in a module).
448 
449  /// Whether to insert vtordisps prior to virtual bases in the Microsoft
450  /// C++ ABI. Possible values are 0, 1, and 2, which mean:
451  ///
452  /// 0: Suppress all vtordisps
453  /// 1: Insert vtordisps in the presence of vbase overrides and non-trivial
454  /// structors
455  /// 2: Always insert vtordisps to support RTTI on partially constructed
456  /// objects
458  // #pragma pack.
459  // Sentinel to represent when the stack is set to mac68k alignment.
460  static const unsigned kMac68kAlignmentSentinel = ~0U;
462  // The current #pragma pack values and locations at each #include.
464  unsigned CurrentValue;
466  bool HasNonDefaultValue, ShouldWarnOnInclude;
467  };
469  // Segment #pragmas.
474 
475  // RAII object to push / pop sentinel slots for all MS #pragma stacks.
476  // Actions should be performed only if we enter / exit a C++ method body.
478  public:
479  PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct);
481 
482  private:
483  Sema &S;
484  StringRef SlotLabel;
485  bool ShouldAct;
486  };
487 
488  /// A mapping that describes the nullability we've seen in each header file.
490 
491  /// Last section used with #pragma init_seg.
494 
495  /// VisContext - Manages the stack for \#pragma GCC visibility.
496  void *VisContext; // Really a "PragmaVisStack*"
497 
498  /// This an attribute introduced by \#pragma clang attribute.
503  bool IsUsed;
504  };
505 
506  /// A push'd group of PragmaAttributeEntries.
508  /// The location of the push attribute.
510  /// The namespace of this push group.
513  };
514 
516 
517  /// The declaration that is currently receiving an attribute from the
518  /// #pragma attribute stack.
520 
521  /// This represents the last location of a "#pragma clang optimize off"
522  /// directive if such a directive has not been closed by an "on" yet. If
523  /// optimizations are currently "on", this is set to an invalid location.
525 
526  /// Flag indicating if Sema is building a recovery call expression.
527  ///
528  /// This flag is used to avoid building recovery call expressions
529  /// if Sema is already doing so, which would cause infinite recursions.
531 
532  /// Used to control the generation of ExprWithCleanups.
534 
535  /// ExprCleanupObjects - This is the stack of objects requiring
536  /// cleanup that are created by the current full expression. The
537  /// element type here is ExprWithCleanups::Object.
539 
540  /// Store a list of either DeclRefExprs or MemberExprs
541  /// that contain a reference to a variable (constant) that may or may not
542  /// be odr-used in this Expr, and we won't know until all lvalue-to-rvalue
543  /// and discarded value conversions have been applied to all subexpressions
544  /// of the enclosing full expression. This is cleared at the end of each
545  /// full expression.
546  llvm::SmallPtrSet<Expr*, 2> MaybeODRUseExprs;
547 
548  std::unique_ptr<sema::FunctionScopeInfo> PreallocatedFunctionScope;
549 
550  /// Stack containing information about each of the nested
551  /// function, block, and method scopes that are currently active.
553 
555  &ExternalSemaSource::ReadExtVectorDecls, 2, 2>
557 
558  /// ExtVectorDecls - This is a list all the extended vector types. This allows
559  /// us to associate a raw vector type with one of the ext_vector type names.
560  /// This is only necessary for issuing pretty diagnostics.
562 
563  /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
564  std::unique_ptr<CXXFieldCollector> FieldCollector;
565 
567 
568  /// Set containing all declared private fields that are not used.
569  NamedDeclSetType UnusedPrivateFields;
570 
571  /// Set containing all typedefs that are likely unused.
574 
575  /// Delete-expressions to be analyzed at the end of translation unit
576  ///
577  /// This list contains class members, and locations of delete-expressions
578  /// that could not be proven as to whether they mismatch with new-expression
579  /// used in initializer of the field.
580  typedef std::pair<SourceLocation, bool> DeleteExprLoc;
582  llvm::MapVector<FieldDecl *, DeleteLocs> DeleteExprs;
583 
584  typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy;
585 
586  /// PureVirtualClassDiagSet - a set of class declarations which we have
587  /// emitted a list of pure virtual functions. Used to prevent emitting the
588  /// same list more than once.
589  std::unique_ptr<RecordDeclSetTy> PureVirtualClassDiagSet;
590 
591  /// ParsingInitForAutoVars - a set of declarations with auto types for which
592  /// we are currently parsing the initializer.
593  llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars;
594 
595  /// Look for a locally scoped extern "C" declaration by the given name.
596  NamedDecl *findLocallyScopedExternCDecl(DeclarationName Name);
597 
598  typedef LazyVector<VarDecl *, ExternalSemaSource,
599  &ExternalSemaSource::ReadTentativeDefinitions, 2, 2>
601 
602  /// All the tentative definitions encountered in the TU.
604 
605  typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource,
606  &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2>
608 
609  /// The set of file scoped decls seen so far that have not been used
610  /// and must warn if not used. Only contains the first declaration.
612 
613  typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource,
614  &ExternalSemaSource::ReadDelegatingConstructors, 2, 2>
616 
617  /// All the delegating constructors seen so far in the file, used for
618  /// cycle detection at the end of the TU.
620 
621  /// All the overriding functions seen during a class definition
622  /// that had their exception spec checks delayed, plus the overridden
623  /// function.
626 
627  /// All the function redeclarations seen during a class definition that had
628  /// their exception spec checks delayed, plus the prior declaration they
629  /// should be checked against. Except during error recovery, the new decl
630  /// should always be a friend declaration, as that's the only valid way to
631  /// redeclare a special member before its class is complete.
634 
635  /// All the members seen during a class definition which were both
636  /// explicitly defaulted and had explicitly-specified exception
637  /// specifications, along with the function type containing their
638  /// user-specified exception specification. Those exception specifications
639  /// were overridden with the default specifications, but we still need to
640  /// check whether they are compatible with the default specification, and
641  /// we can't do that until the nesting set of class definitions is complete.
644 
645  typedef llvm::MapVector<const FunctionDecl *,
646  std::unique_ptr<LateParsedTemplate>>
649 
650  /// Callback to the parser to parse templated functions when needed.
651  typedef void LateTemplateParserCB(void *P, LateParsedTemplate &LPT);
652  typedef void LateTemplateParserCleanupCB(void *P);
653  LateTemplateParserCB *LateTemplateParser;
654  LateTemplateParserCleanupCB *LateTemplateParserCleanup;
656 
657  void SetLateTemplateParser(LateTemplateParserCB *LTP,
658  LateTemplateParserCleanupCB *LTPCleanup,
659  void *P) {
660  LateTemplateParser = LTP;
661  LateTemplateParserCleanup = LTPCleanup;
662  OpaqueParser = P;
663  }
664 
665  class DelayedDiagnostics;
666 
668  sema::DelayedDiagnosticPool *SavedPool;
670  };
673 
674  /// A class which encapsulates the logic for delaying diagnostics
675  /// during parsing and other processing.
677  /// The current pool of diagnostics into which delayed
678  /// diagnostics should go.
680 
681  public:
682  DelayedDiagnostics() : CurPool(nullptr) {}
683 
684  /// Adds a delayed diagnostic.
685  void add(const sema::DelayedDiagnostic &diag); // in DelayedDiagnostic.h
686 
687  /// Determines whether diagnostics should be delayed.
688  bool shouldDelayDiagnostics() { return CurPool != nullptr; }
689 
690  /// Returns the current delayed-diagnostics pool.
692  return CurPool;
693  }
694 
695  /// Enter a new scope. Access and deprecation diagnostics will be
696  /// collected in this pool.
699  state.SavedPool = CurPool;
700  CurPool = &pool;
701  return state;
702  }
703 
704  /// Leave a delayed-diagnostic state that was previously pushed.
705  /// Do not emit any of the diagnostics. This is performed as part
706  /// of the bookkeeping of popping a pool "properly".
708  CurPool = state.SavedPool;
709  }
710 
711  /// Enter a new scope where access and deprecation diagnostics are
712  /// not delayed.
715  state.SavedPool = CurPool;
716  CurPool = nullptr;
717  return state;
718  }
719 
720  /// Undo a previous pushUndelayed().
722  assert(CurPool == nullptr);
723  CurPool = state.SavedPool;
724  }
726 
727  /// A RAII object to temporarily push a declaration context.
728  class ContextRAII {
729  private:
730  Sema &S;
731  DeclContext *SavedContext;
732  ProcessingContextState SavedContextState;
733  QualType SavedCXXThisTypeOverride;
734 
735  public:
736  ContextRAII(Sema &S, DeclContext *ContextToPush, bool NewThisContext = true)
737  : S(S), SavedContext(S.CurContext),
738  SavedContextState(S.DelayedDiagnostics.pushUndelayed()),
739  SavedCXXThisTypeOverride(S.CXXThisTypeOverride)
740  {
741  assert(ContextToPush && "pushing null context");
742  S.CurContext = ContextToPush;
743  if (NewThisContext)
745  }
746 
747  void pop() {
748  if (!SavedContext) return;
749  S.CurContext = SavedContext;
750  S.DelayedDiagnostics.popUndelayed(SavedContextState);
751  S.CXXThisTypeOverride = SavedCXXThisTypeOverride;
752  SavedContext = nullptr;
753  }
754 
756  pop();
757  }
758  };
759 
760  /// RAII object to handle the state changes required to synthesize
761  /// a function body.
763  Sema &S;
764  Sema::ContextRAII SavedContext;
765  bool PushedCodeSynthesisContext = false;
766 
767  public:
769  : S(S), SavedContext(S, DC) {
770  S.PushFunctionScope();
772  Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
773  if (auto *FD = dyn_cast<FunctionDecl>(DC))
774  FD->setWillHaveBody(true);
775  else
776  assert(isa<ObjCMethodDecl>(DC));
777  }
778 
780  assert(!PushedCodeSynthesisContext);
781 
783  Ctx.Kind = Sema::CodeSynthesisContext::DefiningSynthesizedFunction;
784  Ctx.PointOfInstantiation = UseLoc;
785  Ctx.Entity = cast<Decl>(S.CurContext);
787 
788  PushedCodeSynthesisContext = true;
789  }
790 
792  if (PushedCodeSynthesisContext)
794  if (auto *FD = dyn_cast<FunctionDecl>(S.CurContext))
795  FD->setWillHaveBody(false);
798  }
799  };
800 
801  /// WeakUndeclaredIdentifiers - Identifiers contained in
802  /// \#pragma weak before declared. rare. may alias another
803  /// identifier, declared or undeclared
804  llvm::MapVector<IdentifierInfo *, WeakInfo> WeakUndeclaredIdentifiers;
805 
806  /// ExtnameUndeclaredIdentifiers - Identifiers contained in
807  /// \#pragma redefine_extname before declared. Used in Solaris system headers
808  /// to define functions that occur in multiple standards to call the version
809  /// in the currently selected standard.
810  llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*> ExtnameUndeclaredIdentifiers;
811 
812 
813  /// Load weak undeclared identifiers from the external source.
814  void LoadExternalWeakUndeclaredIdentifiers();
815 
816  /// WeakTopLevelDecl - Translation-unit scoped declarations generated by
817  /// \#pragma weak during processing of other Decls.
818  /// I couldn't figure out a clean way to generate these in-line, so
819  /// we store them here and handle separately -- which is a hack.
820  /// It would be best to refactor this.
822 
824 
825  /// Translation Unit Scope - useful to Objective-C actions that need
826  /// to lookup file scope declarations in the "ordinary" C decl namespace.
827  /// For example, user-defined classes, built-in "id" type, etc.
829 
830  /// The C++ "std" namespace, where the standard library resides.
832 
833  /// The C++ "std::bad_alloc" class, which is defined by the C++
834  /// standard library.
836 
837  /// The C++ "std::align_val_t" enum class, which is defined by the C++
838  /// standard library.
840 
841  /// The C++ "std::experimental" namespace, where the experimental parts
842  /// of the standard library resides.
844 
845  /// The C++ "std::initializer_list" template, which is defined in
846  /// <initializer_list>.
848 
849  /// The C++ "std::coroutine_traits" template, which is defined in
850  /// <coroutine_traits>
852 
853  /// The C++ "type_info" declaration, which is defined in <typeinfo>.
855 
856  /// The MSVC "_GUID" struct, which is defined in MSVC header files.
858 
859  /// Caches identifiers/selectors for NSFoundation APIs.
860  std::unique_ptr<NSAPI> NSAPIObj;
861 
862  /// The declaration of the Objective-C NSNumber class.
864 
865  /// The declaration of the Objective-C NSValue class.
867 
868  /// Pointer to NSNumber type (NSNumber *).
870 
871  /// Pointer to NSValue type (NSValue *).
873 
874  /// The Objective-C NSNumber methods used to create NSNumber literals.
875  ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods];
876 
877  /// The declaration of the Objective-C NSString class.
879 
880  /// Pointer to NSString type (NSString *).
882 
883  /// The declaration of the stringWithUTF8String: method.
885 
886  /// The declaration of the valueWithBytes:objCType: method.
888 
889  /// The declaration of the Objective-C NSArray class.
891 
892  /// The declaration of the arrayWithObjects:count: method.
894 
895  /// The declaration of the Objective-C NSDictionary class.
897 
898  /// The declaration of the dictionaryWithObjects:forKeys:count: method.
900 
901  /// id<NSCopying> type.
903 
904  /// will hold 'respondsToSelector:'
906 
907  /// A flag to remember whether the implicit forms of operator new and delete
908  /// have been declared.
910 
911  /// A flag to indicate that we're in a context that permits abstract
912  /// references to fields. This is really a
914 
915  /// Describes how the expressions currently being parsed are
916  /// evaluated at run-time, if at all.
918  /// The current expression and its subexpressions occur within an
919  /// unevaluated operand (C++11 [expr]p7), such as the subexpression of
920  /// \c sizeof, where the type of the expression may be significant but
921  /// no code will be generated to evaluate the value of the expression at
922  /// run time.
923  Unevaluated,
924 
925  /// The current expression occurs within a braced-init-list within
926  /// an unevaluated operand. This is mostly like a regular unevaluated
927  /// context, except that we still instantiate constexpr functions that are
928  /// referenced here so that we can perform narrowing checks correctly.
929  UnevaluatedList,
930 
931  /// The current expression occurs within a discarded statement.
932  /// This behaves largely similarly to an unevaluated operand in preventing
933  /// definitions from being required, but not in other ways.
934  DiscardedStatement,
935 
936  /// The current expression occurs within an unevaluated
937  /// operand that unconditionally permits abstract references to
938  /// fields, such as a SIZE operator in MS-style inline assembly.
939  UnevaluatedAbstract,
940 
941  /// The current context is "potentially evaluated" in C++11 terms,
942  /// but the expression is evaluated at compile-time (like the values of
943  /// cases in a switch statement).
944  ConstantEvaluated,
945 
946  /// The current expression is potentially evaluated at run time,
947  /// which means that code may be generated to evaluate the value of the
948  /// expression at run time.
949  PotentiallyEvaluated,
950 
951  /// The current expression is potentially evaluated, but any
952  /// declarations referenced inside that expression are only used if
953  /// in fact the current expression is used.
954  ///
955  /// This value is used when parsing default function arguments, for which
956  /// we would like to provide diagnostics (e.g., passing non-POD arguments
957  /// through varargs) but do not want to mark declarations as "referenced"
958  /// until the default argument is used.
959  PotentiallyEvaluatedIfUsed
960  };
961 
962  /// Data structure used to record current or nested
963  /// expression evaluation contexts.
965  /// The expression evaluation context.
967 
968  /// Whether the enclosing context needed a cleanup.
970 
971  /// Whether we are in a decltype expression.
973 
974  /// The number of active cleanup objects when we entered
975  /// this expression evaluation context.
977 
978  /// The number of typos encountered during this expression evaluation
979  /// context (i.e. the number of TypoExprs created).
980  unsigned NumTypos;
981 
982  llvm::SmallPtrSet<Expr*, 2> SavedMaybeODRUseExprs;
983 
984  /// The lambdas that are present within this context, if it
985  /// is indeed an unevaluated context.
987 
988  /// The declaration that provides context for lambda expressions
989  /// and block literals if the normal declaration context does not
990  /// suffice, e.g., in a default function argument.
992 
993  /// The context information used to mangle lambda expressions
994  /// and block literals within this context.
995  ///
996  /// This mangling information is allocated lazily, since most contexts
997  /// do not have lambda expressions or block literals.
998  std::unique_ptr<MangleNumberingContext> MangleNumbering;
999 
1000  /// If we are processing a decltype type, a set of call expressions
1001  /// for which we have deferred checking the completeness of the return type.
1003 
1004  /// If we are processing a decltype type, a set of temporary binding
1005  /// expressions for which we have deferred checking the destructor.
1007 
1008  llvm::SmallPtrSet<const Expr *, 8> PossibleDerefs;
1009 
1010  /// \brief Describes whether we are in an expression constext which we have
1011  /// to handle differently.
1013  EK_Decltype, EK_TemplateArgument, EK_Other
1014  } ExprContext;
1015 
1017  unsigned NumCleanupObjects,
1018  CleanupInfo ParentCleanup,
1019  Decl *ManglingContextDecl,
1020  ExpressionKind ExprContext)
1021  : Context(Context), ParentCleanup(ParentCleanup),
1022  NumCleanupObjects(NumCleanupObjects), NumTypos(0),
1023  ManglingContextDecl(ManglingContextDecl), MangleNumbering(),
1024  ExprContext(ExprContext) {}
1025 
1026  /// Retrieve the mangling numbering context, used to consistently
1027  /// number constructs like lambdas for mangling.
1028  MangleNumberingContext &getMangleNumberingContext(ASTContext &Ctx);
1029 
1030  bool isUnevaluated() const {
1031  return Context == ExpressionEvaluationContext::Unevaluated ||
1032  Context == ExpressionEvaluationContext::UnevaluatedAbstract ||
1033  Context == ExpressionEvaluationContext::UnevaluatedList;
1034  }
1035  bool isConstantEvaluated() const {
1036  return Context == ExpressionEvaluationContext::ConstantEvaluated;
1037  }
1038  };
1039 
1040  /// A stack of expression evaluation contexts.
1042 
1043  /// Emit a warning for all pending noderef expressions that we recorded.
1044  void WarnOnPendingNoDerefs(ExpressionEvaluationContextRecord &Rec);
1045 
1046  /// Compute the mangling number context for a lambda expression or
1047  /// block literal.
1048  ///
1049  /// \param DC - The DeclContext containing the lambda expression or
1050  /// block literal.
1051  /// \param[out] ManglingContextDecl - Returns the ManglingContextDecl
1052  /// associated with the context, if relevant.
1053  MangleNumberingContext *getCurrentMangleNumberContext(
1054  const DeclContext *DC,
1055  Decl *&ManglingContextDecl);
1056 
1057 
1058  /// SpecialMemberOverloadResult - The overloading result for a special member
1059  /// function.
1060  ///
1061  /// This is basically a wrapper around PointerIntPair. The lowest bits of the
1062  /// integer are used to determine whether overload resolution succeeded.
1064  public:
1065  enum Kind {
1068  Success
1069  };
1070 
1071  private:
1072  llvm::PointerIntPair<CXXMethodDecl*, 2> Pair;
1073 
1074  public:
1077  : Pair(MD, MD->isDeleted() ? NoMemberOrDeleted : Success) {}
1078 
1079  CXXMethodDecl *getMethod() const { return Pair.getPointer(); }
1080  void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); }
1081 
1082  Kind getKind() const { return static_cast<Kind>(Pair.getInt()); }
1083  void setKind(Kind K) { Pair.setInt(K); }
1084  };
1085 
1087  : public llvm::FastFoldingSetNode,
1089  public:
1090  SpecialMemberOverloadResultEntry(const llvm::FoldingSetNodeID &ID)
1091  : FastFoldingSetNode(ID)
1092  {}
1093  };
1094 
1095  /// A cache of special member function overload resolution results
1096  /// for C++ records.
1097  llvm::FoldingSet<SpecialMemberOverloadResultEntry> SpecialMemberCache;
1098 
1099  /// A cache of the flags available in enumerations with the flag_bits
1100  /// attribute.
1101  mutable llvm::DenseMap<const EnumDecl*, llvm::APInt> FlagBitsCache;
1102 
1103  /// The kind of translation unit we are processing.
1104  ///
1105  /// When we're processing a complete translation unit, Sema will perform
1106  /// end-of-translation-unit semantic tasks (such as creating
1107  /// initializers for tentative definitions in C) once parsing has
1108  /// completed. Modules and precompiled headers perform different kinds of
1109  /// checks.
1111 
1112  llvm::BumpPtrAllocator BumpAlloc;
1113 
1114  /// The number of SFINAE diagnostics that have been trapped.
1116 
1117  typedef llvm::DenseMap<ParmVarDecl *, llvm::TinyPtrVector<ParmVarDecl *>>
1119 
1120  /// A mapping from parameters with unparsed default arguments to the
1121  /// set of instantiations of each parameter.
1122  ///
1123  /// This mapping is a temporary data structure used when parsing
1124  /// nested class templates or nested classes of class templates,
1125  /// where we might end up instantiating an inner class before the
1126  /// default arguments of its methods have been parsed.
1128 
1129  // Contains the locations of the beginning of unparsed default
1130  // argument locations.
1131  llvm::DenseMap<ParmVarDecl *, SourceLocation> UnparsedDefaultArgLocs;
1132 
1133  /// UndefinedInternals - all the used, undefined objects which require a
1134  /// definition in this translation unit.
1135  llvm::MapVector<NamedDecl *, SourceLocation> UndefinedButUsed;
1136 
1137  /// Determine if VD, which must be a variable or function, is an external
1138  /// symbol that nonetheless can't be referenced from outside this translation
1139  /// unit because its type has no linkage and it's not extern "C".
1140  bool isExternalWithNoLinkageType(ValueDecl *VD);
1141 
1142  /// Obtain a sorted list of functions that are undefined but ODR-used.
1143  void getUndefinedButUsed(
1144  SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined);
1145 
1146  /// Retrieves list of suspicious delete-expressions that will be checked at
1147  /// the end of translation unit.
1148  const llvm::MapVector<FieldDecl *, DeleteLocs> &
1149  getMismatchingDeleteExpressions() const;
1150 
1151  typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods;
1152  typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool;
1153 
1154  /// Method Pool - allows efficient lookup when typechecking messages to "id".
1155  /// We need to maintain a list, since selectors can have differing signatures
1156  /// across classes. In Cocoa, this happens to be extremely uncommon (only 1%
1157  /// of selectors are "overloaded").
1158  /// At the head of the list it is recorded whether there were 0, 1, or >= 2
1159  /// methods inside categories with a particular selector.
1160  GlobalMethodPool MethodPool;
1161 
1162  /// Method selectors used in a \@selector expression. Used for implementation
1163  /// of -Wselector.
1164  llvm::MapVector<Selector, SourceLocation> ReferencedSelectors;
1165 
1166  /// Kinds of C++ special members.
1174  CXXInvalid
1175  };
1176 
1177  typedef llvm::PointerIntPair<CXXRecordDecl *, 3, CXXSpecialMember>
1179 
1180  /// The C++ special members which we are currently in the process of
1181  /// declaring. If this process recursively triggers the declaration of the
1182  /// same special member, we should act as if it is not yet declared.
1183  llvm::SmallPtrSet<SpecialMemberDecl, 4> SpecialMembersBeingDeclared;
1184 
1185  /// The function definitions which were renamed as part of typo-correction
1186  /// to match their respective declarations. We want to keep track of them
1187  /// to ensure that we don't emit a "redefinition" error if we encounter a
1188  /// correctly named definition after the renamed definition.
1189  llvm::SmallPtrSet<const NamedDecl *, 4> TypoCorrectedFunctionDefinitions;
1190 
1191  /// Stack of types that correspond to the parameter entities that are
1192  /// currently being copy-initialized. Can be empty.
1194 
1195  void ReadMethodPool(Selector Sel);
1196  void updateOutOfDateSelector(Selector Sel);
1197 
1198  /// Private Helper predicate to check for 'self'.
1199  bool isSelfExpr(Expr *RExpr);
1200  bool isSelfExpr(Expr *RExpr, const ObjCMethodDecl *Method);
1201 
1202  /// Cause the active diagnostic on the DiagosticsEngine to be
1203  /// emitted. This is closely coupled to the SemaDiagnosticBuilder class and
1204  /// should not be used elsewhere.
1205  void EmitCurrentDiagnostic(unsigned DiagID);
1206 
1207  /// Records and restores the FP_CONTRACT state on entry/exit of compound
1208  /// statements.
1210  public:
1211  FPContractStateRAII(Sema &S) : S(S), OldFPFeaturesState(S.FPFeatures) {}
1212  ~FPContractStateRAII() { S.FPFeatures = OldFPFeaturesState; }
1213 
1214  private:
1215  Sema& S;
1216  FPOptions OldFPFeaturesState;
1217  };
1218 
1219  void addImplicitTypedef(StringRef Name, QualType T);
1220 
1221 public:
1222  Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
1224  CodeCompleteConsumer *CompletionConsumer = nullptr);
1225  ~Sema();
1226 
1227  /// Perform initialization that occurs after the parser has been
1228  /// initialized but before it parses anything.
1229  void Initialize();
1230 
1231  const LangOptions &getLangOpts() const { return LangOpts; }
1232  OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; }
1233  FPOptions &getFPOptions() { return FPFeatures; }
1234 
1235  DiagnosticsEngine &getDiagnostics() const { return Diags; }
1236  SourceManager &getSourceManager() const { return SourceMgr; }
1237  Preprocessor &getPreprocessor() const { return PP; }
1238  ASTContext &getASTContext() const { return Context; }
1239  ASTConsumer &getASTConsumer() const { return Consumer; }
1240  ASTMutationListener *getASTMutationListener() const;
1241  ExternalSemaSource* getExternalSource() const { return ExternalSource; }
1242 
1243  ///Registers an external source. If an external source already exists,
1244  /// creates a multiplex external source and appends to it.
1245  ///
1246  ///\param[in] E - A non-null external sema source.
1247  ///
1248  void addExternalSource(ExternalSemaSource *E);
1249 
1250  void PrintStats() const;
1251 
1252  /// Helper class that creates diagnostics with optional
1253  /// template instantiation stacks.
1254  ///
1255  /// This class provides a wrapper around the basic DiagnosticBuilder
1256  /// class that emits diagnostics. SemaDiagnosticBuilder is
1257  /// responsible for emitting the diagnostic (as DiagnosticBuilder
1258  /// does) and, if the diagnostic comes from inside a template
1259  /// instantiation, printing the template instantiation stack as
1260  /// well.
1262  Sema &SemaRef;
1263  unsigned DiagID;
1264 
1265  public:
1266  SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID)
1267  : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { }
1268 
1269  // This is a cunning lie. DiagnosticBuilder actually performs move
1270  // construction in its copy constructor (but due to varied uses, it's not
1271  // possible to conveniently express this as actual move construction). So
1272  // the default copy ctor here is fine, because the base class disables the
1273  // source anyway, so the user-defined ~SemaDiagnosticBuilder is a safe no-op
1274  // in that case anwyay.
1275  SemaDiagnosticBuilder(const SemaDiagnosticBuilder&) = default;
1276 
1278  // If we aren't active, there is nothing to do.
1279  if (!isActive()) return;
1280 
1281  // Otherwise, we need to emit the diagnostic. First flush the underlying
1282  // DiagnosticBuilder data, and clear the diagnostic builder itself so it
1283  // won't emit the diagnostic in its own destructor.
1284  //
1285  // This seems wasteful, in that as written the DiagnosticBuilder dtor will
1286  // do its own needless checks to see if the diagnostic needs to be
1287  // emitted. However, because we take care to ensure that the builder
1288  // objects never escape, a sufficiently smart compiler will be able to
1289  // eliminate that code.
1290  FlushCounts();
1291  Clear();
1292 
1293  // Dispatch to Sema to emit the diagnostic.
1294  SemaRef.EmitCurrentDiagnostic(DiagID);
1295  }
1296 
1297  /// Teach operator<< to produce an object of the correct type.
1298  template<typename T>
1300  const SemaDiagnosticBuilder &Diag, const T &Value) {
1301  const DiagnosticBuilder &BaseDiag = Diag;
1302  BaseDiag << Value;
1303  return Diag;
1304  }
1305  };
1306 
1307  /// Emit a diagnostic.
1309  DiagnosticBuilder DB = Diags.Report(Loc, DiagID);
1310  return SemaDiagnosticBuilder(DB, *this, DiagID);
1311  }
1312 
1313  /// Emit a partial diagnostic.
1315 
1316  /// Build a partial diagnostic.
1317  PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h
1318 
1319  bool findMacroSpelling(SourceLocation &loc, StringRef name);
1320 
1321  /// Get a string to suggest for zero-initialization of a type.
1322  std::string
1323  getFixItZeroInitializerForType(QualType T, SourceLocation Loc) const;
1324  std::string getFixItZeroLiteralForType(QualType T, SourceLocation Loc) const;
1325 
1326  /// Calls \c Lexer::getLocForEndOfToken()
1327  SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset = 0);
1328 
1329  /// Retrieve the module loader associated with the preprocessor.
1330  ModuleLoader &getModuleLoader() const;
1331 
1332  void emitAndClearUnusedLocalTypedefWarnings();
1333 
1334  void ActOnStartOfTranslationUnit();
1335  void ActOnEndOfTranslationUnit();
1336 
1337  void CheckDelegatingCtorCycles();
1338 
1339  Scope *getScopeForContext(DeclContext *Ctx);
1340 
1341  void PushFunctionScope();
1342  void PushBlockScope(Scope *BlockScope, BlockDecl *Block);
1343  sema::LambdaScopeInfo *PushLambdaScope();
1344 
1345  /// This is used to inform Sema what the current TemplateParameterDepth
1346  /// is during Parsing. Currently it is used to pass on the depth
1347  /// when parsing generic lambda 'auto' parameters.
1348  void RecordParsingTemplateParameterDepth(unsigned Depth);
1349 
1350  void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD,
1351  RecordDecl *RD,
1352  CapturedRegionKind K);
1353  void
1354  PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP = nullptr,
1355  const Decl *D = nullptr,
1356  const BlockExpr *blkExpr = nullptr);
1357 
1359  return FunctionScopes.empty() ? nullptr : FunctionScopes.back();
1360  }
1361 
1362  sema::FunctionScopeInfo *getEnclosingFunction() const;
1363 
1364  void setFunctionHasBranchIntoScope();
1365  void setFunctionHasBranchProtectedScope();
1366  void setFunctionHasIndirectGoto();
1367 
1368  void PushCompoundScope(bool IsStmtExpr);
1369  void PopCompoundScope();
1370 
1371  sema::CompoundScopeInfo &getCurCompoundScope() const;
1372  bool isCurCompoundStmtAStmtExpr() const;
1373 
1374  bool hasAnyUnrecoverableErrorsInThisFunction() const;
1375 
1376  /// Retrieve the current block, if any.
1377  sema::BlockScopeInfo *getCurBlock();
1378 
1379  /// Retrieve the current lambda scope info, if any.
1380  /// \param IgnoreNonLambdaCapturingScope true if should find the top-most
1381  /// lambda scope info ignoring all inner capturing scopes that are not
1382  /// lambda scopes.
1384  getCurLambda(bool IgnoreNonLambdaCapturingScope = false);
1385 
1386  /// Retrieve the current generic lambda info, if any.
1387  sema::LambdaScopeInfo *getCurGenericLambda();
1388 
1389  /// Retrieve the current captured region, if any.
1390  sema::CapturedRegionScopeInfo *getCurCapturedRegion();
1391 
1392  /// WeakTopLevelDeclDecls - access to \#pragma weak-generated Decls
1393  SmallVectorImpl<Decl *> &WeakTopLevelDecls() { return WeakTopLevelDecl; }
1394 
1395  void ActOnComment(SourceRange Comment);
1396 
1397  //===--------------------------------------------------------------------===//
1398  // Type Analysis / Processing: SemaType.cpp.
1399  //
1400 
1401  QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs,
1402  const DeclSpec *DS = nullptr);
1403  QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVRA,
1404  const DeclSpec *DS = nullptr);
1405  QualType BuildPointerType(QualType T,
1406  SourceLocation Loc, DeclarationName Entity);
1407  QualType BuildReferenceType(QualType T, bool LValueRef,
1408  SourceLocation Loc, DeclarationName Entity);
1409  QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
1410  Expr *ArraySize, unsigned Quals,
1411  SourceRange Brackets, DeclarationName Entity);
1412  QualType BuildVectorType(QualType T, Expr *VecSize, SourceLocation AttrLoc);
1413  QualType BuildExtVectorType(QualType T, Expr *ArraySize,
1414  SourceLocation AttrLoc);
1415  QualType BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace,
1416  SourceLocation AttrLoc);
1417 
1418  bool CheckFunctionReturnType(QualType T, SourceLocation Loc);
1419 
1420  /// Build a function type.
1421  ///
1422  /// This routine checks the function type according to C++ rules and
1423  /// under the assumption that the result type and parameter types have
1424  /// just been instantiated from a template. It therefore duplicates
1425  /// some of the behavior of GetTypeForDeclarator, but in a much
1426  /// simpler form that is only suitable for this narrow use case.
1427  ///
1428  /// \param T The return type of the function.
1429  ///
1430  /// \param ParamTypes The parameter types of the function. This array
1431  /// will be modified to account for adjustments to the types of the
1432  /// function parameters.
1433  ///
1434  /// \param Loc The location of the entity whose type involves this
1435  /// function type or, if there is no such entity, the location of the
1436  /// type that will have function type.
1437  ///
1438  /// \param Entity The name of the entity that involves the function
1439  /// type, if known.
1440  ///
1441  /// \param EPI Extra information about the function type. Usually this will
1442  /// be taken from an existing function with the same prototype.
1443  ///
1444  /// \returns A suitable function type, if there are no errors. The
1445  /// unqualified type will always be a FunctionProtoType.
1446  /// Otherwise, returns a NULL type.
1447  QualType BuildFunctionType(QualType T,
1448  MutableArrayRef<QualType> ParamTypes,
1449  SourceLocation Loc, DeclarationName Entity,
1450  const FunctionProtoType::ExtProtoInfo &EPI);
1451 
1452  QualType BuildMemberPointerType(QualType T, QualType Class,
1453  SourceLocation Loc,
1454  DeclarationName Entity);
1455  QualType BuildBlockPointerType(QualType T,
1456  SourceLocation Loc, DeclarationName Entity);
1457  QualType BuildParenType(QualType T);
1458  QualType BuildAtomicType(QualType T, SourceLocation Loc);
1459  QualType BuildReadPipeType(QualType T,
1460  SourceLocation Loc);
1461  QualType BuildWritePipeType(QualType T,
1462  SourceLocation Loc);
1463 
1464  TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S);
1465  TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy);
1466 
1467  /// Package the given type and TSI into a ParsedType.
1468  ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo);
1469  DeclarationNameInfo GetNameForDeclarator(Declarator &D);
1470  DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name);
1471  static QualType GetTypeFromParser(ParsedType Ty,
1472  TypeSourceInfo **TInfo = nullptr);
1473  CanThrowResult canThrow(const Expr *E);
1474  const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc,
1475  const FunctionProtoType *FPT);
1476  void UpdateExceptionSpec(FunctionDecl *FD,
1478  bool CheckSpecifiedExceptionType(QualType &T, SourceRange Range);
1479  bool CheckDistantExceptionSpec(QualType T);
1480  bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New);
1481  bool CheckEquivalentExceptionSpec(
1482  const FunctionProtoType *Old, SourceLocation OldLoc,
1483  const FunctionProtoType *New, SourceLocation NewLoc);
1484  bool CheckEquivalentExceptionSpec(
1485  const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
1486  const FunctionProtoType *Old, SourceLocation OldLoc,
1487  const FunctionProtoType *New, SourceLocation NewLoc);
1488  bool handlerCanCatch(QualType HandlerType, QualType ExceptionType);
1489  bool CheckExceptionSpecSubset(const PartialDiagnostic &DiagID,
1490  const PartialDiagnostic &NestedDiagID,
1491  const PartialDiagnostic &NoteID,
1492  const FunctionProtoType *Superset,
1493  SourceLocation SuperLoc,
1494  const FunctionProtoType *Subset,
1495  SourceLocation SubLoc);
1496  bool CheckParamExceptionSpec(const PartialDiagnostic &NestedDiagID,
1497  const PartialDiagnostic &NoteID,
1498  const FunctionProtoType *Target,
1499  SourceLocation TargetLoc,
1500  const FunctionProtoType *Source,
1501  SourceLocation SourceLoc);
1502 
1503  TypeResult ActOnTypeName(Scope *S, Declarator &D);
1504 
1505  /// The parser has parsed the context-sensitive type 'instancetype'
1506  /// in an Objective-C message declaration. Return the appropriate type.
1507  ParsedType ActOnObjCInstanceType(SourceLocation Loc);
1508 
1509  /// Abstract class used to diagnose incomplete types.
1510  struct TypeDiagnoser {
1512 
1513  virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0;
1514  virtual ~TypeDiagnoser() {}
1515  };
1516 
1517  static int getPrintable(int I) { return I; }
1518  static unsigned getPrintable(unsigned I) { return I; }
1519  static bool getPrintable(bool B) { return B; }
1520  static const char * getPrintable(const char *S) { return S; }
1521  static StringRef getPrintable(StringRef S) { return S; }
1522  static const std::string &getPrintable(const std::string &S) { return S; }
1523  static const IdentifierInfo *getPrintable(const IdentifierInfo *II) {
1524  return II;
1525  }
1527  static QualType getPrintable(QualType T) { return T; }
1528  static SourceRange getPrintable(SourceRange R) { return R; }
1529  static SourceRange getPrintable(SourceLocation L) { return L; }
1530  static SourceRange getPrintable(const Expr *E) { return E->getSourceRange(); }
1531  static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();}
1532 
1533  template <typename... Ts> class BoundTypeDiagnoser : public TypeDiagnoser {
1534  unsigned DiagID;
1535  std::tuple<const Ts &...> Args;
1536 
1537  template <std::size_t... Is>
1538  void emit(const SemaDiagnosticBuilder &DB,
1539  llvm::index_sequence<Is...>) const {
1540  // Apply all tuple elements to the builder in order.
1541  bool Dummy[] = {false, (DB << getPrintable(std::get<Is>(Args)))...};
1542  (void)Dummy;
1543  }
1544 
1545  public:
1546  BoundTypeDiagnoser(unsigned DiagID, const Ts &...Args)
1547  : TypeDiagnoser(), DiagID(DiagID), Args(Args...) {
1548  assert(DiagID != 0 && "no diagnostic for type diagnoser");
1549  }
1550 
1551  void diagnose(Sema &S, SourceLocation Loc, QualType T) override {
1552  const SemaDiagnosticBuilder &DB = S.Diag(Loc, DiagID);
1553  emit(DB, llvm::index_sequence_for<Ts...>());
1554  DB << T;
1555  }
1556  };
1557 
1558 private:
1559  /// Methods for marking which expressions involve dereferencing a pointer
1560  /// marked with the 'noderef' attribute. Expressions are checked bottom up as
1561  /// they are parsed, meaning that a noderef pointer may not be accessed. For
1562  /// example, in `&*p` where `p` is a noderef pointer, we will first parse the
1563  /// `*p`, but need to check that `address of` is called on it. This requires
1564  /// keeping a container of all pending expressions and checking if the address
1565  /// of them are eventually taken.
1566  void CheckSubscriptAccessOfNoDeref(const ArraySubscriptExpr *E);
1567  void CheckAddressOfNoDeref(const Expr *E);
1568  void CheckMemberAccessOfNoDeref(const MemberExpr *E);
1569 
1570  bool RequireCompleteTypeImpl(SourceLocation Loc, QualType T,
1571  TypeDiagnoser *Diagnoser);
1572 
1573  struct ModuleScope {
1574  clang::Module *Module = nullptr;
1575  bool ModuleInterface = false;
1576  VisibleModuleSet OuterVisibleModules;
1577  };
1578  /// The modules we're currently parsing.
1580 
1581  /// Get the module whose scope we are currently within.
1582  Module *getCurrentModule() const {
1583  return ModuleScopes.empty() ? nullptr : ModuleScopes.back().Module;
1584  }
1585 
1586  VisibleModuleSet VisibleModules;
1587 
1588 public:
1589  /// Get the module owning an entity.
1590  Module *getOwningModule(Decl *Entity) { return Entity->getOwningModule(); }
1591 
1592  /// Make a merged definition of an existing hidden definition \p ND
1593  /// visible at the specified location.
1594  void makeMergedDefinitionVisible(NamedDecl *ND);
1595 
1596  bool isModuleVisible(const Module *M, bool ModulePrivate = false);
1597 
1598  /// Determine whether a declaration is visible to name lookup.
1599  bool isVisible(const NamedDecl *D) {
1600  return !D->isHidden() || isVisibleSlow(D);
1601  }
1602 
1603  /// Determine whether any declaration of an entity is visible.
1604  bool
1606  llvm::SmallVectorImpl<Module *> *Modules = nullptr) {
1607  return isVisible(D) || hasVisibleDeclarationSlow(D, Modules);
1608  }
1609  bool hasVisibleDeclarationSlow(const NamedDecl *D,
1611 
1612  bool hasVisibleMergedDefinition(NamedDecl *Def);
1613  bool hasMergedDefinitionInCurrentModule(NamedDecl *Def);
1614 
1615  /// Determine if \p D and \p Suggested have a structurally compatible
1616  /// layout as described in C11 6.2.7/1.
1617  bool hasStructuralCompatLayout(Decl *D, Decl *Suggested);
1618 
1619  /// Determine if \p D has a visible definition. If not, suggest a declaration
1620  /// that should be made visible to expose the definition.
1621  bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested,
1622  bool OnlyNeedComplete = false);
1624  NamedDecl *Hidden;
1625  return hasVisibleDefinition(const_cast<NamedDecl*>(D), &Hidden);
1626  }
1627 
1628  /// Determine if the template parameter \p D has a visible default argument.
1629  bool
1631  llvm::SmallVectorImpl<Module *> *Modules = nullptr);
1632 
1633  /// Determine if there is a visible declaration of \p D that is an explicit
1634  /// specialization declaration for a specialization of a template. (For a
1635  /// member specialization, use hasVisibleMemberSpecialization.)
1636  bool hasVisibleExplicitSpecialization(
1637  const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr);
1638 
1639  /// Determine if there is a visible declaration of \p D that is a member
1640  /// specialization declaration (as opposed to an instantiated declaration).
1641  bool hasVisibleMemberSpecialization(
1642  const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr);
1643 
1644  /// Determine if \p A and \p B are equivalent internal linkage declarations
1645  /// from different modules, and thus an ambiguity error can be downgraded to
1646  /// an extension warning.
1647  bool isEquivalentInternalLinkageDeclaration(const NamedDecl *A,
1648  const NamedDecl *B);
1649  void diagnoseEquivalentInternalLinkageDeclarations(
1650  SourceLocation Loc, const NamedDecl *D,
1652 
1653  bool isUsualDeallocationFunction(const CXXMethodDecl *FD);
1654 
1656  return !RequireCompleteTypeImpl(Loc, T, nullptr);
1657  }
1658  bool RequireCompleteType(SourceLocation Loc, QualType T,
1659  TypeDiagnoser &Diagnoser);
1660  bool RequireCompleteType(SourceLocation Loc, QualType T,
1661  unsigned DiagID);
1662 
1663  template <typename... Ts>
1664  bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID,
1665  const Ts &...Args) {
1666  BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...);
1667  return RequireCompleteType(Loc, T, Diagnoser);
1668  }
1669 
1670  void completeExprArrayBound(Expr *E);
1671  bool RequireCompleteExprType(Expr *E, TypeDiagnoser &Diagnoser);
1672  bool RequireCompleteExprType(Expr *E, unsigned DiagID);
1673 
1674  template <typename... Ts>
1675  bool RequireCompleteExprType(Expr *E, unsigned DiagID, const Ts &...Args) {
1676  BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...);
1677  return RequireCompleteExprType(E, Diagnoser);
1678  }
1679 
1680  bool RequireLiteralType(SourceLocation Loc, QualType T,
1681  TypeDiagnoser &Diagnoser);
1682  bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID);
1683 
1684  template <typename... Ts>
1685  bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID,
1686  const Ts &...Args) {
1687  BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...);
1688  return RequireLiteralType(Loc, T, Diagnoser);
1689  }
1690 
1691  QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
1692  const CXXScopeSpec &SS, QualType T,
1693  TagDecl *OwnedTagDecl = nullptr);
1694 
1695  QualType BuildTypeofExprType(Expr *E, SourceLocation Loc);
1696  /// If AsUnevaluated is false, E is treated as though it were an evaluated
1697  /// context, such as when building a type for decltype(auto).
1698  QualType BuildDecltypeType(Expr *E, SourceLocation Loc,
1699  bool AsUnevaluated = true);
1700  QualType BuildUnaryTransformType(QualType BaseType,
1702  SourceLocation Loc);
1703 
1704  //===--------------------------------------------------------------------===//
1705  // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
1706  //
1707 
1708  struct SkipBodyInfo {
1710  : ShouldSkip(false), CheckSameAsPrevious(false), Previous(nullptr),
1711  New(nullptr) {}
1716  };
1717 
1718  DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = nullptr);
1719 
1720  void DiagnoseUseOfUnimplementedSelectors();
1721 
1722  bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
1723 
1725  Scope *S, CXXScopeSpec *SS = nullptr,
1726  bool isClassName = false, bool HasTrailingDot = false,
1727  ParsedType ObjectType = nullptr,
1728  bool IsCtorOrDtorName = false,
1729  bool WantNontrivialTypeSourceInfo = false,
1730  bool IsClassTemplateDeductionContext = true,
1731  IdentifierInfo **CorrectedII = nullptr);
1732  TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S);
1733  bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S);
1734  void DiagnoseUnknownTypeName(IdentifierInfo *&II,
1735  SourceLocation IILoc,
1736  Scope *S,
1737  CXXScopeSpec *SS,
1738  ParsedType &SuggestedType,
1739  bool IsTemplateName = false);
1740 
1741  /// Attempt to behave like MSVC in situations where lookup of an unqualified
1742  /// type name has failed in a dependent context. In these situations, we
1743  /// automatically form a DependentTypeName that will retry lookup in a related
1744  /// scope during instantiation.
1745  ParsedType ActOnMSVCUnknownTypeName(const IdentifierInfo &II,
1746  SourceLocation NameLoc,
1747  bool IsTemplateTypeArg);
1748 
1749  /// Describes the result of the name lookup and resolution performed
1750  /// by \c ClassifyName().
1760  NC_FunctionTemplate
1761  };
1762 
1765  ExprResult Expr;
1766  TemplateName Template;
1767  ParsedType Type;
1768 
1769  explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {}
1770 
1771  public:
1772  NameClassification(ExprResult Expr) : Kind(NC_Expression), Expr(Expr) {}
1773 
1774  NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {}
1775 
1776  NameClassification(const IdentifierInfo *Keyword) : Kind(NC_Keyword) {}
1777 
1779  return NameClassification(NC_Error);
1780  }
1781 
1783  return NameClassification(NC_Unknown);
1784  }
1785 
1787  return NameClassification(NC_NestedNameSpecifier);
1788  }
1789 
1791  NameClassification Result(NC_TypeTemplate);
1792  Result.Template = Name;
1793  return Result;
1794  }
1795 
1797  NameClassification Result(NC_VarTemplate);
1798  Result.Template = Name;
1799  return Result;
1800  }
1801 
1803  NameClassification Result(NC_FunctionTemplate);
1804  Result.Template = Name;
1805  return Result;
1806  }
1807 
1809 
1811  assert(Kind == NC_Type);
1812  return Type;
1813  }
1814 
1816  assert(Kind == NC_Expression);
1817  return Expr;
1818  }
1819 
1821  assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate ||
1822  Kind == NC_VarTemplate);
1823  return Template;
1824  }
1825 
1827  switch (Kind) {
1828  case NC_TypeTemplate:
1829  return TNK_Type_template;
1830  case NC_FunctionTemplate:
1831  return TNK_Function_template;
1832  case NC_VarTemplate:
1833  return TNK_Var_template;
1834  default:
1835  llvm_unreachable("unsupported name classification.");
1836  }
1837  }
1838  };
1839 
1840  /// Perform name lookup on the given name, classifying it based on
1841  /// the results of name lookup and the following token.
1842  ///
1843  /// This routine is used by the parser to resolve identifiers and help direct
1844  /// parsing. When the identifier cannot be found, this routine will attempt
1845  /// to correct the typo and classify based on the resulting name.
1846  ///
1847  /// \param S The scope in which we're performing name lookup.
1848  ///
1849  /// \param SS The nested-name-specifier that precedes the name.
1850  ///
1851  /// \param Name The identifier. If typo correction finds an alternative name,
1852  /// this pointer parameter will be updated accordingly.
1853  ///
1854  /// \param NameLoc The location of the identifier.
1855  ///
1856  /// \param NextToken The token following the identifier. Used to help
1857  /// disambiguate the name.
1858  ///
1859  /// \param IsAddressOfOperand True if this name is the operand of a unary
1860  /// address of ('&') expression, assuming it is classified as an
1861  /// expression.
1862  ///
1863  /// \param CCC The correction callback, if typo correction is desired.
1865  ClassifyName(Scope *S, CXXScopeSpec &SS, IdentifierInfo *&Name,
1866  SourceLocation NameLoc, const Token &NextToken,
1867  bool IsAddressOfOperand,
1868  std::unique_ptr<CorrectionCandidateCallback> CCC = nullptr);
1869 
1870  /// Describes the detailed kind of a template name. Used in diagnostics.
1872  ClassTemplate,
1873  FunctionTemplate,
1874  VarTemplate,
1875  AliasTemplate,
1876  TemplateTemplateParam,
1877  DependentTemplate
1878  };
1880  getTemplateNameKindForDiagnostics(TemplateName Name);
1881 
1882  /// Determine whether it's plausible that E was intended to be a
1883  /// template-name.
1884  bool mightBeIntendedToBeTemplateName(ExprResult E, bool &Dependent) {
1885  if (!getLangOpts().CPlusPlus || E.isInvalid())
1886  return false;
1887  Dependent = false;
1888  if (auto *DRE = dyn_cast<DeclRefExpr>(E.get()))
1889  return !DRE->hasExplicitTemplateArgs();
1890  if (auto *ME = dyn_cast<MemberExpr>(E.get()))
1891  return !ME->hasExplicitTemplateArgs();
1892  Dependent = true;
1893  if (auto *DSDRE = dyn_cast<DependentScopeDeclRefExpr>(E.get()))
1894  return !DSDRE->hasExplicitTemplateArgs();
1895  if (auto *DSME = dyn_cast<CXXDependentScopeMemberExpr>(E.get()))
1896  return !DSME->hasExplicitTemplateArgs();
1897  // Any additional cases recognized here should also be handled by
1898  // diagnoseExprIntendedAsTemplateName.
1899  return false;
1900  }
1901  void diagnoseExprIntendedAsTemplateName(Scope *S, ExprResult TemplateName,
1904 
1905  Decl *ActOnDeclarator(Scope *S, Declarator &D);
1906 
1907  NamedDecl *HandleDeclarator(Scope *S, Declarator &D,
1908  MultiTemplateParamsArg TemplateParameterLists);
1909  void RegisterLocallyScopedExternCDecl(NamedDecl *ND, Scope *S);
1910  bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info);
1911  bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC,
1912  DeclarationName Name, SourceLocation Loc,
1913  bool IsTemplateId);
1914  void
1915  diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals,
1916  SourceLocation FallbackLoc,
1917  SourceLocation ConstQualLoc = SourceLocation(),
1918  SourceLocation VolatileQualLoc = SourceLocation(),
1919  SourceLocation RestrictQualLoc = SourceLocation(),
1920  SourceLocation AtomicQualLoc = SourceLocation(),
1921  SourceLocation UnalignedQualLoc = SourceLocation());
1922 
1923  static bool adjustContextForLocalExternDecl(DeclContext *&DC);
1924  void DiagnoseFunctionSpecifiers(const DeclSpec &DS);
1925  NamedDecl *getShadowedDeclaration(const TypedefNameDecl *D,
1926  const LookupResult &R);
1927  NamedDecl *getShadowedDeclaration(const VarDecl *D, const LookupResult &R);
1928  void CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl,
1929  const LookupResult &R);
1930  void CheckShadow(Scope *S, VarDecl *D);
1931 
1932  /// Warn if 'E', which is an expression that is about to be modified, refers
1933  /// to a shadowing declaration.
1934  void CheckShadowingDeclModification(Expr *E, SourceLocation Loc);
1935 
1936  void DiagnoseShadowingLambdaDecls(const sema::LambdaScopeInfo *LSI);
1937 
1938 private:
1939  /// Map of current shadowing declarations to shadowed declarations. Warn if
1940  /// it looks like the user is trying to modify the shadowing declaration.
1941  llvm::DenseMap<const NamedDecl *, const NamedDecl *> ShadowingDecls;
1942 
1943 public:
1944  void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange);
1945  void handleTagNumbering(const TagDecl *Tag, Scope *TagScope);
1946  void setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec,
1947  TypedefNameDecl *NewTD);
1948  void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D);
1949  NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
1950  TypeSourceInfo *TInfo,
1952  NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D,
1953  LookupResult &Previous, bool &Redeclaration);
1954  NamedDecl *ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
1955  TypeSourceInfo *TInfo,
1956  LookupResult &Previous,
1957  MultiTemplateParamsArg TemplateParamLists,
1958  bool &AddToScope,
1959  ArrayRef<BindingDecl *> Bindings = None);
1960  NamedDecl *
1961  ActOnDecompositionDeclarator(Scope *S, Declarator &D,
1962  MultiTemplateParamsArg TemplateParamLists);
1963  // Returns true if the variable declaration is a redeclaration
1964  bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous);
1965  void CheckVariableDeclarationType(VarDecl *NewVD);
1966  bool DeduceVariableDeclarationType(VarDecl *VDecl, bool DirectInit,
1967  Expr *&Init);
1968  void CheckCompleteVariableDeclaration(VarDecl *VD);
1969  void CheckCompleteDecompositionDeclaration(DecompositionDecl *DD);
1970  void MaybeSuggestAddingStaticToDecl(const FunctionDecl *D);
1971 
1972  NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
1973  TypeSourceInfo *TInfo,
1974  LookupResult &Previous,
1975  MultiTemplateParamsArg TemplateParamLists,
1976  bool &AddToScope);
1977  bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD);
1978 
1979  bool CheckConstexprFunctionDecl(const FunctionDecl *FD);
1980  bool CheckConstexprFunctionBody(const FunctionDecl *FD, Stmt *Body);
1981 
1982  void DiagnoseHiddenVirtualMethods(CXXMethodDecl *MD);
1983  void FindHiddenVirtualMethods(CXXMethodDecl *MD,
1984  SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods);
1985  void NoteHiddenVirtualMethods(CXXMethodDecl *MD,
1986  SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods);
1987  // Returns true if the function declaration is a redeclaration
1988  bool CheckFunctionDeclaration(Scope *S,
1989  FunctionDecl *NewFD, LookupResult &Previous,
1990  bool IsMemberSpecialization);
1991  bool shouldLinkDependentDeclWithPrevious(Decl *D, Decl *OldDecl);
1992  bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD,
1993  QualType NewT, QualType OldT);
1994  void CheckMain(FunctionDecl *FD, const DeclSpec &D);
1995  void CheckMSVCRTEntryPoint(FunctionDecl *FD);
1996  Attr *getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, bool IsDefinition);
1997  Decl *ActOnParamDeclarator(Scope *S, Declarator &D);
1998  ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC,
1999  SourceLocation Loc,
2000  QualType T);
2001  ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc,
2002  SourceLocation NameLoc, IdentifierInfo *Name,
2003  QualType T, TypeSourceInfo *TSInfo,
2004  StorageClass SC);
2005  void ActOnParamDefaultArgument(Decl *param,
2006  SourceLocation EqualLoc,
2007  Expr *defarg);
2008  void ActOnParamUnparsedDefaultArgument(Decl *param,
2009  SourceLocation EqualLoc,
2010  SourceLocation ArgLoc);
2011  void ActOnParamDefaultArgumentError(Decl *param, SourceLocation EqualLoc);
2012  bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg,
2013  SourceLocation EqualLoc);
2014 
2015  void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit);
2016  void ActOnUninitializedDecl(Decl *dcl);
2017  void ActOnInitializerError(Decl *Dcl);
2018 
2019  void ActOnPureSpecifier(Decl *D, SourceLocation PureSpecLoc);
2020  void ActOnCXXForRangeDecl(Decl *D);
2021  StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc,
2022  IdentifierInfo *Ident,
2023  ParsedAttributes &Attrs,
2024  SourceLocation AttrEnd);
2025  void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc);
2026  void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc);
2027  void CheckStaticLocalForDllExport(VarDecl *VD);
2028  void FinalizeDeclaration(Decl *D);
2029  DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS,
2030  ArrayRef<Decl *> Group);
2031  DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef<Decl *> Group);
2032 
2033  /// Should be called on all declarations that might have attached
2034  /// documentation comments.
2035  void ActOnDocumentableDecl(Decl *D);
2036  void ActOnDocumentableDecls(ArrayRef<Decl *> Group);
2037 
2038  void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
2039  SourceLocation LocAfterDecls);
2040  void CheckForFunctionRedefinition(
2041  FunctionDecl *FD, const FunctionDecl *EffectiveDefinition = nullptr,
2042  SkipBodyInfo *SkipBody = nullptr);
2043  Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D,
2044  MultiTemplateParamsArg TemplateParamLists,
2045  SkipBodyInfo *SkipBody = nullptr);
2046  Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D,
2047  SkipBodyInfo *SkipBody = nullptr);
2048  void ActOnStartOfObjCMethodDef(Scope *S, Decl *D);
2050  return D && isa<ObjCMethodDecl>(D);
2051  }
2052 
2053  /// Determine whether we can delay parsing the body of a function or
2054  /// function template until it is used, assuming we don't care about emitting
2055  /// code for that function.
2056  ///
2057  /// This will be \c false if we may need the body of the function in the
2058  /// middle of parsing an expression (where it's impractical to switch to
2059  /// parsing a different function), for instance, if it's constexpr in C++11
2060  /// or has an 'auto' return type in C++14. These cases are essentially bugs.
2061  bool canDelayFunctionBody(const Declarator &D);
2062 
2063  /// Determine whether we can skip parsing the body of a function
2064  /// definition, assuming we don't care about analyzing its body or emitting
2065  /// code for that function.
2066  ///
2067  /// This will be \c false only if we may need the body of the function in
2068  /// order to parse the rest of the program (for instance, if it is
2069  /// \c constexpr in C++11 or has an 'auto' return type in C++14).
2070  bool canSkipFunctionBody(Decl *D);
2071 
2072  void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope);
2073  Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body);
2074  Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation);
2075  Decl *ActOnSkippedFunctionBody(Decl *Decl);
2076  void ActOnFinishInlineFunctionDef(FunctionDecl *D);
2077 
2078  /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an
2079  /// attribute for which parsing is delayed.
2080  void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs);
2081 
2082  /// Diagnose any unused parameters in the given sequence of
2083  /// ParmVarDecl pointers.
2084  void DiagnoseUnusedParameters(ArrayRef<ParmVarDecl *> Parameters);
2085 
2086  /// Diagnose whether the size of parameters or return value of a
2087  /// function or obj-c method definition is pass-by-value and larger than a
2088  /// specified threshold.
2089  void
2090  DiagnoseSizeOfParametersAndReturnValue(ArrayRef<ParmVarDecl *> Parameters,
2091  QualType ReturnTy, NamedDecl *D);
2092 
2093  void DiagnoseInvalidJumps(Stmt *Body);
2094  Decl *ActOnFileScopeAsmDecl(Expr *expr,
2095  SourceLocation AsmLoc,
2096  SourceLocation RParenLoc);
2097 
2098  /// Handle a C++11 empty-declaration and attribute-declaration.
2099  Decl *ActOnEmptyDeclaration(Scope *S, const ParsedAttributesView &AttrList,
2100  SourceLocation SemiLoc);
2101 
2102  enum class ModuleDeclKind {
2103  Interface, ///< 'export module X;'
2104  Implementation, ///< 'module X;'
2105  Partition, ///< 'module partition X;'
2106  };
2107 
2108  /// The parser has processed a module-declaration that begins the definition
2109  /// of a module interface or implementation.
2110  DeclGroupPtrTy ActOnModuleDecl(SourceLocation StartLoc,
2111  SourceLocation ModuleLoc, ModuleDeclKind MDK,
2112  ModuleIdPath Path);
2113 
2114  /// The parser has processed a module import declaration.
2115  ///
2116  /// \param AtLoc The location of the '@' symbol, if any.
2117  ///
2118  /// \param ImportLoc The location of the 'import' keyword.
2119  ///
2120  /// \param Path The module access path.
2121  DeclResult ActOnModuleImport(SourceLocation AtLoc, SourceLocation ImportLoc,
2122  ModuleIdPath Path);
2123 
2124  /// The parser has processed a module import translated from a
2125  /// #include or similar preprocessing directive.
2126  void ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod);
2127  void BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod);
2128 
2129  /// The parsed has entered a submodule.
2130  void ActOnModuleBegin(SourceLocation DirectiveLoc, Module *Mod);
2131  /// The parser has left a submodule.
2132  void ActOnModuleEnd(SourceLocation DirectiveLoc, Module *Mod);
2133 
2134  /// Create an implicit import of the given module at the given
2135  /// source location, for error recovery, if possible.
2136  ///
2137  /// This routine is typically used when an entity found by name lookup
2138  /// is actually hidden within a module that we know about but the user
2139  /// has forgotten to import.
2140  void createImplicitModuleImportForErrorRecovery(SourceLocation Loc,
2141  Module *Mod);
2142 
2143  /// Kinds of missing import. Note, the values of these enumerators correspond
2144  /// to %select values in diagnostics.
2145  enum class MissingImportKind {
2146  Declaration,
2147  Definition,
2148  DefaultArgument,
2149  ExplicitSpecialization,
2150  PartialSpecialization
2151  };
2152 
2153  /// Diagnose that the specified declaration needs to be visible but
2154  /// isn't, and suggest a module import that would resolve the problem.
2155  void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl,
2156  MissingImportKind MIK, bool Recover = true);
2157  void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl,
2158  SourceLocation DeclLoc, ArrayRef<Module *> Modules,
2159  MissingImportKind MIK, bool Recover);
2160 
2161  Decl *ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc,
2162  SourceLocation LBraceLoc);
2163  Decl *ActOnFinishExportDecl(Scope *S, Decl *ExportDecl,
2164  SourceLocation RBraceLoc);
2165 
2166  /// We've found a use of a templated declaration that would trigger an
2167  /// implicit instantiation. Check that any relevant explicit specializations
2168  /// and partial specializations are visible, and diagnose if not.
2169  void checkSpecializationVisibility(SourceLocation Loc, NamedDecl *Spec);
2170 
2171  /// We've found a use of a template specialization that would select a
2172  /// partial specialization. Check that the partial specialization is visible,
2173  /// and diagnose if not.
2174  void checkPartialSpecializationVisibility(SourceLocation Loc,
2175  NamedDecl *Spec);
2176 
2177  /// Retrieve a suitable printing policy for diagnostics.
2179  return getPrintingPolicy(Context, PP);
2180  }
2181 
2182  /// Retrieve a suitable printing policy for diagnostics.
2183  static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx,
2184  const Preprocessor &PP);
2185 
2186  /// Scope actions.
2187  void ActOnPopScope(SourceLocation Loc, Scope *S);
2188  void ActOnTranslationUnitScope(Scope *S);
2189 
2190  Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS,
2191  RecordDecl *&AnonRecord);
2192  Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS,
2193  MultiTemplateParamsArg TemplateParams,
2194  bool IsExplicitInstantiation,
2195  RecordDecl *&AnonRecord);
2196 
2197  Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
2198  AccessSpecifier AS,
2199  RecordDecl *Record,
2200  const PrintingPolicy &Policy);
2201 
2202  Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS,
2203  RecordDecl *Record);
2204 
2205  /// Common ways to introduce type names without a tag for use in diagnostics.
2206  /// Keep in sync with err_tag_reference_non_tag.
2207  enum NonTagKind {
2217  };
2218 
2219  /// Given a non-tag type declaration, returns an enum useful for indicating
2220  /// what kind of non-tag type this is.
2221  NonTagKind getNonTagTypeDeclKind(const Decl *D, TagTypeKind TTK);
2222 
2223  bool isAcceptableTagRedeclaration(const TagDecl *Previous,
2224  TagTypeKind NewTag, bool isDefinition,
2225  SourceLocation NewTagLoc,
2226  const IdentifierInfo *Name);
2227 
2228  enum TagUseKind {
2229  TUK_Reference, // Reference to a tag: 'struct foo *X;'
2230  TUK_Declaration, // Fwd decl of a tag: 'struct foo;'
2231  TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;'
2232  TUK_Friend // Friend declaration: 'friend struct foo;'
2233  };
2234 
2235  Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
2236  SourceLocation KWLoc, CXXScopeSpec &SS, IdentifierInfo *Name,
2237  SourceLocation NameLoc, const ParsedAttributesView &Attr,
2238  AccessSpecifier AS, SourceLocation ModulePrivateLoc,
2239  MultiTemplateParamsArg TemplateParameterLists, bool &OwnedDecl,
2240  bool &IsDependent, SourceLocation ScopedEnumKWLoc,
2241  bool ScopedEnumUsesClassTag, TypeResult UnderlyingType,
2242  bool IsTypeSpecifier, bool IsTemplateParamOrArg,
2243  SkipBodyInfo *SkipBody = nullptr);
2244 
2245  Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc,
2246  unsigned TagSpec, SourceLocation TagLoc,
2247  CXXScopeSpec &SS, IdentifierInfo *Name,
2248  SourceLocation NameLoc,
2249  const ParsedAttributesView &Attr,
2250  MultiTemplateParamsArg TempParamLists);
2251 
2252  TypeResult ActOnDependentTag(Scope *S,
2253  unsigned TagSpec,
2254  TagUseKind TUK,
2255  const CXXScopeSpec &SS,
2256  IdentifierInfo *Name,
2257  SourceLocation TagLoc,
2258  SourceLocation NameLoc);
2259 
2260  void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart,
2261  IdentifierInfo *ClassName,
2262  SmallVectorImpl<Decl *> &Decls);
2263  Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart,
2264  Declarator &D, Expr *BitfieldWidth);
2265 
2266  FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
2267  Declarator &D, Expr *BitfieldWidth,
2268  InClassInitStyle InitStyle,
2269  AccessSpecifier AS);
2270  MSPropertyDecl *HandleMSProperty(Scope *S, RecordDecl *TagD,
2271  SourceLocation DeclStart, Declarator &D,
2272  Expr *BitfieldWidth,
2273  InClassInitStyle InitStyle,
2274  AccessSpecifier AS,
2275  const ParsedAttr &MSPropertyAttr);
2276 
2277  FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T,
2278  TypeSourceInfo *TInfo,
2279  RecordDecl *Record, SourceLocation Loc,
2280  bool Mutable, Expr *BitfieldWidth,
2281  InClassInitStyle InitStyle,
2282  SourceLocation TSSL,
2283  AccessSpecifier AS, NamedDecl *PrevDecl,
2284  Declarator *D = nullptr);
2285 
2286  bool CheckNontrivialField(FieldDecl *FD);
2287  void DiagnoseNontrivial(const CXXRecordDecl *Record, CXXSpecialMember CSM);
2288 
2290  /// The triviality of a method unaffected by "trivial_abi".
2292 
2293  /// The triviality of a method affected by "trivial_abi".
2294  TAH_ConsiderTrivialABI
2295  };
2296 
2297  bool SpecialMemberIsTrivial(CXXMethodDecl *MD, CXXSpecialMember CSM,
2298  TrivialABIHandling TAH = TAH_IgnoreTrivialABI,
2299  bool Diagnose = false);
2300  CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD);
2301  void ActOnLastBitfield(SourceLocation DeclStart,
2302  SmallVectorImpl<Decl *> &AllIvarDecls);
2303  Decl *ActOnIvar(Scope *S, SourceLocation DeclStart,
2304  Declarator &D, Expr *BitfieldWidth,
2305  tok::ObjCKeywordKind visibility);
2306 
2307  // This is used for both record definitions and ObjC interface declarations.
2308  void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl,
2309  ArrayRef<Decl *> Fields, SourceLocation LBrac,
2310  SourceLocation RBrac, const ParsedAttributesView &AttrList);
2311 
2312  /// ActOnTagStartDefinition - Invoked when we have entered the
2313  /// scope of a tag's definition (e.g., for an enumeration, class,
2314  /// struct, or union).
2315  void ActOnTagStartDefinition(Scope *S, Decl *TagDecl);
2316 
2317  /// Perform ODR-like check for C/ObjC when merging tag types from modules.
2318  /// Differently from C++, actually parse the body and reject / error out
2319  /// in case of a structural mismatch.
2320  bool ActOnDuplicateDefinition(DeclSpec &DS, Decl *Prev,
2321  SkipBodyInfo &SkipBody);
2322 
2324 
2325  /// Invoked when we enter a tag definition that we're skipping.
2326  SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD);
2327 
2328  Decl *ActOnObjCContainerStartDefinition(Decl *IDecl);
2329 
2330  /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a
2331  /// C++ record definition's base-specifiers clause and are starting its
2332  /// member declarations.
2333  void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl,
2334  SourceLocation FinalLoc,
2335  bool IsFinalSpelledSealed,
2336  SourceLocation LBraceLoc);
2337 
2338  /// ActOnTagFinishDefinition - Invoked once we have finished parsing
2339  /// the definition of a tag (enumeration, class, struct, or union).
2340  void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl,
2341  SourceRange BraceRange);
2342 
2343  void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context);
2344 
2345  void ActOnObjCContainerFinishDefinition();
2346 
2347  /// Invoked when we must temporarily exit the objective-c container
2348  /// scope for parsing/looking-up C constructs.
2349  ///
2350  /// Must be followed by a call to \see ActOnObjCReenterContainerContext
2351  void ActOnObjCTemporaryExitContainerContext(DeclContext *DC);
2352  void ActOnObjCReenterContainerContext(DeclContext *DC);
2353 
2354  /// ActOnTagDefinitionError - Invoked when there was an unrecoverable
2355  /// error parsing the definition of a tag.
2356  void ActOnTagDefinitionError(Scope *S, Decl *TagDecl);
2357 
2358  EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum,
2359  EnumConstantDecl *LastEnumConst,
2360  SourceLocation IdLoc,
2361  IdentifierInfo *Id,
2362  Expr *val);
2363  bool CheckEnumUnderlyingType(TypeSourceInfo *TI);
2364  bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped,
2365  QualType EnumUnderlyingTy, bool IsFixed,
2366  const EnumDecl *Prev);
2367 
2368  /// Determine whether the body of an anonymous enumeration should be skipped.
2369  /// \param II The name of the first enumerator.
2370  SkipBodyInfo shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II,
2371  SourceLocation IILoc);
2372 
2373  Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant,
2375  const ParsedAttributesView &Attrs,
2376  SourceLocation EqualLoc, Expr *Val);
2377  void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange,
2378  Decl *EnumDecl, ArrayRef<Decl *> Elements, Scope *S,
2379  const ParsedAttributesView &Attr);
2380 
2381  DeclContext *getContainingDC(DeclContext *DC);
2382 
2383  /// Set the current declaration context until it gets popped.
2384  void PushDeclContext(Scope *S, DeclContext *DC);
2385  void PopDeclContext();
2386 
2387  /// EnterDeclaratorContext - Used when we must lookup names in the context
2388  /// of a declarator's nested name specifier.
2389  void EnterDeclaratorContext(Scope *S, DeclContext *DC);
2390  void ExitDeclaratorContext(Scope *S);
2391 
2392  /// Push the parameters of D, which must be a function, into scope.
2393  void ActOnReenterFunctionContext(Scope* S, Decl* D);
2394  void ActOnExitFunctionContext();
2395 
2396  DeclContext *getFunctionLevelDeclContext();
2397 
2398  /// getCurFunctionDecl - If inside of a function body, this returns a pointer
2399  /// to the function decl for the function being parsed. If we're currently
2400  /// in a 'block', this returns the containing context.
2401  FunctionDecl *getCurFunctionDecl();
2402 
2403  /// getCurMethodDecl - If inside of a method body, this returns a pointer to
2404  /// the method decl for the method being parsed. If we're currently
2405  /// in a 'block', this returns the containing context.
2406  ObjCMethodDecl *getCurMethodDecl();
2407 
2408  /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
2409  /// or C function we're in, otherwise return null. If we're currently
2410  /// in a 'block', this returns the containing context.
2411  NamedDecl *getCurFunctionOrMethodDecl();
2412 
2413  /// Add this decl to the scope shadowed decl chains.
2414  void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true);
2415 
2416  /// Make the given externally-produced declaration visible at the
2417  /// top level scope.
2418  ///
2419  /// \param D The externally-produced declaration to push.
2420  ///
2421  /// \param Name The name of the externally-produced declaration.
2422  void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name);
2423 
2424  /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
2425  /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
2426  /// true if 'D' belongs to the given declaration context.
2427  ///
2428  /// \param AllowInlineNamespace If \c true, allow the declaration to be in the
2429  /// enclosing namespace set of the context, rather than contained
2430  /// directly within it.
2431  bool isDeclInScope(NamedDecl *D, DeclContext *Ctx, Scope *S = nullptr,
2432  bool AllowInlineNamespace = false);
2433 
2434  /// Finds the scope corresponding to the given decl context, if it
2435  /// happens to be an enclosing scope. Otherwise return NULL.
2436  static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC);
2437 
2438  /// Subroutines of ActOnDeclarator().
2439  TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
2440  TypeSourceInfo *TInfo);
2441  bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New);
2442 
2443  /// Describes the kind of merge to perform for availability
2444  /// attributes (including "deprecated", "unavailable", and "availability").
2446  /// Don't merge availability attributes at all.
2448  /// Merge availability attributes for a redeclaration, which requires
2449  /// an exact match.
2451  /// Merge availability attributes for an override, which requires
2452  /// an exact match or a weakening of constraints.
2454  /// Merge availability attributes for an implementation of
2455  /// a protocol requirement.
2457  };
2458 
2459  /// Attribute merging methods. Return true if a new attribute was added.
2460  AvailabilityAttr *mergeAvailabilityAttr(NamedDecl *D, SourceRange Range,
2461  IdentifierInfo *Platform,
2462  bool Implicit,
2463  VersionTuple Introduced,
2464  VersionTuple Deprecated,
2465  VersionTuple Obsoleted,
2466  bool IsUnavailable,
2467  StringRef Message,
2468  bool IsStrict, StringRef Replacement,
2470  unsigned AttrSpellingListIndex);
2471  TypeVisibilityAttr *mergeTypeVisibilityAttr(Decl *D, SourceRange Range,
2472  TypeVisibilityAttr::VisibilityType Vis,
2473  unsigned AttrSpellingListIndex);
2474  VisibilityAttr *mergeVisibilityAttr(Decl *D, SourceRange Range,
2475  VisibilityAttr::VisibilityType Vis,
2476  unsigned AttrSpellingListIndex);
2477  UuidAttr *mergeUuidAttr(Decl *D, SourceRange Range,
2478  unsigned AttrSpellingListIndex, StringRef Uuid);
2479  DLLImportAttr *mergeDLLImportAttr(Decl *D, SourceRange Range,
2480  unsigned AttrSpellingListIndex);
2481  DLLExportAttr *mergeDLLExportAttr(Decl *D, SourceRange Range,
2482  unsigned AttrSpellingListIndex);
2483  MSInheritanceAttr *
2484  mergeMSInheritanceAttr(Decl *D, SourceRange Range, bool BestCase,
2485  unsigned AttrSpellingListIndex,
2486  MSInheritanceAttr::Spelling SemanticSpelling);
2487  FormatAttr *mergeFormatAttr(Decl *D, SourceRange Range,
2488  IdentifierInfo *Format, int FormatIdx,
2489  int FirstArg, unsigned AttrSpellingListIndex);
2490  SectionAttr *mergeSectionAttr(Decl *D, SourceRange Range, StringRef Name,
2491  unsigned AttrSpellingListIndex);
2492  CodeSegAttr *mergeCodeSegAttr(Decl *D, SourceRange Range, StringRef Name,
2493  unsigned AttrSpellingListIndex);
2494  AlwaysInlineAttr *mergeAlwaysInlineAttr(Decl *D, SourceRange Range,
2495  IdentifierInfo *Ident,
2496  unsigned AttrSpellingListIndex);
2497  MinSizeAttr *mergeMinSizeAttr(Decl *D, SourceRange Range,
2498  unsigned AttrSpellingListIndex);
2499  NoSpeculativeLoadHardeningAttr *
2500  mergeNoSpeculativeLoadHardeningAttr(Decl *D,
2501  const NoSpeculativeLoadHardeningAttr &AL);
2502  SpeculativeLoadHardeningAttr *
2503  mergeSpeculativeLoadHardeningAttr(Decl *D,
2504  const SpeculativeLoadHardeningAttr &AL);
2505  OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D, SourceRange Range,
2506  unsigned AttrSpellingListIndex);
2507  InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, const ParsedAttr &AL);
2508  InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D,
2509  const InternalLinkageAttr &AL);
2510  CommonAttr *mergeCommonAttr(Decl *D, const ParsedAttr &AL);
2511  CommonAttr *mergeCommonAttr(Decl *D, const CommonAttr &AL);
2512 
2513  void mergeDeclAttributes(NamedDecl *New, Decl *Old,
2514  AvailabilityMergeKind AMK = AMK_Redeclaration);
2515  void MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New,
2516  LookupResult &OldDecls);
2517  bool MergeFunctionDecl(FunctionDecl *New, NamedDecl *&Old, Scope *S,
2518  bool MergeTypeWithOld);
2519  bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old,
2520  Scope *S, bool MergeTypeWithOld);
2521  void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old);
2522  void MergeVarDecl(VarDecl *New, LookupResult &Previous);
2523  void MergeVarDeclTypes(VarDecl *New, VarDecl *Old, bool MergeTypeWithOld);
2524  void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old);
2525  bool checkVarDeclRedefinition(VarDecl *OldDefn, VarDecl *NewDefn);
2526  void notePreviousDefinition(const NamedDecl *Old, SourceLocation New);
2527  bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S);
2528 
2529  // AssignmentAction - This is used by all the assignment diagnostic functions
2530  // to represent what is actually causing the operation
2539  AA_Passing_CFAudited
2540  };
2541 
2542  /// C++ Overloading.
2544  /// This is a legitimate overload: the existing declarations are
2545  /// functions or function templates with different signatures.
2547 
2548  /// This is not an overload because the signature exactly matches
2549  /// an existing declaration.
2551 
2552  /// This is not an overload because the lookup results contain a
2553  /// non-function.
2554  Ovl_NonFunction
2555  };
2556  OverloadKind CheckOverload(Scope *S,
2557  FunctionDecl *New,
2558  const LookupResult &OldDecls,
2559  NamedDecl *&OldDecl,
2560  bool IsForUsingDecl);
2561  bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl,
2562  bool ConsiderCudaAttrs = true);
2563 
2564  /// Checks availability of the function depending on the current
2565  /// function context.Inside an unavailable function,unavailability is ignored.
2566  ///
2567  /// \returns true if \p FD is unavailable and current context is inside
2568  /// an available function, false otherwise.
2569  bool isFunctionConsideredUnavailable(FunctionDecl *FD);
2570 
2572  TryImplicitConversion(Expr *From, QualType ToType,
2573  bool SuppressUserConversions,
2574  bool AllowExplicit,
2575  bool InOverloadResolution,
2576  bool CStyle,
2577  bool AllowObjCWritebackConversion);
2578 
2579  bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
2580  bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
2581  bool IsComplexPromotion(QualType FromType, QualType ToType);
2582  bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
2583  bool InOverloadResolution,
2584  QualType& ConvertedType, bool &IncompatibleObjC);
2585  bool isObjCPointerConversion(QualType FromType, QualType ToType,
2586  QualType& ConvertedType, bool &IncompatibleObjC);
2587  bool isObjCWritebackConversion(QualType FromType, QualType ToType,
2588  QualType &ConvertedType);
2589  bool IsBlockPointerConversion(QualType FromType, QualType ToType,
2590  QualType& ConvertedType);
2591  bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
2592  const FunctionProtoType *NewType,
2593  unsigned *ArgPos = nullptr);
2594  void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
2595  QualType FromType, QualType ToType);
2596 
2597  void maybeExtendBlockObject(ExprResult &E);
2598  CastKind PrepareCastToObjCObjectPointer(ExprResult &E);
2599  bool CheckPointerConversion(Expr *From, QualType ToType,
2600  CastKind &Kind,
2601  CXXCastPath& BasePath,
2602  bool IgnoreBaseAccess,
2603  bool Diagnose = true);
2604  bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
2605  bool InOverloadResolution,
2606  QualType &ConvertedType);
2607  bool CheckMemberPointerConversion(Expr *From, QualType ToType,
2608  CastKind &Kind,
2609  CXXCastPath &BasePath,
2610  bool IgnoreBaseAccess);
2611  bool IsQualificationConversion(QualType FromType, QualType ToType,
2612  bool CStyle, bool &ObjCLifetimeConversion);
2613  bool IsFunctionConversion(QualType FromType, QualType ToType,
2614  QualType &ResultTy);
2615  bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType);
2616  bool isSameOrCompatibleFunctionType(CanQualType Param, CanQualType Arg);
2617 
2618  ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
2619  const VarDecl *NRVOCandidate,
2620  QualType ResultType,
2621  Expr *Value,
2622  bool AllowNRVO = true);
2623 
2624  bool CanPerformCopyInitialization(const InitializedEntity &Entity,
2625  ExprResult Init);
2626  ExprResult PerformCopyInitialization(const InitializedEntity &Entity,
2627  SourceLocation EqualLoc,
2628  ExprResult Init,
2629  bool TopLevelOfInitList = false,
2630  bool AllowExplicit = false);
2631  ExprResult PerformObjectArgumentInitialization(Expr *From,
2632  NestedNameSpecifier *Qualifier,
2633  NamedDecl *FoundDecl,
2634  CXXMethodDecl *Method);
2635 
2636  /// Check that the lifetime of the initializer (and its subobjects) is
2637  /// sufficient for initializing the entity, and perform lifetime extension
2638  /// (when permitted) if not.
2639  void checkInitializerLifetime(const InitializedEntity &Entity, Expr *Init);
2640 
2641  ExprResult PerformContextuallyConvertToBool(Expr *From);
2642  ExprResult PerformContextuallyConvertToObjCPointer(Expr *From);
2643 
2644  /// Contexts in which a converted constant expression is required.
2645  enum CCEKind {
2646  CCEK_CaseValue, ///< Expression in a case label.
2647  CCEK_Enumerator, ///< Enumerator value with fixed underlying type.
2648  CCEK_TemplateArg, ///< Value of a non-type template parameter.
2649  CCEK_NewExpr, ///< Constant expression in a noptr-new-declarator.
2650  CCEK_ConstexprIf ///< Condition in a constexpr if statement.
2651  };
2653  llvm::APSInt &Value, CCEKind CCE);
2655  APValue &Value, CCEKind CCE);
2656 
2657  /// Abstract base class used to perform a contextual implicit
2658  /// conversion from an expression to any type passing a filter.
2660  public:
2661  bool Suppress;
2663 
2664  ContextualImplicitConverter(bool Suppress = false,
2665  bool SuppressConversion = false)
2666  : Suppress(Suppress), SuppressConversion(SuppressConversion) {}
2667 
2668  /// Determine whether the specified type is a valid destination type
2669  /// for this conversion.
2670  virtual bool match(QualType T) = 0;
2671 
2672  /// Emits a diagnostic complaining that the expression does not have
2673  /// integral or enumeration type.
2674  virtual SemaDiagnosticBuilder
2675  diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) = 0;
2676 
2677  /// Emits a diagnostic when the expression has incomplete class type.
2678  virtual SemaDiagnosticBuilder
2679  diagnoseIncomplete(Sema &S, SourceLocation Loc, QualType T) = 0;
2680 
2681  /// Emits a diagnostic when the only matching conversion function
2682  /// is explicit.
2683  virtual SemaDiagnosticBuilder diagnoseExplicitConv(
2684  Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0;
2685 
2686  /// Emits a note for the explicit conversion function.
2687  virtual SemaDiagnosticBuilder
2688  noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0;
2689 
2690  /// Emits a diagnostic when there are multiple possible conversion
2691  /// functions.
2692  virtual SemaDiagnosticBuilder
2693  diagnoseAmbiguous(Sema &S, SourceLocation Loc, QualType T) = 0;
2694 
2695  /// Emits a note for one of the candidate conversions.
2696  virtual SemaDiagnosticBuilder
2697  noteAmbiguous(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0;
2698 
2699  /// Emits a diagnostic when we picked a conversion function
2700  /// (for cases when we are not allowed to pick a conversion function).
2701  virtual SemaDiagnosticBuilder diagnoseConversion(
2702  Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0;
2703 
2705  };
2706 
2708  bool AllowScopedEnumerations;
2709 
2710  public:
2711  ICEConvertDiagnoser(bool AllowScopedEnumerations,
2712  bool Suppress, bool SuppressConversion)
2713  : ContextualImplicitConverter(Suppress, SuppressConversion),
2714  AllowScopedEnumerations(AllowScopedEnumerations) {}
2715 
2716  /// Match an integral or (possibly scoped) enumeration type.
2717  bool match(QualType T) override;
2718 
2721  return diagnoseNotInt(S, Loc, T);
2722  }
2723 
2724  /// Emits a diagnostic complaining that the expression does not have
2725  /// integral or enumeration type.
2726  virtual SemaDiagnosticBuilder
2727  diagnoseNotInt(Sema &S, SourceLocation Loc, QualType T) = 0;
2728  };
2729 
2730  /// Perform a contextual implicit conversion.
2731  ExprResult PerformContextualImplicitConversion(
2732  SourceLocation Loc, Expr *FromE, ContextualImplicitConverter &Converter);
2733 
2734 
2738  OS_Error
2739  };
2740  ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE);
2741 
2742  // Note that LK_String is intentionally after the other literals, as
2743  // this is used for diagnostics logic.
2751  LK_None
2752  };
2753  ObjCLiteralKind CheckLiteralKind(Expr *FromE);
2754 
2755  ExprResult PerformObjectMemberConversion(Expr *From,
2756  NestedNameSpecifier *Qualifier,
2757  NamedDecl *FoundDecl,
2758  NamedDecl *Member);
2759 
2760  // Members have to be NamespaceDecl* or TranslationUnitDecl*.
2761  // TODO: make this is a typesafe union.
2764 
2766 
2767  void AddOverloadCandidate(FunctionDecl *Function, DeclAccessPair FoundDecl,
2768  ArrayRef<Expr *> Args,
2769  OverloadCandidateSet &CandidateSet,
2770  bool SuppressUserConversions = false,
2771  bool PartialOverloading = false,
2772  bool AllowExplicit = false,
2773  ADLCallKind IsADLCandidate = ADLCallKind::NotADL,
2774  ConversionSequenceList EarlyConversions = None);
2775  void AddFunctionCandidates(const UnresolvedSetImpl &Functions,
2776  ArrayRef<Expr *> Args,
2777  OverloadCandidateSet &CandidateSet,
2778  TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr,
2779  bool SuppressUserConversions = false,
2780  bool PartialOverloading = false,
2781  bool FirstArgumentIsBase = false);
2782  void AddMethodCandidate(DeclAccessPair FoundDecl,
2783  QualType ObjectType,
2784  Expr::Classification ObjectClassification,
2785  ArrayRef<Expr *> Args,
2786  OverloadCandidateSet& CandidateSet,
2787  bool SuppressUserConversion = false);
2788  void AddMethodCandidate(CXXMethodDecl *Method,
2789  DeclAccessPair FoundDecl,
2790  CXXRecordDecl *ActingContext, QualType ObjectType,
2791  Expr::Classification ObjectClassification,
2792  ArrayRef<Expr *> Args,
2793  OverloadCandidateSet& CandidateSet,
2794  bool SuppressUserConversions = false,
2795  bool PartialOverloading = false,
2796  ConversionSequenceList EarlyConversions = None);
2797  void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl,
2798  DeclAccessPair FoundDecl,
2799  CXXRecordDecl *ActingContext,
2800  TemplateArgumentListInfo *ExplicitTemplateArgs,
2801  QualType ObjectType,
2802  Expr::Classification ObjectClassification,
2803  ArrayRef<Expr *> Args,
2804  OverloadCandidateSet& CandidateSet,
2805  bool SuppressUserConversions = false,
2806  bool PartialOverloading = false);
2807  void AddTemplateOverloadCandidate(
2808  FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl,
2809  TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args,
2810  OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false,
2811  bool PartialOverloading = false,
2812  ADLCallKind IsADLCandidate = ADLCallKind::NotADL);
2813  bool CheckNonDependentConversions(FunctionTemplateDecl *FunctionTemplate,
2814  ArrayRef<QualType> ParamTypes,
2815  ArrayRef<Expr *> Args,
2816  OverloadCandidateSet &CandidateSet,
2817  ConversionSequenceList &Conversions,
2818  bool SuppressUserConversions,
2819  CXXRecordDecl *ActingContext = nullptr,
2820  QualType ObjectType = QualType(),
2822  ObjectClassification = {});
2823  void AddConversionCandidate(CXXConversionDecl *Conversion,
2824  DeclAccessPair FoundDecl,
2825  CXXRecordDecl *ActingContext,
2826  Expr *From, QualType ToType,
2827  OverloadCandidateSet& CandidateSet,
2828  bool AllowObjCConversionOnExplicit,
2829  bool AllowResultConversion = true);
2830  void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate,
2831  DeclAccessPair FoundDecl,
2832  CXXRecordDecl *ActingContext,
2833  Expr *From, QualType ToType,
2834  OverloadCandidateSet &CandidateSet,
2835  bool AllowObjCConversionOnExplicit,
2836  bool AllowResultConversion = true);
2837  void AddSurrogateCandidate(CXXConversionDecl *Conversion,
2838  DeclAccessPair FoundDecl,
2839  CXXRecordDecl *ActingContext,
2840  const FunctionProtoType *Proto,
2841  Expr *Object, ArrayRef<Expr *> Args,
2842  OverloadCandidateSet& CandidateSet);
2843  void AddMemberOperatorCandidates(OverloadedOperatorKind Op,
2844  SourceLocation OpLoc, ArrayRef<Expr *> Args,
2845  OverloadCandidateSet& CandidateSet,
2846  SourceRange OpRange = SourceRange());
2847  void AddBuiltinCandidate(QualType *ParamTys, ArrayRef<Expr *> Args,
2848  OverloadCandidateSet& CandidateSet,
2849  bool IsAssignmentOperator = false,
2850  unsigned NumContextualBoolArguments = 0);
2851  void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
2852  SourceLocation OpLoc, ArrayRef<Expr *> Args,
2853  OverloadCandidateSet& CandidateSet);
2854  void AddArgumentDependentLookupCandidates(DeclarationName Name,
2855  SourceLocation Loc,
2856  ArrayRef<Expr *> Args,
2857  TemplateArgumentListInfo *ExplicitTemplateArgs,
2858  OverloadCandidateSet& CandidateSet,
2859  bool PartialOverloading = false);
2860 
2861  // Emit as a 'note' the specific overload candidate
2862  void NoteOverloadCandidate(NamedDecl *Found, FunctionDecl *Fn,
2863  QualType DestType = QualType(),
2864  bool TakingAddress = false);
2865 
2866  // Emit as a series of 'note's all template and non-templates identified by
2867  // the expression Expr
2868  void NoteAllOverloadCandidates(Expr *E, QualType DestType = QualType(),
2869  bool TakingAddress = false);
2870 
2871  /// Check the enable_if expressions on the given function. Returns the first
2872  /// failing attribute, or NULL if they were all successful.
2873  EnableIfAttr *CheckEnableIf(FunctionDecl *Function, ArrayRef<Expr *> Args,
2874  bool MissingImplicitThis = false);
2875 
2876  /// Find the failed Boolean condition within a given Boolean
2877  /// constant expression, and describe it with a string.
2878  std::pair<Expr *, std::string> findFailedBooleanCondition(Expr *Cond);
2879 
2880  /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any
2881  /// non-ArgDependent DiagnoseIfAttrs.
2882  ///
2883  /// Argument-dependent diagnose_if attributes should be checked each time a
2884  /// function is used as a direct callee of a function call.
2885  ///
2886  /// Returns true if any errors were emitted.
2887  bool diagnoseArgDependentDiagnoseIfAttrs(const FunctionDecl *Function,
2888  const Expr *ThisArg,
2890  SourceLocation Loc);
2891 
2892  /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any
2893  /// ArgDependent DiagnoseIfAttrs.
2894  ///
2895  /// Argument-independent diagnose_if attributes should be checked on every use
2896  /// of a function.
2897  ///
2898  /// Returns true if any errors were emitted.
2899  bool diagnoseArgIndependentDiagnoseIfAttrs(const NamedDecl *ND,
2900  SourceLocation Loc);
2901 
2902  /// Returns whether the given function's address can be taken or not,
2903  /// optionally emitting a diagnostic if the address can't be taken.
2904  ///
2905  /// Returns false if taking the address of the function is illegal.
2906  bool checkAddressOfFunctionIsAvailable(const FunctionDecl *Function,
2907  bool Complain = false,
2908  SourceLocation Loc = SourceLocation());
2909 
2910  // [PossiblyAFunctionType] --> [Return]
2911  // NonFunctionType --> NonFunctionType
2912  // R (A) --> R(A)
2913  // R (*)(A) --> R (A)
2914  // R (&)(A) --> R (A)
2915  // R (S::*)(A) --> R (A)
2916  QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType);
2917 
2918  FunctionDecl *
2919  ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr,
2920  QualType TargetType,
2921  bool Complain,
2922  DeclAccessPair &Found,
2923  bool *pHadMultipleCandidates = nullptr);
2924 
2925  FunctionDecl *
2926  resolveAddressOfOnlyViableOverloadCandidate(Expr *E,
2927  DeclAccessPair &FoundResult);
2928 
2929  bool resolveAndFixAddressOfOnlyViableOverloadCandidate(
2930  ExprResult &SrcExpr, bool DoFunctionPointerConversion = false);
2931 
2932  FunctionDecl *
2933  ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl,
2934  bool Complain = false,
2935  DeclAccessPair *Found = nullptr);
2936 
2937  bool ResolveAndFixSingleFunctionTemplateSpecialization(
2938  ExprResult &SrcExpr,
2939  bool DoFunctionPointerConverion = false,
2940  bool Complain = false,
2941  SourceRange OpRangeForComplaining = SourceRange(),
2942  QualType DestTypeForComplaining = QualType(),
2943  unsigned DiagIDForComplaining = 0);
2944 
2945 
2946  Expr *FixOverloadedFunctionReference(Expr *E,
2947  DeclAccessPair FoundDecl,
2948  FunctionDecl *Fn);
2949  ExprResult FixOverloadedFunctionReference(ExprResult,
2950  DeclAccessPair FoundDecl,
2951  FunctionDecl *Fn);
2952 
2953  void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE,
2954  ArrayRef<Expr *> Args,
2955  OverloadCandidateSet &CandidateSet,
2956  bool PartialOverloading = false);
2957 
2958  // An enum used to represent the different possible results of building a
2959  // range-based for loop.
2963  FRS_DiagnosticIssued
2964  };
2965 
2966  ForRangeStatus BuildForRangeBeginEndCall(SourceLocation Loc,
2967  SourceLocation RangeLoc,
2968  const DeclarationNameInfo &NameInfo,
2969  LookupResult &MemberLookup,
2970  OverloadCandidateSet *CandidateSet,
2971  Expr *Range, ExprResult *CallExpr);
2972 
2973  ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn,
2974  UnresolvedLookupExpr *ULE,
2975  SourceLocation LParenLoc,
2976  MultiExprArg Args,
2977  SourceLocation RParenLoc,
2978  Expr *ExecConfig,
2979  bool AllowTypoCorrection=true,
2980  bool CalleesAddressIsTaken=false);
2981 
2982  bool buildOverloadedCallSet(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE,
2983  MultiExprArg Args, SourceLocation RParenLoc,
2984  OverloadCandidateSet *CandidateSet,
2985  ExprResult *Result);
2986 
2987  ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc,
2988  UnaryOperatorKind Opc,
2989  const UnresolvedSetImpl &Fns,
2990  Expr *input, bool RequiresADL = true);
2991 
2992  ExprResult CreateOverloadedBinOp(SourceLocation OpLoc,
2993  BinaryOperatorKind Opc,
2994  const UnresolvedSetImpl &Fns,
2995  Expr *LHS, Expr *RHS,
2996  bool RequiresADL = true);
2997 
2998  ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
2999  SourceLocation RLoc,
3000  Expr *Base,Expr *Idx);
3001 
3002  ExprResult
3003  BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
3004  SourceLocation LParenLoc,
3005  MultiExprArg Args,
3006  SourceLocation RParenLoc);
3007  ExprResult
3008  BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
3009  MultiExprArg Args,
3010  SourceLocation RParenLoc);
3011 
3012  ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base,
3013  SourceLocation OpLoc,
3014  bool *NoArrowOperatorFound = nullptr);
3015 
3016  /// CheckCallReturnType - Checks that a call expression's return type is
3017  /// complete. Returns true on failure. The location passed in is the location
3018  /// that best represents the call.
3019  bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc,
3020  CallExpr *CE, FunctionDecl *FD);
3021 
3022  /// Helpers for dealing with blocks and functions.
3023  bool CheckParmsForFunctionDef(ArrayRef<ParmVarDecl *> Parameters,
3024  bool CheckParameterNames);
3025  void CheckCXXDefaultArguments(FunctionDecl *FD);
3026  void CheckExtraCXXDefaultArguments(Declarator &D);
3027  Scope *getNonFieldDeclScope(Scope *S);
3028 
3029  /// \name Name lookup
3030  ///
3031  /// These routines provide name lookup that is used during semantic
3032  /// analysis to resolve the various kinds of names (identifiers,
3033  /// overloaded operator names, constructor names, etc.) into zero or
3034  /// more declarations within a particular scope. The major entry
3035  /// points are LookupName, which performs unqualified name lookup,
3036  /// and LookupQualifiedName, which performs qualified name lookup.
3037  ///
3038  /// All name lookup is performed based on some specific criteria,
3039  /// which specify what names will be visible to name lookup and how
3040  /// far name lookup should work. These criteria are important both
3041  /// for capturing language semantics (certain lookups will ignore
3042  /// certain names, for example) and for performance, since name
3043  /// lookup is often a bottleneck in the compilation of C++. Name
3044  /// lookup criteria is specified via the LookupCriteria enumeration.
3045  ///
3046  /// The results of name lookup can vary based on the kind of name
3047  /// lookup performed, the current language, and the translation
3048  /// unit. In C, for example, name lookup will either return nothing
3049  /// (no entity found) or a single declaration. In C++, name lookup
3050  /// can additionally refer to a set of overloaded functions or
3051  /// result in an ambiguity. All of the possible results of name
3052  /// lookup are captured by the LookupResult class, which provides
3053  /// the ability to distinguish among them.
3054  //@{
3055 
3056  /// Describes the kind of name lookup to perform.
3058  /// Ordinary name lookup, which finds ordinary names (functions,
3059  /// variables, typedefs, etc.) in C and most kinds of names
3060  /// (functions, variables, members, types, etc.) in C++.
3061  LookupOrdinaryName = 0,
3062  /// Tag name lookup, which finds the names of enums, classes,
3063  /// structs, and unions.
3065  /// Label name lookup.
3067  /// Member name lookup, which finds the names of
3068  /// class/struct/union members.
3070  /// Look up of an operator name (e.g., operator+) for use with
3071  /// operator overloading. This lookup is similar to ordinary name
3072  /// lookup, but will ignore any declarations that are class members.
3074  /// Look up of a name that precedes the '::' scope resolution
3075  /// operator in C++. This lookup completely ignores operator, object,
3076  /// function, and enumerator names (C++ [basic.lookup.qual]p1).
3078  /// Look up a namespace name within a C++ using directive or
3079  /// namespace alias definition, ignoring non-namespace names (C++
3080  /// [basic.lookup.udir]p1).
3082  /// Look up all declarations in a scope with the given name,
3083  /// including resolved using declarations. This is appropriate
3084  /// for checking redeclarations for a using declaration.
3086  /// Look up an ordinary name that is going to be redeclared as a
3087  /// name with linkage. This lookup ignores any declarations that
3088  /// are outside of the current scope unless they have linkage. See
3089  /// C99 6.2.2p4-5 and C++ [basic.link]p6.
3091  /// Look up a friend of a local class. This lookup does not look
3092  /// outside the innermost non-class scope. See C++11 [class.friend]p11.
3094  /// Look up the name of an Objective-C protocol.
3096  /// Look up implicit 'self' parameter of an objective-c method.
3098  /// Look up the name of an OpenMP user-defined reduction operation.
3100  /// Look up any declaration with any name.
3101  LookupAnyName
3102  };
3103 
3104  /// Specifies whether (or how) name lookup is being performed for a
3105  /// redeclaration (vs. a reference).
3107  /// The lookup is a reference to this name that is not for the
3108  /// purpose of redeclaring the name.
3109  NotForRedeclaration = 0,
3110  /// The lookup results will be used for redeclaration of a name,
3111  /// if an entity by that name already exists and is visible.
3113  /// The lookup results will be used for redeclaration of a name
3114  /// with external linkage; non-visible lookup results with external linkage
3115  /// may also be found.
3116  ForExternalRedeclaration
3117  };
3118 
3120  // A declaration with an owning module for linkage can never link against
3121  // anything that is not visible. We don't need to check linkage here; if
3122  // the context has internal linkage, redeclaration lookup won't find things
3123  // from other TUs, and we can't safely compute linkage yet in general.
3124  if (cast<Decl>(CurContext)
3125  ->getOwningModuleForLinkage(/*IgnoreLinkage*/true))
3126  return ForVisibleRedeclaration;
3127  return ForExternalRedeclaration;
3128  }
3129 
3130  /// The possible outcomes of name lookup for a literal operator.
3132  /// The lookup resulted in an error.
3134  /// The lookup found no match but no diagnostic was issued.
3136  /// The lookup found a single 'cooked' literal operator, which
3137  /// expects a normal literal to be built and passed to it.
3139  /// The lookup found a single 'raw' literal operator, which expects
3140  /// a string literal containing the spelling of the literal token.
3142  /// The lookup found an overload set of literal operator templates,
3143  /// which expect the characters of the spelling of the literal token to be
3144  /// passed as a non-type template argument pack.
3146  /// The lookup found an overload set of literal operator templates,
3147  /// which expect the character type and characters of the spelling of the
3148  /// string literal token to be passed as template arguments.
3149  LOLR_StringTemplate
3150  };
3151 
3152  SpecialMemberOverloadResult LookupSpecialMember(CXXRecordDecl *D,
3154  bool ConstArg,
3155  bool VolatileArg,
3156  bool RValueThis,
3157  bool ConstThis,
3158  bool VolatileThis);
3159 
3160  typedef std::function<void(const TypoCorrection &)> TypoDiagnosticGenerator;
3161  typedef std::function<ExprResult(Sema &, TypoExpr *, TypoCorrection)>
3163 
3164 private:
3165  bool CppLookupName(LookupResult &R, Scope *S);
3166 
3167  struct TypoExprState {
3168  std::unique_ptr<TypoCorrectionConsumer> Consumer;
3169  TypoDiagnosticGenerator DiagHandler;
3170  TypoRecoveryCallback RecoveryHandler;
3171  TypoExprState();
3172  TypoExprState(TypoExprState &&other) noexcept;
3173  TypoExprState &operator=(TypoExprState &&other) noexcept;
3174  };
3175 
3176  /// The set of unhandled TypoExprs and their associated state.
3177  llvm::MapVector<TypoExpr *, TypoExprState> DelayedTypos;
3178 
3179  /// Creates a new TypoExpr AST node.
3180  TypoExpr *createDelayedTypo(std::unique_ptr<TypoCorrectionConsumer> TCC,
3181  TypoDiagnosticGenerator TDG,
3182  TypoRecoveryCallback TRC);
3183 
3184  // The set of known/encountered (unique, canonicalized) NamespaceDecls.
3185  //
3186  // The boolean value will be true to indicate that the namespace was loaded
3187  // from an AST/PCH file, or false otherwise.
3188  llvm::MapVector<NamespaceDecl*, bool> KnownNamespaces;
3189 
3190  /// Whether we have already loaded known namespaces from an extenal
3191  /// source.
3192  bool LoadedExternalKnownNamespaces;
3193 
3194  /// Helper for CorrectTypo and CorrectTypoDelayed used to create and
3195  /// populate a new TypoCorrectionConsumer. Returns nullptr if typo correction
3196  /// should be skipped entirely.
3197  std::unique_ptr<TypoCorrectionConsumer>
3198  makeTypoCorrectionConsumer(const DeclarationNameInfo &Typo,
3199  Sema::LookupNameKind LookupKind, Scope *S,
3200  CXXScopeSpec *SS,
3201  std::unique_ptr<CorrectionCandidateCallback> CCC,
3202  DeclContext *MemberContext, bool EnteringContext,
3203  const ObjCObjectPointerType *OPT,
3204  bool ErrorRecovery);
3205 
3206 public:
3207  const TypoExprState &getTypoExprState(TypoExpr *TE) const;
3208 
3209  /// Clears the state of the given TypoExpr.
3210  void clearDelayedTypo(TypoExpr *TE);
3211 
3212  /// Look up a name, looking for a single declaration. Return
3213  /// null if the results were absent, ambiguous, or overloaded.
3214  ///
3215  /// It is preferable to use the elaborated form and explicitly handle
3216  /// ambiguity and overloaded.
3217  NamedDecl *LookupSingleName(Scope *S, DeclarationName Name,
3218  SourceLocation Loc,
3219  LookupNameKind NameKind,
3220  RedeclarationKind Redecl
3221  = NotForRedeclaration);
3222  bool LookupName(LookupResult &R, Scope *S,
3223  bool AllowBuiltinCreation = false);
3224  bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
3225  bool InUnqualifiedLookup = false);
3226  bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
3227  CXXScopeSpec &SS);
3228  bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS,
3229  bool AllowBuiltinCreation = false,
3230  bool EnteringContext = false);
3231  ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc,
3232  RedeclarationKind Redecl
3233  = NotForRedeclaration);
3234  bool LookupInSuper(LookupResult &R, CXXRecordDecl *Class);
3235 
3236  void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
3237  QualType T1, QualType T2,
3238  UnresolvedSetImpl &Functions);
3239 
3240  LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc,
3241  SourceLocation GnuLabelLoc = SourceLocation());
3242 
3243  DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class);
3244  CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class);
3245  CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class,
3246  unsigned Quals);
3247  CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals,
3248  bool RValueThis, unsigned ThisQuals);
3249  CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class,
3250  unsigned Quals);
3251  CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals,
3252  bool RValueThis, unsigned ThisQuals);
3253  CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class);
3254 
3255  bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id);
3256  LiteralOperatorLookupResult LookupLiteralOperator(Scope *S, LookupResult &R,
3257  ArrayRef<QualType> ArgTys,
3258  bool AllowRaw,
3259  bool AllowTemplate,
3260  bool AllowStringTemplate,
3261  bool DiagnoseMissing);
3262  bool isKnownName(StringRef name);
3263 
3264  void ArgumentDependentLookup(DeclarationName Name, SourceLocation Loc,
3265  ArrayRef<Expr *> Args, ADLResult &Functions);
3266 
3267  void LookupVisibleDecls(Scope *S, LookupNameKind Kind,
3268  VisibleDeclConsumer &Consumer,
3269  bool IncludeGlobalScope = true,
3270  bool LoadExternal = true);
3272  VisibleDeclConsumer &Consumer,
3273  bool IncludeGlobalScope = true,
3274  bool IncludeDependentBases = false,
3275  bool LoadExternal = true);
3276 
3278  CTK_NonError, // CorrectTypo used in a non error recovery situation.
3279  CTK_ErrorRecovery // CorrectTypo used in normal error recovery.
3280  };
3281 
3282  TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
3283  Sema::LookupNameKind LookupKind,
3284  Scope *S, CXXScopeSpec *SS,
3285  std::unique_ptr<CorrectionCandidateCallback> CCC,
3286  CorrectTypoKind Mode,
3287  DeclContext *MemberContext = nullptr,
3288  bool EnteringContext = false,
3289  const ObjCObjectPointerType *OPT = nullptr,
3290  bool RecordFailure = true);
3291 
3292  TypoExpr *CorrectTypoDelayed(const DeclarationNameInfo &Typo,
3293  Sema::LookupNameKind LookupKind, Scope *S,
3294  CXXScopeSpec *SS,
3295  std::unique_ptr<CorrectionCandidateCallback> CCC,
3296  TypoDiagnosticGenerator TDG,
3298  DeclContext *MemberContext = nullptr,
3299  bool EnteringContext = false,
3300  const ObjCObjectPointerType *OPT = nullptr);
3301 
3302  /// Process any TypoExprs in the given Expr and its children,
3303  /// generating diagnostics as appropriate and returning a new Expr if there
3304  /// were typos that were all successfully corrected and ExprError if one or
3305  /// more typos could not be corrected.
3306  ///
3307  /// \param E The Expr to check for TypoExprs.
3308  ///
3309  /// \param InitDecl A VarDecl to avoid because the Expr being corrected is its
3310  /// initializer.
3311  ///
3312  /// \param Filter A function applied to a newly rebuilt Expr to determine if
3313  /// it is an acceptable/usable result from a single combination of typo
3314  /// corrections. As long as the filter returns ExprError, different
3315  /// combinations of corrections will be tried until all are exhausted.
3316  ExprResult
3317  CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl = nullptr,
3318  llvm::function_ref<ExprResult(Expr *)> Filter =
3319  [](Expr *E) -> ExprResult { return E; });
3320 
3321  ExprResult
3323  llvm::function_ref<ExprResult(Expr *)> Filter) {
3324  return CorrectDelayedTyposInExpr(E, nullptr, Filter);
3325  }
3326 
3327  ExprResult
3328  CorrectDelayedTyposInExpr(ExprResult ER, VarDecl *InitDecl = nullptr,
3329  llvm::function_ref<ExprResult(Expr *)> Filter =
3330  [](Expr *E) -> ExprResult { return E; }) {
3331  return ER.isInvalid() ? ER : CorrectDelayedTyposInExpr(ER.get(), Filter);
3332  }
3333 
3334  ExprResult
3336  llvm::function_ref<ExprResult(Expr *)> Filter) {
3337  return CorrectDelayedTyposInExpr(ER, nullptr, Filter);
3338  }
3339 
3340  void diagnoseTypo(const TypoCorrection &Correction,
3341  const PartialDiagnostic &TypoDiag,
3342  bool ErrorRecovery = true);
3343 
3344  void diagnoseTypo(const TypoCorrection &Correction,
3345  const PartialDiagnostic &TypoDiag,
3346  const PartialDiagnostic &PrevNote,
3347  bool ErrorRecovery = true);
3348 
3349  void MarkTypoCorrectedFunctionDefinition(const NamedDecl *F);
3350 
3351  void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc,
3352  ArrayRef<Expr *> Args,
3353  AssociatedNamespaceSet &AssociatedNamespaces,
3354  AssociatedClassSet &AssociatedClasses);
3355 
3356  void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S,
3357  bool ConsiderLinkage, bool AllowInlineNamespace);
3358 
3359  bool CheckRedeclarationModuleOwnership(NamedDecl *New, NamedDecl *Old);
3360 
3361  void DiagnoseAmbiguousLookup(LookupResult &Result);
3362  //@}
3363 
3364  ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id,
3365  SourceLocation IdLoc,
3366  bool TypoCorrection = false);
3367  NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
3368  Scope *S, bool ForRedeclaration,
3369  SourceLocation Loc);
3370  NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
3371  Scope *S);
3372  void AddKnownFunctionAttributes(FunctionDecl *FD);
3373 
3374  // More parsing and symbol table subroutines.
3375 
3376  void ProcessPragmaWeak(Scope *S, Decl *D);
3377  // Decl attributes - this routine is the top level dispatcher.
3378  void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD);
3379  // Helper for delayed processing of attributes.
3380  void ProcessDeclAttributeDelayed(Decl *D,
3381  const ParsedAttributesView &AttrList);
3382  void ProcessDeclAttributeList(Scope *S, Decl *D, const ParsedAttributesView &AL,
3383  bool IncludeCXX11Attributes = true);
3384  bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl,
3385  const ParsedAttributesView &AttrList);
3386 
3387  void checkUnusedDeclAttributes(Declarator &D);
3388 
3389  /// Determine if type T is a valid subject for a nonnull and similar
3390  /// attributes. By default, we look through references (the behavior used by
3391  /// nonnull), but if the second parameter is true, then we treat a reference
3392  /// type as valid.
3393  bool isValidPointerAttrType(QualType T, bool RefOkay = false);
3394 
3395  bool CheckRegparmAttr(const ParsedAttr &attr, unsigned &value);
3396  bool CheckCallingConvAttr(const ParsedAttr &attr, CallingConv &CC,
3397  const FunctionDecl *FD = nullptr);
3398  bool CheckAttrTarget(const ParsedAttr &CurrAttr);
3399  bool CheckAttrNoArgs(const ParsedAttr &CurrAttr);
3400  bool checkStringLiteralArgumentAttr(const ParsedAttr &Attr, unsigned ArgNum,
3401  StringRef &Str,
3402  SourceLocation *ArgLocation = nullptr);
3403  bool checkSectionName(SourceLocation LiteralLoc, StringRef Str);
3404  bool checkTargetAttr(SourceLocation LiteralLoc, StringRef Str);
3405  bool checkMSInheritanceAttrOnDefinition(
3406  CXXRecordDecl *RD, SourceRange Range, bool BestCase,
3407  MSInheritanceAttr::Spelling SemanticSpelling);
3408 
3409  void CheckAlignasUnderalignment(Decl *D);
3410 
3411  /// Adjust the calling convention of a method to be the ABI default if it
3412  /// wasn't specified explicitly. This handles method types formed from
3413  /// function type typedefs and typename template arguments.
3414  void adjustMemberFunctionCC(QualType &T, bool IsStatic, bool IsCtorOrDtor,
3415  SourceLocation Loc);
3416 
3417  // Check if there is an explicit attribute, but only look through parens.
3418  // The intent is to look for an attribute on the current declarator, but not
3419  // one that came from a typedef.
3420  bool hasExplicitCallingConv(QualType &T);
3421 
3422  /// Get the outermost AttributedType node that sets a calling convention.
3423  /// Valid types should not have multiple attributes with different CCs.
3424  const AttributedType *getCallingConvAttributedType(QualType T) const;
3425 
3426  /// Stmt attributes - this routine is the top level dispatcher.
3427  StmtResult ProcessStmtAttributes(Stmt *Stmt,
3428  const ParsedAttributesView &Attrs,
3429  SourceRange Range);
3430 
3431  void WarnConflictingTypedMethods(ObjCMethodDecl *Method,
3432  ObjCMethodDecl *MethodDecl,
3433  bool IsProtocolMethodDecl);
3434 
3435  void CheckConflictingOverridingMethod(ObjCMethodDecl *Method,
3436  ObjCMethodDecl *Overridden,
3437  bool IsProtocolMethodDecl);
3438 
3439  /// WarnExactTypedMethods - This routine issues a warning if method
3440  /// implementation declaration matches exactly that of its declaration.
3441  void WarnExactTypedMethods(ObjCMethodDecl *Method,
3442  ObjCMethodDecl *MethodDecl,
3443  bool IsProtocolMethodDecl);
3444 
3445  typedef llvm::SmallPtrSet<Selector, 8> SelectorSet;
3446 
3447  /// CheckImplementationIvars - This routine checks if the instance variables
3448  /// listed in the implelementation match those listed in the interface.
3449  void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
3450  ObjCIvarDecl **Fields, unsigned nIvars,
3451  SourceLocation Loc);
3452 
3453  /// ImplMethodsVsClassMethods - This is main routine to warn if any method
3454  /// remains unimplemented in the class or category \@implementation.
3455  void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl,
3456  ObjCContainerDecl* IDecl,
3457  bool IncompleteImpl = false);
3458 
3459  /// DiagnoseUnimplementedProperties - This routine warns on those properties
3460  /// which must be implemented by this implementation.
3461  void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl,
3462  ObjCContainerDecl *CDecl,
3463  bool SynthesizeProperties);
3464 
3465  /// Diagnose any null-resettable synthesized setters.
3466  void diagnoseNullResettableSynthesizedSetters(const ObjCImplDecl *impDecl);
3467 
3468  /// DefaultSynthesizeProperties - This routine default synthesizes all
3469  /// properties which must be synthesized in the class's \@implementation.
3470  void DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl,
3471  ObjCInterfaceDecl *IDecl,
3472  SourceLocation AtEnd);
3473  void DefaultSynthesizeProperties(Scope *S, Decl *D, SourceLocation AtEnd);
3474 
3475  /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is
3476  /// an ivar synthesized for 'Method' and 'Method' is a property accessor
3477  /// declared in class 'IFace'.
3478  bool IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace,
3479  ObjCMethodDecl *Method, ObjCIvarDecl *IV);
3480 
3481  /// DiagnoseUnusedBackingIvarInAccessor - Issue an 'unused' warning if ivar which
3482  /// backs the property is not used in the property's accessor.
3483  void DiagnoseUnusedBackingIvarInAccessor(Scope *S,
3484  const ObjCImplementationDecl *ImplD);
3485 
3486  /// GetIvarBackingPropertyAccessor - If method is a property setter/getter and
3487  /// it property has a backing ivar, returns this ivar; otherwise, returns NULL.
3488  /// It also returns ivar's property on success.
3489  ObjCIvarDecl *GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method,
3490  const ObjCPropertyDecl *&PDecl) const;
3491 
3492  /// Called by ActOnProperty to handle \@property declarations in
3493  /// class extensions.
3494  ObjCPropertyDecl *HandlePropertyInClassExtension(Scope *S,
3495  SourceLocation AtLoc,
3496  SourceLocation LParenLoc,
3497  FieldDeclarator &FD,
3498  Selector GetterSel,
3499  SourceLocation GetterNameLoc,
3500  Selector SetterSel,
3501  SourceLocation SetterNameLoc,
3502  const bool isReadWrite,
3503  unsigned &Attributes,
3504  const unsigned AttributesAsWritten,
3505  QualType T,
3506  TypeSourceInfo *TSI,
3507  tok::ObjCKeywordKind MethodImplKind);
3508 
3509  /// Called by ActOnProperty and HandlePropertyInClassExtension to
3510  /// handle creating the ObjcPropertyDecl for a category or \@interface.
3511  ObjCPropertyDecl *CreatePropertyDecl(Scope *S,
3512  ObjCContainerDecl *CDecl,
3513  SourceLocation AtLoc,
3514  SourceLocation LParenLoc,
3515  FieldDeclarator &FD,
3516  Selector GetterSel,
3517  SourceLocation GetterNameLoc,
3518  Selector SetterSel,
3519  SourceLocation SetterNameLoc,
3520  const bool isReadWrite,
3521  const unsigned Attributes,
3522  const unsigned AttributesAsWritten,
3523  QualType T,
3524  TypeSourceInfo *TSI,
3525  tok::ObjCKeywordKind MethodImplKind,
3526  DeclContext *lexicalDC = nullptr);
3527 
3528  /// AtomicPropertySetterGetterRules - This routine enforces the rule (via
3529  /// warning) when atomic property has one but not the other user-declared
3530  /// setter or getter.
3531  void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl,
3532  ObjCInterfaceDecl* IDecl);
3533 
3534  void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D);
3535 
3536  void DiagnoseMissingDesignatedInitOverrides(
3537  const ObjCImplementationDecl *ImplD,
3538  const ObjCInterfaceDecl *IFD);
3539 
3540  void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID);
3541 
3544  MMS_strict
3545  };
3546 
3547  /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
3548  /// true, or false, accordingly.
3549  bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
3550  const ObjCMethodDecl *PrevMethod,
3551  MethodMatchStrategy strategy = MMS_strict);
3552 
3553  /// MatchAllMethodDeclarations - Check methods declaraed in interface or
3554  /// or protocol against those declared in their implementations.
3555  void MatchAllMethodDeclarations(const SelectorSet &InsMap,
3556  const SelectorSet &ClsMap,
3557  SelectorSet &InsMapSeen,
3558  SelectorSet &ClsMapSeen,
3559  ObjCImplDecl* IMPDecl,
3560  ObjCContainerDecl* IDecl,
3561  bool &IncompleteImpl,
3562  bool ImmediateClass,
3563  bool WarnCategoryMethodImpl=false);
3564 
3565  /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in
3566  /// category matches with those implemented in its primary class and
3567  /// warns each time an exact match is found.
3568  void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP);
3569 
3570  /// Add the given method to the list of globally-known methods.
3571  void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method);
3572 
3573 private:
3574  /// AddMethodToGlobalPool - Add an instance or factory method to the global
3575  /// pool. See descriptoin of AddInstanceMethodToGlobalPool.
3576  void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance);
3577 
3578  /// LookupMethodInGlobalPool - Returns the instance or factory method and
3579  /// optionally warns if there are multiple signatures.
3580  ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R,
3581  bool receiverIdOrClass,
3582  bool instance);
3583 
3584 public:
3585  /// - Returns instance or factory methods in global method pool for
3586  /// given selector. It checks the desired kind first, if none is found, and
3587  /// parameter checkTheOther is set, it then checks the other kind. If no such
3588  /// method or only one method is found, function returns false; otherwise, it
3589  /// returns true.
3590  bool
3591  CollectMultipleMethodsInGlobalPool(Selector Sel,
3593  bool InstanceFirst, bool CheckTheOther,
3594  const ObjCObjectType *TypeBound = nullptr);
3595 
3596  bool
3597  AreMultipleMethodsInGlobalPool(Selector Sel, ObjCMethodDecl *BestMethod,
3598  SourceRange R, bool receiverIdOrClass,
3600 
3601  void
3602  DiagnoseMultipleMethodInGlobalPool(SmallVectorImpl<ObjCMethodDecl*> &Methods,
3603  Selector Sel, SourceRange R,
3604  bool receiverIdOrClass);
3605 
3606 private:
3607  /// - Returns a selector which best matches given argument list or
3608  /// nullptr if none could be found
3609  ObjCMethodDecl *SelectBestMethod(Selector Sel, MultiExprArg Args,
3610  bool IsInstance,
3612 
3613 
3614  /// Record the typo correction failure and return an empty correction.
3615  TypoCorrection FailedCorrection(IdentifierInfo *Typo, SourceLocation TypoLoc,
3616  bool RecordFailure = true) {
3617  if (RecordFailure)
3618  TypoCorrectionFailures[Typo].insert(TypoLoc);
3619  return TypoCorrection();
3620  }
3621 
3622 public:
3623  /// AddInstanceMethodToGlobalPool - All instance methods in a translation
3624  /// unit are added to a global pool. This allows us to efficiently associate
3625  /// a selector with a method declaraation for purposes of typechecking
3626  /// messages sent to "id" (where the class of the object is unknown).
3627  void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
3628  AddMethodToGlobalPool(Method, impl, /*instance*/true);
3629  }
3630 
3631  /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
3632  void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
3633  AddMethodToGlobalPool(Method, impl, /*instance*/false);
3634  }
3635 
3636  /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global
3637  /// pool.
3638  void AddAnyMethodToGlobalPool(Decl *D);
3639 
3640  /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
3641  /// there are multiple signatures.
3643  bool receiverIdOrClass=false) {
3644  return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
3645  /*instance*/true);
3646  }
3647 
3648  /// LookupFactoryMethodInGlobalPool - Returns the method and warns if
3649  /// there are multiple signatures.
3651  bool receiverIdOrClass=false) {
3652  return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
3653  /*instance*/false);
3654  }
3655 
3656  const ObjCMethodDecl *SelectorsForTypoCorrection(Selector Sel,
3657  QualType ObjectType=QualType());
3658  /// LookupImplementedMethodInGlobalPool - Returns the method which has an
3659  /// implementation.
3660  ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel);
3661 
3662  /// CollectIvarsToConstructOrDestruct - Collect those ivars which require
3663  /// initialization.
3664  void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI,
3666 
3667  //===--------------------------------------------------------------------===//
3668  // Statement Parsing Callbacks: SemaStmt.cpp.
3669 public:
3670  class FullExprArg {
3671  public:
3672  FullExprArg() : E(nullptr) { }
3673  FullExprArg(Sema &actions) : E(nullptr) { }
3674 
3676  return E;
3677  }
3678 
3679  Expr *get() const { return E; }
3680 
3682  return E;
3683  }
3684 
3685  private:
3686  // FIXME: No need to make the entire Sema class a friend when it's just
3687  // Sema::MakeFullExpr that needs access to the constructor below.
3688  friend class Sema;
3689 
3690  explicit FullExprArg(Expr *expr) : E(expr) {}
3691 
3692  Expr *E;
3693  };
3694 
3696  return MakeFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation());
3697  }
3699  return FullExprArg(
3700  ActOnFinishFullExpr(Arg, CC, /*DiscardedValue*/ false).get());
3701  }
3703  ExprResult FE =
3704  ActOnFinishFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation(),
3705  /*DiscardedValue*/ true);
3706  return FullExprArg(FE.get());
3707  }
3708 
3709  StmtResult ActOnExprStmt(ExprResult Arg, bool DiscardedValue = true);
3710  StmtResult ActOnExprStmtError();
3711 
3712  StmtResult ActOnNullStmt(SourceLocation SemiLoc,
3713  bool HasLeadingEmptyMacro = false);
3714 
3715  void ActOnStartOfCompoundStmt(bool IsStmtExpr);
3716  void ActOnFinishOfCompoundStmt();
3717  StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
3718  ArrayRef<Stmt *> Elts, bool isStmtExpr);
3719 
3720  /// A RAII object to enter scope of a compound statement.
3722  public:
3723  CompoundScopeRAII(Sema &S, bool IsStmtExpr = false) : S(S) {
3724  S.ActOnStartOfCompoundStmt(IsStmtExpr);
3725  }
3726 
3728  S.ActOnFinishOfCompoundStmt();
3729  }
3730 
3731  private:
3732  Sema &S;
3733  };
3734 
3735  /// An RAII helper that pops function a function scope on exit.
3738  bool Active;
3739  FunctionScopeRAII(Sema &S) : S(S), Active(true) {}
3741  if (Active)
3743  }
3744  void disable() { Active = false; }
3745  };
3746 
3747  StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl,
3748  SourceLocation StartLoc,
3749  SourceLocation EndLoc);
3750  void ActOnForEachDeclStmt(DeclGroupPtrTy Decl);
3751  StmtResult ActOnForEachLValueExpr(Expr *E);
3752  ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val);
3753  StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS,
3754  SourceLocation DotDotDotLoc, ExprResult RHS,
3756  void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt);
3757 
3758  StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
3759  SourceLocation ColonLoc,
3760  Stmt *SubStmt, Scope *CurScope);
3761  StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl,
3762  SourceLocation ColonLoc, Stmt *SubStmt);
3763 
3764  StmtResult ActOnAttributedStmt(SourceLocation AttrLoc,
3765  ArrayRef<const Attr*> Attrs,
3766  Stmt *SubStmt);
3767 
3768  class ConditionResult;
3769  StmtResult ActOnIfStmt(SourceLocation IfLoc, bool IsConstexpr,
3770  Stmt *InitStmt,
3771  ConditionResult Cond, Stmt *ThenVal,
3772  SourceLocation ElseLoc, Stmt *ElseVal);
3773  StmtResult BuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
3774  Stmt *InitStmt,
3775  ConditionResult Cond, Stmt *ThenVal,
3776  SourceLocation ElseLoc, Stmt *ElseVal);
3777  StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc,
3778  Stmt *InitStmt,
3779  ConditionResult Cond);
3780  StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
3781  Stmt *Switch, Stmt *Body);
3782  StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ConditionResult Cond,
3783  Stmt *Body);
3784  StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body,
3785  SourceLocation WhileLoc, SourceLocation CondLParen,
3786  Expr *Cond, SourceLocation CondRParen);
3787 
3788  StmtResult ActOnForStmt(SourceLocation ForLoc,
3789  SourceLocation LParenLoc,
3790  Stmt *First,
3791  ConditionResult Second,
3792  FullExprArg Third,
3793  SourceLocation RParenLoc,
3794  Stmt *Body);
3795  ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc,
3796  Expr *collection);
3797  StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
3798  Stmt *First, Expr *collection,
3799  SourceLocation RParenLoc);
3800  StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body);
3801 
3803  /// Initial building of a for-range statement.
3805  /// Instantiation or recovery rebuild of a for-range statement. Don't
3806  /// attempt any typo-correction.
3808  /// Determining whether a for-range statement could be built. Avoid any
3809  /// unnecessary or irreversible actions.
3810  BFRK_Check
3811  };
3812 
3813  StmtResult ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc,
3814  SourceLocation CoawaitLoc,
3815  Stmt *InitStmt,
3816  Stmt *LoopVar,
3817  SourceLocation ColonLoc, Expr *Collection,
3818  SourceLocation RParenLoc,
3820  StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc,
3821  SourceLocation CoawaitLoc,
3822  Stmt *InitStmt,
3823  SourceLocation ColonLoc,
3824  Stmt *RangeDecl, Stmt *Begin, Stmt *End,
3825  Expr *Cond, Expr *Inc,
3826  Stmt *LoopVarDecl,
3827  SourceLocation RParenLoc,
3829  StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body);
3830 
3831  StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
3832  SourceLocation LabelLoc,
3833  LabelDecl *TheDecl);
3834  StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
3835  SourceLocation StarLoc,
3836  Expr *DestExp);
3837  StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope);
3838  StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope);
3839 
3840  void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope,
3841  CapturedRegionKind Kind, unsigned NumParams);
3842  typedef std::pair<StringRef, QualType> CapturedParamNameType;
3843  void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope,
3846  StmtResult ActOnCapturedRegionEnd(Stmt *S);
3847  void ActOnCapturedRegionError();
3848  RecordDecl *CreateCapturedStmtRecordDecl(CapturedDecl *&CD,
3849  SourceLocation Loc,
3850  unsigned NumParams);
3851 
3853  CES_Strict = 0,
3854  CES_AllowParameters = 1,
3855  CES_AllowDifferentTypes = 2,
3856  CES_AllowExceptionVariables = 4,
3857  CES_FormerDefault = (CES_AllowParameters),
3858  CES_Default = (CES_AllowParameters | CES_AllowDifferentTypes),
3859  CES_AsIfByStdMove = (CES_AllowParameters | CES_AllowDifferentTypes |
3860  CES_AllowExceptionVariables),
3861  };
3862 
3863  VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E,
3865  bool isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD,
3867 
3868  StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
3869  Scope *CurScope);
3870  StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
3871  StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
3872 
3873  StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
3874  bool IsVolatile, unsigned NumOutputs,
3875  unsigned NumInputs, IdentifierInfo **Names,
3876  MultiExprArg Constraints, MultiExprArg Exprs,
3877  Expr *AsmString, MultiExprArg Clobbers,
3878  SourceLocation RParenLoc);
3879 
3880  void FillInlineAsmIdentifierInfo(Expr *Res,
3881  llvm::InlineAsmIdentifierInfo &Info);
3882  ExprResult LookupInlineAsmIdentifier(CXXScopeSpec &SS,
3883  SourceLocation TemplateKWLoc,
3884  UnqualifiedId &Id,
3885  bool IsUnevaluatedContext);
3886  bool LookupInlineAsmField(StringRef Base, StringRef Member,
3887  unsigned &Offset, SourceLocation AsmLoc);
3888  ExprResult LookupInlineAsmVarDeclField(Expr *RefExpr, StringRef Member,
3889  SourceLocation AsmLoc);
3890  StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
3891  ArrayRef<Token> AsmToks,
3892  StringRef AsmString,
3893  unsigned NumOutputs, unsigned NumInputs,
3894  ArrayRef<StringRef> Constraints,
3895  ArrayRef<StringRef> Clobbers,
3896  ArrayRef<Expr*> Exprs,
3897  SourceLocation EndLoc);
3898  LabelDecl *GetOrCreateMSAsmLabel(StringRef ExternalLabelName,
3899  SourceLocation Location,
3900  bool AlwaysCreate);
3901 
3902  VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType,
3903  SourceLocation StartLoc,
3904  SourceLocation IdLoc, IdentifierInfo *Id,
3905  bool Invalid = false);
3906 
3907  Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D);
3908 
3909  StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen,
3910  Decl *Parm, Stmt *Body);
3911 
3912  StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body);
3913 
3914  StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try,
3915  MultiStmtArg Catch, Stmt *Finally);
3916 
3917  StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw);
3918  StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw,
3919  Scope *CurScope);
3920  ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc,
3921  Expr *operand);
3922  StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
3923  Expr *SynchExpr,
3924  Stmt *SynchBody);
3925 
3926  StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body);
3927 
3928  VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo,
3929  SourceLocation StartLoc,
3930  SourceLocation IdLoc,
3931  IdentifierInfo *Id);
3932 
3933  Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D);
3934 
3935  StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
3936  Decl *ExDecl, Stmt *HandlerBlock);
3937  StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
3938  ArrayRef<Stmt *> Handlers);
3939 
3940  StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ?
3941  SourceLocation TryLoc, Stmt *TryBlock,
3942  Stmt *Handler);
3943  StmtResult ActOnSEHExceptBlock(SourceLocation Loc,
3944  Expr *FilterExpr,
3945  Stmt *Block);
3946  void ActOnStartSEHFinallyBlock();
3947  void ActOnAbortSEHFinallyBlock();
3948  StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block);
3949  StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope);
3950 
3951  void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock);
3952 
3953  bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const;
3954 
3955  /// If it's a file scoped decl that must warn if not used, keep track
3956  /// of it.
3957  void MarkUnusedFileScopedDecl(const DeclaratorDecl *D);
3958 
3959  /// DiagnoseUnusedExprResult - If the statement passed in is an expression
3960  /// whose result is unused, warn.
3961  void DiagnoseUnusedExprResult(const Stmt *S);
3962  void DiagnoseUnusedNestedTypedefs(const RecordDecl *D);
3963  void DiagnoseUnusedDecl(const NamedDecl *ND);
3964 
3965  /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null
3966  /// statement as a \p Body, and it is located on the same line.
3967  ///
3968  /// This helps prevent bugs due to typos, such as:
3969  /// if (condition);
3970  /// do_stuff();
3971  void DiagnoseEmptyStmtBody(SourceLocation StmtLoc,
3972  const Stmt *Body,
3973  unsigned DiagID);
3974 
3975  /// Warn if a for/while loop statement \p S, which is followed by
3976  /// \p PossibleBody, has a suspicious null statement as a body.
3977  void DiagnoseEmptyLoopBody(const Stmt *S,
3978  const Stmt *PossibleBody);
3979 
3980  /// Warn if a value is moved to itself.
3981  void DiagnoseSelfMove(const Expr *LHSExpr, const Expr *RHSExpr,
3982  SourceLocation OpLoc);
3983 
3984  /// Warn if we're implicitly casting from a _Nullable pointer type to a
3985  /// _Nonnull one.
3986  void diagnoseNullableToNonnullConversion(QualType DstType, QualType SrcType,
3987  SourceLocation Loc);
3988 
3989  /// Warn when implicitly casting 0 to nullptr.
3990  void diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E);
3991 
3993  return DelayedDiagnostics.push(pool);
3994  }
3995  void PopParsingDeclaration(ParsingDeclState state, Decl *decl);
3996 
3997  typedef ProcessingContextState ParsingClassState;
3998  ParsingClassState PushParsingClass() {
4000  }
4001  void PopParsingClass(ParsingClassState state) {
4003  }
4004 
4005  void redelayDiagnostics(sema::DelayedDiagnosticPool &pool);
4006 
4007  void DiagnoseAvailabilityOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
4008  const ObjCInterfaceDecl *UnknownObjCClass,
4009  bool ObjCPropertyAccess,
4010  bool AvoidPartialAvailabilityChecks = false,
4011  ObjCInterfaceDecl *ClassReceiver = nullptr);
4012 
4013  bool makeUnavailableInSystemHeader(SourceLocation loc,
4014  UnavailableAttr::ImplicitReason reason);
4015 
4016  /// Issue any -Wunguarded-availability warnings in \c FD
4017  void DiagnoseUnguardedAvailabilityViolations(Decl *FD);
4018 
4019  //===--------------------------------------------------------------------===//
4020  // Expression Parsing Callbacks: SemaExpr.cpp.
4021 
4022  bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid);
4023  bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
4024  const ObjCInterfaceDecl *UnknownObjCClass = nullptr,
4025  bool ObjCPropertyAccess = false,
4026  bool AvoidPartialAvailabilityChecks = false,
4027  ObjCInterfaceDecl *ClassReciever = nullptr);
4028  void NoteDeletedFunction(FunctionDecl *FD);
4029  void NoteDeletedInheritingConstructor(CXXConstructorDecl *CD);
4030  std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD);
4031  bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
4032  ObjCMethodDecl *Getter,
4033  SourceLocation Loc);
4034  void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
4035  ArrayRef<Expr *> Args);
4036 
4037  void PushExpressionEvaluationContext(
4038  ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl = nullptr,
4040  ExpressionEvaluationContextRecord::EK_Other);
4041  enum ReuseLambdaContextDecl_t { ReuseLambdaContextDecl };
4042  void PushExpressionEvaluationContext(
4045  ExpressionEvaluationContextRecord::EK_Other);
4046  void PopExpressionEvaluationContext();
4047 
4048  void DiscardCleanupsInEvaluationContext();
4049 
4050  ExprResult TransformToPotentiallyEvaluated(Expr *E);
4051  ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
4052 
4053  ExprResult ActOnConstantExpression(ExprResult Res);
4054 
4055  // Functions for marking a declaration referenced. These functions also
4056  // contain the relevant logic for marking if a reference to a function or
4057  // variable is an odr-use (in the C++11 sense). There are separate variants
4058  // for expressions referring to a decl; these exist because odr-use marking
4059  // needs to be delayed for some constant variables when we build one of the
4060  // named expressions.
4061  //
4062  // MightBeOdrUse indicates whether the use could possibly be an odr-use, and
4063  // should usually be true. This only needs to be set to false if the lack of
4064  // odr-use cannot be determined from the current context (for instance,
4065  // because the name denotes a virtual function and was written without an
4066  // explicit nested-name-specifier).
4067  void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse);
4068  void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func,
4069  bool MightBeOdrUse = true);
4070  void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var);
4071  void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base = nullptr);
4072  void MarkMemberReferenced(MemberExpr *E);
4073 
4074  void UpdateMarkingForLValueToRValue(Expr *E);
4075  void CleanupVarDeclMarking();
4076 
4078  TryCapture_Implicit, TryCapture_ExplicitByVal, TryCapture_ExplicitByRef
4079  };
4080 
4081  /// Try to capture the given variable.
4082  ///
4083  /// \param Var The variable to capture.
4084  ///
4085  /// \param Loc The location at which the capture occurs.
4086  ///
4087  /// \param Kind The kind of capture, which may be implicit (for either a
4088  /// block or a lambda), or explicit by-value or by-reference (for a lambda).
4089  ///
4090  /// \param EllipsisLoc The location of the ellipsis, if one is provided in
4091  /// an explicit lambda capture.
4092  ///
4093  /// \param BuildAndDiagnose Whether we are actually supposed to add the
4094  /// captures or diagnose errors. If false, this routine merely check whether
4095  /// the capture can occur without performing the capture itself or complaining
4096  /// if the variable cannot be captured.
4097  ///
4098  /// \param CaptureType Will be set to the type of the field used to capture
4099  /// this variable in the innermost block or lambda. Only valid when the
4100  /// variable can be captured.
4101  ///
4102  /// \param DeclRefType Will be set to the type of a reference to the capture
4103  /// from within the current scope. Only valid when the variable can be
4104  /// captured.
4105  ///
4106  /// \param FunctionScopeIndexToStopAt If non-null, it points to the index
4107  /// of the FunctionScopeInfo stack beyond which we do not attempt to capture.
4108  /// This is useful when enclosing lambdas must speculatively capture
4109  /// variables that may or may not be used in certain specializations of
4110  /// a nested generic lambda.
4111  ///
4112  /// \returns true if an error occurred (i.e., the variable cannot be
4113  /// captured) and false if the capture succeeded.
4114  bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, TryCaptureKind Kind,
4115  SourceLocation EllipsisLoc, bool BuildAndDiagnose,
4116  QualType &CaptureType,
4117  QualType &DeclRefType,
4118  const unsigned *const FunctionScopeIndexToStopAt);
4119 
4120  /// Try to capture the given variable.
4121  bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc,
4122  TryCaptureKind Kind = TryCapture_Implicit,
4123  SourceLocation EllipsisLoc = SourceLocation());
4124 
4125  /// Checks if the variable must be captured.
4126  bool NeedToCaptureVariable(VarDecl *Var, SourceLocation Loc);
4127 
4128  /// Given a variable, determine the type that a reference to that
4129  /// variable will have in the given scope.
4130  QualType getCapturedDeclRefType(VarDecl *Var, SourceLocation Loc);
4131 
4132  /// Mark all of the declarations referenced within a particular AST node as
4133  /// referenced. Used when template instantiation instantiates a non-dependent
4134  /// type -- entities referenced by the type are now referenced.
4135  void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T);
4136  void MarkDeclarationsReferencedInExpr(Expr *E,
4137  bool SkipLocalVariables = false);
4138 
4139  /// Try to recover by turning the given expression into a
4140  /// call. Returns true if recovery was attempted or an error was
4141  /// emitted; this may also leave the ExprResult invalid.
4142  bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD,
4143  bool ForceComplain = false,
4144  bool (*IsPlausibleResult)(QualType) = nullptr);
4145 
4146  /// Figure out if an expression could be turned into a call.
4147  bool tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy,
4148  UnresolvedSetImpl &NonTemplateOverloads);
4149 
4150  /// Conditionally issue a diagnostic based on the current
4151  /// evaluation context.
4152  ///
4153  /// \param Statement If Statement is non-null, delay reporting the
4154  /// diagnostic until the function body is parsed, and then do a basic
4155  /// reachability analysis to determine if the statement is reachable.
4156  /// If it is unreachable, the diagnostic will not be emitted.
4157  bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement,
4158  const PartialDiagnostic &PD);
4159 
4160  // Primary Expressions.
4161  SourceRange getExprRange(Expr *E) const;
4162 
4163  ExprResult ActOnIdExpression(
4164  Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
4165  UnqualifiedId &Id, bool HasTrailingLParen, bool IsAddressOfOperand,
4166  std::unique_ptr<CorrectionCandidateCallback> CCC = nullptr,
4167  bool IsInlineAsmIdentifier = false, Token *KeywordReplacement = nullptr);
4168 
4169  void DecomposeUnqualifiedId(const UnqualifiedId &Id,
4170  TemplateArgumentListInfo &Buffer,
4171  DeclarationNameInfo &NameInfo,
4172  const TemplateArgumentListInfo *&TemplateArgs);
4173 
4174  bool
4175  DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
4176  std::unique_ptr<CorrectionCandidateCallback> CCC,
4177  TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr,
4178  ArrayRef<Expr *> Args = None, TypoExpr **Out = nullptr);
4179 
4180  ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S,
4181  IdentifierInfo *II,
4182  bool AllowBuiltinCreation=false);
4183 
4184  ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS,
4185  SourceLocation TemplateKWLoc,
4186  const DeclarationNameInfo &NameInfo,
4187  bool isAddressOfOperand,
4188  const TemplateArgumentListInfo *TemplateArgs);
4189 
4190  ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
4191  ExprValueKind VK,
4192  SourceLocation Loc,
4193  const CXXScopeSpec *SS = nullptr);
4194  ExprResult
4195  BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK,
4196  const DeclarationNameInfo &NameInfo,
4197  const CXXScopeSpec *SS = nullptr,
4198  NamedDecl *FoundD = nullptr,
4199  const TemplateArgumentListInfo *TemplateArgs = nullptr);
4200  ExprResult
4201  BuildAnonymousStructUnionMemberReference(
4202  const CXXScopeSpec &SS,
4203  SourceLocation nameLoc,
4204  IndirectFieldDecl *indirectField,
4205  DeclAccessPair FoundDecl = DeclAccessPair::make(nullptr, AS_none),
4206  Expr *baseObjectExpr = nullptr,
4207  SourceLocation opLoc = SourceLocation());
4208 
4209  ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
4210  SourceLocation TemplateKWLoc,
4211  LookupResult &R,
4212  const TemplateArgumentListInfo *TemplateArgs,
4213  const Scope *S);
4214  ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS,
4215  SourceLocation TemplateKWLoc,
4216  LookupResult &R,
4217  const TemplateArgumentListInfo *TemplateArgs,
4218  bool IsDefiniteInstance,
4219  const Scope *S);
4220  bool UseArgumentDependentLookup(const CXXScopeSpec &SS,
4221  const LookupResult &R,
4222  bool HasTrailingLParen);
4223 
4224  ExprResult
4225  BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS,
4226  const DeclarationNameInfo &NameInfo,
4227  bool IsAddressOfOperand, const Scope *S,
4228  TypeSourceInfo **RecoveryTSI = nullptr);
4229 
4230  ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
4231  SourceLocation TemplateKWLoc,
4232  const DeclarationNameInfo &NameInfo,
4233  const TemplateArgumentListInfo *TemplateArgs);
4234 
4235  ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
4236  LookupResult &R,
4237  bool NeedsADL,
4238  bool AcceptInvalidDecl = false);
4239  ExprResult BuildDeclarationNameExpr(
4240  const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D,
4241  NamedDecl *FoundD = nullptr,
4242  const TemplateArgumentListInfo *TemplateArgs = nullptr,
4243  bool AcceptInvalidDecl = false);
4244 
4245  ExprResult BuildLiteralOperatorCall(LookupResult &R,
4246  DeclarationNameInfo &SuffixInfo,
4247  ArrayRef<Expr *> Args,
4248  SourceLocation LitEndLoc,
4249  TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr);
4250 
4251  ExprResult BuildPredefinedExpr(SourceLocation Loc,
4253  ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
4254  ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val);
4255 
4256  bool CheckLoopHintExpr(Expr *E, SourceLocation Loc);
4257 
4258  ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr);
4259  ExprResult ActOnCharacterConstant(const Token &Tok,
4260  Scope *UDLScope = nullptr);
4261  ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E);
4262  ExprResult ActOnParenListExpr(SourceLocation L,
4263  SourceLocation R,
4264  MultiExprArg Val);
4265 
4266  /// ActOnStringLiteral - The specified tokens were lexed as pasted string
4267  /// fragments (e.g. "foo" "bar" L"baz").
4268  ExprResult ActOnStringLiteral(ArrayRef<Token> StringToks,
4269  Scope *UDLScope = nullptr);
4270 
4271  ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc,
4272  SourceLocation DefaultLoc,
4273  SourceLocation RParenLoc,
4274  Expr *ControllingExpr,
4275  ArrayRef<ParsedType> ArgTypes,
4276  ArrayRef<Expr *> ArgExprs);
4277  ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc,
4278  SourceLocation DefaultLoc,
4279  SourceLocation RParenLoc,
4280  Expr *ControllingExpr,
4282  ArrayRef<Expr *> Exprs);
4283 
4284  // Binary/Unary Operators. 'Tok' is the token for the operator.
4285  ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc,
4286  Expr *InputExpr);
4287  ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc,
4288  UnaryOperatorKind Opc, Expr *Input);
4289  ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
4290  tok::TokenKind Op, Expr *Input);
4291 
4292  bool isQualifiedMemberAccess(Expr *E);
4293  QualType CheckAddressOfOperand(ExprResult &Operand, SourceLocation OpLoc);
4294 
4295  ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo,
4296  SourceLocation OpLoc,
4297  UnaryExprOrTypeTrait ExprKind,
4298  SourceRange R);
4299  ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc,
4300  UnaryExprOrTypeTrait ExprKind);
4301  ExprResult
4302  ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc,
4303  UnaryExprOrTypeTrait ExprKind,
4304  bool IsType, void *TyOrEx,
4305  SourceRange ArgRange);
4306 
4307  ExprResult CheckPlaceholderExpr(Expr *E);
4308  bool CheckVecStepExpr(Expr *E);
4309 
4310  bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind);
4311  bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc,
4312  SourceRange ExprRange,
4313  UnaryExprOrTypeTrait ExprKind);
4314  ExprResult ActOnSizeofParameterPackExpr(Scope *S,
4315  SourceLocation OpLoc,
4316  IdentifierInfo &Name,
4317  SourceLocation NameLoc,
4318  SourceLocation RParenLoc);
4319  ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
4320  tok::TokenKind Kind, Expr *Input);
4321 
4322  ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc,
4323  Expr *Idx, SourceLocation RLoc);
4324  ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc,
4325  Expr *Idx, SourceLocation RLoc);
4326  ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc,
4327  Expr *LowerBound, SourceLocation ColonLoc,
4328  Expr *Length, SourceLocation RBLoc);
4329 
4330  // This struct is for use by ActOnMemberAccess to allow
4331  // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after
4332  // changing the access operator from a '.' to a '->' (to see if that is the
4333  // change needed to fix an error about an unknown member, e.g. when the class
4334  // defines a custom operator->).
4336  Scope *S;
4339  };
4340 
4341  ExprResult BuildMemberReferenceExpr(
4342  Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow,
4343  CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
4344  NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo,
4345  const TemplateArgumentListInfo *TemplateArgs,
4346  const Scope *S,
4347  ActOnMemberAccessExtraArgs *ExtraArgs = nullptr);
4348 
4349  ExprResult
4350  BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc,
4351  bool IsArrow, const CXXScopeSpec &SS,
4352  SourceLocation TemplateKWLoc,
4353  NamedDecl *FirstQualifierInScope, LookupResult &R,
4354  const TemplateArgumentListInfo *TemplateArgs,
4355  const Scope *S,
4356  bool SuppressQualifierCheck = false,
4357  ActOnMemberAccessExtraArgs *ExtraArgs = nullptr);
4358 
4359  ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow,
4360  SourceLocation OpLoc,
4361  const CXXScopeSpec &SS, FieldDecl *Field,
4362  DeclAccessPair FoundDecl,
4363  const DeclarationNameInfo &MemberNameInfo);
4364 
4365  ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow);
4366 
4367  bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType,
4368  const CXXScopeSpec &SS,
4369  const LookupResult &R);
4370 
4371  ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType,
4372  bool IsArrow, SourceLocation OpLoc,
4373  const CXXScopeSpec &SS,
4374  SourceLocation TemplateKWLoc,
4375  NamedDecl *FirstQualifierInScope,
4376  const DeclarationNameInfo &NameInfo,
4377  const TemplateArgumentListInfo *TemplateArgs);
4378 
4379  ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base,
4380  SourceLocation OpLoc,
4381  tok::TokenKind OpKind,
4382  CXXScopeSpec &SS,
4383  SourceLocation TemplateKWLoc,
4384  UnqualifiedId &Member,
4385  Decl *ObjCImpDecl);
4386 
4387  void ActOnDefaultCtorInitializers(Decl *CDtorDecl);
4388  bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
4389  FunctionDecl *FDecl,
4390  const FunctionProtoType *Proto,
4391  ArrayRef<Expr *> Args,
4392  SourceLocation RParenLoc,
4393  bool ExecConfig = false);
4394  void CheckStaticArrayArgument(SourceLocation CallLoc,
4395  ParmVarDecl *Param,
4396  const Expr *ArgExpr);
4397 
4398  /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
4399  /// This provides the location of the left/right parens and a list of comma
4400  /// locations.
4401  ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc,
4402  MultiExprArg ArgExprs, SourceLocation RParenLoc,
4403  Expr *ExecConfig = nullptr,
4404  bool IsExecConfig = false);
4405  ExprResult
4406  BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, SourceLocation LParenLoc,
4407  ArrayRef<Expr *> Arg, SourceLocation RParenLoc,
4408  Expr *Config = nullptr, bool IsExecConfig = false,
4409  ADLCallKind UsesADL = ADLCallKind::NotADL);
4410 
4411  ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc,
4412  MultiExprArg ExecConfig,
4413  SourceLocation GGGLoc);
4414 
4415  ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc,
4416  Declarator &D, ParsedType &Ty,
4417  SourceLocation RParenLoc, Expr *CastExpr);
4418  ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc,
4419  TypeSourceInfo *Ty,
4420  SourceLocation RParenLoc,
4421  Expr *Op);
4422  CastKind PrepareScalarCast(ExprResult &src, QualType destType);
4423 
4424  /// Build an altivec or OpenCL literal.
4425  ExprResult BuildVectorLiteral(SourceLocation LParenLoc,
4426  SourceLocation RParenLoc, Expr *E,
4427  TypeSourceInfo *TInfo);
4428 
4429  ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME);
4430 
4431  ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
4432  ParsedType Ty,
4433  SourceLocation RParenLoc,
4434  Expr *InitExpr);
4435 
4436  ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc,
4437  TypeSourceInfo *TInfo,
4438  SourceLocation RParenLoc,
4439  Expr *LiteralExpr);
4440 
4441  ExprResult ActOnInitList(SourceLocation LBraceLoc,
4442  MultiExprArg InitArgList,
4443  SourceLocation RBraceLoc);
4444 
4445  ExprResult ActOnDesignatedInitializer(Designation &Desig,
4446  SourceLocation Loc,
4447  bool GNUSyntax,
4448  ExprResult Init);
4449 
4450 private:
4451  static BinaryOperatorKind ConvertTokenKindToBinaryOpcode(tok::TokenKind Kind);
4452 
4453 public:
4454  ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
4455  tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr);
4456  ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc,
4457  BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr);
4458  ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc,
4459  Expr *LHSExpr, Expr *RHSExpr);
4460 
4461  void DiagnoseCommaOperator(const Expr *LHS, SourceLocation Loc);
4462 
4463  /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
4464  /// in the case of a the GNU conditional expr extension.
4465  ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
4466  SourceLocation ColonLoc,
4467  Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr);
4468 
4469  /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
4470  ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
4471  LabelDecl *TheDecl);
4472 
4473  void ActOnStartStmtExpr();
4474  ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt,
4475  SourceLocation RPLoc); // "({..})"
4476  void ActOnStmtExprError();
4477 
4478  // __builtin_offsetof(type, identifier(.identifier|[expr])*)
4481  bool isBrackets; // true if [expr], false if .ident
4482  union {
4485  } U;
4486  };
4487 
4488  /// __builtin_offsetof(type, a.b[123][456].c)
4489  ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc,
4490  TypeSourceInfo *TInfo,
4491  ArrayRef<OffsetOfComponent> Components,
4492  SourceLocation RParenLoc);
4493  ExprResult ActOnBuiltinOffsetOf(Scope *S,
4494  SourceLocation BuiltinLoc,
4496  ParsedType ParsedArgTy,
4497  ArrayRef<OffsetOfComponent> Components,
4498  SourceLocation RParenLoc);
4499 
4500  // __builtin_choose_expr(constExpr, expr1, expr2)
4501  ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
4502  Expr *CondExpr, Expr *LHSExpr,
4503  Expr *RHSExpr, SourceLocation RPLoc);
4504 
4505  // __builtin_va_arg(expr, type)
4506  ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty,
4507  SourceLocation RPLoc);
4508  ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E,
4509  TypeSourceInfo *TInfo, SourceLocation RPLoc);
4510 
4511  // __null
4512  ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
4513 
4514  bool CheckCaseExpression(Expr *E);
4515 
4516  /// Describes the result of an "if-exists" condition check.
4518  /// The symbol exists.
4520 
4521  /// The symbol does not exist.
4523 
4524  /// The name is a dependent name, so the results will differ
4525  /// from one instantiation to the next.
4527 
4528  /// An error occurred.
4529  IER_Error
4530  };
4531 
4533  CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS,
4534  const DeclarationNameInfo &TargetNameInfo);
4535 
4537  CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc,
4538  bool IsIfExists, CXXScopeSpec &SS,
4539  UnqualifiedId &Name);
4540 
4541  StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc,
4542  bool IsIfExists,
4543  NestedNameSpecifierLoc QualifierLoc,
4544  DeclarationNameInfo NameInfo,
4545  Stmt *Nested);
4546  StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc,
4547  bool IsIfExists,
4548  CXXScopeSpec &SS, UnqualifiedId &Name,
4549  Stmt *Nested);
4550 
4551  //===------------------------- "Block" Extension ------------------------===//
4552 
4553  /// ActOnBlockStart - This callback is invoked when a block literal is
4554  /// started.
4555  void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
4556 
4557  /// ActOnBlockArguments - This callback allows processing of block arguments.
4558  /// If there are no arguments, this is still invoked.
4559  void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo,
4560  Scope *CurScope);
4561 
4562  /// ActOnBlockError - If there is an error parsing a block, this callback
4563  /// is invoked to pop the information about the block from the action impl.
4564  void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
4565 
4566  /// ActOnBlockStmtExpr - This is called when the body of a block statement
4567  /// literal was successfully completed. ^(int x){...}
4568  ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body,
4569  Scope *CurScope);
4570 
4571  //===---------------------------- Clang Extensions ----------------------===//
4572 
4573  /// __builtin_convertvector(...)
4574  ExprResult ActOnConvertVectorExpr(Expr *E, ParsedType ParsedDestTy,
4575  SourceLocation BuiltinLoc,
4576  SourceLocation RParenLoc);
4577 
4578  //===---------------------------- OpenCL Features -----------------------===//
4579 
4580  /// __builtin_astype(...)
4581  ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy,
4582  SourceLocation BuiltinLoc,
4583  SourceLocation RParenLoc);
4584 
4585  //===---------------------------- C++ Features --------------------------===//
4586 
4587  // Act on C++ namespaces
4588  Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc,
4589  SourceLocation NamespaceLoc,
4590  SourceLocation IdentLoc, IdentifierInfo *Ident,
4591  SourceLocation LBrace,
4592  const ParsedAttributesView &AttrList,
4594  void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace);
4595 
4596  NamespaceDecl *getStdNamespace() const;
4597  NamespaceDecl *getOrCreateStdNamespace();
4598 
4599  NamespaceDecl *lookupStdExperimentalNamespace();
4600 
4601  CXXRecordDecl *getStdBadAlloc() const;
4602  EnumDecl *getStdAlignValT() const;
4603 
4604 private:
4605  // A cache representing if we've fully checked the various comparison category
4606  // types stored in ASTContext. The bit-index corresponds to the integer value
4607  // of a ComparisonCategoryType enumerator.
4608  llvm::SmallBitVector FullyCheckedComparisonCategories;
4609 
4610  ValueDecl *tryLookupCtorInitMemberDecl(CXXRecordDecl *ClassDecl,
4611  CXXScopeSpec &SS,
4612  ParsedType TemplateTypeTy,
4613  IdentifierInfo *MemberOrBase);
4614 
4615 public:
4616  /// Lookup the specified comparison category types in the standard
4617  /// library, an check the VarDecls possibly returned by the operator<=>
4618  /// builtins for that type.
4619  ///
4620  /// \return The type of the comparison category type corresponding to the
4621  /// specified Kind, or a null type if an error occurs
4622  QualType CheckComparisonCategoryType(ComparisonCategoryType Kind,
4623  SourceLocation Loc);
4624 
4625  /// Tests whether Ty is an instance of std::initializer_list and, if
4626  /// it is and Element is not NULL, assigns the element type to Element.
4627  bool isStdInitializerList(QualType Ty, QualType *Element);
4628 
4629  /// Looks for the std::initializer_list template and instantiates it
4630  /// with Element, or emits an error if it's not found.
4631  ///
4632  /// \returns The instantiated template, or null on error.
4633  QualType BuildStdInitializerList(QualType Element, SourceLocation Loc);
4634 
4635  /// Determine whether Ctor is an initializer-list constructor, as
4636  /// defined in [dcl.init.list]p2.
4637  bool isInitListConstructor(const FunctionDecl *Ctor);
4638 
4639  Decl *ActOnUsingDirective(Scope *CurScope, SourceLocation UsingLoc,
4640  SourceLocation NamespcLoc, CXXScopeSpec &SS,
4641  SourceLocation IdentLoc,
4642  IdentifierInfo *NamespcName,
4643  const ParsedAttributesView &AttrList);
4644 
4645  void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
4646 
4647  Decl *ActOnNamespaceAliasDef(Scope *CurScope,
4648  SourceLocation NamespaceLoc,
4649  SourceLocation AliasLoc,
4650  IdentifierInfo *Alias,
4651  CXXScopeSpec &SS,
4652  SourceLocation IdentLoc,
4653  IdentifierInfo *Ident);
4654 
4655  void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow);
4656  bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target,
4657  const LookupResult &PreviousDecls,
4658  UsingShadowDecl *&PrevShadow);
4659  UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD,
4660  NamedDecl *Target,
4661  UsingShadowDecl *PrevDecl);
4662 
4663  bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc,
4664  bool HasTypenameKeyword,
4665  const CXXScopeSpec &SS,
4666  SourceLocation NameLoc,
4667  const LookupResult &Previous);
4668  bool CheckUsingDeclQualifier(SourceLocation UsingLoc,
4669  bool HasTypename,
4670  const CXXScopeSpec &SS,
4671  const DeclarationNameInfo &NameInfo,
4672  SourceLocation NameLoc);
4673 
4674  NamedDecl *BuildUsingDeclaration(
4675  Scope *S, AccessSpecifier AS, SourceLocation UsingLoc,
4676  bool HasTypenameKeyword, SourceLocation TypenameLoc, CXXScopeSpec &SS,
4677  DeclarationNameInfo NameInfo, SourceLocation EllipsisLoc,
4678  const ParsedAttributesView &AttrList, bool IsInstantiation);
4679  NamedDecl *BuildUsingPackDecl(NamedDecl *InstantiatedFrom,
4680  ArrayRef<NamedDecl *> Expansions);
4681 
4682  bool CheckInheritingConstructorUsingDecl(UsingDecl *UD);
4683 
4684  /// Given a derived-class using shadow declaration for a constructor and the
4685  /// correspnding base class constructor, find or create the implicit
4686  /// synthesized derived class constructor to use for this initialization.
4687  CXXConstructorDecl *
4688  findInheritingConstructor(SourceLocation Loc, CXXConstructorDecl *BaseCtor,
4689  ConstructorUsingShadowDecl *DerivedShadow);
4690 
4691  Decl *ActOnUsingDeclaration(Scope *CurScope, AccessSpecifier AS,
4692  SourceLocation UsingLoc,
4693  SourceLocation TypenameLoc, CXXScopeSpec &SS,
4694  UnqualifiedId &Name, SourceLocation EllipsisLoc,
4695  const ParsedAttributesView &AttrList);
4696  Decl *ActOnAliasDeclaration(Scope *CurScope, AccessSpecifier AS,
4697  MultiTemplateParamsArg TemplateParams,
4698  SourceLocation UsingLoc, UnqualifiedId &Name,
4699  const ParsedAttributesView &AttrList,
4700  TypeResult Type, Decl *DeclFromDeclSpec);
4701 
4702  /// BuildCXXConstructExpr - Creates a complete call to a constructor,
4703  /// including handling of its default argument expressions.
4704  ///
4705  /// \param ConstructKind - a CXXConstructExpr::ConstructionKind
4706  ExprResult
4707  BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
4708  NamedDecl *FoundDecl,
4709  CXXConstructorDecl *Constructor, MultiExprArg Exprs,
4710  bool HadMultipleCandidates, bool IsListInitialization,
4711  bool IsStdInitListInitialization,
4712  bool RequiresZeroInit, unsigned ConstructKind,
4713  SourceRange ParenRange);
4714 
4715  /// Build a CXXConstructExpr whose constructor has already been resolved if
4716  /// it denotes an inherited constructor.
4717  ExprResult
4718  BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
4719  CXXConstructorDecl *Constructor, bool Elidable,
4720  MultiExprArg Exprs,
4721  bool HadMultipleCandidates, bool IsListInitialization,
4722  bool IsStdInitListInitialization,
4723  bool RequiresZeroInit, unsigned ConstructKind,
4724  SourceRange ParenRange);
4725 
4726  // FIXME: Can we remove this and have the above BuildCXXConstructExpr check if
4727  // the constructor can be elidable?
4728  ExprResult
4729  BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
4730  NamedDecl *FoundDecl,
4731  CXXConstructorDecl *Constructor, bool Elidable,
4732  MultiExprArg Exprs, bool HadMultipleCandidates,
4733  bool IsListInitialization,
4734  bool IsStdInitListInitialization, bool RequiresZeroInit,
4735  unsigned ConstructKind, SourceRange ParenRange);
4736 
4737  ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field);
4738 
4739 
4740  /// Instantiate or parse a C++ default argument expression as necessary.
4741  /// Return true on error.
4742  bool CheckCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD,
4743  ParmVarDecl *Param);
4744 
4745  /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating
4746  /// the default expr if needed.
4747  ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc,
4748  FunctionDecl *FD,
4749  ParmVarDecl *Param);
4750 
4751  /// FinalizeVarWithDestructor - Prepare for calling destructor on the
4752  /// constructed variable.
4753  void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType);
4754 
4755  /// Helper class that collects exception specifications for
4756  /// implicitly-declared special member functions.
4758  // Pointer to allow copying
4759  Sema *Self;
4760  // We order exception specifications thus:
4761  // noexcept is the most restrictive, but is only used in C++11.
4762  // throw() comes next.
4763  // Then a throw(collected exceptions)
4764  // Finally no specification, which is expressed as noexcept(false).
4765  // throw(...) is used instead if any called function uses it.
4766  ExceptionSpecificationType ComputedEST;
4767  llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen;
4768  SmallVector<QualType, 4> Exceptions;
4769 
4770  void ClearExceptions() {
4771  ExceptionsSeen.clear();
4772  Exceptions.clear();
4773  }
4774 
4775  public:
4777  : Self(&Self), ComputedEST(EST_BasicNoexcept) {
4778  if (!Self.getLangOpts().CPlusPlus11)
4779  ComputedEST = EST_DynamicNone;
4780  }
4781 
4782  /// Get the computed exception specification type.
4784  assert(!isComputedNoexcept(ComputedEST) &&
4785  "noexcept(expr) should not be a possible result");
4786  return ComputedEST;
4787  }
4788 
4789  /// The number of exceptions in the exception specification.
4790  unsigned size() const { return Exceptions.size(); }
4791 
4792  /// The set of exceptions in the exception specification.
4793  const QualType *data() const { return Exceptions.data(); }
4794 
4795  /// Integrate another called method into the collected data.
4796  void CalledDecl(SourceLocation CallLoc, const CXXMethodDecl *Method);
4797 
4798  /// Integrate an invoked expression into the collected data.
4799  void CalledExpr(Expr *E);
4800 
4801  /// Overwrite an EPI's exception specification with this
4802  /// computed exception specification.
4805  ESI.Type = getExceptionSpecType();
4806  if (ESI.Type == EST_Dynamic) {
4807  ESI.Exceptions = Exceptions;
4808  } else if (ESI.Type == EST_None) {
4809  /// C++11 [except.spec]p14:
4810  /// The exception-specification is noexcept(false) if the set of
4811  /// potential exceptions of the special member function contains "any"
4812  ESI.Type = EST_NoexceptFalse;
4814  tok::kw_false).get();
4815  }
4816  return ESI;
4817  }
4818  };
4819 
4820  /// Determine what sort of exception specification a defaulted
4821  /// copy constructor of a class will have.
4823  ComputeDefaultedDefaultCtorExceptionSpec(SourceLocation Loc,
4824  CXXMethodDecl *MD);
4825 
4826  /// Determine what sort of exception specification a defaulted
4827  /// default constructor of a class will have, and whether the parameter
4828  /// will be const.
4830  ComputeDefaultedCopyCtorExceptionSpec(CXXMethodDecl *MD);
4831 
4832  /// Determine what sort of exception specification a defaulted
4833  /// copy assignment operator of a class will have, and whether the
4834  /// parameter will be const.
4836  ComputeDefaultedCopyAssignmentExceptionSpec(CXXMethodDecl *MD);
4837 
4838  /// Determine what sort of exception specification a defaulted move
4839  /// constructor of a class will have.
4841  ComputeDefaultedMoveCtorExceptionSpec(CXXMethodDecl *MD);
4842 
4843  /// Determine what sort of exception specification a defaulted move
4844  /// assignment operator of a class will have.
4846  ComputeDefaultedMoveAssignmentExceptionSpec(CXXMethodDecl *MD);
4847 
4848  /// Determine what sort of exception specification a defaulted
4849  /// destructor of a class will have.
4851  ComputeDefaultedDtorExceptionSpec(CXXMethodDecl *MD);
4852 
4853  /// Determine what sort of exception specification an inheriting
4854  /// constructor of a class will have.
4856  ComputeInheritingCtorExceptionSpec(SourceLocation Loc,
4857  CXXConstructorDecl *CD);
4858 
4859  /// Evaluate the implicit exception specification for a defaulted
4860  /// special member function.
4861  void EvaluateImplicitExceptionSpec(SourceLocation Loc, CXXMethodDecl *MD);
4862 
4863  /// Check the given noexcept-specifier, convert its expression, and compute
4864  /// the appropriate ExceptionSpecificationType.
4865  ExprResult ActOnNoexceptSpec(SourceLocation NoexceptLoc, Expr *NoexceptExpr,
4867 
4868  /// Check the given exception-specification and update the
4869  /// exception specification information with the results.
4870  void checkExceptionSpecification(bool IsTopLevel,
4872  ArrayRef<ParsedType> DynamicExceptions,
4873  ArrayRef<SourceRange> DynamicExceptionRanges,
4874  Expr *NoexceptExpr,
4875  SmallVectorImpl<QualType> &Exceptions,
4877 
4878  /// Determine if we're in a case where we need to (incorrectly) eagerly
4879  /// parse an exception specification to work around a libstdc++ bug.
4880  bool isLibstdcxxEagerExceptionSpecHack(const Declarator &D);
4881 
4882  /// Add an exception-specification to the given member function
4883  /// (or member function template). The exception-specification was parsed
4884  /// after the method itself was declared.
4885  void actOnDelayedExceptionSpecification(Decl *Method,
4887  SourceRange SpecificationRange,
4888  ArrayRef<ParsedType> DynamicExceptions,
4889  ArrayRef<SourceRange> DynamicExceptionRanges,
4890  Expr *NoexceptExpr);
4891 
4893 
4894  /// Determine if a special member function should have a deleted
4895  /// definition when it is defaulted.
4896  bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM,
4897  InheritedConstructorInfo *ICI = nullptr,
4898  bool Diagnose = false);
4899 
4900  /// Declare the implicit default constructor for the given class.
4901  ///
4902  /// \param ClassDecl The class declaration into which the implicit
4903  /// default constructor will be added.
4904  ///
4905  /// \returns The implicitly-declared default constructor.
4906  CXXConstructorDecl *DeclareImplicitDefaultConstructor(
4907  CXXRecordDecl *ClassDecl);
4908 
4909  /// DefineImplicitDefaultConstructor - Checks for feasibility of
4910  /// defining this constructor as the default constructor.
4911  void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
4912  CXXConstructorDecl *Constructor);
4913 
4914  /// Declare the implicit destructor for the given class.
4915  ///
4916  /// \param ClassDecl The class declaration into which the implicit
4917  /// destructor will be added.
4918  ///
4919  /// \returns The implicitly-declared destructor.
4920  CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl);
4921 
4922  /// DefineImplicitDestructor - Checks for feasibility of
4923  /// defining this destructor as the default destructor.
4924  void DefineImplicitDestructor(SourceLocation CurrentLocation,
4925  CXXDestructorDecl *Destructor);
4926 
4927  /// Build an exception spec for destructors that don't have one.
4928  ///
4929  /// C++11 says that user-defined destructors with no exception spec get one
4930  /// that looks as if the destructor was implicitly declared.
4931  void AdjustDestructorExceptionSpec(CXXDestructorDecl *Destructor);
4932 
4933  /// Define the specified inheriting constructor.
4934  void DefineInheritingConstructor(SourceLocation UseLoc,
4935  CXXConstructorDecl *Constructor);
4936 
4937  /// Declare the implicit copy constructor for the given class.
4938  ///
4939  /// \param ClassDecl The class declaration into which the implicit
4940  /// copy constructor will be added.
4941  ///
4942  /// \returns The implicitly-declared copy constructor.
4943  CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl);
4944 
4945  /// DefineImplicitCopyConstructor - Checks for feasibility of
4946  /// defining this constructor as the copy constructor.
4947  void DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
4948  CXXConstructorDecl *Constructor);
4949 
4950  /// Declare the implicit move constructor for the given class.
4951  ///
4952  /// \param ClassDecl The Class declaration into which the implicit
4953  /// move constructor will be added.
4954  ///
4955  /// \returns The implicitly-declared move constructor, or NULL if it wasn't
4956  /// declared.
4957  CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl);
4958 
4959  /// DefineImplicitMoveConstructor - Checks for feasibility of
4960  /// defining this constructor as the move constructor.
4961  void DefineImplicitMoveConstructor(SourceLocation CurrentLocation,
4962  CXXConstructorDecl *Constructor);
4963 
4964  /// Declare the implicit copy assignment operator for the given class.
4965  ///
4966  /// \param ClassDecl The class declaration into which the implicit
4967  /// copy assignment operator will be added.
4968  ///
4969  /// \returns The implicitly-declared copy assignment operator.
4970  CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl);
4971 
4972  /// Defines an implicitly-declared copy assignment operator.
4973  void DefineImplicitCopyAssignment(SourceLocation CurrentLocation,
4974  CXXMethodDecl *MethodDecl);
4975 
4976  /// Declare the implicit move assignment operator for the given class.
4977  ///
4978  /// \param ClassDecl The Class declaration into which the implicit
4979  /// move assignment operator will be added.
4980  ///
4981  /// \returns The implicitly-declared move assignment operator, or NULL if it
4982  /// wasn't declared.
4983  CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl);
4984 
4985  /// Defines an implicitly-declared move assignment operator.
4986  void DefineImplicitMoveAssignment(SourceLocation CurrentLocation,
4987  CXXMethodDecl *MethodDecl);
4988 
4989  /// Force the declaration of any implicitly-declared members of this
4990  /// class.
4991  void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class);
4992 
4993  /// Check a completed declaration of an implicit special member.
4994  void CheckImplicitSpecialMemberDeclaration(Scope *S, FunctionDecl *FD);
4995 
4996  /// Determine whether the given function is an implicitly-deleted
4997  /// special member function.
4998  bool isImplicitlyDeleted(FunctionDecl *FD);
4999 
5000  /// Check whether 'this' shows up in the type of a static member
5001  /// function after the (naturally empty) cv-qualifier-seq would be.
5002  ///
5003  /// \returns true if an error occurred.
5004  bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method);
5005 
5006  /// Whether this' shows up in the exception specification of a static
5007  /// member function.
5008  bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method);
5009 
5010  /// Check whether 'this' shows up in the attributes of the given
5011  /// static member function.
5012  ///
5013  /// \returns true if an error occurred.
5014  bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method);
5015 
5016  /// MaybeBindToTemporary - If the passed in expression has a record type with
5017  /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise
5018  /// it simply returns the passed in expression.
5019  ExprResult MaybeBindToTemporary(Expr *E);
5020 
5021  bool CompleteConstructorCall(CXXConstructorDecl *Constructor,
5022  MultiExprArg ArgsPtr,
5023  SourceLocation Loc,
5024  SmallVectorImpl<Expr*> &ConvertedArgs,
5025  bool AllowExplicit = false,
5026  bool IsListInitialization = false);
5027 
5028  ParsedType getInheritingConstructorName(CXXScopeSpec &SS,
5029  SourceLocation NameLoc,
5030  IdentifierInfo &Name);
5031 
5032  ParsedType getConstructorName(IdentifierInfo &II, SourceLocation NameLoc,
5033  Scope *S, CXXScopeSpec &SS,
5034  bool EnteringContext);
5035  ParsedType getDestructorName(SourceLocation TildeLoc,
5036  IdentifierInfo &II, SourceLocation NameLoc,
5037  Scope *S, CXXScopeSpec &SS,
5038  ParsedType ObjectType,
5039  bool EnteringContext);
5040 
5041  ParsedType getDestructorTypeForDecltype(const DeclSpec &DS,
5042  ParsedType ObjectType);
5043 
5044  // Checks that reinterpret casts don't have undefined behavior.
5045  void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType,
5046  bool IsDereference, SourceRange Range);
5047 
5048  /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
5049  ExprResult ActOnCXXNamedCast(SourceLocation OpLoc,
5051  SourceLocation LAngleBracketLoc,
5052  Declarator &D,
5053  SourceLocation RAngleBracketLoc,
5054  SourceLocation LParenLoc,
5055  Expr *E,
5056  SourceLocation RParenLoc);
5057 
5058  ExprResult BuildCXXNamedCast(SourceLocation OpLoc,
5059  tok::TokenKind Kind,
5060  TypeSourceInfo *Ty,
5061  Expr *E,
5062  SourceRange AngleBrackets,
5063  SourceRange Parens);
5064 
5065  ExprResult BuildCXXTypeId(QualType TypeInfoType,
5066  SourceLocation TypeidLoc,
5067  TypeSourceInfo *Operand,
5068  SourceLocation RParenLoc);
5069  ExprResult BuildCXXTypeId(QualType TypeInfoType,
5070  SourceLocation TypeidLoc,
5071  Expr *Operand,
5072  SourceLocation RParenLoc);
5073 
5074  /// ActOnCXXTypeid - Parse typeid( something ).
5075  ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
5076  SourceLocation LParenLoc, bool isType,
5077  void *TyOrExpr,
5078  SourceLocation RParenLoc);
5079 
5080  ExprResult BuildCXXUuidof(QualType TypeInfoType,
5081  SourceLocation TypeidLoc,
5082  TypeSourceInfo *Operand,
5083  SourceLocation RParenLoc);
5084  ExprResult BuildCXXUuidof(QualType TypeInfoType,
5085  SourceLocation TypeidLoc,
5086  Expr *Operand,
5087  SourceLocation RParenLoc);
5088 
5089  /// ActOnCXXUuidof - Parse __uuidof( something ).
5090  ExprResult ActOnCXXUuidof(SourceLocation OpLoc,
5091  SourceLocation LParenLoc, bool isType,
5092  void *TyOrExpr,
5093  SourceLocation RParenLoc);
5094 
5095  /// Handle a C++1z fold-expression: ( expr op ... op expr ).
5096  ExprResult ActOnCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
5097  tok::TokenKind Operator,
5098  SourceLocation EllipsisLoc, Expr *RHS,
5099  SourceLocation RParenLoc);
5100  ExprResult BuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
5101  BinaryOperatorKind Operator,
5102  SourceLocation EllipsisLoc, Expr *RHS,
5103  SourceLocation RParenLoc);
5104  ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
5105  BinaryOperatorKind Operator);
5106 
5107  //// ActOnCXXThis - Parse 'this' pointer.
5108  ExprResult ActOnCXXThis(SourceLocation loc);
5109 
5110  /// Try to retrieve the type of the 'this' pointer.
5111  ///
5112  /// \returns The type of 'this', if possible. Otherwise, returns a NULL type.
5113  QualType getCurrentThisType();
5114 
5115  /// When non-NULL, the C++ 'this' expression is allowed despite the
5116  /// current context not being a non-static member function. In such cases,
5117  /// this provides the type used for 'this'.
5119 
5120  /// RAII object used to temporarily allow the C++ 'this' expression
5121  /// to be used, with the given qualifiers on the current class type.
5123  Sema &S;
5124  QualType OldCXXThisTypeOverride;
5125  bool Enabled;
5126 
5127  public:
5128  /// Introduce a new scope where 'this' may be allowed (when enabled),
5129  /// using the given declaration (which is either a class template or a
5130  /// class) along with the given qualifiers.
5131  /// along with the qualifiers placed on '*this'.
5132  CXXThisScopeRAII(Sema &S, Decl *ContextDecl, Qualifiers CXXThisTypeQuals,
5133  bool Enabled = true);
5134 
5135  ~CXXThisScopeRAII();
5136  };
5137 
5138  /// Make sure the value of 'this' is actually available in the current
5139  /// context, if it is a potentially evaluated context.
5140  ///
5141  /// \param Loc The location at which the capture of 'this' occurs.
5142  ///
5143  /// \param Explicit Whether 'this' is explicitly captured in a lambda
5144  /// capture list.
5145  ///
5146  /// \param FunctionScopeIndexToStopAt If non-null, it points to the index
5147  /// of the FunctionScopeInfo stack beyond which we do not attempt to capture.
5148  /// This is useful when enclosing lambdas must speculatively capture
5149  /// 'this' that may or may not be used in certain specializations of
5150  /// a nested generic lambda (depending on whether the name resolves to
5151  /// a non-static member function or a static function).
5152  /// \return returns 'true' if failed, 'false' if success.
5153  bool CheckCXXThisCapture(SourceLocation Loc, bool Explicit = false,
5154  bool BuildAndDiagnose = true,
5155  const unsigned *const FunctionScopeIndexToStopAt = nullptr,
5156  bool ByCopy = false);
5157 
5158  /// Determine whether the given type is the type of *this that is used
5159  /// outside of the body of a member function for a type that is currently
5160  /// being defined.
5161  bool isThisOutsideMemberFunctionBody(QualType BaseType);
5162 
5163  /// ActOnCXXBoolLiteral - Parse {true,false} literals.
5164  ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
5165 
5166 
5167  /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals.
5168  ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
5169