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