clang  7.0.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 
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.
49 class alignas(8) InitializedEntity {
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 the result of a statement expression.
64 
65  /// The entity being initialized is an exception object that
66  /// is being thrown.
68 
69  /// The entity being initialized is a non-static data member
70  /// subobject.
72 
73  /// The entity being initialized is an element of an array.
75 
76  /// The entity being initialized is an object (or array of
77  /// objects) allocated via new.
79 
80  /// The entity being initialized is a temporary object.
82 
83  /// The entity being initialized is a base member subobject.
85 
86  /// The initialization is being done by a delegating constructor.
88 
89  /// The entity being initialized is an element of a vector.
90  /// or vector.
92 
93  /// The entity being initialized is a field of block descriptor for
94  /// the copied-in c++ object.
96 
97  /// The entity being initialized is a field of block descriptor for the
98  /// copied-in lambda object that's used in the lambda to block conversion.
100 
101  /// The entity being initialized is the real or imaginary part of a
102  /// complex number.
104 
105  /// The entity being initialized is the field that captures a
106  /// variable in a lambda.
108 
109  /// The entity being initialized is the initializer for a compound
110  /// literal.
112 
113  /// The entity being implicitly initialized back to the formal
114  /// result type.
116 
117  /// The entity being initialized is a function parameter; function
118  /// is member of group of audited CF APIs.
120 
121  /// The entity being initialized is a structured binding of a
122  /// decomposition declaration.
124 
125  // Note: err_init_conversion_failed in DiagnosticSemaKinds.td uses this
126  // enum as an index for its first %select. When modifying this list,
127  // that diagnostic text needs to be updated as well.
128  };
129 
130 private:
131  /// The kind of entity being initialized.
133 
134  /// If non-NULL, the parent entity in which this
135  /// initialization occurs.
136  const InitializedEntity *Parent = nullptr;
137 
138  /// The type of the object or reference being initialized.
139  QualType Type;
140 
141  /// The mangling number for the next reference temporary to be created.
142  mutable unsigned ManglingNumber = 0;
143 
144  struct LN {
145  /// When Kind == EK_Result, EK_Exception, EK_New, the
146  /// location of the 'return', 'throw', or 'new' keyword,
147  /// respectively. When Kind == EK_Temporary, the location where
148  /// the temporary is being created.
149  unsigned Location;
150 
151  /// Whether the entity being initialized may end up using the
152  /// named return value optimization (NRVO).
153  bool NRVO;
154  };
155 
156  struct VD {
157  /// The VarDecl, FieldDecl, or BindingDecl being initialized.
158  ValueDecl *VariableOrMember;
159 
160  /// When Kind == EK_Member, whether this is an implicit member
161  /// initialization in a copy or move constructor. These can perform array
162  /// copies.
163  bool IsImplicitFieldInit;
164 
165  /// When Kind == EK_Member, whether this is the initial initialization
166  /// check for a default member initializer.
167  bool IsDefaultMemberInit;
168  };
169 
170  struct C {
171  /// The name of the variable being captured by an EK_LambdaCapture.
172  IdentifierInfo *VarID;
173 
174  /// The source location at which the capture occurs.
175  unsigned Location;
176  };
177 
178  union {
179  /// When Kind == EK_Variable, EK_Member or EK_Binding, the variable.
181 
182  /// When Kind == EK_RelatedResult, the ObjectiveC method where
183  /// result type was implicitly changed to accommodate ARC semantics.
185 
186  /// When Kind == EK_Parameter, the ParmVarDecl, with the
187  /// low bit indicating whether the parameter is "consumed".
189 
190  /// When Kind == EK_Temporary or EK_CompoundLiteralInit, the type
191  /// source information for the temporary.
193 
194  struct LN LocAndNRVO;
195 
196  /// When Kind == EK_Base, the base specifier that provides the
197  /// base class. The lower bit specifies whether the base is an inherited
198  /// virtual base.
200 
201  /// When Kind == EK_ArrayElement, EK_VectorElement, or
202  /// EK_ComplexElement, the index of the array or vector element being
203  /// initialized.
204  unsigned Index;
205 
206  struct C Capture;
207  };
208 
209  InitializedEntity() = default;
210 
211  /// Create the initialization entity for a variable.
213  : Kind(EK), Type(Var->getType()), Variable{Var, false, false} {}
214 
215  /// Create the initialization entity for the result of a
216  /// function, throwing an object, performing an explicit cast, or
217  /// initializing a parameter for which there is no declaration.
219  bool NRVO = false)
220  : Kind(Kind), Type(Type) {
221  LocAndNRVO.Location = Loc.getRawEncoding();
222  LocAndNRVO.NRVO = NRVO;
223  }
224 
225  /// Create the initialization entity for a member subobject.
226  InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent,
227  bool Implicit, bool DefaultMemberInit)
228  : Kind(EK_Member), Parent(Parent), Type(Member->getType()),
229  Variable{Member, Implicit, DefaultMemberInit} {}
230 
231  /// Create the initialization entity for an array element.
232  InitializedEntity(ASTContext &Context, unsigned Index,
233  const InitializedEntity &Parent);
234 
235  /// Create the initialization entity for a lambda capture.
237  : Kind(EK_LambdaCapture), Type(FieldType) {
238  Capture.VarID = VarID;
239  Capture.Location = Loc.getRawEncoding();
240  }
241 
242 public:
243  /// Create the initialization entity for a variable.
245  return InitializedEntity(Var);
246  }
247 
248  /// Create the initialization entity for a parameter.
250  const ParmVarDecl *Parm) {
251  return InitializeParameter(Context, Parm, Parm->getType());
252  }
253 
254  /// Create the initialization entity for a parameter, but use
255  /// another type.
257  const ParmVarDecl *Parm,
258  QualType Type) {
259  bool Consumed = (Context.getLangOpts().ObjCAutoRefCount &&
260  Parm->hasAttr<NSConsumedAttr>());
261 
262  InitializedEntity Entity;
263  Entity.Kind = EK_Parameter;
264  Entity.Type =
266  Entity.Parent = nullptr;
267  Entity.Parameter
268  = (static_cast<uintptr_t>(Consumed) | reinterpret_cast<uintptr_t>(Parm));
269  return Entity;
270  }
271 
272  /// Create the initialization entity for a parameter that is
273  /// only known by its type.
275  QualType Type,
276  bool Consumed) {
277  InitializedEntity Entity;
278  Entity.Kind = EK_Parameter;
279  Entity.Type = Context.getVariableArrayDecayedType(Type);
280  Entity.Parent = nullptr;
281  Entity.Parameter = (Consumed);
282  return Entity;
283  }
284 
285  /// Create the initialization entity for the result of a function.
287  QualType Type, bool NRVO) {
288  return InitializedEntity(EK_Result, ReturnLoc, Type, NRVO);
289  }
290 
292  QualType Type) {
293  return InitializedEntity(EK_StmtExprResult, ReturnLoc, Type);
294  }
295 
297  QualType Type, bool NRVO) {
298  return InitializedEntity(EK_BlockElement, BlockVarLoc, Type, NRVO);
299  }
300 
302  QualType Type, bool NRVO) {
304  BlockVarLoc, Type, NRVO);
305  }
306 
307  /// Create the initialization entity for an exception object.
309  QualType Type, bool NRVO) {
310  return InitializedEntity(EK_Exception, ThrowLoc, Type, NRVO);
311  }
312 
313  /// Create the initialization entity for an object allocated via new.
315  return InitializedEntity(EK_New, NewLoc, Type);
316  }
317 
318  /// Create the initialization entity for a temporary.
320  return InitializeTemporary(nullptr, Type);
321  }
322 
323  /// Create the initialization entity for a temporary.
325  return InitializeTemporary(TypeInfo, TypeInfo->getType());
326  }
327 
328  /// Create the initialization entity for a temporary.
330  QualType Type) {
332  Result.TypeInfo = TypeInfo;
333  return Result;
334  }
335 
336  /// Create the initialization entity for a related result.
338  QualType Type) {
340  Result.MethodDecl = MD;
341  return Result;
342  }
343 
344  /// Create the initialization entity for a base class subobject.
345  static InitializedEntity
347  bool IsInheritedVirtualBase,
348  const InitializedEntity *Parent = nullptr);
349 
350  /// Create the initialization entity for a delegated constructor.
353  }
354 
355  /// Create the initialization entity for a member subobject.
356  static InitializedEntity
358  const InitializedEntity *Parent = nullptr,
359  bool Implicit = false) {
360  return InitializedEntity(Member, Parent, Implicit, false);
361  }
362 
363  /// Create the initialization entity for a member subobject.
364  static InitializedEntity
366  const InitializedEntity *Parent = nullptr,
367  bool Implicit = false) {
368  return InitializedEntity(Member->getAnonField(), Parent, Implicit, false);
369  }
370 
371  /// Create the initialization entity for a default member initializer.
372  static InitializedEntity
374  return InitializedEntity(Member, nullptr, false, true);
375  }
376 
377  /// Create the initialization entity for an array element.
379  unsigned Index,
380  const InitializedEntity &Parent) {
381  return InitializedEntity(Context, Index, Parent);
382  }
383 
384  /// Create the initialization entity for a structured binding.
386  return InitializedEntity(Binding, EK_Binding);
387  }
388 
389  /// Create the initialization entity for a lambda capture.
391  QualType FieldType,
392  SourceLocation Loc) {
393  return InitializedEntity(VarID, FieldType, Loc);
394  }
395 
396  /// Create the entity for a compound literal initializer.
399  TSI->getType());
400  Result.TypeInfo = TSI;
401  return Result;
402  }
403 
404  /// Determine the kind of initialization.
405  EntityKind getKind() const { return Kind; }
406 
407  /// Retrieve the parent of the entity being initialized, when
408  /// the initialization itself is occurring within the context of a
409  /// larger initialization.
410  const InitializedEntity *getParent() const { return Parent; }
411 
412  /// Retrieve type being initialized.
413  QualType getType() const { return Type; }
414 
415  /// Retrieve complete type-source information for the object being
416  /// constructed, if known.
418  if (Kind == EK_Temporary || Kind == EK_CompoundLiteralInit)
419  return TypeInfo;
420 
421  return nullptr;
422  }
423 
424  /// Retrieve the name of the entity being initialized.
425  DeclarationName getName() const;
426 
427  /// Retrieve the variable, parameter, or field being
428  /// initialized.
429  ValueDecl *getDecl() const;
430 
431  /// Retrieve the ObjectiveC method being initialized.
433 
434  /// Determine whether this initialization allows the named return
435  /// value optimization, which also applies to thrown objects.
436  bool allowsNRVO() const;
437 
438  bool isParameterKind() const {
439  return (getKind() == EK_Parameter ||
441  }
442 
443  /// Determine whether this initialization consumes the
444  /// parameter.
445  bool isParameterConsumed() const {
446  assert(isParameterKind() && "Not a parameter");
447  return (Parameter & 1);
448  }
449 
450  /// Retrieve the base specifier.
452  assert(getKind() == EK_Base && "Not a base specifier");
453  return reinterpret_cast<const CXXBaseSpecifier *>(Base & ~0x1);
454  }
455 
456  /// Return whether the base is an inherited virtual base.
457  bool isInheritedVirtualBase() const {
458  assert(getKind() == EK_Base && "Not a base specifier");
459  return Base & 0x1;
460  }
461 
462  /// Determine whether this is an array new with an unknown bound.
464  return getKind() == EK_New && dyn_cast_or_null<IncompleteArrayType>(
466  }
467 
468  /// Is this the implicit initialization of a member of a class from
469  /// a defaulted constructor?
471  return getKind() == EK_Member && Variable.IsImplicitFieldInit;
472  }
473 
474  /// Is this the default member initializer of a member (specified inside
475  /// the class definition)?
477  return getKind() == EK_Member && Variable.IsDefaultMemberInit;
478  }
479 
480  /// Determine the location of the 'return' keyword when initializing
481  /// the result of a function call.
483  assert(getKind() == EK_Result && "No 'return' location!");
485  }
486 
487  /// Determine the location of the 'throw' keyword when initializing
488  /// an exception object.
490  assert(getKind() == EK_Exception && "No 'throw' location!");
492  }
493 
494  /// If this is an array, vector, or complex number element, get the
495  /// element's index.
496  unsigned getElementIndex() const {
497  assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
499  return Index;
500  }
501 
502  /// If this is already the initializer for an array or vector
503  /// element, sets the element index.
504  void setElementIndex(unsigned Index) {
505  assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
507  this->Index = Index;
508  }
509 
510  /// For a lambda capture, return the capture's name.
511  StringRef getCapturedVarName() const {
512  assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
513  return Capture.VarID->getName();
514  }
515 
516  /// Determine the location of the capture when initializing
517  /// field from a captured variable in a lambda.
519  assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
520  return SourceLocation::getFromRawEncoding(Capture.Location);
521  }
522 
525  }
526 
527  unsigned allocateManglingNumber() const { return ++ManglingNumber; }
528 
529  /// Dump a representation of the initialized entity to standard error,
530  /// for debugging purposes.
531  void dump() const;
532 
533 private:
534  unsigned dumpImpl(raw_ostream &OS) const;
535 };
536 
537 /// Describes the kind of initialization being performed, along with
538 /// location information for tokens related to the initialization (equal sign,
539 /// parentheses).
541 public:
542  /// The kind of initialization being performed.
543  enum InitKind {
544  /// Direct initialization
546 
547  /// Direct list-initialization
549 
550  /// Copy initialization
552 
553  /// Default initialization
555 
556  /// Value initialization
557  IK_Value
558  };
559 
560 private:
561  /// The context of the initialization.
562  enum InitContext {
563  /// Normal context
564  IC_Normal,
565 
566  /// Normal context, but allows explicit conversion functionss
567  IC_ExplicitConvs,
568 
569  /// Implicit context (value initialization)
570  IC_Implicit,
571 
572  /// Static cast context
573  IC_StaticCast,
574 
575  /// C-style cast context
576  IC_CStyleCast,
577 
578  /// Functional cast context
579  IC_FunctionalCast
580  };
581 
582  /// The kind of initialization being performed.
583  InitKind Kind : 8;
584 
585  /// The context of the initialization.
586  InitContext Context : 8;
587 
588  /// The source locations involved in the initialization.
589  SourceLocation Locations[3];
590 
591  InitializationKind(InitKind Kind, InitContext Context, SourceLocation Loc1,
592  SourceLocation Loc2, SourceLocation Loc3)
593  : Kind(Kind), Context(Context) {
594  Locations[0] = Loc1;
595  Locations[1] = Loc2;
596  Locations[2] = Loc3;
597  }
598 
599 public:
600  /// Create a direct initialization.
602  SourceLocation LParenLoc,
603  SourceLocation RParenLoc) {
604  return InitializationKind(IK_Direct, IC_Normal,
605  InitLoc, LParenLoc, RParenLoc);
606  }
607 
609  return InitializationKind(IK_DirectList, IC_Normal, InitLoc, InitLoc,
610  InitLoc);
611  }
612 
614  SourceLocation LBraceLoc,
615  SourceLocation RBraceLoc) {
616  return InitializationKind(IK_DirectList, IC_Normal, InitLoc, LBraceLoc,
617  RBraceLoc);
618  }
619 
620  /// Create a direct initialization due to a cast that isn't a C-style
621  /// or functional cast.
623  return InitializationKind(IK_Direct, IC_StaticCast, TypeRange.getBegin(),
624  TypeRange.getBegin(), TypeRange.getEnd());
625  }
626 
627  /// Create a direct initialization for a C-style cast.
629  SourceRange TypeRange,
630  bool InitList) {
631  // C++ cast syntax doesn't permit init lists, but C compound literals are
632  // exactly that.
633  return InitializationKind(InitList ? IK_DirectList : IK_Direct,
634  IC_CStyleCast, StartLoc, TypeRange.getBegin(),
635  TypeRange.getEnd());
636  }
637 
638  /// Create a direct initialization for a functional cast.
640  bool InitList) {
641  return InitializationKind(InitList ? IK_DirectList : IK_Direct,
642  IC_FunctionalCast, TypeRange.getBegin(),
643  TypeRange.getBegin(), TypeRange.getEnd());
644  }
645 
646  /// Create a copy initialization.
648  SourceLocation EqualLoc,
649  bool AllowExplicitConvs = false) {
650  return InitializationKind(IK_Copy,
651  AllowExplicitConvs? IC_ExplicitConvs : IC_Normal,
652  InitLoc, EqualLoc, EqualLoc);
653  }
654 
655  /// Create a default initialization.
657  return InitializationKind(IK_Default, IC_Normal, InitLoc, InitLoc, InitLoc);
658  }
659 
660  /// Create a value initialization.
662  SourceLocation LParenLoc,
663  SourceLocation RParenLoc,
664  bool isImplicit = false) {
665  return InitializationKind(IK_Value, isImplicit ? IC_Implicit : IC_Normal,
666  InitLoc, LParenLoc, RParenLoc);
667  }
668 
669  /// Create an initialization from an initializer (which, for direct
670  /// initialization from a parenthesized list, will be a ParenListExpr).
672  Expr *Init) {
673  if (!Init) return CreateDefault(Loc);
674  if (!DirectInit) return CreateCopy(Loc, Init->getLocStart());
675  if (isa<InitListExpr>(Init))
676  return CreateDirectList(Loc, Init->getLocStart(), Init->getLocEnd());
677  return CreateDirect(Loc, Init->getLocStart(), Init->getLocEnd());
678  }
679 
680  /// Determine the initialization kind.
681  InitKind getKind() const {
682  return Kind;
683  }
684 
685  /// Determine whether this initialization is an explicit cast.
686  bool isExplicitCast() const {
687  return Context >= IC_StaticCast;
688  }
689 
690  /// Determine whether this initialization is a C-style cast.
692  return Context >= IC_CStyleCast;
693  }
694 
695  /// Determine whether this is a C-style cast.
696  bool isCStyleCast() const {
697  return Context == IC_CStyleCast;
698  }
699 
700  /// Determine whether this is a functional-style cast.
701  bool isFunctionalCast() const {
702  return Context == IC_FunctionalCast;
703  }
704 
705  /// Determine whether this initialization is an implicit
706  /// value-initialization, e.g., as occurs during aggregate
707  /// initialization.
708  bool isImplicitValueInit() const { return Context == IC_Implicit; }
709 
710  /// Retrieve the location at which initialization is occurring.
711  SourceLocation getLocation() const { return Locations[0]; }
712 
713  /// Retrieve the source range that covers the initialization.
715  return SourceRange(Locations[0], Locations[2]);
716  }
717 
718  /// Retrieve the location of the equal sign for copy initialization
719  /// (if present).
721  assert(Kind == IK_Copy && "Only copy initialization has an '='");
722  return Locations[1];
723  }
724 
725  bool isCopyInit() const { return Kind == IK_Copy; }
726 
727  /// Retrieve whether this initialization allows the use of explicit
728  /// constructors.
729  bool AllowExplicit() const { return !isCopyInit(); }
730 
731  /// Retrieve whether this initialization allows the use of explicit
732  /// conversion functions when binding a reference. If the reference is the
733  /// first parameter in a copy or move constructor, such conversions are
734  /// permitted even though we are performing copy-initialization.
736  return !isCopyInit() || Context == IC_ExplicitConvs;
737  }
738 
739  /// Determine whether this initialization has a source range containing the
740  /// locations of open and closing parentheses or braces.
741  bool hasParenOrBraceRange() const {
742  return Kind == IK_Direct || Kind == IK_Value || Kind == IK_DirectList;
743  }
744 
745  /// Retrieve the source range containing the locations of the open
746  /// and closing parentheses or braces for value, direct, and direct list
747  /// initializations.
749  assert(hasParenOrBraceRange() && "Only direct, value, and direct-list "
750  "initialization have parentheses or "
751  "braces");
752  return SourceRange(Locations[1], Locations[2]);
753  }
754 };
755 
756 /// Describes the sequence of initializations required to initialize
757 /// a given object or reference with a set of arguments.
759 public:
760  /// Describes the kind of initialization sequence computed.
762  /// A failed initialization sequence. The failure kind tells what
763  /// happened.
764  FailedSequence = 0,
765 
766  /// A dependent initialization, which could not be
767  /// type-checked due to the presence of dependent types or
768  /// dependently-typed expressions.
770 
771  /// A normal sequence.
772  NormalSequence
773  };
774 
775  /// Describes the kind of a particular step in an initialization
776  /// sequence.
777  enum StepKind {
778  /// Resolve the address of an overloaded function to a specific
779  /// function declaration.
781 
782  /// Perform a derived-to-base cast, producing an rvalue.
784 
785  /// Perform a derived-to-base cast, producing an xvalue.
787 
788  /// Perform a derived-to-base cast, producing an lvalue.
790 
791  /// Reference binding to an lvalue.
793 
794  /// Reference binding to a temporary.
796 
797  /// An optional copy of a temporary object to another
798  /// temporary object, which is permitted (but not required) by
799  /// C++98/03 but not C++0x.
801 
802  /// Direct-initialization from a reference-related object in the
803  /// final stage of class copy-initialization.
805 
806  /// Perform a user-defined conversion, either via a conversion
807  /// function or via a constructor.
809 
810  /// Perform a qualification conversion, producing an rvalue.
812 
813  /// Perform a qualification conversion, producing an xvalue.
815 
816  /// Perform a qualification conversion, producing an lvalue.
818 
819  /// Perform a conversion adding _Atomic to a type.
821 
822  /// Perform a load from a glvalue, producing an rvalue.
824 
825  /// Perform an implicit conversion sequence.
827 
828  /// Perform an implicit conversion sequence without narrowing.
830 
831  /// Perform list-initialization without a constructor.
833 
834  /// Unwrap the single-element initializer list for a reference.
836 
837  /// Rewrap the single-element initializer list for a reference.
839 
840  /// Perform initialization via a constructor.
842 
843  /// Perform initialization via a constructor, taking arguments from
844  /// a single InitListExpr.
846 
847  /// Zero-initialize the object
849 
850  /// C assignment
852 
853  /// Initialization by string
855 
856  /// An initialization that "converts" an Objective-C object
857  /// (not a point to an object) to another Objective-C object type.
859 
860  /// Array indexing for initialization by elementwise copy.
862 
863  /// Array initialization by elementwise copy.
865 
866  /// Array initialization (from an array rvalue).
868 
869  /// Array initialization (from an array rvalue) as a GNU extension.
871 
872  /// Array initialization from a parenthesized initializer list.
873  /// This is a GNU C++ extension.
875 
876  /// Pass an object by indirect copy-and-restore.
878 
879  /// Pass an object by indirect restore.
881 
882  /// Produce an Objective-C object pointer.
884 
885  /// Construct a std::initializer_list from an initializer list.
887 
888  /// Perform initialization via a constructor taking a single
889  /// std::initializer_list argument.
891 
892  /// Initialize an OpenCL sampler from an integer.
894 
895  /// Initialize queue_t from 0.
897 
898  /// Passing zero to a function where OpenCL event_t is expected.
899  SK_OCLZeroEvent
900  };
901 
902  /// A single step in the initialization sequence.
903  class Step {
904  public:
905  /// The kind of conversion or initialization step we are taking.
907 
908  // The type that results from this initialization.
910 
911  struct F {
915  };
916 
917  union {
918  /// When Kind == SK_ResolvedOverloadedFunction or Kind ==
919  /// SK_UserConversion, the function that the expression should be
920  /// resolved to or the conversion function to call, respectively.
921  /// When Kind == SK_ConstructorInitialization or SK_ListConstruction,
922  /// the constructor to be called.
923  ///
924  /// Always a FunctionDecl, plus a Boolean flag telling if it was
925  /// selected from an overloaded set having size greater than 1.
926  /// For conversion decls, the naming class is the source type.
927  /// For construct decls, the naming class is the target type.
928  struct F Function;
929 
930  /// When Kind = SK_ConversionSequence, the implicit conversion
931  /// sequence.
933 
934  /// When Kind = SK_RewrapInitList, the syntactic form of the
935  /// wrapping list.
937  };
938 
939  void Destroy();
940  };
941 
942 private:
943  /// The kind of initialization sequence computed.
945 
946  /// Steps taken by this initialization.
947  SmallVector<Step, 4> Steps;
948 
949 public:
950  /// Describes why initialization failed.
951  enum FailureKind {
952  /// Too many initializers provided for a reference.
954 
955  /// Reference initialized from a parenthesized initializer list.
957 
958  /// Array must be initialized with an initializer list.
960 
961  /// Array must be initialized with an initializer list or a
962  /// string literal.
964 
965  /// Array must be initialized with an initializer list or a
966  /// wide string literal.
968 
969  /// Initializing a wide char array with narrow string literal.
971 
972  /// Initializing char array with wide string literal.
974 
975  /// Initializing wide char array with incompatible wide string
976  /// literal.
978 
979  /// Initializing char8_t array with plain string literal.
981 
982  /// Initializing char array with UTF-8 string literal.
984 
985  /// Array type mismatch.
987 
988  /// Non-constant array initializer
990 
991  /// Cannot resolve the address of an overloaded function.
993 
994  /// Overloading due to reference initialization failed.
996 
997  /// Non-const lvalue reference binding to a temporary.
999 
1000  /// Non-const lvalue reference binding to a bit-field.
1002 
1003  /// Non-const lvalue reference binding to a vector element.
1005 
1006  /// Non-const lvalue reference binding to an lvalue of unrelated
1007  /// type.
1009 
1010  /// Rvalue reference binding to an lvalue.
1012 
1013  /// Reference binding drops qualifiers.
1015 
1016  /// Reference binding failed.
1018 
1019  /// Implicit conversion failed.
1021 
1022  /// Implicit conversion failed.
1024 
1025  /// Too many initializers for scalar
1027 
1028  /// Scalar initialized from a parenthesized initializer list.
1030 
1031  /// Reference initialization from an initializer list
1033 
1034  /// Initialization of some unused destination type with an
1035  /// initializer list.
1037 
1038  /// Overloading for a user-defined conversion failed.
1040 
1041  /// Overloading for initialization by constructor failed.
1043 
1044  /// Overloading for list-initialization by constructor failed.
1046 
1047  /// Default-initialization of a 'const' object.
1049 
1050  /// Initialization of an incomplete type.
1052 
1053  /// Variable-length array must not have an initializer.
1055 
1056  /// List initialization failed at some point.
1058 
1059  /// Initializer has a placeholder type which cannot be
1060  /// resolved by initialization.
1062 
1063  /// Trying to take the address of a function that doesn't support
1064  /// having its address taken.
1066 
1067  /// List-copy-initialization chose an explicit constructor.
1069  };
1070 
1071 private:
1072  /// The reason why initialization failed.
1073  FailureKind Failure;
1074 
1075  /// The failed result of overload resolution.
1076  OverloadingResult FailedOverloadResult;
1077 
1078  /// The candidate set created when initialization failed.
1079  OverloadCandidateSet FailedCandidateSet;
1080 
1081  /// The incomplete type that caused a failure.
1082  QualType FailedIncompleteType;
1083 
1084  /// The fixit that needs to be applied to make this initialization
1085  /// succeed.
1086  std::string ZeroInitializationFixit;
1087  SourceLocation ZeroInitializationFixitLoc;
1088 
1089 public:
1090  /// Call for initializations are invalid but that would be valid
1091  /// zero initialzations if Fixit was applied.
1092  void SetZeroInitializationFixit(const std::string& Fixit, SourceLocation L) {
1093  ZeroInitializationFixit = Fixit;
1094  ZeroInitializationFixitLoc = L;
1095  }
1096 
1097 private:
1098  /// Prints a follow-up note that highlights the location of
1099  /// the initialized entity, if it's remote.
1100  void PrintInitLocationNote(Sema &S, const InitializedEntity &Entity);
1101 
1102 public:
1103  /// Try to perform initialization of the given entity, creating a
1104  /// record of the steps required to perform the initialization.
1105  ///
1106  /// The generated initialization sequence will either contain enough
1107  /// information to diagnose
1108  ///
1109  /// \param S the semantic analysis object.
1110  ///
1111  /// \param Entity the entity being initialized.
1112  ///
1113  /// \param Kind the kind of initialization being performed.
1114  ///
1115  /// \param Args the argument(s) provided for initialization.
1116  ///
1117  /// \param TopLevelOfInitList true if we are initializing from an expression
1118  /// at the top level inside an initializer list. This disallows
1119  /// narrowing conversions in C++11 onwards.
1120  /// \param TreatUnavailableAsInvalid true if we want to treat unavailable
1121  /// as invalid.
1123  const InitializedEntity &Entity,
1124  const InitializationKind &Kind,
1125  MultiExprArg Args,
1126  bool TopLevelOfInitList = false,
1127  bool TreatUnavailableAsInvalid = true);
1128  void InitializeFrom(Sema &S, const InitializedEntity &Entity,
1129  const InitializationKind &Kind, MultiExprArg Args,
1130  bool TopLevelOfInitList, bool TreatUnavailableAsInvalid);
1131 
1133 
1134  /// Perform the actual initialization of the given entity based on
1135  /// the computed initialization sequence.
1136  ///
1137  /// \param S the semantic analysis object.
1138  ///
1139  /// \param Entity the entity being initialized.
1140  ///
1141  /// \param Kind the kind of initialization being performed.
1142  ///
1143  /// \param Args the argument(s) provided for initialization, ownership of
1144  /// which is transferred into the routine.
1145  ///
1146  /// \param ResultType if non-NULL, will be set to the type of the
1147  /// initialized object, which is the type of the declaration in most
1148  /// cases. However, when the initialized object is a variable of
1149  /// incomplete array type and the initializer is an initializer
1150  /// list, this type will be set to the completed array type.
1151  ///
1152  /// \returns an expression that performs the actual object initialization, if
1153  /// the initialization is well-formed. Otherwise, emits diagnostics
1154  /// and returns an invalid expression.
1155  ExprResult Perform(Sema &S,
1156  const InitializedEntity &Entity,
1157  const InitializationKind &Kind,
1158  MultiExprArg Args,
1159  QualType *ResultType = nullptr);
1160 
1161  /// Diagnose an potentially-invalid initialization sequence.
1162  ///
1163  /// \returns true if the initialization sequence was ill-formed,
1164  /// false otherwise.
1165  bool Diagnose(Sema &S,
1166  const InitializedEntity &Entity,
1167  const InitializationKind &Kind,
1168  ArrayRef<Expr *> Args);
1169 
1170  /// Determine the kind of initialization sequence computed.
1171  enum SequenceKind getKind() const { return SequenceKind; }
1172 
1173  /// Set the kind of sequence computed.
1174  void setSequenceKind(enum SequenceKind SK) { SequenceKind = SK; }
1175 
1176  /// Determine whether the initialization sequence is valid.
1177  explicit operator bool() const { return !Failed(); }
1178 
1179  /// Determine whether the initialization sequence is invalid.
1180  bool Failed() const { return SequenceKind == FailedSequence; }
1181 
1183 
1184  step_iterator step_begin() const { return Steps.begin(); }
1185  step_iterator step_end() const { return Steps.end(); }
1186 
1187  using step_range = llvm::iterator_range<step_iterator>;
1188 
1189  step_range steps() const { return {step_begin(), step_end()}; }
1190 
1191  /// Determine whether this initialization is a direct reference
1192  /// binding (C++ [dcl.init.ref]).
1193  bool isDirectReferenceBinding() const;
1194 
1195  /// Determine whether this initialization failed due to an ambiguity.
1196  bool isAmbiguous() const;
1197 
1198  /// Determine whether this initialization is direct call to a
1199  /// constructor.
1200  bool isConstructorInitialization() const;
1201 
1202  /// Returns whether the last step in this initialization sequence is a
1203  /// narrowing conversion, defined by C++0x [dcl.init.list]p7.
1204  ///
1205  /// If this function returns true, *isInitializerConstant will be set to
1206  /// describe whether *Initializer was a constant expression. If
1207  /// *isInitializerConstant is set to true, *ConstantValue will be set to the
1208  /// evaluated value of *Initializer.
1209  bool endsWithNarrowing(ASTContext &Ctx, const Expr *Initializer,
1210  bool *isInitializerConstant,
1211  APValue *ConstantValue) const;
1212 
1213  /// Add a new step in the initialization that resolves the address
1214  /// of an overloaded function to a specific function declaration.
1215  ///
1216  /// \param Function the function to which the overloaded function reference
1217  /// resolves.
1218  void AddAddressOverloadResolutionStep(FunctionDecl *Function,
1219  DeclAccessPair Found,
1220  bool HadMultipleCandidates);
1221 
1222  /// Add a new step in the initialization that performs a derived-to-
1223  /// base cast.
1224  ///
1225  /// \param BaseType the base type to which we will be casting.
1226  ///
1227  /// \param Category Indicates whether the result will be treated as an
1228  /// rvalue, an xvalue, or an lvalue.
1229  void AddDerivedToBaseCastStep(QualType BaseType,
1231 
1232  /// Add a new step binding a reference to an object.
1233  ///
1234  /// \param BindingTemporary True if we are binding a reference to a temporary
1235  /// object (thereby extending its lifetime); false if we are binding to an
1236  /// lvalue or an lvalue treated as an rvalue.
1237  void AddReferenceBindingStep(QualType T, bool BindingTemporary);
1238 
1239  /// Add a new step that makes an extraneous copy of the input
1240  /// to a temporary of the same class type.
1241  ///
1242  /// This extraneous copy only occurs during reference binding in
1243  /// C++98/03, where we are permitted (but not required) to introduce
1244  /// an extra copy. At a bare minimum, we must check that we could
1245  /// call the copy constructor, and produce a diagnostic if the copy
1246  /// constructor is inaccessible or no copy constructor matches.
1247  //
1248  /// \param T The type of the temporary being created.
1249  void AddExtraneousCopyToTemporary(QualType T);
1250 
1251  /// Add a new step that makes a copy of the input to an object of
1252  /// the given type, as the final step in class copy-initialization.
1253  void AddFinalCopy(QualType T);
1254 
1255  /// Add a new step invoking a conversion function, which is either
1256  /// a constructor or a conversion function.
1257  void AddUserConversionStep(FunctionDecl *Function,
1258  DeclAccessPair FoundDecl,
1259  QualType T,
1260  bool HadMultipleCandidates);
1261 
1262  /// Add a new step that performs a qualification conversion to the
1263  /// given type.
1264  void AddQualificationConversionStep(QualType Ty,
1265  ExprValueKind Category);
1266 
1267  /// Add a new step that performs conversion from non-atomic to atomic
1268  /// type.
1269  void AddAtomicConversionStep(QualType Ty);
1270 
1271  /// Add a new step that performs a load of the given type.
1272  ///
1273  /// Although the term "LValueToRValue" is conventional, this applies to both
1274  /// lvalues and xvalues.
1275  void AddLValueToRValueStep(QualType Ty);
1276 
1277  /// Add a new step that applies an implicit conversion sequence.
1278  void AddConversionSequenceStep(const ImplicitConversionSequence &ICS,
1279  QualType T, bool TopLevelOfInitList = false);
1280 
1281  /// Add a list-initialization step.
1282  void AddListInitializationStep(QualType T);
1283 
1284  /// Add a constructor-initialization step.
1285  ///
1286  /// \param FromInitList The constructor call is syntactically an initializer
1287  /// list.
1288  /// \param AsInitList The constructor is called as an init list constructor.
1289  void AddConstructorInitializationStep(DeclAccessPair FoundDecl,
1290  CXXConstructorDecl *Constructor,
1291  QualType T,
1292  bool HadMultipleCandidates,
1293  bool FromInitList, bool AsInitList);
1294 
1295  /// Add a zero-initialization step.
1296  void AddZeroInitializationStep(QualType T);
1297 
1298  /// Add a C assignment step.
1299  //
1300  // FIXME: It isn't clear whether this should ever be needed;
1301  // ideally, we would handle everything needed in C in the common
1302  // path. However, that isn't the case yet.
1303  void AddCAssignmentStep(QualType T);
1304 
1305  /// Add a string init step.
1306  void AddStringInitStep(QualType T);
1307 
1308  /// Add an Objective-C object conversion step, which is
1309  /// always a no-op.
1310  void AddObjCObjectConversionStep(QualType T);
1311 
1312  /// Add an array initialization loop step.
1313  void AddArrayInitLoopStep(QualType T, QualType EltTy);
1314 
1315  /// Add an array initialization step.
1316  void AddArrayInitStep(QualType T, bool IsGNUExtension);
1317 
1318  /// Add a parenthesized array initialization step.
1319  void AddParenthesizedArrayInitStep(QualType T);
1320 
1321  /// Add a step to pass an object by indirect copy-restore.
1322  void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy);
1323 
1324  /// Add a step to "produce" an Objective-C object (by
1325  /// retaining it).
1326  void AddProduceObjCObjectStep(QualType T);
1327 
1328  /// Add a step to construct a std::initializer_list object from an
1329  /// initializer list.
1330  void AddStdInitializerListConstructionStep(QualType T);
1331 
1332  /// Add a step to initialize an OpenCL sampler from an integer
1333  /// constant.
1334  void AddOCLSamplerInitStep(QualType T);
1335 
1336  /// Add a step to initialize an OpenCL event_t from a NULL
1337  /// constant.
1338  void AddOCLZeroEventStep(QualType T);
1339 
1340  /// Add a step to initialize an OpenCL queue_t from 0.
1341  void AddOCLZeroQueueStep(QualType T);
1342 
1343  /// Add steps to unwrap a initializer list for a reference around a
1344  /// single element and rewrap it at the end.
1345  void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
1346 
1347  /// Note that this initialization sequence failed.
1348  void SetFailed(FailureKind Failure) {
1349  SequenceKind = FailedSequence;
1350  this->Failure = Failure;
1351  assert((Failure != FK_Incomplete || !FailedIncompleteType.isNull()) &&
1352  "Incomplete type failure requires a type!");
1353  }
1354 
1355  /// Note that this initialization sequence failed due to failed
1356  /// overload resolution.
1357  void SetOverloadFailure(FailureKind Failure, OverloadingResult Result);
1358 
1359  /// Retrieve a reference to the candidate set when overload
1360  /// resolution fails.
1362  return FailedCandidateSet;
1363  }
1364 
1365  /// Get the overloading result, for when the initialization
1366  /// sequence failed due to a bad overload.
1368  return FailedOverloadResult;
1369  }
1370 
1371  /// Note that this initialization sequence failed due to an
1372  /// incomplete type.
1373  void setIncompleteTypeFailure(QualType IncompleteType) {
1374  FailedIncompleteType = IncompleteType;
1375  SetFailed(FK_Incomplete);
1376  }
1377 
1378  /// Determine why initialization failed.
1380  assert(Failed() && "Not an initialization failure!");
1381  return Failure;
1382  }
1383 
1384  /// Dump a representation of this initialization sequence to
1385  /// the given stream, for debugging purposes.
1386  void dump(raw_ostream &OS) const;
1387 
1388  /// Dump a representation of this initialization sequence to
1389  /// standard error, for debugging purposes.
1390  void dump() const;
1391 };
1392 
1393 } // namespace clang
1394 
1395 #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:1716
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:2988
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:1428
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.
The entity being initialized is the result of a statement expression.
static InitializedEntity InitializeMemberFromDefaultMemberInitializer(FieldDecl *Member)
Create the initialization entity for a default member initializer.
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2477
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:2973
Represents a variable declaration or definition.
Definition: Decl.h:814
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:1535
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:2534
Rewrap the single-element initializer list for a reference.
FieldDecl * getAnonField() const
Definition: Decl.h:2810
int Category
Definition: Format.cpp:1608
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:4050
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:6575
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:3024
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:538
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:277
Overloading for list-initialization by constructor failed.
Perform list-initialization without a constructor.
Cannot resolve the address of an overloaded function.
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:637
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.
void dump() const
Dump a representation of the initialized entity to standard error, for debugging purposes.
Definition: SemaInit.cpp:3131
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:3056
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
SourceLocation getLocStart() const LLVM_READONLY
Definition: Stmt.h:401
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...
SourceLocation getLocEnd() const LLVM_READONLY
Definition: Stmt.h:403
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:2780
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
static InitializedEntity InitializeStmtExprResult(SourceLocation ReturnLoc, QualType Type)
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:5969
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:648
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.
bool isDefaultMemberInitializer() const
Is this the default member initializer of a member (specified inside the class definition)?
ObjCMethodDecl * getMethodDecl() const
Retrieve the ObjectiveC method being initialized.
SourceLocation getBegin() const
const LangOptions & getLangOpts() const
Definition: ASTContext.h:696
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