clang  9.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.
390  QualType FieldType,
391  SourceLocation Loc) {
392  return InitializedEntity(VarID, FieldType, Loc);
393  }
394 
395  /// Create the entity for a compound literal initializer.
398  TSI->getType());
399  Result.TypeInfo = TSI;
400  return Result;
401  }
402 
403  /// Determine the kind of initialization.
404  EntityKind getKind() const { return Kind; }
405 
406  /// Retrieve the parent of the entity being initialized, when
407  /// the initialization itself is occurring within the context of a
408  /// larger initialization.
409  const InitializedEntity *getParent() const { return Parent; }
410 
411  /// Retrieve type being initialized.
412  QualType getType() const { return Type; }
413 
414  /// Retrieve complete type-source information for the object being
415  /// constructed, if known.
417  if (Kind == EK_Temporary || Kind == EK_CompoundLiteralInit)
418  return TypeInfo;
419 
420  return nullptr;
421  }
422 
423  /// Retrieve the name of the entity being initialized.
424  DeclarationName getName() const;
425 
426  /// Retrieve the variable, parameter, or field being
427  /// initialized.
428  ValueDecl *getDecl() const;
429 
430  /// Retrieve the ObjectiveC method being initialized.
432 
433  /// Determine whether this initialization allows the named return
434  /// value optimization, which also applies to thrown objects.
435  bool allowsNRVO() const;
436 
437  bool isParameterKind() const {
438  return (getKind() == EK_Parameter ||
440  }
441 
442  /// Determine whether this initialization consumes the
443  /// parameter.
444  bool isParameterConsumed() const {
445  assert(isParameterKind() && "Not a parameter");
446  return (Parameter & 1);
447  }
448 
449  /// Retrieve the base specifier.
451  assert(getKind() == EK_Base && "Not a base specifier");
452  return reinterpret_cast<const CXXBaseSpecifier *>(Base & ~0x1);
453  }
454 
455  /// Return whether the base is an inherited virtual base.
456  bool isInheritedVirtualBase() const {
457  assert(getKind() == EK_Base && "Not a base specifier");
458  return Base & 0x1;
459  }
460 
461  /// Determine whether this is an array new with an unknown bound.
463  return getKind() == EK_New && dyn_cast_or_null<IncompleteArrayType>(
465  }
466 
467  /// Is this the implicit initialization of a member of a class from
468  /// a defaulted constructor?
470  return getKind() == EK_Member && Variable.IsImplicitFieldInit;
471  }
472 
473  /// Is this the default member initializer of a member (specified inside
474  /// the class definition)?
476  return getKind() == EK_Member && Variable.IsDefaultMemberInit;
477  }
478 
479  /// Determine the location of the 'return' keyword when initializing
480  /// the result of a function call.
482  assert(getKind() == EK_Result && "No 'return' location!");
484  }
485 
486  /// Determine the location of the 'throw' keyword when initializing
487  /// an exception object.
489  assert(getKind() == EK_Exception && "No 'throw' location!");
491  }
492 
493  /// If this is an array, vector, or complex number element, get the
494  /// element's index.
495  unsigned getElementIndex() const {
496  assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
498  return Index;
499  }
500 
501  /// If this is already the initializer for an array or vector
502  /// element, sets the element index.
503  void setElementIndex(unsigned Index) {
504  assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
506  this->Index = Index;
507  }
508 
509  /// For a lambda capture, return the capture's name.
510  StringRef getCapturedVarName() const {
511  assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
512  return Capture.VarID->getName();
513  }
514 
515  /// Determine the location of the capture when initializing
516  /// field from a captured variable in a lambda.
518  assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
519  return SourceLocation::getFromRawEncoding(Capture.Location);
520  }
521 
524  }
525 
526  unsigned allocateManglingNumber() const { return ++ManglingNumber; }
527 
528  /// Dump a representation of the initialized entity to standard error,
529  /// for debugging purposes.
530  void dump() const;
531 
532 private:
533  unsigned dumpImpl(raw_ostream &OS) const;
534 };
535 
536 /// Describes the kind of initialization being performed, along with
537 /// location information for tokens related to the initialization (equal sign,
538 /// parentheses).
540 public:
541  /// The kind of initialization being performed.
542  enum InitKind {
543  /// Direct initialization
545 
546  /// Direct list-initialization
548 
549  /// Copy initialization
551 
552  /// Default initialization
554 
555  /// Value initialization
556  IK_Value
557  };
558 
559 private:
560  /// The context of the initialization.
561  enum InitContext {
562  /// Normal context
563  IC_Normal,
564 
565  /// Normal context, but allows explicit conversion functionss
566  IC_ExplicitConvs,
567 
568  /// Implicit context (value initialization)
569  IC_Implicit,
570 
571  /// Static cast context
572  IC_StaticCast,
573 
574  /// C-style cast context
575  IC_CStyleCast,
576 
577  /// Functional cast context
578  IC_FunctionalCast
579  };
580 
581  /// The kind of initialization being performed.
582  InitKind Kind : 8;
583 
584  /// The context of the initialization.
585  InitContext Context : 8;
586 
587  /// The source locations involved in the initialization.
588  SourceLocation Locations[3];
589 
590  InitializationKind(InitKind Kind, InitContext Context, SourceLocation Loc1,
591  SourceLocation Loc2, SourceLocation Loc3)
592  : Kind(Kind), Context(Context) {
593  Locations[0] = Loc1;
594  Locations[1] = Loc2;
595  Locations[2] = Loc3;
596  }
597 
598 public:
599  /// Create a direct initialization.
601  SourceLocation LParenLoc,
602  SourceLocation RParenLoc) {
603  return InitializationKind(IK_Direct, IC_Normal,
604  InitLoc, LParenLoc, RParenLoc);
605  }
606 
608  return InitializationKind(IK_DirectList, IC_Normal, InitLoc, InitLoc,
609  InitLoc);
610  }
611 
613  SourceLocation LBraceLoc,
614  SourceLocation RBraceLoc) {
615  return InitializationKind(IK_DirectList, IC_Normal, InitLoc, LBraceLoc,
616  RBraceLoc);
617  }
618 
619  /// Create a direct initialization due to a cast that isn't a C-style
620  /// or functional cast.
622  return InitializationKind(IK_Direct, IC_StaticCast, TypeRange.getBegin(),
623  TypeRange.getBegin(), TypeRange.getEnd());
624  }
625 
626  /// Create a direct initialization for a C-style cast.
628  SourceRange TypeRange,
629  bool InitList) {
630  // C++ cast syntax doesn't permit init lists, but C compound literals are
631  // exactly that.
632  return InitializationKind(InitList ? IK_DirectList : IK_Direct,
633  IC_CStyleCast, StartLoc, TypeRange.getBegin(),
634  TypeRange.getEnd());
635  }
636 
637  /// Create a direct initialization for a functional cast.
639  bool InitList) {
640  return InitializationKind(InitList ? IK_DirectList : IK_Direct,
641  IC_FunctionalCast, TypeRange.getBegin(),
642  TypeRange.getBegin(), TypeRange.getEnd());
643  }
644 
645  /// Create a copy initialization.
647  SourceLocation EqualLoc,
648  bool AllowExplicitConvs = false) {
649  return InitializationKind(IK_Copy,
650  AllowExplicitConvs? IC_ExplicitConvs : IC_Normal,
651  InitLoc, EqualLoc, EqualLoc);
652  }
653 
654  /// Create a default initialization.
656  return InitializationKind(IK_Default, IC_Normal, InitLoc, InitLoc, InitLoc);
657  }
658 
659  /// Create a value initialization.
661  SourceLocation LParenLoc,
662  SourceLocation RParenLoc,
663  bool isImplicit = false) {
664  return InitializationKind(IK_Value, isImplicit ? IC_Implicit : IC_Normal,
665  InitLoc, LParenLoc, RParenLoc);
666  }
667 
668  /// Create an initialization from an initializer (which, for direct
669  /// initialization from a parenthesized list, will be a ParenListExpr).
671  Expr *Init) {
672  if (!Init) return CreateDefault(Loc);
673  if (!DirectInit)
674  return CreateCopy(Loc, Init->getBeginLoc());
675  if (isa<InitListExpr>(Init))
676  return CreateDirectList(Loc, Init->getBeginLoc(), Init->getEndLoc());
677  return CreateDirect(Loc, Init->getBeginLoc(), Init->getEndLoc());
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 an opaque OpenCL type (event_t, queue_t, etc.) with zero
896  SK_OCLZeroOpaqueType
897  };
898 
899  /// A single step in the initialization sequence.
900  class Step {
901  public:
902  /// The kind of conversion or initialization step we are taking.
904 
905  // The type that results from this initialization.
907 
908  struct F {
912  };
913 
914  union {
915  /// When Kind == SK_ResolvedOverloadedFunction or Kind ==
916  /// SK_UserConversion, the function that the expression should be
917  /// resolved to or the conversion function to call, respectively.
918  /// When Kind == SK_ConstructorInitialization or SK_ListConstruction,
919  /// the constructor to be called.
920  ///
921  /// Always a FunctionDecl, plus a Boolean flag telling if it was
922  /// selected from an overloaded set having size greater than 1.
923  /// For conversion decls, the naming class is the source type.
924  /// For construct decls, the naming class is the target type.
925  struct F Function;
926 
927  /// When Kind = SK_ConversionSequence, the implicit conversion
928  /// sequence.
930 
931  /// When Kind = SK_RewrapInitList, the syntactic form of the
932  /// wrapping list.
934  };
935 
936  void Destroy();
937  };
938 
939 private:
940  /// The kind of initialization sequence computed.
942 
943  /// Steps taken by this initialization.
944  SmallVector<Step, 4> Steps;
945 
946 public:
947  /// Describes why initialization failed.
948  enum FailureKind {
949  /// Too many initializers provided for a reference.
951 
952  /// Reference initialized from a parenthesized initializer list.
954 
955  /// Array must be initialized with an initializer list.
957 
958  /// Array must be initialized with an initializer list or a
959  /// string literal.
961 
962  /// Array must be initialized with an initializer list or a
963  /// wide string literal.
965 
966  /// Initializing a wide char array with narrow string literal.
968 
969  /// Initializing char array with wide string literal.
971 
972  /// Initializing wide char array with incompatible wide string
973  /// literal.
975 
976  /// Initializing char8_t array with plain string literal.
978 
979  /// Initializing char array with UTF-8 string literal.
981 
982  /// Array type mismatch.
984 
985  /// Non-constant array initializer
987 
988  /// Cannot resolve the address of an overloaded function.
990 
991  /// Overloading due to reference initialization failed.
993 
994  /// Non-const lvalue reference binding to a temporary.
996 
997  /// Non-const lvalue reference binding to a bit-field.
999 
1000  /// Non-const lvalue reference binding to a vector element.
1002 
1003  /// Non-const lvalue reference binding to an lvalue of unrelated
1004  /// type.
1006 
1007  /// Rvalue reference binding to an lvalue.
1009 
1010  /// Reference binding drops qualifiers.
1012 
1013  /// Reference binding failed.
1015 
1016  /// Implicit conversion failed.
1018 
1019  /// Implicit conversion failed.
1021 
1022  /// Too many initializers for scalar
1024 
1025  /// Scalar initialized from a parenthesized initializer list.
1027 
1028  /// Reference initialization from an initializer list
1030 
1031  /// Initialization of some unused destination type with an
1032  /// initializer list.
1034 
1035  /// Overloading for a user-defined conversion failed.
1037 
1038  /// Overloading for initialization by constructor failed.
1040 
1041  /// Overloading for list-initialization by constructor failed.
1043 
1044  /// Default-initialization of a 'const' object.
1046 
1047  /// Initialization of an incomplete type.
1049 
1050  /// Variable-length array must not have an initializer.
1052 
1053  /// List initialization failed at some point.
1055 
1056  /// Initializer has a placeholder type which cannot be
1057  /// resolved by initialization.
1059 
1060  /// Trying to take the address of a function that doesn't support
1061  /// having its address taken.
1063 
1064  /// List-copy-initialization chose an explicit constructor.
1066  };
1067 
1068 private:
1069  /// The reason why initialization failed.
1070  FailureKind Failure;
1071 
1072  /// The failed result of overload resolution.
1073  OverloadingResult FailedOverloadResult;
1074 
1075  /// The candidate set created when initialization failed.
1076  OverloadCandidateSet FailedCandidateSet;
1077 
1078  /// The incomplete type that caused a failure.
1079  QualType FailedIncompleteType;
1080 
1081  /// The fixit that needs to be applied to make this initialization
1082  /// succeed.
1083  std::string ZeroInitializationFixit;
1084  SourceLocation ZeroInitializationFixitLoc;
1085 
1086 public:
1087  /// Call for initializations are invalid but that would be valid
1088  /// zero initialzations if Fixit was applied.
1089  void SetZeroInitializationFixit(const std::string& Fixit, SourceLocation L) {
1090  ZeroInitializationFixit = Fixit;
1091  ZeroInitializationFixitLoc = L;
1092  }
1093 
1094 private:
1095  /// Prints a follow-up note that highlights the location of
1096  /// the initialized entity, if it's remote.
1097  void PrintInitLocationNote(Sema &S, const InitializedEntity &Entity);
1098 
1099 public:
1100  /// Try to perform initialization of the given entity, creating a
1101  /// record of the steps required to perform the initialization.
1102  ///
1103  /// The generated initialization sequence will either contain enough
1104  /// information to diagnose
1105  ///
1106  /// \param S the semantic analysis object.
1107  ///
1108  /// \param Entity the entity being initialized.
1109  ///
1110  /// \param Kind the kind of initialization being performed.
1111  ///
1112  /// \param Args the argument(s) provided for initialization.
1113  ///
1114  /// \param TopLevelOfInitList true if we are initializing from an expression
1115  /// at the top level inside an initializer list. This disallows
1116  /// narrowing conversions in C++11 onwards.
1117  /// \param TreatUnavailableAsInvalid true if we want to treat unavailable
1118  /// as invalid.
1120  const InitializedEntity &Entity,
1121  const InitializationKind &Kind,
1122  MultiExprArg Args,
1123  bool TopLevelOfInitList = false,
1124  bool TreatUnavailableAsInvalid = true);
1125  void InitializeFrom(Sema &S, const InitializedEntity &Entity,
1126  const InitializationKind &Kind, MultiExprArg Args,
1127  bool TopLevelOfInitList, bool TreatUnavailableAsInvalid);
1128 
1130 
1131  /// Perform the actual initialization of the given entity based on
1132  /// the computed initialization sequence.
1133  ///
1134  /// \param S the semantic analysis object.
1135  ///
1136  /// \param Entity the entity being initialized.
1137  ///
1138  /// \param Kind the kind of initialization being performed.
1139  ///
1140  /// \param Args the argument(s) provided for initialization, ownership of
1141  /// which is transferred into the routine.
1142  ///
1143  /// \param ResultType if non-NULL, will be set to the type of the
1144  /// initialized object, which is the type of the declaration in most
1145  /// cases. However, when the initialized object is a variable of
1146  /// incomplete array type and the initializer is an initializer
1147  /// list, this type will be set to the completed array type.
1148  ///
1149  /// \returns an expression that performs the actual object initialization, if
1150  /// the initialization is well-formed. Otherwise, emits diagnostics
1151  /// and returns an invalid expression.
1152  ExprResult Perform(Sema &S,
1153  const InitializedEntity &Entity,
1154  const InitializationKind &Kind,
1155  MultiExprArg Args,
1156  QualType *ResultType = nullptr);
1157 
1158  /// Diagnose an potentially-invalid initialization sequence.
1159  ///
1160  /// \returns true if the initialization sequence was ill-formed,
1161  /// false otherwise.
1162  bool Diagnose(Sema &S,
1163  const InitializedEntity &Entity,
1164  const InitializationKind &Kind,
1165  ArrayRef<Expr *> Args);
1166 
1167  /// Determine the kind of initialization sequence computed.
1168  enum SequenceKind getKind() const { return SequenceKind; }
1169 
1170  /// Set the kind of sequence computed.
1171  void setSequenceKind(enum SequenceKind SK) { SequenceKind = SK; }
1172 
1173  /// Determine whether the initialization sequence is valid.
1174  explicit operator bool() const { return !Failed(); }
1175 
1176  /// Determine whether the initialization sequence is invalid.
1177  bool Failed() const { return SequenceKind == FailedSequence; }
1178 
1180 
1181  step_iterator step_begin() const { return Steps.begin(); }
1182  step_iterator step_end() const { return Steps.end(); }
1183 
1184  using step_range = llvm::iterator_range<step_iterator>;
1185 
1186  step_range steps() const { return {step_begin(), step_end()}; }
1187 
1188  /// Determine whether this initialization is a direct reference
1189  /// binding (C++ [dcl.init.ref]).
1190  bool isDirectReferenceBinding() const;
1191 
1192  /// Determine whether this initialization failed due to an ambiguity.
1193  bool isAmbiguous() const;
1194 
1195  /// Determine whether this initialization is direct call to a
1196  /// constructor.
1197  bool isConstructorInitialization() const;
1198 
1199  /// Returns whether the last step in this initialization sequence is a
1200  /// narrowing conversion, defined by C++0x [dcl.init.list]p7.
1201  ///
1202  /// If this function returns true, *isInitializerConstant will be set to
1203  /// describe whether *Initializer was a constant expression. If
1204  /// *isInitializerConstant is set to true, *ConstantValue will be set to the
1205  /// evaluated value of *Initializer.
1206  bool endsWithNarrowing(ASTContext &Ctx, const Expr *Initializer,
1207  bool *isInitializerConstant,
1208  APValue *ConstantValue) const;
1209 
1210  /// Add a new step in the initialization that resolves the address
1211  /// of an overloaded function to a specific function declaration.
1212  ///
1213  /// \param Function the function to which the overloaded function reference
1214  /// resolves.
1215  void AddAddressOverloadResolutionStep(FunctionDecl *Function,
1216  DeclAccessPair Found,
1217  bool HadMultipleCandidates);
1218 
1219  /// Add a new step in the initialization that performs a derived-to-
1220  /// base cast.
1221  ///
1222  /// \param BaseType the base type to which we will be casting.
1223  ///
1224  /// \param Category Indicates whether the result will be treated as an
1225  /// rvalue, an xvalue, or an lvalue.
1226  void AddDerivedToBaseCastStep(QualType BaseType,
1228 
1229  /// Add a new step binding a reference to an object.
1230  ///
1231  /// \param BindingTemporary True if we are binding a reference to a temporary
1232  /// object (thereby extending its lifetime); false if we are binding to an
1233  /// lvalue or an lvalue treated as an rvalue.
1234  void AddReferenceBindingStep(QualType T, bool BindingTemporary);
1235 
1236  /// Add a new step that makes an extraneous copy of the input
1237  /// to a temporary of the same class type.
1238  ///
1239  /// This extraneous copy only occurs during reference binding in
1240  /// C++98/03, where we are permitted (but not required) to introduce
1241  /// an extra copy. At a bare minimum, we must check that we could
1242  /// call the copy constructor, and produce a diagnostic if the copy
1243  /// constructor is inaccessible or no copy constructor matches.
1244  //
1245  /// \param T The type of the temporary being created.
1246  void AddExtraneousCopyToTemporary(QualType T);
1247 
1248  /// Add a new step that makes a copy of the input to an object of
1249  /// the given type, as the final step in class copy-initialization.
1250  void AddFinalCopy(QualType T);
1251 
1252  /// Add a new step invoking a conversion function, which is either
1253  /// a constructor or a conversion function.
1254  void AddUserConversionStep(FunctionDecl *Function,
1255  DeclAccessPair FoundDecl,
1256  QualType T,
1257  bool HadMultipleCandidates);
1258 
1259  /// Add a new step that performs a qualification conversion to the
1260  /// given type.
1261  void AddQualificationConversionStep(QualType Ty,
1262  ExprValueKind Category);
1263 
1264  /// Add a new step that performs conversion from non-atomic to atomic
1265  /// type.
1266  void AddAtomicConversionStep(QualType Ty);
1267 
1268  /// Add a new step that performs a load of the given type.
1269  ///
1270  /// Although the term "LValueToRValue" is conventional, this applies to both
1271  /// lvalues and xvalues.
1272  void AddLValueToRValueStep(QualType Ty);
1273 
1274  /// Add a new step that applies an implicit conversion sequence.
1275  void AddConversionSequenceStep(const ImplicitConversionSequence &ICS,
1276  QualType T, bool TopLevelOfInitList = false);
1277 
1278  /// Add a list-initialization step.
1279  void AddListInitializationStep(QualType T);
1280 
1281  /// Add a constructor-initialization step.
1282  ///
1283  /// \param FromInitList The constructor call is syntactically an initializer
1284  /// list.
1285  /// \param AsInitList The constructor is called as an init list constructor.
1286  void AddConstructorInitializationStep(DeclAccessPair FoundDecl,
1287  CXXConstructorDecl *Constructor,
1288  QualType T,
1289  bool HadMultipleCandidates,
1290  bool FromInitList, bool AsInitList);
1291 
1292  /// Add a zero-initialization step.
1293  void AddZeroInitializationStep(QualType T);
1294 
1295  /// Add a C assignment step.
1296  //
1297  // FIXME: It isn't clear whether this should ever be needed;
1298  // ideally, we would handle everything needed in C in the common
1299  // path. However, that isn't the case yet.
1300  void AddCAssignmentStep(QualType T);
1301 
1302  /// Add a string init step.
1303  void AddStringInitStep(QualType T);
1304 
1305  /// Add an Objective-C object conversion step, which is
1306  /// always a no-op.
1307  void AddObjCObjectConversionStep(QualType T);
1308 
1309  /// Add an array initialization loop step.
1310  void AddArrayInitLoopStep(QualType T, QualType EltTy);
1311 
1312  /// Add an array initialization step.
1313  void AddArrayInitStep(QualType T, bool IsGNUExtension);
1314 
1315  /// Add a parenthesized array initialization step.
1316  void AddParenthesizedArrayInitStep(QualType T);
1317 
1318  /// Add a step to pass an object by indirect copy-restore.
1319  void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy);
1320 
1321  /// Add a step to "produce" an Objective-C object (by
1322  /// retaining it).
1323  void AddProduceObjCObjectStep(QualType T);
1324 
1325  /// Add a step to construct a std::initializer_list object from an
1326  /// initializer list.
1327  void AddStdInitializerListConstructionStep(QualType T);
1328 
1329  /// Add a step to initialize an OpenCL sampler from an integer
1330  /// constant.
1331  void AddOCLSamplerInitStep(QualType T);
1332 
1333  /// Add a step to initialzie an OpenCL opaque type (event_t, queue_t, etc.)
1334  /// from a zero constant.
1335  void AddOCLZeroOpaqueTypeStep(QualType T);
1336 
1337  /// Add a step to initialize by zero types defined in the
1338  /// cl_intel_device_side_avc_motion_estimation OpenCL extension
1339  void AddOCLIntelSubgroupAVCZeroInitStep(QualType T);
1340 
1341  /// Add steps to unwrap a initializer list for a reference around a
1342  /// single element and rewrap it at the end.
1343  void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
1344 
1345  /// Note that this initialization sequence failed.
1346  void SetFailed(FailureKind Failure) {
1347  SequenceKind = FailedSequence;
1348  this->Failure = Failure;
1349  assert((Failure != FK_Incomplete || !FailedIncompleteType.isNull()) &&
1350  "Incomplete type failure requires a type!");
1351  }
1352 
1353  /// Note that this initialization sequence failed due to failed
1354  /// overload resolution.
1355  void SetOverloadFailure(FailureKind Failure, OverloadingResult Result);
1356 
1357  /// Retrieve a reference to the candidate set when overload
1358  /// resolution fails.
1360  return FailedCandidateSet;
1361  }
1362 
1363  /// Get the overloading result, for when the initialization
1364  /// sequence failed due to a bad overload.
1366  return FailedOverloadResult;
1367  }
1368 
1369  /// Note that this initialization sequence failed due to an
1370  /// incomplete type.
1371  void setIncompleteTypeFailure(QualType IncompleteType) {
1372  FailedIncompleteType = IncompleteType;
1373  SetFailed(FK_Incomplete);
1374  }
1375 
1376  /// Determine why initialization failed.
1378  assert(Failed() && "Not an initialization failure!");
1379  return Failure;
1380  }
1381 
1382  /// Dump a representation of this initialization sequence to
1383  /// the given stream, for debugging purposes.
1384  void dump(raw_ostream &OS) const;
1385 
1386  /// Dump a representation of this initialization sequence to
1387  /// standard error, for debugging purposes.
1388  void dump() const;
1389 };
1390 
1391 } // namespace clang
1392 
1393 #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:1737
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:634
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:3107
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:1409
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:2491
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:3092
Represents a variable declaration or definition.
Definition: Decl.h:812
Array initialization by elementwise copy.
SourceLocation getEqualLoc() const
Retrieve the location of the equal sign for copy initialization (if present).
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h: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:1549
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:154
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:263
Represents a member of a struct/union/class.
Definition: Decl.h:2578
Rewrap the single-element initializer list for a reference.
FieldDecl * getAnonField() const
Definition: Decl.h:2854
int Category
Definition: Format.cpp:1631
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:4211
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:6810
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:3143
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:533
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:312
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.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:636
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:106
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:3250
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:699
__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:89
InitKind getKind() const
Determine the initialization kind.
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:276
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:3175
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:836
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.
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:2824
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:38
Represents a base class of a C++ class.
Definition: DeclCXX.h:191
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:6157
Perform initialization via a constructor, taking arguments from a single InitListExpr.
SourceRange getRange() const
Retrieve the source range that covers the initialization.
bool isParameterConsumed() const
Determine whether this initialization consumes the parameter.
The entity being initialized is a field of block descriptor for the copied-in lambda object that&#39;s us...
The entity being initialized is the field that captures a variable in a lambda.
void setSequenceKind(enum SequenceKind SK)
Set the kind of sequence computed.
A dependent initialization, which could not be type-checked due to the presence of dependent types or...
bool isCStyleCast() const
Determine whether this is a C-style cast.
ObjCMethodDecl * MethodDecl
When Kind == EK_RelatedResult, the ObjectiveC method where result type was implicitly changed to acco...
The initialization is being done by a delegating constructor.
Array initialization (from an array rvalue).
InitKind
The kind of initialization being performed.
QualType getType() const
Definition: Decl.h:647
static InitializedEntity InitializeParameter(ASTContext &Context, const ParmVarDecl *Parm, QualType Type)
Create the initialization entity for a parameter, but use another type.
Default-initialization of a &#39;const&#39; object.
A trivial tuple used to represent a source range.
Describes an entity that is being initialized.
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:706
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