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