clang 20.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, or BindingDecl being initialized.
163 ValueDecl *VariableOrMember;
164
165 /// When Kind == EK_Member, whether this is an implicit member
166 /// initialization in a copy or move constructor. These can perform array
167 /// copies.
168 bool IsImplicitFieldInit;
169
170 /// When Kind == EK_Member, whether this is the initial initialization
171 /// check for a default member initializer.
172 bool IsDefaultMemberInit;
173 };
174
175 struct C {
176 /// The name of the variable being captured by an EK_LambdaCapture.
177 IdentifierInfo *VarID;
178
179 /// The source location at which the capture occurs.
180 SourceLocation Location;
181 };
182
183 union {
184 /// When Kind == EK_Variable, EK_Member, EK_Binding, or
185 /// EK_TemplateParameter, the variable, binding, or template parameter.
187
188 /// When Kind == EK_RelatedResult, the ObjectiveC method where
189 /// result type was implicitly changed to accommodate ARC semantics.
191
192 /// When Kind == EK_Parameter, the ParmVarDecl, with the
193 /// integer indicating whether the parameter is "consumed".
194 llvm::PointerIntPair<ParmVarDecl *, 1> Parameter;
195
196 /// When Kind == EK_Temporary or EK_CompoundLiteralInit, the type
197 /// source information for the temporary.
199
200 struct LN LocAndNRVO;
201
202 /// When Kind == EK_Base, the base specifier that provides the
203 /// base class. The integer specifies whether the base is an inherited
204 /// virtual base.
205 llvm::PointerIntPair<const CXXBaseSpecifier *, 1> Base;
206
207 /// When Kind == EK_ArrayElement, EK_VectorElement, or
208 /// EK_ComplexElement, the index of the array or vector element being
209 /// initialized.
210 unsigned Index;
211
212 struct C Capture;
213 };
214
216
217 /// Create the initialization entity for a variable.
218 InitializedEntity(VarDecl *Var, EntityKind EK = EK_Variable)
219 : Kind(EK), Type(Var->getType()), Variable{Var, false, false} {}
220
221 /// Create the initialization entity for the result of a
222 /// function, throwing an object, performing an explicit cast, or
223 /// initializing a parameter for which there is no declaration.
224 InitializedEntity(EntityKind Kind, SourceLocation Loc, QualType Type,
225 bool NRVO = false)
226 : Kind(Kind), Type(Type) {
227 new (&LocAndNRVO) LN;
228 LocAndNRVO.Location = Loc;
229 LocAndNRVO.NRVO = NRVO;
230 }
231
232 /// Create the initialization entity for a member subobject.
233 InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent,
234 bool Implicit, bool DefaultMemberInit,
235 bool IsParenAggInit = false)
236 : Kind(IsParenAggInit ? EK_ParenAggInitMember : EK_Member),
238 Variable{Member, Implicit, DefaultMemberInit} {}
239
240 /// Create the initialization entity for an array element.
241 InitializedEntity(ASTContext &Context, unsigned Index,
242 const InitializedEntity &Parent);
243
244 /// Create the initialization entity for a lambda capture.
245 InitializedEntity(IdentifierInfo *VarID, QualType FieldType, SourceLocation Loc)
246 : Kind(EK_LambdaCapture), Type(FieldType) {
247 new (&Capture) C;
248 Capture.VarID = VarID;
249 Capture.Location = Loc;
250 }
251
252public:
253 /// Create the initialization entity for a variable.
255 return InitializedEntity(Var);
256 }
257
258 /// Create the initialization entity for a parameter.
260 ParmVarDecl *Parm) {
261 return InitializeParameter(Context, Parm, Parm->getType());
262 }
263
264 /// Create the initialization entity for a parameter, but use
265 /// another type.
266 static InitializedEntity
268 bool Consumed = (Context.getLangOpts().ObjCAutoRefCount &&
269 Parm->hasAttr<NSConsumedAttr>());
270
271 InitializedEntity Entity;
272 Entity.Kind = EK_Parameter;
273 Entity.Type =
274 Context.getVariableArrayDecayedType(Type.getUnqualifiedType());
275 Entity.Parent = nullptr;
276 Entity.Parameter = {Parm, Consumed};
277 return Entity;
278 }
279
280 /// Create the initialization entity for a parameter that is
281 /// only known by its type.
284 bool Consumed) {
285 InitializedEntity Entity;
286 Entity.Kind = EK_Parameter;
287 Entity.Type = Context.getVariableArrayDecayedType(Type);
288 Entity.Parent = nullptr;
289 Entity.Parameter = {nullptr, Consumed};
290 return Entity;
291 }
292
293 /// Create the initialization entity for a template parameter.
294 static InitializedEntity
296 InitializedEntity Entity;
297 Entity.Kind = EK_TemplateParameter;
298 Entity.Type = T;
299 Entity.Parent = nullptr;
300 Entity.Variable = {Param, false, false};
301 return Entity;
302 }
303
304 /// Create the initialization entity for the result of a function.
306 QualType Type) {
307 return InitializedEntity(EK_Result, ReturnLoc, Type);
308 }
309
311 QualType Type) {
312 return InitializedEntity(EK_StmtExprResult, ReturnLoc, Type);
313 }
314
316 QualType Type) {
317 return InitializedEntity(EK_BlockElement, BlockVarLoc, Type);
318 }
319
321 QualType Type) {
323 BlockVarLoc, Type);
324 }
325
326 /// Create the initialization entity for an exception object.
328 QualType Type) {
329 return InitializedEntity(EK_Exception, ThrowLoc, Type);
330 }
331
332 /// Create the initialization entity for an object allocated via new.
334 return InitializedEntity(EK_New, NewLoc, Type);
335 }
336
337 /// Create the initialization entity for a temporary.
339 return InitializeTemporary(nullptr, Type);
340 }
341
342 /// Create the initialization entity for a temporary.
345 QualType Type = TypeInfo->getType();
346 if (Context.getLangOpts().OpenCLCPlusPlus) {
347 assert(!Type.hasAddressSpace() && "Temporary already has address space!");
348 Type = Context.getAddrSpaceQualType(Type, LangAS::opencl_private);
349 }
350
352 }
353
354 /// Create the initialization entity for a temporary.
356 QualType Type) {
358 Result.TypeInfo = TypeInfo;
359 return Result;
360 }
361
362 /// Create the initialization entity for a related result.
364 QualType Type) {
366 Result.MethodDecl = MD;
367 return Result;
368 }
369
370 /// Create the initialization entity for a base class subobject.
371 static InitializedEntity
373 bool IsInheritedVirtualBase,
374 const InitializedEntity *Parent = nullptr);
375
376 /// Create the initialization entity for a delegated constructor.
379 }
380
381 /// Create the initialization entity for a member subobject.
382 static InitializedEntity
384 const InitializedEntity *Parent = nullptr,
385 bool Implicit = false) {
386 return InitializedEntity(Member, Parent, Implicit, false);
387 }
388
389 /// Create the initialization entity for a member subobject.
390 static InitializedEntity
392 const InitializedEntity *Parent = nullptr,
393 bool Implicit = false) {
394 return InitializedEntity(Member->getAnonField(), Parent, Implicit, false);
395 }
396
397 /// Create the initialization entity for a member subobject initialized via
398 /// parenthesized aggregate init.
400 return InitializedEntity(Member, /*Parent=*/nullptr, /*Implicit=*/false,
401 /*DefaultMemberInit=*/false,
402 /*IsParenAggInit=*/true);
403 }
404
405 /// Create the initialization entity for a default member initializer.
406 static InitializedEntity
408 return InitializedEntity(Member, nullptr, false, true);
409 }
410
411 /// Create the initialization entity for an array element.
413 unsigned Index,
414 const InitializedEntity &Parent) {
415 return InitializedEntity(Context, Index, Parent);
416 }
417
418 /// Create the initialization entity for a structured binding.
420 return InitializedEntity(Binding, EK_Binding);
421 }
422
423 /// Create the initialization entity for a lambda capture.
424 ///
425 /// \p VarID The name of the entity being captured, or nullptr for 'this'.
427 QualType FieldType,
429 return InitializedEntity(VarID, FieldType, Loc);
430 }
431
432 /// Create the entity for a compound literal initializer.
435 TSI->getType());
436 Result.TypeInfo = TSI;
437 return Result;
438 }
439
440 /// Determine the kind of initialization.
441 EntityKind getKind() const { return Kind; }
442
443 /// Retrieve the parent of the entity being initialized, when
444 /// the initialization itself is occurring within the context of a
445 /// larger initialization.
446 const InitializedEntity *getParent() const { return Parent; }
447
448 /// Retrieve type being initialized.
449 QualType getType() const { return Type; }
450
451 /// Retrieve complete type-source information for the object being
452 /// constructed, if known.
455 return TypeInfo;
456
457 return nullptr;
458 }
459
460 /// Retrieve the name of the entity being initialized.
461 DeclarationName getName() const;
462
463 /// Retrieve the variable, parameter, or field being
464 /// initialized.
465 ValueDecl *getDecl() const;
466
467 /// Retrieve the ObjectiveC method being initialized.
469
470 /// Determine whether this initialization allows the named return
471 /// value optimization, which also applies to thrown objects.
472 bool allowsNRVO() const;
473
474 bool isParameterKind() const {
475 return (getKind() == EK_Parameter ||
477 }
478
481 }
482
483 /// Determine whether this initialization consumes the
484 /// parameter.
485 bool isParameterConsumed() const {
486 assert(isParameterKind() && "Not a parameter");
487 return Parameter.getInt();
488 }
489
490 /// Retrieve the base specifier.
492 assert(getKind() == EK_Base && "Not a base specifier");
493 return Base.getPointer();
494 }
495
496 /// Return whether the base is an inherited virtual base.
498 assert(getKind() == EK_Base && "Not a base specifier");
499 return Base.getInt();
500 }
501
502 /// Determine whether this is an array new with an unknown bound.
504 return getKind() == EK_New && isa_and_nonnull<IncompleteArrayType>(
505 getType()->getAsArrayTypeUnsafe());
506 }
507
508 /// Is this the implicit initialization of a member of a class from
509 /// a defaulted constructor?
511 return getKind() == EK_Member && Variable.IsImplicitFieldInit;
512 }
513
514 /// Is this the default member initializer of a member (specified inside
515 /// the class definition)?
517 return getKind() == EK_Member && Variable.IsDefaultMemberInit;
518 }
519
520 /// Determine the location of the 'return' keyword when initializing
521 /// the result of a function call.
523 assert(getKind() == EK_Result && "No 'return' location!");
524 return LocAndNRVO.Location;
525 }
526
527 /// Determine the location of the 'throw' keyword when initializing
528 /// an exception object.
530 assert(getKind() == EK_Exception && "No 'throw' location!");
531 return LocAndNRVO.Location;
532 }
533
534 /// If this is an array, vector, or complex number element, get the
535 /// element's index.
536 unsigned getElementIndex() const {
537 assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
539 return Index;
540 }
541
542 /// If this is already the initializer for an array or vector
543 /// element, sets the element index.
544 void setElementIndex(unsigned Index) {
545 assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
547 this->Index = Index;
548 }
549
550 /// For a lambda capture, return the capture's name.
551 StringRef getCapturedVarName() const {
552 assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
553 return Capture.VarID ? Capture.VarID->getName() : "this";
554 }
555
556 /// Determine the location of the capture when initializing
557 /// field from a captured variable in a lambda.
559 assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
560 return Capture.Location;
561 }
562
565 }
566
567 unsigned allocateManglingNumber() const { return ++ManglingNumber; }
568
569 /// Dump a representation of the initialized entity to standard error,
570 /// for debugging purposes.
571 void dump() const;
572
573private:
574 unsigned dumpImpl(raw_ostream &OS) const;
575};
576
577/// Describes the kind of initialization being performed, along with
578/// location information for tokens related to the initialization (equal sign,
579/// parentheses).
581public:
582 /// The kind of initialization being performed.
583 enum InitKind {
584 /// Direct initialization
586
587 /// Direct list-initialization
589
590 /// Copy initialization
592
593 /// Default initialization
595
596 /// Value initialization
598 };
599
600private:
601 /// The context of the initialization.
602 enum InitContext {
603 /// Normal context
604 IC_Normal,
605
606 /// Normal context, but allows explicit conversion functions
607 IC_ExplicitConvs,
608
609 /// Implicit context (value initialization)
610 IC_Implicit,
611
612 /// Static cast context
613 IC_StaticCast,
614
615 /// C-style cast context
616 IC_CStyleCast,
617
618 /// Functional cast context
619 IC_FunctionalCast
620 };
621
622 /// The kind of initialization being performed.
623 InitKind Kind : 8;
624
625 /// The context of the initialization.
626 InitContext Context : 8;
627
628 /// The source locations involved in the initialization.
629 SourceLocation Locations[3];
630
631 InitializationKind(InitKind Kind, InitContext Context, SourceLocation Loc1,
632 SourceLocation Loc2, SourceLocation Loc3)
633 : Kind(Kind), Context(Context) {
634 Locations[0] = Loc1;
635 Locations[1] = Loc2;
636 Locations[2] = Loc3;
637 }
638
639public:
640 /// Create a direct initialization.
642 SourceLocation LParenLoc,
643 SourceLocation RParenLoc) {
644 return InitializationKind(IK_Direct, IC_Normal,
645 InitLoc, LParenLoc, RParenLoc);
646 }
647
649 return InitializationKind(IK_DirectList, IC_Normal, InitLoc, InitLoc,
650 InitLoc);
651 }
652
654 SourceLocation LBraceLoc,
655 SourceLocation RBraceLoc) {
656 return InitializationKind(IK_DirectList, IC_Normal, InitLoc, LBraceLoc,
657 RBraceLoc);
658 }
659
660 /// Create a direct initialization due to a cast that isn't a C-style
661 /// or functional cast.
663 return InitializationKind(IK_Direct, IC_StaticCast, TypeRange.getBegin(),
664 TypeRange.getBegin(), TypeRange.getEnd());
665 }
666
667 /// Create a direct initialization for a C-style cast.
669 SourceRange TypeRange,
670 bool InitList) {
671 // C++ cast syntax doesn't permit init lists, but C compound literals are
672 // exactly that.
673 return InitializationKind(InitList ? IK_DirectList : IK_Direct,
674 IC_CStyleCast, StartLoc, TypeRange.getBegin(),
675 TypeRange.getEnd());
676 }
677
678 /// Create a direct initialization for a functional cast.
680 bool InitList) {
681 return InitializationKind(InitList ? IK_DirectList : IK_Direct,
682 IC_FunctionalCast, TypeRange.getBegin(),
683 TypeRange.getBegin(), TypeRange.getEnd());
684 }
685
686 /// Create a copy initialization.
688 SourceLocation EqualLoc,
689 bool AllowExplicitConvs = false) {
691 AllowExplicitConvs? IC_ExplicitConvs : IC_Normal,
692 InitLoc, EqualLoc, EqualLoc);
693 }
694
695 /// Create a default initialization.
697 return InitializationKind(IK_Default, IC_Normal, InitLoc, InitLoc, InitLoc);
698 }
699
700 /// Create a value initialization.
702 SourceLocation LParenLoc,
703 SourceLocation RParenLoc,
704 bool isImplicit = false) {
705 return InitializationKind(IK_Value, isImplicit ? IC_Implicit : IC_Normal,
706 InitLoc, LParenLoc, RParenLoc);
707 }
708
709 /// Create an initialization from an initializer (which, for direct
710 /// initialization from a parenthesized list, will be a ParenListExpr).
712 Expr *Init) {
713 if (!Init) return CreateDefault(Loc);
714 if (!DirectInit)
715 return CreateCopy(Loc, Init->getBeginLoc());
716 if (isa<InitListExpr>(Init))
717 return CreateDirectList(Loc, Init->getBeginLoc(), Init->getEndLoc());
718 return CreateDirect(Loc, Init->getBeginLoc(), Init->getEndLoc());
719 }
720
721 /// Determine the initialization kind.
723 return Kind;
724 }
725
726 /// Determine whether this initialization is an explicit cast.
727 bool isExplicitCast() const {
728 return Context >= IC_StaticCast;
729 }
730
731 /// Determine whether this initialization is a static cast.
732 bool isStaticCast() const { return Context == IC_StaticCast; }
733
734 /// Determine whether this initialization is a C-style cast.
736 return Context >= IC_CStyleCast;
737 }
738
739 /// Determine whether this is a C-style cast.
740 bool isCStyleCast() const {
741 return Context == IC_CStyleCast;
742 }
743
744 /// Determine whether this is a functional-style cast.
745 bool isFunctionalCast() const {
746 return Context == IC_FunctionalCast;
747 }
748
749 /// Determine whether this initialization is an implicit
750 /// value-initialization, e.g., as occurs during aggregate
751 /// initialization.
752 bool isImplicitValueInit() const { return Context == IC_Implicit; }
753
754 /// Retrieve the location at which initialization is occurring.
755 SourceLocation getLocation() const { return Locations[0]; }
756
757 /// Retrieve the source range that covers the initialization.
759 return SourceRange(Locations[0], Locations[2]);
760 }
761
762 /// Retrieve the location of the equal sign for copy initialization
763 /// (if present).
765 assert(Kind == IK_Copy && "Only copy initialization has an '='");
766 return Locations[1];
767 }
768
769 bool isCopyInit() const { return Kind == IK_Copy; }
770
771 /// Retrieve whether this initialization allows the use of explicit
772 /// constructors.
773 bool AllowExplicit() const { return !isCopyInit(); }
774
775 /// Retrieve whether this initialization allows the use of explicit
776 /// conversion functions when binding a reference. If the reference is the
777 /// first parameter in a copy or move constructor, such conversions are
778 /// permitted even though we are performing copy-initialization.
780 return !isCopyInit() || Context == IC_ExplicitConvs;
781 }
782
783 /// Determine whether this initialization has a source range containing the
784 /// locations of open and closing parentheses or braces.
785 bool hasParenOrBraceRange() const {
786 return Kind == IK_Direct || Kind == IK_Value || Kind == IK_DirectList;
787 }
788
789 /// Retrieve the source range containing the locations of the open
790 /// and closing parentheses or braces for value, direct, and direct list
791 /// initializations.
793 assert(hasParenOrBraceRange() && "Only direct, value, and direct-list "
794 "initialization have parentheses or "
795 "braces");
796 return SourceRange(Locations[1], Locations[2]);
797 }
798};
799
800/// Describes the sequence of initializations required to initialize
801/// a given object or reference with a set of arguments.
803public:
804 /// Describes the kind of initialization sequence computed.
806 /// A failed initialization sequence. The failure kind tells what
807 /// happened.
809
810 /// A dependent initialization, which could not be
811 /// type-checked due to the presence of dependent types or
812 /// dependently-typed expressions.
814
815 /// A normal sequence.
817 };
818
819 /// Describes the kind of a particular step in an initialization
820 /// sequence.
821 enum StepKind {
822 /// Resolve the address of an overloaded function to a specific
823 /// function declaration.
825
826 /// Perform a derived-to-base cast, producing an rvalue.
828
829 /// Perform a derived-to-base cast, producing an xvalue.
831
832 /// Perform a derived-to-base cast, producing an lvalue.
834
835 /// Reference binding to an lvalue.
837
838 /// Reference binding to a temporary.
840
841 /// An optional copy of a temporary object to another
842 /// temporary object, which is permitted (but not required) by
843 /// C++98/03 but not C++0x.
845
846 /// Direct-initialization from a reference-related object in the
847 /// final stage of class copy-initialization.
849
850 /// Perform a user-defined conversion, either via a conversion
851 /// function or via a constructor.
853
854 /// Perform a qualification conversion, producing a prvalue.
856
857 /// Perform a qualification conversion, producing an xvalue.
859
860 /// Perform a qualification conversion, producing an lvalue.
862
863 /// Perform a function reference conversion, see [dcl.init.ref]p4.
865
866 /// Perform a conversion adding _Atomic to a type.
868
869 /// Perform an implicit conversion sequence.
871
872 /// Perform an implicit conversion sequence without narrowing.
874
875 /// Perform list-initialization without a constructor.
877
878 /// Unwrap the single-element initializer list for a reference.
880
881 /// Rewrap the single-element initializer list for a reference.
883
884 /// Perform initialization via a constructor.
886
887 /// Perform initialization via a constructor, taking arguments from
888 /// a single InitListExpr.
890
891 /// Zero-initialize the object
893
894 /// C assignment
896
897 /// Initialization by string
899
900 /// An initialization that "converts" an Objective-C object
901 /// (not a point to an object) to another Objective-C object type.
903
904 /// Array indexing for initialization by elementwise copy.
906
907 /// Array initialization by elementwise copy.
909
910 /// Array initialization (from an array rvalue).
912
913 /// Array initialization (from an array rvalue) as a GNU extension.
915
916 /// Array initialization from a parenthesized initializer list.
917 /// This is a GNU C++ extension.
919
920 /// Pass an object by indirect copy-and-restore.
922
923 /// Pass an object by indirect restore.
925
926 /// Produce an Objective-C object pointer.
928
929 /// Construct a std::initializer_list from an initializer list.
931
932 /// Perform initialization via a constructor taking a single
933 /// std::initializer_list argument.
935
936 /// Initialize an OpenCL sampler from an integer.
938
939 /// Initialize an opaque OpenCL type (event_t, queue_t, etc.) with zero
941
942 /// Initialize an aggreagate with parenthesized list of values.
943 /// This is a C++20 feature.
945 };
946
947 /// A single step in the initialization sequence.
948 class Step {
949 public:
950 /// The kind of conversion or initialization step we are taking.
952
953 // The type that results from this initialization.
955
956 struct F {
960 };
961
962 union {
963 /// When Kind == SK_ResolvedOverloadedFunction or Kind ==
964 /// SK_UserConversion, the function that the expression should be
965 /// resolved to or the conversion function to call, respectively.
966 /// When Kind == SK_ConstructorInitialization or SK_ListConstruction,
967 /// the constructor to be called.
968 ///
969 /// Always a FunctionDecl, plus a Boolean flag telling if it was
970 /// selected from an overloaded set having size greater than 1.
971 /// For conversion decls, the naming class is the source type.
972 /// For construct decls, the naming class is the target type.
973 struct F Function;
974
975 /// When Kind = SK_ConversionSequence, the implicit conversion
976 /// sequence.
978
979 /// When Kind = SK_RewrapInitList, the syntactic form of the
980 /// wrapping list.
982 };
983
984 void Destroy();
985 };
986
987private:
988 /// The kind of initialization sequence computed.
990
991 /// Steps taken by this initialization.
993
994public:
995 /// Describes why initialization failed.
997 /// Too many initializers provided for a reference.
999
1000 /// Reference initialized from a parenthesized initializer list.
1002
1003 /// Array must be initialized with an initializer list.
1005
1006 /// Array must be initialized with an initializer list or a
1007 /// string literal.
1009
1010 /// Array must be initialized with an initializer list or a
1011 /// wide string literal.
1013
1014 /// Initializing a wide char array with narrow string literal.
1016
1017 /// Initializing char array with wide string literal.
1019
1020 /// Initializing wide char array with incompatible wide string
1021 /// literal.
1023
1024 /// Initializing char8_t array with plain string literal.
1026
1027 /// Initializing char array with UTF-8 string literal.
1029
1030 /// Array type mismatch.
1032
1033 /// Non-constant array initializer
1035
1036 /// Cannot resolve the address of an overloaded function.
1038
1039 /// Overloading due to reference initialization failed.
1041
1042 /// Non-const lvalue reference binding to a temporary.
1044
1045 /// Non-const lvalue reference binding to a bit-field.
1047
1048 /// Non-const lvalue reference binding to a vector element.
1050
1051 /// Non-const lvalue reference binding to a matrix element.
1053
1054 /// Non-const lvalue reference binding to an lvalue of unrelated
1055 /// type.
1057
1058 /// Rvalue reference binding to an lvalue.
1060
1061 /// Reference binding drops qualifiers.
1063
1064 /// Reference with mismatching address space binding to temporary.
1066
1067 /// Reference binding failed.
1069
1070 /// Implicit conversion failed.
1072
1073 /// Implicit conversion failed.
1075
1076 /// Too many initializers for scalar
1078
1079 /// Scalar initialized from a parenthesized initializer list.
1081
1082 /// Reference initialization from an initializer list
1084
1085 /// Initialization of some unused destination type with an
1086 /// initializer list.
1088
1089 /// Overloading for a user-defined conversion failed.
1091
1092 /// Overloading for initialization by constructor failed.
1094
1095 /// Overloading for list-initialization by constructor failed.
1097
1098 /// Default-initialization of a 'const' object.
1100
1101 /// Initialization of an incomplete type.
1103
1104 /// Variable-length array must not have an initializer.
1106
1107 /// List initialization failed at some point.
1109
1110 /// Initializer has a placeholder type which cannot be
1111 /// resolved by initialization.
1113
1114 /// Trying to take the address of a function that doesn't support
1115 /// having its address taken.
1117
1118 /// List-copy-initialization chose an explicit constructor.
1120
1121 /// Parenthesized list initialization failed at some point.
1122 /// This is a C++20 feature.
1124
1125 // A designated initializer was provided for a non-aggregate type.
1127 };
1128
1129private:
1130 /// The reason why initialization failed.
1131 FailureKind Failure;
1132
1133 /// The failed result of overload resolution.
1134 OverloadingResult FailedOverloadResult;
1135
1136 /// The candidate set created when initialization failed.
1137 OverloadCandidateSet FailedCandidateSet;
1138
1139 /// The incomplete type that caused a failure.
1140 QualType FailedIncompleteType;
1141
1142 /// The fixit that needs to be applied to make this initialization
1143 /// succeed.
1144 std::string ZeroInitializationFixit;
1145 SourceLocation ZeroInitializationFixitLoc;
1146
1147public:
1148 /// Call for initializations are invalid but that would be valid
1149 /// zero initialzations if Fixit was applied.
1150 void SetZeroInitializationFixit(const std::string& Fixit, SourceLocation L) {
1151 ZeroInitializationFixit = Fixit;
1152 ZeroInitializationFixitLoc = L;
1153 }
1154
1155private:
1156 /// Prints a follow-up note that highlights the location of
1157 /// the initialized entity, if it's remote.
1158 void PrintInitLocationNote(Sema &S, const InitializedEntity &Entity);
1159
1160public:
1161 /// Try to perform initialization of the given entity, creating a
1162 /// record of the steps required to perform the initialization.
1163 ///
1164 /// The generated initialization sequence will either contain enough
1165 /// information to diagnose
1166 ///
1167 /// \param S the semantic analysis object.
1168 ///
1169 /// \param Entity the entity being initialized.
1170 ///
1171 /// \param Kind the kind of initialization being performed.
1172 ///
1173 /// \param Args the argument(s) provided for initialization.
1174 ///
1175 /// \param TopLevelOfInitList true if we are initializing from an expression
1176 /// at the top level inside an initializer list. This disallows
1177 /// narrowing conversions in C++11 onwards.
1178 /// \param TreatUnavailableAsInvalid true if we want to treat unavailable
1179 /// as invalid.
1181 const InitializedEntity &Entity,
1182 const InitializationKind &Kind,
1183 MultiExprArg Args,
1184 bool TopLevelOfInitList = false,
1185 bool TreatUnavailableAsInvalid = true);
1186 void InitializeFrom(Sema &S, const InitializedEntity &Entity,
1188 bool TopLevelOfInitList, bool TreatUnavailableAsInvalid);
1189
1191
1192 /// Perform the actual initialization of the given entity based on
1193 /// the computed initialization sequence.
1194 ///
1195 /// \param S the semantic analysis object.
1196 ///
1197 /// \param Entity the entity being initialized.
1198 ///
1199 /// \param Kind the kind of initialization being performed.
1200 ///
1201 /// \param Args the argument(s) provided for initialization, ownership of
1202 /// which is transferred into the routine.
1203 ///
1204 /// \param ResultType if non-NULL, will be set to the type of the
1205 /// initialized object, which is the type of the declaration in most
1206 /// cases. However, when the initialized object is a variable of
1207 /// incomplete array type and the initializer is an initializer
1208 /// list, this type will be set to the completed array type.
1209 ///
1210 /// \returns an expression that performs the actual object initialization, if
1211 /// the initialization is well-formed. Otherwise, emits diagnostics
1212 /// and returns an invalid expression.
1214 const InitializedEntity &Entity,
1215 const InitializationKind &Kind,
1216 MultiExprArg Args,
1217 QualType *ResultType = nullptr);
1218
1219 /// Diagnose an potentially-invalid initialization sequence.
1220 ///
1221 /// \returns true if the initialization sequence was ill-formed,
1222 /// false otherwise.
1223 bool Diagnose(Sema &S,
1224 const InitializedEntity &Entity,
1225 const InitializationKind &Kind,
1226 ArrayRef<Expr *> Args);
1227
1228 /// Determine the kind of initialization sequence computed.
1229 enum SequenceKind getKind() const { return SequenceKind; }
1230
1231 /// Set the kind of sequence computed.
1233
1234 /// Determine whether the initialization sequence is valid.
1235 explicit operator bool() const { return !Failed(); }
1236
1237 /// Determine whether the initialization sequence is invalid.
1238 bool Failed() const { return SequenceKind == FailedSequence; }
1239
1241
1242 step_iterator step_begin() const { return Steps.begin(); }
1243 step_iterator step_end() const { return Steps.end(); }
1244
1245 using step_range = llvm::iterator_range<step_iterator>;
1246
1247 step_range steps() const { return {step_begin(), step_end()}; }
1248
1249 /// Determine whether this initialization is a direct reference
1250 /// binding (C++ [dcl.init.ref]).
1251 bool isDirectReferenceBinding() const;
1252
1253 /// Determine whether this initialization failed due to an ambiguity.
1254 bool isAmbiguous() const;
1255
1256 /// Determine whether this initialization is direct call to a
1257 /// constructor.
1258 bool isConstructorInitialization() const;
1259
1260 /// Add a new step in the initialization that resolves the address
1261 /// of an overloaded function to a specific function declaration.
1262 ///
1263 /// \param Function the function to which the overloaded function reference
1264 /// resolves.
1267 bool HadMultipleCandidates);
1268
1269 /// Add a new step in the initialization that performs a derived-to-
1270 /// base cast.
1271 ///
1272 /// \param BaseType the base type to which we will be casting.
1273 ///
1274 /// \param Category Indicates whether the result will be treated as an
1275 /// rvalue, an xvalue, or an lvalue.
1276 void AddDerivedToBaseCastStep(QualType BaseType,
1278
1279 /// Add a new step binding a reference to an object.
1280 ///
1281 /// \param BindingTemporary True if we are binding a reference to a temporary
1282 /// object (thereby extending its lifetime); false if we are binding to an
1283 /// lvalue or an lvalue treated as an rvalue.
1284 void AddReferenceBindingStep(QualType T, bool BindingTemporary);
1285
1286 /// Add a new step that makes an extraneous copy of the input
1287 /// to a temporary of the same class type.
1288 ///
1289 /// This extraneous copy only occurs during reference binding in
1290 /// C++98/03, where we are permitted (but not required) to introduce
1291 /// an extra copy. At a bare minimum, we must check that we could
1292 /// call the copy constructor, and produce a diagnostic if the copy
1293 /// constructor is inaccessible or no copy constructor matches.
1294 //
1295 /// \param T The type of the temporary being created.
1297
1298 /// Add a new step that makes a copy of the input to an object of
1299 /// the given type, as the final step in class copy-initialization.
1300 void AddFinalCopy(QualType T);
1301
1302 /// Add a new step invoking a conversion function, which is either
1303 /// a constructor or a conversion function.
1305 DeclAccessPair FoundDecl,
1306 QualType T,
1307 bool HadMultipleCandidates);
1308
1309 /// Add a new step that performs a qualification conversion to the
1310 /// given type.
1313
1314 /// Add a new step that performs a function reference conversion to the
1315 /// given type.
1317
1318 /// Add a new step that performs conversion from non-atomic to atomic
1319 /// type.
1321
1322 /// Add a new step that applies an implicit conversion sequence.
1324 QualType T, bool TopLevelOfInitList = false);
1325
1326 /// Add a list-initialization step.
1328
1329 /// Add a constructor-initialization step.
1330 ///
1331 /// \param FromInitList The constructor call is syntactically an initializer
1332 /// list.
1333 /// \param AsInitList The constructor is called as an init list constructor.
1335 CXXConstructorDecl *Constructor,
1336 QualType T,
1337 bool HadMultipleCandidates,
1338 bool FromInitList, bool AsInitList);
1339
1340 /// Add a zero-initialization step.
1342
1343 /// Add a C assignment step.
1344 //
1345 // FIXME: It isn't clear whether this should ever be needed;
1346 // ideally, we would handle everything needed in C in the common
1347 // path. However, that isn't the case yet.
1349
1350 /// Add a string init step.
1352
1353 /// Add an Objective-C object conversion step, which is
1354 /// always a no-op.
1356
1357 /// Add an array initialization loop step.
1359
1360 /// Add an array initialization step.
1361 void AddArrayInitStep(QualType T, bool IsGNUExtension);
1362
1363 /// Add a parenthesized array initialization step.
1365
1366 /// Add a step to pass an object by indirect copy-restore.
1367 void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy);
1368
1369 /// Add a step to "produce" an Objective-C object (by
1370 /// retaining it).
1372
1373 /// Add a step to construct a std::initializer_list object from an
1374 /// initializer list.
1376
1377 /// Add a step to initialize an OpenCL sampler from an integer
1378 /// constant.
1380
1381 /// Add a step to initialzie an OpenCL opaque type (event_t, queue_t, etc.)
1382 /// from a zero constant.
1384
1386
1387 /// Add steps to unwrap a initializer list for a reference around a
1388 /// single element and rewrap it at the end.
1390
1391 /// Note that this initialization sequence failed.
1392 void SetFailed(FailureKind Failure) {
1394 this->Failure = Failure;
1395 assert((Failure != FK_Incomplete || !FailedIncompleteType.isNull()) &&
1396 "Incomplete type failure requires a type!");
1397 }
1398
1399 /// Note that this initialization sequence failed due to failed
1400 /// overload resolution.
1402
1403 /// Retrieve a reference to the candidate set when overload
1404 /// resolution fails.
1406 return FailedCandidateSet;
1407 }
1408
1409 /// Get the overloading result, for when the initialization
1410 /// sequence failed due to a bad overload.
1412 return FailedOverloadResult;
1413 }
1414
1415 /// Note that this initialization sequence failed due to an
1416 /// incomplete type.
1417 void setIncompleteTypeFailure(QualType IncompleteType) {
1418 FailedIncompleteType = IncompleteType;
1420 }
1421
1422 /// Determine why initialization failed.
1424 assert(Failed() && "Not an initialization failure!");
1425 return Failure;
1426 }
1427
1428 /// Dump a representation of this initialization sequence to
1429 /// the given stream, for debugging purposes.
1430 void dump(raw_ostream &OS) const;
1431
1432 /// Dump a representation of this initialization sequence to
1433 /// standard error, for debugging purposes.
1434 void dump() const;
1435};
1436
1437} // namespace clang
1438
1439#endif // LLVM_CLANG_SEMA_INITIALIZATION_H
Defines the clang::ASTContext interface.
NodeId Parent
Definition: ASTDiff.cpp:191
MatchType Type
enum clang::sema::@1655::IndirectLocalPathEntry::EntryKind Kind
int Category
Definition: Format.cpp:3004
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:759
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:187
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2539
A POD class for pairing a NamedDecl* with an access specifier.
bool hasAttr() const
Definition: DeclBase.h:584
The name of a declaration.
This represents one expression.
Definition: Expr.h:110
Represents a member of a struct/union/class.
Definition: Decl.h:3030
Represents a function declaration or definition.
Definition: Decl.h:1932
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:567
Represents a field injected from an anonymous union/struct into the parent scope.
Definition: Decl.h:3318
Describes an C or C++ initializer list.
Definition: Expr.h:5039
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.
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 CreateFunctionalCast(SourceRange TypeRange, bool InitList)
Create a direct initialization for a functional cast.
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:3976
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:7521
void AddStringInitStep(QualType T)
Add a string init step.
Definition: SemaInit.cpp:4011
void AddStdInitializerListConstructionStep(QualType T)
Add a step to construct a std::initializer_list object from an initializer list.
Definition: SemaInit.cpp:4066
void AddConstructorInitializationStep(DeclAccessPair FoundDecl, CXXConstructorDecl *Constructor, QualType T, bool HadMultipleCandidates, bool FromInitList, bool AsInitList)
Add a constructor-initialization step.
Definition: SemaInit.cpp:3983
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:3919
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:3932
void AddFunctionReferenceConversionStep(QualType Ty)
Add a new step that performs a function reference conversion to the given type.
Definition: SemaInit.cpp:3951
void AddDerivedToBaseCastStep(QualType BaseType, ExprValueKind Category)
Add a new step in the initialization that performs a derived-to- base cast.
Definition: SemaInit.cpp:3882
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:6319
void AddParenthesizedListInitStep(QualType T)
Definition: SemaInit.cpp:4087
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:3810
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:4080
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:3904
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:4018
void SetOverloadFailure(FailureKind Failure, OverloadingResult Result)
Note that this initialization sequence failed due to failed overload resolution.
Definition: SemaInit.cpp:4109
step_iterator step_end() const
void AddParenthesizedArrayInitStep(QualType T)
Add a parenthesized array initialization step.
Definition: SemaInit.cpp:4043
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:3911
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:4073
void AddCAssignmentStep(QualType T)
Add a C assignment step.
Definition: SemaInit.cpp:4004
void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy)
Add a step to pass an object by indirect copy-restore.
Definition: SemaInit.cpp:4050
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:4094
bool Diagnose(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, ArrayRef< Expr * > Args)
Diagnose an potentially-invalid initialization sequence.
Definition: SemaInit.cpp:8609
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:3958
void dump() const
Dump a representation of this initialization sequence to standard error, for debugging purposes.
Definition: SemaInit.cpp:9465
void AddConversionSequenceStep(const ImplicitConversionSequence &ICS, QualType T, bool TopLevelOfInitList=false)
Add a new step that applies an implicit conversion sequence.
Definition: SemaInit.cpp:3965
void AddZeroInitializationStep(QualType T)
Add a zero-initialization step.
Definition: SemaInit.cpp:3997
void AddProduceObjCObjectStep(QualType T)
Add a step to "produce" an Objective-C object (by retaining it).
Definition: SemaInit.cpp:4059
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:3896
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:3799
void AddArrayInitLoopStep(QualType T, QualType EltTy)
Add an array initialization loop step.
Definition: SemaInit.cpp:4032
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:3870
void AddArrayInitStep(QualType T, bool IsGNUExtension)
Add an array initialization step.
Definition: SemaInit.cpp:4025
bool isConstructorInitialization() const
Determine whether this initialization is direct call to a constructor.
Definition: SemaInit.cpp:3864
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:3580
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:3592
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:3630
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:3664
void dump() const
Dump a representation of the initialized entity to standard error, for debugging purposes.
Definition: SemaInit.cpp:3745
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.
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.
static InitializedEntity InitializeTemplateParameter(QualType T, NonTypeTemplateParmDecl *Param)
Create the initialization entity for a template parameter.
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.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
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:1008
Represents a parameter to a function.
Definition: Decl.h:1722
A (possibly-)qualified type.
Definition: Type.h:941
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:1008
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:493
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: Type.h:7721
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:7732
The base class of the type hierarchy.
Definition: Type.h:1829
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:667
QualType getType() const
Definition: Decl.h:678
Represents a variable declaration or definition.
Definition: Decl.h:879
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
#define bool
Definition: stdbool.h:24