clang  7.0.0svn
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 
14 #ifndef LLVM_CLANG_SEMA_INITIALIZATION_H
15 #define LLVM_CLANG_SEMA_INITIALIZATION_H
16 
17 #include "clang/AST/ASTContext.h"
18 #include "clang/AST/Attr.h"
19 #include "clang/AST/Decl.h"
22 #include "clang/AST/Expr.h"
23 #include "clang/AST/Type.h"
25 #include "clang/Basic/LLVM.h"
28 #include "clang/Basic/Specifiers.h"
29 #include "clang/Sema/Overload.h"
30 #include "clang/Sema/Ownership.h"
31 #include "llvm/ADT/ArrayRef.h"
32 #include "llvm/ADT/SmallVector.h"
33 #include "llvm/ADT/StringRef.h"
34 #include "llvm/ADT/iterator_range.h"
35 #include "llvm/Support/Casting.h"
36 #include <cassert>
37 #include <cstdint>
38 #include <string>
39 
40 namespace clang {
41 
42 class APValue;
43 class CXXBaseSpecifier;
44 class CXXConstructorDecl;
45 class ObjCMethodDecl;
46 class Sema;
47 
48 /// Describes an entity that is being initialized.
50 public:
51  /// Specifies the kind of entity being initialized.
52  enum EntityKind {
53  /// The entity being initialized is a variable.
55 
56  /// The entity being initialized is a function parameter.
58 
59  /// The entity being initialized is the result of a function call.
61 
62  /// The entity being initialized is an exception object that
63  /// is being thrown.
65 
66  /// The entity being initialized is a non-static data member
67  /// subobject.
69 
70  /// The entity being initialized is an element of an array.
72 
73  /// The entity being initialized is an object (or array of
74  /// objects) allocated via new.
76 
77  /// The entity being initialized is a temporary object.
79 
80  /// The entity being initialized is a base member subobject.
82 
83  /// The initialization is being done by a delegating constructor.
85 
86  /// The entity being initialized is an element of a vector.
87  /// or vector.
89 
90  /// The entity being initialized is a field of block descriptor for
91  /// the copied-in c++ object.
93 
94  /// The entity being initialized is a field of block descriptor for the
95  /// copied-in lambda object that's used in the lambda to block conversion.
97 
98  /// The entity being initialized is the real or imaginary part of a
99  /// complex number.
101 
102  /// The entity being initialized is the field that captures a
103  /// variable in a lambda.
105 
106  /// The entity being initialized is the initializer for a compound
107  /// literal.
109 
110  /// The entity being implicitly initialized back to the formal
111  /// result type.
113 
114  /// The entity being initialized is a function parameter; function
115  /// is member of group of audited CF APIs.
117 
118  /// The entity being initialized is a structured binding of a
119  /// decomposition declaration.
121 
122  // Note: err_init_conversion_failed in DiagnosticSemaKinds.td uses this
123  // enum as an index for its first %select. When modifying this list,
124  // that diagnostic text needs to be updated as well.
125  };
126 
127 private:
128  /// The kind of entity being initialized.
130 
131  /// If non-NULL, the parent entity in which this
132  /// initialization occurs.
133  const InitializedEntity *Parent = nullptr;
134 
135  /// The type of the object or reference being initialized.
136  QualType Type;
137 
138  /// The mangling number for the next reference temporary to be created.
139  mutable unsigned ManglingNumber = 0;
140 
141  struct LN {
142  /// When Kind == EK_Result, EK_Exception, EK_New, the
143  /// location of the 'return', 'throw', or 'new' keyword,
144  /// respectively. When Kind == EK_Temporary, the location where
145  /// the temporary is being created.
146  unsigned Location;
147 
148  /// Whether the entity being initialized may end up using the
149  /// named return value optimization (NRVO).
150  bool NRVO;
151  };
152 
153  struct VD {
154  /// The VarDecl, FieldDecl, or BindingDecl being initialized.
155  ValueDecl *VariableOrMember;
156 
157  /// When Kind == EK_Member, whether this is an implicit member
158  /// initialization in a copy or move constructor. These can perform array
159  /// copies.
160  bool IsImplicitFieldInit;
161  };
162 
163  struct C {
164  /// The name of the variable being captured by an EK_LambdaCapture.
165  IdentifierInfo *VarID;
166 
167  /// The source location at which the capture occurs.
168  unsigned Location;
169  };
170 
171  union {
172  /// When Kind == EK_Variable, EK_Member or EK_Binding, the variable.
174 
175  /// When Kind == EK_RelatedResult, the ObjectiveC method where
176  /// result type was implicitly changed to accommodate ARC semantics.
178 
179  /// When Kind == EK_Parameter, the ParmVarDecl, with the
180  /// low bit indicating whether the parameter is "consumed".
182 
183  /// When Kind == EK_Temporary or EK_CompoundLiteralInit, the type
184  /// source information for the temporary.
186 
187  struct LN LocAndNRVO;
188 
189  /// When Kind == EK_Base, the base specifier that provides the
190  /// base class. The lower bit specifies whether the base is an inherited
191  /// virtual base.
193 
194  /// When Kind == EK_ArrayElement, EK_VectorElement, or
195  /// EK_ComplexElement, the index of the array or vector element being
196  /// initialized.
197  unsigned Index;
198 
199  struct C Capture;
200  };
201 
202  InitializedEntity() = default;
203 
204  /// Create the initialization entity for a variable.
206  : Kind(EK), Type(Var->getType()), Variable{Var, false} {}
207 
208  /// Create the initialization entity for the result of a
209  /// function, throwing an object, performing an explicit cast, or
210  /// initializing a parameter for which there is no declaration.
212  bool NRVO = false)
213  : Kind(Kind), Type(Type) {
214  LocAndNRVO.Location = Loc.getRawEncoding();
215  LocAndNRVO.NRVO = NRVO;
216  }
217 
218  /// Create the initialization entity for a member subobject.
219  InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent,
220  bool Implicit)
221  : Kind(EK_Member), Parent(Parent), Type(Member->getType()),
222  Variable{Member, Implicit} {}
223 
224  /// Create the initialization entity for an array element.
225  InitializedEntity(ASTContext &Context, unsigned Index,
226  const InitializedEntity &Parent);
227 
228  /// Create the initialization entity for a lambda capture.
230  : Kind(EK_LambdaCapture), Type(FieldType) {
231  Capture.VarID = VarID;
232  Capture.Location = Loc.getRawEncoding();
233  }
234 
235 public:
236  /// Create the initialization entity for a variable.
238  return InitializedEntity(Var);
239  }
240 
241  /// Create the initialization entity for a parameter.
243  const ParmVarDecl *Parm) {
244  return InitializeParameter(Context, Parm, Parm->getType());
245  }
246 
247  /// Create the initialization entity for a parameter, but use
248  /// another type.
250  const ParmVarDecl *Parm,
251  QualType Type) {
252  bool Consumed = (Context.getLangOpts().ObjCAutoRefCount &&
253  Parm->hasAttr<NSConsumedAttr>());
254 
255  InitializedEntity Entity;
256  Entity.Kind = EK_Parameter;
257  Entity.Type =
259  Entity.Parent = nullptr;
260  Entity.Parameter
261  = (static_cast<uintptr_t>(Consumed) | reinterpret_cast<uintptr_t>(Parm));
262  return Entity;
263  }
264 
265  /// Create the initialization entity for a parameter that is
266  /// only known by its type.
268  QualType Type,
269  bool Consumed) {
270  InitializedEntity Entity;
271  Entity.Kind = EK_Parameter;
272  Entity.Type = Context.getVariableArrayDecayedType(Type);
273  Entity.Parent = nullptr;
274  Entity.Parameter = (Consumed);
275  return Entity;
276  }
277 
278  /// Create the initialization entity for the result of a function.
280  QualType Type, bool NRVO) {
281  return InitializedEntity(EK_Result, ReturnLoc, Type, NRVO);
282  }
283 
285  QualType Type, bool NRVO) {
286  return InitializedEntity(EK_BlockElement, BlockVarLoc, Type, NRVO);
287  }
288 
290  QualType Type, bool NRVO) {
292  BlockVarLoc, Type, NRVO);
293  }
294 
295  /// Create the initialization entity for an exception object.
297  QualType Type, bool NRVO) {
298  return InitializedEntity(EK_Exception, ThrowLoc, Type, NRVO);
299  }
300 
301  /// Create the initialization entity for an object allocated via new.
303  return InitializedEntity(EK_New, NewLoc, Type);
304  }
305 
306  /// Create the initialization entity for a temporary.
308  return InitializeTemporary(nullptr, Type);
309  }
310 
311  /// Create the initialization entity for a temporary.
313  return InitializeTemporary(TypeInfo, TypeInfo->getType());
314  }
315 
316  /// Create the initialization entity for a temporary.
318  QualType Type) {
320  Result.TypeInfo = TypeInfo;
321  return Result;
322  }
323 
324  /// Create the initialization entity for a related result.
326  QualType Type) {
328  Result.MethodDecl = MD;
329  return Result;
330  }
331 
332  /// Create the initialization entity for a base class subobject.
333  static InitializedEntity
335  bool IsInheritedVirtualBase,
336  const InitializedEntity *Parent = nullptr);
337 
338  /// Create the initialization entity for a delegated constructor.
341  }
342 
343  /// Create the initialization entity for a member subobject.
344  static InitializedEntity
346  const InitializedEntity *Parent = nullptr,
347  bool Implicit = false) {
348  return InitializedEntity(Member, Parent, Implicit);
349  }
350 
351  /// Create the initialization entity for a member subobject.
352  static InitializedEntity
354  const InitializedEntity *Parent = nullptr,
355  bool Implicit = false) {
356  return InitializedEntity(Member->getAnonField(), Parent, Implicit);
357  }
358 
359  /// Create the initialization entity for an array element.
361  unsigned Index,
362  const InitializedEntity &Parent) {
363  return InitializedEntity(Context, Index, Parent);
364  }
365 
366  /// Create the initialization entity for a structured binding.
368  return InitializedEntity(Binding, EK_Binding);
369  }
370 
371  /// Create the initialization entity for a lambda capture.
373  QualType FieldType,
374  SourceLocation Loc) {
375  return InitializedEntity(VarID, FieldType, Loc);
376  }
377 
378  /// Create the entity for a compound literal initializer.
381  TSI->getType());
382  Result.TypeInfo = TSI;
383  return Result;
384  }
385 
386  /// Determine the kind of initialization.
387  EntityKind getKind() const { return Kind; }
388 
389  /// Retrieve the parent of the entity being initialized, when
390  /// the initialization itself is occurring within the context of a
391  /// larger initialization.
392  const InitializedEntity *getParent() const { return Parent; }
393 
394  /// Retrieve type being initialized.
395  QualType getType() const { return Type; }
396 
397  /// Retrieve complete type-source information for the object being
398  /// constructed, if known.
400  if (Kind == EK_Temporary || Kind == EK_CompoundLiteralInit)
401  return TypeInfo;
402 
403  return nullptr;
404  }
405 
406  /// Retrieve the name of the entity being initialized.
407  DeclarationName getName() const;
408 
409  /// Retrieve the variable, parameter, or field being
410  /// initialized.
411  ValueDecl *getDecl() const;
412 
413  /// Retrieve the ObjectiveC method being initialized.
415 
416  /// Determine whether this initialization allows the named return
417  /// value optimization, which also applies to thrown objects.
418  bool allowsNRVO() const;
419 
420  bool isParameterKind() const {
421  return (getKind() == EK_Parameter ||
423  }
424 
425  /// Determine whether this initialization consumes the
426  /// parameter.
427  bool isParameterConsumed() const {
428  assert(isParameterKind() && "Not a parameter");
429  return (Parameter & 1);
430  }
431 
432  /// Retrieve the base specifier.
434  assert(getKind() == EK_Base && "Not a base specifier");
435  return reinterpret_cast<const CXXBaseSpecifier *>(Base & ~0x1);
436  }
437 
438  /// Return whether the base is an inherited virtual base.
439  bool isInheritedVirtualBase() const {
440  assert(getKind() == EK_Base && "Not a base specifier");
441  return Base & 0x1;
442  }
443 
444  /// Determine whether this is an array new with an unknown bound.
446  return getKind() == EK_New && dyn_cast_or_null<IncompleteArrayType>(
448  }
449 
450  /// Is this the implicit initialization of a member of a class from
451  /// a defaulted constructor?
453  return getKind() == EK_Member && Variable.IsImplicitFieldInit;
454  }
455 
456  /// Determine the location of the 'return' keyword when initializing
457  /// the result of a function call.
459  assert(getKind() == EK_Result && "No 'return' location!");
461  }
462 
463  /// Determine the location of the 'throw' keyword when initializing
464  /// an exception object.
466  assert(getKind() == EK_Exception && "No 'throw' location!");
468  }
469 
470  /// If this is an array, vector, or complex number element, get the
471  /// element's index.
472  unsigned getElementIndex() const {
473  assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
475  return Index;
476  }
477 
478  /// If this is already the initializer for an array or vector
479  /// element, sets the element index.
480  void setElementIndex(unsigned Index) {
481  assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
483  this->Index = Index;
484  }
485 
486  /// For a lambda capture, return the capture's name.
487  StringRef getCapturedVarName() const {
488  assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
489  return Capture.VarID->getName();
490  }
491 
492  /// Determine the location of the capture when initializing
493  /// field from a captured variable in a lambda.
495  assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
496  return SourceLocation::getFromRawEncoding(Capture.Location);
497  }
498 
501  }
502 
503  unsigned allocateManglingNumber() const { return ++ManglingNumber; }
504 
505  /// Dump a representation of the initialized entity to standard error,
506  /// for debugging purposes.
507  void dump() const;
508 
509 private:
510  unsigned dumpImpl(raw_ostream &OS) const;
511 };
512 
513 /// Describes the kind of initialization being performed, along with
514 /// location information for tokens related to the initialization (equal sign,
515 /// parentheses).
517 public:
518  /// The kind of initialization being performed.
519  enum InitKind {
520  /// Direct initialization
522 
523  /// Direct list-initialization
525 
526  /// Copy initialization
528 
529  /// Default initialization
531 
532  /// Value initialization
533  IK_Value
534  };
535 
536 private:
537  /// The context of the initialization.
538  enum InitContext {
539  /// Normal context
540  IC_Normal,
541 
542  /// Normal context, but allows explicit conversion functionss
543  IC_ExplicitConvs,
544 
545  /// Implicit context (value initialization)
546  IC_Implicit,
547 
548  /// Static cast context
549  IC_StaticCast,
550 
551  /// C-style cast context
552  IC_CStyleCast,
553 
554  /// Functional cast context
555  IC_FunctionalCast
556  };
557 
558  /// The kind of initialization being performed.
559  InitKind Kind : 8;
560 
561  /// The context of the initialization.
562  InitContext Context : 8;
563 
564  /// The source locations involved in the initialization.
565  SourceLocation Locations[3];
566 
567  InitializationKind(InitKind Kind, InitContext Context, SourceLocation Loc1,
568  SourceLocation Loc2, SourceLocation Loc3)
569  : Kind(Kind), Context(Context) {
570  Locations[0] = Loc1;
571  Locations[1] = Loc2;
572  Locations[2] = Loc3;
573  }
574 
575 public:
576  /// Create a direct initialization.
578  SourceLocation LParenLoc,
579  SourceLocation RParenLoc) {
580  return InitializationKind(IK_Direct, IC_Normal,
581  InitLoc, LParenLoc, RParenLoc);
582  }
583 
585  return InitializationKind(IK_DirectList, IC_Normal, InitLoc, InitLoc,
586  InitLoc);
587  }
588 
590  SourceLocation LBraceLoc,
591  SourceLocation RBraceLoc) {
592  return InitializationKind(IK_DirectList, IC_Normal, InitLoc, LBraceLoc,
593  RBraceLoc);
594  }
595 
596  /// Create a direct initialization due to a cast that isn't a C-style
597  /// or functional cast.
599  return InitializationKind(IK_Direct, IC_StaticCast, TypeRange.getBegin(),
600  TypeRange.getBegin(), TypeRange.getEnd());
601  }
602 
603  /// Create a direct initialization for a C-style cast.
605  SourceRange TypeRange,
606  bool InitList) {
607  // C++ cast syntax doesn't permit init lists, but C compound literals are
608  // exactly that.
609  return InitializationKind(InitList ? IK_DirectList : IK_Direct,
610  IC_CStyleCast, StartLoc, TypeRange.getBegin(),
611  TypeRange.getEnd());
612  }
613 
614  /// Create a direct initialization for a functional cast.
616  bool InitList) {
617  return InitializationKind(InitList ? IK_DirectList : IK_Direct,
618  IC_FunctionalCast, TypeRange.getBegin(),
619  TypeRange.getBegin(), TypeRange.getEnd());
620  }
621 
622  /// Create a copy initialization.
624  SourceLocation EqualLoc,
625  bool AllowExplicitConvs = false) {
626  return InitializationKind(IK_Copy,
627  AllowExplicitConvs? IC_ExplicitConvs : IC_Normal,
628  InitLoc, EqualLoc, EqualLoc);
629  }
630 
631  /// Create a default initialization.
633  return InitializationKind(IK_Default, IC_Normal, InitLoc, InitLoc, InitLoc);
634  }
635 
636  /// Create a value initialization.
638  SourceLocation LParenLoc,
639  SourceLocation RParenLoc,
640  bool isImplicit = false) {
641  return InitializationKind(IK_Value, isImplicit ? IC_Implicit : IC_Normal,
642  InitLoc, LParenLoc, RParenLoc);
643  }
644 
645  /// Create an initialization from an initializer (which, for direct
646  /// initialization from a parenthesized list, will be a ParenListExpr).
648  Expr *Init) {
649  if (!Init) return CreateDefault(Loc);
650  if (!DirectInit) return CreateCopy(Loc, Init->getLocStart());
651  if (isa<InitListExpr>(Init))
652  return CreateDirectList(Loc, Init->getLocStart(), Init->getLocEnd());
653  return CreateDirect(Loc, Init->getLocStart(), Init->getLocEnd());
654  }
655 
656  /// Determine the initialization kind.
657  InitKind getKind() const {
658  return Kind;
659  }
660 
661  /// Determine whether this initialization is an explicit cast.
662  bool isExplicitCast() const {
663  return Context >= IC_StaticCast;
664  }
665 
666  /// Determine whether this initialization is a C-style cast.
667  bool isCStyleOrFunctionalCast() const {
668  return Context >= IC_CStyleCast;
669  }
670 
671  /// Determine whether this is a C-style cast.
672  bool isCStyleCast() const {
673  return Context == IC_CStyleCast;
674  }
675 
676  /// Determine whether this is a functional-style cast.
677  bool isFunctionalCast() const {
678  return Context == IC_FunctionalCast;
679  }
680 
681  /// Determine whether this initialization is an implicit
682  /// value-initialization, e.g., as occurs during aggregate
683  /// initialization.
684  bool isImplicitValueInit() const { return Context == IC_Implicit; }
685 
686  /// Retrieve the location at which initialization is occurring.
687  SourceLocation getLocation() const { return Locations[0]; }
688 
689  /// Retrieve the source range that covers the initialization.
691  return SourceRange(Locations[0], Locations[2]);
692  }
693 
694  /// Retrieve the location of the equal sign for copy initialization
695  /// (if present).
697  assert(Kind == IK_Copy && "Only copy initialization has an '='");
698  return Locations[1];
699  }
700 
701  bool isCopyInit() const { return Kind == IK_Copy; }
702 
703  /// Retrieve whether this initialization allows the use of explicit
704  /// constructors.
705  bool AllowExplicit() const { return !isCopyInit(); }
706 
707  /// Retrieve whether this initialization allows the use of explicit
708  /// conversion functions when binding a reference. If the reference is the
709  /// first parameter in a copy or move constructor, such conversions are
710  /// permitted even though we are performing copy-initialization.
712  return !isCopyInit() || Context == IC_ExplicitConvs;
713  }
714 
715  /// Determine whether this initialization has a source range containing the
716  /// locations of open and closing parentheses or braces.
717  bool hasParenOrBraceRange() const {
718  return Kind == IK_Direct || Kind == IK_Value || Kind == IK_DirectList;
719  }
720 
721  /// Retrieve the source range containing the locations of the open
722  /// and closing parentheses or braces for value, direct, and direct list
723  /// initializations.
725  assert(hasParenOrBraceRange() && "Only direct, value, and direct-list "
726  "initialization have parentheses or "
727  "braces");
728  return SourceRange(Locations[1], Locations[2]);
729  }
730 };
731 
732 /// Describes the sequence of initializations required to initialize
733 /// a given object or reference with a set of arguments.
735 public:
736  /// Describes the kind of initialization sequence computed.
738  /// A failed initialization sequence. The failure kind tells what
739  /// happened.
740  FailedSequence = 0,
741 
742  /// A dependent initialization, which could not be
743  /// type-checked due to the presence of dependent types or
744  /// dependently-typed expressions.
746 
747  /// A normal sequence.
748  NormalSequence
749  };
750 
751  /// Describes the kind of a particular step in an initialization
752  /// sequence.
753  enum StepKind {
754  /// Resolve the address of an overloaded function to a specific
755  /// function declaration.
757 
758  /// Perform a derived-to-base cast, producing an rvalue.
760 
761  /// Perform a derived-to-base cast, producing an xvalue.
763 
764  /// Perform a derived-to-base cast, producing an lvalue.
766 
767  /// Reference binding to an lvalue.
769 
770  /// Reference binding to a temporary.
772 
773  /// An optional copy of a temporary object to another
774  /// temporary object, which is permitted (but not required) by
775  /// C++98/03 but not C++0x.
777 
778  /// Direct-initialization from a reference-related object in the
779  /// final stage of class copy-initialization.
781 
782  /// Perform a user-defined conversion, either via a conversion
783  /// function or via a constructor.
785 
786  /// Perform a qualification conversion, producing an rvalue.
788 
789  /// Perform a qualification conversion, producing an xvalue.
791 
792  /// Perform a qualification conversion, producing an lvalue.
794 
795  /// Perform a conversion adding _Atomic to a type.
797 
798  /// Perform a load from a glvalue, producing an rvalue.
800 
801  /// Perform an implicit conversion sequence.
803 
804  /// Perform an implicit conversion sequence without narrowing.
806 
807  /// Perform list-initialization without a constructor.
809 
810  /// Unwrap the single-element initializer list for a reference.
812 
813  /// Rewrap the single-element initializer list for a reference.
815 
816  /// Perform initialization via a constructor.
818 
819  /// Perform initialization via a constructor, taking arguments from
820  /// a single InitListExpr.
822 
823  /// Zero-initialize the object
825 
826  /// C assignment
828 
829  /// Initialization by string
831 
832  /// An initialization that "converts" an Objective-C object
833  /// (not a point to an object) to another Objective-C object type.
835 
836  /// Array indexing for initialization by elementwise copy.
838 
839  /// Array initialization by elementwise copy.
841 
842  /// Array initialization (from an array rvalue).
844 
845  /// Array initialization (from an array rvalue) as a GNU extension.
847 
848  /// Array initialization from a parenthesized initializer list.
849  /// This is a GNU C++ extension.
851 
852  /// Pass an object by indirect copy-and-restore.
854 
855  /// Pass an object by indirect restore.
857 
858  /// Produce an Objective-C object pointer.
860 
861  /// Construct a std::initializer_list from an initializer list.
863 
864  /// Perform initialization via a constructor taking a single
865  /// std::initializer_list argument.
867 
868  /// Initialize an OpenCL sampler from an integer.
870 
871  /// Initialize queue_t from 0.
873 
874  /// Passing zero to a function where OpenCL event_t is expected.
875  SK_OCLZeroEvent
876  };
877 
878  /// A single step in the initialization sequence.
879  class Step {
880  public:
881  /// The kind of conversion or initialization step we are taking.
883 
884  // The type that results from this initialization.
886 
887  struct F {
891  };
892 
893  union {
894  /// When Kind == SK_ResolvedOverloadedFunction or Kind ==
895  /// SK_UserConversion, the function that the expression should be
896  /// resolved to or the conversion function to call, respectively.
897  /// When Kind == SK_ConstructorInitialization or SK_ListConstruction,
898  /// the constructor to be called.
899  ///
900  /// Always a FunctionDecl, plus a Boolean flag telling if it was
901  /// selected from an overloaded set having size greater than 1.
902  /// For conversion decls, the naming class is the source type.
903  /// For construct decls, the naming class is the target type.
904  struct F Function;
905 
906  /// When Kind = SK_ConversionSequence, the implicit conversion
907  /// sequence.
909 
910  /// When Kind = SK_RewrapInitList, the syntactic form of the
911  /// wrapping list.
913  };
914 
915  void Destroy();
916  };
917 
918 private:
919  /// The kind of initialization sequence computed.
921 
922  /// Steps taken by this initialization.
923  SmallVector<Step, 4> Steps;
924 
925 public:
926  /// Describes why initialization failed.
927  enum FailureKind {
928  /// Too many initializers provided for a reference.
930 
931  /// Reference initialized from a parenthesized initializer list.
933 
934  /// Array must be initialized with an initializer list.
936 
937  /// Array must be initialized with an initializer list or a
938  /// string literal.
940 
941  /// Array must be initialized with an initializer list or a
942  /// wide string literal.
944 
945  /// Initializing a wide char array with narrow string literal.
947 
948  /// Initializing char array with wide string literal.
950 
951  /// Initializing wide char array with incompatible wide string
952  /// literal.
954 
955  /// Initializing char8_t array with plain string literal.
957 
958  /// Initializing char array with UTF-8 string literal.
960 
961  /// Array type mismatch.
963 
964  /// Non-constant array initializer
966 
967  /// Cannot resolve the address of an overloaded function.
969 
970  /// Overloading due to reference initialization failed.
972 
973  /// Non-const lvalue reference binding to a temporary.
975 
976  /// Non-const lvalue reference binding to a bit-field.
978 
979  /// Non-const lvalue reference binding to a vector element.
981 
982  /// Non-const lvalue reference binding to an lvalue of unrelated
983  /// type.
985 
986  /// Rvalue reference binding to an lvalue.
988 
989  /// Reference binding drops qualifiers.
991 
992  /// Reference binding failed.
994 
995  /// Implicit conversion failed.
997 
998  /// Implicit conversion failed.
1000 
1001  /// Too many initializers for scalar
1003 
1004  /// Scalar initialized from a parenthesized initializer list.
1006 
1007  /// Reference initialization from an initializer list
1009 
1010  /// Initialization of some unused destination type with an
1011  /// initializer list.
1013 
1014  /// Overloading for a user-defined conversion failed.
1016 
1017  /// Overloading for initialization by constructor failed.
1019 
1020  /// Overloading for list-initialization by constructor failed.
1022 
1023  /// Default-initialization of a 'const' object.
1025 
1026  /// Initialization of an incomplete type.
1028 
1029  /// Variable-length array must not have an initializer.
1031 
1032  /// List initialization failed at some point.
1034 
1035  /// Initializer has a placeholder type which cannot be
1036  /// resolved by initialization.
1038 
1039  /// Trying to take the address of a function that doesn't support
1040  /// having its address taken.
1042 
1043  /// List-copy-initialization chose an explicit constructor.
1045  };
1046 
1047 private:
1048  /// The reason why initialization failed.
1049  FailureKind Failure;
1050 
1051  /// The failed result of overload resolution.
1052  OverloadingResult FailedOverloadResult;
1053 
1054  /// The candidate set created when initialization failed.
1055  OverloadCandidateSet FailedCandidateSet;
1056 
1057  /// The incomplete type that caused a failure.
1058  QualType FailedIncompleteType;
1059 
1060  /// The fixit that needs to be applied to make this initialization
1061  /// succeed.
1062  std::string ZeroInitializationFixit;
1063  SourceLocation ZeroInitializationFixitLoc;
1064 
1065 public:
1066  /// Call for initializations are invalid but that would be valid
1067  /// zero initialzations if Fixit was applied.
1068  void SetZeroInitializationFixit(const std::string& Fixit, SourceLocation L) {
1069  ZeroInitializationFixit = Fixit;
1070  ZeroInitializationFixitLoc = L;
1071  }
1072 
1073 private:
1074  /// Prints a follow-up note that highlights the location of
1075  /// the initialized entity, if it's remote.
1076  void PrintInitLocationNote(Sema &S, const InitializedEntity &Entity);
1077 
1078 public:
1079  /// Try to perform initialization of the given entity, creating a
1080  /// record of the steps required to perform the initialization.
1081  ///
1082  /// The generated initialization sequence will either contain enough
1083  /// information to diagnose
1084  ///
1085  /// \param S the semantic analysis object.
1086  ///
1087  /// \param Entity the entity being initialized.
1088  ///
1089  /// \param Kind the kind of initialization being performed.
1090  ///
1091  /// \param Args the argument(s) provided for initialization.
1092  ///
1093  /// \param TopLevelOfInitList true if we are initializing from an expression
1094  /// at the top level inside an initializer list. This disallows
1095  /// narrowing conversions in C++11 onwards.
1096  /// \param TreatUnavailableAsInvalid true if we want to treat unavailable
1097  /// as invalid.
1099  const InitializedEntity &Entity,
1100  const InitializationKind &Kind,
1101  MultiExprArg Args,
1102  bool TopLevelOfInitList = false,
1103  bool TreatUnavailableAsInvalid = true);
1104  void InitializeFrom(Sema &S, const InitializedEntity &Entity,
1105  const InitializationKind &Kind, MultiExprArg Args,
1106  bool TopLevelOfInitList, bool TreatUnavailableAsInvalid);
1107 
1109 
1110  /// Perform the actual initialization of the given entity based on
1111  /// the computed initialization sequence.
1112  ///
1113  /// \param S the semantic analysis object.
1114  ///
1115  /// \param Entity the entity being initialized.
1116  ///
1117  /// \param Kind the kind of initialization being performed.
1118  ///
1119  /// \param Args the argument(s) provided for initialization, ownership of
1120  /// which is transferred into the routine.
1121  ///
1122  /// \param ResultType if non-NULL, will be set to the type of the
1123  /// initialized object, which is the type of the declaration in most
1124  /// cases. However, when the initialized object is a variable of
1125  /// incomplete array type and the initializer is an initializer
1126  /// list, this type will be set to the completed array type.
1127  ///
1128  /// \returns an expression that performs the actual object initialization, if
1129  /// the initialization is well-formed. Otherwise, emits diagnostics
1130  /// and returns an invalid expression.
1131  ExprResult Perform(Sema &S,
1132  const InitializedEntity &Entity,
1133  const InitializationKind &Kind,
1134  MultiExprArg Args,
1135  QualType *ResultType = nullptr);
1136 
1137  /// Diagnose an potentially-invalid initialization sequence.
1138  ///
1139  /// \returns true if the initialization sequence was ill-formed,
1140  /// false otherwise.
1141  bool Diagnose(Sema &S,
1142  const InitializedEntity &Entity,
1143  const InitializationKind &Kind,
1144  ArrayRef<Expr *> Args);
1145 
1146  /// Determine the kind of initialization sequence computed.
1147  enum SequenceKind getKind() const { return SequenceKind; }
1148 
1149  /// Set the kind of sequence computed.
1150  void setSequenceKind(enum SequenceKind SK) { SequenceKind = SK; }
1151 
1152  /// Determine whether the initialization sequence is valid.
1153  explicit operator bool() const { return !Failed(); }
1154 
1155  /// Determine whether the initialization sequence is invalid.
1156  bool Failed() const { return SequenceKind == FailedSequence; }
1157 
1159 
1160  step_iterator step_begin() const { return Steps.begin(); }
1161  step_iterator step_end() const { return Steps.end(); }
1162 
1163  using step_range = llvm::iterator_range<step_iterator>;
1164 
1165  step_range steps() const { return {step_begin(), step_end()}; }
1166 
1167  /// Determine whether this initialization is a direct reference
1168  /// binding (C++ [dcl.init.ref]).
1169  bool isDirectReferenceBinding() const;
1170 
1171  /// Determine whether this initialization failed due to an ambiguity.
1172  bool isAmbiguous() const;
1173 
1174  /// Determine whether this initialization is direct call to a
1175  /// constructor.
1176  bool isConstructorInitialization() const;
1177 
1178  /// Returns whether the last step in this initialization sequence is a
1179  /// narrowing conversion, defined by C++0x [dcl.init.list]p7.
1180  ///
1181  /// If this function returns true, *isInitializerConstant will be set to
1182  /// describe whether *Initializer was a constant expression. If
1183  /// *isInitializerConstant is set to true, *ConstantValue will be set to the
1184  /// evaluated value of *Initializer.
1185  bool endsWithNarrowing(ASTContext &Ctx, const Expr *Initializer,
1186  bool *isInitializerConstant,
1187  APValue *ConstantValue) const;
1188 
1189  /// Add a new step in the initialization that resolves the address
1190  /// of an overloaded function to a specific function declaration.
1191  ///
1192  /// \param Function the function to which the overloaded function reference
1193  /// resolves.
1194  void AddAddressOverloadResolutionStep(FunctionDecl *Function,
1195  DeclAccessPair Found,
1196  bool HadMultipleCandidates);
1197 
1198  /// Add a new step in the initialization that performs a derived-to-
1199  /// base cast.
1200  ///
1201  /// \param BaseType the base type to which we will be casting.
1202  ///
1203  /// \param Category Indicates whether the result will be treated as an
1204  /// rvalue, an xvalue, or an lvalue.
1205  void AddDerivedToBaseCastStep(QualType BaseType,
1207 
1208  /// Add a new step binding a reference to an object.
1209  ///
1210  /// \param BindingTemporary True if we are binding a reference to a temporary
1211  /// object (thereby extending its lifetime); false if we are binding to an
1212  /// lvalue or an lvalue treated as an rvalue.
1213  void AddReferenceBindingStep(QualType T, bool BindingTemporary);
1214 
1215  /// Add a new step that makes an extraneous copy of the input
1216  /// to a temporary of the same class type.
1217  ///
1218  /// This extraneous copy only occurs during reference binding in
1219  /// C++98/03, where we are permitted (but not required) to introduce
1220  /// an extra copy. At a bare minimum, we must check that we could
1221  /// call the copy constructor, and produce a diagnostic if the copy
1222  /// constructor is inaccessible or no copy constructor matches.
1223  //
1224  /// \param T The type of the temporary being created.
1225  void AddExtraneousCopyToTemporary(QualType T);
1226 
1227  /// Add a new step that makes a copy of the input to an object of
1228  /// the given type, as the final step in class copy-initialization.
1229  void AddFinalCopy(QualType T);
1230 
1231  /// Add a new step invoking a conversion function, which is either
1232  /// a constructor or a conversion function.
1233  void AddUserConversionStep(FunctionDecl *Function,
1234  DeclAccessPair FoundDecl,
1235  QualType T,
1236  bool HadMultipleCandidates);
1237 
1238  /// Add a new step that performs a qualification conversion to the
1239  /// given type.
1240  void AddQualificationConversionStep(QualType Ty,
1241  ExprValueKind Category);
1242 
1243  /// Add a new step that performs conversion from non-atomic to atomic
1244  /// type.
1245  void AddAtomicConversionStep(QualType Ty);
1246 
1247  /// Add a new step that performs a load of the given type.
1248  ///
1249  /// Although the term "LValueToRValue" is conventional, this applies to both
1250  /// lvalues and xvalues.
1251  void AddLValueToRValueStep(QualType Ty);
1252 
1253  /// Add a new step that applies an implicit conversion sequence.
1254  void AddConversionSequenceStep(const ImplicitConversionSequence &ICS,
1255  QualType T, bool TopLevelOfInitList = false);
1256 
1257  /// Add a list-initialization step.
1258  void AddListInitializationStep(QualType T);
1259 
1260  /// Add a constructor-initialization step.
1261  ///
1262  /// \param FromInitList The constructor call is syntactically an initializer
1263  /// list.
1264  /// \param AsInitList The constructor is called as an init list constructor.
1265  void AddConstructorInitializationStep(DeclAccessPair FoundDecl,
1266  CXXConstructorDecl *Constructor,
1267  QualType T,
1268  bool HadMultipleCandidates,
1269  bool FromInitList, bool AsInitList);
1270 
1271  /// Add a zero-initialization step.
1272  void AddZeroInitializationStep(QualType T);
1273 
1274  /// Add a C assignment step.
1275  //
1276  // FIXME: It isn't clear whether this should ever be needed;
1277  // ideally, we would handle everything needed in C in the common
1278  // path. However, that isn't the case yet.
1279  void AddCAssignmentStep(QualType T);
1280 
1281  /// Add a string init step.
1282  void AddStringInitStep(QualType T);
1283 
1284  /// Add an Objective-C object conversion step, which is
1285  /// always a no-op.
1286  void AddObjCObjectConversionStep(QualType T);
1287 
1288  /// Add an array initialization loop step.
1289  void AddArrayInitLoopStep(QualType T, QualType EltTy);
1290 
1291  /// Add an array initialization step.
1292  void AddArrayInitStep(QualType T, bool IsGNUExtension);
1293 
1294  /// Add a parenthesized array initialization step.
1295  void AddParenthesizedArrayInitStep(QualType T);
1296 
1297  /// Add a step to pass an object by indirect copy-restore.
1298  void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy);
1299 
1300  /// Add a step to "produce" an Objective-C object (by
1301  /// retaining it).
1302  void AddProduceObjCObjectStep(QualType T);
1303 
1304  /// Add a step to construct a std::initializer_list object from an
1305  /// initializer list.
1306  void AddStdInitializerListConstructionStep(QualType T);
1307 
1308  /// Add a step to initialize an OpenCL sampler from an integer
1309  /// constant.
1310  void AddOCLSamplerInitStep(QualType T);
1311 
1312  /// Add a step to initialize an OpenCL event_t from a NULL
1313  /// constant.
1314  void AddOCLZeroEventStep(QualType T);
1315 
1316  /// Add a step to initialize an OpenCL queue_t from 0.
1317  void AddOCLZeroQueueStep(QualType T);
1318 
1319  /// Add steps to unwrap a initializer list for a reference around a
1320  /// single element and rewrap it at the end.
1321  void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
1322 
1323  /// Note that this initialization sequence failed.
1324  void SetFailed(FailureKind Failure) {
1325  SequenceKind = FailedSequence;
1326  this->Failure = Failure;
1327  assert((Failure != FK_Incomplete || !FailedIncompleteType.isNull()) &&
1328  "Incomplete type failure requires a type!");
1329  }
1330 
1331  /// Note that this initialization sequence failed due to failed
1332  /// overload resolution.
1333  void SetOverloadFailure(FailureKind Failure, OverloadingResult Result);
1334 
1335  /// Retrieve a reference to the candidate set when overload
1336  /// resolution fails.
1338  return FailedCandidateSet;
1339  }
1340 
1341  /// Get the overloading result, for when the initialization
1342  /// sequence failed due to a bad overload.
1344  return FailedOverloadResult;
1345  }
1346 
1347  /// Note that this initialization sequence failed due to an
1348  /// incomplete type.
1349  void setIncompleteTypeFailure(QualType IncompleteType) {
1350  FailedIncompleteType = IncompleteType;
1351  SetFailed(FK_Incomplete);
1352  }
1353 
1354  /// Determine why initialization failed.
1356  assert(Failed() && "Not an initialization failure!");
1357  return Failure;
1358  }
1359 
1360  /// Dump a representation of this initialization sequence to
1361  /// the given stream, for debugging purposes.
1362  void dump(raw_ostream &OS) const;
1363 
1364  /// Dump a representation of this initialization sequence to
1365  /// standard error, for debugging purposes.
1366  void dump() const;
1367 };
1368 
1369 } // namespace clang
1370 
1371 #endif // LLVM_CLANG_SEMA_INITIALIZATION_H
Perform a derived-to-base cast, producing an lvalue.
Defines the clang::ASTContext interface.
QualType getVariableArrayDecayedType(QualType Ty) const
Returns a vla type where known sizes are replaced with [*].
Represents a function declaration or definition.
Definition: Decl.h:1714
InitListExpr * WrappingSyntacticList
When Kind = SK_RewrapInitList, the syntactic form of the wrapping list.
step_iterator step_begin() const
static InitializationKind CreateDirectList(SourceLocation InitLoc, SourceLocation LBraceLoc, SourceLocation RBraceLoc)
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
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:655
unsigned Index
When Kind == EK_ArrayElement, EK_VectorElement, or EK_ComplexElement, the index of the array or vecto...
DeclarationName getName() const
Retrieve the name of the entity being initialized.
Definition: SemaInit.cpp:2985
Produce an Objective-C object pointer.
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.
C Language Family Type Representation.
static InitializedEntity InitializeMember(FieldDecl *Member, const InitializedEntity *Parent=nullptr, bool Implicit=false)
Create the initialization entity for a member subobject.
static InitializedEntity InitializeParameter(ASTContext &Context, const ParmVarDecl *Parm)
Create the initialization entity for a parameter.
uintptr_t Base
When Kind == EK_Base, the base specifier that provides the base class.
FailureKind getFailureKind() const
Determine why initialization failed.
static InitializationKind CreateDirect(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a direct initialization.
The base class of the type hierarchy.
Definition: Type.h:1421
The entity being initialized is a variable.
static InitializationKind CreateDefault(SourceLocation InitLoc)
Create a default initialization.
Overloading for a user-defined conversion failed.
TypeSourceInfo * getTypeSourceInfo() const
Retrieve complete type-source information for the object being constructed, if known.
A container of type source information.
Definition: Decl.h:86
Perform a derived-to-base cast, producing an xvalue.
SourceLocation getCaptureLoc() const
Determine the location of the capture when initializing field from a captured variable in a lambda...
constexpr XRayInstrMask Function
Definition: XRayInstr.h:39
The entity being initialized is a base member subobject.
List-copy-initialization chose an explicit constructor.
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2463
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.
static InitializedEntity InitializeBase(ASTContext &Context, const CXXBaseSpecifier *Base, bool IsInheritedVirtualBase, const InitializedEntity *Parent=nullptr)
Create the initialization entity for a base class subobject.
Definition: SemaInit.cpp:2970
Represents a variable declaration or definition.
Definition: Decl.h:812
Array initialization by elementwise copy.
SourceLocation getEqualLoc() const
Retrieve the location of the equal sign for copy initialization (if present).
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
Non-const lvalue reference binding to an lvalue of unrelated type.
SourceLocation getThrowLoc() const
Determine the location of the &#39;throw&#39; keyword when initializing an exception object.
static InitializedEntity InitializeResult(SourceLocation ReturnLoc, QualType Type, bool NRVO)
Create the initialization entity for the result of a function.
Perform a derived-to-base cast, producing an rvalue.
static InitializationKind CreateDirectList(SourceLocation InitLoc)
EntityKind getKind() const
Determine the kind of initialization.
Initializing char array with UTF-8 string literal.
void setElementIndex(unsigned Index)
If this is already the initializer for an array or vector element, sets the element index...
Represents a parameter to a function.
Definition: Decl.h:1533
The entity being initialized is a temporary object.
const CXXBaseSpecifier * getBaseSpecifier() const
Retrieve the base specifier.
Non-const lvalue reference binding to a vector element.
bool isImplicitMemberInitializer() const
Is this the implicit initialization of a member of a class from a defaulted constructor?
Construct a std::initializer_list from an initializer list.
Trying to take the address of a function that doesn&#39;t support having its address taken.
One of these records is kept for each identifier that is lexed.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:150
static InitializationKind CreateForInit(SourceLocation Loc, bool DirectInit, Expr *Init)
Create an initialization from an initializer (which, for direct initialization from a parenthesized l...
bool isInheritedVirtualBase() const
Return whether the base is an inherited virtual base.
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.
Represents a member of a struct/union/class.
Definition: Decl.h:2521
Rewrap the single-element initializer list for a reference.
FieldDecl * getAnonField() const
Definition: Decl.h:2797
int Category
Definition: Format.cpp:1601
StringRef getCapturedVarName() const
For a lambda capture, return the capture&#39;s name.
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:3952
static InitializedEntity InitializeTemporary(TypeSourceInfo *TypeInfo)
Create the initialization entity for a temporary.
SourceRange getParenOrBraceRange() const
Retrieve the source range containing the locations of the open and closing parentheses or braces for ...
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.
bool isImplicitValueInit() const
Determine whether this initialization is an implicit value-initialization, e.g., as occurs during agg...
static InitializedEntity InitializeLambdaToBlock(SourceLocation BlockVarLoc, QualType Type, bool NRVO)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type...
Definition: Type.h:6505
OverloadCandidateSet & getFailedCandidateSet()
Retrieve a reference to the candidate set when overload resolution fails.
unsigned getElementIndex() const
If this is an array, vector, or complex number element, get the element&#39;s index.
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.
SmallVectorImpl< Step >::const_iterator step_iterator
The entity being initialized is an element of a vector.
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.
bool hasParenOrBraceRange() const
Determine whether this initialization has a source range containing the locations of open and closing...
ValueDecl * getDecl() const
Retrieve the variable, parameter, or field being initialized.
Definition: SemaInit.cpp:3020
static InitializedEntity InitializeNew(SourceLocation NewLoc, QualType Type)
Create the initialization entity for an object allocated via new.
NodeId Parent
Definition: ASTDiff.cpp:192
Perform an implicit conversion sequence.
bool hasAttr() const
Definition: DeclBase.h:536
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:276
Overloading for list-initialization by constructor failed.
Perform list-initialization without a constructor.
Non-const lvalue reference binding to a bit-field.
Cannot resolve the address of an overloaded function.
SourceLocation getLocEnd() const LLVM_READONLY
Definition: Stmt.cpp:291
static InitializedEntity InitializeTemporary(TypeSourceInfo *TypeInfo, QualType Type)
Create the initialization entity for a temporary.
bool isFunctionalCast() const
Determine whether this is a functional-style cast.
unsigned allocateManglingNumber() const
The entity being initialized is a field of block descriptor for the copied-in c++ object...
static InitializedEntity InitializeMember(IndirectFieldDecl *Member, const InitializedEntity *Parent=nullptr, bool Implicit=false)
Create the initialization entity for a member subobject.
Initializing wide char array with incompatible wide string literal.
The entity being initialized is the real or imaginary part of a complex number.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:636
Expr - This represents one expression.
Definition: Expr.h:106
Defines the clang::LangOptions interface.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:107
Initializing char8_t array with plain string literal.
static InitializationKind CreateFunctionalCast(SourceRange TypeRange, bool InitList)
Create a direct initialization for a functional cast.
const FunctionProtoType * T
void dump() const
Dump a representation of the initialized entity to standard error, for debugging purposes.
Definition: SemaInit.cpp:3124
Scalar initialized from a parenthesized initializer list.
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.
OverloadingResult getFailedOverloadResult() const
Get the overloading result, for when the initialization sequence failed due to a bad overload...
static InitializedEntity InitializeVariable(VarDecl *Var)
Create the initialization entity for a variable.
Initializing a wide char array with narrow string literal.
#define bool
Definition: stdbool.h:31
Resolve the address of an overloaded function to a specific function declaration. ...
The entity being initialized is an exception object that is being thrown.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
bool isExplicitCast() const
Determine whether this initialization is an explicit cast.
Initializer has a placeholder type which cannot be resolved by initialization.
SourceLocation getEnd() const
SourceLocation getLocation() const
Retrieve the location at which initialization is occurring.
bool AllowExplicit() const
Retrieve whether this initialization allows the use of explicit constructors.
SourceLocation getReturnLoc() const
Determine the location of the &#39;return&#39; keyword when initializing the result of a function call...
The result type of a method or function.
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:720
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Definition: opencl-c.h:82
InitKind getKind() const
Determine the initialization kind.
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.
bool allowExplicitConversionFunctionsInRefBinding() const
Retrieve whether this initialization allows the use of explicit conversion functions when binding a r...
Perform a qualification conversion, producing an lvalue.
Kind
ImplicitConversionSequence - Represents an implicit conversion sequence, which may be a standard conv...
Definition: Overload.h:487
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Definition: Ownership.h:157
bool allowsNRVO() const
Determine whether this initialization allows the named return value optimization, which also applies ...
Definition: SemaInit.cpp:3051
SequenceKind
Describes the kind of initialization sequence computed.
Array indexing for initialization by elementwise copy.
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.
bool isCStyleOrFunctionalCast() const
Determine whether this initialization is a C-style cast.
StepKind
Describes the kind of a particular step in an initialization sequence.
llvm::iterator_range< step_iterator > step_range
TypeSourceInfo * TypeInfo
When Kind == EK_Temporary or EK_CompoundLiteralInit, the type source information for the temporary...
OverloadingResult
OverloadingResult - Capture the result of performing overload resolution.
Definition: Overload.h:52
VD Variable
When Kind == EK_Variable, EK_Member or EK_Binding, the variable.
static InitializedEntity InitializeElement(ASTContext &Context, unsigned Index, const InitializedEntity &Parent)
Create the initialization entity for an array element.
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.
Describes the kind of initialization being performed, along with location information for tokens rela...
The entity being initialized is an element of an array.
Reference initialized from a parenthesized initializer list.
Overloading for initialization by constructor failed.
An optional copy of a temporary object to another temporary object, which is permitted (but not requi...
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13...
Definition: Overload.h:830
static InitializationKind CreateCast(SourceRange TypeRange)
Create a direct initialization due to a cast that isn&#39;t a C-style or functional cast.
Pass an object by indirect copy-and-restore.
Defines various enumerations that describe declaration and type specifiers.
A POD class for pairing a NamedDecl* with an access specifier.
void SetFailed(FailureKind Failure)
Note that this initialization sequence failed.
Array must be initialized with an initializer list or a string literal.
QualType getType() const
Retrieve type being initialized.
Dataflow Directional Tag Classes.
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.
Represents a field injected from an anonymous union/struct into the parent scope. ...
Definition: Decl.h:2767
const InitializedEntity * getParent() const
Retrieve the parent of the entity being initialized, when the initialization itself is occurring with...
DeclarationName - The name of a declaration.
Array initialization (from an array rvalue) as a GNU extension.
static InitializationKind CreateCStyleCast(SourceLocation StartLoc, SourceRange TypeRange, bool InitList)
Create a direct initialization for a C-style cast.
Overloading due to reference initialization failed.
Array must be initialized with an initializer list.
The entity being initialized is a structured binding of a decomposition declaration.
step_iterator step_end() const
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:192
Direct-initialization from a reference-related object in the final stage of class copy-initialization...
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:5905
Perform initialization via a constructor, taking arguments from a single InitListExpr.
SourceRange getRange() const
Retrieve the source range that covers the initialization.
bool isParameterConsumed() const
Determine whether this initialization consumes the parameter.
The entity being initialized is a field of block descriptor for the copied-in lambda object that&#39;s us...
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...
bool isCStyleCast() const
Determine whether this is a C-style cast.
ObjCMethodDecl * MethodDecl
When Kind == EK_RelatedResult, the ObjectiveC method where result type was implicitly changed to acco...
The initialization is being done by a delegating constructor.
Array initialization (from an array rvalue).
InitKind
The kind of initialization being performed.
QualType getType() const
Definition: Decl.h:647
static InitializedEntity InitializeParameter(ASTContext &Context, const ParmVarDecl *Parm, QualType Type)
Create the initialization entity for a parameter, but use another type.
Default-initialization of a &#39;const&#39; object.
A trivial tuple used to represent a source range.
Describes an entity that is being initialized.
ObjCMethodDecl * getMethodDecl() const
Retrieve the ObjectiveC method being initialized.
SourceLocation getLocStart() const LLVM_READONLY
Definition: Stmt.cpp:278
SourceLocation getBegin() const
const LangOptions & getLangOpts() const
Definition: ASTContext.h:689
bool isVariableLengthArrayNew() const
Determine whether this is an array new with an unknown bound.
Direct list-initialization.
Array initialization from a parenthesized initializer list.
static InitializedEntity InitializeBinding(VarDecl *Binding)
Create the initialization entity for a structured binding.
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:97