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