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