clang  10.0.0svn
Initialization.h
Go to the documentation of this file.
1 //===- Initialization.h - Semantic Analysis for Initializers ----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides supporting data types for initialization of objects.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_SEMA_INITIALIZATION_H
14 #define LLVM_CLANG_SEMA_INITIALIZATION_H
15 
16 #include "clang/AST/ASTContext.h"
17 #include "clang/AST/Attr.h"
18 #include "clang/AST/Decl.h"
21 #include "clang/AST/Expr.h"
22 #include "clang/AST/Type.h"
24 #include "clang/Basic/LLVM.h"
27 #include "clang/Basic/Specifiers.h"
28 #include "clang/Sema/Overload.h"
29 #include "clang/Sema/Ownership.h"
30 #include "llvm/ADT/ArrayRef.h"
31 #include "llvm/ADT/SmallVector.h"
32 #include "llvm/ADT/StringRef.h"
33 #include "llvm/ADT/iterator_range.h"
34 #include "llvm/Support/Casting.h"
35 #include <cassert>
36 #include <cstdint>
37 #include <string>
38 
39 namespace clang {
40 
41 class APValue;
42 class CXXBaseSpecifier;
43 class CXXConstructorDecl;
44 class ObjCMethodDecl;
45 class Sema;
46 
47 /// Describes an entity that is being initialized.
48 class alignas(8) InitializedEntity {
49 public:
50  /// Specifies the kind of entity being initialized.
51  enum EntityKind {
52  /// The entity being initialized is a variable.
54 
55  /// The entity being initialized is a function parameter.
57 
58  /// The entity being initialized is the result of a function call.
60 
61  /// The entity being initialized is the result of a statement expression.
63 
64  /// The entity being initialized is an exception object that
65  /// is being thrown.
67 
68  /// The entity being initialized is a non-static data member
69  /// subobject.
71 
72  /// The entity being initialized is an element of an array.
74 
75  /// The entity being initialized is an object (or array of
76  /// objects) allocated via new.
78 
79  /// The entity being initialized is a temporary object.
81 
82  /// The entity being initialized is a base member subobject.
84 
85  /// The initialization is being done by a delegating constructor.
87 
88  /// The entity being initialized is an element of a vector.
89  /// or vector.
91 
92  /// The entity being initialized is a field of block descriptor for
93  /// the copied-in c++ object.
95 
96  /// The entity being initialized is a field of block descriptor for the
97  /// copied-in lambda object that's used in the lambda to block conversion.
99 
100  /// The entity being initialized is the real or imaginary part of a
101  /// complex number.
103 
104  /// The entity being initialized is the field that captures a
105  /// variable in a lambda.
107 
108  /// The entity being initialized is the initializer for a compound
109  /// literal.
111 
112  /// The entity being implicitly initialized back to the formal
113  /// result type.
115 
116  /// The entity being initialized is a function parameter; function
117  /// is member of group of audited CF APIs.
119 
120  /// The entity being initialized is a structured binding of a
121  /// decomposition declaration.
123 
124  // Note: err_init_conversion_failed in DiagnosticSemaKinds.td uses this
125  // enum as an index for its first %select. When modifying this list,
126  // that diagnostic text needs to be updated as well.
127  };
128 
129 private:
130  /// The kind of entity being initialized.
132 
133  /// If non-NULL, the parent entity in which this
134  /// initialization occurs.
135  const InitializedEntity *Parent = nullptr;
136 
137  /// The type of the object or reference being initialized.
138  QualType Type;
139 
140  /// The mangling number for the next reference temporary to be created.
141  mutable unsigned ManglingNumber = 0;
142 
143  struct LN {
144  /// When Kind == EK_Result, EK_Exception, EK_New, the
145  /// location of the 'return', 'throw', or 'new' keyword,
146  /// respectively. When Kind == EK_Temporary, the location where
147  /// the temporary is being created.
148  unsigned Location;
149 
150  /// Whether the entity being initialized may end up using the
151  /// named return value optimization (NRVO).
152  bool NRVO;
153  };
154 
155  struct VD {
156  /// The VarDecl, FieldDecl, or BindingDecl being initialized.
157  ValueDecl *VariableOrMember;
158 
159  /// When Kind == EK_Member, whether this is an implicit member
160  /// initialization in a copy or move constructor. These can perform array
161  /// copies.
162  bool IsImplicitFieldInit;
163 
164  /// When Kind == EK_Member, whether this is the initial initialization
165  /// check for a default member initializer.
166  bool IsDefaultMemberInit;
167  };
168 
169  struct C {
170  /// The name of the variable being captured by an EK_LambdaCapture.
171  IdentifierInfo *VarID;
172 
173  /// The source location at which the capture occurs.
174  unsigned Location;
175  };
176 
177  union {
178  /// When Kind == EK_Variable, EK_Member or EK_Binding, the variable.
180 
181  /// When Kind == EK_RelatedResult, the ObjectiveC method where
182  /// result type was implicitly changed to accommodate ARC semantics.
184 
185  /// When Kind == EK_Parameter, the ParmVarDecl, with the
186  /// low bit indicating whether the parameter is "consumed".
188 
189  /// When Kind == EK_Temporary or EK_CompoundLiteralInit, the type
190  /// source information for the temporary.
192 
193  struct LN LocAndNRVO;
194 
195  /// When Kind == EK_Base, the base specifier that provides the
196  /// base class. The lower bit specifies whether the base is an inherited
197  /// virtual base.
199 
200  /// When Kind == EK_ArrayElement, EK_VectorElement, or
201  /// EK_ComplexElement, the index of the array or vector element being
202  /// initialized.
203  unsigned Index;
204 
205  struct C Capture;
206  };
207 
208  InitializedEntity() = default;
209 
210  /// Create the initialization entity for a variable.
212  : Kind(EK), Type(Var->getType()), Variable{Var, false, false} {}
213 
214  /// Create the initialization entity for the result of a
215  /// function, throwing an object, performing an explicit cast, or
216  /// initializing a parameter for which there is no declaration.
218  bool NRVO = false)
219  : Kind(Kind), Type(Type) {
220  LocAndNRVO.Location = Loc.getRawEncoding();
221  LocAndNRVO.NRVO = NRVO;
222  }
223 
224  /// Create the initialization entity for a member subobject.
225  InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent,
226  bool Implicit, bool DefaultMemberInit)
227  : Kind(EK_Member), Parent(Parent), Type(Member->getType()),
228  Variable{Member, Implicit, DefaultMemberInit} {}
229 
230  /// Create the initialization entity for an array element.
231  InitializedEntity(ASTContext &Context, unsigned Index,
232  const InitializedEntity &Parent);
233 
234  /// Create the initialization entity for a lambda capture.
236  : Kind(EK_LambdaCapture), Type(FieldType) {
237  Capture.VarID = VarID;
238  Capture.Location = Loc.getRawEncoding();
239  }
240 
241 public:
242  /// Create the initialization entity for a variable.
244  return InitializedEntity(Var);
245  }
246 
247  /// Create the initialization entity for a parameter.
249  const ParmVarDecl *Parm) {
250  return InitializeParameter(Context, Parm, Parm->getType());
251  }
252 
253  /// Create the initialization entity for a parameter, but use
254  /// another type.
256  const ParmVarDecl *Parm,
257  QualType Type) {
258  bool Consumed = (Context.getLangOpts().ObjCAutoRefCount &&
259  Parm->hasAttr<NSConsumedAttr>());
260 
261  InitializedEntity Entity;
262  Entity.Kind = EK_Parameter;
263  Entity.Type =
265  Entity.Parent = nullptr;
266  Entity.Parameter
267  = (static_cast<uintptr_t>(Consumed) | reinterpret_cast<uintptr_t>(Parm));
268  return Entity;
269  }
270 
271  /// Create the initialization entity for a parameter that is
272  /// only known by its type.
274  QualType Type,
275  bool Consumed) {
276  InitializedEntity Entity;
277  Entity.Kind = EK_Parameter;
278  Entity.Type = Context.getVariableArrayDecayedType(Type);
279  Entity.Parent = nullptr;
280  Entity.Parameter = (Consumed);
281  return Entity;
282  }
283 
284  /// Create the initialization entity for the result of a function.
286  QualType Type, bool NRVO) {
287  return InitializedEntity(EK_Result, ReturnLoc, Type, NRVO);
288  }
289 
291  QualType Type) {
292  return InitializedEntity(EK_StmtExprResult, ReturnLoc, Type);
293  }
294 
296  QualType Type, bool NRVO) {
297  return InitializedEntity(EK_BlockElement, BlockVarLoc, Type, NRVO);
298  }
299 
301  QualType Type, bool NRVO) {
303  BlockVarLoc, Type, NRVO);
304  }
305 
306  /// Create the initialization entity for an exception object.
308  QualType Type, bool NRVO) {
309  return InitializedEntity(EK_Exception, ThrowLoc, Type, NRVO);
310  }
311 
312  /// Create the initialization entity for an object allocated via new.
314  return InitializedEntity(EK_New, NewLoc, Type);
315  }
316 
317  /// Create the initialization entity for a temporary.
319  return InitializeTemporary(nullptr, Type);
320  }
321 
322  /// Create the initialization entity for a temporary.
324  return InitializeTemporary(TypeInfo, TypeInfo->getType());
325  }
326 
327  /// Create the initialization entity for a temporary.
329  QualType Type) {
331  Result.TypeInfo = TypeInfo;
332  return Result;
333  }
334 
335  /// Create the initialization entity for a related result.
337  QualType Type) {
339  Result.MethodDecl = MD;
340  return Result;
341  }
342 
343  /// Create the initialization entity for a base class subobject.
344  static InitializedEntity
346  bool IsInheritedVirtualBase,
347  const InitializedEntity *Parent = nullptr);
348 
349  /// Create the initialization entity for a delegated constructor.
352  }
353 
354  /// Create the initialization entity for a member subobject.
355  static InitializedEntity
357  const InitializedEntity *Parent = nullptr,
358  bool Implicit = false) {
359  return InitializedEntity(Member, Parent, Implicit, false);
360  }
361 
362  /// Create the initialization entity for a member subobject.
363  static InitializedEntity
365  const InitializedEntity *Parent = nullptr,
366  bool Implicit = false) {
367  return InitializedEntity(Member->getAnonField(), Parent, Implicit, false);
368  }
369 
370  /// Create the initialization entity for a default member initializer.
371  static InitializedEntity
373  return InitializedEntity(Member, nullptr, false, true);
374  }
375 
376  /// Create the initialization entity for an array element.
378  unsigned Index,
379  const InitializedEntity &Parent) {
380  return InitializedEntity(Context, Index, Parent);
381  }
382 
383  /// Create the initialization entity for a structured binding.
385  return InitializedEntity(Binding, EK_Binding);
386  }
387 
388  /// Create the initialization entity for a lambda capture.
389  ///
390  /// \p VarID The name of the entity being captured, or nullptr for 'this'.
392  QualType FieldType,
393  SourceLocation Loc) {
394  return InitializedEntity(VarID, FieldType, Loc);
395  }
396 
397  /// Create the entity for a compound literal initializer.
400  TSI->getType());
401  Result.TypeInfo = TSI;
402  return Result;
403  }
404 
405  /// Determine the kind of initialization.
406  EntityKind getKind() const { return Kind; }
407 
408  /// Retrieve the parent of the entity being initialized, when
409  /// the initialization itself is occurring within the context of a
410  /// larger initialization.
411  const InitializedEntity *getParent() const { return Parent; }
412 
413  /// Retrieve type being initialized.
414  QualType getType() const { return Type; }
415 
416  /// Retrieve complete type-source information for the object being
417  /// constructed, if known.
419  if (Kind == EK_Temporary || Kind == EK_CompoundLiteralInit)
420  return TypeInfo;
421 
422  return nullptr;
423  }
424 
425  /// Retrieve the name of the entity being initialized.
426  DeclarationName getName() const;
427 
428  /// Retrieve the variable, parameter, or field being
429  /// initialized.
430  ValueDecl *getDecl() const;
431 
432  /// Retrieve the ObjectiveC method being initialized.
434 
435  /// Determine whether this initialization allows the named return
436  /// value optimization, which also applies to thrown objects.
437  bool allowsNRVO() const;
438 
439  bool isParameterKind() const {
440  return (getKind() == EK_Parameter ||
442  }
443 
444  /// Determine whether this initialization consumes the
445  /// parameter.
446  bool isParameterConsumed() const {
447  assert(isParameterKind() && "Not a parameter");
448  return (Parameter & 1);
449  }
450 
451  /// Retrieve the base specifier.
453  assert(getKind() == EK_Base && "Not a base specifier");
454  return reinterpret_cast<const CXXBaseSpecifier *>(Base & ~0x1);
455  }
456 
457  /// Return whether the base is an inherited virtual base.
458  bool isInheritedVirtualBase() const {
459  assert(getKind() == EK_Base && "Not a base specifier");
460  return Base & 0x1;
461  }
462 
463  /// Determine whether this is an array new with an unknown bound.
465  return getKind() == EK_New && dyn_cast_or_null<IncompleteArrayType>(
467  }
468 
469  /// Is this the implicit initialization of a member of a class from
470  /// a defaulted constructor?
472  return getKind() == EK_Member && Variable.IsImplicitFieldInit;
473  }
474 
475  /// Is this the default member initializer of a member (specified inside
476  /// the class definition)?
478  return getKind() == EK_Member && Variable.IsDefaultMemberInit;
479  }
480 
481  /// Determine the location of the 'return' keyword when initializing
482  /// the result of a function call.
484  assert(getKind() == EK_Result && "No 'return' location!");
486  }
487 
488  /// Determine the location of the 'throw' keyword when initializing
489  /// an exception object.
491  assert(getKind() == EK_Exception && "No 'throw' location!");
493  }
494 
495  /// If this is an array, vector, or complex number element, get the
496  /// element's index.
497  unsigned getElementIndex() const {
498  assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
500  return Index;
501  }
502 
503  /// If this is already the initializer for an array or vector
504  /// element, sets the element index.
505  void setElementIndex(unsigned Index) {
506  assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
508  this->Index = Index;
509  }
510 
511  /// For a lambda capture, return the capture's name.
512  StringRef getCapturedVarName() const {
513  assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
514  return Capture.VarID ? Capture.VarID->getName() : "this";
515  }
516 
517  /// Determine the location of the capture when initializing
518  /// field from a captured variable in a lambda.
520  assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
521  return SourceLocation::getFromRawEncoding(Capture.Location);
522  }
523 
526  }
527 
528  unsigned allocateManglingNumber() const { return ++ManglingNumber; }
529 
530  /// Dump a representation of the initialized entity to standard error,
531  /// for debugging purposes.
532  void dump() const;
533 
534 private:
535  unsigned dumpImpl(raw_ostream &OS) const;
536 };
537 
538 /// Describes the kind of initialization being performed, along with
539 /// location information for tokens related to the initialization (equal sign,
540 /// parentheses).
542 public:
543  /// The kind of initialization being performed.
544  enum InitKind {
545  /// Direct initialization
547 
548  /// Direct list-initialization
550 
551  /// Copy initialization
553 
554  /// Default initialization
556 
557  /// Value initialization
558  IK_Value
559  };
560 
561 private:
562  /// The context of the initialization.
563  enum InitContext {
564  /// Normal context
565  IC_Normal,
566 
567  /// Normal context, but allows explicit conversion functionss
568  IC_ExplicitConvs,
569 
570  /// Implicit context (value initialization)
571  IC_Implicit,
572 
573  /// Static cast context
574  IC_StaticCast,
575 
576  /// C-style cast context
577  IC_CStyleCast,
578 
579  /// Functional cast context
580  IC_FunctionalCast
581  };
582 
583  /// The kind of initialization being performed.
584  InitKind Kind : 8;
585 
586  /// The context of the initialization.
587  InitContext Context : 8;
588 
589  /// The source locations involved in the initialization.
590  SourceLocation Locations[3];
591 
592  InitializationKind(InitKind Kind, InitContext Context, SourceLocation Loc1,
593  SourceLocation Loc2, SourceLocation Loc3)
594  : Kind(Kind), Context(Context) {
595  Locations[0] = Loc1;
596  Locations[1] = Loc2;
597  Locations[2] = Loc3;
598  }
599 
600 public:
601  /// Create a direct initialization.
603  SourceLocation LParenLoc,
604  SourceLocation RParenLoc) {
605  return InitializationKind(IK_Direct, IC_Normal,
606  InitLoc, LParenLoc, RParenLoc);
607  }
608 
610  return InitializationKind(IK_DirectList, IC_Normal, InitLoc, InitLoc,
611  InitLoc);
612  }
613 
615  SourceLocation LBraceLoc,
616  SourceLocation RBraceLoc) {
617  return InitializationKind(IK_DirectList, IC_Normal, InitLoc, LBraceLoc,
618  RBraceLoc);
619  }
620 
621  /// Create a direct initialization due to a cast that isn't a C-style
622  /// or functional cast.
624  return InitializationKind(IK_Direct, IC_StaticCast, TypeRange.getBegin(),
625  TypeRange.getBegin(), TypeRange.getEnd());
626  }
627 
628  /// Create a direct initialization for a C-style cast.
630  SourceRange TypeRange,
631  bool InitList) {
632  // C++ cast syntax doesn't permit init lists, but C compound literals are
633  // exactly that.
634  return InitializationKind(InitList ? IK_DirectList : IK_Direct,
635  IC_CStyleCast, StartLoc, TypeRange.getBegin(),
636  TypeRange.getEnd());
637  }
638 
639  /// Create a direct initialization for a functional cast.
641  bool InitList) {
642  return InitializationKind(InitList ? IK_DirectList : IK_Direct,
643  IC_FunctionalCast, TypeRange.getBegin(),
644  TypeRange.getBegin(), TypeRange.getEnd());
645  }
646 
647  /// Create a copy initialization.
649  SourceLocation EqualLoc,
650  bool AllowExplicitConvs = false) {
651  return InitializationKind(IK_Copy,
652  AllowExplicitConvs? IC_ExplicitConvs : IC_Normal,
653  InitLoc, EqualLoc, EqualLoc);
654  }
655 
656  /// Create a default initialization.
658  return InitializationKind(IK_Default, IC_Normal, InitLoc, InitLoc, InitLoc);
659  }
660 
661  /// Create a value initialization.
663  SourceLocation LParenLoc,
664  SourceLocation RParenLoc,
665  bool isImplicit = false) {
666  return InitializationKind(IK_Value, isImplicit ? IC_Implicit : IC_Normal,
667  InitLoc, LParenLoc, RParenLoc);
668  }
669 
670  /// Create an initialization from an initializer (which, for direct
671  /// initialization from a parenthesized list, will be a ParenListExpr).
673  Expr *Init) {
674  if (!Init) return CreateDefault(Loc);
675  if (!DirectInit)
676  return CreateCopy(Loc, Init->getBeginLoc());
677  if (isa<InitListExpr>(Init))
678  return CreateDirectList(Loc, Init->getBeginLoc(), Init->getEndLoc());
679  return CreateDirect(Loc, Init->getBeginLoc(), Init->getEndLoc());
680  }
681 
682  /// Determine the initialization kind.
683  InitKind getKind() const {
684  return Kind;
685  }
686 
687  /// Determine whether this initialization is an explicit cast.
688  bool isExplicitCast() const {
689  return Context >= IC_StaticCast;
690  }
691 
692  /// Determine whether this initialization is a C-style cast.
694  return Context >= IC_CStyleCast;
695  }
696 
697  /// Determine whether this is a C-style cast.
698  bool isCStyleCast() const {
699  return Context == IC_CStyleCast;
700  }
701 
702  /// Determine whether this is a functional-style cast.
703  bool isFunctionalCast() const {
704  return Context == IC_FunctionalCast;
705  }
706 
707  /// Determine whether this initialization is an implicit
708  /// value-initialization, e.g., as occurs during aggregate
709  /// initialization.
710  bool isImplicitValueInit() const { return Context == IC_Implicit; }
711 
712  /// Retrieve the location at which initialization is occurring.
713  SourceLocation getLocation() const { return Locations[0]; }
714 
715  /// Retrieve the source range that covers the initialization.
717  return SourceRange(Locations[0], Locations[2]);
718  }
719 
720  /// Retrieve the location of the equal sign for copy initialization
721  /// (if present).
723  assert(Kind == IK_Copy && "Only copy initialization has an '='");
724  return Locations[1];
725  }
726 
727  bool isCopyInit() const { return Kind == IK_Copy; }
728 
729  /// Retrieve whether this initialization allows the use of explicit
730  /// constructors.
731  bool AllowExplicit() const { return !isCopyInit(); }
732 
733  /// Retrieve whether this initialization allows the use of explicit
734  /// conversion functions when binding a reference. If the reference is the
735  /// first parameter in a copy or move constructor, such conversions are
736  /// permitted even though we are performing copy-initialization.
738  return !isCopyInit() || Context == IC_ExplicitConvs;
739  }
740 
741  /// Determine whether this initialization has a source range containing the
742  /// locations of open and closing parentheses or braces.
743  bool hasParenOrBraceRange() const {
744  return Kind == IK_Direct || Kind == IK_Value || Kind == IK_DirectList;
745  }
746 
747  /// Retrieve the source range containing the locations of the open
748  /// and closing parentheses or braces for value, direct, and direct list
749  /// initializations.
751  assert(hasParenOrBraceRange() && "Only direct, value, and direct-list "
752  "initialization have parentheses or "
753  "braces");
754  return SourceRange(Locations[1], Locations[2]);
755  }
756 };
757 
758 /// Describes the sequence of initializations required to initialize
759 /// a given object or reference with a set of arguments.
761 public:
762  /// Describes the kind of initialization sequence computed.
764  /// A failed initialization sequence. The failure kind tells what
765  /// happened.
766  FailedSequence = 0,
767 
768  /// A dependent initialization, which could not be
769  /// type-checked due to the presence of dependent types or
770  /// dependently-typed expressions.
772 
773  /// A normal sequence.
774  NormalSequence
775  };
776 
777  /// Describes the kind of a particular step in an initialization
778  /// sequence.
779  enum StepKind {
780  /// Resolve the address of an overloaded function to a specific
781  /// function declaration.
783 
784  /// Perform a derived-to-base cast, producing an rvalue.
786 
787  /// Perform a derived-to-base cast, producing an xvalue.
789 
790  /// Perform a derived-to-base cast, producing an lvalue.
792 
793  /// Reference binding to an lvalue.
795 
796  /// Reference binding to a temporary.
798 
799  /// An optional copy of a temporary object to another
800  /// temporary object, which is permitted (but not required) by
801  /// C++98/03 but not C++0x.
803 
804  /// Direct-initialization from a reference-related object in the
805  /// final stage of class copy-initialization.
807 
808  /// Perform a user-defined conversion, either via a conversion
809  /// function or via a constructor.
811 
812  /// Perform a qualification conversion, producing an rvalue.
814 
815  /// Perform a qualification conversion, producing an xvalue.
817 
818  /// Perform a qualification conversion, producing an lvalue.
820 
821  /// Perform a conversion adding _Atomic to a type.
823 
824  /// Perform an implicit conversion sequence.
826 
827  /// Perform an implicit conversion sequence without narrowing.
829 
830  /// Perform list-initialization without a constructor.
832 
833  /// Unwrap the single-element initializer list for a reference.
835 
836  /// Rewrap the single-element initializer list for a reference.
838 
839  /// Perform initialization via a constructor.
841 
842  /// Perform initialization via a constructor, taking arguments from
843  /// a single InitListExpr.
845 
846  /// Zero-initialize the object
848 
849  /// C assignment
851 
852  /// Initialization by string
854 
855  /// An initialization that "converts" an Objective-C object
856  /// (not a point to an object) to another Objective-C object type.
858 
859  /// Array indexing for initialization by elementwise copy.
861 
862  /// Array initialization by elementwise copy.
864 
865  /// Array initialization (from an array rvalue).
867 
868  /// Array initialization (from an array rvalue) as a GNU extension.
870 
871  /// Array initialization from a parenthesized initializer list.
872  /// This is a GNU C++ extension.
874 
875  /// Pass an object by indirect copy-and-restore.
877 
878  /// Pass an object by indirect restore.
880 
881  /// Produce an Objective-C object pointer.
883 
884  /// Construct a std::initializer_list from an initializer list.
886 
887  /// Perform initialization via a constructor taking a single
888  /// std::initializer_list argument.
890 
891  /// Initialize an OpenCL sampler from an integer.
893 
894  /// Initialize an opaque OpenCL type (event_t, queue_t, etc.) with zero
895  SK_OCLZeroOpaqueType
896  };
897 
898  /// A single step in the initialization sequence.
899  class Step {
900  public:
901  /// The kind of conversion or initialization step we are taking.
903 
904  // The type that results from this initialization.
906 
907  struct F {
911  };
912 
913  union {
914  /// When Kind == SK_ResolvedOverloadedFunction or Kind ==
915  /// SK_UserConversion, the function that the expression should be
916  /// resolved to or the conversion function to call, respectively.
917  /// When Kind == SK_ConstructorInitialization or SK_ListConstruction,
918  /// the constructor to be called.
919  ///
920  /// Always a FunctionDecl, plus a Boolean flag telling if it was
921  /// selected from an overloaded set having size greater than 1.
922  /// For conversion decls, the naming class is the source type.
923  /// For construct decls, the naming class is the target type.
924  struct F Function;
925 
926  /// When Kind = SK_ConversionSequence, the implicit conversion
927  /// sequence.
929 
930  /// When Kind = SK_RewrapInitList, the syntactic form of the
931  /// wrapping list.
933  };
934 
935  void Destroy();
936  };
937 
938 private:
939  /// The kind of initialization sequence computed.
941 
942  /// Steps taken by this initialization.
943  SmallVector<Step, 4> Steps;
944 
945 public:
946  /// Describes why initialization failed.
947  enum FailureKind {
948  /// Too many initializers provided for a reference.
950 
951  /// Reference initialized from a parenthesized initializer list.
953 
954  /// Array must be initialized with an initializer list.
956 
957  /// Array must be initialized with an initializer list or a
958  /// string literal.
960 
961  /// Array must be initialized with an initializer list or a
962  /// wide string literal.
964 
965  /// Initializing a wide char array with narrow string literal.
967 
968  /// Initializing char array with wide string literal.
970 
971  /// Initializing wide char array with incompatible wide string
972  /// literal.
974 
975  /// Initializing char8_t array with plain string literal.
977 
978  /// Initializing char array with UTF-8 string literal.
980 
981  /// Array type mismatch.
983 
984  /// Non-constant array initializer
986 
987  /// Cannot resolve the address of an overloaded function.
989 
990  /// Overloading due to reference initialization failed.
992 
993  /// Non-const lvalue reference binding to a temporary.
995 
996  /// Non-const lvalue reference binding to a bit-field.
998 
999  /// Non-const lvalue reference binding to a vector element.
1001 
1002  /// Non-const lvalue reference binding to an lvalue of unrelated
1003  /// type.
1005 
1006  /// Rvalue reference binding to an lvalue.
1008 
1009  /// Reference binding drops qualifiers.
1011 
1012  /// Reference with mismatching address space binding to temporary.
1014 
1015  /// Reference binding failed.
1017 
1018  /// Implicit conversion failed.
1020 
1021  /// Implicit conversion failed.
1023 
1024  /// Too many initializers for scalar
1026 
1027  /// Scalar initialized from a parenthesized initializer list.
1029 
1030  /// Reference initialization from an initializer list
1032 
1033  /// Initialization of some unused destination type with an
1034  /// initializer list.
1036 
1037  /// Overloading for a user-defined conversion failed.
1039 
1040  /// Overloading for initialization by constructor failed.
1042 
1043  /// Overloading for list-initialization by constructor failed.
1045 
1046  /// Default-initialization of a 'const' object.
1048 
1049  /// Initialization of an incomplete type.
1051 
1052  /// Variable-length array must not have an initializer.
1054 
1055  /// List initialization failed at some point.
1057 
1058  /// Initializer has a placeholder type which cannot be
1059  /// resolved by initialization.
1061 
1062  /// Trying to take the address of a function that doesn't support
1063  /// having its address taken.
1065 
1066  /// List-copy-initialization chose an explicit constructor.
1068  };
1069 
1070 private:
1071  /// The reason why initialization failed.
1072  FailureKind Failure;
1073 
1074  /// The failed result of overload resolution.
1075  OverloadingResult FailedOverloadResult;
1076 
1077  /// The candidate set created when initialization failed.
1078  OverloadCandidateSet FailedCandidateSet;
1079 
1080  /// The incomplete type that caused a failure.
1081  QualType FailedIncompleteType;
1082 
1083  /// The fixit that needs to be applied to make this initialization
1084  /// succeed.
1085  std::string ZeroInitializationFixit;
1086  SourceLocation ZeroInitializationFixitLoc;
1087 
1088 public:
1089  /// Call for initializations are invalid but that would be valid
1090  /// zero initialzations if Fixit was applied.
1091  void SetZeroInitializationFixit(const std::string& Fixit, SourceLocation L) {
1092  ZeroInitializationFixit = Fixit;
1093  ZeroInitializationFixitLoc = L;
1094  }
1095 
1096 private:
1097  /// Prints a follow-up note that highlights the location of
1098  /// the initialized entity, if it's remote.
1099  void PrintInitLocationNote(Sema &S, const InitializedEntity &Entity);
1100 
1101 public:
1102  /// Try to perform initialization of the given entity, creating a
1103  /// record of the steps required to perform the initialization.
1104  ///
1105  /// The generated initialization sequence will either contain enough
1106  /// information to diagnose
1107  ///
1108  /// \param S the semantic analysis object.
1109  ///
1110  /// \param Entity the entity being initialized.
1111  ///
1112  /// \param Kind the kind of initialization being performed.
1113  ///
1114  /// \param Args the argument(s) provided for initialization.
1115  ///
1116  /// \param TopLevelOfInitList true if we are initializing from an expression
1117  /// at the top level inside an initializer list. This disallows
1118  /// narrowing conversions in C++11 onwards.
1119  /// \param TreatUnavailableAsInvalid true if we want to treat unavailable
1120  /// as invalid.
1122  const InitializedEntity &Entity,
1123  const InitializationKind &Kind,
1124  MultiExprArg Args,
1125  bool TopLevelOfInitList = false,
1126  bool TreatUnavailableAsInvalid = true);
1127  void InitializeFrom(Sema &S, const InitializedEntity &Entity,
1128  const InitializationKind &Kind, MultiExprArg Args,
1129  bool TopLevelOfInitList, bool TreatUnavailableAsInvalid);
1130 
1132 
1133  /// Perform the actual initialization of the given entity based on
1134  /// the computed initialization sequence.
1135  ///
1136  /// \param S the semantic analysis object.
1137  ///
1138  /// \param Entity the entity being initialized.
1139  ///
1140  /// \param Kind the kind of initialization being performed.
1141  ///
1142  /// \param Args the argument(s) provided for initialization, ownership of
1143  /// which is transferred into the routine.
1144  ///
1145  /// \param ResultType if non-NULL, will be set to the type of the
1146  /// initialized object, which is the type of the declaration in most
1147  /// cases. However, when the initialized object is a variable of
1148  /// incomplete array type and the initializer is an initializer
1149  /// list, this type will be set to the completed array type.
1150  ///
1151  /// \returns an expression that performs the actual object initialization, if
1152  /// the initialization is well-formed. Otherwise, emits diagnostics
1153  /// and returns an invalid expression.
1154  ExprResult Perform(Sema &S,
1155  const InitializedEntity &Entity,
1156  const InitializationKind &Kind,
1157  MultiExprArg Args,
1158  QualType *ResultType = nullptr);
1159 
1160  /// Diagnose an potentially-invalid initialization sequence.
1161  ///
1162  /// \returns true if the initialization sequence was ill-formed,
1163  /// false otherwise.
1164  bool Diagnose(Sema &S,
1165  const InitializedEntity &Entity,
1166  const InitializationKind &Kind,
1167  ArrayRef<Expr *> Args);
1168 
1169  /// Determine the kind of initialization sequence computed.
1170  enum SequenceKind getKind() const { return SequenceKind; }
1171 
1172  /// Set the kind of sequence computed.
1173  void setSequenceKind(enum SequenceKind SK) { SequenceKind = SK; }
1174 
1175  /// Determine whether the initialization sequence is valid.
1176  explicit operator bool() const { return !Failed(); }
1177 
1178  /// Determine whether the initialization sequence is invalid.
1179  bool Failed() const { return SequenceKind == FailedSequence; }
1180 
1182 
1183  step_iterator step_begin() const { return Steps.begin(); }
1184  step_iterator step_end() const { return Steps.end(); }
1185 
1186  using step_range = llvm::iterator_range<step_iterator>;
1187 
1188  step_range steps() const { return {step_begin(), step_end()}; }
1189 
1190  /// Determine whether this initialization is a direct reference
1191  /// binding (C++ [dcl.init.ref]).
1192  bool isDirectReferenceBinding() const;
1193 
1194  /// Determine whether this initialization failed due to an ambiguity.
1195  bool isAmbiguous() const;
1196 
1197  /// Determine whether this initialization is direct call to a
1198  /// constructor.
1199  bool isConstructorInitialization() const;
1200 
1201  /// Returns whether the last step in this initialization sequence is a
1202  /// narrowing conversion, defined by C++0x [dcl.init.list]p7.
1203  ///
1204  /// If this function returns true, *isInitializerConstant will be set to
1205  /// describe whether *Initializer was a constant expression. If
1206  /// *isInitializerConstant is set to true, *ConstantValue will be set to the
1207  /// evaluated value of *Initializer.
1208  bool endsWithNarrowing(ASTContext &Ctx, const Expr *Initializer,
1209  bool *isInitializerConstant,
1210  APValue *ConstantValue) const;
1211 
1212  /// Add a new step in the initialization that resolves the address
1213  /// of an overloaded function to a specific function declaration.
1214  ///
1215  /// \param Function the function to which the overloaded function reference
1216  /// resolves.
1217  void AddAddressOverloadResolutionStep(FunctionDecl *Function,
1218  DeclAccessPair Found,
1219  bool HadMultipleCandidates);
1220 
1221  /// Add a new step in the initialization that performs a derived-to-
1222  /// base cast.
1223  ///
1224  /// \param BaseType the base type to which we will be casting.
1225  ///
1226  /// \param Category Indicates whether the result will be treated as an
1227  /// rvalue, an xvalue, or an lvalue.
1228  void AddDerivedToBaseCastStep(QualType BaseType,
1230 
1231  /// Add a new step binding a reference to an object.
1232  ///
1233  /// \param BindingTemporary True if we are binding a reference to a temporary
1234  /// object (thereby extending its lifetime); false if we are binding to an
1235  /// lvalue or an lvalue treated as an rvalue.
1236  void AddReferenceBindingStep(QualType T, bool BindingTemporary);
1237 
1238  /// Add a new step that makes an extraneous copy of the input
1239  /// to a temporary of the same class type.
1240  ///
1241  /// This extraneous copy only occurs during reference binding in
1242  /// C++98/03, where we are permitted (but not required) to introduce
1243  /// an extra copy. At a bare minimum, we must check that we could
1244  /// call the copy constructor, and produce a diagnostic if the copy
1245  /// constructor is inaccessible or no copy constructor matches.
1246  //
1247  /// \param T The type of the temporary being created.
1248  void AddExtraneousCopyToTemporary(QualType T);
1249 
1250  /// Add a new step that makes a copy of the input to an object of
1251  /// the given type, as the final step in class copy-initialization.
1252  void AddFinalCopy(QualType T);
1253 
1254  /// Add a new step invoking a conversion function, which is either
1255  /// a constructor or a conversion function.
1256  void AddUserConversionStep(FunctionDecl *Function,
1257  DeclAccessPair FoundDecl,
1258  QualType T,
1259  bool HadMultipleCandidates);
1260 
1261  /// Add a new step that performs a qualification conversion to the
1262  /// given type.
1263  void AddQualificationConversionStep(QualType Ty,
1264  ExprValueKind Category);
1265 
1266  /// Add a new step that performs conversion from non-atomic to atomic
1267  /// type.
1268  void AddAtomicConversionStep(QualType Ty);
1269 
1270  /// Add a new step that applies an implicit conversion sequence.
1271  void AddConversionSequenceStep(const ImplicitConversionSequence &ICS,
1272  QualType T, bool TopLevelOfInitList = false);
1273 
1274  /// Add a list-initialization step.
1275  void AddListInitializationStep(QualType T);
1276 
1277  /// Add a constructor-initialization step.
1278  ///
1279  /// \param FromInitList The constructor call is syntactically an initializer
1280  /// list.
1281  /// \param AsInitList The constructor is called as an init list constructor.
1282  void AddConstructorInitializationStep(DeclAccessPair FoundDecl,
1283  CXXConstructorDecl *Constructor,
1284  QualType T,
1285  bool HadMultipleCandidates,
1286  bool FromInitList, bool AsInitList);
1287 
1288  /// Add a zero-initialization step.
1289  void AddZeroInitializationStep(QualType T);
1290 
1291  /// Add a C assignment step.
1292  //
1293  // FIXME: It isn't clear whether this should ever be needed;
1294  // ideally, we would handle everything needed in C in the common
1295  // path. However, that isn't the case yet.
1296  void AddCAssignmentStep(QualType T);
1297 
1298  /// Add a string init step.
1299  void AddStringInitStep(QualType T);
1300 
1301  /// Add an Objective-C object conversion step, which is
1302  /// always a no-op.
1303  void AddObjCObjectConversionStep(QualType T);
1304 
1305  /// Add an array initialization loop step.
1306  void AddArrayInitLoopStep(QualType T, QualType EltTy);
1307 
1308  /// Add an array initialization step.
1309  void AddArrayInitStep(QualType T, bool IsGNUExtension);
1310 
1311  /// Add a parenthesized array initialization step.
1312  void AddParenthesizedArrayInitStep(QualType T);
1313 
1314  /// Add a step to pass an object by indirect copy-restore.
1315  void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy);
1316 
1317  /// Add a step to "produce" an Objective-C object (by
1318  /// retaining it).
1319  void AddProduceObjCObjectStep(QualType T);
1320 
1321  /// Add a step to construct a std::initializer_list object from an
1322  /// initializer list.
1323  void AddStdInitializerListConstructionStep(QualType T);
1324 
1325  /// Add a step to initialize an OpenCL sampler from an integer
1326  /// constant.
1327  void AddOCLSamplerInitStep(QualType T);
1328 
1329  /// Add a step to initialzie an OpenCL opaque type (event_t, queue_t, etc.)
1330  /// from a zero constant.
1331  void AddOCLZeroOpaqueTypeStep(QualType T);
1332 
1333  /// Add a step to initialize by zero types defined in the
1334  /// cl_intel_device_side_avc_motion_estimation OpenCL extension
1335  void AddOCLIntelSubgroupAVCZeroInitStep(QualType T);
1336 
1337  /// Add steps to unwrap a initializer list for a reference around a
1338  /// single element and rewrap it at the end.
1339  void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
1340 
1341  /// Note that this initialization sequence failed.
1342  void SetFailed(FailureKind Failure) {
1343  SequenceKind = FailedSequence;
1344  this->Failure = Failure;
1345  assert((Failure != FK_Incomplete || !FailedIncompleteType.isNull()) &&
1346  "Incomplete type failure requires a type!");
1347  }
1348 
1349  /// Note that this initialization sequence failed due to failed
1350  /// overload resolution.
1351  void SetOverloadFailure(FailureKind Failure, OverloadingResult Result);
1352 
1353  /// Retrieve a reference to the candidate set when overload
1354  /// resolution fails.
1356  return FailedCandidateSet;
1357  }
1358 
1359  /// Get the overloading result, for when the initialization
1360  /// sequence failed due to a bad overload.
1362  return FailedOverloadResult;
1363  }
1364 
1365  /// Note that this initialization sequence failed due to an
1366  /// incomplete type.
1367  void setIncompleteTypeFailure(QualType IncompleteType) {
1368  FailedIncompleteType = IncompleteType;
1369  SetFailed(FK_Incomplete);
1370  }
1371 
1372  /// Determine why initialization failed.
1374  assert(Failed() && "Not an initialization failure!");
1375  return Failure;
1376  }
1377 
1378  /// Dump a representation of this initialization sequence to
1379  /// the given stream, for debugging purposes.
1380  void dump(raw_ostream &OS) const;
1381 
1382  /// Dump a representation of this initialization sequence to
1383  /// standard error, for debugging purposes.
1384  void dump() const;
1385 };
1386 
1387 } // namespace clang
1388 
1389 #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:1784
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:643
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:3255
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:1436
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:38
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:2352
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:3240
Represents a variable declaration or definition.
Definition: Decl.h:827
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:138
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:1600
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:160
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.
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:274
Represents a member of a struct/union/class.
Definition: Decl.h:2643
Rewrap the single-element initializer list for a reference.
FieldDecl * getAnonField() const
Definition: Decl.h:2924
int Category
Definition: Format.cpp:1810
Reference with mismatching address space binding to temporary.
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:4375
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:6909
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:3291
static InitializedEntity InitializeNew(SourceLocation NewLoc, QualType Type)
Create the initialization entity for an object allocated via new.
NodeId Parent
Definition: ASTDiff.cpp:191
Perform an implicit conversion sequence.
bool hasAttr() const
Definition: DeclBase.h:542
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:329
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.
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.
bool Destroy(InterpState &S, CodePtr OpPC, uint32_t I)
Definition: Interp.h:794
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:644
This represents one expression.
Definition: Expr.h:108
Defines the clang::LangOptions interface.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:122
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:3398
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.
__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-base.h:62
Initializing a wide char array with narrow string literal.
#define bool
Definition: stdbool.h:15
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:708
InitKind getKind() const
Determine the initialization kind.
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:287
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:486
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Definition: Ownership.h:153
bool allowsNRVO() const
Determine whether this initialization allows the named return value optimization, which also applies ...
Definition: SemaInit.cpp:3323
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:51
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:846
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.
Optional< types::ID > Type
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.
Represents a field injected from an anonymous union/struct into the parent scope. ...
Definition: Decl.h:2894
const InitializedEntity * getParent() const
Retrieve the parent of the entity being initialized, when the initialization itself is occurring with...
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:115
Represents a base class of a C++ class.
Definition: DeclCXX.h:147
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:6228
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:655
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:723
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