clang 23.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
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 an element of a matrix.
95 /// or matrix.
97
98 /// The entity being initialized is a field of block descriptor for
99 /// the copied-in c++ object.
101
102 /// The entity being initialized is a field of block descriptor for the
103 /// copied-in lambda object that's used in the lambda to block conversion.
105
106 /// The entity being initialized is the real or imaginary part of a
107 /// complex number.
109
110 /// The entity being initialized is the field that captures a
111 /// variable in a lambda.
113
114 /// The entity being initialized is the initializer for a compound
115 /// literal.
117
118 /// The entity being implicitly initialized back to the formal
119 /// result type.
121
122 /// The entity being initialized is a function parameter; function
123 /// is member of group of audited CF APIs.
125
126 /// The entity being initialized is a structured binding of a
127 /// decomposition declaration.
129
130 /// The entity being initialized is a non-static data member subobject of an
131 /// object initialized via parenthesized aggregate initialization.
133
134 // Note: err_init_conversion_failed in DiagnosticSemaKinds.td uses this
135 // enum as an index for its first %select. When modifying this list,
136 // that diagnostic text needs to be updated as well.
137 };
138
139private:
140 /// The kind of entity being initialized.
141 EntityKind Kind;
142
143 /// If non-NULL, the parent entity in which this
144 /// initialization occurs.
145 const InitializedEntity *Parent = nullptr;
146
147 /// The type of the object or reference being initialized.
149
150 /// The mangling number for the next reference temporary to be created.
151 mutable unsigned ManglingNumber = 0;
152
153 struct LN {
154 /// When Kind == EK_Result, EK_Exception, EK_New, the
155 /// location of the 'return', 'throw', or 'new' keyword,
156 /// respectively. When Kind == EK_Temporary, the location where
157 /// the temporary is being created.
158 SourceLocation Location;
159
160 /// Whether the entity being initialized may end up using the
161 /// named return value optimization (NRVO).
162 bool NRVO;
163
164 /// When Kind == EK_New, whether this is initializing an array of runtime
165 /// size (which needs an array filler).
166 bool VariableLengthArrayNew;
167 };
168
169 struct VD {
170 /// The VarDecl, FieldDecl, TemplateParmDecl, or BindingDecl being
171 /// initialized.
172 NamedDecl *VariableOrMember;
173
174 /// When Kind == EK_Member, whether this is an implicit member
175 /// initialization in a copy or move constructor. These can perform array
176 /// copies.
177 bool IsImplicitFieldInit;
178
179 /// When Kind == EK_Member, whether this is the initial initialization
180 /// check for a default member initializer.
181 bool IsDefaultMemberInit;
182 };
183
184 struct C {
185 /// The name of the variable being captured by an EK_LambdaCapture.
186 IdentifierInfo *VarID;
187
188 /// The source location at which the capture occurs.
189 SourceLocation Location;
190 };
191
192 union {
193 /// When Kind == EK_Variable, EK_Member, EK_Binding, or
194 /// EK_TemplateParameter, the variable, binding, or template parameter.
196
197 /// When Kind == EK_RelatedResult, the ObjectiveC method where
198 /// result type was implicitly changed to accommodate ARC semantics.
200
201 /// When Kind == EK_Parameter, the ParmVarDecl, with the
202 /// integer indicating whether the parameter is "consumed".
203 llvm::PointerIntPair<ParmVarDecl *, 1> Parameter;
204
205 /// When Kind == EK_Temporary or EK_CompoundLiteralInit, the type
206 /// source information for the temporary.
208
209 struct LN LocAndNRVO;
210
211 /// When Kind == EK_Base, the base specifier that provides the
212 /// base class. The integer specifies whether the base is an inherited
213 /// virtual base.
214 llvm::PointerIntPair<const CXXBaseSpecifier *, 1> Base;
215
216 /// When Kind == EK_ArrayElement, EK_VectorElement, EK_MatrixElement,
217 /// or EK_ComplexElement, the index of the array or vector element being
218 /// initialized.
219 unsigned Index;
220
221 struct C Capture;
222 };
223
225
226 /// Create the initialization entity for a variable.
227 InitializedEntity(VarDecl *Var, EntityKind EK = EK_Variable)
228 : Kind(EK), Type(Var->getType()), Variable{Var, false, false} {}
229
230 /// Create the initialization entity for the result of a
231 /// function, throwing an object, performing an explicit cast, or
232 /// initializing a parameter for which there is no declaration.
233 InitializedEntity(EntityKind Kind, SourceLocation Loc, QualType Type,
234 bool NRVO = false, bool VariableLengthArrayNew = false)
235 : Kind(Kind), Type(Type) {
236 new (&LocAndNRVO) LN;
237 LocAndNRVO.Location = Loc;
238 LocAndNRVO.NRVO = NRVO;
239 LocAndNRVO.VariableLengthArrayNew = VariableLengthArrayNew;
240 }
241
242 /// Create the initialization entity for a member subobject.
243 InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent,
244 bool Implicit, bool DefaultMemberInit,
245 bool IsParenAggInit = false)
246 : Kind(IsParenAggInit ? EK_ParenAggInitMember : EK_Member),
247 Parent(Parent), Type(Member->getType()),
248 Variable{Member, Implicit, DefaultMemberInit} {}
249
250 /// Create the initialization entity for an array element.
251 InitializedEntity(ASTContext &Context, unsigned Index,
252 const InitializedEntity &Parent);
253
254 /// Create the initialization entity for a lambda capture.
255 InitializedEntity(IdentifierInfo *VarID, QualType FieldType, SourceLocation Loc)
256 : Kind(EK_LambdaCapture), Type(FieldType) {
257 new (&Capture) C;
258 Capture.VarID = VarID;
259 Capture.Location = Loc;
260 }
261
262public:
263 /// Create the initialization entity for a variable.
264 static InitializedEntity InitializeVariable(VarDecl *Var) {
265 return InitializedEntity(Var);
266 }
267
268 /// Create the initialization entity for a parameter.
269 static InitializedEntity InitializeParameter(ASTContext &Context,
270 ParmVarDecl *Parm) {
271 return InitializeParameter(Context, Parm, Parm->getType());
272 }
273
274 /// Create the initialization entity for a parameter, but use
275 /// another type.
276 static InitializedEntity
278 bool Consumed = (Context.getLangOpts().ObjCAutoRefCount &&
279 Parm->hasAttr<NSConsumedAttr>());
280
281 InitializedEntity Entity;
282 Entity.Kind = EK_Parameter;
283 Entity.Type =
284 Context.getVariableArrayDecayedType(Type.getUnqualifiedType());
285 Entity.Parent = nullptr;
286 Entity.Parameter = {Parm, Consumed};
287 return Entity;
288 }
289
290 /// Create the initialization entity for a parameter that is
291 /// only known by its type.
292 static InitializedEntity InitializeParameter(ASTContext &Context,
293 QualType Type,
294 bool Consumed) {
295 InitializedEntity Entity;
296 Entity.Kind = EK_Parameter;
297 Entity.Type = Context.getVariableArrayDecayedType(Type);
298 Entity.Parent = nullptr;
299 Entity.Parameter = {nullptr, Consumed};
300 return Entity;
301 }
302
303 /// Create the initialization entity for a template parameter.
304 static InitializedEntity InitializeTemplateParameter(QualType T,
305 NamedDecl *Param) {
306 InitializedEntity Entity;
307 Entity.Kind = EK_TemplateParameter;
308 Entity.Type = T;
309 Entity.Parent = nullptr;
310 Entity.Variable = {Param, false, false};
311 return Entity;
312 }
313
314 /// Create the initialization entity for the result of a function.
315 static InitializedEntity InitializeResult(SourceLocation ReturnLoc,
316 QualType Type) {
317 return InitializedEntity(EK_Result, ReturnLoc, Type);
318 }
319
320 static InitializedEntity InitializeStmtExprResult(SourceLocation ReturnLoc,
321 QualType Type) {
322 return InitializedEntity(EK_StmtExprResult, ReturnLoc, Type);
323 }
324
325 static InitializedEntity InitializeBlock(SourceLocation BlockVarLoc,
326 QualType Type) {
327 return InitializedEntity(EK_BlockElement, BlockVarLoc, Type);
328 }
329
330 static InitializedEntity InitializeLambdaToBlock(SourceLocation BlockVarLoc,
331 QualType Type) {
332 return InitializedEntity(EK_LambdaToBlockConversionBlockElement,
333 BlockVarLoc, Type);
334 }
335
336 /// Create the initialization entity for an exception object.
337 static InitializedEntity InitializeException(SourceLocation ThrowLoc,
338 QualType Type) {
339 return InitializedEntity(EK_Exception, ThrowLoc, Type);
340 }
341
342 /// Create the initialization entity for an object allocated via new.
343 static InitializedEntity InitializeNew(SourceLocation NewLoc, QualType Type,
344 bool VariableLengthArrayNew) {
345 return InitializedEntity(EK_New, NewLoc, Type, /*NRVO=*/false,
346 VariableLengthArrayNew);
347 }
348
349 /// Create the initialization entity for a temporary.
350 static InitializedEntity InitializeTemporary(QualType Type) {
351 return InitializeTemporary(nullptr, Type);
352 }
353
354 /// Create the initialization entity for a temporary.
355 static InitializedEntity InitializeTemporary(ASTContext &Context,
357 QualType Type = TypeInfo->getType();
358 if (Context.getLangOpts().OpenCLCPlusPlus) {
359 assert(!Type.hasAddressSpace() && "Temporary already has address space!");
360 Type = Context.getAddrSpaceQualType(Type, LangAS::opencl_private);
361 }
362
363 return InitializeTemporary(TypeInfo, Type);
364 }
365
366 /// Create the initialization entity for a temporary.
367 static InitializedEntity InitializeTemporary(TypeSourceInfo *TypeInfo,
368 QualType Type) {
369 InitializedEntity Result(EK_Temporary, SourceLocation(), Type);
370 Result.TypeInfo = TypeInfo;
371 return Result;
372 }
373
374 /// Create the initialization entity for a related result.
375 static InitializedEntity InitializeRelatedResult(ObjCMethodDecl *MD,
376 QualType Type) {
377 InitializedEntity Result(EK_RelatedResult, SourceLocation(), Type);
378 Result.MethodDecl = MD;
379 return Result;
380 }
381
382 /// Create the initialization entity for a base class subobject.
383 static InitializedEntity
385 bool IsInheritedVirtualBase,
386 const InitializedEntity *Parent = nullptr);
387
388 /// Create the initialization entity for a delegated constructor.
389 static InitializedEntity InitializeDelegation(QualType Type) {
390 return InitializedEntity(EK_Delegating, SourceLocation(), Type);
391 }
392
393 /// Create the initialization entity for a member subobject.
394 static InitializedEntity
396 const InitializedEntity *Parent = nullptr,
397 bool Implicit = false) {
398 return InitializedEntity(Member, Parent, Implicit, false);
399 }
400
401 /// Create the initialization entity for a member subobject.
402 static InitializedEntity
404 const InitializedEntity *Parent = nullptr,
405 bool Implicit = false) {
406 return InitializedEntity(Member->getAnonField(), Parent, Implicit, false);
407 }
408
409 /// Create the initialization entity for a member subobject initialized via
410 /// parenthesized aggregate init.
412 return InitializedEntity(Member, /*Parent=*/nullptr, /*Implicit=*/false,
413 /*DefaultMemberInit=*/false,
414 /*IsParenAggInit=*/true);
415 }
416
417 /// Create the initialization entity for a default member initializer.
418 static InitializedEntity
420 return InitializedEntity(Member, nullptr, false, true);
421 }
422
423 /// Create the initialization entity for an array element.
424 static InitializedEntity InitializeElement(ASTContext &Context,
425 unsigned Index,
426 const InitializedEntity &Parent) {
427 return InitializedEntity(Context, Index, Parent);
428 }
429
430 /// Create the initialization entity for a structured binding.
431 static InitializedEntity InitializeBinding(VarDecl *Binding) {
432 return InitializedEntity(Binding, EK_Binding);
433 }
434
435 /// Create the initialization entity for a lambda capture.
436 ///
437 /// \p VarID The name of the entity being captured, or nullptr for 'this'.
438 static InitializedEntity InitializeLambdaCapture(IdentifierInfo *VarID,
439 QualType FieldType,
440 SourceLocation Loc) {
441 return InitializedEntity(VarID, FieldType, Loc);
442 }
443
444 /// Create the entity for a compound literal initializer.
445 static InitializedEntity InitializeCompoundLiteralInit(TypeSourceInfo *TSI) {
446 InitializedEntity Result(EK_CompoundLiteralInit, SourceLocation(),
447 TSI->getType());
448 Result.TypeInfo = TSI;
449 return Result;
450 }
451
452 /// Determine the kind of initialization.
453 EntityKind getKind() const { return Kind; }
454
455 /// Retrieve the parent of the entity being initialized, when
456 /// the initialization itself is occurring within the context of a
457 /// larger initialization.
458 const InitializedEntity *getParent() const { return Parent; }
459
460 /// Retrieve type being initialized.
461 QualType getType() const { return Type; }
462
463 /// Retrieve complete type-source information for the object being
464 /// constructed, if known.
466 if (Kind == EK_Temporary || Kind == EK_CompoundLiteralInit)
467 return TypeInfo;
468
469 return nullptr;
470 }
471
472 /// Retrieve the name of the entity being initialized.
473 DeclarationName getName() const;
474
475 /// Retrieve the variable, parameter, or field being
476 /// initialized.
477 ValueDecl *getDecl() const;
478
479 /// Retrieve the ObjectiveC method being initialized.
481
482 /// Determine whether this initialization allows the named return
483 /// value optimization, which also applies to thrown objects.
484 bool allowsNRVO() const;
485
486 bool isParameterKind() const {
487 return (getKind() == EK_Parameter ||
489 }
490
493 }
494
495 /// Determine whether this initialization consumes the
496 /// parameter.
497 bool isParameterConsumed() const {
498 assert(isParameterKind() && "Not a parameter");
499 return Parameter.getInt();
500 }
501
502 /// Retrieve the base specifier.
504 assert(getKind() == EK_Base && "Not a base specifier");
505 return Base.getPointer();
506 }
507
508 /// Return whether the base is an inherited virtual base.
510 assert(getKind() == EK_Base && "Not a base specifier");
511 return Base.getInt();
512 }
513
514 /// Determine whether this is an array new with an unknown bound.
516 return getKind() == EK_New && LocAndNRVO.VariableLengthArrayNew;
517 }
518
519 /// Is this the implicit initialization of a member of a class from
520 /// a defaulted constructor?
522 return getKind() == EK_Member && Variable.IsImplicitFieldInit;
523 }
524
525 /// Is this the default member initializer of a member (specified inside
526 /// the class definition)?
528 return getKind() == EK_Member && Variable.IsDefaultMemberInit;
529 }
530
531 /// Determine the location of the 'return' keyword when initializing
532 /// the result of a function call.
534 assert(getKind() == EK_Result && "No 'return' location!");
535 return LocAndNRVO.Location;
536 }
537
538 /// Determine the location of the 'throw' keyword when initializing
539 /// an exception object.
541 assert(getKind() == EK_Exception && "No 'throw' location!");
542 return LocAndNRVO.Location;
543 }
544
545 /// If this is an array, vector, or complex number element, get the
546 /// element's index.
547 unsigned getElementIndex() const {
548 assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
550 return Index;
551 }
552
553 /// If this is already the initializer for an array or vector
554 /// element, sets the element index.
555 void setElementIndex(unsigned Index) {
556 assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
558 this->Index = Index;
559 }
560
561 /// For a lambda capture, return the capture's name.
562 StringRef getCapturedVarName() const {
563 assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
564 return Capture.VarID ? Capture.VarID->getName() : "this";
565 }
566
567 /// Determine the location of the capture when initializing
568 /// field from a captured variable in a lambda.
570 assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
571 return Capture.Location;
572 }
573
577
578 unsigned allocateManglingNumber() const { return ++ManglingNumber; }
579
580 /// Dump a representation of the initialized entity to standard error,
581 /// for debugging purposes.
582 void dump() const;
583
584private:
585 unsigned dumpImpl(raw_ostream &OS) const;
586};
587
588/// Describes the kind of initialization being performed, along with
589/// location information for tokens related to the initialization (equal sign,
590/// parentheses).
591class InitializationKind {
592public:
593 /// The kind of initialization being performed.
594 enum InitKind {
595 /// Direct initialization
597
598 /// Direct list-initialization
600
601 /// Copy initialization
603
604 /// Default initialization
606
607 /// Value initialization
609 };
610
611private:
612 /// The context of the initialization.
613 enum InitContext {
614 /// Normal context
615 IC_Normal,
616
617 /// Normal context, but allows explicit conversion functions
618 IC_ExplicitConvs,
619
620 /// Implicit context (value initialization)
621 IC_Implicit,
622
623 /// Static cast context
624 IC_StaticCast,
625
626 /// C-style cast context
627 IC_CStyleCast,
628
629 /// Functional cast context
630 IC_FunctionalCast
631 };
632
633 /// The kind of initialization being performed.
634 InitKind Kind : 8;
635
636 /// The context of the initialization.
637 InitContext Context : 8;
638
639 /// The source locations involved in the initialization.
640 SourceLocation Locations[3];
641
642 InitializationKind(InitKind Kind, InitContext Context, SourceLocation Loc1,
643 SourceLocation Loc2, SourceLocation Loc3)
644 : Kind(Kind), Context(Context) {
645 Locations[0] = Loc1;
646 Locations[1] = Loc2;
647 Locations[2] = Loc3;
648 }
649
650public:
651 /// Create a direct initialization.
652 static InitializationKind CreateDirect(SourceLocation InitLoc,
653 SourceLocation LParenLoc,
654 SourceLocation RParenLoc) {
655 return InitializationKind(IK_Direct, IC_Normal,
656 InitLoc, LParenLoc, RParenLoc);
657 }
658
659 static InitializationKind CreateDirectList(SourceLocation InitLoc) {
660 return InitializationKind(IK_DirectList, IC_Normal, InitLoc, InitLoc,
661 InitLoc);
662 }
663
664 static InitializationKind CreateDirectList(SourceLocation InitLoc,
665 SourceLocation LBraceLoc,
666 SourceLocation RBraceLoc) {
667 return InitializationKind(IK_DirectList, IC_Normal, InitLoc, LBraceLoc,
668 RBraceLoc);
669 }
670
671 /// Create a direct initialization due to a cast that isn't a C-style
672 /// or functional cast.
673 static InitializationKind CreateCast(SourceRange TypeRange) {
674 return InitializationKind(IK_Direct, IC_StaticCast, TypeRange.getBegin(),
675 TypeRange.getBegin(), TypeRange.getEnd());
676 }
677
678 /// Create a direct initialization for a C-style cast.
679 static InitializationKind CreateCStyleCast(SourceLocation StartLoc,
680 SourceRange TypeRange,
681 bool InitList) {
682 // C++ cast syntax doesn't permit init lists, but C compound literals are
683 // exactly that.
684 return InitializationKind(InitList ? IK_DirectList : IK_Direct,
685 IC_CStyleCast, StartLoc, TypeRange.getBegin(),
686 TypeRange.getEnd());
687 }
688
689 /// Create a direct initialization for a functional cast.
690 static InitializationKind CreateFunctionalCast(SourceLocation StartLoc,
691 SourceRange ParenRange,
692 bool InitList) {
693 return InitializationKind(InitList ? IK_DirectList : IK_Direct,
694 IC_FunctionalCast, StartLoc,
695 ParenRange.getBegin(), ParenRange.getEnd());
696 }
697
698 /// Create a copy initialization.
699 static InitializationKind CreateCopy(SourceLocation InitLoc,
700 SourceLocation EqualLoc,
701 bool AllowExplicitConvs = false) {
702 return InitializationKind(IK_Copy,
703 AllowExplicitConvs? IC_ExplicitConvs : IC_Normal,
704 InitLoc, EqualLoc, EqualLoc);
705 }
706
707 /// Create a default initialization.
708 static InitializationKind CreateDefault(SourceLocation InitLoc) {
709 return InitializationKind(IK_Default, IC_Normal, InitLoc, InitLoc, InitLoc);
710 }
711
712 /// Create a value initialization.
713 static InitializationKind CreateValue(SourceLocation InitLoc,
714 SourceLocation LParenLoc,
715 SourceLocation RParenLoc,
716 bool isImplicit = false) {
717 return InitializationKind(IK_Value, isImplicit ? IC_Implicit : IC_Normal,
718 InitLoc, LParenLoc, RParenLoc);
719 }
720
721 /// Create an initialization from an initializer (which, for direct
722 /// initialization from a parenthesized list, will be a ParenListExpr).
723 static InitializationKind CreateForInit(SourceLocation Loc, bool DirectInit,
724 Expr *Init) {
725 if (!Init) return CreateDefault(Loc);
726 if (!DirectInit)
727 return CreateCopy(Loc, Init->getBeginLoc());
729 return CreateDirectList(Loc, Init->getBeginLoc(), Init->getEndLoc());
730 return CreateDirect(Loc, Init->getBeginLoc(), Init->getEndLoc());
731 }
732
733 /// Determine the initialization kind.
735 return Kind;
736 }
737
738 /// Determine whether this initialization is an explicit cast.
739 bool isExplicitCast() const {
740 return Context >= IC_StaticCast;
741 }
742
743 /// Determine whether this initialization is a static cast.
744 bool isStaticCast() const { return Context == IC_StaticCast; }
745
746 /// Determine whether this initialization is a C-style cast.
748 return Context >= IC_CStyleCast;
749 }
750
751 /// Determine whether this is a C-style cast.
752 bool isCStyleCast() const {
753 return Context == IC_CStyleCast;
754 }
755
756 /// Determine whether this is a functional-style cast.
757 bool isFunctionalCast() const {
758 return Context == IC_FunctionalCast;
759 }
760
761 /// Determine whether this initialization is an implicit
762 /// value-initialization, e.g., as occurs during aggregate
763 /// initialization.
764 bool isImplicitValueInit() const { return Context == IC_Implicit; }
765
766 /// Retrieve the location at which initialization is occurring.
767 SourceLocation getLocation() const { return Locations[0]; }
768
769 /// Retrieve the source range that covers the initialization.
771 return SourceRange(Locations[0], Locations[2]);
772 }
773
774 /// Retrieve the location of the equal sign for copy initialization
775 /// (if present).
777 assert(Kind == IK_Copy && "Only copy initialization has an '='");
778 return Locations[1];
779 }
780
781 bool isCopyInit() const { return Kind == IK_Copy; }
782
783 /// Retrieve whether this initialization allows the use of explicit
784 /// constructors.
785 bool AllowExplicit() const { return !isCopyInit(); }
786
787 /// Retrieve whether this initialization allows the use of explicit
788 /// conversion functions when binding a reference. If the reference is the
789 /// first parameter in a copy or move constructor, such conversions are
790 /// permitted even though we are performing copy-initialization.
792 return !isCopyInit() || Context == IC_ExplicitConvs;
793 }
794
795 /// Determine whether this initialization has a source range containing the
796 /// locations of open and closing parentheses or braces.
797 bool hasParenOrBraceRange() const {
798 return Kind == IK_Direct || Kind == IK_Value || Kind == IK_DirectList;
799 }
800
801 /// Retrieve the source range containing the locations of the open
802 /// and closing parentheses or braces for value, direct, and direct list
803 /// initializations.
805 assert(hasParenOrBraceRange() && "Only direct, value, and direct-list "
806 "initialization have parentheses or "
807 "braces");
808 return SourceRange(Locations[1], Locations[2]);
809 }
810};
811
812/// Describes the sequence of initializations required to initialize
813/// a given object or reference with a set of arguments.
815public:
816 /// Describes the kind of initialization sequence computed.
818 /// A failed initialization sequence. The failure kind tells what
819 /// happened.
821
822 /// A dependent initialization, which could not be
823 /// type-checked due to the presence of dependent types or
824 /// dependently-typed expressions.
826
827 /// A normal sequence.
829 };
830
831 /// Describes the kind of a particular step in an initialization
832 /// sequence.
833 enum StepKind {
834 /// Resolve the address of an overloaded function to a specific
835 /// function declaration.
837
838 /// Perform a derived-to-base cast, producing an rvalue.
840
841 /// Perform a derived-to-base cast, producing an xvalue.
843
844 /// Perform a derived-to-base cast, producing an lvalue.
846
847 /// Reference binding to an lvalue.
849
850 /// Reference binding to a temporary.
852
853 /// An optional copy of a temporary object to another
854 /// temporary object, which is permitted (but not required) by
855 /// C++98/03 but not C++0x.
857
858 /// Direct-initialization from a reference-related object in the
859 /// final stage of class copy-initialization.
861
862 /// Perform a user-defined conversion, either via a conversion
863 /// function or via a constructor.
865
866 /// Perform a qualification conversion, producing a prvalue.
868
869 /// Perform a qualification conversion, producing an xvalue.
871
872 /// Perform a qualification conversion, producing an lvalue.
874
875 /// Perform a function reference conversion, see [dcl.init.ref]p4.
877
878 /// Perform a conversion adding _Atomic to a type.
880
881 /// Perform an implicit conversion sequence.
883
884 /// Perform an implicit conversion sequence without narrowing.
886
887 /// Perform list-initialization without a constructor.
889
890 /// Unwrap the single-element initializer list for a reference.
892
893 /// Rewrap the single-element initializer list for a reference.
895
896 /// Perform initialization via a constructor.
898
899 /// Perform initialization via a constructor, taking arguments from
900 /// a single InitListExpr.
902
903 /// Zero-initialize the object
905
906 /// C assignment
908
909 /// Initialization by string
911
912 /// An initialization that "converts" an Objective-C object
913 /// (not a point to an object) to another Objective-C object type.
915
916 /// Array indexing for initialization by elementwise copy.
918
919 /// Array initialization by elementwise copy.
921
922 /// Array initialization (from an array rvalue).
924
925 /// Array initialization (from an array rvalue) as a GNU extension.
927
928 /// Array initialization from a parenthesized initializer list.
929 /// This is a GNU C++ extension.
931
932 /// Pass an object by indirect copy-and-restore.
934
935 /// Pass an object by indirect restore.
937
938 /// Produce an Objective-C object pointer.
940
941 /// Construct a std::initializer_list from an initializer list.
943
944 /// Perform initialization via a constructor taking a single
945 /// std::initializer_list argument.
947
948 /// Initialize an OpenCL sampler from an integer.
950
951 /// Initialize an opaque OpenCL type (event_t, queue_t, etc.) with zero
953
954 /// Initialize an aggreagate with parenthesized list of values.
955 /// This is a C++20 feature.
957 };
958
959 /// A single step in the initialization sequence.
960 class Step {
961 public:
962 /// The kind of conversion or initialization step we are taking.
964
965 // The type that results from this initialization.
967
973
974 union {
975 /// When Kind == SK_ResolvedOverloadedFunction or Kind ==
976 /// SK_UserConversion, the function that the expression should be
977 /// resolved to or the conversion function to call, respectively.
978 /// When Kind == SK_ConstructorInitialization or SK_ListConstruction,
979 /// the constructor to be called.
980 ///
981 /// Always a FunctionDecl, plus a Boolean flag telling if it was
982 /// selected from an overloaded set having size greater than 1.
983 /// For conversion decls, the naming class is the source type.
984 /// For construct decls, the naming class is the target type.
985 struct F Function;
986
987 /// When Kind = SK_ConversionSequence, the implicit conversion
988 /// sequence.
990
991 /// When Kind = SK_RewrapInitList, the syntactic form of the
992 /// wrapping list.
994 };
995
996 void Destroy();
997 };
998
999private:
1000 /// The kind of initialization sequence computed.
1002
1003 /// Steps taken by this initialization.
1005
1006public:
1007 /// Describes why initialization failed.
1009 /// Too many initializers provided for a reference.
1011
1012 /// Reference initialized from a parenthesized initializer list.
1014
1015 /// Array must be initialized with an initializer list.
1017
1018 /// Array must be initialized with an initializer list or a
1019 /// string literal.
1021
1022 /// Array must be initialized with an initializer list or a
1023 /// wide string literal.
1025
1026 /// Initializing a wide char array with narrow string literal.
1028
1029 /// Initializing char array with wide string literal.
1031
1032 /// Initializing wide char array with incompatible wide string
1033 /// literal.
1035
1036 /// Initializing char8_t array with plain string literal.
1038
1039 /// Initializing char array with UTF-8 string literal.
1041
1042 /// Array type mismatch.
1044
1045 /// Non-constant array initializer
1047
1048 /// Cannot resolve the address of an overloaded function.
1050
1051 /// Overloading due to reference initialization failed.
1053
1054 /// Non-const lvalue reference binding to a temporary.
1056
1057 /// Non-const lvalue reference binding to a bit-field.
1059
1060 /// Non-const lvalue reference binding to a vector element.
1062
1063 /// Non-const lvalue reference binding to a matrix element.
1065
1066 /// Non-const lvalue reference binding to an lvalue of unrelated
1067 /// type.
1069
1070 /// Rvalue reference binding to an lvalue.
1072
1073 /// Reference binding drops qualifiers.
1075
1076 /// Reference with mismatching address space binding to temporary.
1078
1079 /// Reference binding failed.
1081
1082 /// Implicit conversion failed.
1084
1085 /// Implicit conversion failed.
1087
1088 /// Too many initializers for scalar
1090
1091 /// Scalar initialized from a parenthesized initializer list.
1093
1094 /// Reference initialization from an initializer list
1096
1097 /// Initialization of some unused destination type with an
1098 /// initializer list.
1100
1101 /// Overloading for a user-defined conversion failed.
1103
1104 /// Overloading for initialization by constructor failed.
1106
1107 /// Overloading for list-initialization by constructor failed.
1109
1110 /// Default-initialization of a 'const' object.
1112
1113 /// Initialization of an incomplete type.
1115
1116 /// Variable-length array must not have an initializer.
1118
1119 /// List initialization failed at some point.
1121
1122 /// Initializer has a placeholder type which cannot be
1123 /// resolved by initialization.
1125
1126 /// Trying to take the address of a function that doesn't support
1127 /// having its address taken.
1129
1130 /// List-copy-initialization chose an explicit constructor.
1132
1133 /// Parenthesized list initialization failed at some point.
1134 /// This is a C++20 feature.
1136
1137 // A designated initializer was provided for a non-aggregate type.
1139
1140 /// HLSL intialization list flattening failed.
1142 };
1143
1144private:
1145 /// The reason why initialization failed.
1146 FailureKind Failure;
1147
1148 /// The failed result of overload resolution.
1149 OverloadingResult FailedOverloadResult;
1150
1151 /// The candidate set created when initialization failed.
1152 OverloadCandidateSet FailedCandidateSet;
1153
1154 /// The incomplete type that caused a failure.
1155 QualType FailedIncompleteType;
1156
1157 /// The fixit that needs to be applied to make this initialization
1158 /// succeed.
1159 std::string ZeroInitializationFixit;
1160 SourceLocation ZeroInitializationFixitLoc;
1161
1162public:
1163 /// Call for initializations are invalid but that would be valid
1164 /// zero initialzations if Fixit was applied.
1165 void SetZeroInitializationFixit(const std::string& Fixit, SourceLocation L) {
1166 ZeroInitializationFixit = Fixit;
1167 ZeroInitializationFixitLoc = L;
1168 }
1169
1170private:
1171 /// Prints a follow-up note that highlights the location of
1172 /// the initialized entity, if it's remote.
1173 void PrintInitLocationNote(Sema &S, const InitializedEntity &Entity);
1174
1175public:
1176 /// Try to perform initialization of the given entity, creating a
1177 /// record of the steps required to perform the initialization.
1178 ///
1179 /// The generated initialization sequence will either contain enough
1180 /// information to diagnose
1181 ///
1182 /// \param S the semantic analysis object.
1183 ///
1184 /// \param Entity the entity being initialized.
1185 ///
1186 /// \param Kind the kind of initialization being performed.
1187 ///
1188 /// \param Args the argument(s) provided for initialization.
1189 ///
1190 /// \param TopLevelOfInitList true if we are initializing from an expression
1191 /// at the top level inside an initializer list. This disallows
1192 /// narrowing conversions in C++11 onwards.
1193 /// \param TreatUnavailableAsInvalid true if we want to treat unavailable
1194 /// as invalid.
1196 const InitializedEntity &Entity,
1197 const InitializationKind &Kind,
1198 MultiExprArg Args,
1199 bool TopLevelOfInitList = false,
1200 bool TreatUnavailableAsInvalid = true);
1201 void InitializeFrom(Sema &S, const InitializedEntity &Entity,
1202 const InitializationKind &Kind, MultiExprArg Args,
1203 bool TopLevelOfInitList, bool TreatUnavailableAsInvalid);
1204
1206
1207 /// Perform the actual initialization of the given entity based on
1208 /// the computed initialization sequence.
1209 ///
1210 /// \param S the semantic analysis object.
1211 ///
1212 /// \param Entity the entity being initialized.
1213 ///
1214 /// \param Kind the kind of initialization being performed.
1215 ///
1216 /// \param Args the argument(s) provided for initialization, ownership of
1217 /// which is transferred into the routine.
1218 ///
1219 /// \param ResultType if non-NULL, will be set to the type of the
1220 /// initialized object, which is the type of the declaration in most
1221 /// cases. However, when the initialized object is a variable of
1222 /// incomplete array type and the initializer is an initializer
1223 /// list, this type will be set to the completed array type.
1224 ///
1225 /// \returns an expression that performs the actual object initialization, if
1226 /// the initialization is well-formed. Otherwise, emits diagnostics
1227 /// and returns an invalid expression.
1229 const InitializedEntity &Entity,
1230 const InitializationKind &Kind,
1231 MultiExprArg Args,
1232 QualType *ResultType = nullptr);
1233
1234 /// Diagnose an potentially-invalid initialization sequence.
1235 ///
1236 /// \returns true if the initialization sequence was ill-formed,
1237 /// false otherwise.
1238 bool Diagnose(Sema &S,
1239 const InitializedEntity &Entity,
1240 const InitializationKind &Kind,
1241 ArrayRef<Expr *> Args);
1242
1243 /// Determine the kind of initialization sequence computed.
1244 enum SequenceKind getKind() const { return SequenceKind; }
1245
1246 /// Set the kind of sequence computed.
1248
1249 /// Determine whether the initialization sequence is valid.
1250 explicit operator bool() const { return !Failed(); }
1251
1252 /// Determine whether the initialization sequence is invalid.
1253 bool Failed() const { return SequenceKind == FailedSequence; }
1254
1256
1257 step_iterator step_begin() const { return Steps.begin(); }
1258 step_iterator step_end() const { return Steps.end(); }
1259
1260 using step_range = llvm::iterator_range<step_iterator>;
1261
1262 step_range steps() const { return {step_begin(), step_end()}; }
1263
1264 /// Determine whether this initialization is a direct reference
1265 /// binding (C++ [dcl.init.ref]).
1266 bool isDirectReferenceBinding() const;
1267
1268 /// Determine whether this initialization failed due to an ambiguity.
1269 bool isAmbiguous() const;
1270
1271 /// Determine whether this initialization is direct call to a
1272 /// constructor.
1273 bool isConstructorInitialization() const;
1274
1275 /// Add a new step in the initialization that resolves the address
1276 /// of an overloaded function to a specific function declaration.
1277 ///
1278 /// \param Function the function to which the overloaded function reference
1279 /// resolves.
1282 bool HadMultipleCandidates);
1283
1284 /// Add a new step in the initialization that performs a derived-to-
1285 /// base cast.
1286 ///
1287 /// \param BaseType the base type to which we will be casting.
1288 ///
1289 /// \param Category Indicates whether the result will be treated as an
1290 /// rvalue, an xvalue, or an lvalue.
1291 void AddDerivedToBaseCastStep(QualType BaseType,
1292 ExprValueKind Category);
1293
1294 /// Add a new step binding a reference to an object.
1295 ///
1296 /// \param BindingTemporary True if we are binding a reference to a temporary
1297 /// object (thereby extending its lifetime); false if we are binding to an
1298 /// lvalue or an lvalue treated as an rvalue.
1299 void AddReferenceBindingStep(QualType T, bool BindingTemporary);
1300
1301 /// Add a new step that makes an extraneous copy of the input
1302 /// to a temporary of the same class type.
1303 ///
1304 /// This extraneous copy only occurs during reference binding in
1305 /// C++98/03, where we are permitted (but not required) to introduce
1306 /// an extra copy. At a bare minimum, we must check that we could
1307 /// call the copy constructor, and produce a diagnostic if the copy
1308 /// constructor is inaccessible or no copy constructor matches.
1309 //
1310 /// \param T The type of the temporary being created.
1312
1313 /// Add a new step that makes a copy of the input to an object of
1314 /// the given type, as the final step in class copy-initialization.
1315 void AddFinalCopy(QualType T);
1316
1317 /// Add a new step invoking a conversion function, which is either
1318 /// a constructor or a conversion function.
1320 DeclAccessPair FoundDecl,
1321 QualType T,
1322 bool HadMultipleCandidates);
1323
1324 /// Add a new step that performs a qualification conversion to the
1325 /// given type.
1327 ExprValueKind Category);
1328
1329 /// Add a new step that performs a function reference conversion to the
1330 /// given type.
1332
1333 /// Add a new step that performs conversion from non-atomic to atomic
1334 /// type.
1336
1337 /// Add a new step that applies an implicit conversion sequence.
1339 QualType T, bool TopLevelOfInitList = false);
1340
1341 /// Add a list-initialization step.
1343
1344 /// Add a constructor-initialization step.
1345 ///
1346 /// \param FromInitList The constructor call is syntactically an initializer
1347 /// list.
1348 /// \param AsInitList The constructor is called as an init list constructor.
1351 QualType T,
1352 bool HadMultipleCandidates,
1353 bool FromInitList, bool AsInitList);
1354
1355 /// Add a zero-initialization step.
1357
1358 /// Add a C assignment step.
1359 //
1360 // FIXME: It isn't clear whether this should ever be needed;
1361 // ideally, we would handle everything needed in C in the common
1362 // path. However, that isn't the case yet.
1364
1365 /// Add a string init step.
1367
1368 /// Add an Objective-C object conversion step, which is
1369 /// always a no-op.
1371
1372 /// Add an array initialization loop step.
1373 void AddArrayInitLoopStep(QualType T, QualType EltTy);
1374
1375 /// Add an array initialization step.
1376 void AddArrayInitStep(QualType T, bool IsGNUExtension);
1377
1378 /// Add a parenthesized array initialization step.
1380
1381 /// Add a step to pass an object by indirect copy-restore.
1382 void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy);
1383
1384 /// Add a step to "produce" an Objective-C object (by
1385 /// retaining it).
1387
1388 /// Add a step to construct a std::initializer_list object from an
1389 /// initializer list.
1391
1392 /// Add a step to initialize an OpenCL sampler from an integer
1393 /// constant.
1395
1396 /// Add a step to initialzie an OpenCL opaque type (event_t, queue_t, etc.)
1397 /// from a zero constant.
1399
1401
1402 /// Only used when initializing structured bindings from an array with
1403 /// direct-list-initialization. Unwrap the initializer list to get the array
1404 /// for array copy.
1405 void AddUnwrapInitListInitStep(InitListExpr *Syntactic);
1406
1407 /// Add steps to unwrap a initializer list for a reference around a
1408 /// single element and rewrap it at the end.
1409 void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
1410
1411 /// Note that this initialization sequence failed.
1412 void SetFailed(FailureKind Failure) {
1414 this->Failure = Failure;
1415 assert((Failure != FK_Incomplete || !FailedIncompleteType.isNull()) &&
1416 "Incomplete type failure requires a type!");
1417 }
1418
1419 /// Note that this initialization sequence failed due to failed
1420 /// overload resolution.
1421 void SetOverloadFailure(FailureKind Failure, OverloadingResult Result);
1422
1423 /// Retrieve a reference to the candidate set when overload
1424 /// resolution fails.
1426 return FailedCandidateSet;
1427 }
1428
1429 /// Get the overloading result, for when the initialization
1430 /// sequence failed due to a bad overload.
1432 return FailedOverloadResult;
1433 }
1434
1435 /// Note that this initialization sequence failed due to an
1436 /// incomplete type.
1437 void setIncompleteTypeFailure(QualType IncompleteType) {
1438 FailedIncompleteType = IncompleteType;
1440 }
1441
1442 /// Determine why initialization failed.
1444 assert(Failed() && "Not an initialization failure!");
1445 return Failure;
1446 }
1447
1448 /// Dump a representation of this initialization sequence to
1449 /// the given stream, for debugging purposes.
1450 void dump(raw_ostream &OS) const;
1451
1452 /// Dump a representation of this initialization sequence to
1453 /// standard error, for debugging purposes.
1454 void dump() const;
1455};
1456
1457} // namespace clang
1458
1459#endif // LLVM_CLANG_SEMA_INITIALIZATION_H
Defines the clang::ASTContext interface.
TokenType getType() const
Returns the token's type, e.g.
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.
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:226
Represents a base class of a C++ class.
Definition DeclCXX.h:146
Represents a C++ constructor within a class.
Definition DeclCXX.h:2611
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:3160
Represents a function declaration or definition.
Definition Decl.h:2000
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:622
Represents a field injected from an anonymous union/struct into the parent scope.
Definition Decl.h:3467
Describes an C or C++ initializer list.
Definition Expr.h:5302
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...
step_iterator step_begin() const
void AddListInitializationStep(QualType T)
Add a list-initialization step.
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.
void AddStringInitStep(QualType T)
Add a string init step.
void AddStdInitializerListConstructionStep(QualType T)
Add a step to construct a std::initializer_list object from an initializer list.
void AddConstructorInitializationStep(DeclAccessPair FoundDecl, CXXConstructorDecl *Constructor, QualType T, bool HadMultipleCandidates, bool FromInitList, bool AsInitList)
Add a constructor-initialization step.
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...
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
InitializationSequence(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, bool TopLevelOfInitList=false, bool TreatUnavailableAsInvalid=true)
Try to perform initialization of the given entity, creating a record of the steps required to perform...
void AddQualificationConversionStep(QualType Ty, ExprValueKind Category)
Add a new step that performs a qualification conversion to the given type.
void AddFunctionReferenceConversionStep(QualType Ty)
Add a new step that performs a function reference conversion to the given type.
void AddDerivedToBaseCastStep(QualType BaseType, ExprValueKind Category)
Add a new step in the initialization that performs a derived-to- base cast.
FailureKind getFailureKind() const
Determine why initialization failed.
void InitializeFrom(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, bool TopLevelOfInitList, bool TreatUnavailableAsInvalid)
void AddParenthesizedListInitStep(QualType T)
void SetFailed(FailureKind Failure)
Note that this initialization sequence failed.
bool isAmbiguous() const
Determine whether this initialization failed due to an ambiguity.
void AddUnwrapInitListInitStep(InitListExpr *Syntactic)
Only used when initializing structured bindings from an array with direct-list-initialization.
void AddOCLZeroOpaqueTypeStep(QualType T)
Add a step to initialzie an OpenCL opaque type (event_t, queue_t, etc.) from a zero constant.
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...
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.
void SetOverloadFailure(FailureKind Failure, OverloadingResult Result)
Note that this initialization sequence failed due to failed overload resolution.
step_iterator step_end() const
void AddParenthesizedArrayInitStep(QualType T)
Add a parenthesized array initialization step.
void AddExtraneousCopyToTemporary(QualType T)
Add a new step that makes an extraneous copy of the input to a temporary of the same class type.
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.
void AddCAssignmentStep(QualType T)
Add a C assignment step.
void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy)
Add a step to pass an object by indirect copy-restore.
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...
bool Diagnose(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, ArrayRef< Expr * > Args)
Diagnose an potentially-invalid initialization sequence.
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.
void dump() const
Dump a representation of this initialization sequence to standard error, for debugging purposes.
void AddConversionSequenceStep(const ImplicitConversionSequence &ICS, QualType T, bool TopLevelOfInitList=false)
Add a new step that applies an implicit conversion sequence.
void AddZeroInitializationStep(QualType T)
Add a zero-initialization step.
void AddProduceObjCObjectStep(QualType T)
Add a step to "produce" an Objective-C object (by retaining it).
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.
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_HLSLInitListFlatteningFailed
HLSL intialization list flattening failed.
@ 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....
void AddArrayInitLoopStep(QualType T, QualType EltTy)
Add an array initialization loop step.
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...
void AddArrayInitStep(QualType T, bool IsGNUExtension)
Add an array initialization step.
bool isConstructorInitialization() const
Determine whether this initialization is direct call to a constructor.
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.
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.
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.
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
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 ...
void dump() const
Dump a representation of the initialized entity to standard error, for debugging purposes.
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_MatrixElement
The entity being initialized is an element of a matrix.
@ 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, EK_MatrixElement, or EK_ComplexElement,...
static InitializedEntity InitializeCompoundLiteralInit(TypeSourceInfo *TSI)
Create the entity for a compound literal initializer.
static InitializedEntity InitializeNew(SourceLocation NewLoc, QualType Type, bool VariableLengthArrayNew)
Create the initialization entity for an object allocated via new.
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:274
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:1160
Represents a parameter to a function.
Definition Decl.h:1790
A (possibly-)qualified type.
Definition TypeBase.h:937
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:868
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:8402
QualType getType() const
Return the type wrapped by this type source info.
Definition TypeBase.h:8413
The base class of the type hierarchy.
Definition TypeBase.h:1866
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
QualType getType() const
Definition Decl.h:723
Represents a variable declaration or definition.
Definition Decl.h:926
#define bool
Definition gpuintrin.h:32
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition Address.h:330
OverloadingResult
OverloadingResult - Capture the result of performing overload resolution.
Definition Overload.h:50
MutableArrayRef< Expr * > MultiExprArg
Definition Ownership.h:259
@ Result
The result type of a method or function.
Definition TypeBase.h:905
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition Specifiers.h:132
ActionResult< Expr * > ExprResult
Definition Ownership.h:249
@ Implicit
An implicit conversion.
Definition Sema.h:440
#define false
Definition stdbool.h:26