clang  3.8.0
Initialization.h
Go to the documentation of this file.
1 //===--- Initialization.h - Semantic Analysis for Initializers --*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file provides supporting data types for initialization of objects.
11 //
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_SEMA_INITIALIZATION_H
14 #define LLVM_CLANG_SEMA_INITIALIZATION_H
15 
16 #include "clang/AST/ASTContext.h"
17 #include "clang/AST/Attr.h"
18 #include "clang/AST/Type.h"
21 #include "clang/Sema/Overload.h"
22 #include "clang/Sema/Ownership.h"
23 #include "llvm/ADT/PointerIntPair.h"
24 #include "llvm/ADT/SmallVector.h"
25 #include <cassert>
26 
27 namespace clang {
28 
29 class CXXBaseSpecifier;
30 class DeclaratorDecl;
31 class DeclaratorInfo;
32 class FieldDecl;
33 class FunctionDecl;
34 class ParmVarDecl;
35 class Sema;
36 class TypeLoc;
37 class VarDecl;
38 class ObjCMethodDecl;
39 
40 /// \brief Describes an entity that is being initialized.
42 public:
43  /// \brief Specifies the kind of entity being initialized.
44  enum EntityKind {
45  /// \brief The entity being initialized is a variable.
47  /// \brief The entity being initialized is a function parameter.
49  /// \brief The entity being initialized is the result of a function call.
51  /// \brief The entity being initialized is an exception object that
52  /// is being thrown.
54  /// \brief The entity being initialized is a non-static data member
55  /// subobject.
57  /// \brief The entity being initialized is an element of an array.
59  /// \brief The entity being initialized is an object (or array of
60  /// objects) allocated via new.
62  /// \brief The entity being initialized is a temporary object.
64  /// \brief The entity being initialized is a base member subobject.
66  /// \brief The initialization is being done by a delegating constructor.
68  /// \brief The entity being initialized is an element of a vector.
69  /// or vector.
71  /// \brief The entity being initialized is a field of block descriptor for
72  /// the copied-in c++ object.
74  /// \brief The entity being initialized is the real or imaginary part of a
75  /// complex number.
77  /// \brief The entity being initialized is the field that captures a
78  /// variable in a lambda.
80  /// \brief The entity being initialized is the initializer for a compound
81  /// literal.
83  /// \brief The entity being implicitly initialized back to the formal
84  /// result type.
86  /// \brief The entity being initialized is a function parameter; function
87  /// is member of group of audited CF APIs.
89 
90  // Note: err_init_conversion_failed in DiagnosticSemaKinds.td uses this
91  // enum as an index for its first %select. When modifying this list,
92  // that diagnostic text needs to be updated as well.
93  };
94 
95 private:
96  /// \brief The kind of entity being initialized.
98 
99  /// \brief If non-NULL, the parent entity in which this
100  /// initialization occurs.
101  const InitializedEntity *Parent;
102 
103  /// \brief The type of the object or reference being initialized.
104  QualType Type;
105 
106  /// \brief The mangling number for the next reference temporary to be created.
107  mutable unsigned ManglingNumber;
108 
109  struct LN {
110  /// \brief When Kind == EK_Result, EK_Exception, EK_New, the
111  /// location of the 'return', 'throw', or 'new' keyword,
112  /// respectively. When Kind == EK_Temporary, the location where
113  /// the temporary is being created.
114  unsigned Location;
115 
116  /// \brief Whether the entity being initialized may end up using the
117  /// named return value optimization (NRVO).
118  bool NRVO;
119  };
120 
121  struct C {
122  /// \brief The name of the variable being captured by an EK_LambdaCapture.
123  IdentifierInfo *VarID;
124 
125  /// \brief The source location at which the capture occurs.
126  unsigned Location;
127  };
128 
129  union {
130  /// \brief When Kind == EK_Variable, or EK_Member, the VarDecl or
131  /// FieldDecl, respectively.
133 
134  /// \brief When Kind == EK_RelatedResult, the ObjectiveC method where
135  /// result type was implicitly changed to accommodate ARC semantics.
137 
138  /// \brief When Kind == EK_Parameter, the ParmVarDecl, with the
139  /// low bit indicating whether the parameter is "consumed".
140  uintptr_t Parameter;
141 
142  /// \brief When Kind == EK_Temporary or EK_CompoundLiteralInit, the type
143  /// source information for the temporary.
145 
146  struct LN LocAndNRVO;
147 
148  /// \brief When Kind == EK_Base, the base specifier that provides the
149  /// base class. The lower bit specifies whether the base is an inherited
150  /// virtual base.
151  uintptr_t Base;
152 
153  /// \brief When Kind == EK_ArrayElement, EK_VectorElement, or
154  /// EK_ComplexElement, the index of the array or vector element being
155  /// initialized.
156  unsigned Index;
157 
158  struct C Capture;
159  };
160 
161  InitializedEntity() : ManglingNumber(0) {}
162 
163  /// \brief Create the initialization entity for a variable.
164  InitializedEntity(VarDecl *Var)
165  : Kind(EK_Variable), Parent(nullptr), Type(Var->getType()),
166  ManglingNumber(0), VariableOrMember(Var) { }
167 
168  /// \brief Create the initialization entity for the result of a
169  /// function, throwing an object, performing an explicit cast, or
170  /// initializing a parameter for which there is no declaration.
171  InitializedEntity(EntityKind Kind, SourceLocation Loc, QualType Type,
172  bool NRVO = false)
173  : Kind(Kind), Parent(nullptr), Type(Type), ManglingNumber(0)
174  {
175  LocAndNRVO.Location = Loc.getRawEncoding();
176  LocAndNRVO.NRVO = NRVO;
177  }
178 
179  /// \brief Create the initialization entity for a member subobject.
180  InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent)
181  : Kind(EK_Member), Parent(Parent), Type(Member->getType()),
182  ManglingNumber(0), VariableOrMember(Member) { }
183 
184  /// \brief Create the initialization entity for an array element.
185  InitializedEntity(ASTContext &Context, unsigned Index,
186  const InitializedEntity &Parent);
187 
188  /// \brief Create the initialization entity for a lambda capture.
189  InitializedEntity(IdentifierInfo *VarID, QualType FieldType, SourceLocation Loc)
190  : Kind(EK_LambdaCapture), Parent(nullptr), Type(FieldType),
191  ManglingNumber(0)
192  {
193  Capture.VarID = VarID;
194  Capture.Location = Loc.getRawEncoding();
195  }
196 
197 public:
198  /// \brief Create the initialization entity for a variable.
200  return InitializedEntity(Var);
201  }
202 
203  /// \brief Create the initialization entity for a parameter.
205  ParmVarDecl *Parm) {
206  return InitializeParameter(Context, Parm, Parm->getType());
207  }
208 
209  /// \brief Create the initialization entity for a parameter, but use
210  /// another type.
212  ParmVarDecl *Parm,
213  QualType Type) {
214  bool Consumed = (Context.getLangOpts().ObjCAutoRefCount &&
215  Parm->hasAttr<NSConsumedAttr>());
216 
217  InitializedEntity Entity;
218  Entity.Kind = EK_Parameter;
219  Entity.Type =
221  Entity.Parent = nullptr;
222  Entity.Parameter
223  = (static_cast<uintptr_t>(Consumed) | reinterpret_cast<uintptr_t>(Parm));
224  return Entity;
225  }
226 
227  /// \brief Create the initialization entity for a parameter that is
228  /// only known by its type.
230  QualType Type,
231  bool Consumed) {
232  InitializedEntity Entity;
233  Entity.Kind = EK_Parameter;
234  Entity.Type = Context.getVariableArrayDecayedType(Type);
235  Entity.Parent = nullptr;
236  Entity.Parameter = (Consumed);
237  return Entity;
238  }
239 
240  /// \brief Create the initialization entity for the result of a function.
242  QualType Type, bool NRVO) {
243  return InitializedEntity(EK_Result, ReturnLoc, Type, NRVO);
244  }
245 
247  QualType Type, bool NRVO) {
248  return InitializedEntity(EK_BlockElement, BlockVarLoc, Type, NRVO);
249  }
250 
251  /// \brief Create the initialization entity for an exception object.
253  QualType Type, bool NRVO) {
254  return InitializedEntity(EK_Exception, ThrowLoc, Type, NRVO);
255  }
256 
257  /// \brief Create the initialization entity for an object allocated via new.
259  return InitializedEntity(EK_New, NewLoc, Type);
260  }
261 
262  /// \brief Create the initialization entity for a temporary.
265  Result.TypeInfo = nullptr;
266  return Result;
267  }
268 
269  /// \brief Create the initialization entity for a temporary.
272  TypeInfo->getType());
273  Result.TypeInfo = TypeInfo;
274  return Result;
275  }
276 
277  /// \brief Create the initialization entity for a related result.
279  QualType Type) {
281  Result.MethodDecl = MD;
282  return Result;
283  }
284 
285 
286  /// \brief Create the initialization entity for a base class subobject.
288  const CXXBaseSpecifier *Base,
289  bool IsInheritedVirtualBase);
290 
291  /// \brief Create the initialization entity for a delegated constructor.
294  }
295 
296  /// \brief Create the initialization entity for a member subobject.
297  static InitializedEntity
299  const InitializedEntity *Parent = nullptr) {
300  return InitializedEntity(Member, Parent);
301  }
302 
303  /// \brief Create the initialization entity for a member subobject.
304  static InitializedEntity
306  const InitializedEntity *Parent = nullptr) {
307  return InitializedEntity(Member->getAnonField(), Parent);
308  }
309 
310  /// \brief Create the initialization entity for an array element.
312  unsigned Index,
313  const InitializedEntity &Parent) {
314  return InitializedEntity(Context, Index, Parent);
315  }
316 
317  /// \brief Create the initialization entity for a lambda capture.
319  QualType FieldType,
320  SourceLocation Loc) {
321  return InitializedEntity(VarID, FieldType, Loc);
322  }
323 
324  /// \brief Create the entity for a compound literal initializer.
327  TSI->getType());
328  Result.TypeInfo = TSI;
329  return Result;
330  }
331 
332 
333  /// \brief Determine the kind of initialization.
334  EntityKind getKind() const { return Kind; }
335 
336  /// \brief Retrieve the parent of the entity being initialized, when
337  /// the initialization itself is occurring within the context of a
338  /// larger initialization.
339  const InitializedEntity *getParent() const { return Parent; }
340 
341  /// \brief Retrieve type being initialized.
342  QualType getType() const { return Type; }
343 
344  /// \brief Retrieve complete type-source information for the object being
345  /// constructed, if known.
347  if (Kind == EK_Temporary || Kind == EK_CompoundLiteralInit)
348  return TypeInfo;
349 
350  return nullptr;
351  }
352 
353  /// \brief Retrieve the name of the entity being initialized.
354  DeclarationName getName() const;
355 
356  /// \brief Retrieve the variable, parameter, or field being
357  /// initialized.
358  DeclaratorDecl *getDecl() const;
359 
360  /// \brief Retrieve the ObjectiveC method being initialized.
362 
363  /// \brief Determine whether this initialization allows the named return
364  /// value optimization, which also applies to thrown objects.
365  bool allowsNRVO() const;
366 
367  bool isParameterKind() const {
368  return (getKind() == EK_Parameter ||
370  }
371  /// \brief Determine whether this initialization consumes the
372  /// parameter.
373  bool isParameterConsumed() const {
374  assert(isParameterKind() && "Not a parameter");
375  return (Parameter & 1);
376  }
377 
378  /// \brief Retrieve the base specifier.
380  assert(getKind() == EK_Base && "Not a base specifier");
381  return reinterpret_cast<const CXXBaseSpecifier *>(Base & ~0x1);
382  }
383 
384  /// \brief Return whether the base is an inherited virtual base.
385  bool isInheritedVirtualBase() const {
386  assert(getKind() == EK_Base && "Not a base specifier");
387  return Base & 0x1;
388  }
389 
390  /// \brief Determine the location of the 'return' keyword when initializing
391  /// the result of a function call.
393  assert(getKind() == EK_Result && "No 'return' location!");
395  }
396 
397  /// \brief Determine the location of the 'throw' keyword when initializing
398  /// an exception object.
400  assert(getKind() == EK_Exception && "No 'throw' location!");
402  }
403 
404  /// \brief If this is an array, vector, or complex number element, get the
405  /// element's index.
406  unsigned getElementIndex() const {
407  assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
409  return Index;
410  }
411  /// \brief If this is already the initializer for an array or vector
412  /// element, sets the element index.
413  void setElementIndex(unsigned Index) {
414  assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
416  this->Index = Index;
417  }
418  /// \brief For a lambda capture, return the capture's name.
419  StringRef getCapturedVarName() const {
420  assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
421  return Capture.VarID->getName();
422  }
423  /// \brief Determine the location of the capture when initializing
424  /// field from a captured variable in a lambda.
426  assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
428  }
429 
432  }
433 
434  unsigned allocateManglingNumber() const { return ++ManglingNumber; }
435 
436  /// Dump a representation of the initialized entity to standard error,
437  /// for debugging purposes.
438  void dump() const;
439 
440 private:
441  unsigned dumpImpl(raw_ostream &OS) const;
442 };
443 
444 /// \brief Describes the kind of initialization being performed, along with
445 /// location information for tokens related to the initialization (equal sign,
446 /// parentheses).
448 public:
449  /// \brief The kind of initialization being performed.
450  enum InitKind {
451  IK_Direct, ///< Direct initialization
452  IK_DirectList, ///< Direct list-initialization
453  IK_Copy, ///< Copy initialization
454  IK_Default, ///< Default initialization
455  IK_Value ///< Value initialization
456  };
457 
458 private:
459  /// \brief The context of the initialization.
460  enum InitContext {
461  IC_Normal, ///< Normal context
462  IC_ExplicitConvs, ///< Normal context, but allows explicit conversion funcs
463  IC_Implicit, ///< Implicit context (value initialization)
464  IC_StaticCast, ///< Static cast context
465  IC_CStyleCast, ///< C-style cast context
466  IC_FunctionalCast ///< Functional cast context
467  };
468 
469  /// \brief The kind of initialization being performed.
470  InitKind Kind : 8;
471 
472  /// \brief The context of the initialization.
473  InitContext Context : 8;
474 
475  /// \brief The source locations involved in the initialization.
476  SourceLocation Locations[3];
477 
478  InitializationKind(InitKind Kind, InitContext Context, SourceLocation Loc1,
479  SourceLocation Loc2, SourceLocation Loc3)
480  : Kind(Kind), Context(Context)
481  {
482  Locations[0] = Loc1;
483  Locations[1] = Loc2;
484  Locations[2] = Loc3;
485  }
486 
487 public:
488  /// \brief Create a direct initialization.
490  SourceLocation LParenLoc,
491  SourceLocation RParenLoc) {
492  return InitializationKind(IK_Direct, IC_Normal,
493  InitLoc, LParenLoc, RParenLoc);
494  }
495 
497  return InitializationKind(IK_DirectList, IC_Normal,
498  InitLoc, InitLoc, InitLoc);
499  }
500 
501  /// \brief Create a direct initialization due to a cast that isn't a C-style
502  /// or functional cast.
504  return InitializationKind(IK_Direct, IC_StaticCast, TypeRange.getBegin(),
505  TypeRange.getBegin(), TypeRange.getEnd());
506  }
507 
508  /// \brief Create a direct initialization for a C-style cast.
510  SourceRange TypeRange,
511  bool InitList) {
512  // C++ cast syntax doesn't permit init lists, but C compound literals are
513  // exactly that.
514  return InitializationKind(InitList ? IK_DirectList : IK_Direct,
515  IC_CStyleCast, StartLoc, TypeRange.getBegin(),
516  TypeRange.getEnd());
517  }
518 
519  /// \brief Create a direct initialization for a functional cast.
521  bool InitList) {
522  return InitializationKind(InitList ? IK_DirectList : IK_Direct,
523  IC_FunctionalCast, TypeRange.getBegin(),
524  TypeRange.getBegin(), TypeRange.getEnd());
525  }
526 
527  /// \brief Create a copy initialization.
529  SourceLocation EqualLoc,
530  bool AllowExplicitConvs = false) {
531  return InitializationKind(IK_Copy,
532  AllowExplicitConvs? IC_ExplicitConvs : IC_Normal,
533  InitLoc, EqualLoc, EqualLoc);
534  }
535 
536  /// \brief Create a default initialization.
538  return InitializationKind(IK_Default, IC_Normal, InitLoc, InitLoc, InitLoc);
539  }
540 
541  /// \brief Create a value initialization.
543  SourceLocation LParenLoc,
544  SourceLocation RParenLoc,
545  bool isImplicit = false) {
546  return InitializationKind(IK_Value, isImplicit ? IC_Implicit : IC_Normal,
547  InitLoc, LParenLoc, RParenLoc);
548  }
549 
550  /// \brief Determine the initialization kind.
551  InitKind getKind() const {
552  return Kind;
553  }
554 
555  /// \brief Determine whether this initialization is an explicit cast.
556  bool isExplicitCast() const {
557  return Context >= IC_StaticCast;
558  }
559 
560  /// \brief Determine whether this initialization is a C-style cast.
561  bool isCStyleOrFunctionalCast() const {
562  return Context >= IC_CStyleCast;
563  }
564 
565  /// \brief Determine whether this is a C-style cast.
566  bool isCStyleCast() const {
567  return Context == IC_CStyleCast;
568  }
569 
570  /// \brief Determine whether this is a functional-style cast.
571  bool isFunctionalCast() const {
572  return Context == IC_FunctionalCast;
573  }
574 
575  /// \brief Determine whether this initialization is an implicit
576  /// value-initialization, e.g., as occurs during aggregate
577  /// initialization.
578  bool isImplicitValueInit() const { return Context == IC_Implicit; }
579 
580  /// \brief Retrieve the location at which initialization is occurring.
581  SourceLocation getLocation() const { return Locations[0]; }
582 
583  /// \brief Retrieve the source range that covers the initialization.
585  return SourceRange(Locations[0], Locations[2]);
586  }
587 
588  /// \brief Retrieve the location of the equal sign for copy initialization
589  /// (if present).
591  assert(Kind == IK_Copy && "Only copy initialization has an '='");
592  return Locations[1];
593  }
594 
595  bool isCopyInit() const { return Kind == IK_Copy; }
596 
597  /// \brief Retrieve whether this initialization allows the use of explicit
598  /// constructors.
599  bool AllowExplicit() const { return !isCopyInit(); }
600 
601  /// \brief Retrieve whether this initialization allows the use of explicit
602  /// conversion functions when binding a reference. If the reference is the
603  /// first parameter in a copy or move constructor, such conversions are
604  /// permitted even though we are performing copy-initialization.
606  return !isCopyInit() || Context == IC_ExplicitConvs;
607  }
608 
609  /// \brief Retrieve the source range containing the locations of the open
610  /// and closing parentheses for value and direct initializations.
612  assert((Kind == IK_Direct || Kind == IK_Value) &&
613  "Only direct- and value-initialization have parentheses");
614  return SourceRange(Locations[1], Locations[2]);
615  }
616 };
617 
618 /// \brief Describes the sequence of initializations required to initialize
619 /// a given object or reference with a set of arguments.
621 public:
622  /// \brief Describes the kind of initialization sequence computed.
624  /// \brief A failed initialization sequence. The failure kind tells what
625  /// happened.
627 
628  /// \brief A dependent initialization, which could not be
629  /// type-checked due to the presence of dependent types or
630  /// dependently-typed expressions.
632 
633  /// \brief A normal sequence.
635  };
636 
637  /// \brief Describes the kind of a particular step in an initialization
638  /// sequence.
639  enum StepKind {
640  /// \brief Resolve the address of an overloaded function to a specific
641  /// function declaration.
643  /// \brief Perform a derived-to-base cast, producing an rvalue.
645  /// \brief Perform a derived-to-base cast, producing an xvalue.
647  /// \brief Perform a derived-to-base cast, producing an lvalue.
649  /// \brief Reference binding to an lvalue.
651  /// \brief Reference binding to a temporary.
653  /// \brief An optional copy of a temporary object to another
654  /// temporary object, which is permitted (but not required) by
655  /// C++98/03 but not C++0x.
657  /// \brief Perform a user-defined conversion, either via a conversion
658  /// function or via a constructor.
660  /// \brief Perform a qualification conversion, producing an rvalue.
662  /// \brief Perform a qualification conversion, producing an xvalue.
664  /// \brief Perform a qualification conversion, producing an lvalue.
666  /// \brief Perform a conversion adding _Atomic to a type.
668  /// \brief Perform a load from a glvalue, producing an rvalue.
670  /// \brief Perform an implicit conversion sequence.
672  /// \brief Perform an implicit conversion sequence without narrowing.
674  /// \brief Perform list-initialization without a constructor.
676  /// \brief Unwrap the single-element initializer list for a reference.
678  /// \brief Rewrap the single-element initializer list for a reference.
680  /// \brief Perform initialization via a constructor.
682  /// \brief Perform initialization via a constructor, taking arguments from
683  /// a single InitListExpr.
685  /// \brief Zero-initialize the object
687  /// \brief C assignment
689  /// \brief Initialization by string
691  /// \brief An initialization that "converts" an Objective-C object
692  /// (not a point to an object) to another Objective-C object type.
694  /// \brief Array initialization (from an array rvalue).
695  /// This is a GNU C extension.
697  /// \brief Array initialization from a parenthesized initializer list.
698  /// This is a GNU C++ extension.
700  /// \brief Pass an object by indirect copy-and-restore.
702  /// \brief Pass an object by indirect restore.
704  /// \brief Produce an Objective-C object pointer.
706  /// \brief Construct a std::initializer_list from an initializer list.
708  /// \brief Perform initialization via a constructor taking a single
709  /// std::initializer_list argument.
711  /// \brief Initialize an OpenCL sampler from an integer.
713  /// \brief Passing zero to a function where OpenCL event_t is expected.
715  };
716 
717  /// \brief A single step in the initialization sequence.
718  class Step {
719  public:
720  /// \brief The kind of conversion or initialization step we are taking.
722 
723  // \brief The type that results from this initialization.
725 
726  struct F {
730  };
731 
732  union {
733  /// \brief When Kind == SK_ResolvedOverloadedFunction or Kind ==
734  /// SK_UserConversion, the function that the expression should be
735  /// resolved to or the conversion function to call, respectively.
736  /// When Kind == SK_ConstructorInitialization or SK_ListConstruction,
737  /// the constructor to be called.
738  ///
739  /// Always a FunctionDecl, plus a Boolean flag telling if it was
740  /// selected from an overloaded set having size greater than 1.
741  /// For conversion decls, the naming class is the source type.
742  /// For construct decls, the naming class is the target type.
743  struct F Function;
744 
745  /// \brief When Kind = SK_ConversionSequence, the implicit conversion
746  /// sequence.
748 
749  /// \brief When Kind = SK_RewrapInitList, the syntactic form of the
750  /// wrapping list.
752  };
753 
754  void Destroy();
755  };
756 
757 private:
758  /// \brief The kind of initialization sequence computed.
760 
761  /// \brief Steps taken by this initialization.
762  SmallVector<Step, 4> Steps;
763 
764 public:
765  /// \brief Describes why initialization failed.
766  enum FailureKind {
767  /// \brief Too many initializers provided for a reference.
769  /// \brief Array must be initialized with an initializer list.
771  /// \brief Array must be initialized with an initializer list or a
772  /// string literal.
774  /// \brief Array must be initialized with an initializer list or a
775  /// wide string literal.
777  /// \brief Initializing a wide char array with narrow string literal.
779  /// \brief Initializing char array with wide string literal.
781  /// \brief Initializing wide char array with incompatible wide string
782  /// literal.
784  /// \brief Array type mismatch.
786  /// \brief Non-constant array initializer
788  /// \brief Cannot resolve the address of an overloaded function.
790  /// \brief Overloading due to reference initialization failed.
792  /// \brief Non-const lvalue reference binding to a temporary.
794  /// \brief Non-const lvalue reference binding to an lvalue of unrelated
795  /// type.
797  /// \brief Rvalue reference binding to an lvalue.
799  /// \brief Reference binding drops qualifiers.
801  /// \brief Reference binding failed.
803  /// \brief Implicit conversion failed.
805  /// \brief Implicit conversion failed.
807  /// \brief Too many initializers for scalar
809  /// \brief Reference initialization from an initializer list
811  /// \brief Initialization of some unused destination type with an
812  /// initializer list.
814  /// \brief Overloading for a user-defined conversion failed.
816  /// \brief Overloading for initialization by constructor failed.
818  /// \brief Overloading for list-initialization by constructor failed.
820  /// \brief Default-initialization of a 'const' object.
822  /// \brief Initialization of an incomplete type.
824  /// \brief Variable-length array must not have an initializer.
826  /// \brief List initialization failed at some point.
828  /// \brief Initializer has a placeholder type which cannot be
829  /// resolved by initialization.
831  /// \brief Trying to take the address of a function that doesn't support
832  /// having its address taken.
834  /// \brief List-copy-initialization chose an explicit constructor.
836  };
837 
838 private:
839  /// \brief The reason why initialization failed.
840  FailureKind Failure;
841 
842  /// \brief The failed result of overload resolution.
843  OverloadingResult FailedOverloadResult;
844 
845  /// \brief The candidate set created when initialization failed.
846  OverloadCandidateSet FailedCandidateSet;
847 
848  /// \brief The incomplete type that caused a failure.
849  QualType FailedIncompleteType;
850 
851  /// \brief The fixit that needs to be applied to make this initialization
852  /// succeed.
853  std::string ZeroInitializationFixit;
854  SourceLocation ZeroInitializationFixitLoc;
855 
856 public:
857  /// \brief Call for initializations are invalid but that would be valid
858  /// zero initialzations if Fixit was applied.
859  void SetZeroInitializationFixit(const std::string& Fixit, SourceLocation L) {
860  ZeroInitializationFixit = Fixit;
861  ZeroInitializationFixitLoc = L;
862  }
863 
864 private:
865 
866  /// \brief Prints a follow-up note that highlights the location of
867  /// the initialized entity, if it's remote.
868  void PrintInitLocationNote(Sema &S, const InitializedEntity &Entity);
869 
870 public:
871  /// \brief Try to perform initialization of the given entity, creating a
872  /// record of the steps required to perform the initialization.
873  ///
874  /// The generated initialization sequence will either contain enough
875  /// information to diagnose
876  ///
877  /// \param S the semantic analysis object.
878  ///
879  /// \param Entity the entity being initialized.
880  ///
881  /// \param Kind the kind of initialization being performed.
882  ///
883  /// \param Args the argument(s) provided for initialization.
884  ///
885  /// \param TopLevelOfInitList true if we are initializing from an expression
886  /// at the top level inside an initializer list. This disallows
887  /// narrowing conversions in C++11 onwards.
889  const InitializedEntity &Entity,
890  const InitializationKind &Kind,
891  MultiExprArg Args,
892  bool TopLevelOfInitList = false);
893  void InitializeFrom(Sema &S, const InitializedEntity &Entity,
894  const InitializationKind &Kind, MultiExprArg Args,
895  bool TopLevelOfInitList);
896 
898 
899  /// \brief Perform the actual initialization of the given entity based on
900  /// the computed initialization sequence.
901  ///
902  /// \param S the semantic analysis object.
903  ///
904  /// \param Entity the entity being initialized.
905  ///
906  /// \param Kind the kind of initialization being performed.
907  ///
908  /// \param Args the argument(s) provided for initialization, ownership of
909  /// which is transferred into the routine.
910  ///
911  /// \param ResultType if non-NULL, will be set to the type of the
912  /// initialized object, which is the type of the declaration in most
913  /// cases. However, when the initialized object is a variable of
914  /// incomplete array type and the initializer is an initializer
915  /// list, this type will be set to the completed array type.
916  ///
917  /// \returns an expression that performs the actual object initialization, if
918  /// the initialization is well-formed. Otherwise, emits diagnostics
919  /// and returns an invalid expression.
921  const InitializedEntity &Entity,
922  const InitializationKind &Kind,
923  MultiExprArg Args,
924  QualType *ResultType = nullptr);
925 
926  /// \brief Diagnose an potentially-invalid initialization sequence.
927  ///
928  /// \returns true if the initialization sequence was ill-formed,
929  /// false otherwise.
930  bool Diagnose(Sema &S,
931  const InitializedEntity &Entity,
932  const InitializationKind &Kind,
933  ArrayRef<Expr *> Args);
934 
935  /// \brief Determine the kind of initialization sequence computed.
936  enum SequenceKind getKind() const { return SequenceKind; }
937 
938  /// \brief Set the kind of sequence computed.
939  void setSequenceKind(enum SequenceKind SK) { SequenceKind = SK; }
940 
941  /// \brief Determine whether the initialization sequence is valid.
942  explicit operator bool() const { return !Failed(); }
943 
944  /// \brief Determine whether the initialization sequence is invalid.
945  bool Failed() const { return SequenceKind == FailedSequence; }
946 
948  step_iterator step_begin() const { return Steps.begin(); }
949  step_iterator step_end() const { return Steps.end(); }
950 
951  /// \brief Determine whether this initialization is a direct reference
952  /// binding (C++ [dcl.init.ref]).
953  bool isDirectReferenceBinding() const;
954 
955  /// \brief Determine whether this initialization failed due to an ambiguity.
956  bool isAmbiguous() const;
957 
958  /// \brief Determine whether this initialization is direct call to a
959  /// constructor.
960  bool isConstructorInitialization() const;
961 
962  /// \brief Returns whether the last step in this initialization sequence is a
963  /// narrowing conversion, defined by C++0x [dcl.init.list]p7.
964  ///
965  /// If this function returns true, *isInitializerConstant will be set to
966  /// describe whether *Initializer was a constant expression. If
967  /// *isInitializerConstant is set to true, *ConstantValue will be set to the
968  /// evaluated value of *Initializer.
969  bool endsWithNarrowing(ASTContext &Ctx, const Expr *Initializer,
970  bool *isInitializerConstant,
971  APValue *ConstantValue) const;
972 
973  /// \brief Add a new step in the initialization that resolves the address
974  /// of an overloaded function to a specific function declaration.
975  ///
976  /// \param Function the function to which the overloaded function reference
977  /// resolves.
979  DeclAccessPair Found,
980  bool HadMultipleCandidates);
981 
982  /// \brief Add a new step in the initialization that performs a derived-to-
983  /// base cast.
984  ///
985  /// \param BaseType the base type to which we will be casting.
986  ///
987  /// \param Category Indicates whether the result will be treated as an
988  /// rvalue, an xvalue, or an lvalue.
989  void AddDerivedToBaseCastStep(QualType BaseType,
991 
992  /// \brief Add a new step binding a reference to an object.
993  ///
994  /// \param BindingTemporary True if we are binding a reference to a temporary
995  /// object (thereby extending its lifetime); false if we are binding to an
996  /// lvalue or an lvalue treated as an rvalue.
997  void AddReferenceBindingStep(QualType T, bool BindingTemporary);
998 
999  /// \brief Add a new step that makes an extraneous copy of the input
1000  /// to a temporary of the same class type.
1001  ///
1002  /// This extraneous copy only occurs during reference binding in
1003  /// C++98/03, where we are permitted (but not required) to introduce
1004  /// an extra copy. At a bare minimum, we must check that we could
1005  /// call the copy constructor, and produce a diagnostic if the copy
1006  /// constructor is inaccessible or no copy constructor matches.
1007  //
1008  /// \param T The type of the temporary being created.
1010 
1011  /// \brief Add a new step invoking a conversion function, which is either
1012  /// a constructor or a conversion function.
1013  void AddUserConversionStep(FunctionDecl *Function,
1014  DeclAccessPair FoundDecl,
1015  QualType T,
1016  bool HadMultipleCandidates);
1017 
1018  /// \brief Add a new step that performs a qualification conversion to the
1019  /// given type.
1022 
1023  /// \brief Add a new step that performs conversion from non-atomic to atomic
1024  /// type.
1026 
1027  /// \brief Add a new step that performs a load of the given type.
1028  ///
1029  /// Although the term "LValueToRValue" is conventional, this applies to both
1030  /// lvalues and xvalues.
1032 
1033  /// \brief Add a new step that applies an implicit conversion sequence.
1035  QualType T, bool TopLevelOfInitList = false);
1036 
1037  /// \brief Add a list-initialization step.
1039 
1040  /// \brief Add a constructor-initialization step.
1041  ///
1042  /// \param FromInitList The constructor call is syntactically an initializer
1043  /// list.
1044  /// \param AsInitList The constructor is called as an init list constructor.
1046  AccessSpecifier Access,
1047  QualType T,
1048  bool HadMultipleCandidates,
1049  bool FromInitList, bool AsInitList);
1050 
1051  /// \brief Add a zero-initialization step.
1053 
1054  /// \brief Add a C assignment step.
1055  //
1056  // FIXME: It isn't clear whether this should ever be needed;
1057  // ideally, we would handle everything needed in C in the common
1058  // path. However, that isn't the case yet.
1059  void AddCAssignmentStep(QualType T);
1060 
1061  /// \brief Add a string init step.
1062  void AddStringInitStep(QualType T);
1063 
1064  /// \brief Add an Objective-C object conversion step, which is
1065  /// always a no-op.
1067 
1068  /// \brief Add an array initialization step.
1069  void AddArrayInitStep(QualType T);
1070 
1071  /// \brief Add a parenthesized array initialization step.
1073 
1074  /// \brief Add a step to pass an object by indirect copy-restore.
1075  void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy);
1076 
1077  /// \brief Add a step to "produce" an Objective-C object (by
1078  /// retaining it).
1080 
1081  /// \brief Add a step to construct a std::initializer_list object from an
1082  /// initializer list.
1084 
1085  /// \brief Add a step to initialize an OpenCL sampler from an integer
1086  /// constant.
1088 
1089  /// \brief Add a step to initialize an OpenCL event_t from a NULL
1090  /// constant.
1091  void AddOCLZeroEventStep(QualType T);
1092 
1093  /// \brief Add steps to unwrap a initializer list for a reference around a
1094  /// single element and rewrap it at the end.
1095  void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
1096 
1097  /// \brief Note that this initialization sequence failed.
1098  void SetFailed(FailureKind Failure) {
1100  this->Failure = Failure;
1101  assert((Failure != FK_Incomplete || !FailedIncompleteType.isNull()) &&
1102  "Incomplete type failure requires a type!");
1103  }
1104 
1105  /// \brief Note that this initialization sequence failed due to failed
1106  /// overload resolution.
1108 
1109  /// \brief Retrieve a reference to the candidate set when overload
1110  /// resolution fails.
1112  return FailedCandidateSet;
1113  }
1114 
1115  /// \brief Get the overloading result, for when the initialization
1116  /// sequence failed due to a bad overload.
1118  return FailedOverloadResult;
1119  }
1120 
1121  /// \brief Note that this initialization sequence failed due to an
1122  /// incomplete type.
1123  void setIncompleteTypeFailure(QualType IncompleteType) {
1124  FailedIncompleteType = IncompleteType;
1126  }
1127 
1128  /// \brief Determine why initialization failed.
1130  assert(Failed() && "Not an initialization failure!");
1131  return Failure;
1132  }
1133 
1134  /// \brief Dump a representation of this initialization sequence to
1135  /// the given stream, for debugging purposes.
1136  void dump(raw_ostream &OS) const;
1137 
1138  /// \brief Dump a representation of this initialization sequence to
1139  /// standard error, for debugging purposes.
1140  void dump() const;
1141 };
1142 
1143 } // end namespace clang
1144 
1145 #endif // LLVM_CLANG_SEMA_INITIALIZATION_H
Perform a derived-to-base cast, producing an lvalue.
Defines the clang::ASTContext interface.
SourceLocation getEnd() const
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1483
InitListExpr * WrappingSyntacticList
When Kind = SK_RewrapInitList, the syntactic form of the wrapping list.
bool Diagnose(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, ArrayRef< Expr * > Args)
Diagnose an potentially-invalid initialization sequence.
Definition: SemaInit.cpp:6878
void SetZeroInitializationFixit(const std::string &Fixit, SourceLocation L)
Call for initializations are invalid but that would be valid zero initialzations if Fixit was applied...
A (possibly-)qualified type.
Definition: Type.h:575
unsigned Index
When Kind == EK_ArrayElement, EK_VectorElement, or EK_ComplexElement, the index of the array or vecto...
step_iterator step_end() const
bool endsWithNarrowing(ASTContext &Ctx, const Expr *Initializer, bool *isInitializerConstant, APValue *ConstantValue) const
Returns whether the last step in this initialization sequence is a narrowing conversion, defined by C++0x [dcl.init.list]p7.
Produce an Objective-C object pointer.
void AddOCLZeroEventStep(QualType T)
Add a step to initialize an OpenCL event_t from a NULL constant.
Definition: SemaInit.cpp:3230
Initializing char array with wide string literal.
static InitializedEntity InitializeException(SourceLocation ThrowLoc, QualType Type, bool NRVO)
Create the initialization entity for an exception object.
Perform an implicit conversion sequence without narrowing.
An initialization that "converts" an Objective-C object (not a point to an object) to another Objecti...
Perform a qualification conversion, producing an rvalue.
SmallVectorImpl< Step >::const_iterator step_iterator
C Language Family Type Representation.
uintptr_t Base
When Kind == EK_Base, the base specifier that provides the base class.
static InitializationKind CreateDirect(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a direct initialization.
The base class of the type hierarchy.
Definition: Type.h:1249
SourceLocation getEqualLoc() const
Retrieve the location of the equal sign for copy initialization (if present).
The entity being initialized is a variable.
static InitializationKind CreateDefault(SourceLocation InitLoc)
Create a default initialization.
Overloading for a user-defined conversion failed.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:90
A container of type source information.
Definition: Decl.h:61
void AddAddressOverloadResolutionStep(FunctionDecl *Function, DeclAccessPair Found, bool HadMultipleCandidates)
Add a new step in the initialization that resolves the address of an overloaded function to a specifi...
Definition: SemaInit.cpp:3034
Perform a derived-to-base cast, producing an xvalue.
The entity being initialized is a base member subobject.
bool isFunctionalCast() const
Determine whether this is a functional-style cast.
List-copy-initialization chose an explicit constructor.
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2134
static InitializedEntity InitializeTemporary(QualType Type)
Create the initialization entity for a temporary.
The entity being initialized is a function parameter; function is member of group of audited CF APIs...
Initialize an OpenCL sampler from an integer.
EntityKind getKind() const
Determine the kind of initialization.
QualType getVariableArrayDecayedType(QualType Ty) const
Returns a vla type where known sizes are replaced with [*].
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:699
void AddCAssignmentStep(QualType T)
Add a C assignment step.
Definition: SemaInit.cpp:3165
SourceRange getParenRange() const
Retrieve the source range containing the locations of the open and closing parentheses for value and ...
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:113
Non-const lvalue reference binding to an lvalue of unrelated type.
step_iterator step_begin() const
static InitializedEntity InitializeResult(SourceLocation ReturnLoc, QualType Type, bool NRVO)
Create the initialization entity for the result of a function.
SourceLocation getThrowLoc() const
Determine the location of the 'throw' keyword when initializing an exception object.
Perform a derived-to-base cast, producing an rvalue.
void AddReferenceBindingStep(QualType T, bool BindingTemporary)
Add a new step binding a reference to an object.
Definition: SemaInit.cpp:3058
static InitializationKind CreateDirectList(SourceLocation InitLoc)
bool allowsNRVO() const
Determine whether this initialization allows the named return value optimization, which also applies ...
Definition: SemaInit.cpp:2864
void setElementIndex(unsigned Index)
If this is already the initializer for an array or vector element, sets the element index...
ParmVarDecl - Represents a parameter to a function.
Definition: Decl.h:1299
The entity being initialized is a temporary object.
bool allowExplicitConversionFunctionsInRefBinding() const
Retrieve whether this initialization allows the use of explicit conversion functions when binding a r...
void InitializeFrom(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, bool TopLevelOfInitList)
Definition: SemaInit.cpp:4819
Construct a std::initializer_list from an initializer list.
Trying to take the address of a function that doesn't support having its address taken.
One of these records is kept for each identifier that is lexed.
bool hasAttr() const
Definition: DeclBase.h:498
void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic)
Add steps to unwrap a initializer list for a reference around a single element and rewrap it at the e...
Definition: SemaInit.cpp:3237
bool isDirectReferenceBinding() const
Determine whether this initialization is a direct reference binding (C++ [dcl.init.ref]).
Definition: SemaInit.cpp:2980
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:91
ImplicitConversionSequence * ICS
When Kind = SK_ConversionSequence, the implicit conversion sequence.
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
DeclaratorDecl * getDecl() const
Retrieve the variable, parameter, or field being initialized.
Definition: SemaInit.cpp:2835
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
Definition: Decl.h:2209
SourceLocation getReturnLoc() const
Determine the location of the 'return' keyword when initializing the result of a function call...
Rewrap the single-element initializer list for a reference.
void AddOCLSamplerInitStep(QualType T)
Add a step to initialize an OpenCL sampler from an integer constant.
Definition: SemaInit.cpp:3223
int Category
Definition: Format.cpp:1726
TypeSourceInfo * getTypeSourceInfo() const
Retrieve complete type-source information for the object being constructed, if known.
void SetOverloadFailure(FailureKind Failure, OverloadingResult Result)
Note that this initialization sequence failed due to failed overload resolution.
Definition: SemaInit.cpp:3252
static InitializedEntity InitializeBlock(SourceLocation BlockVarLoc, QualType Type, bool NRVO)
Perform initialization via a constructor taking a single std::initializer_list argument.
Describes an C or C++ initializer list.
Definition: Expr.h:3724
static InitializedEntity InitializeTemporary(TypeSourceInfo *TypeInfo)
Create the initialization entity for a temporary.
const LangOptions & getLangOpts() const
Definition: ASTContext.h:596
EntityKind
Specifies the kind of entity being initialized.
static InitializedEntity InitializeDelegation(QualType Type)
Create the initialization entity for a delegated constructor.
StepKind Kind
The kind of conversion or initialization step we are taking.
SourceRange getRange() const
Retrieve the source range that covers the initialization.
OverloadCandidateSet & getFailedCandidateSet()
Retrieve a reference to the candidate set when overload resolution fails.
Variable-length array must not have an initializer.
Initialization of an incomplete type.
The entity being initialized is a non-static data member subobject.
static InitializationKind CreateValue(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc, bool isImplicit=false)
Create a value initialization.
Unwrap the single-element initializer list for a reference.
void AddParenthesizedArrayInitStep(QualType T)
Add a parenthesized array initialization step.
Definition: SemaInit.cpp:3193
ExprResult Perform(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, QualType *ResultType=nullptr)
Perform the actual initialization of the given entity based on the computed initialization sequence...
Definition: SemaInit.cpp:6046
The entity being initialized is an element of a vector.
bool isAmbiguous() const
Determine whether this initialization failed due to an ambiguity.
Definition: SemaInit.cpp:2984
Perform initialization via a constructor.
Perform a user-defined conversion, either via a conversion function or via a constructor.
The entity being initialized is a function parameter.
QualType getType() const
Definition: Decl.h:530
static InitializedEntity InitializeNew(SourceLocation NewLoc, QualType Type)
Create the initialization entity for an object allocated via new.
Perform an implicit conversion sequence.
bool isInheritedVirtualBase() const
Return whether the base is an inherited virtual base.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:259
Overloading for list-initialization by constructor failed.
Perform list-initialization without a constructor.
void AddObjCObjectConversionStep(QualType T)
Add an Objective-C object conversion step, which is always a no-op.
Definition: SemaInit.cpp:3179
Cannot resolve the address of an overloaded function.
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:577
void AddStdInitializerListConstructionStep(QualType T)
Add a step to construct a std::initializer_list object from an initializer list.
Definition: SemaInit.cpp:3216
static InitializedEntity InitializeMember(FieldDecl *Member, const InitializedEntity *Parent=nullptr)
Create the initialization entity for a member subobject.
FieldDecl * getAnonField() const
Definition: Decl.h:2465
ASTContext * Context
The entity being initialized is a field of block descriptor for the copied-in c++ object...
Initializing wide char array with incompatible wide string literal.
The entity being initialized is the real or imaginary part of a complex number.
friend class ASTContext
Definition: Type.h:4012
Expr - This represents one expression.
Definition: Expr.h:104
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:99
static InitializationKind CreateFunctionalCast(SourceRange TypeRange, bool InitList)
Create a direct initialization for a functional cast.
uintptr_t Parameter
When Kind == EK_Parameter, the ParmVarDecl, with the low bit indicating whether the parameter is "con...
The entity being initialized is an object (or array of objects) allocated via new.
Perform a qualification conversion, producing an xvalue.
static InitializedEntity InitializeVariable(VarDecl *Var)
Create the initialization entity for a variable.
Initializing a wide char array with narrow string literal.
void AddProduceObjCObjectStep(QualType T)
Add a step to "produce" an Objective-C object (by retaining it).
Definition: SemaInit.cpp:3209
Passing zero to a function where OpenCL event_t is expected.
void AddConstructorInitializationStep(CXXConstructorDecl *Constructor, AccessSpecifier Access, QualType T, bool HadMultipleCandidates, bool FromInitList, bool AsInitList)
Add a constructor-initialization step.
Definition: SemaInit.cpp:3142
#define bool
Definition: stdbool.h:31
Resolve the address of an overloaded function to a specific function declaration. ...
void AddArrayInitStep(QualType T)
Add an array initialization step.
Definition: SemaInit.cpp:3186
The entity being initialized is an exception object that is being thrown.
struct F Function
When Kind == SK_ResolvedOverloadedFunction or Kind == SK_UserConversion, the function that the expres...
ObjCMethodDecl * getMethodDecl() const
Retrieve the ObjectiveC method being initialized.
Initializer has a placeholder type which cannot be resolved by initialization.
FailureKind getFailureKind() const
Determine why initialization failed.
void AddStringInitStep(QualType T)
Add a string init step.
Definition: SemaInit.cpp:3172
The result type of a method or function.
InitKind getKind() const
Determine the initialization kind.
void AddZeroInitializationStep(QualType T)
Add a zero-initialization step.
Definition: SemaInit.cpp:3158
static InitializedEntity InitializeMember(IndirectFieldDecl *Member, const InitializedEntity *Parent=nullptr)
Create the initialization entity for a member subobject.
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
FailureKind
Describes why initialization failed.
List initialization failed at some point.
Perform a conversion adding _Atomic to a type.
void AddListInitializationStep(QualType T)
Add a list-initialization step.
Definition: SemaInit.cpp:3133
Perform a qualification conversion, producing an lvalue.
void AddLValueToRValueStep(QualType Ty)
Add a new step that performs a load of the given type.
Definition: SemaInit.cpp:3113
Kind
ImplicitConversionSequence - Represents an implicit conversion sequence, which may be a standard conv...
Definition: Overload.h:375
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Definition: Ownership.h:145
SequenceKind
Describes the kind of initialization sequence computed.
Encodes a location in the source.
Reference initialization from an initializer list.
static InitializedEntity InitializeLambdaCapture(IdentifierInfo *VarID, QualType FieldType, SourceLocation Loc)
Create the initialization entity for a lambda capture.
SourceLocation getLocation() const
Retrieve the location at which initialization is occurring.
SourceLocation getCaptureLoc() const
Determine the location of the capture when initializing field from a captured variable in a lambda...
StepKind
Describes the kind of a particular step in an initialization sequence.
TypeSourceInfo * TypeInfo
When Kind == EK_Temporary or EK_CompoundLiteralInit, the type source information for the temporary...
static InitializedEntity InitializeParameter(ASTContext &Context, ParmVarDecl *Parm, QualType Type)
Create the initialization entity for a parameter, but use another type.
OverloadingResult
OverloadingResult - Capture the result of performing overload resolution.
Definition: Overload.h:40
static InitializedEntity InitializeElement(ASTContext &Context, unsigned Index, const InitializedEntity &Parent)
Create the initialization entity for an array element.
bool isExplicitCast() const
Determine whether this initialization is an explicit cast.
const InitializedEntity * getParent() const
Retrieve the parent of the entity being initialized, when the initialization itself is occurring with...
Initialization of some unused destination type with an initializer list.
static InitializedEntity InitializeCompoundLiteralInit(TypeSourceInfo *TSI)
Create the entity for a compound literal initializer.
The entity being initialized is the result of a function call.
The entity being implicitly initialized back to the formal result type.
The entity being initialized is the initializer for a compound literal.
void AddExtraneousCopyToTemporary(QualType T)
Add a new step that makes an extraneous copy of the input to a temporary of the same class type...
Definition: SemaInit.cpp:3066
Describes the kind of initialization being performed, along with location information for tokens rela...
The entity being initialized is an element of an array.
StringRef getCapturedVarName() const
For a lambda capture, return the capture's name.
bool isCStyleOrFunctionalCast() const
Determine whether this initialization is a C-style cast.
Overloading for initialization by constructor failed.
SourceLocation getBegin() const
An optional copy of a temporary object to another temporary object, which is permitted (but not requi...
void AddAtomicConversionStep(QualType Ty)
Add a new step that performs conversion from non-atomic to atomic type.
Definition: SemaInit.cpp:3106
void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy)
Add a step to pass an object by indirect copy-restore.
Definition: SemaInit.cpp:3200
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13...
Definition: Overload.h:700
enum SequenceKind getKind() const
Determine the kind of initialization sequence computed.
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:69
static InitializationKind CreateCast(SourceRange TypeRange)
Create a direct initialization due to a cast that isn't a C-style or functional cast.
Pass an object by indirect copy-and-restore.
A POD class for pairing a NamedDecl* with an access specifier.
void SetFailed(FailureKind Failure)
Note that this initialization sequence failed.
bool isCStyleCast() const
Determine whether this is a C-style cast.
Array must be initialized with an initializer list or a string literal.
void setIncompleteTypeFailure(QualType IncompleteType)
Note that this initialization sequence failed due to an incomplete type.
A single step in the initialization sequence.
static InitializedEntity InitializeParameter(ASTContext &Context, QualType Type, bool Consumed)
Create the initialization entity for a parameter that is only known by its type.
Array must be initialized with an initializer list or a wide string literal.
Too many initializers provided for a reference.
Perform a load from a glvalue, producing an rvalue.
IndirectFieldDecl - An instance of this class is created to represent a field injected from an anonym...
Definition: Decl.h:2437
DeclarationName - The name of a declaration.
DeclaratorDecl * VariableOrMember
When Kind == EK_Variable, or EK_Member, the VarDecl or FieldDecl, respectively.
static InitializationKind CreateCStyleCast(SourceLocation StartLoc, SourceRange TypeRange, bool InitList)
Create a direct initialization for a C-style cast.
Overloading due to reference initialization failed.
bool isParameterKind() const
static InitializedEntity InitializeBase(ASTContext &Context, const CXXBaseSpecifier *Base, bool IsInheritedVirtualBase)
Create the initialization entity for a base class subobject.
Definition: SemaInit.cpp:2788
const CXXBaseSpecifier * getBaseSpecifier() const
Retrieve the base specifier.
Array must be initialized with an initializer list.
bool isParameterConsumed() const
Determine whether this initialization consumes the parameter.
void AddDerivedToBaseCastStep(QualType BaseType, ExprValueKind Category)
Add a new step in the initialization that performs a derived-to- base cast.
Definition: SemaInit.cpp:3046
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
Definition: APValue.h:38
Represents a base class of a C++ class.
Definition: DeclCXX.h:157
QualType getType() const
Retrieve type being initialized.
OverloadingResult getFailedOverloadResult() const
Get the overloading result, for when the initialization sequence failed due to a bad overload...
bool AllowExplicit() const
Retrieve whether this initialization allows the use of explicit constructors.
void AddUserConversionStep(FunctionDecl *Function, DeclAccessPair FoundDecl, QualType T, bool HadMultipleCandidates)
Add a new step invoking a conversion function, which is either a constructor or a conversion function...
Definition: SemaInit.cpp:3074
bool Failed() const
Determine whether the initialization sequence is invalid.
Defines the clang::SourceLocation class and associated facilities.
Describes the sequence of initializations required to initialize a given object or reference with a s...
static InitializedEntity InitializeRelatedResult(ObjCMethodDecl *MD, QualType Type)
Create the initialization entity for a related result.
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:5169
void dump() const
Dump a representation of the initialized entity to standard error, for debugging purposes.
Definition: SemaInit.cpp:2931
Perform initialization via a constructor, taking arguments from a single InitListExpr.
The entity being initialized is the field that captures a variable in a lambda.
void setSequenceKind(enum SequenceKind SK)
Set the kind of sequence computed.
A dependent initialization, which could not be type-checked due to the presence of dependent types or...
InitializationSequence(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, bool TopLevelOfInitList=false)
Try to perform initialization of the given entity, creating a record of the steps required to perform...
Definition: SemaInit.cpp:4799
bool isImplicitValueInit() const
Determine whether this initialization is an implicit value-initialization, e.g., as occurs during agg...
unsigned allocateManglingNumber() const
ObjCMethodDecl * MethodDecl
When Kind == EK_RelatedResult, the ObjectiveC method where result type was implicitly changed to acco...
DeclarationName getName() const
Retrieve the name of the entity being initialized.
Definition: SemaInit.cpp:2802
The initialization is being done by a delegating constructor.
void AddQualificationConversionStep(QualType Ty, ExprValueKind Category)
Add a new step that performs a qualification conversion to the given type.
Definition: SemaInit.cpp:3087
bool isConstructorInitialization() const
Determine whether this initialization is direct call to a constructor.
Definition: SemaInit.cpp:3028
A failed initialization sequence.
Array initialization (from an array rvalue).
InitKind
The kind of initialization being performed.
Default-initialization of a 'const' object.
void AddConversionSequenceStep(const ImplicitConversionSequence &ICS, QualType T, bool TopLevelOfInitList=false)
Add a new step that applies an implicit conversion sequence.
Definition: SemaInit.cpp:3122
A trivial tuple used to represent a source range.
void dump() const
Dump a representation of this initialization sequence to standard error, for debugging purposes...
Definition: SemaInit.cpp:7555
unsigned getElementIndex() const
If this is an array, vector, or complex number element, get the element's index.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:642
Describes an entity that is being initialized.
static InitializedEntity InitializeParameter(ASTContext &Context, ParmVarDecl *Parm)
Create the initialization entity for a parameter.
Direct list-initialization.
Array initialization from a parenthesized initializer list.