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