clang 22.0.0git
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
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"
28#include "clang/Sema/Overload.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
39namespace clang {
40
41class CXXBaseSpecifier;
42class CXXConstructorDecl;
43class ObjCMethodDecl;
44class Sema;
45
46/// Describes an entity that is being initialized.
47class alignas(8) InitializedEntity {
48public:
49 /// Specifies the kind of entity being initialized.
51 /// The entity being initialized is a variable.
53
54 /// The entity being initialized is a function parameter.
56
57 /// The entity being initialized is a non-type template parameter.
59
60 /// The entity being initialized is the result of a function call.
62
63 /// The entity being initialized is the result of a statement expression.
65
66 /// The entity being initialized is an exception object that
67 /// is being thrown.
69
70 /// The entity being initialized is a non-static data member
71 /// subobject.
73
74 /// The entity being initialized is an element of an array.
76
77 /// The entity being initialized is an object (or array of
78 /// objects) allocated via new.
80
81 /// The entity being initialized is a temporary object.
83
84 /// The entity being initialized is a base member subobject.
86
87 /// The initialization is being done by a delegating constructor.
89
90 /// The entity being initialized is an element of a vector.
91 /// or vector.
93
94 /// The entity being initialized is a field of block descriptor for
95 /// the copied-in c++ object.
97
98 /// The entity being initialized is a field of block descriptor for the
99 /// copied-in lambda object that's used in the lambda to block conversion.
101
102 /// The entity being initialized is the real or imaginary part of a
103 /// complex number.
105
106 /// The entity being initialized is the field that captures a
107 /// variable in a lambda.
109
110 /// The entity being initialized is the initializer for a compound
111 /// literal.
113
114 /// The entity being implicitly initialized back to the formal
115 /// result type.
117
118 /// The entity being initialized is a function parameter; function
119 /// is member of group of audited CF APIs.
121
122 /// The entity being initialized is a structured binding of a
123 /// decomposition declaration.
125
126 /// The entity being initialized is a non-static data member subobject of an
127 /// object initialized via parenthesized aggregate initialization.
129
130 // Note: err_init_conversion_failed in DiagnosticSemaKinds.td uses this
131 // enum as an index for its first %select. When modifying this list,
132 // that diagnostic text needs to be updated as well.
133 };
134
135private:
136 /// The kind of entity being initialized.
137 EntityKind Kind;
138
139 /// If non-NULL, the parent entity in which this
140 /// initialization occurs.
141 const InitializedEntity *Parent = nullptr;
142
143 /// The type of the object or reference being initialized.
145
146 /// The mangling number for the next reference temporary to be created.
147 mutable unsigned ManglingNumber = 0;
148
149 struct LN {
150 /// When Kind == EK_Result, EK_Exception, EK_New, the
151 /// location of the 'return', 'throw', or 'new' keyword,
152 /// respectively. When Kind == EK_Temporary, the location where
153 /// the temporary is being created.
154 SourceLocation Location;
155
156 /// Whether the entity being initialized may end up using the
157 /// named return value optimization (NRVO).
158 bool NRVO;
159 };
160
161 struct VD {
162 /// The VarDecl, FieldDecl, TemplateParmDecl, or BindingDecl being
163 /// initialized.
164 NamedDecl *VariableOrMember;
165
166 /// When Kind == EK_Member, whether this is an implicit member
167 /// initialization in a copy or move constructor. These can perform array
168 /// copies.
169 bool IsImplicitFieldInit;
170
171 /// When Kind == EK_Member, whether this is the initial initialization
172 /// check for a default member initializer.
173 bool IsDefaultMemberInit;
174 };
175
176 struct C {
177 /// The name of the variable being captured by an EK_LambdaCapture.
178 IdentifierInfo *VarID;
179
180 /// The source location at which the capture occurs.
181 SourceLocation Location;
182 };
183
184 union {
185 /// When Kind == EK_Variable, EK_Member, EK_Binding, or
186 /// EK_TemplateParameter, the variable, binding, or template parameter.
188
189 /// When Kind == EK_RelatedResult, the ObjectiveC method where
190 /// result type was implicitly changed to accommodate ARC semantics.
192
193 /// When Kind == EK_Parameter, the ParmVarDecl, with the
194 /// integer indicating whether the parameter is "consumed".
195 llvm::PointerIntPair<ParmVarDecl *, 1> Parameter;
196
197 /// When Kind == EK_Temporary or EK_CompoundLiteralInit, the type
198 /// source information for the temporary.
200
201 struct LN LocAndNRVO;
202
203 /// When Kind == EK_Base, the base specifier that provides the
204 /// base class. The integer specifies whether the base is an inherited
205 /// virtual base.
206 llvm::PointerIntPair<const CXXBaseSpecifier *, 1> Base;
207
208 /// When Kind == EK_ArrayElement, EK_VectorElement, or
209 /// EK_ComplexElement, the index of the array or vector element being
210 /// initialized.
211 unsigned Index;
212
213 struct C Capture;
214 };
215
217
218 /// Create the initialization entity for a variable.
219 InitializedEntity(VarDecl *Var, EntityKind EK = EK_Variable)
220 : Kind(EK), Type(Var->getType()), Variable{Var, false, false} {}
221
222 /// Create the initialization entity for the result of a
223 /// function, throwing an object, performing an explicit cast, or
224 /// initializing a parameter for which there is no declaration.
225 InitializedEntity(EntityKind Kind, SourceLocation Loc, QualType Type,
226 bool NRVO = false)
227 : Kind(Kind), Type(Type) {
228 new (&LocAndNRVO) LN;
229 LocAndNRVO.Location = Loc;
230 LocAndNRVO.NRVO = NRVO;
231 }
232
233 /// Create the initialization entity for a member subobject.
234 InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent,
235 bool Implicit, bool DefaultMemberInit,
236 bool IsParenAggInit = false)
237 : Kind(IsParenAggInit ? EK_ParenAggInitMember : EK_Member),
239 Variable{Member, Implicit, DefaultMemberInit} {}
240
241 /// Create the initialization entity for an array element.
242 InitializedEntity(ASTContext &Context, unsigned Index,
243 const InitializedEntity &Parent);
244
245 /// Create the initialization entity for a lambda capture.
246 InitializedEntity(IdentifierInfo *VarID, QualType FieldType, SourceLocation Loc)
247 : Kind(EK_LambdaCapture), Type(FieldType) {
248 new (&Capture) C;
249 Capture.VarID = VarID;
250 Capture.Location = Loc;
251 }
252
253public:
254 /// Create the initialization entity for a variable.
256 return InitializedEntity(Var);
257 }
258
259 /// Create the initialization entity for a parameter.
261 ParmVarDecl *Parm) {
262 return InitializeParameter(Context, Parm, Parm->getType());
263 }
264
265 /// Create the initialization entity for a parameter, but use
266 /// another type.
267 static InitializedEntity
269 bool Consumed = (Context.getLangOpts().ObjCAutoRefCount &&
270 Parm->hasAttr<NSConsumedAttr>());
271
272 InitializedEntity Entity;
273 Entity.Kind = EK_Parameter;
274 Entity.Type =
275 Context.getVariableArrayDecayedType(Type.getUnqualifiedType());
276 Entity.Parent = nullptr;
277 Entity.Parameter = {Parm, Consumed};
278 return Entity;
279 }
280
281 /// Create the initialization entity for a parameter that is
282 /// only known by its type.
285 bool Consumed) {
286 InitializedEntity Entity;
287 Entity.Kind = EK_Parameter;
288 Entity.Type = Context.getVariableArrayDecayedType(Type);
289 Entity.Parent = nullptr;
290 Entity.Parameter = {nullptr, Consumed};
291 return Entity;
292 }
293
294 /// Create the initialization entity for a template parameter.
296 NamedDecl *Param) {
297 InitializedEntity Entity;
298 Entity.Kind = EK_TemplateParameter;
299 Entity.Type = T;
300 Entity.Parent = nullptr;
301 Entity.Variable = {Param, false, false};
302 return Entity;
303 }
304
305 /// Create the initialization entity for the result of a function.
307 QualType Type) {
308 return InitializedEntity(EK_Result, ReturnLoc, Type);
309 }
310
312 QualType Type) {
313 return InitializedEntity(EK_StmtExprResult, ReturnLoc, Type);
314 }
315
317 QualType Type) {
318 return InitializedEntity(EK_BlockElement, BlockVarLoc, Type);
319 }
320
322 QualType Type) {
324 BlockVarLoc, Type);
325 }
326
327 /// Create the initialization entity for an exception object.
329 QualType Type) {
330 return InitializedEntity(EK_Exception, ThrowLoc, Type);
331 }
332
333 /// Create the initialization entity for an object allocated via new.
335 return InitializedEntity(EK_New, NewLoc, Type);
336 }
337
338 /// Create the initialization entity for a temporary.
340 return InitializeTemporary(nullptr, Type);
341 }
342
343 /// Create the initialization entity for a temporary.
346 QualType Type = TypeInfo->getType();
347 if (Context.getLangOpts().OpenCLCPlusPlus) {
348 assert(!Type.hasAddressSpace() && "Temporary already has address space!");
349 Type = Context.getAddrSpaceQualType(Type, LangAS::opencl_private);
350 }
351
353 }
354
355 /// Create the initialization entity for a temporary.
357 QualType Type) {
359 Result.TypeInfo = TypeInfo;
360 return Result;
361 }
362
363 /// Create the initialization entity for a related result.
365 QualType Type) {
367 Result.MethodDecl = MD;
368 return Result;
369 }
370
371 /// Create the initialization entity for a base class subobject.
372 static InitializedEntity
374 bool IsInheritedVirtualBase,
375 const InitializedEntity *Parent = nullptr);
376
377 /// Create the initialization entity for a delegated constructor.
380 }
381
382 /// Create the initialization entity for a member subobject.
383 static InitializedEntity
385 const InitializedEntity *Parent = nullptr,
386 bool Implicit = false) {
387 return InitializedEntity(Member, Parent, Implicit, false);
388 }
389
390 /// Create the initialization entity for a member subobject.
391 static InitializedEntity
393 const InitializedEntity *Parent = nullptr,
394 bool Implicit = false) {
395 return InitializedEntity(Member->getAnonField(), Parent, Implicit, false);
396 }
397
398 /// Create the initialization entity for a member subobject initialized via
399 /// parenthesized aggregate init.
401 return InitializedEntity(Member, /*Parent=*/nullptr, /*Implicit=*/false,
402 /*DefaultMemberInit=*/false,
403 /*IsParenAggInit=*/true);
404 }
405
406 /// Create the initialization entity for a default member initializer.
407 static InitializedEntity
409 return InitializedEntity(Member, nullptr, false, true);
410 }
411
412 /// Create the initialization entity for an array element.
414 unsigned Index,
415 const InitializedEntity &Parent) {
416 return InitializedEntity(Context, Index, Parent);
417 }
418
419 /// Create the initialization entity for a structured binding.
421 return InitializedEntity(Binding, EK_Binding);
422 }
423
424 /// Create the initialization entity for a lambda capture.
425 ///
426 /// \p VarID The name of the entity being captured, or nullptr for 'this'.
428 QualType FieldType,
430 return InitializedEntity(VarID, FieldType, Loc);
431 }
432
433 /// Create the entity for a compound literal initializer.
436 TSI->getType());
437 Result.TypeInfo = TSI;
438 return Result;
439 }
440
441 /// Determine the kind of initialization.
442 EntityKind getKind() const { return Kind; }
443
444 /// Retrieve the parent of the entity being initialized, when
445 /// the initialization itself is occurring within the context of a
446 /// larger initialization.
447 const InitializedEntity *getParent() const { return Parent; }
448
449 /// Retrieve type being initialized.
450 QualType getType() const { return Type; }
451
452 /// Retrieve complete type-source information for the object being
453 /// constructed, if known.
456 return TypeInfo;
457
458 return nullptr;
459 }
460
461 /// Retrieve the name of the entity being initialized.
462 DeclarationName getName() const;
463
464 /// Retrieve the variable, parameter, or field being
465 /// initialized.
466 ValueDecl *getDecl() const;
467
468 /// Retrieve the ObjectiveC method being initialized.
470
471 /// Determine whether this initialization allows the named return
472 /// value optimization, which also applies to thrown objects.
473 bool allowsNRVO() const;
474
475 bool isParameterKind() const {
476 return (getKind() == EK_Parameter ||
478 }
479
482 }
483
484 /// Determine whether this initialization consumes the
485 /// parameter.
486 bool isParameterConsumed() const {
487 assert(isParameterKind() && "Not a parameter");
488 return Parameter.getInt();
489 }
490
491 /// Retrieve the base specifier.
493 assert(getKind() == EK_Base && "Not a base specifier");
494 return Base.getPointer();
495 }
496
497 /// Return whether the base is an inherited virtual base.
499 assert(getKind() == EK_Base && "Not a base specifier");
500 return Base.getInt();
501 }
502
503 /// Determine whether this is an array new with an unknown bound.
505 return getKind() == EK_New && isa_and_nonnull<IncompleteArrayType>(
506 getType()->getAsArrayTypeUnsafe());
507 }
508
509 /// Is this the implicit initialization of a member of a class from
510 /// a defaulted constructor?
512 return getKind() == EK_Member && Variable.IsImplicitFieldInit;
513 }
514
515 /// Is this the default member initializer of a member (specified inside
516 /// the class definition)?
518 return getKind() == EK_Member && Variable.IsDefaultMemberInit;
519 }
520
521 /// Determine the location of the 'return' keyword when initializing
522 /// the result of a function call.
524 assert(getKind() == EK_Result && "No 'return' location!");
525 return LocAndNRVO.Location;
526 }
527
528 /// Determine the location of the 'throw' keyword when initializing
529 /// an exception object.
531 assert(getKind() == EK_Exception && "No 'throw' location!");
532 return LocAndNRVO.Location;
533 }
534
535 /// If this is an array, vector, or complex number element, get the
536 /// element's index.
537 unsigned getElementIndex() const {
538 assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
540 return Index;
541 }
542
543 /// If this is already the initializer for an array or vector
544 /// element, sets the element index.
545 void setElementIndex(unsigned Index) {
546 assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
548 this->Index = Index;
549 }
550
551 /// For a lambda capture, return the capture's name.
552 StringRef getCapturedVarName() const {
553 assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
554 return Capture.VarID ? Capture.VarID->getName() : "this";
555 }
556
557 /// Determine the location of the capture when initializing
558 /// field from a captured variable in a lambda.
560 assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
561 return Capture.Location;
562 }
563
566 }
567
568 unsigned allocateManglingNumber() const { return ++ManglingNumber; }
569
570 /// Dump a representation of the initialized entity to standard error,
571 /// for debugging purposes.
572 void dump() const;
573
574private:
575 unsigned dumpImpl(raw_ostream &OS) const;
576};
577
578/// Describes the kind of initialization being performed, along with
579/// location information for tokens related to the initialization (equal sign,
580/// parentheses).
582public:
583 /// The kind of initialization being performed.
584 enum InitKind {
585 /// Direct initialization
587
588 /// Direct list-initialization
590
591 /// Copy initialization
593
594 /// Default initialization
596
597 /// Value initialization
599 };
600
601private:
602 /// The context of the initialization.
603 enum InitContext {
604 /// Normal context
605 IC_Normal,
606
607 /// Normal context, but allows explicit conversion functions
608 IC_ExplicitConvs,
609
610 /// Implicit context (value initialization)
611 IC_Implicit,
612
613 /// Static cast context
614 IC_StaticCast,
615
616 /// C-style cast context
617 IC_CStyleCast,
618
619 /// Functional cast context
620 IC_FunctionalCast
621 };
622
623 /// The kind of initialization being performed.
624 InitKind Kind : 8;
625
626 /// The context of the initialization.
627 InitContext Context : 8;
628
629 /// The source locations involved in the initialization.
630 SourceLocation Locations[3];
631
632 InitializationKind(InitKind Kind, InitContext Context, SourceLocation Loc1,
633 SourceLocation Loc2, SourceLocation Loc3)
634 : Kind(Kind), Context(Context) {
635 Locations[0] = Loc1;
636 Locations[1] = Loc2;
637 Locations[2] = Loc3;
638 }
639
640public:
641 /// Create a direct initialization.
643 SourceLocation LParenLoc,
644 SourceLocation RParenLoc) {
645 return InitializationKind(IK_Direct, IC_Normal,
646 InitLoc, LParenLoc, RParenLoc);
647 }
648
650 return InitializationKind(IK_DirectList, IC_Normal, InitLoc, InitLoc,
651 InitLoc);
652 }
653
655 SourceLocation LBraceLoc,
656 SourceLocation RBraceLoc) {
657 return InitializationKind(IK_DirectList, IC_Normal, InitLoc, LBraceLoc,
658 RBraceLoc);
659 }
660
661 /// Create a direct initialization due to a cast that isn't a C-style
662 /// or functional cast.
664 return InitializationKind(IK_Direct, IC_StaticCast, TypeRange.getBegin(),
665 TypeRange.getBegin(), TypeRange.getEnd());
666 }
667
668 /// Create a direct initialization for a C-style cast.
670 SourceRange TypeRange,
671 bool InitList) {
672 // C++ cast syntax doesn't permit init lists, but C compound literals are
673 // exactly that.
674 return InitializationKind(InitList ? IK_DirectList : IK_Direct,
675 IC_CStyleCast, StartLoc, TypeRange.getBegin(),
676 TypeRange.getEnd());
677 }
678
679 /// Create a direct initialization for a functional cast.
681 SourceRange ParenRange,
682 bool InitList) {
683 return InitializationKind(InitList ? IK_DirectList : IK_Direct,
684 IC_FunctionalCast, StartLoc,
685 ParenRange.getBegin(), ParenRange.getEnd());
686 }
687
688 /// Create a copy initialization.
690 SourceLocation EqualLoc,
691 bool AllowExplicitConvs = false) {
693 AllowExplicitConvs? IC_ExplicitConvs : IC_Normal,
694 InitLoc, EqualLoc, EqualLoc);
695 }
696
697 /// Create a default initialization.
699 return InitializationKind(IK_Default, IC_Normal, InitLoc, InitLoc, InitLoc);
700 }
701
702 /// Create a value initialization.
704 SourceLocation LParenLoc,
705 SourceLocation RParenLoc,
706 bool isImplicit = false) {
707 return InitializationKind(IK_Value, isImplicit ? IC_Implicit : IC_Normal,
708 InitLoc, LParenLoc, RParenLoc);
709 }
710
711 /// Create an initialization from an initializer (which, for direct
712 /// initialization from a parenthesized list, will be a ParenListExpr).
714 Expr *Init) {
715 if (!Init) return CreateDefault(Loc);
716 if (!DirectInit)
717 return CreateCopy(Loc, Init->getBeginLoc());
718 if (isa<InitListExpr>(Init))
719 return CreateDirectList(Loc, Init->getBeginLoc(), Init->getEndLoc());
720 return CreateDirect(Loc, Init->getBeginLoc(), Init->getEndLoc());
721 }
722
723 /// Determine the initialization kind.
725 return Kind;
726 }
727
728 /// Determine whether this initialization is an explicit cast.
729 bool isExplicitCast() const {
730 return Context >= IC_StaticCast;
731 }
732
733 /// Determine whether this initialization is a static cast.
734 bool isStaticCast() const { return Context == IC_StaticCast; }
735
736 /// Determine whether this initialization is a C-style cast.
738 return Context >= IC_CStyleCast;
739 }
740
741 /// Determine whether this is a C-style cast.
742 bool isCStyleCast() const {
743 return Context == IC_CStyleCast;
744 }
745
746 /// Determine whether this is a functional-style cast.
747 bool isFunctionalCast() const {
748 return Context == IC_FunctionalCast;
749 }
750
751 /// Determine whether this initialization is an implicit
752 /// value-initialization, e.g., as occurs during aggregate
753 /// initialization.
754 bool isImplicitValueInit() const { return Context == IC_Implicit; }
755
756 /// Retrieve the location at which initialization is occurring.
757 SourceLocation getLocation() const { return Locations[0]; }
758
759 /// Retrieve the source range that covers the initialization.
761 return SourceRange(Locations[0], Locations[2]);
762 }
763
764 /// Retrieve the location of the equal sign for copy initialization
765 /// (if present).
767 assert(Kind == IK_Copy && "Only copy initialization has an '='");
768 return Locations[1];
769 }
770
771 bool isCopyInit() const { return Kind == IK_Copy; }
772
773 /// Retrieve whether this initialization allows the use of explicit
774 /// constructors.
775 bool AllowExplicit() const { return !isCopyInit(); }
776
777 /// Retrieve whether this initialization allows the use of explicit
778 /// conversion functions when binding a reference. If the reference is the
779 /// first parameter in a copy or move constructor, such conversions are
780 /// permitted even though we are performing copy-initialization.
782 return !isCopyInit() || Context == IC_ExplicitConvs;
783 }
784
785 /// Determine whether this initialization has a source range containing the
786 /// locations of open and closing parentheses or braces.
787 bool hasParenOrBraceRange() const {
788 return Kind == IK_Direct || Kind == IK_Value || Kind == IK_DirectList;
789 }
790
791 /// Retrieve the source range containing the locations of the open
792 /// and closing parentheses or braces for value, direct, and direct list
793 /// initializations.
795 assert(hasParenOrBraceRange() && "Only direct, value, and direct-list "
796 "initialization have parentheses or "
797 "braces");
798 return SourceRange(Locations[1], Locations[2]);
799 }
800};
801
802/// Describes the sequence of initializations required to initialize
803/// a given object or reference with a set of arguments.
805public:
806 /// Describes the kind of initialization sequence computed.
808 /// A failed initialization sequence. The failure kind tells what
809 /// happened.
811
812 /// A dependent initialization, which could not be
813 /// type-checked due to the presence of dependent types or
814 /// dependently-typed expressions.
816
817 /// A normal sequence.
819 };
820
821 /// Describes the kind of a particular step in an initialization
822 /// sequence.
823 enum StepKind {
824 /// Resolve the address of an overloaded function to a specific
825 /// function declaration.
827
828 /// Perform a derived-to-base cast, producing an rvalue.
830
831 /// Perform a derived-to-base cast, producing an xvalue.
833
834 /// Perform a derived-to-base cast, producing an lvalue.
836
837 /// Reference binding to an lvalue.
839
840 /// Reference binding to a temporary.
842
843 /// An optional copy of a temporary object to another
844 /// temporary object, which is permitted (but not required) by
845 /// C++98/03 but not C++0x.
847
848 /// Direct-initialization from a reference-related object in the
849 /// final stage of class copy-initialization.
851
852 /// Perform a user-defined conversion, either via a conversion
853 /// function or via a constructor.
855
856 /// Perform a qualification conversion, producing a prvalue.
858
859 /// Perform a qualification conversion, producing an xvalue.
861
862 /// Perform a qualification conversion, producing an lvalue.
864
865 /// Perform a function reference conversion, see [dcl.init.ref]p4.
867
868 /// Perform a conversion adding _Atomic to a type.
870
871 /// Perform an implicit conversion sequence.
873
874 /// Perform an implicit conversion sequence without narrowing.
876
877 /// Perform list-initialization without a constructor.
879
880 /// Unwrap the single-element initializer list for a reference.
882
883 /// Rewrap the single-element initializer list for a reference.
885
886 /// Perform initialization via a constructor.
888
889 /// Perform initialization via a constructor, taking arguments from
890 /// a single InitListExpr.
892
893 /// Zero-initialize the object
895
896 /// C assignment
898
899 /// Initialization by string
901
902 /// An initialization that "converts" an Objective-C object
903 /// (not a point to an object) to another Objective-C object type.
905
906 /// Array indexing for initialization by elementwise copy.
908
909 /// Array initialization by elementwise copy.
911
912 /// Array initialization (from an array rvalue).
914
915 /// Array initialization (from an array rvalue) as a GNU extension.
917
918 /// Array initialization from a parenthesized initializer list.
919 /// This is a GNU C++ extension.
921
922 /// Pass an object by indirect copy-and-restore.
924
925 /// Pass an object by indirect restore.
927
928 /// Produce an Objective-C object pointer.
930
931 /// Construct a std::initializer_list from an initializer list.
933
934 /// Perform initialization via a constructor taking a single
935 /// std::initializer_list argument.
937
938 /// Initialize an OpenCL sampler from an integer.
940
941 /// Initialize an opaque OpenCL type (event_t, queue_t, etc.) with zero
943
944 /// Initialize an aggreagate with parenthesized list of values.
945 /// This is a C++20 feature.
947 };
948
949 /// A single step in the initialization sequence.
950 class Step {
951 public:
952 /// The kind of conversion or initialization step we are taking.
954
955 // The type that results from this initialization.
957
958 struct F {
962 };
963
964 union {
965 /// When Kind == SK_ResolvedOverloadedFunction or Kind ==
966 /// SK_UserConversion, the function that the expression should be
967 /// resolved to or the conversion function to call, respectively.
968 /// When Kind == SK_ConstructorInitialization or SK_ListConstruction,
969 /// the constructor to be called.
970 ///
971 /// Always a FunctionDecl, plus a Boolean flag telling if it was
972 /// selected from an overloaded set having size greater than 1.
973 /// For conversion decls, the naming class is the source type.
974 /// For construct decls, the naming class is the target type.
975 struct F Function;
976
977 /// When Kind = SK_ConversionSequence, the implicit conversion
978 /// sequence.
980
981 /// When Kind = SK_RewrapInitList, the syntactic form of the
982 /// wrapping list.
984 };
985
986 void Destroy();
987 };
988
989private:
990 /// The kind of initialization sequence computed.
992
993 /// Steps taken by this initialization.
995
996public:
997 /// Describes why initialization failed.
999 /// Too many initializers provided for a reference.
1001
1002 /// Reference initialized from a parenthesized initializer list.
1004
1005 /// Array must be initialized with an initializer list.
1007
1008 /// Array must be initialized with an initializer list or a
1009 /// string literal.
1011
1012 /// Array must be initialized with an initializer list or a
1013 /// wide string literal.
1015
1016 /// Initializing a wide char array with narrow string literal.
1018
1019 /// Initializing char array with wide string literal.
1021
1022 /// Initializing wide char array with incompatible wide string
1023 /// literal.
1025
1026 /// Initializing char8_t array with plain string literal.
1028
1029 /// Initializing char array with UTF-8 string literal.
1031
1032 /// Array type mismatch.
1034
1035 /// Non-constant array initializer
1037
1038 /// Cannot resolve the address of an overloaded function.
1040
1041 /// Overloading due to reference initialization failed.
1043
1044 /// Non-const lvalue reference binding to a temporary.
1046
1047 /// Non-const lvalue reference binding to a bit-field.
1049
1050 /// Non-const lvalue reference binding to a vector element.
1052
1053 /// Non-const lvalue reference binding to a matrix element.
1055
1056 /// Non-const lvalue reference binding to an lvalue of unrelated
1057 /// type.
1059
1060 /// Rvalue reference binding to an lvalue.
1062
1063 /// Reference binding drops qualifiers.
1065
1066 /// Reference with mismatching address space binding to temporary.
1068
1069 /// Reference binding failed.
1071
1072 /// Implicit conversion failed.
1074
1075 /// Implicit conversion failed.
1077
1078 /// Too many initializers for scalar
1080
1081 /// Scalar initialized from a parenthesized initializer list.
1083
1084 /// Reference initialization from an initializer list
1086
1087 /// Initialization of some unused destination type with an
1088 /// initializer list.
1090
1091 /// Overloading for a user-defined conversion failed.
1093
1094 /// Overloading for initialization by constructor failed.
1096
1097 /// Overloading for list-initialization by constructor failed.
1099
1100 /// Default-initialization of a 'const' object.
1102
1103 /// Initialization of an incomplete type.
1105
1106 /// Variable-length array must not have an initializer.
1108
1109 /// List initialization failed at some point.
1111
1112 /// Initializer has a placeholder type which cannot be
1113 /// resolved by initialization.
1115
1116 /// Trying to take the address of a function that doesn't support
1117 /// having its address taken.
1119
1120 /// List-copy-initialization chose an explicit constructor.
1122
1123 /// Parenthesized list initialization failed at some point.
1124 /// This is a C++20 feature.
1126
1127 // A designated initializer was provided for a non-aggregate type.
1129 };
1130
1131private:
1132 /// The reason why initialization failed.
1133 FailureKind Failure;
1134
1135 /// The failed result of overload resolution.
1136 OverloadingResult FailedOverloadResult;
1137
1138 /// The candidate set created when initialization failed.
1139 OverloadCandidateSet FailedCandidateSet;
1140
1141 /// The incomplete type that caused a failure.
1142 QualType FailedIncompleteType;
1143
1144 /// The fixit that needs to be applied to make this initialization
1145 /// succeed.
1146 std::string ZeroInitializationFixit;
1147 SourceLocation ZeroInitializationFixitLoc;
1148
1149public:
1150 /// Call for initializations are invalid but that would be valid
1151 /// zero initialzations if Fixit was applied.
1152 void SetZeroInitializationFixit(const std::string& Fixit, SourceLocation L) {
1153 ZeroInitializationFixit = Fixit;
1154 ZeroInitializationFixitLoc = L;
1155 }
1156
1157private:
1158 /// Prints a follow-up note that highlights the location of
1159 /// the initialized entity, if it's remote.
1160 void PrintInitLocationNote(Sema &S, const InitializedEntity &Entity);
1161
1162public:
1163 /// Try to perform initialization of the given entity, creating a
1164 /// record of the steps required to perform the initialization.
1165 ///
1166 /// The generated initialization sequence will either contain enough
1167 /// information to diagnose
1168 ///
1169 /// \param S the semantic analysis object.
1170 ///
1171 /// \param Entity the entity being initialized.
1172 ///
1173 /// \param Kind the kind of initialization being performed.
1174 ///
1175 /// \param Args the argument(s) provided for initialization.
1176 ///
1177 /// \param TopLevelOfInitList true if we are initializing from an expression
1178 /// at the top level inside an initializer list. This disallows
1179 /// narrowing conversions in C++11 onwards.
1180 /// \param TreatUnavailableAsInvalid true if we want to treat unavailable
1181 /// as invalid.
1183 const InitializedEntity &Entity,
1184 const InitializationKind &Kind,
1185 MultiExprArg Args,
1186 bool TopLevelOfInitList = false,
1187 bool TreatUnavailableAsInvalid = true);
1188 void InitializeFrom(Sema &S, const InitializedEntity &Entity,
1190 bool TopLevelOfInitList, bool TreatUnavailableAsInvalid);
1191
1193
1194 /// Perform the actual initialization of the given entity based on
1195 /// the computed initialization sequence.
1196 ///
1197 /// \param S the semantic analysis object.
1198 ///
1199 /// \param Entity the entity being initialized.
1200 ///
1201 /// \param Kind the kind of initialization being performed.
1202 ///
1203 /// \param Args the argument(s) provided for initialization, ownership of
1204 /// which is transferred into the routine.
1205 ///
1206 /// \param ResultType if non-NULL, will be set to the type of the
1207 /// initialized object, which is the type of the declaration in most
1208 /// cases. However, when the initialized object is a variable of
1209 /// incomplete array type and the initializer is an initializer
1210 /// list, this type will be set to the completed array type.
1211 ///
1212 /// \returns an expression that performs the actual object initialization, if
1213 /// the initialization is well-formed. Otherwise, emits diagnostics
1214 /// and returns an invalid expression.
1216 const InitializedEntity &Entity,
1217 const InitializationKind &Kind,
1218 MultiExprArg Args,
1219 QualType *ResultType = nullptr);
1220
1221 /// Diagnose an potentially-invalid initialization sequence.
1222 ///
1223 /// \returns true if the initialization sequence was ill-formed,
1224 /// false otherwise.
1225 bool Diagnose(Sema &S,
1226 const InitializedEntity &Entity,
1227 const InitializationKind &Kind,
1228 ArrayRef<Expr *> Args);
1229
1230 /// Determine the kind of initialization sequence computed.
1231 enum SequenceKind getKind() const { return SequenceKind; }
1232
1233 /// Set the kind of sequence computed.
1235
1236 /// Determine whether the initialization sequence is valid.
1237 explicit operator bool() const { return !Failed(); }
1238
1239 /// Determine whether the initialization sequence is invalid.
1240 bool Failed() const { return SequenceKind == FailedSequence; }
1241
1243
1244 step_iterator step_begin() const { return Steps.begin(); }
1245 step_iterator step_end() const { return Steps.end(); }
1246
1247 using step_range = llvm::iterator_range<step_iterator>;
1248
1249 step_range steps() const { return {step_begin(), step_end()}; }
1250
1251 /// Determine whether this initialization is a direct reference
1252 /// binding (C++ [dcl.init.ref]).
1253 bool isDirectReferenceBinding() const;
1254
1255 /// Determine whether this initialization failed due to an ambiguity.
1256 bool isAmbiguous() const;
1257
1258 /// Determine whether this initialization is direct call to a
1259 /// constructor.
1260 bool isConstructorInitialization() const;
1261
1262 /// Add a new step in the initialization that resolves the address
1263 /// of an overloaded function to a specific function declaration.
1264 ///
1265 /// \param Function the function to which the overloaded function reference
1266 /// resolves.
1269 bool HadMultipleCandidates);
1270
1271 /// Add a new step in the initialization that performs a derived-to-
1272 /// base cast.
1273 ///
1274 /// \param BaseType the base type to which we will be casting.
1275 ///
1276 /// \param Category Indicates whether the result will be treated as an
1277 /// rvalue, an xvalue, or an lvalue.
1278 void AddDerivedToBaseCastStep(QualType BaseType,
1280
1281 /// Add a new step binding a reference to an object.
1282 ///
1283 /// \param BindingTemporary True if we are binding a reference to a temporary
1284 /// object (thereby extending its lifetime); false if we are binding to an
1285 /// lvalue or an lvalue treated as an rvalue.
1286 void AddReferenceBindingStep(QualType T, bool BindingTemporary);
1287
1288 /// Add a new step that makes an extraneous copy of the input
1289 /// to a temporary of the same class type.
1290 ///
1291 /// This extraneous copy only occurs during reference binding in
1292 /// C++98/03, where we are permitted (but not required) to introduce
1293 /// an extra copy. At a bare minimum, we must check that we could
1294 /// call the copy constructor, and produce a diagnostic if the copy
1295 /// constructor is inaccessible or no copy constructor matches.
1296 //
1297 /// \param T The type of the temporary being created.
1299
1300 /// Add a new step that makes a copy of the input to an object of
1301 /// the given type, as the final step in class copy-initialization.
1302 void AddFinalCopy(QualType T);
1303
1304 /// Add a new step invoking a conversion function, which is either
1305 /// a constructor or a conversion function.
1307 DeclAccessPair FoundDecl,
1308 QualType T,
1309 bool HadMultipleCandidates);
1310
1311 /// Add a new step that performs a qualification conversion to the
1312 /// given type.
1315
1316 /// Add a new step that performs a function reference conversion to the
1317 /// given type.
1319
1320 /// Add a new step that performs conversion from non-atomic to atomic
1321 /// type.
1323
1324 /// Add a new step that applies an implicit conversion sequence.
1326 QualType T, bool TopLevelOfInitList = false);
1327
1328 /// Add a list-initialization step.
1330
1331 /// Add a constructor-initialization step.
1332 ///
1333 /// \param FromInitList The constructor call is syntactically an initializer
1334 /// list.
1335 /// \param AsInitList The constructor is called as an init list constructor.
1338 QualType T,
1339 bool HadMultipleCandidates,
1340 bool FromInitList, bool AsInitList);
1341
1342 /// Add a zero-initialization step.
1344
1345 /// Add a C assignment step.
1346 //
1347 // FIXME: It isn't clear whether this should ever be needed;
1348 // ideally, we would handle everything needed in C in the common
1349 // path. However, that isn't the case yet.
1351
1352 /// Add a string init step.
1354
1355 /// Add an Objective-C object conversion step, which is
1356 /// always a no-op.
1358
1359 /// Add an array initialization loop step.
1361
1362 /// Add an array initialization step.
1363 void AddArrayInitStep(QualType T, bool IsGNUExtension);
1364
1365 /// Add a parenthesized array initialization step.
1367
1368 /// Add a step to pass an object by indirect copy-restore.
1369 void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy);
1370
1371 /// Add a step to "produce" an Objective-C object (by
1372 /// retaining it).
1374
1375 /// Add a step to construct a std::initializer_list object from an
1376 /// initializer list.
1378
1379 /// Add a step to initialize an OpenCL sampler from an integer
1380 /// constant.
1382
1383 /// Add a step to initialzie an OpenCL opaque type (event_t, queue_t, etc.)
1384 /// from a zero constant.
1386
1388
1389 /// Only used when initializing structured bindings from an array with
1390 /// direct-list-initialization. Unwrap the initializer list to get the array
1391 /// for array copy.
1392 void AddUnwrapInitListInitStep(InitListExpr *Syntactic);
1393
1394 /// Add steps to unwrap a initializer list for a reference around a
1395 /// single element and rewrap it at the end.
1397
1398 /// Note that this initialization sequence failed.
1399 void SetFailed(FailureKind Failure) {
1401 this->Failure = Failure;
1402 assert((Failure != FK_Incomplete || !FailedIncompleteType.isNull()) &&
1403 "Incomplete type failure requires a type!");
1404 }
1405
1406 /// Note that this initialization sequence failed due to failed
1407 /// overload resolution.
1409
1410 /// Retrieve a reference to the candidate set when overload
1411 /// resolution fails.
1413 return FailedCandidateSet;
1414 }
1415
1416 /// Get the overloading result, for when the initialization
1417 /// sequence failed due to a bad overload.
1419 return FailedOverloadResult;
1420 }
1421
1422 /// Note that this initialization sequence failed due to an
1423 /// incomplete type.
1424 void setIncompleteTypeFailure(QualType IncompleteType) {
1425 FailedIncompleteType = IncompleteType;
1427 }
1428
1429 /// Determine why initialization failed.
1431 assert(Failed() && "Not an initialization failure!");
1432 return Failure;
1433 }
1434
1435 /// Dump a representation of this initialization sequence to
1436 /// the given stream, for debugging purposes.
1437 void dump(raw_ostream &OS) const;
1438
1439 /// Dump a representation of this initialization sequence to
1440 /// standard error, for debugging purposes.
1441 void dump() const;
1442};
1443
1444} // namespace clang
1445
1446#endif // LLVM_CLANG_SEMA_INITIALIZATION_H
Defines the clang::ASTContext interface.
NodeId Parent
Definition: ASTDiff.cpp:191
MatchType Type
enum clang::sema::@1840::IndirectLocalPathEntry::EntryKind Kind
int Category
Definition: Format.cpp:3180
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::LangOptions interface.
SourceLocation Loc
Definition: SemaObjC.cpp:754
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2604
A POD class for pairing a NamedDecl* with an access specifier.
bool hasAttr() const
Definition: DeclBase.h:577
The name of a declaration.
This represents one expression.
Definition: Expr.h:112
Represents a member of a struct/union/class.
Definition: Decl.h:3153
Represents a function declaration or definition.
Definition: Decl.h:1999
One of these records is kept for each identifier that is lexed.
ImplicitConversionSequence - Represents an implicit conversion sequence, which may be a standard conv...
Definition: Overload.h:615
Represents a field injected from an anonymous union/struct into the parent scope.
Definition: Decl.h:3460
Describes an C or C++ initializer list.
Definition: Expr.h:5235
Describes the kind of initialization being performed, along with location information for tokens rela...
SourceLocation getLocation() const
Retrieve the location at which initialization is occurring.
static InitializationKind CreateCast(SourceRange TypeRange)
Create a direct initialization due to a cast that isn't a C-style or functional cast.
InitKind
The kind of initialization being performed.
@ IK_DirectList
Direct list-initialization.
@ IK_Value
Value initialization.
@ IK_Direct
Direct initialization.
@ IK_Copy
Copy initialization.
@ IK_Default
Default initialization.
SourceLocation getEqualLoc() const
Retrieve the location of the equal sign for copy initialization (if present).
bool isCStyleOrFunctionalCast() const
Determine whether this initialization is a C-style cast.
static InitializationKind CreateDefault(SourceLocation InitLoc)
Create a default initialization.
bool hasParenOrBraceRange() const
Determine whether this initialization has a source range containing the locations of open and closing...
bool isExplicitCast() const
Determine whether this initialization is an explicit cast.
bool isFunctionalCast() const
Determine whether this is a functional-style cast.
InitKind getKind() const
Determine the initialization kind.
static InitializationKind CreateFunctionalCast(SourceLocation StartLoc, SourceRange ParenRange, bool InitList)
Create a direct initialization for a functional cast.
bool AllowExplicit() const
Retrieve whether this initialization allows the use of explicit constructors.
static InitializationKind CreateDirect(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a direct initialization.
static InitializationKind CreateForInit(SourceLocation Loc, bool DirectInit, Expr *Init)
Create an initialization from an initializer (which, for direct initialization from a parenthesized l...
bool isImplicitValueInit() const
Determine whether this initialization is an implicit value-initialization, e.g., as occurs during agg...
bool isCStyleCast() const
Determine whether this is a C-style cast.
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
static InitializationKind CreateDirectList(SourceLocation InitLoc)
SourceRange getParenOrBraceRange() const
Retrieve the source range containing the locations of the open and closing parentheses or braces for ...
bool allowExplicitConversionFunctionsInRefBinding() const
Retrieve whether this initialization allows the use of explicit conversion functions when binding a r...
static InitializationKind CreateDirectList(SourceLocation InitLoc, SourceLocation LBraceLoc, SourceLocation RBraceLoc)
bool isStaticCast() const
Determine whether this initialization is a static cast.
static InitializationKind CreateValue(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc, bool isImplicit=false)
Create a value initialization.
SourceRange getRange() const
Retrieve the source range that covers the initialization.
static InitializationKind CreateCStyleCast(SourceLocation StartLoc, SourceRange TypeRange, bool InitList)
Create a direct initialization for a C-style cast.
A single step in the initialization sequence.
StepKind Kind
The kind of conversion or initialization step we are taking.
InitListExpr * WrappingSyntacticList
When Kind = SK_RewrapInitList, the syntactic form of the wrapping list.
ImplicitConversionSequence * ICS
When Kind = SK_ConversionSequence, the implicit conversion sequence.
struct F Function
When Kind == SK_ResolvedOverloadedFunction or Kind == SK_UserConversion, the function that the expres...
Describes the sequence of initializations required to initialize a given object or reference with a s...
step_iterator step_begin() const
void AddListInitializationStep(QualType T)
Add a list-initialization step.
Definition: SemaInit.cpp:4047
ExprResult Perform(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, QualType *ResultType=nullptr)
Perform the actual initialization of the given entity based on the computed initialization sequence.
Definition: SemaInit.cpp:7739
void AddStringInitStep(QualType T)
Add a string init step.
Definition: SemaInit.cpp:4082
void AddStdInitializerListConstructionStep(QualType T)
Add a step to construct a std::initializer_list object from an initializer list.
Definition: SemaInit.cpp:4137
void AddConstructorInitializationStep(DeclAccessPair FoundDecl, CXXConstructorDecl *Constructor, QualType T, bool HadMultipleCandidates, bool FromInitList, bool AsInitList)
Add a constructor-initialization step.
Definition: SemaInit.cpp:4054
StepKind
Describes the kind of a particular step in an initialization sequence.
@ SK_StdInitializerListConstructorCall
Perform initialization via a constructor taking a single std::initializer_list argument.
@ SK_AtomicConversion
Perform a conversion adding _Atomic to a type.
@ SK_ObjCObjectConversion
An initialization that "converts" an Objective-C object (not a point to an object) to another Objecti...
@ SK_GNUArrayInit
Array initialization (from an array rvalue) as a GNU extension.
@ SK_CastDerivedToBaseLValue
Perform a derived-to-base cast, producing an lvalue.
@ SK_ProduceObjCObject
Produce an Objective-C object pointer.
@ SK_FunctionReferenceConversion
Perform a function reference conversion, see [dcl.init.ref]p4.
@ SK_BindReference
Reference binding to an lvalue.
@ SK_ArrayLoopInit
Array initialization by elementwise copy.
@ SK_ConstructorInitialization
Perform initialization via a constructor.
@ SK_OCLSamplerInit
Initialize an OpenCL sampler from an integer.
@ SK_StringInit
Initialization by string.
@ SK_ZeroInitialization
Zero-initialize the object.
@ SK_CastDerivedToBaseXValue
Perform a derived-to-base cast, producing an xvalue.
@ SK_QualificationConversionXValue
Perform a qualification conversion, producing an xvalue.
@ SK_UserConversion
Perform a user-defined conversion, either via a conversion function or via a constructor.
@ SK_CastDerivedToBasePRValue
Perform a derived-to-base cast, producing an rvalue.
@ SK_BindReferenceToTemporary
Reference binding to a temporary.
@ SK_PassByIndirectRestore
Pass an object by indirect restore.
@ SK_ParenthesizedArrayInit
Array initialization from a parenthesized initializer list.
@ SK_ParenthesizedListInit
Initialize an aggreagate with parenthesized list of values.
@ SK_ArrayInit
Array initialization (from an array rvalue).
@ SK_ExtraneousCopyToTemporary
An optional copy of a temporary object to another temporary object, which is permitted (but not requi...
@ SK_ArrayLoopIndex
Array indexing for initialization by elementwise copy.
@ SK_ConversionSequenceNoNarrowing
Perform an implicit conversion sequence without narrowing.
@ SK_RewrapInitList
Rewrap the single-element initializer list for a reference.
@ SK_ConstructorInitializationFromList
Perform initialization via a constructor, taking arguments from a single InitListExpr.
@ SK_PassByIndirectCopyRestore
Pass an object by indirect copy-and-restore.
@ SK_ResolveAddressOfOverloadedFunction
Resolve the address of an overloaded function to a specific function declaration.
@ SK_UnwrapInitList
Unwrap the single-element initializer list for a reference.
@ SK_FinalCopy
Direct-initialization from a reference-related object in the final stage of class copy-initialization...
@ SK_QualificationConversionLValue
Perform a qualification conversion, producing an lvalue.
@ SK_StdInitializerList
Construct a std::initializer_list from an initializer list.
@ SK_QualificationConversionPRValue
Perform a qualification conversion, producing a prvalue.
@ SK_ConversionSequence
Perform an implicit conversion sequence.
@ SK_ListInitialization
Perform list-initialization without a constructor.
@ SK_OCLZeroOpaqueType
Initialize an opaque OpenCL type (event_t, queue_t, etc.) with zero.
void AddUserConversionStep(FunctionDecl *Function, DeclAccessPair FoundDecl, QualType T, bool HadMultipleCandidates)
Add a new step invoking a conversion function, which is either a constructor or a conversion function...
Definition: SemaInit.cpp:3990
void SetZeroInitializationFixit(const std::string &Fixit, SourceLocation L)
Call for initializations are invalid but that would be valid zero initialzations if Fixit was applied...
llvm::iterator_range< step_iterator > step_range
void AddQualificationConversionStep(QualType Ty, ExprValueKind Category)
Add a new step that performs a qualification conversion to the given type.
Definition: SemaInit.cpp:4003
void AddFunctionReferenceConversionStep(QualType Ty)
Add a new step that performs a function reference conversion to the given type.
Definition: SemaInit.cpp:4022
void AddDerivedToBaseCastStep(QualType BaseType, ExprValueKind Category)
Add a new step in the initialization that performs a derived-to- base cast.
Definition: SemaInit.cpp:3953
FailureKind getFailureKind() const
Determine why initialization failed.
void InitializeFrom(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, bool TopLevelOfInitList, bool TreatUnavailableAsInvalid)
Definition: SemaInit.cpp:6528
void AddParenthesizedListInitStep(QualType T)
Definition: SemaInit.cpp:4158
void SetFailed(FailureKind Failure)
Note that this initialization sequence failed.
bool isAmbiguous() const
Determine whether this initialization failed due to an ambiguity.
Definition: SemaInit.cpp:3881
void AddUnwrapInitListInitStep(InitListExpr *Syntactic)
Only used when initializing structured bindings from an array with direct-list-initialization.
Definition: SemaInit.cpp:4165
void AddOCLZeroOpaqueTypeStep(QualType T)
Add a step to initialzie an OpenCL opaque type (event_t, queue_t, etc.) from a zero constant.
Definition: SemaInit.cpp:4151
void AddFinalCopy(QualType T)
Add a new step that makes a copy of the input to an object of the given type, as the final step in cl...
Definition: SemaInit.cpp:3975
OverloadingResult getFailedOverloadResult() const
Get the overloading result, for when the initialization sequence failed due to a bad overload.
void setSequenceKind(enum SequenceKind SK)
Set the kind of sequence computed.
void AddObjCObjectConversionStep(QualType T)
Add an Objective-C object conversion step, which is always a no-op.
Definition: SemaInit.cpp:4089
void SetOverloadFailure(FailureKind Failure, OverloadingResult Result)
Note that this initialization sequence failed due to failed overload resolution.
Definition: SemaInit.cpp:4190
step_iterator step_end() const
void AddParenthesizedArrayInitStep(QualType T)
Add a parenthesized array initialization step.
Definition: SemaInit.cpp:4114
void AddExtraneousCopyToTemporary(QualType T)
Add a new step that makes an extraneous copy of the input to a temporary of the same class type.
Definition: SemaInit.cpp:3982
void setIncompleteTypeFailure(QualType IncompleteType)
Note that this initialization sequence failed due to an incomplete type.
void AddOCLSamplerInitStep(QualType T)
Add a step to initialize an OpenCL sampler from an integer constant.
Definition: SemaInit.cpp:4144
void AddCAssignmentStep(QualType T)
Add a C assignment step.
Definition: SemaInit.cpp:4075
void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy)
Add a step to pass an object by indirect copy-restore.
Definition: SemaInit.cpp:4121
void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic)
Add steps to unwrap a initializer list for a reference around a single element and rewrap it at the e...
Definition: SemaInit.cpp:4175
bool Diagnose(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, ArrayRef< Expr * > Args)
Diagnose an potentially-invalid initialization sequence.
Definition: SemaInit.cpp:8821
bool Failed() const
Determine whether the initialization sequence is invalid.
void AddAtomicConversionStep(QualType Ty)
Add a new step that performs conversion from non-atomic to atomic type.
Definition: SemaInit.cpp:4029
void dump() const
Dump a representation of this initialization sequence to standard error, for debugging purposes.
Definition: SemaInit.cpp:9685
void AddConversionSequenceStep(const ImplicitConversionSequence &ICS, QualType T, bool TopLevelOfInitList=false)
Add a new step that applies an implicit conversion sequence.
Definition: SemaInit.cpp:4036
void AddZeroInitializationStep(QualType T)
Add a zero-initialization step.
Definition: SemaInit.cpp:4068
void AddProduceObjCObjectStep(QualType T)
Add a step to "produce" an Objective-C object (by retaining it).
Definition: SemaInit.cpp:4130
enum SequenceKind getKind() const
Determine the kind of initialization sequence computed.
SequenceKind
Describes the kind of initialization sequence computed.
@ NormalSequence
A normal sequence.
@ FailedSequence
A failed initialization sequence.
@ DependentSequence
A dependent initialization, which could not be type-checked due to the presence of dependent types or...
void AddReferenceBindingStep(QualType T, bool BindingTemporary)
Add a new step binding a reference to an object.
Definition: SemaInit.cpp:3967
FailureKind
Describes why initialization failed.
@ FK_UserConversionOverloadFailed
Overloading for a user-defined conversion failed.
@ FK_NarrowStringIntoWideCharArray
Initializing a wide char array with narrow string literal.
@ FK_ArrayTypeMismatch
Array type mismatch.
@ FK_ParenthesizedListInitForReference
Reference initialized from a parenthesized initializer list.
@ FK_NonConstLValueReferenceBindingToVectorElement
Non-const lvalue reference binding to a vector element.
@ FK_ReferenceInitDropsQualifiers
Reference binding drops qualifiers.
@ FK_InitListBadDestinationType
Initialization of some unused destination type with an initializer list.
@ FK_ConversionFromPropertyFailed
Implicit conversion failed.
@ FK_NonConstLValueReferenceBindingToUnrelated
Non-const lvalue reference binding to an lvalue of unrelated type.
@ FK_ListConstructorOverloadFailed
Overloading for list-initialization by constructor failed.
@ FK_ReferenceInitFailed
Reference binding failed.
@ FK_ArrayNeedsInitList
Array must be initialized with an initializer list.
@ FK_PlainStringIntoUTF8Char
Initializing char8_t array with plain string literal.
@ FK_NonConstantArrayInit
Non-constant array initializer.
@ FK_NonConstLValueReferenceBindingToTemporary
Non-const lvalue reference binding to a temporary.
@ FK_ConversionFailed
Implicit conversion failed.
@ FK_ArrayNeedsInitListOrStringLiteral
Array must be initialized with an initializer list or a string literal.
@ FK_ParenthesizedListInitForScalar
Scalar initialized from a parenthesized initializer list.
@ FK_PlaceholderType
Initializer has a placeholder type which cannot be resolved by initialization.
@ FK_IncompatWideStringIntoWideChar
Initializing wide char array with incompatible wide string literal.
@ FK_NonConstLValueReferenceBindingToMatrixElement
Non-const lvalue reference binding to a matrix element.
@ FK_TooManyInitsForReference
Too many initializers provided for a reference.
@ FK_NonConstLValueReferenceBindingToBitfield
Non-const lvalue reference binding to a bit-field.
@ FK_ReferenceAddrspaceMismatchTemporary
Reference with mismatching address space binding to temporary.
@ FK_ListInitializationFailed
List initialization failed at some point.
@ FK_TooManyInitsForScalar
Too many initializers for scalar.
@ FK_AddressOfOverloadFailed
Cannot resolve the address of an overloaded function.
@ FK_VariableLengthArrayHasInitializer
Variable-length array must not have an initializer.
@ FK_ArrayNeedsInitListOrWideStringLiteral
Array must be initialized with an initializer list or a wide string literal.
@ FK_RValueReferenceBindingToLValue
Rvalue reference binding to an lvalue.
@ FK_Incomplete
Initialization of an incomplete type.
@ FK_WideStringIntoCharArray
Initializing char array with wide string literal.
@ FK_ExplicitConstructor
List-copy-initialization chose an explicit constructor.
@ FK_ReferenceInitOverloadFailed
Overloading due to reference initialization failed.
@ FK_ConstructorOverloadFailed
Overloading for initialization by constructor failed.
@ FK_ReferenceBindingToInitList
Reference initialization from an initializer list.
@ FK_DefaultInitOfConst
Default-initialization of a 'const' object.
@ FK_ParenthesizedListInitFailed
Parenthesized list initialization failed at some point.
@ FK_AddressOfUnaddressableFunction
Trying to take the address of a function that doesn't support having its address taken.
@ FK_UTF8StringIntoPlainChar
Initializing char array with UTF-8 string literal.
bool isDirectReferenceBinding() const
Determine whether this initialization is a direct reference binding (C++ [dcl.init....
Definition: SemaInit.cpp:3870
void AddArrayInitLoopStep(QualType T, QualType EltTy)
Add an array initialization loop step.
Definition: SemaInit.cpp:4103
void AddAddressOverloadResolutionStep(FunctionDecl *Function, DeclAccessPair Found, bool HadMultipleCandidates)
Add a new step in the initialization that resolves the address of an overloaded function to a specifi...
Definition: SemaInit.cpp:3941
void AddArrayInitStep(QualType T, bool IsGNUExtension)
Add an array initialization step.
Definition: SemaInit.cpp:4096
bool isConstructorInitialization() const
Determine whether this initialization is direct call to a constructor.
Definition: SemaInit.cpp:3935
SmallVectorImpl< Step >::const_iterator step_iterator
OverloadCandidateSet & getFailedCandidateSet()
Retrieve a reference to the candidate set when overload resolution fails.
Describes an entity that is being initialized.
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:3651
static InitializedEntity InitializeResult(SourceLocation ReturnLoc, QualType Type)
Create the initialization entity for the result of a function.
static InitializedEntity InitializeMember(FieldDecl *Member, const InitializedEntity *Parent=nullptr, bool Implicit=false)
Create the initialization entity for a member subobject.
VD Variable
When Kind == EK_Variable, EK_Member, EK_Binding, or EK_TemplateParameter, the variable,...
static InitializedEntity InitializeRelatedResult(ObjCMethodDecl *MD, QualType Type)
Create the initialization entity for a related result.
EntityKind getKind() const
Determine the kind of initialization.
DeclarationName getName() const
Retrieve the name of the entity being initialized.
Definition: SemaInit.cpp:3663
static InitializedEntity InitializeException(SourceLocation ThrowLoc, QualType Type)
Create the initialization entity for an exception object.
unsigned allocateManglingNumber() const
QualType getType() const
Retrieve type being initialized.
static InitializedEntity InitializeTemporary(ASTContext &Context, TypeSourceInfo *TypeInfo)
Create the initialization entity for a temporary.
ValueDecl * getDecl() const
Retrieve the variable, parameter, or field being initialized.
Definition: SemaInit.cpp:3701
static InitializedEntity InitializeParameter(ASTContext &Context, QualType Type, bool Consumed)
Create the initialization entity for a parameter that is only known by its type.
static InitializedEntity InitializeStmtExprResult(SourceLocation ReturnLoc, QualType Type)
bool isImplicitMemberInitializer() const
Is this the implicit initialization of a member of a class from a defaulted constructor?
const InitializedEntity * getParent() const
Retrieve the parent of the entity being initialized, when the initialization itself is occurring with...
static InitializedEntity InitializeTemporary(QualType Type)
Create the initialization entity for a temporary.
bool isParameterConsumed() const
Determine whether this initialization consumes the parameter.
static InitializedEntity InitializeBinding(VarDecl *Binding)
Create the initialization entity for a structured binding.
static InitializedEntity InitializeParameter(ASTContext &Context, ParmVarDecl *Parm, QualType Type)
Create the initialization entity for a parameter, but use another type.
TypeSourceInfo * TypeInfo
When Kind == EK_Temporary or EK_CompoundLiteralInit, the type source information for the temporary.
static InitializedEntity InitializeMemberFromDefaultMemberInitializer(FieldDecl *Member)
Create the initialization entity for a default member initializer.
static InitializedEntity InitializeElement(ASTContext &Context, unsigned Index, const InitializedEntity &Parent)
Create the initialization entity for an array element.
unsigned getElementIndex() const
If this is an array, vector, or complex number element, get the element's index.
bool isInheritedVirtualBase() const
Return whether the base is an inherited virtual base.
static InitializedEntity InitializeLambdaToBlock(SourceLocation BlockVarLoc, QualType Type)
void setElementIndex(unsigned Index)
If this is already the initializer for an array or vector element, sets the element index.
SourceLocation getCaptureLoc() const
Determine the location of the capture when initializing field from a captured variable in a lambda.
static InitializedEntity InitializeBlock(SourceLocation BlockVarLoc, QualType Type)
bool isParamOrTemplateParamKind() const
static InitializedEntity InitializeNew(SourceLocation NewLoc, QualType Type)
Create the initialization entity for an object allocated via new.
llvm::PointerIntPair< const CXXBaseSpecifier *, 1 > Base
When Kind == EK_Base, the base specifier that provides the base class.
static InitializedEntity InitializeTemporary(TypeSourceInfo *TypeInfo, QualType Type)
Create the initialization entity for a temporary.
static InitializedEntity InitializeVariable(VarDecl *Var)
Create the initialization entity for a variable.
bool allowsNRVO() const
Determine whether this initialization allows the named return value optimization, which also applies ...
Definition: SemaInit.cpp:3735
void dump() const
Dump a representation of the initialized entity to standard error, for debugging purposes.
Definition: SemaInit.cpp:3816
static InitializedEntity InitializeParameter(ASTContext &Context, ParmVarDecl *Parm)
Create the initialization entity for a parameter.
static InitializedEntity InitializeLambdaCapture(IdentifierInfo *VarID, QualType FieldType, SourceLocation Loc)
Create the initialization entity for a lambda capture.
static InitializedEntity InitializeTemplateParameter(QualType T, NamedDecl *Param)
Create the initialization entity for a template parameter.
EntityKind
Specifies the kind of entity being initialized.
@ EK_Variable
The entity being initialized is a variable.
@ EK_Temporary
The entity being initialized is a temporary object.
@ EK_Binding
The entity being initialized is a structured binding of a decomposition declaration.
@ EK_BlockElement
The entity being initialized is a field of block descriptor for the copied-in c++ object.
@ EK_Parameter_CF_Audited
The entity being initialized is a function parameter; function is member of group of audited CF APIs.
@ EK_LambdaToBlockConversionBlockElement
The entity being initialized is a field of block descriptor for the copied-in lambda object that's us...
@ EK_Member
The entity being initialized is a non-static data member subobject.
@ EK_Base
The entity being initialized is a base member subobject.
@ EK_Result
The entity being initialized is the result of a function call.
@ EK_TemplateParameter
The entity being initialized is a non-type template parameter.
@ EK_StmtExprResult
The entity being initialized is the result of a statement expression.
@ EK_ParenAggInitMember
The entity being initialized is a non-static data member subobject of an object initialized via paren...
@ EK_VectorElement
The entity being initialized is an element of a vector.
@ EK_New
The entity being initialized is an object (or array of objects) allocated via new.
@ EK_CompoundLiteralInit
The entity being initialized is the initializer for a compound literal.
@ EK_Parameter
The entity being initialized is a function parameter.
@ EK_Delegating
The initialization is being done by a delegating constructor.
@ EK_ComplexElement
The entity being initialized is the real or imaginary part of a complex number.
@ EK_ArrayElement
The entity being initialized is an element of an array.
@ EK_LambdaCapture
The entity being initialized is the field that captures a variable in a lambda.
@ EK_Exception
The entity being initialized is an exception object that is being thrown.
@ EK_RelatedResult
The entity being implicitly initialized back to the formal result type.
StringRef getCapturedVarName() const
For a lambda capture, return the capture's name.
static InitializedEntity InitializeMemberFromParenAggInit(FieldDecl *Member)
Create the initialization entity for a member subobject initialized via parenthesized aggregate init.
SourceLocation getThrowLoc() const
Determine the location of the 'throw' keyword when initializing an exception object.
static InitializedEntity InitializeDelegation(QualType Type)
Create the initialization entity for a delegated constructor.
unsigned Index
When Kind == EK_ArrayElement, EK_VectorElement, or EK_ComplexElement, the index of the array or vecto...
static InitializedEntity InitializeCompoundLiteralInit(TypeSourceInfo *TSI)
Create the entity for a compound literal initializer.
static InitializedEntity InitializeMember(IndirectFieldDecl *Member, const InitializedEntity *Parent=nullptr, bool Implicit=false)
Create the initialization entity for a member subobject.
bool isVariableLengthArrayNew() const
Determine whether this is an array new with an unknown bound.
ObjCMethodDecl * MethodDecl
When Kind == EK_RelatedResult, the ObjectiveC method where result type was implicitly changed to acco...
bool isDefaultMemberInitializer() const
Is this the default member initializer of a member (specified inside the class definition)?
llvm::PointerIntPair< ParmVarDecl *, 1 > Parameter
When Kind == EK_Parameter, the ParmVarDecl, with the integer indicating whether the parameter is "con...
const CXXBaseSpecifier * getBaseSpecifier() const
Retrieve the base specifier.
SourceLocation getReturnLoc() const
Determine the location of the 'return' keyword when initializing the result of a function call.
TypeSourceInfo * getTypeSourceInfo() const
Retrieve complete type-source information for the object being constructed, if known.
ObjCMethodDecl * getMethodDecl() const
Retrieve the ObjectiveC method being initialized.
This represents a decl that may have a name.
Definition: Decl.h:273
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13....
Definition: Overload.h:1153
Represents a parameter to a function.
Definition: Decl.h:1789
A (possibly-)qualified type.
Definition: TypeBase.h:937
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: TypeBase.h:1004
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:850
Encodes a location in the source.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
A container of type source information.
Definition: TypeBase.h:8314
QualType getType() const
Return the type wrapped by this type source info.
Definition: TypeBase.h:8325
The base class of the type hierarchy.
Definition: TypeBase.h:1833
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:711
QualType getType() const
Definition: Decl.h:722
Represents a variable declaration or definition.
Definition: Decl.h:925
#define bool
Definition: gpuintrin.h:32
The JSON file list parser is used to communicate input to InstallAPI.
OverloadingResult
OverloadingResult - Capture the result of performing overload resolution.
Definition: Overload.h:50
@ Result
The result type of a method or function.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:132
const FunctionProtoType * T
@ Implicit
An implicit conversion.
#define false
Definition: stdbool.h:26