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  /// All the members seen during a class definition which were both
686  /// explicitly defaulted and had explicitly-specified exception
687  /// specifications, along with the function type containing their
688  /// user-specified exception specification. Those exception specifications
689  /// were overridden with the default specifications, but we still need to
690  /// check whether they are compatible with the default specification, and
691  /// we can't do that until the nesting set of class definitions is complete.
694 
695  typedef llvm::MapVector<const FunctionDecl *,
696  std::unique_ptr<LateParsedTemplate>>
699 
700  /// Callback to the parser to parse templated functions when needed.
701  typedef void LateTemplateParserCB(void *P, LateParsedTemplate &LPT);
702  typedef void LateTemplateParserCleanupCB(void *P);
703  LateTemplateParserCB *LateTemplateParser;
704  LateTemplateParserCleanupCB *LateTemplateParserCleanup;
706 
707  void SetLateTemplateParser(LateTemplateParserCB *LTP,
708  LateTemplateParserCleanupCB *LTPCleanup,
709  void *P) {
710  LateTemplateParser = LTP;
711  LateTemplateParserCleanup = LTPCleanup;
712  OpaqueParser = P;
713  }
714 
715  class DelayedDiagnostics;
716 
718  sema::DelayedDiagnosticPool *SavedPool;
720  };
723 
724  /// A class which encapsulates the logic for delaying diagnostics
725  /// during parsing and other processing.
727  /// The current pool of diagnostics into which delayed
728  /// diagnostics should go.
730 
731  public:
732  DelayedDiagnostics() : CurPool(nullptr) {}
733 
734  /// Adds a delayed diagnostic.
735  void add(const sema::DelayedDiagnostic &diag); // in DelayedDiagnostic.h
736 
737  /// Determines whether diagnostics should be delayed.
738  bool shouldDelayDiagnostics() { return CurPool != nullptr; }
739 
740  /// Returns the current delayed-diagnostics pool.
742  return CurPool;
743  }
744 
745  /// Enter a new scope. Access and deprecation diagnostics will be
746  /// collected in this pool.
749  state.SavedPool = CurPool;
750  CurPool = &pool;
751  return state;
752  }
753 
754  /// Leave a delayed-diagnostic state that was previously pushed.
755  /// Do not emit any of the diagnostics. This is performed as part
756  /// of the bookkeeping of popping a pool "properly".
758  CurPool = state.SavedPool;
759  }
760 
761  /// Enter a new scope where access and deprecation diagnostics are
762  /// not delayed.
765  state.SavedPool = CurPool;
766  CurPool = nullptr;
767  return state;
768  }
769 
770  /// Undo a previous pushUndelayed().
772  assert(CurPool == nullptr);
773  CurPool = state.SavedPool;
774  }
776 
777  /// A RAII object to temporarily push a declaration context.
778  class ContextRAII {
779  private:
780  Sema &S;
781  DeclContext *SavedContext;
782  ProcessingContextState SavedContextState;
783  QualType SavedCXXThisTypeOverride;
784 
785  public:
786  ContextRAII(Sema &S, DeclContext *ContextToPush, bool NewThisContext = true)
787  : S(S), SavedContext(S.CurContext),
788  SavedContextState(S.DelayedDiagnostics.pushUndelayed()),
789  SavedCXXThisTypeOverride(S.CXXThisTypeOverride)
790  {
791  assert(ContextToPush && "pushing null context");
792  S.CurContext = ContextToPush;
793  if (NewThisContext)
795  }
796 
797  void pop() {
798  if (!SavedContext) return;
799  S.CurContext = SavedContext;
800  S.DelayedDiagnostics.popUndelayed(SavedContextState);
801  S.CXXThisTypeOverride = SavedCXXThisTypeOverride;
802  SavedContext = nullptr;
803  }
804 
806  pop();
807  }
808  };
809 
810  /// RAII object to handle the state changes required to synthesize
811  /// a function body.
813  Sema &S;
814  Sema::ContextRAII SavedContext;
815  bool PushedCodeSynthesisContext = false;
816 
817  public:
819  : S(S), SavedContext(S, DC) {
820  S.PushFunctionScope();
822  Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
823  if (auto *FD = dyn_cast<FunctionDecl>(DC))
824  FD->setWillHaveBody(true);
825  else
826  assert(isa<ObjCMethodDecl>(DC));
827  }
828 
830  assert(!PushedCodeSynthesisContext);
831 
833  Ctx.Kind = Sema::CodeSynthesisContext::DefiningSynthesizedFunction;
834  Ctx.PointOfInstantiation = UseLoc;
835  Ctx.Entity = cast<Decl>(S.CurContext);
837 
838  PushedCodeSynthesisContext = true;
839  }
840 
842  if (PushedCodeSynthesisContext)
844  if (auto *FD = dyn_cast<FunctionDecl>(S.CurContext))
845  FD->setWillHaveBody(false);
848  }
849  };
850 
851  /// WeakUndeclaredIdentifiers - Identifiers contained in
852  /// \#pragma weak before declared. rare. may alias another
853  /// identifier, declared or undeclared
854  llvm::MapVector<IdentifierInfo *, WeakInfo> WeakUndeclaredIdentifiers;
855 
856  /// ExtnameUndeclaredIdentifiers - Identifiers contained in
857  /// \#pragma redefine_extname before declared. Used in Solaris system headers
858  /// to define functions that occur in multiple standards to call the version
859  /// in the currently selected standard.
860  llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*> ExtnameUndeclaredIdentifiers;
861 
862 
863  /// Load weak undeclared identifiers from the external source.
864  void LoadExternalWeakUndeclaredIdentifiers();
865 
866  /// WeakTopLevelDecl - Translation-unit scoped declarations generated by
867  /// \#pragma weak during processing of other Decls.
868  /// I couldn't figure out a clean way to generate these in-line, so
869  /// we store them here and handle separately -- which is a hack.
870  /// It would be best to refactor this.
872 
874 
875  /// Translation Unit Scope - useful to Objective-C actions that need
876  /// to lookup file scope declarations in the "ordinary" C decl namespace.
877  /// For example, user-defined classes, built-in "id" type, etc.
879 
880  /// The C++ "std" namespace, where the standard library resides.
882 
883  /// The C++ "std::bad_alloc" class, which is defined by the C++
884  /// standard library.
886 
887  /// The C++ "std::align_val_t" enum class, which is defined by the C++
888  /// standard library.
890 
891  /// The C++ "std::experimental" namespace, where the experimental parts
892  /// of the standard library resides.
894 
895  /// The C++ "std::initializer_list" template, which is defined in
896  /// <initializer_list>.
898 
899  /// The C++ "std::coroutine_traits" template, which is defined in
900  /// <coroutine_traits>
902 
903  /// The C++ "type_info" declaration, which is defined in <typeinfo>.
905 
906  /// The MSVC "_GUID" struct, which is defined in MSVC header files.
908 
909  /// Caches identifiers/selectors for NSFoundation APIs.
910  std::unique_ptr<NSAPI> NSAPIObj;
911 
912  /// The declaration of the Objective-C NSNumber class.
914 
915  /// The declaration of the Objective-C NSValue class.
917 
918  /// Pointer to NSNumber type (NSNumber *).
920 
921  /// Pointer to NSValue type (NSValue *).
923 
924  /// The Objective-C NSNumber methods used to create NSNumber literals.
925  ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods];
926 
927  /// The declaration of the Objective-C NSString class.
929 
930  /// Pointer to NSString type (NSString *).
932 
933  /// The declaration of the stringWithUTF8String: method.
935 
936  /// The declaration of the valueWithBytes:objCType: method.
938 
939  /// The declaration of the Objective-C NSArray class.
941 
942  /// The declaration of the arrayWithObjects:count: method.
944 
945  /// The declaration of the Objective-C NSDictionary class.
947 
948  /// The declaration of the dictionaryWithObjects:forKeys:count: method.
950 
951  /// id<NSCopying> type.
953 
954  /// will hold 'respondsToSelector:'
956 
957  /// A flag to remember whether the implicit forms of operator new and delete
958  /// have been declared.
960 
961  /// A flag to indicate that we're in a context that permits abstract
962  /// references to fields. This is really a
964 
965  /// Describes how the expressions currently being parsed are
966  /// evaluated at run-time, if at all.
968  /// The current expression and its subexpressions occur within an
969  /// unevaluated operand (C++11 [expr]p7), such as the subexpression of
970  /// \c sizeof, where the type of the expression may be significant but
971  /// no code will be generated to evaluate the value of the expression at
972  /// run time.
973  Unevaluated,
974 
975  /// The current expression occurs within a braced-init-list within
976  /// an unevaluated operand. This is mostly like a regular unevaluated
977  /// context, except that we still instantiate constexpr functions that are
978  /// referenced here so that we can perform narrowing checks correctly.
979  UnevaluatedList,
980 
981  /// The current expression occurs within a discarded statement.
982  /// This behaves largely similarly to an unevaluated operand in preventing
983  /// definitions from being required, but not in other ways.
984  DiscardedStatement,
985 
986  /// The current expression occurs within an unevaluated
987  /// operand that unconditionally permits abstract references to
988  /// fields, such as a SIZE operator in MS-style inline assembly.
989  UnevaluatedAbstract,
990 
991  /// The current context is "potentially evaluated" in C++11 terms,
992  /// but the expression is evaluated at compile-time (like the values of
993  /// cases in a switch statement).
994  ConstantEvaluated,
995 
996  /// The current expression is potentially evaluated at run time,
997  /// which means that code may be generated to evaluate the value of the
998  /// expression at run time.
999  PotentiallyEvaluated,
1000 
1001  /// The current expression is potentially evaluated, but any
1002  /// declarations referenced inside that expression are only used if
1003  /// in fact the current expression is used.
1004  ///
1005  /// This value is used when parsing default function arguments, for which
1006  /// we would like to provide diagnostics (e.g., passing non-POD arguments
1007  /// through varargs) but do not want to mark declarations as "referenced"
1008  /// until the default argument is used.
1009  PotentiallyEvaluatedIfUsed
1010  };
1011 
1012  /// Data structure used to record current or nested
1013  /// expression evaluation contexts.
1015  /// The expression evaluation context.
1017 
1018  /// Whether the enclosing context needed a cleanup.
1020 
1021  /// Whether we are in a decltype expression.
1023 
1024  /// The number of active cleanup objects when we entered
1025  /// this expression evaluation context.
1027 
1028  /// The number of typos encountered during this expression evaluation
1029  /// context (i.e. the number of TypoExprs created).
1030  unsigned NumTypos;
1031 
1033 
1034  /// The lambdas that are present within this context, if it
1035  /// is indeed an unevaluated context.
1037 
1038  /// The declaration that provides context for lambda expressions
1039  /// and block literals if the normal declaration context does not
1040  /// suffice, e.g., in a default function argument.
1042 
1043  /// The context information used to mangle lambda expressions
1044  /// and block literals within this context.
1045  ///
1046  /// This mangling information is allocated lazily, since most contexts
1047  /// do not have lambda expressions or block literals.
1048  std::unique_ptr<MangleNumberingContext> MangleNumbering;
1049 
1050  /// If we are processing a decltype type, a set of call expressions
1051  /// for which we have deferred checking the completeness of the return type.
1053 
1054  /// If we are processing a decltype type, a set of temporary binding
1055  /// expressions for which we have deferred checking the destructor.
1057 
1058  llvm::SmallPtrSet<const Expr *, 8> PossibleDerefs;
1059 
1060  /// \brief Describes whether we are in an expression constext which we have
1061  /// to handle differently.
1063  EK_Decltype, EK_TemplateArgument, EK_Other
1064  } ExprContext;
1065 
1067  unsigned NumCleanupObjects,
1068  CleanupInfo ParentCleanup,
1069  Decl *ManglingContextDecl,
1070  ExpressionKind ExprContext)
1071  : Context(Context), ParentCleanup(ParentCleanup),
1072  NumCleanupObjects(NumCleanupObjects), NumTypos(0),
1073  ManglingContextDecl(ManglingContextDecl), MangleNumbering(),
1074  ExprContext(ExprContext) {}
1075 
1076  /// Retrieve the mangling numbering context, used to consistently
1077  /// number constructs like lambdas for mangling.
1078  MangleNumberingContext &getMangleNumberingContext(ASTContext &Ctx);
1079 
1080  bool isUnevaluated() const {
1081  return Context == ExpressionEvaluationContext::Unevaluated ||
1082  Context == ExpressionEvaluationContext::UnevaluatedAbstract ||
1083  Context == ExpressionEvaluationContext::UnevaluatedList;
1084  }
1085  bool isConstantEvaluated() const {
1086  return Context == ExpressionEvaluationContext::ConstantEvaluated;
1087  }
1088  };
1089 
1090  /// A stack of expression evaluation contexts.
1092 
1093  /// Emit a warning for all pending noderef expressions that we recorded.
1094  void WarnOnPendingNoDerefs(ExpressionEvaluationContextRecord &Rec);
1095 
1096  /// Compute the mangling number context for a lambda expression or
1097  /// block literal.
1098  ///
1099  /// \param DC - The DeclContext containing the lambda expression or
1100  /// block literal.
1101  /// \param[out] ManglingContextDecl - Returns the ManglingContextDecl
1102  /// associated with the context, if relevant.
1103  MangleNumberingContext *getCurrentMangleNumberContext(
1104  const DeclContext *DC,
1105  Decl *&ManglingContextDecl);
1106 
1107 
1108  /// SpecialMemberOverloadResult - The overloading result for a special member
1109  /// function.
1110  ///
1111  /// This is basically a wrapper around PointerIntPair. The lowest bits of the
1112  /// integer are used to determine whether overload resolution succeeded.
1114  public:
1115  enum Kind {
1118  Success
1119  };
1120 
1121  private:
1122  llvm::PointerIntPair<CXXMethodDecl*, 2> Pair;
1123 
1124  public:
1127  : Pair(MD, MD->isDeleted() ? NoMemberOrDeleted : Success) {}
1128 
1129  CXXMethodDecl *getMethod() const { return Pair.getPointer(); }
1130  void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); }
1131 
1132  Kind getKind() const { return static_cast<Kind>(Pair.getInt()); }
1133  void setKind(Kind K) { Pair.setInt(K); }
1134  };
1135 
1137  : public llvm::FastFoldingSetNode,
1139  public:
1140  SpecialMemberOverloadResultEntry(const llvm::FoldingSetNodeID &ID)
1141  : FastFoldingSetNode(ID)
1142  {}
1143  };
1144 
1145  /// A cache of special member function overload resolution results
1146  /// for C++ records.
1147  llvm::FoldingSet<SpecialMemberOverloadResultEntry> SpecialMemberCache;
1148 
1149  /// A cache of the flags available in enumerations with the flag_bits
1150  /// attribute.
1151  mutable llvm::DenseMap<const EnumDecl*, llvm::APInt> FlagBitsCache;
1152 
1153  /// The kind of translation unit we are processing.
1154  ///
1155  /// When we're processing a complete translation unit, Sema will perform
1156  /// end-of-translation-unit semantic tasks (such as creating
1157  /// initializers for tentative definitions in C) once parsing has
1158  /// completed. Modules and precompiled headers perform different kinds of
1159  /// checks.
1161 
1162  llvm::BumpPtrAllocator BumpAlloc;
1163 
1164  /// The number of SFINAE diagnostics that have been trapped.
1166 
1167  typedef llvm::DenseMap<ParmVarDecl *, llvm::TinyPtrVector<ParmVarDecl *>>
1169 
1170  /// A mapping from parameters with unparsed default arguments to the
1171  /// set of instantiations of each parameter.
1172  ///
1173  /// This mapping is a temporary data structure used when parsing
1174  /// nested class templates or nested classes of class templates,
1175  /// where we might end up instantiating an inner class before the
1176  /// default arguments of its methods have been parsed.
1178 
1179  // Contains the locations of the beginning of unparsed default
1180  // argument locations.
1181  llvm::DenseMap<ParmVarDecl *, SourceLocation> UnparsedDefaultArgLocs;
1182 
1183  /// UndefinedInternals - all the used, undefined objects which require a
1184  /// definition in this translation unit.
1185  llvm::MapVector<NamedDecl *, SourceLocation> UndefinedButUsed;
1186 
1187  /// Determine if VD, which must be a variable or function, is an external
1188  /// symbol that nonetheless can't be referenced from outside this translation
1189  /// unit because its type has no linkage and it's not extern "C".
1190  bool isExternalWithNoLinkageType(ValueDecl *VD);
1191 
1192  /// Obtain a sorted list of functions that are undefined but ODR-used.
1193  void getUndefinedButUsed(
1194  SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined);
1195 
1196  /// Retrieves list of suspicious delete-expressions that will be checked at
1197  /// the end of translation unit.
1198  const llvm::MapVector<FieldDecl *, DeleteLocs> &
1199  getMismatchingDeleteExpressions() const;
1200 
1201  typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods;
1202  typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool;
1203 
1204  /// Method Pool - allows efficient lookup when typechecking messages to "id".
1205  /// We need to maintain a list, since selectors can have differing signatures
1206  /// across classes. In Cocoa, this happens to be extremely uncommon (only 1%
1207  /// of selectors are "overloaded").
1208  /// At the head of the list it is recorded whether there were 0, 1, or >= 2
1209  /// methods inside categories with a particular selector.
1210  GlobalMethodPool MethodPool;
1211 
1212  /// Method selectors used in a \@selector expression. Used for implementation
1213  /// of -Wselector.
1214  llvm::MapVector<Selector, SourceLocation> ReferencedSelectors;
1215 
1216  /// List of SourceLocations where 'self' is implicitly retained inside a
1217  /// block.
1220 
1221  /// Kinds of C++ special members.
1229  CXXInvalid
1230  };
1231 
1232  typedef llvm::PointerIntPair<CXXRecordDecl *, 3, CXXSpecialMember>
1234 
1235  /// The C++ special members which we are currently in the process of
1236  /// declaring. If this process recursively triggers the declaration of the
1237  /// same special member, we should act as if it is not yet declared.
1238  llvm::SmallPtrSet<SpecialMemberDecl, 4> SpecialMembersBeingDeclared;
1239 
1240  /// The function definitions which were renamed as part of typo-correction
1241  /// to match their respective declarations. We want to keep track of them
1242  /// to ensure that we don't emit a "redefinition" error if we encounter a
1243  /// correctly named definition after the renamed definition.
1244  llvm::SmallPtrSet<const NamedDecl *, 4> TypoCorrectedFunctionDefinitions;
1245 
1246  /// Stack of types that correspond to the parameter entities that are
1247  /// currently being copy-initialized. Can be empty.
1249 
1250  void ReadMethodPool(Selector Sel);
1251  void updateOutOfDateSelector(Selector Sel);
1252 
1253  /// Private Helper predicate to check for 'self'.
1254  bool isSelfExpr(Expr *RExpr);
1255  bool isSelfExpr(Expr *RExpr, const ObjCMethodDecl *Method);
1256 
1257  /// Cause the active diagnostic on the DiagosticsEngine to be
1258  /// emitted. This is closely coupled to the SemaDiagnosticBuilder class and
1259  /// should not be used elsewhere.
1260  void EmitCurrentDiagnostic(unsigned DiagID);
1261 
1262  /// Records and restores the FP_CONTRACT state on entry/exit of compound
1263  /// statements.
1265  public:
1266  FPContractStateRAII(Sema &S) : S(S), OldFPFeaturesState(S.FPFeatures) {}
1267  ~FPContractStateRAII() { S.FPFeatures = OldFPFeaturesState; }
1268 
1269  private:
1270  Sema& S;
1271  FPOptions OldFPFeaturesState;
1272  };
1273 
1274  void addImplicitTypedef(StringRef Name, QualType T);
1275 
1276 public:
1277  Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
1279  CodeCompleteConsumer *CompletionConsumer = nullptr);
1280  ~Sema();
1281 
1282  /// Perform initialization that occurs after the parser has been
1283  /// initialized but before it parses anything.
1284  void Initialize();
1285 
1286  const LangOptions &getLangOpts() const { return LangOpts; }
1287  OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; }
1288  FPOptions &getFPOptions() { return FPFeatures; }
1289 
1290  DiagnosticsEngine &getDiagnostics() const { return Diags; }
1291  SourceManager &getSourceManager() const { return SourceMgr; }
1292  Preprocessor &getPreprocessor() const { return PP; }
1293  ASTContext &getASTContext() const { return Context; }
1294  ASTConsumer &getASTConsumer() const { return Consumer; }
1295  ASTMutationListener *getASTMutationListener() const;
1296  ExternalSemaSource* getExternalSource() const { return ExternalSource; }
1297 
1298  ///Registers an external source. If an external source already exists,
1299  /// creates a multiplex external source and appends to it.
1300  ///
1301  ///\param[in] E - A non-null external sema source.
1302  ///
1303  void addExternalSource(ExternalSemaSource *E);
1304 
1305  void PrintStats() const;
1306 
1307  /// Helper class that creates diagnostics with optional
1308  /// template instantiation stacks.
1309  ///
1310  /// This class provides a wrapper around the basic DiagnosticBuilder
1311  /// class that emits diagnostics. SemaDiagnosticBuilder is
1312  /// responsible for emitting the diagnostic (as DiagnosticBuilder
1313  /// does) and, if the diagnostic comes from inside a template
1314  /// instantiation, printing the template instantiation stack as
1315  /// well.
1317  Sema &SemaRef;
1318  unsigned DiagID;
1319 
1320  public:
1321  SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID)
1322  : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { }
1323 
1324  // This is a cunning lie. DiagnosticBuilder actually performs move
1325  // construction in its copy constructor (but due to varied uses, it's not
1326  // possible to conveniently express this as actual move construction). So
1327  // the default copy ctor here is fine, because the base class disables the
1328  // source anyway, so the user-defined ~SemaDiagnosticBuilder is a safe no-op
1329  // in that case anwyay.
1330  SemaDiagnosticBuilder(const SemaDiagnosticBuilder&) = default;
1331 
1333  // If we aren't active, there is nothing to do.
1334  if (!isActive()) return;
1335 
1336  // Otherwise, we need to emit the diagnostic. First flush the underlying
1337  // DiagnosticBuilder data, and clear the diagnostic builder itself so it
1338  // won't emit the diagnostic in its own destructor.
1339  //
1340  // This seems wasteful, in that as written the DiagnosticBuilder dtor will
1341  // do its own needless checks to see if the diagnostic needs to be
1342  // emitted. However, because we take care to ensure that the builder
1343  // objects never escape, a sufficiently smart compiler will be able to
1344  // eliminate that code.
1345  FlushCounts();
1346  Clear();
1347 
1348  // Dispatch to Sema to emit the diagnostic.
1349  SemaRef.EmitCurrentDiagnostic(DiagID);
1350  }
1351 
1352  /// Teach operator<< to produce an object of the correct type.
1353  template<typename T>
1355  const SemaDiagnosticBuilder &Diag, const T &Value) {
1356  const DiagnosticBuilder &BaseDiag = Diag;
1357  BaseDiag << Value;
1358  return Diag;
1359  }
1360  };
1361 
1362  /// Emit a diagnostic.
1364  DiagnosticBuilder DB = Diags.Report(Loc, DiagID);
1365  return SemaDiagnosticBuilder(DB, *this, DiagID);
1366  }
1367 
1368  /// Emit a partial diagnostic.
1370 
1371  /// Build a partial diagnostic.
1372  PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h
1373 
1374  bool findMacroSpelling(SourceLocation &loc, StringRef name);
1375 
1376  /// Get a string to suggest for zero-initialization of a type.
1377  std::string
1378  getFixItZeroInitializerForType(QualType T, SourceLocation Loc) const;
1379  std::string getFixItZeroLiteralForType(QualType T, SourceLocation Loc) const;
1380 
1381  /// Calls \c Lexer::getLocForEndOfToken()
1382  SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset = 0);
1383 
1384  /// Retrieve the module loader associated with the preprocessor.
1385  ModuleLoader &getModuleLoader() const;
1386 
1387  void emitAndClearUnusedLocalTypedefWarnings();
1388 
1390  /// The global module fragment, between 'module;' and a module-declaration.
1392  /// A normal translation unit fragment. For a non-module unit, this is the
1393  /// entire translation unit. Otherwise, it runs from the module-declaration
1394  /// to the private-module-fragment (if any) or the end of the TU (if not).
1396  /// The private module fragment, between 'module :private;' and the end of
1397  /// the translation unit.
1398  Private
1399  };
1400 
1401  void ActOnStartOfTranslationUnit();
1402  void ActOnEndOfTranslationUnit();
1403  void ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind);
1404 
1405  void CheckDelegatingCtorCycles();
1406 
1407  Scope *getScopeForContext(DeclContext *Ctx);
1408 
1409  void PushFunctionScope();
1410  void PushBlockScope(Scope *BlockScope, BlockDecl *Block);
1411  sema::LambdaScopeInfo *PushLambdaScope();
1412 
1413  /// This is used to inform Sema what the current TemplateParameterDepth
1414  /// is during Parsing. Currently it is used to pass on the depth
1415  /// when parsing generic lambda 'auto' parameters.
1416  void RecordParsingTemplateParameterDepth(unsigned Depth);
1417 
1418  void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD,
1419  RecordDecl *RD,
1420  CapturedRegionKind K);
1421  void
1422  PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP = nullptr,
1423  const Decl *D = nullptr,
1424  const BlockExpr *blkExpr = nullptr);
1425 
1427  return FunctionScopes.empty() ? nullptr : FunctionScopes.back();
1428  }
1429 
1430  sema::FunctionScopeInfo *getEnclosingFunction() const;
1431 
1432  void setFunctionHasBranchIntoScope();
1433  void setFunctionHasBranchProtectedScope();
1434  void setFunctionHasIndirectGoto();
1435 
1436  void PushCompoundScope(bool IsStmtExpr);
1437  void PopCompoundScope();
1438 
1439  sema::CompoundScopeInfo &getCurCompoundScope() const;
1440 
1441  bool hasAnyUnrecoverableErrorsInThisFunction() const;
1442 
1443  /// Retrieve the current block, if any.
1444  sema::BlockScopeInfo *getCurBlock();
1445 
1446  /// Retrieve the current lambda scope info, if any.
1447  /// \param IgnoreNonLambdaCapturingScope true if should find the top-most
1448  /// lambda scope info ignoring all inner capturing scopes that are not
1449  /// lambda scopes.
1451  getCurLambda(bool IgnoreNonLambdaCapturingScope = false);
1452 
1453  /// Retrieve the current generic lambda info, if any.
1454  sema::LambdaScopeInfo *getCurGenericLambda();
1455 
1456  /// Retrieve the current captured region, if any.
1457  sema::CapturedRegionScopeInfo *getCurCapturedRegion();
1458 
1459  /// WeakTopLevelDeclDecls - access to \#pragma weak-generated Decls
1460  SmallVectorImpl<Decl *> &WeakTopLevelDecls() { return WeakTopLevelDecl; }
1461 
1462  void ActOnComment(SourceRange Comment);
1463 
1464  //===--------------------------------------------------------------------===//
1465  // Type Analysis / Processing: SemaType.cpp.
1466  //
1467 
1468  QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs,
1469  const DeclSpec *DS = nullptr);
1470  QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVRA,
1471  const DeclSpec *DS = nullptr);
1472  QualType BuildPointerType(QualType T,
1473  SourceLocation Loc, DeclarationName Entity);
1474  QualType BuildReferenceType(QualType T, bool LValueRef,
1475  SourceLocation Loc, DeclarationName Entity);
1476  QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
1477  Expr *ArraySize, unsigned Quals,
1478  SourceRange Brackets, DeclarationName Entity);
1479  QualType BuildVectorType(QualType T, Expr *VecSize, SourceLocation AttrLoc);
1480  QualType BuildExtVectorType(QualType T, Expr *ArraySize,
1481  SourceLocation AttrLoc);
1482  QualType BuildAddressSpaceAttr(QualType &T, LangAS ASIdx, Expr *AddrSpace,
1483  SourceLocation AttrLoc);
1484 
1485  /// Same as above, but constructs the AddressSpace index if not provided.
1486  QualType BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace,
1487  SourceLocation AttrLoc);
1488 
1489  bool CheckFunctionReturnType(QualType T, SourceLocation Loc);
1490 
1491  /// Build a function type.
1492  ///
1493  /// This routine checks the function type according to C++ rules and
1494  /// under the assumption that the result type and parameter types have
1495  /// just been instantiated from a template. It therefore duplicates
1496  /// some of the behavior of GetTypeForDeclarator, but in a much
1497  /// simpler form that is only suitable for this narrow use case.
1498  ///
1499  /// \param T The return type of the function.
1500  ///
1501  /// \param ParamTypes The parameter types of the function. This array
1502  /// will be modified to account for adjustments to the types of the
1503  /// function parameters.
1504  ///
1505  /// \param Loc The location of the entity whose type involves this
1506  /// function type or, if there is no such entity, the location of the
1507  /// type that will have function type.
1508  ///
1509  /// \param Entity The name of the entity that involves the function
1510  /// type, if known.
1511  ///
1512  /// \param EPI Extra information about the function type. Usually this will
1513  /// be taken from an existing function with the same prototype.
1514  ///
1515  /// \returns A suitable function type, if there are no errors. The
1516  /// unqualified type will always be a FunctionProtoType.
1517  /// Otherwise, returns a NULL type.
1518  QualType BuildFunctionType(QualType T,
1519  MutableArrayRef<QualType> ParamTypes,
1520  SourceLocation Loc, DeclarationName Entity,
1521  const FunctionProtoType::ExtProtoInfo &EPI);
1522 
1523  QualType BuildMemberPointerType(QualType T, QualType Class,
1524  SourceLocation Loc,
1525  DeclarationName Entity);
1526  QualType BuildBlockPointerType(QualType T,
1527  SourceLocation Loc, DeclarationName Entity);
1528  QualType BuildParenType(QualType T);
1529  QualType BuildAtomicType(QualType T, SourceLocation Loc);
1530  QualType BuildReadPipeType(QualType T,
1531  SourceLocation Loc);
1532  QualType BuildWritePipeType(QualType T,
1533  SourceLocation Loc);
1534 
1535  TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S);
1536  TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy);
1537 
1538  /// Package the given type and TSI into a ParsedType.
1539  ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo);
1540  DeclarationNameInfo GetNameForDeclarator(Declarator &D);
1541  DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name);
1542  static QualType GetTypeFromParser(ParsedType Ty,
1543  TypeSourceInfo **TInfo = nullptr);
1544  CanThrowResult canThrow(const Expr *E);
1545  const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc,
1546  const FunctionProtoType *FPT);
1547  void UpdateExceptionSpec(FunctionDecl *FD,
1549  bool CheckSpecifiedExceptionType(QualType &T, SourceRange Range);
1550  bool CheckDistantExceptionSpec(QualType T);
1551  bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New);
1552  bool CheckEquivalentExceptionSpec(
1553  const FunctionProtoType *Old, SourceLocation OldLoc,
1554  const FunctionProtoType *New, SourceLocation NewLoc);
1555  bool CheckEquivalentExceptionSpec(
1556  const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
1557  const FunctionProtoType *Old, SourceLocation OldLoc,
1558  const FunctionProtoType *New, SourceLocation NewLoc);
1559  bool handlerCanCatch(QualType HandlerType, QualType ExceptionType);
1560  bool CheckExceptionSpecSubset(const PartialDiagnostic &DiagID,
1561  const PartialDiagnostic &NestedDiagID,
1562  const PartialDiagnostic &NoteID,
1563  const FunctionProtoType *Superset,
1564  SourceLocation SuperLoc,
1565  const FunctionProtoType *Subset,
1566  SourceLocation SubLoc);
1567  bool CheckParamExceptionSpec(const PartialDiagnostic &NestedDiagID,
1568  const PartialDiagnostic &NoteID,
1569  const FunctionProtoType *Target,
1570  SourceLocation TargetLoc,
1571  const FunctionProtoType *Source,
1572  SourceLocation SourceLoc);
1573 
1574  TypeResult ActOnTypeName(Scope *S, Declarator &D);
1575 
1576  /// The parser has parsed the context-sensitive type 'instancetype'
1577  /// in an Objective-C message declaration. Return the appropriate type.
1578  ParsedType ActOnObjCInstanceType(SourceLocation Loc);
1579 
1580  /// Abstract class used to diagnose incomplete types.
1581  struct TypeDiagnoser {
1583 
1584  virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0;
1585  virtual ~TypeDiagnoser() {}
1586  };
1587 
1588  static int getPrintable(int I) { return I; }
1589  static unsigned getPrintable(unsigned I) { return I; }
1590  static bool getPrintable(bool B) { return B; }
1591  static const char * getPrintable(const char *S) { return S; }
1592  static StringRef getPrintable(StringRef S) { return S; }
1593  static const std::string &getPrintable(const std::string &S) { return S; }
1594  static const IdentifierInfo *getPrintable(const IdentifierInfo *II) {
1595  return II;
1596  }
1598  static QualType getPrintable(QualType T) { return T; }
1599  static SourceRange getPrintable(SourceRange R) { return R; }
1600  static SourceRange getPrintable(SourceLocation L) { return L; }
1601  static SourceRange getPrintable(const Expr *E) { return E->getSourceRange(); }
1602  static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();}
1603 
1604  template <typename... Ts> class BoundTypeDiagnoser : public TypeDiagnoser {
1605  unsigned DiagID;
1606  std::tuple<const Ts &...> Args;
1607 
1608  template <std::size_t... Is>
1609  void emit(const SemaDiagnosticBuilder &DB,
1610  llvm::index_sequence<Is...>) const {
1611  // Apply all tuple elements to the builder in order.
1612  bool Dummy[] = {false, (DB << getPrintable(std::get<Is>(Args)))...};
1613  (void)Dummy;
1614  }
1615 
1616  public:
1617  BoundTypeDiagnoser(unsigned DiagID, const Ts &...Args)
1618  : TypeDiagnoser(), DiagID(DiagID), Args(Args...) {
1619  assert(DiagID != 0 && "no diagnostic for type diagnoser");
1620  }
1621 
1622  void diagnose(Sema &S, SourceLocation Loc, QualType T) override {
1623  const SemaDiagnosticBuilder &DB = S.Diag(Loc, DiagID);
1624  emit(DB, llvm::index_sequence_for<Ts...>());
1625  DB << T;
1626  }
1627  };
1628 
1629 private:
1630  /// Methods for marking which expressions involve dereferencing a pointer
1631  /// marked with the 'noderef' attribute. Expressions are checked bottom up as
1632  /// they are parsed, meaning that a noderef pointer may not be accessed. For
1633  /// example, in `&*p` where `p` is a noderef pointer, we will first parse the
1634  /// `*p`, but need to check that `address of` is called on it. This requires
1635  /// keeping a container of all pending expressions and checking if the address
1636  /// of them are eventually taken.
1637  void CheckSubscriptAccessOfNoDeref(const ArraySubscriptExpr *E);
1638  void CheckAddressOfNoDeref(const Expr *E);
1639  void CheckMemberAccessOfNoDeref(const MemberExpr *E);
1640 
1641  bool RequireCompleteTypeImpl(SourceLocation Loc, QualType T,
1642  TypeDiagnoser *Diagnoser);
1643 
1644  struct ModuleScope {
1645  SourceLocation BeginLoc;
1646  clang::Module *Module = nullptr;
1647  bool ModuleInterface = false;
1648  bool ImplicitGlobalModuleFragment = false;
1649  VisibleModuleSet OuterVisibleModules;
1650  };
1651  /// The modules we're currently parsing.
1653 
1654  /// Get the module whose scope we are currently within.
1655  Module *getCurrentModule() const {
1656  return ModuleScopes.empty() ? nullptr : ModuleScopes.back().Module;
1657  }
1658 
1659  VisibleModuleSet VisibleModules;
1660 
1661 public:
1662  /// Get the module owning an entity.
1663  Module *getOwningModule(Decl *Entity) { return Entity->getOwningModule(); }
1664 
1665  /// Make a merged definition of an existing hidden definition \p ND
1666  /// visible at the specified location.
1667  void makeMergedDefinitionVisible(NamedDecl *ND);
1668 
1669  bool isModuleVisible(const Module *M, bool ModulePrivate = false);
1670 
1671  /// Determine whether a declaration is visible to name lookup.
1672  bool isVisible(const NamedDecl *D) {
1673  return !D->isHidden() || isVisibleSlow(D);
1674  }
1675 
1676  /// Determine whether any declaration of an entity is visible.
1677  bool
1679  llvm::SmallVectorImpl<Module *> *Modules = nullptr) {
1680  return isVisible(D) || hasVisibleDeclarationSlow(D, Modules);
1681  }
1682  bool hasVisibleDeclarationSlow(const NamedDecl *D,
1684 
1685  bool hasVisibleMergedDefinition(NamedDecl *Def);
1686  bool hasMergedDefinitionInCurrentModule(NamedDecl *Def);
1687 
1688  /// Determine if \p D and \p Suggested have a structurally compatible
1689  /// layout as described in C11 6.2.7/1.
1690  bool hasStructuralCompatLayout(Decl *D, Decl *Suggested);
1691 
1692  /// Determine if \p D has a visible definition. If not, suggest a declaration
1693  /// that should be made visible to expose the definition.
1694  bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested,
1695  bool OnlyNeedComplete = false);
1697  NamedDecl *Hidden;
1698  return hasVisibleDefinition(const_cast<NamedDecl*>(D), &Hidden);
1699  }
1700 
1701  /// Determine if the template parameter \p D has a visible default argument.
1702  bool
1704  llvm::SmallVectorImpl<Module *> *Modules = nullptr);
1705 
1706  /// Determine if there is a visible declaration of \p D that is an explicit
1707  /// specialization declaration for a specialization of a template. (For a
1708  /// member specialization, use hasVisibleMemberSpecialization.)
1709  bool hasVisibleExplicitSpecialization(
1710  const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr);
1711 
1712  /// Determine if there is a visible declaration of \p D that is a member
1713  /// specialization declaration (as opposed to an instantiated declaration).
1714  bool hasVisibleMemberSpecialization(
1715  const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr);
1716 
1717  /// Determine if \p A and \p B are equivalent internal linkage declarations
1718  /// from different modules, and thus an ambiguity error can be downgraded to
1719  /// an extension warning.
1720  bool isEquivalentInternalLinkageDeclaration(const NamedDecl *A,
1721  const NamedDecl *B);
1722  void diagnoseEquivalentInternalLinkageDeclarations(
1723  SourceLocation Loc, const NamedDecl *D,
1725 
1726  bool isUsualDeallocationFunction(const CXXMethodDecl *FD);
1727 
1729  return !RequireCompleteTypeImpl(Loc, T, nullptr);
1730  }
1731  bool RequireCompleteType(SourceLocation Loc, QualType T,
1732  TypeDiagnoser &Diagnoser);
1733  bool RequireCompleteType(SourceLocation Loc, QualType T,
1734  unsigned DiagID);
1735 
1736  template <typename... Ts>
1737  bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID,
1738  const Ts &...Args) {
1739  BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...);
1740  return RequireCompleteType(Loc, T, Diagnoser);
1741  }
1742 
1743  void completeExprArrayBound(Expr *E);
1744  bool RequireCompleteExprType(Expr *E, TypeDiagnoser &Diagnoser);
1745  bool RequireCompleteExprType(Expr *E, unsigned DiagID);
1746 
1747  template <typename... Ts>
1748  bool RequireCompleteExprType(Expr *E, unsigned DiagID, const Ts &...Args) {
1749  BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...);
1750  return RequireCompleteExprType(E, Diagnoser);
1751  }
1752 
1753  bool RequireLiteralType(SourceLocation Loc, QualType T,
1754  TypeDiagnoser &Diagnoser);
1755  bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID);
1756 
1757  template <typename... Ts>
1758  bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID,
1759  const Ts &...Args) {
1760  BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...);
1761  return RequireLiteralType(Loc, T, Diagnoser);
1762  }
1763 
1764  QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
1765  const CXXScopeSpec &SS, QualType T,
1766  TagDecl *OwnedTagDecl = nullptr);
1767 
1768  QualType BuildTypeofExprType(Expr *E, SourceLocation Loc);
1769  /// If AsUnevaluated is false, E is treated as though it were an evaluated
1770  /// context, such as when building a type for decltype(auto).
1771  QualType BuildDecltypeType(Expr *E, SourceLocation Loc,
1772  bool AsUnevaluated = true);
1773  QualType BuildUnaryTransformType(QualType BaseType,
1775  SourceLocation Loc);
1776 
1777  //===--------------------------------------------------------------------===//
1778  // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
1779  //
1780 
1781  struct SkipBodyInfo {
1783  : ShouldSkip(false), CheckSameAsPrevious(false), Previous(nullptr),
1784  New(nullptr) {}
1789  };
1790 
1791  DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = nullptr);
1792 
1793  void DiagnoseUseOfUnimplementedSelectors();
1794 
1795  bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
1796 
1798  Scope *S, CXXScopeSpec *SS = nullptr,
1799  bool isClassName = false, bool HasTrailingDot = false,
1800  ParsedType ObjectType = nullptr,
1801  bool IsCtorOrDtorName = false,
1802  bool WantNontrivialTypeSourceInfo = false,
1803  bool IsClassTemplateDeductionContext = true,
1804  IdentifierInfo **CorrectedII = nullptr);
1805  TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S);
1806  bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S);
1807  void DiagnoseUnknownTypeName(IdentifierInfo *&II,
1808  SourceLocation IILoc,
1809  Scope *S,
1810  CXXScopeSpec *SS,
1811  ParsedType &SuggestedType,
1812  bool IsTemplateName = false);
1813 
1814  /// Attempt to behave like MSVC in situations where lookup of an unqualified
1815  /// type name has failed in a dependent context. In these situations, we
1816  /// automatically form a DependentTypeName that will retry lookup in a related
1817  /// scope during instantiation.
1818  ParsedType ActOnMSVCUnknownTypeName(const IdentifierInfo &II,
1819  SourceLocation NameLoc,
1820  bool IsTemplateTypeArg);
1821 
1822  /// Describes the result of the name lookup and resolution performed
1823  /// by \c ClassifyName().
1833  NC_FunctionTemplate
1834  };
1835 
1838  ExprResult Expr;
1839  TemplateName Template;
1840  ParsedType Type;
1841 
1842  explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {}
1843 
1844  public:
1845  NameClassification(ExprResult Expr) : Kind(NC_Expression), Expr(Expr) {}
1846 
1847  NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {}
1848 
1849  NameClassification(const IdentifierInfo *Keyword) : Kind(NC_Keyword) {}
1850 
1852  return NameClassification(NC_Error);
1853  }
1854 
1856  return NameClassification(NC_Unknown);
1857  }
1858 
1860  return NameClassification(NC_NestedNameSpecifier);
1861  }
1862 
1864  NameClassification Result(NC_TypeTemplate);
1865  Result.Template = Name;
1866  return Result;
1867  }
1868 
1870  NameClassification Result(NC_VarTemplate);
1871  Result.Template = Name;
1872  return Result;
1873  }
1874 
1876  NameClassification Result(NC_FunctionTemplate);
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);
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  default:
1908  llvm_unreachable("unsupported name classification.");
1909  }
1910  }
1911  };
1912 
1913  /// Perform name lookup on the given name, classifying it based on
1914  /// the results of name lookup and the following token.
1915  ///
1916  /// This routine is used by the parser to resolve identifiers and help direct
1917  /// parsing. When the identifier cannot be found, this routine will attempt
1918  /// to correct the typo and classify based on the resulting name.
1919  ///
1920  /// \param S The scope in which we're performing name lookup.
1921  ///
1922  /// \param SS The nested-name-specifier that precedes the name.
1923  ///
1924  /// \param Name The identifier. If typo correction finds an alternative name,
1925  /// this pointer parameter will be updated accordingly.
1926  ///
1927  /// \param NameLoc The location of the identifier.
1928  ///
1929  /// \param NextToken The token following the identifier. Used to help
1930  /// disambiguate the name.
1931  ///
1932  /// \param IsAddressOfOperand True if this name is the operand of a unary
1933  /// address of ('&') expression, assuming it is classified as an
1934  /// expression.
1935  ///
1936  /// \param CCC The correction callback, if typo correction is desired.
1937  NameClassification ClassifyName(Scope *S, CXXScopeSpec &SS,
1938  IdentifierInfo *&Name, SourceLocation NameLoc,
1939  const Token &NextToken,
1940  bool IsAddressOfOperand,
1941  CorrectionCandidateCallback *CCC = nullptr);
1942 
1943  /// Describes the detailed kind of a template name. Used in diagnostics.
1945  ClassTemplate,
1946  FunctionTemplate,
1947  VarTemplate,
1948  AliasTemplate,
1949  TemplateTemplateParam,
1950  DependentTemplate
1951  };
1953  getTemplateNameKindForDiagnostics(TemplateName Name);
1954 
1955  /// Determine whether it's plausible that E was intended to be a
1956  /// template-name.
1957  bool mightBeIntendedToBeTemplateName(ExprResult E, bool &Dependent) {
1958  if (!getLangOpts().CPlusPlus || E.isInvalid())
1959  return false;
1960  Dependent = false;
1961  if (auto *DRE = dyn_cast<DeclRefExpr>(E.get()))
1962  return !DRE->hasExplicitTemplateArgs();
1963  if (auto *ME = dyn_cast<MemberExpr>(E.get()))
1964  return !ME->hasExplicitTemplateArgs();
1965  Dependent = true;
1966  if (auto *DSDRE = dyn_cast<DependentScopeDeclRefExpr>(E.get()))
1967  return !DSDRE->hasExplicitTemplateArgs();
1968  if (auto *DSME = dyn_cast<CXXDependentScopeMemberExpr>(E.get()))
1969  return !DSME->hasExplicitTemplateArgs();
1970  // Any additional cases recognized here should also be handled by
1971  // diagnoseExprIntendedAsTemplateName.
1972  return false;
1973  }
1974  void diagnoseExprIntendedAsTemplateName(Scope *S, ExprResult TemplateName,
1977 
1978  Decl *ActOnDeclarator(Scope *S, Declarator &D);
1979 
1980  NamedDecl *HandleDeclarator(Scope *S, Declarator &D,
1981  MultiTemplateParamsArg TemplateParameterLists);
1982  void RegisterLocallyScopedExternCDecl(NamedDecl *ND, Scope *S);
1983  bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info);
1984  bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC,
1985  DeclarationName Name, SourceLocation Loc,
1986  bool IsTemplateId);
1987  void
1988  diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals,
1989  SourceLocation FallbackLoc,
1990  SourceLocation ConstQualLoc = SourceLocation(),
1991  SourceLocation VolatileQualLoc = SourceLocation(),
1992  SourceLocation RestrictQualLoc = SourceLocation(),
1993  SourceLocation AtomicQualLoc = SourceLocation(),
1994  SourceLocation UnalignedQualLoc = SourceLocation());
1995 
1996  static bool adjustContextForLocalExternDecl(DeclContext *&DC);
1997  void DiagnoseFunctionSpecifiers(const DeclSpec &DS);
1998  NamedDecl *getShadowedDeclaration(const TypedefNameDecl *D,
1999  const LookupResult &R);
2000  NamedDecl *getShadowedDeclaration(const VarDecl *D, const LookupResult &R);
2001  void CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl,
2002  const LookupResult &R);
2003  void CheckShadow(Scope *S, VarDecl *D);
2004 
2005  /// Warn if 'E', which is an expression that is about to be modified, refers
2006  /// to a shadowing declaration.
2007  void CheckShadowingDeclModification(Expr *E, SourceLocation Loc);
2008 
2009  void DiagnoseShadowingLambdaDecls(const sema::LambdaScopeInfo *LSI);
2010 
2011 private:
2012  /// Map of current shadowing declarations to shadowed declarations. Warn if
2013  /// it looks like the user is trying to modify the shadowing declaration.
2014  llvm::DenseMap<const NamedDecl *, const NamedDecl *> ShadowingDecls;
2015 
2016 public:
2017  void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange);
2018  void handleTagNumbering(const TagDecl *Tag, Scope *TagScope);
2019  void setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec,
2020  TypedefNameDecl *NewTD);
2021  void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D);
2022  NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
2023  TypeSourceInfo *TInfo,
2025  NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D,
2026  LookupResult &Previous, bool &Redeclaration);
2027  NamedDecl *ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
2028  TypeSourceInfo *TInfo,
2029  LookupResult &Previous,
2030  MultiTemplateParamsArg TemplateParamLists,
2031  bool &AddToScope,
2032  ArrayRef<BindingDecl *> Bindings = None);
2033  NamedDecl *
2034  ActOnDecompositionDeclarator(Scope *S, Declarator &D,
2035  MultiTemplateParamsArg TemplateParamLists);
2036  // Returns true if the variable declaration is a redeclaration
2037  bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous);
2038  void CheckVariableDeclarationType(VarDecl *NewVD);
2039  bool DeduceVariableDeclarationType(VarDecl *VDecl, bool DirectInit,
2040  Expr *&Init);
2041  void CheckCompleteVariableDeclaration(VarDecl *VD);
2042  void CheckCompleteDecompositionDeclaration(DecompositionDecl *DD);
2043  void MaybeSuggestAddingStaticToDecl(const FunctionDecl *D);
2044 
2045  NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
2046  TypeSourceInfo *TInfo,
2047  LookupResult &Previous,
2048  MultiTemplateParamsArg TemplateParamLists,
2049  bool &AddToScope);
2050  bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD);
2051 
2052  bool CheckConstexprFunctionDecl(const FunctionDecl *FD);
2053  bool CheckConstexprFunctionBody(const FunctionDecl *FD, Stmt *Body);
2054 
2055  void DiagnoseHiddenVirtualMethods(CXXMethodDecl *MD);
2056  void FindHiddenVirtualMethods(CXXMethodDecl *MD,
2057  SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods);
2058  void NoteHiddenVirtualMethods(CXXMethodDecl *MD,
2059  SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods);
2060  // Returns true if the function declaration is a redeclaration
2061  bool CheckFunctionDeclaration(Scope *S,
2062  FunctionDecl *NewFD, LookupResult &Previous,
2063  bool IsMemberSpecialization);
2064  bool shouldLinkDependentDeclWithPrevious(Decl *D, Decl *OldDecl);
2065  bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD,
2066  QualType NewT, QualType OldT);
2067  void CheckMain(FunctionDecl *FD, const DeclSpec &D);
2068  void CheckMSVCRTEntryPoint(FunctionDecl *FD);
2069  Attr *getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, bool IsDefinition);
2070  Decl *ActOnParamDeclarator(Scope *S, Declarator &D);
2071  ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC,
2072  SourceLocation Loc,
2073  QualType T);
2074  ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc,
2075  SourceLocation NameLoc, IdentifierInfo *Name,
2076  QualType T, TypeSourceInfo *TSInfo,
2077  StorageClass SC);
2078  void ActOnParamDefaultArgument(Decl *param,
2079  SourceLocation EqualLoc,
2080  Expr *defarg);
2081  void ActOnParamUnparsedDefaultArgument(Decl *param,
2082  SourceLocation EqualLoc,
2083  SourceLocation ArgLoc);
2084  void ActOnParamDefaultArgumentError(Decl *param, SourceLocation EqualLoc);
2085  bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg,
2086  SourceLocation EqualLoc);
2087 
2088  void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit);
2089  void ActOnUninitializedDecl(Decl *dcl);
2090  void ActOnInitializerError(Decl *Dcl);
2091 
2092  void ActOnPureSpecifier(Decl *D, SourceLocation PureSpecLoc);
2093  void ActOnCXXForRangeDecl(Decl *D);
2094  StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc,
2095  IdentifierInfo *Ident,
2096  ParsedAttributes &Attrs,
2097  SourceLocation AttrEnd);
2098  void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc);
2099  void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc);
2100  void CheckStaticLocalForDllExport(VarDecl *VD);
2101  void FinalizeDeclaration(Decl *D);
2102  DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS,
2103  ArrayRef<Decl *> Group);
2104  DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef<Decl *> Group);
2105 
2106  /// Should be called on all declarations that might have attached
2107  /// documentation comments.
2108  void ActOnDocumentableDecl(Decl *D);
2109  void ActOnDocumentableDecls(ArrayRef<Decl *> Group);
2110 
2111  void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
2112  SourceLocation LocAfterDecls);
2113  void CheckForFunctionRedefinition(
2114  FunctionDecl *FD, const FunctionDecl *EffectiveDefinition = nullptr,
2115  SkipBodyInfo *SkipBody = nullptr);
2116  Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D,
2117  MultiTemplateParamsArg TemplateParamLists,
2118  SkipBodyInfo *SkipBody = nullptr);
2119  Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D,
2120  SkipBodyInfo *SkipBody = nullptr);
2121  void ActOnStartOfObjCMethodDef(Scope *S, Decl *D);
2123  return D && isa<ObjCMethodDecl>(D);
2124  }
2125 
2126  /// Determine whether we can delay parsing the body of a function or
2127  /// function template until it is used, assuming we don't care about emitting
2128  /// code for that function.
2129  ///
2130  /// This will be \c false if we may need the body of the function in the
2131  /// middle of parsing an expression (where it's impractical to switch to
2132  /// parsing a different function), for instance, if it's constexpr in C++11
2133  /// or has an 'auto' return type in C++14. These cases are essentially bugs.
2134  bool canDelayFunctionBody(const Declarator &D);
2135 
2136  /// Determine whether we can skip parsing the body of a function
2137  /// definition, assuming we don't care about analyzing its body or emitting
2138  /// code for that function.
2139  ///
2140  /// This will be \c false only if we may need the body of the function in
2141  /// order to parse the rest of the program (for instance, if it is
2142  /// \c constexpr in C++11 or has an 'auto' return type in C++14).
2143  bool canSkipFunctionBody(Decl *D);
2144 
2145  void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope);
2146  Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body);
2147  Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation);
2148  Decl *ActOnSkippedFunctionBody(Decl *Decl);
2149  void ActOnFinishInlineFunctionDef(FunctionDecl *D);
2150 
2151  /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an
2152  /// attribute for which parsing is delayed.
2153  void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs);
2154 
2155  /// Diagnose any unused parameters in the given sequence of
2156  /// ParmVarDecl pointers.
2157  void DiagnoseUnusedParameters(ArrayRef<ParmVarDecl *> Parameters);
2158 
2159  /// Diagnose whether the size of parameters or return value of a
2160  /// function or obj-c method definition is pass-by-value and larger than a
2161  /// specified threshold.
2162  void
2163  DiagnoseSizeOfParametersAndReturnValue(ArrayRef<ParmVarDecl *> Parameters,
2164  QualType ReturnTy, NamedDecl *D);
2165 
2166  void DiagnoseInvalidJumps(Stmt *Body);
2167  Decl *ActOnFileScopeAsmDecl(Expr *expr,
2168  SourceLocation AsmLoc,
2169  SourceLocation RParenLoc);
2170 
2171  /// Handle a C++11 empty-declaration and attribute-declaration.
2172  Decl *ActOnEmptyDeclaration(Scope *S, const ParsedAttributesView &AttrList,
2173  SourceLocation SemiLoc);
2174 
2175  enum class ModuleDeclKind {
2176  Interface, ///< 'export module X;'
2177  Implementation, ///< 'module X;'
2178  };
2179 
2180  /// The parser has processed a module-declaration that begins the definition
2181  /// of a module interface or implementation.
2182  DeclGroupPtrTy ActOnModuleDecl(SourceLocation StartLoc,
2183  SourceLocation ModuleLoc, ModuleDeclKind MDK,
2184  ModuleIdPath Path, bool IsFirstDecl);
2185 
2186  /// The parser has processed a global-module-fragment declaration that begins
2187  /// the definition of the global module fragment of the current module unit.
2188  /// \param ModuleLoc The location of the 'module' keyword.
2189  DeclGroupPtrTy ActOnGlobalModuleFragmentDecl(SourceLocation ModuleLoc);
2190 
2191  /// The parser has processed a private-module-fragment declaration that begins
2192  /// the definition of the private module fragment of the current module unit.
2193  /// \param ModuleLoc The location of the 'module' keyword.
2194  /// \param PrivateLoc The location of the 'private' keyword.
2195  DeclGroupPtrTy ActOnPrivateModuleFragmentDecl(SourceLocation ModuleLoc,
2196  SourceLocation PrivateLoc);
2197 
2198  /// The parser has processed a module import declaration.
2199  ///
2200  /// \param StartLoc The location of the first token in the declaration. This
2201  /// could be the location of an '@', 'export', or 'import'.
2202  /// \param ExportLoc The location of the 'export' keyword, if any.
2203  /// \param ImportLoc The location of the 'import' keyword.
2204  /// \param Path The module access path.
2205  DeclResult ActOnModuleImport(SourceLocation StartLoc,
2206  SourceLocation ExportLoc,
2207  SourceLocation ImportLoc, ModuleIdPath Path);
2208  DeclResult ActOnModuleImport(SourceLocation StartLoc,
2209  SourceLocation ExportLoc,
2210  SourceLocation ImportLoc, Module *M,
2211  ModuleIdPath Path = {});
2212 
2213  /// The parser has processed a module import translated from a
2214  /// #include or similar preprocessing directive.
2215  void ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod);
2216  void BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod);
2217 
2218  /// The parsed has entered a submodule.
2219  void ActOnModuleBegin(SourceLocation DirectiveLoc, Module *Mod);
2220  /// The parser has left a submodule.
2221  void ActOnModuleEnd(SourceLocation DirectiveLoc, Module *Mod);
2222 
2223  /// Create an implicit import of the given module at the given
2224  /// source location, for error recovery, if possible.
2225  ///
2226  /// This routine is typically used when an entity found by name lookup
2227  /// is actually hidden within a module that we know about but the user
2228  /// has forgotten to import.
2229  void createImplicitModuleImportForErrorRecovery(SourceLocation Loc,
2230  Module *Mod);
2231 
2232  /// Kinds of missing import. Note, the values of these enumerators correspond
2233  /// to %select values in diagnostics.
2234  enum class MissingImportKind {
2235  Declaration,
2236  Definition,
2237  DefaultArgument,
2238  ExplicitSpecialization,
2239  PartialSpecialization
2240  };
2241 
2242  /// Diagnose that the specified declaration needs to be visible but
2243  /// isn't, and suggest a module import that would resolve the problem.
2244  void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl,
2245  MissingImportKind MIK, bool Recover = true);
2246  void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl,
2247  SourceLocation DeclLoc, ArrayRef<Module *> Modules,
2248  MissingImportKind MIK, bool Recover);
2249 
2250  Decl *ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc,
2251  SourceLocation LBraceLoc);
2252  Decl *ActOnFinishExportDecl(Scope *S, Decl *ExportDecl,
2253  SourceLocation RBraceLoc);
2254 
2255  /// We've found a use of a templated declaration that would trigger an
2256  /// implicit instantiation. Check that any relevant explicit specializations
2257  /// and partial specializations are visible, and diagnose if not.
2258  void checkSpecializationVisibility(SourceLocation Loc, NamedDecl *Spec);
2259 
2260  /// We've found a use of a template specialization that would select a
2261  /// partial specialization. Check that the partial specialization is visible,
2262  /// and diagnose if not.
2263  void checkPartialSpecializationVisibility(SourceLocation Loc,
2264  NamedDecl *Spec);
2265 
2266  /// Retrieve a suitable printing policy for diagnostics.
2268  return getPrintingPolicy(Context, PP);
2269  }
2270 
2271  /// Retrieve a suitable printing policy for diagnostics.
2272  static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx,
2273  const Preprocessor &PP);
2274 
2275  /// Scope actions.
2276  void ActOnPopScope(SourceLocation Loc, Scope *S);
2277  void ActOnTranslationUnitScope(Scope *S);
2278 
2279  Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS,
2280  RecordDecl *&AnonRecord);
2281  Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS,
2282  MultiTemplateParamsArg TemplateParams,
2283  bool IsExplicitInstantiation,
2284  RecordDecl *&AnonRecord);
2285 
2286  Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
2287  AccessSpecifier AS,
2288  RecordDecl *Record,
2289  const PrintingPolicy &Policy);
2290 
2291  Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS,
2292  RecordDecl *Record);
2293 
2294  /// Common ways to introduce type names without a tag for use in diagnostics.
2295  /// Keep in sync with err_tag_reference_non_tag.
2296  enum NonTagKind {
2306  };
2307 
2308  /// Given a non-tag type declaration, returns an enum useful for indicating
2309  /// what kind of non-tag type this is.
2310  NonTagKind getNonTagTypeDeclKind(const Decl *D, TagTypeKind TTK);
2311 
2312  bool isAcceptableTagRedeclaration(const TagDecl *Previous,
2313  TagTypeKind NewTag, bool isDefinition,
2314  SourceLocation NewTagLoc,
2315  const IdentifierInfo *Name);
2316 
2317  enum TagUseKind {
2318  TUK_Reference, // Reference to a tag: 'struct foo *X;'
2319  TUK_Declaration, // Fwd decl of a tag: 'struct foo;'
2320  TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;'
2321  TUK_Friend // Friend declaration: 'friend struct foo;'
2322  };
2323 
2324  Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
2325  SourceLocation KWLoc, CXXScopeSpec &SS, IdentifierInfo *Name,
2326  SourceLocation NameLoc, const ParsedAttributesView &Attr,
2327  AccessSpecifier AS, SourceLocation ModulePrivateLoc,
2328  MultiTemplateParamsArg TemplateParameterLists, bool &OwnedDecl,
2329  bool &IsDependent, SourceLocation ScopedEnumKWLoc,
2330  bool ScopedEnumUsesClassTag, TypeResult UnderlyingType,
2331  bool IsTypeSpecifier, bool IsTemplateParamOrArg,
2332  SkipBodyInfo *SkipBody = nullptr);
2333 
2334  Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc,
2335  unsigned TagSpec, SourceLocation TagLoc,
2336  CXXScopeSpec &SS, IdentifierInfo *Name,
2337  SourceLocation NameLoc,
2338  const ParsedAttributesView &Attr,
2339  MultiTemplateParamsArg TempParamLists);
2340 
2341  TypeResult ActOnDependentTag(Scope *S,
2342  unsigned TagSpec,
2343  TagUseKind TUK,
2344  const CXXScopeSpec &SS,
2345  IdentifierInfo *Name,
2346  SourceLocation TagLoc,
2347  SourceLocation NameLoc);
2348 
2349  void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart,
2350  IdentifierInfo *ClassName,
2351  SmallVectorImpl<Decl *> &Decls);
2352  Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart,
2353  Declarator &D, Expr *BitfieldWidth);
2354 
2355  FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
2356  Declarator &D, Expr *BitfieldWidth,
2357  InClassInitStyle InitStyle,
2358  AccessSpecifier AS);
2359  MSPropertyDecl *HandleMSProperty(Scope *S, RecordDecl *TagD,
2360  SourceLocation DeclStart, Declarator &D,
2361  Expr *BitfieldWidth,
2362  InClassInitStyle InitStyle,
2363  AccessSpecifier AS,
2364  const ParsedAttr &MSPropertyAttr);
2365 
2366  FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T,
2367  TypeSourceInfo *TInfo,
2368  RecordDecl *Record, SourceLocation Loc,
2369  bool Mutable, Expr *BitfieldWidth,
2370  InClassInitStyle InitStyle,
2371  SourceLocation TSSL,
2372  AccessSpecifier AS, NamedDecl *PrevDecl,
2373  Declarator *D = nullptr);
2374 
2375  bool CheckNontrivialField(FieldDecl *FD);
2376  void DiagnoseNontrivial(const CXXRecordDecl *Record, CXXSpecialMember CSM);
2377 
2379  /// The triviality of a method unaffected by "trivial_abi".
2381 
2382  /// The triviality of a method affected by "trivial_abi".
2383  TAH_ConsiderTrivialABI
2384  };
2385 
2386  bool SpecialMemberIsTrivial(CXXMethodDecl *MD, CXXSpecialMember CSM,
2387  TrivialABIHandling TAH = TAH_IgnoreTrivialABI,
2388  bool Diagnose = false);
2389  CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD);
2390  void ActOnLastBitfield(SourceLocation DeclStart,
2391  SmallVectorImpl<Decl *> &AllIvarDecls);
2392  Decl *ActOnIvar(Scope *S, SourceLocation DeclStart,
2393  Declarator &D, Expr *BitfieldWidth,
2394  tok::ObjCKeywordKind visibility);
2395 
2396  // This is used for both record definitions and ObjC interface declarations.
2397  void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl,
2398  ArrayRef<Decl *> Fields, SourceLocation LBrac,
2399  SourceLocation RBrac, const ParsedAttributesView &AttrList);
2400 
2401  /// ActOnTagStartDefinition - Invoked when we have entered the
2402  /// scope of a tag's definition (e.g., for an enumeration, class,
2403  /// struct, or union).
2404  void ActOnTagStartDefinition(Scope *S, Decl *TagDecl);
2405 
2406  /// Perform ODR-like check for C/ObjC when merging tag types from modules.
2407  /// Differently from C++, actually parse the body and reject / error out
2408  /// in case of a structural mismatch.
2409  bool ActOnDuplicateDefinition(DeclSpec &DS, Decl *Prev,
2410  SkipBodyInfo &SkipBody);
2411 
2413 
2414  /// Invoked when we enter a tag definition that we're skipping.
2415  SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD);
2416 
2417  Decl *ActOnObjCContainerStartDefinition(Decl *IDecl);
2418 
2419  /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a
2420  /// C++ record definition's base-specifiers clause and are starting its
2421  /// member declarations.
2422  void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl,
2423  SourceLocation FinalLoc,
2424  bool IsFinalSpelledSealed,
2425  SourceLocation LBraceLoc);
2426 
2427  /// ActOnTagFinishDefinition - Invoked once we have finished parsing
2428  /// the definition of a tag (enumeration, class, struct, or union).
2429  void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl,
2430  SourceRange BraceRange);
2431 
2432  void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context);
2433 
2434  void ActOnObjCContainerFinishDefinition();
2435 
2436  /// Invoked when we must temporarily exit the objective-c container
2437  /// scope for parsing/looking-up C constructs.
2438  ///
2439  /// Must be followed by a call to \see ActOnObjCReenterContainerContext
2440  void ActOnObjCTemporaryExitContainerContext(DeclContext *DC);
2441  void ActOnObjCReenterContainerContext(DeclContext *DC);
2442 
2443  /// ActOnTagDefinitionError - Invoked when there was an unrecoverable
2444  /// error parsing the definition of a tag.
2445  void ActOnTagDefinitionError(Scope *S, Decl *TagDecl);
2446 
2447  EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum,
2448  EnumConstantDecl *LastEnumConst,
2449  SourceLocation IdLoc,
2450  IdentifierInfo *Id,
2451  Expr *val);
2452  bool CheckEnumUnderlyingType(TypeSourceInfo *TI);
2453  bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped,
2454  QualType EnumUnderlyingTy, bool IsFixed,
2455  const EnumDecl *Prev);
2456 
2457  /// Determine whether the body of an anonymous enumeration should be skipped.
2458  /// \param II The name of the first enumerator.
2459  SkipBodyInfo shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II,
2460  SourceLocation IILoc);
2461 
2462  Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant,
2464  const ParsedAttributesView &Attrs,
2465  SourceLocation EqualLoc, Expr *Val);
2466  void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange,
2467  Decl *EnumDecl, ArrayRef<Decl *> Elements, Scope *S,
2468  const ParsedAttributesView &Attr);
2469 
2470  DeclContext *getContainingDC(DeclContext *DC);
2471 
2472  /// Set the current declaration context until it gets popped.
2473  void PushDeclContext(Scope *S, DeclContext *DC);
2474  void PopDeclContext();
2475 
2476  /// EnterDeclaratorContext - Used when we must lookup names in the context
2477  /// of a declarator's nested name specifier.
2478  void EnterDeclaratorContext(Scope *S, DeclContext *DC);
2479  void ExitDeclaratorContext(Scope *S);
2480 
2481  /// Push the parameters of D, which must be a function, into scope.
2482  void ActOnReenterFunctionContext(Scope* S, Decl* D);
2483  void ActOnExitFunctionContext();
2484 
2485  DeclContext *getFunctionLevelDeclContext();
2486 
2487  /// getCurFunctionDecl - If inside of a function body, this returns a pointer
2488  /// to the function decl for the function being parsed. If we're currently
2489  /// in a 'block', this returns the containing context.
2490  FunctionDecl *getCurFunctionDecl();
2491 
2492  /// getCurMethodDecl - If inside of a method body, this returns a pointer to
2493  /// the method decl for the method being parsed. If we're currently
2494  /// in a 'block', this returns the containing context.
2495  ObjCMethodDecl *getCurMethodDecl();
2496 
2497  /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
2498  /// or C function we're in, otherwise return null. If we're currently
2499  /// in a 'block', this returns the containing context.
2500  NamedDecl *getCurFunctionOrMethodDecl();
2501 
2502  /// Add this decl to the scope shadowed decl chains.
2503  void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true);
2504 
2505  /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
2506  /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
2507  /// true if 'D' belongs to the given declaration context.
2508  ///
2509  /// \param AllowInlineNamespace If \c true, allow the declaration to be in the
2510  /// enclosing namespace set of the context, rather than contained
2511  /// directly within it.
2512  bool isDeclInScope(NamedDecl *D, DeclContext *Ctx, Scope *S = nullptr,
2513  bool AllowInlineNamespace = false);
2514 
2515  /// Finds the scope corresponding to the given decl context, if it
2516  /// happens to be an enclosing scope. Otherwise return NULL.
2517  static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC);
2518 
2519  /// Subroutines of ActOnDeclarator().
2520  TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
2521  TypeSourceInfo *TInfo);
2522  bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New);
2523 
2524  /// Describes the kind of merge to perform for availability
2525  /// attributes (including "deprecated", "unavailable", and "availability").
2527  /// Don't merge availability attributes at all.
2529  /// Merge availability attributes for a redeclaration, which requires
2530  /// an exact match.
2532  /// Merge availability attributes for an override, which requires
2533  /// an exact match or a weakening of constraints.
2535  /// Merge availability attributes for an implementation of
2536  /// a protocol requirement.
2538  };
2539 
2540  /// Describes the kind of priority given to an availability attribute.
2541  ///
2542  /// The sum of priorities deteremines the final priority of the attribute.
2543  /// The final priority determines how the attribute will be merged.
2544  /// An attribute with a lower priority will always remove higher priority
2545  /// attributes for the specified platform when it is being applied. An
2546  /// attribute with a higher priority will not be applied if the declaration
2547  /// already has an availability attribute with a lower priority for the
2548  /// specified platform. The final prirority values are not expected to match
2549  /// the values in this enumeration, but instead should be treated as a plain
2550  /// integer value. This enumeration just names the priority weights that are
2551  /// used to calculate that final vaue.
2553  /// The availability attribute was specified explicitly next to the
2554  /// declaration.
2555  AP_Explicit = 0,
2556 
2557  /// The availability attribute was applied using '#pragma clang attribute'.
2558  AP_PragmaClangAttribute = 1,
2559 
2560  /// The availability attribute for a specific platform was inferred from
2561  /// an availability attribute for another platform.
2562  AP_InferredFromOtherPlatform = 2
2563  };
2564 
2565  /// Attribute merging methods. Return true if a new attribute was added.
2566  AvailabilityAttr *mergeAvailabilityAttr(
2567  NamedDecl *D, SourceRange Range, IdentifierInfo *Platform, bool Implicit,
2568  VersionTuple Introduced, VersionTuple Deprecated, VersionTuple Obsoleted,
2569  bool IsUnavailable, StringRef Message, bool IsStrict,
2570  StringRef Replacement, AvailabilityMergeKind AMK, int Priority,
2571  unsigned AttrSpellingListIndex);
2572  TypeVisibilityAttr *mergeTypeVisibilityAttr(Decl *D, SourceRange Range,
2573  TypeVisibilityAttr::VisibilityType Vis,
2574  unsigned AttrSpellingListIndex);
2575  VisibilityAttr *mergeVisibilityAttr(Decl *D, SourceRange Range,
2576  VisibilityAttr::VisibilityType Vis,
2577  unsigned AttrSpellingListIndex);
2578  UuidAttr *mergeUuidAttr(Decl *D, SourceRange Range,
2579  unsigned AttrSpellingListIndex, StringRef Uuid);
2580  DLLImportAttr *mergeDLLImportAttr(Decl *D, SourceRange Range,
2581  unsigned AttrSpellingListIndex);
2582  DLLExportAttr *mergeDLLExportAttr(Decl *D, SourceRange Range,
2583  unsigned AttrSpellingListIndex);
2584  MSInheritanceAttr *
2585  mergeMSInheritanceAttr(Decl *D, SourceRange Range, bool BestCase,
2586  unsigned AttrSpellingListIndex,
2587  MSInheritanceAttr::Spelling SemanticSpelling);
2588  FormatAttr *mergeFormatAttr(Decl *D, SourceRange Range,
2589  IdentifierInfo *Format, int FormatIdx,
2590  int FirstArg, unsigned AttrSpellingListIndex);
2591  SectionAttr *mergeSectionAttr(Decl *D, SourceRange Range, StringRef Name,
2592  unsigned AttrSpellingListIndex);
2593  CodeSegAttr *mergeCodeSegAttr(Decl *D, SourceRange Range, StringRef Name,
2594  unsigned AttrSpellingListIndex);
2595  AlwaysInlineAttr *mergeAlwaysInlineAttr(Decl *D, SourceRange Range,
2596  IdentifierInfo *Ident,
2597  unsigned AttrSpellingListIndex);
2598  MinSizeAttr *mergeMinSizeAttr(Decl *D, SourceRange Range,
2599  unsigned AttrSpellingListIndex);
2600  NoSpeculativeLoadHardeningAttr *
2601  mergeNoSpeculativeLoadHardeningAttr(Decl *D,
2602  const NoSpeculativeLoadHardeningAttr &AL);
2603  SpeculativeLoadHardeningAttr *
2604  mergeSpeculativeLoadHardeningAttr(Decl *D,
2605  const SpeculativeLoadHardeningAttr &AL);
2606  OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D, SourceRange Range,
2607  unsigned AttrSpellingListIndex);
2608  InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, const ParsedAttr &AL);
2609  InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D,
2610  const InternalLinkageAttr &AL);
2611  CommonAttr *mergeCommonAttr(Decl *D, const ParsedAttr &AL);
2612  CommonAttr *mergeCommonAttr(Decl *D, const CommonAttr &AL);
2613 
2614  void mergeDeclAttributes(NamedDecl *New, Decl *Old,
2615  AvailabilityMergeKind AMK = AMK_Redeclaration);
2616  void MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New,
2617  LookupResult &OldDecls);
2618  bool MergeFunctionDecl(FunctionDecl *New, NamedDecl *&Old, Scope *S,
2619  bool MergeTypeWithOld);
2620  bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old,
2621  Scope *S, bool MergeTypeWithOld);
2622  void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old);
2623  void MergeVarDecl(VarDecl *New, LookupResult &Previous);
2624  void MergeVarDeclTypes(VarDecl *New, VarDecl *Old, bool MergeTypeWithOld);
2625  void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old);
2626  bool checkVarDeclRedefinition(VarDecl *OldDefn, VarDecl *NewDefn);
2627  void notePreviousDefinition(const NamedDecl *Old, SourceLocation New);
2628  bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S);
2629 
2630  // AssignmentAction - This is used by all the assignment diagnostic functions
2631  // to represent what is actually causing the operation
2640  AA_Passing_CFAudited
2641  };
2642 
2643  /// C++ Overloading.
2645  /// This is a legitimate overload: the existing declarations are
2646  /// functions or function templates with different signatures.
2648 
2649  /// This is not an overload because the signature exactly matches
2650  /// an existing declaration.
2652 
2653  /// This is not an overload because the lookup results contain a
2654  /// non-function.
2655  Ovl_NonFunction
2656  };
2657  OverloadKind CheckOverload(Scope *S,
2658  FunctionDecl *New,
2659  const LookupResult &OldDecls,
2660  NamedDecl *&OldDecl,
2661  bool IsForUsingDecl);
2662  bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl,
2663  bool ConsiderCudaAttrs = true);
2664 
2666  TryImplicitConversion(Expr *From, QualType ToType,
2667  bool SuppressUserConversions,
2668  bool AllowExplicit,
2669  bool InOverloadResolution,
2670  bool CStyle,
2671  bool AllowObjCWritebackConversion);
2672 
2673  bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
2674  bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
2675  bool IsComplexPromotion(QualType FromType, QualType ToType);
2676  bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
2677  bool InOverloadResolution,
2678  QualType& ConvertedType, bool &IncompatibleObjC);
2679  bool isObjCPointerConversion(QualType FromType, QualType ToType,
2680  QualType& ConvertedType, bool &IncompatibleObjC);
2681  bool isObjCWritebackConversion(QualType FromType, QualType ToType,
2682  QualType &ConvertedType);
2683  bool IsBlockPointerConversion(QualType FromType, QualType ToType,
2684  QualType& ConvertedType);
2685  bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
2686  const FunctionProtoType *NewType,
2687  unsigned *ArgPos = nullptr);
2688  void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
2689  QualType FromType, QualType ToType);
2690 
2691  void maybeExtendBlockObject(ExprResult &E);
2692  CastKind PrepareCastToObjCObjectPointer(ExprResult &E);
2693  bool CheckPointerConversion(Expr *From, QualType ToType,
2694  CastKind &Kind,
2695  CXXCastPath& BasePath,
2696  bool IgnoreBaseAccess,
2697  bool Diagnose = true);
2698  bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
2699  bool InOverloadResolution,
2700  QualType &ConvertedType);
2701  bool CheckMemberPointerConversion(Expr *From, QualType ToType,
2702  CastKind &Kind,
2703  CXXCastPath &BasePath,
2704  bool IgnoreBaseAccess);
2705  bool IsQualificationConversion(QualType FromType, QualType ToType,
2706  bool CStyle, bool &ObjCLifetimeConversion);
2707  bool IsFunctionConversion(QualType FromType, QualType ToType,
2708  QualType &ResultTy);
2709  bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType);
2710  bool isSameOrCompatibleFunctionType(CanQualType Param, CanQualType Arg);
2711 
2712  ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
2713  const VarDecl *NRVOCandidate,
2714  QualType ResultType,
2715  Expr *Value,
2716  bool AllowNRVO = true);
2717 
2718  bool CanPerformCopyInitialization(const InitializedEntity &Entity,
2719  ExprResult Init);
2720  ExprResult PerformCopyInitialization(const InitializedEntity &Entity,
2721  SourceLocation EqualLoc,
2722  ExprResult Init,
2723  bool TopLevelOfInitList = false,
2724  bool AllowExplicit = false);
2725  ExprResult PerformObjectArgumentInitialization(Expr *From,
2726  NestedNameSpecifier *Qualifier,
2727  NamedDecl *FoundDecl,
2728  CXXMethodDecl *Method);
2729 
2730  /// Check that the lifetime of the initializer (and its subobjects) is
2731  /// sufficient for initializing the entity, and perform lifetime extension
2732  /// (when permitted) if not.
2733  void checkInitializerLifetime(const InitializedEntity &Entity, Expr *Init);
2734 
2735  ExprResult PerformContextuallyConvertToBool(Expr *From);
2736  ExprResult PerformContextuallyConvertToObjCPointer(Expr *From);
2737 
2738  /// Contexts in which a converted constant expression is required.
2739  enum CCEKind {
2740  CCEK_CaseValue, ///< Expression in a case label.
2741  CCEK_Enumerator, ///< Enumerator value with fixed underlying type.
2742  CCEK_TemplateArg, ///< Value of a non-type template parameter.
2743  CCEK_NewExpr, ///< Constant expression in a noptr-new-declarator.
2744  CCEK_ConstexprIf ///< Condition in a constexpr if statement.
2745  };
2747  llvm::APSInt &Value, CCEKind CCE);
2749  APValue &Value, CCEKind CCE);
2750 
2751  /// Abstract base class used to perform a contextual implicit
2752  /// conversion from an expression to any type passing a filter.
2754  public:
2755  bool Suppress;
2757 
2758  ContextualImplicitConverter(bool Suppress = false,
2759  bool SuppressConversion = false)
2760  : Suppress(Suppress), SuppressConversion(SuppressConversion) {}
2761 
2762  /// Determine whether the specified type is a valid destination type
2763  /// for this conversion.
2764  virtual bool match(QualType T) = 0;
2765 
2766  /// Emits a diagnostic complaining that the expression does not have
2767  /// integral or enumeration type.
2768  virtual SemaDiagnosticBuilder
2769  diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) = 0;
2770 
2771  /// Emits a diagnostic when the expression has incomplete class type.
2772  virtual SemaDiagnosticBuilder
2773  diagnoseIncomplete(Sema &S, SourceLocation Loc, QualType T) = 0;
2774 
2775  /// Emits a diagnostic when the only matching conversion function
2776  /// is explicit.
2777  virtual SemaDiagnosticBuilder diagnoseExplicitConv(
2778  Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0;
2779 
2780  /// Emits a note for the explicit conversion function.
2781  virtual SemaDiagnosticBuilder
2782  noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0;
2783 
2784  /// Emits a diagnostic when there are multiple possible conversion
2785  /// functions.
2786  virtual SemaDiagnosticBuilder
2787  diagnoseAmbiguous(Sema &S, SourceLocation Loc, QualType T) = 0;
2788 
2789  /// Emits a note for one of the candidate conversions.
2790  virtual SemaDiagnosticBuilder
2791  noteAmbiguous(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0;
2792 
2793  /// Emits a diagnostic when we picked a conversion function
2794  /// (for cases when we are not allowed to pick a conversion function).
2795  virtual SemaDiagnosticBuilder diagnoseConversion(
2796  Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0;
2797 
2799  };
2800 
2802  bool AllowScopedEnumerations;
2803 
2804  public:
2805  ICEConvertDiagnoser(bool AllowScopedEnumerations,
2806  bool Suppress, bool SuppressConversion)
2807  : ContextualImplicitConverter(Suppress, SuppressConversion),
2808  AllowScopedEnumerations(AllowScopedEnumerations) {}
2809 
2810  /// Match an integral or (possibly scoped) enumeration type.
2811  bool match(QualType T) override;
2812 
2815  return diagnoseNotInt(S, Loc, T);
2816  }
2817 
2818  /// Emits a diagnostic complaining that the expression does not have
2819  /// integral or enumeration type.
2820  virtual SemaDiagnosticBuilder
2821  diagnoseNotInt(Sema &S, SourceLocation Loc, QualType T) = 0;
2822  };
2823 
2824  /// Perform a contextual implicit conversion.
2825  ExprResult PerformContextualImplicitConversion(
2826  SourceLocation Loc, Expr *FromE, ContextualImplicitConverter &Converter);
2827 
2828 
2832  OS_Error
2833  };
2834  ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE);
2835 
2836  // Note that LK_String is intentionally after the other literals, as
2837  // this is used for diagnostics logic.
2845  LK_None
2846  };
2847  ObjCLiteralKind CheckLiteralKind(Expr *FromE);
2848 
2849  ExprResult PerformObjectMemberConversion(Expr *From,
2850  NestedNameSpecifier *Qualifier,
2851  NamedDecl *FoundDecl,
2852  NamedDecl *Member);
2853 
2854  // Members have to be NamespaceDecl* or TranslationUnitDecl*.
2855  // TODO: make this is a typesafe union.
2858 
2860 
2861  void AddOverloadCandidate(FunctionDecl *Function, DeclAccessPair FoundDecl,
2862  ArrayRef<Expr *> Args,
2863  OverloadCandidateSet &CandidateSet,
2864  bool SuppressUserConversions = false,
2865  bool PartialOverloading = false,
2866  bool AllowExplicit = false,
2867  ADLCallKind IsADLCandidate = ADLCallKind::NotADL,
2868  ConversionSequenceList EarlyConversions = None);
2869  void AddFunctionCandidates(const UnresolvedSetImpl &Functions,
2870  ArrayRef<Expr *> Args,
2871  OverloadCandidateSet &CandidateSet,
2872  TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr,
2873  bool SuppressUserConversions = false,
2874  bool PartialOverloading = false,
2875  bool FirstArgumentIsBase = false);
2876  void AddMethodCandidate(DeclAccessPair FoundDecl,
2877  QualType ObjectType,
2878  Expr::Classification ObjectClassification,
2879  ArrayRef<Expr *> Args,
2880  OverloadCandidateSet& CandidateSet,
2881  bool SuppressUserConversion = false);
2882  void AddMethodCandidate(CXXMethodDecl *Method,
2883  DeclAccessPair FoundDecl,
2884  CXXRecordDecl *ActingContext, QualType ObjectType,
2885  Expr::Classification ObjectClassification,
2886  ArrayRef<Expr *> Args,
2887  OverloadCandidateSet& CandidateSet,
2888  bool SuppressUserConversions = false,
2889  bool PartialOverloading = false,
2890  ConversionSequenceList EarlyConversions = None);
2891  void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl,
2892  DeclAccessPair FoundDecl,
2893  CXXRecordDecl *ActingContext,
2894  TemplateArgumentListInfo *ExplicitTemplateArgs,
2895  QualType ObjectType,
2896  Expr::Classification ObjectClassification,
2897  ArrayRef<Expr *> Args,
2898  OverloadCandidateSet& CandidateSet,
2899  bool SuppressUserConversions = false,
2900  bool PartialOverloading = false);
2901  void AddTemplateOverloadCandidate(
2902  FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl,
2903  TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args,
2904  OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false,
2905  bool PartialOverloading = false,
2906  ADLCallKind IsADLCandidate = ADLCallKind::NotADL);
2907  bool CheckNonDependentConversions(FunctionTemplateDecl *FunctionTemplate,
2908  ArrayRef<QualType> ParamTypes,
2909  ArrayRef<Expr *> Args,
2910  OverloadCandidateSet &CandidateSet,
2911  ConversionSequenceList &Conversions,
2912  bool SuppressUserConversions,
2913  CXXRecordDecl *ActingContext = nullptr,
2914  QualType ObjectType = QualType(),
2916  ObjectClassification = {});
2917  void AddConversionCandidate(CXXConversionDecl *Conversion,
2918  DeclAccessPair FoundDecl,
2919  CXXRecordDecl *ActingContext,
2920  Expr *From, QualType ToType,
2921  OverloadCandidateSet& CandidateSet,
2922  bool AllowObjCConversionOnExplicit,
2923  bool AllowResultConversion = true);
2924  void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate,
2925  DeclAccessPair FoundDecl,
2926  CXXRecordDecl *ActingContext,
2927  Expr *From, QualType ToType,
2928  OverloadCandidateSet &CandidateSet,
2929  bool AllowObjCConversionOnExplicit,
2930  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 
4255  // Primary Expressions.
4256  SourceRange getExprRange(Expr *E) const;
4257 
4258  ExprResult ActOnIdExpression(
4259  Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
4260  UnqualifiedId &Id, bool HasTrailingLParen, bool IsAddressOfOperand,
4261  CorrectionCandidateCallback *CCC = nullptr,
4262  bool IsInlineAsmIdentifier = false, Token *KeywordReplacement = nullptr);
4263 
4264  void DecomposeUnqualifiedId(const UnqualifiedId &Id,
4265  TemplateArgumentListInfo &Buffer,
4266  DeclarationNameInfo &NameInfo,
4267  const TemplateArgumentListInfo *&TemplateArgs);
4268 
4269  bool
4270  DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
4272  TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr,
4273  ArrayRef<Expr *> Args = None, TypoExpr **Out = nullptr);
4274 
4275  ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S,
4276  IdentifierInfo *II,
4277  bool AllowBuiltinCreation=false);
4278 
4279  ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS,
4280  SourceLocation TemplateKWLoc,
4281  const DeclarationNameInfo &NameInfo,
4282  bool isAddressOfOperand,
4283  const TemplateArgumentListInfo *TemplateArgs);
4284 
4285  ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
4286  ExprValueKind VK,
4287  SourceLocation Loc,
4288  const CXXScopeSpec *SS = nullptr);
4289  ExprResult
4290  BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK,
4291  const DeclarationNameInfo &NameInfo,
4292  const CXXScopeSpec *SS = nullptr,
4293  NamedDecl *FoundD = nullptr,
4294  const TemplateArgumentListInfo *TemplateArgs = nullptr);
4295  ExprResult
4296  BuildAnonymousStructUnionMemberReference(
4297  const CXXScopeSpec &SS,
4298  SourceLocation nameLoc,
4299  IndirectFieldDecl *indirectField,
4300  DeclAccessPair FoundDecl = DeclAccessPair::make(nullptr, AS_none),
4301  Expr *baseObjectExpr = nullptr,
4302  SourceLocation opLoc = SourceLocation());
4303 
4304  ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
4305  SourceLocation TemplateKWLoc,
4306  LookupResult &R,
4307  const TemplateArgumentListInfo *TemplateArgs,
4308  const Scope *S);
4309  ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS,
4310  SourceLocation TemplateKWLoc,
4311  LookupResult &R,
4312  const TemplateArgumentListInfo *TemplateArgs,
4313  bool IsDefiniteInstance,
4314  const Scope *S);
4315  bool UseArgumentDependentLookup(const CXXScopeSpec &SS,
4316  const LookupResult &R,
4317  bool HasTrailingLParen);
4318 
4319  ExprResult
4320  BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS,
4321  const DeclarationNameInfo &NameInfo,
4322  bool IsAddressOfOperand, const Scope *S,
4323  TypeSourceInfo **RecoveryTSI = nullptr);
4324 
4325  ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
4326  SourceLocation TemplateKWLoc,
4327  const DeclarationNameInfo &NameInfo,
4328  const TemplateArgumentListInfo *TemplateArgs);
4329 
4330  ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
4331  LookupResult &R,
4332  bool NeedsADL,
4333  bool AcceptInvalidDecl = false);
4334  ExprResult BuildDeclarationNameExpr(
4335  const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D,
4336  NamedDecl *FoundD = nullptr,
4337  const TemplateArgumentListInfo *TemplateArgs = nullptr,
4338  bool AcceptInvalidDecl = false);
4339 
4340  ExprResult BuildLiteralOperatorCall(LookupResult &R,
4341  DeclarationNameInfo &SuffixInfo,
4342  ArrayRef<Expr *> Args,
4343  SourceLocation LitEndLoc,
4344  TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr);
4345 
4346  ExprResult BuildPredefinedExpr(SourceLocation Loc,
4348  ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
4349  ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val);
4350 
4351  bool CheckLoopHintExpr(Expr *E, SourceLocation Loc);
4352 
4353  ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr);
4354  ExprResult ActOnCharacterConstant(const Token &Tok,
4355  Scope *UDLScope = nullptr);
4356  ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E);
4357  ExprResult ActOnParenListExpr(SourceLocation L,
4358  SourceLocation R,
4359  MultiExprArg Val);
4360 
4361  /// ActOnStringLiteral - The specified tokens were lexed as pasted string
4362  /// fragments (e.g. "foo" "bar" L"baz").
4363  ExprResult ActOnStringLiteral(ArrayRef<Token> StringToks,
4364  Scope *UDLScope = nullptr);
4365 
4366  ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc,
4367  SourceLocation DefaultLoc,
4368  SourceLocation RParenLoc,
4369  Expr *ControllingExpr,
4370  ArrayRef<ParsedType> ArgTypes,
4371  ArrayRef<Expr *> ArgExprs);
4372  ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc,
4373  SourceLocation DefaultLoc,
4374  SourceLocation RParenLoc,
4375  Expr *ControllingExpr,
4377  ArrayRef<Expr *> Exprs);
4378 
4379  // Binary/Unary Operators. 'Tok' is the token for the operator.
4380  ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc,
4381  Expr *InputExpr);
4382  ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc,
4383  UnaryOperatorKind Opc, Expr *Input);
4384  ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
4385  tok::TokenKind Op, Expr *Input);
4386 
4387  bool isQualifiedMemberAccess(Expr *E);
4388  QualType CheckAddressOfOperand(ExprResult &Operand, SourceLocation OpLoc);
4389 
4390  ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo,
4391  SourceLocation OpLoc,
4392  UnaryExprOrTypeTrait ExprKind,
4393  SourceRange R);
4394  ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc,
4395  UnaryExprOrTypeTrait ExprKind);
4396  ExprResult
4397  ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc,
4398  UnaryExprOrTypeTrait ExprKind,
4399  bool IsType, void *TyOrEx,
4400  SourceRange ArgRange);
4401 
4402  ExprResult CheckPlaceholderExpr(Expr *E);
4403  bool CheckVecStepExpr(Expr *E);
4404 
4405  bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind);
4406  bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc,
4407  SourceRange ExprRange,
4408  UnaryExprOrTypeTrait ExprKind);
4409  ExprResult ActOnSizeofParameterPackExpr(Scope *S,
4410  SourceLocation OpLoc,
4411  IdentifierInfo &Name,
4412  SourceLocation NameLoc,
4413  SourceLocation RParenLoc);
4414  ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
4415  tok::TokenKind Kind, Expr *Input);
4416 
4417  ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc,
4418  Expr *Idx, SourceLocation RLoc);
4419  ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc,
4420  Expr *Idx, SourceLocation RLoc);
4421  ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc,
4422  Expr *LowerBound, SourceLocation ColonLoc,
4423  Expr *Length, SourceLocation RBLoc);
4424 
4425  // This struct is for use by ActOnMemberAccess to allow
4426  // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after
4427  // changing the access operator from a '.' to a '->' (to see if that is the
4428  // change needed to fix an error about an unknown member, e.g. when the class
4429  // defines a custom operator->).
4431  Scope *S;
4434  };
4435 
4436  ExprResult BuildMemberReferenceExpr(
4437  Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow,
4438  CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
4439  NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo,
4440  const TemplateArgumentListInfo *TemplateArgs,
4441  const Scope *S,
4442  ActOnMemberAccessExtraArgs *ExtraArgs = nullptr);
4443 
4444  ExprResult
4445  BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc,
4446  bool IsArrow, const CXXScopeSpec &SS,
4447  SourceLocation TemplateKWLoc,
4448  NamedDecl *FirstQualifierInScope, LookupResult &R,
4449  const TemplateArgumentListInfo *TemplateArgs,
4450  const Scope *S,
4451  bool SuppressQualifierCheck = false,
4452  ActOnMemberAccessExtraArgs *ExtraArgs = nullptr);
4453 
4454  ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow,
4455  SourceLocation OpLoc,
4456  const CXXScopeSpec &SS, FieldDecl *Field,
4457  DeclAccessPair FoundDecl,
4458  const DeclarationNameInfo &MemberNameInfo);
4459 
4460  ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow);
4461 
4462  bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType,
4463  const CXXScopeSpec &SS,
4464  const LookupResult &R);
4465 
4466  ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType,
4467  bool IsArrow, SourceLocation OpLoc,
4468  const CXXScopeSpec &SS,
4469  SourceLocation TemplateKWLoc,
4470  NamedDecl *FirstQualifierInScope,
4471  const DeclarationNameInfo &NameInfo,
4472  const TemplateArgumentListInfo *TemplateArgs);
4473 
4474  ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base,
4475  SourceLocation OpLoc,
4476  tok::TokenKind OpKind,
4477  CXXScopeSpec &SS,
4478  SourceLocation TemplateKWLoc,
4479  UnqualifiedId &Member,
4480  Decl *ObjCImpDecl);
4481 
4482  void ActOnDefaultCtorInitializers(Decl *CDtorDecl);
4483  bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
4484  FunctionDecl *FDecl,
4485  const FunctionProtoType *Proto,
4486  ArrayRef<Expr *> Args,
4487  SourceLocation RParenLoc,
4488  bool ExecConfig = false);
4489  void CheckStaticArrayArgument(SourceLocation CallLoc,
4490  ParmVarDecl *Param,
4491  const Expr *ArgExpr);
4492 
4493  /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
4494  /// This provides the location of the left/right parens and a list of comma
4495  /// locations.
4496  ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc,
4497  MultiExprArg ArgExprs, SourceLocation RParenLoc,
4498  Expr *ExecConfig = nullptr,
4499  bool IsExecConfig = false);
4500  ExprResult
4501  BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, SourceLocation LParenLoc,
4502  ArrayRef<Expr *> Arg, SourceLocation RParenLoc,
4503  Expr *Config = nullptr, bool IsExecConfig = false,
4504  ADLCallKind UsesADL = ADLCallKind::NotADL);
4505 
4506  ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc,
4507  MultiExprArg ExecConfig,
4508  SourceLocation GGGLoc);
4509 
4510  ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc,
4511  Declarator &D, ParsedType &Ty,
4512  SourceLocation RParenLoc, Expr *CastExpr);
4513  ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc,
4514  TypeSourceInfo *Ty,
4515  SourceLocation RParenLoc,
4516  Expr *Op);
4517  CastKind PrepareScalarCast(ExprResult &src, QualType destType);
4518 
4519  /// Build an altivec or OpenCL literal.
4520  ExprResult BuildVectorLiteral(SourceLocation LParenLoc,
4521  SourceLocation RParenLoc, Expr *E,
4522  TypeSourceInfo *TInfo);
4523 
4524  ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME);
4525 
4526  ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
4527  ParsedType Ty,
4528  SourceLocation RParenLoc,
4529  Expr *InitExpr);
4530 
4531  ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc,
4532  TypeSourceInfo *TInfo,
4533  SourceLocation RParenLoc,
4534  Expr *LiteralExpr);
4535 
4536  ExprResult ActOnInitList(SourceLocation LBraceLoc,
4537  MultiExprArg InitArgList,
4538  SourceLocation RBraceLoc);
4539 
4540  ExprResult ActOnDesignatedInitializer(Designation &Desig,
4541  SourceLocation Loc,
4542  bool GNUSyntax,
4543  ExprResult Init);
4544 
4545 private:
4546  static BinaryOperatorKind ConvertTokenKindToBinaryOpcode(tok::TokenKind Kind);
4547 
4548 public:
4549  ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
4550  tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr);
4551  ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc,
4552  BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr);
4553  ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc,
4554  Expr *LHSExpr, Expr *RHSExpr);
4555 
4556  void DiagnoseCommaOperator(const Expr *LHS, SourceLocation Loc);
4557 
4558  /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
4559  /// in the case of a the GNU conditional expr extension.
4560  ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
4561  SourceLocation ColonLoc,
4562  Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr);
4563 
4564  /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
4565  ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
4566  LabelDecl *TheDecl);
4567 
4568  void ActOnStartStmtExpr();
4569  ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt,
4570  SourceLocation RPLoc); // "({..})"
4571  // Handle the final expression in a statement expression.
4572  ExprResult ActOnStmtExprResult(ExprResult E);
4573  void ActOnStmtExprError();
4574 
4575  // __builtin_offsetof(type, identifier(.identifier|[expr])*)
4578  bool isBrackets; // true if [expr], false if .ident
4579  union {
4582  } U;
4583  };
4584 
4585  /// __builtin_offsetof(type, a.b[123][456].c)
4586  ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc,
4587  TypeSourceInfo *TInfo,
4588  ArrayRef<OffsetOfComponent> Components,
4589  SourceLocation RParenLoc);
4590  ExprResult ActOnBuiltinOffsetOf(Scope *S,
4591  SourceLocation BuiltinLoc,
4593  ParsedType ParsedArgTy,
4594  ArrayRef<OffsetOfComponent> Components,
4595  SourceLocation RParenLoc);
4596 
4597  // __builtin_choose_expr(constExpr, expr1, expr2)
4598  ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
4599  Expr *CondExpr, Expr *LHSExpr,
4600  Expr *RHSExpr, SourceLocation RPLoc);
4601 
4602  // __builtin_va_arg(expr, type)
4603  ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty,
4604  SourceLocation RPLoc);
4605  ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E,
4606  TypeSourceInfo *TInfo, SourceLocation RPLoc);
4607 
4608  // __null
4609  ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
4610 
4611  bool CheckCaseExpression(Expr *E);
4612 
4613  /// Describes the result of an "if-exists" condition check.
4615  /// The symbol exists.
4617 
4618  /// The symbol does not exist.
4620 
4621  /// The name is a dependent name, so the results will differ
4622  /// from one instantiation to the next.
4624 
4625  /// An error occurred.
4626  IER_Error
4627  };
4628 
4630  CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS,
4631  const DeclarationNameInfo &TargetNameInfo);
4632 
4634  CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc,
4635  bool IsIfExists, CXXScopeSpec &SS,
4636  UnqualifiedId &Name);
4637 
4638  StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc,
4639  bool IsIfExists,
4640  NestedNameSpecifierLoc QualifierLoc,
4641  DeclarationNameInfo NameInfo,
4642  Stmt *Nested);
4643  StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc,
4644  bool IsIfExists,
4645  CXXScopeSpec &SS, UnqualifiedId &Name,
4646  Stmt *Nested);
4647 
4648  //===------------------------- "Block" Extension ------------------------===//
4649 
4650  /// ActOnBlockStart - This callback is invoked when a block literal is
4651  /// started.
4652  void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
4653 
4654  /// ActOnBlockArguments - This callback allows processing of block arguments.
4655  /// If there are no arguments, this is still invoked.
4656  void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo,
4657  Scope *CurScope);
4658 
4659  /// ActOnBlockError - If there is an error parsing a block, this callback
4660  /// is invoked to pop the information about the block from the action impl.
4661  void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
4662 
4663  /// ActOnBlockStmtExpr - This is called when the body of a block statement
4664  /// literal was successfully completed. ^(int x){...}
4665  ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body,
4666  Scope *CurScope);
4667 
4668  //===---------------------------- Clang Extensions ----------------------===//
4669 
4670  /// __builtin_convertvector(...)
4671  ExprResult ActOnConvertVectorExpr(Expr *E, ParsedType ParsedDestTy,
4672  SourceLocation BuiltinLoc,
4673  SourceLocation RParenLoc);
4674 
4675  //===---------------------------- OpenCL Features -----------------------===//
4676 
4677  /// __builtin_astype(...)
4678  ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy,
4679  SourceLocation BuiltinLoc,
4680  SourceLocation RParenLoc);
4681 
4682  //===---------------------------- C++ Features --------------------------===//
4683 
4684  // Act on C++ namespaces
4685  Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc,
4686  SourceLocation NamespaceLoc,
4687  SourceLocation IdentLoc, IdentifierInfo *Ident,
4688  SourceLocation LBrace,
4689  const ParsedAttributesView &AttrList,
4691  void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace);
4692 
4693  NamespaceDecl *getStdNamespace() const;
4694  NamespaceDecl *getOrCreateStdNamespace();
4695 
4696  NamespaceDecl *lookupStdExperimentalNamespace();
4697 
4698  CXXRecordDecl *getStdBadAlloc() const;
4699  EnumDecl *getStdAlignValT() const;
4700 
4701 private:
4702  // A cache representing if we've fully checked the various comparison category
4703  // types stored in ASTContext. The bit-index corresponds to the integer value
4704  // of a ComparisonCategoryType enumerator.
4705  llvm::SmallBitVector FullyCheckedComparisonCategories;
4706 
4707  ValueDecl *tryLookupCtorInitMemberDecl(CXXRecordDecl *ClassDecl,
4708  CXXScopeSpec &SS,
4709  ParsedType TemplateTypeTy,
4710  IdentifierInfo *MemberOrBase);
4711 
4712 public:
4713  /// Lookup the specified comparison category types in the standard
4714  /// library, an check the VarDecls possibly returned by the operator<=>
4715  /// builtins for that type.
4716  ///
4717  /// \return The type of the comparison category type corresponding to the
4718  /// specified Kind, or a null type if an error occurs
4719  QualType CheckComparisonCategoryType(ComparisonCategoryType Kind,
4720  SourceLocation Loc);
4721 
4722  /// Tests whether Ty is an instance of std::initializer_list and, if
4723  /// it is and Element is not NULL, assigns the element type to Element.
4724  bool isStdInitializerList(QualType Ty, QualType *Element);
4725 
4726  /// Looks for the std::initializer_list template and instantiates it
4727  /// with Element, or emits an error if it's not found.
4728  ///
4729  /// \returns The instantiated template, or null on error.
4730  QualType BuildStdInitializerList(QualType Element, SourceLocation Loc);
4731 
4732  /// Determine whether Ctor is an initializer-list constructor, as
4733  /// defined in [dcl.init.list]p2.
4734  bool isInitListConstructor(const FunctionDecl *Ctor);
4735 
4736  Decl *ActOnUsingDirective(Scope *CurScope, SourceLocation UsingLoc,
4737  SourceLocation NamespcLoc, CXXScopeSpec &SS,
4738  SourceLocation IdentLoc,
4739  IdentifierInfo *NamespcName,
4740  const ParsedAttributesView &AttrList);
4741 
4742  void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
4743 
4744  Decl *ActOnNamespaceAliasDef(Scope *CurScope,
4745  SourceLocation NamespaceLoc,
4746  SourceLocation AliasLoc,
4747  IdentifierInfo *Alias,
4748  CXXScopeSpec &SS,
4749  SourceLocation IdentLoc,
4750  IdentifierInfo *Ident);
4751 
4752  void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow);
4753  bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target,
4754  const LookupResult &PreviousDecls,
4755  UsingShadowDecl *&PrevShadow);
4756  UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD,
4757  NamedDecl *Target,
4758  UsingShadowDecl *PrevDecl);
4759 
4760  bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc,
4761  bool HasTypenameKeyword,
4762  const CXXScopeSpec &SS,
4763  SourceLocation NameLoc,
4764  const LookupResult &Previous);
4765  bool CheckUsingDeclQualifier(SourceLocation UsingLoc,
4766  bool HasTypename,
4767  const CXXScopeSpec &SS,
4768  const DeclarationNameInfo &NameInfo,
4769  SourceLocation NameLoc);
4770 
4771  NamedDecl *BuildUsingDeclaration(
4772  Scope *S, AccessSpecifier AS, SourceLocation UsingLoc,
4773  bool HasTypenameKeyword, SourceLocation TypenameLoc, CXXScopeSpec &SS,
4774  DeclarationNameInfo NameInfo, SourceLocation EllipsisLoc,
4775  const ParsedAttributesView &AttrList, bool IsInstantiation);
4776  NamedDecl *BuildUsingPackDecl(NamedDecl *InstantiatedFrom,
4777  ArrayRef<NamedDecl *> Expansions);
4778 
4779  bool CheckInheritingConstructorUsingDecl(UsingDecl *UD);
4780 
4781  /// Given a derived-class using shadow declaration for a constructor and the
4782  /// correspnding base class constructor, find or create the implicit
4783  /// synthesized derived class constructor to use for this initialization.
4784  CXXConstructorDecl *
4785  findInheritingConstructor(SourceLocation Loc, CXXConstructorDecl *BaseCtor,
4786  ConstructorUsingShadowDecl *DerivedShadow);
4787 
4788  Decl *ActOnUsingDeclaration(Scope *CurScope, AccessSpecifier AS,
4789  SourceLocation UsingLoc,
4790  SourceLocation TypenameLoc, CXXScopeSpec &SS,
4791  UnqualifiedId &Name, SourceLocation EllipsisLoc,
4792  const ParsedAttributesView &AttrList);
4793  Decl *ActOnAliasDeclaration(Scope *CurScope, AccessSpecifier AS,
4794  MultiTemplateParamsArg TemplateParams,
4795  SourceLocation UsingLoc, UnqualifiedId &Name,
4796  const ParsedAttributesView &AttrList,
4797  TypeResult Type, Decl *DeclFromDeclSpec);
4798 
4799  /// BuildCXXConstructExpr - Creates a complete call to a constructor,
4800  /// including handling of its default argument expressions.
4801  ///
4802  /// \param ConstructKind - a CXXConstructExpr::ConstructionKind
4803  ExprResult
4804  BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
4805  NamedDecl *FoundDecl,
4806  CXXConstructorDecl *Constructor, MultiExprArg Exprs,
4807  bool HadMultipleCandidates, bool IsListInitialization,
4808  bool IsStdInitListInitialization,
4809  bool RequiresZeroInit, unsigned ConstructKind,
4810  SourceRange ParenRange);
4811 
4812  /// Build a CXXConstructExpr whose constructor has already been resolved if
4813  /// it denotes an inherited constructor.
4814  ExprResult
4815  BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
4816  CXXConstructorDecl *Constructor, bool Elidable,
4817  MultiExprArg Exprs,
4818  bool HadMultipleCandidates, bool IsListInitialization,
4819  bool IsStdInitListInitialization,
4820  bool RequiresZeroInit, unsigned ConstructKind,
4821  SourceRange ParenRange);
4822 
4823  // FIXME: Can we remove this and have the above BuildCXXConstructExpr check if
4824  // the constructor can be elidable?
4825  ExprResult
4826  BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
4827  NamedDecl *FoundDecl,
4828  CXXConstructorDecl *Constructor, bool Elidable,
4829  MultiExprArg Exprs, bool HadMultipleCandidates,
4830  bool IsListInitialization,
4831  bool IsStdInitListInitialization, bool RequiresZeroInit,
4832  unsigned ConstructKind, SourceRange ParenRange);
4833 
4834  ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field);
4835 
4836 
4837  /// Instantiate or parse a C++ default argument expression as necessary.
4838  /// Return true on error.
4839  bool CheckCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD,
4840  ParmVarDecl *Param);
4841 
4842  /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating
4843  /// the default expr if needed.
4844  ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc,
4845  FunctionDecl *FD,
4846  ParmVarDecl *Param);
4847 
4848  /// FinalizeVarWithDestructor - Prepare for calling destructor on the
4849  /// constructed variable.
4850  void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType);
4851 
4852  /// Helper class that collects exception specifications for
4853  /// implicitly-declared special member functions.
4855  // Pointer to allow copying
4856  Sema *Self;
4857  // We order exception specifications thus:
4858  // noexcept is the most restrictive, but is only used in C++11.
4859  // throw() comes next.
4860  // Then a throw(collected exceptions)
4861  // Finally no specification, which is expressed as noexcept(false).
4862  // throw(...) is used instead if any called function uses it.
4863  ExceptionSpecificationType ComputedEST;
4864  llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen;
4865  SmallVector<QualType, 4> Exceptions;
4866 
4867  void ClearExceptions() {
4868  ExceptionsSeen.clear();
4869  Exceptions.clear();
4870  }
4871 
4872  public:
4874  : Self(&Self), ComputedEST(EST_BasicNoexcept) {
4875  if (!Self.getLangOpts().CPlusPlus11)
4876  ComputedEST = EST_DynamicNone;
4877  }
4878 
4879  /// Get the computed exception specification type.
4881  assert(!isComputedNoexcept(ComputedEST) &&
4882  "noexcept(expr) should not be a possible result");
4883  return ComputedEST;
4884  }
4885 
4886  /// The number of exceptions in the exception specification.
4887  unsigned size() const { return Exceptions.size(); }
4888 
4889  /// The set of exceptions in the exception specification.
4890  const QualType *data() const { return Exceptions.data(); }
4891 
4892  /// Integrate another called method into the collected data.
4893  void CalledDecl(SourceLocation CallLoc, const CXXMethodDecl *Method);
4894 
4895  /// Integrate an invoked expression into the collected data.
4896  void CalledExpr(Expr *E);
4897 
4898  /// Overwrite an EPI's exception specification with this
4899  /// computed exception specification.
4902  ESI.Type = getExceptionSpecType();
4903  if (ESI.Type == EST_Dynamic) {
4904  ESI.Exceptions = Exceptions;
4905  } else if (ESI.Type == EST_None) {
4906  /// C++11 [except.spec]p14:
4907  /// The exception-specification is noexcept(false) if the set of
4908  /// potential exceptions of the special member function contains "any"
4909  ESI.Type = EST_NoexceptFalse;
4911  tok::kw_false).get();
4912  }
4913  return ESI;
4914  }
4915  };
4916 
4917  /// Determine what sort of exception specification a defaulted
4918  /// copy constructor of a class will have.
4920  ComputeDefaultedDefaultCtorExceptionSpec(SourceLocation Loc,
4921  CXXMethodDecl *MD);
4922 
4923  /// Determine what sort of exception specification a defaulted
4924  /// default constructor of a class will have, and whether the parameter
4925  /// will be const.
4927  ComputeDefaultedCopyCtorExceptionSpec(CXXMethodDecl *MD);
4928 
4929  /// Determine what sort of exception specification a defaulted
4930  /// copy assignment operator of a class will have, and whether the
4931  /// parameter will be const.
4933  ComputeDefaultedCopyAssignmentExceptionSpec(CXXMethodDecl *MD);
4934 
4935  /// Determine what sort of exception specification a defaulted move
4936  /// constructor of a class will have.
4938  ComputeDefaultedMoveCtorExceptionSpec(CXXMethodDecl *MD);
4939 
4940  /// Determine what sort of exception specification a defaulted move
4941  /// assignment operator of a class will have.
4943  ComputeDefaultedMoveAssignmentExceptionSpec(CXXMethodDecl *MD);
4944 
4945  /// Determine what sort of exception specification a defaulted
4946  /// destructor of a class will have.
4948  ComputeDefaultedDtorExceptionSpec(CXXMethodDecl *MD);
4949 
4950  /// Determine what sort of exception specification an inheriting
4951  /// constructor of a class will have.
4953  ComputeInheritingCtorExceptionSpec(SourceLocation Loc,
4954  CXXConstructorDecl *CD);
4955 
4956  /// Evaluate the implicit exception specification for a defaulted
4957  /// special member function.
4958  void EvaluateImplicitExceptionSpec(SourceLocation Loc, CXXMethodDecl *MD);
4959 
4960  /// Check the given noexcept-specifier, convert its expression, and compute
4961  /// the appropriate ExceptionSpecificationType.
4962  ExprResult ActOnNoexceptSpec(SourceLocation NoexceptLoc, Expr *NoexceptExpr,
4964 
4965  /// Check the given exception-specification and update the
4966  /// exception specification information with the results.
4967  void checkExceptionSpecification(bool IsTopLevel,
4969  ArrayRef<ParsedType> DynamicExceptions,
4970  ArrayRef<SourceRange> DynamicExceptionRanges,
4971  Expr *NoexceptExpr,
4972  SmallVectorImpl<QualType> &Exceptions,
4974 
4975  /// Determine if we're in a case where we need to (incorrectly) eagerly
4976  /// parse an exception specification to work around a libstdc++ bug.
4977  bool isLibstdcxxEagerExceptionSpecHack(const Declarator &D);
4978 
4979  /// Add an exception-specification to the given member function
4980  /// (or member function template). The exception-specification was parsed
4981  /// after the method itself was declared.
4982  void actOnDelayedExceptionSpecification(Decl *Method,
4984  SourceRange SpecificationRange,
4985  ArrayRef<ParsedType> DynamicExceptions,
4986  ArrayRef<SourceRange> DynamicExceptionRanges,
4987  Expr *NoexceptExpr);
4988 
4990 
4991  /// Determine if a special member function should have a deleted
4992  /// definition when it is defaulted.
4993  bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM,
4994  InheritedConstructorInfo *ICI = nullptr,
4995  bool Diagnose = false);
4996 
4997  /// Declare the implicit default constructor for the given class.
4998  ///
4999  /// \param ClassDecl The class declaration into which the implicit
5000  /// default constructor will be added.
5001  ///
5002  /// \returns The implicitly-declared default constructor.
5003  CXXConstructorDecl *DeclareImplicitDefaultConstructor(
5004  CXXRecordDecl *ClassDecl);
5005 
5006  /// DefineImplicitDefaultConstructor - Checks for feasibility of
5007  /// defining this constructor as the default constructor.
5008  void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
5009  CXXConstructorDecl *Constructor);
5010 
5011  /// Declare the implicit destructor for the given class.
5012  ///
5013  /// \param ClassDecl The class declaration into which the implicit
5014  /// destructor will be added.
5015  ///
5016  /// \returns The implicitly-declared destructor.
5017  CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl);
5018 
5019  /// DefineImplicitDestructor - Checks for feasibility of
5020  /// defining this destructor as the default destructor.
5021  void DefineImplicitDestructor(SourceLocation CurrentLocation,
5022  CXXDestructorDecl *Destructor);
5023 
5024  /// Build an exception spec for destructors that don't have one.
5025  ///
5026  /// C++11 says that user-defined destructors with no exception spec get one
5027  /// that looks as if the destructor was implicitly declared.
5028  void AdjustDestructorExceptionSpec(CXXDestructorDecl *Destructor);
5029 
5030  /// Define the specified inheriting constructor.
5031  void DefineInheritingConstructor(SourceLocation UseLoc,
5032  CXXConstructorDecl *Constructor);
5033 
5034  /// Declare the implicit copy constructor for the given class.
5035  ///
5036  /// \param ClassDecl The class declaration into which the implicit
5037  /// copy constructor will be added.
5038  ///
5039  /// \returns The implicitly-declared copy constructor.
5040  CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl);
5041 
5042  /// DefineImplicitCopyConstructor - Checks for feasibility of
5043  /// defining this constructor as the copy constructor.
5044  void DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
5045  CXXConstructorDecl *Constructor);
5046 
5047  /// Declare the implicit move constructor for the given class.
5048  ///
5049  /// \param ClassDecl The Class declaration into which the implicit
5050  /// move constructor will be added.
5051  ///
5052  /// \returns The implicitly-declared move constructor, or NULL if it wasn't
5053  /// declared.
5054  CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl);
5055 
5056  /// DefineImplicitMoveConstructor - Checks for feasibility of
5057  /// defining this constructor as the move constructor.
5058  void DefineImplicitMoveConstructor(SourceLocation CurrentLocation,
5059  CXXConstructorDecl *Constructor);
5060 
5061  /// Declare the implicit copy assignment operator for the given class.
5062  ///
5063  /// \param ClassDecl The class declaration into which the implicit
5064  /// copy assignment operator will be added.
5065  ///
5066  /// \returns The implicitly-declared copy assignment operator.
5067  CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl);
5068 
5069  /// Defines an implicitly-declared copy assignment operator.
5070  void DefineImplicitCopyAssignment(SourceLocation CurrentLocation,
5071  CXXMethodDecl *MethodDecl);
5072 
5073  /// Declare the implicit move assignment operator for the given class.
5074  ///
5075  /// \param ClassDecl The Class declaration into which the implicit
5076  /// move assignment operator will be added.
5077  ///
5078  /// \returns The implicitly-declared move assignment operator, or NULL if it
5079  /// wasn't declared.
5080  CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl);
5081 
5082  /// Defines an implicitly-declared move assignment operator.
5083  void DefineImplicitMoveAssignment(SourceLocation CurrentLocation,
5084  CXXMethodDecl *MethodDecl);
5085 
5086  /// Force the declaration of any implicitly-declared members of this
5087  /// class.
5088  void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class);
5089 
5090  /// Check a completed declaration of an implicit special member.
5091  void CheckImplicitSpecialMemberDeclaration(Scope *S, FunctionDecl *FD);
5092 
5093  /// Determine whether the given function is an implicitly-deleted
5094  /// special member function.
5095  bool isImplicitlyDeleted(FunctionDecl *FD);
5096 
5097  /// Check whether 'this' shows up in the type of a static member
5098  /// function after the (naturally empty) cv-qualifier-seq would be.
5099  ///
5100  /// \returns true if an error occurred.
5101  bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method);
5102 
5103  /// Whether this' shows up in the exception specification of a static
5104  /// member function.
5105  bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method);
5106 
5107  /// Check whether 'this' shows up in the attributes of the given
5108  /// static member function.
5109  ///
5110  /// \returns true if an error occurred.
5111  bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method);
5112 
5113  /// MaybeBindToTemporary - If the passed in expression has a record type with
5114  /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise
5115  /// it simply returns the passed in expression.
5116  ExprResult MaybeBindToTemporary(Expr *E);
5117 
5118  bool CompleteConstructorCall(CXXConstructorDecl *Constructor,
5119  MultiExprArg ArgsPtr,
5120  SourceLocation Loc,
5121  SmallVectorImpl<Expr*> &ConvertedArgs,
5122  bool AllowExplicit = false,
5123  bool IsListInitialization = false);
5124 
5125  ParsedType getInheritingConstructorName(CXXScopeSpec &SS,
5126  SourceLocation NameLoc,
5127  IdentifierInfo &Name);
5128 
5129  ParsedType getConstructorName(IdentifierInfo &II, SourceLocation NameLoc,
5130  Scope *S, CXXScopeSpec &SS,
5131  bool EnteringContext);
5132  ParsedType getDestructorName(SourceLocation TildeLoc,
5133  IdentifierInfo &II, SourceLocation NameLoc,
5134  Scope *S, CXXScopeSpec &SS,
5135  ParsedType ObjectType,
5136  bool EnteringContext);
5137 
5138  ParsedType getDestructorTypeForDecltype(const DeclSpec &DS,
5139  ParsedType ObjectType);
5140 
5141  // Checks that reinterpret casts don't have undefined behavior.
5142  void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType,
5143  bool IsDereference, SourceRange Range);
5144 
5145  /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
5146  ExprResult ActOnCXXNamedCast(SourceLocation OpLoc,
5148  SourceLocation LAngleBracketLoc,
5149  Declarator &D,