1 //===--- SemaInit.h - Semantic Analysis for Initializers --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides supporting data types for initialization of objects.
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_SEMA_INITIALIZATION_H
14 #define LLVM_CLANG_SEMA_INITIALIZATION_H
16 #include "clang/Sema/Ownership.h"
17 #include "clang/Sema/Overload.h"
18 #include "clang/AST/Type.h"
19 #include "clang/AST/UnresolvedSet.h"
20 #include "clang/Basic/SourceLocation.h"
21 #include "llvm/ADT/PointerIntPair.h"
22 #include "llvm/ADT/SmallVector.h"
27 class CXXBaseSpecifier;
37 /// \brief Describes an entity that is being initialized.
38 class InitializedEntity {
40 /// \brief Specifies the kind of entity being initialized.
42 /// \brief The entity being initialized is a variable.
44 /// \brief The entity being initialized is a function parameter.
46 /// \brief The entity being initialized is the result of a function call.
48 /// \brief The entity being initialized is an exception object that
51 /// \brief The entity being initialized is a non-static data member
54 /// \brief The entity being initialized is an element of an array.
56 /// \brief The entity being initialized is an object (or array of
57 /// objects) allocated via new.
59 /// \brief The entity being initialized is a temporary object.
61 /// \brief The entity being initialized is a base member subobject.
63 /// \brief The initialization is being done by a delegating constructor.
65 /// \brief The entity being initialized is an element of a vector.
68 /// \brief The entity being initialized is a field of block descriptor for
69 /// the copied-in c++ object.
71 /// \brief The entity being initialized is the real or imaginary part of a
77 /// \brief The kind of entity being initialized.
80 /// \brief If non-NULL, the parent entity in which this
81 /// initialization occurs.
82 const InitializedEntity *Parent;
84 /// \brief The type of the object or reference being initialized.
88 /// \brief When Kind == EK_Variable or EK_Member, the VarDecl or
89 /// FieldDecl, respectively.
90 DeclaratorDecl *VariableOrMember;
92 /// \brief When Kind == EK_Parameter, the ParmVarDecl, with the
93 /// low bit indicating whether the parameter is "consumed".
96 /// \brief When Kind == EK_Temporary, the type source information for
98 TypeSourceInfo *TypeInfo;
101 /// \brief When Kind == EK_Result, EK_Exception, or EK_New, the
102 /// location of the 'return', 'throw', or 'new' keyword,
103 /// respectively. When Kind == EK_Temporary, the location where
104 /// the temporary is being created.
107 /// \brief Whether the entity being initialized may end up using the
108 /// named return value optimization (NRVO).
112 /// \brief When Kind == EK_Base, the base specifier that provides the
113 /// base class. The lower bit specifies whether the base is an inherited
117 /// \brief When Kind == EK_ArrayElement, EK_VectorElement, or
118 /// EK_ComplexElement, the index of the array or vector element being
123 InitializedEntity() { }
125 /// \brief Create the initialization entity for a variable.
126 InitializedEntity(VarDecl *Var)
127 : Kind(EK_Variable), Parent(0), Type(Var->getType()),
128 VariableOrMember(Var) { }
130 /// \brief Create the initialization entity for the result of a
131 /// function, throwing an object, performing an explicit cast, or
132 /// initializing a parameter for which there is no declaration.
133 InitializedEntity(EntityKind Kind, SourceLocation Loc, QualType Type,
135 : Kind(Kind), Parent(0), Type(Type)
137 LocAndNRVO.Location = Loc.getRawEncoding();
138 LocAndNRVO.NRVO = NRVO;
141 /// \brief Create the initialization entity for a member subobject.
142 InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent)
143 : Kind(EK_Member), Parent(Parent), Type(Member->getType()),
144 VariableOrMember(Member) { }
146 /// \brief Create the initialization entity for an array element.
147 InitializedEntity(ASTContext &Context, unsigned Index,
148 const InitializedEntity &Parent);
151 /// \brief Create the initialization entity for a variable.
152 static InitializedEntity InitializeVariable(VarDecl *Var) {
153 return InitializedEntity(Var);
156 /// \brief Create the initialization entity for a parameter.
157 static InitializedEntity InitializeParameter(ASTContext &Context,
159 bool Consumed = (Context.getLangOptions().ObjCAutoRefCount &&
160 Parm->hasAttr<NSConsumedAttr>());
162 InitializedEntity Entity;
163 Entity.Kind = EK_Parameter;
164 Entity.Type = Context.getVariableArrayDecayedType(
165 Parm->getType().getUnqualifiedType());
168 = (static_cast<uintptr_t>(Consumed) | reinterpret_cast<uintptr_t>(Parm));
172 /// \brief Create the initialization entity for a parameter that is
173 /// only known by its type.
174 static InitializedEntity InitializeParameter(ASTContext &Context,
177 InitializedEntity Entity;
178 Entity.Kind = EK_Parameter;
179 Entity.Type = Context.getVariableArrayDecayedType(Type);
181 Entity.Parameter = (Consumed);
185 /// \brief Create the initialization entity for the result of a function.
186 static InitializedEntity InitializeResult(SourceLocation ReturnLoc,
187 QualType Type, bool NRVO) {
188 return InitializedEntity(EK_Result, ReturnLoc, Type, NRVO);
191 static InitializedEntity InitializeBlock(SourceLocation BlockVarLoc,
192 QualType Type, bool NRVO) {
193 return InitializedEntity(EK_BlockElement, BlockVarLoc, Type, NRVO);
196 /// \brief Create the initialization entity for an exception object.
197 static InitializedEntity InitializeException(SourceLocation ThrowLoc,
198 QualType Type, bool NRVO) {
199 return InitializedEntity(EK_Exception, ThrowLoc, Type, NRVO);
202 /// \brief Create the initialization entity for an object allocated via new.
203 static InitializedEntity InitializeNew(SourceLocation NewLoc, QualType Type) {
204 return InitializedEntity(EK_New, NewLoc, Type);
207 /// \brief Create the initialization entity for a temporary.
208 static InitializedEntity InitializeTemporary(QualType Type) {
209 return InitializedEntity(EK_Temporary, SourceLocation(), Type);
212 /// \brief Create the initialization entity for a temporary.
213 static InitializedEntity InitializeTemporary(TypeSourceInfo *TypeInfo) {
214 InitializedEntity Result(EK_Temporary, SourceLocation(),
215 TypeInfo->getType());
216 Result.TypeInfo = TypeInfo;
220 /// \brief Create the initialization entity for a base class subobject.
221 static InitializedEntity InitializeBase(ASTContext &Context,
222 CXXBaseSpecifier *Base,
223 bool IsInheritedVirtualBase);
225 /// \brief Create the initialization entity for a delegated constructor.
226 static InitializedEntity InitializeDelegation(QualType Type) {
227 return InitializedEntity(EK_Delegating, SourceLocation(), Type);
230 /// \brief Create the initialization entity for a member subobject.
231 static InitializedEntity InitializeMember(FieldDecl *Member,
232 const InitializedEntity *Parent = 0) {
233 return InitializedEntity(Member, Parent);
236 /// \brief Create the initialization entity for a member subobject.
237 static InitializedEntity InitializeMember(IndirectFieldDecl *Member,
238 const InitializedEntity *Parent = 0) {
239 return InitializedEntity(Member->getAnonField(), Parent);
242 /// \brief Create the initialization entity for an array element.
243 static InitializedEntity InitializeElement(ASTContext &Context,
245 const InitializedEntity &Parent) {
246 return InitializedEntity(Context, Index, Parent);
249 /// \brief Determine the kind of initialization.
250 EntityKind getKind() const { return Kind; }
252 /// \brief Retrieve the parent of the entity being initialized, when
253 /// the initialization itself is occurring within the context of a
254 /// larger initialization.
255 const InitializedEntity *getParent() const { return Parent; }
257 /// \brief Retrieve type being initialized.
258 QualType getType() const { return Type; }
260 /// \brief Retrieve complete type-source information for the object being
261 /// constructed, if known.
262 TypeSourceInfo *getTypeSourceInfo() const {
263 if (Kind == EK_Temporary)
269 /// \brief Retrieve the name of the entity being initialized.
270 DeclarationName getName() const;
272 /// \brief Retrieve the variable, parameter, or field being
274 DeclaratorDecl *getDecl() const;
276 /// \brief Determine whether this initialization allows the named return
277 /// value optimization, which also applies to thrown objects.
278 bool allowsNRVO() const;
280 /// \brief Determine whether this initialization consumes the
282 bool isParameterConsumed() const {
283 assert(getKind() == EK_Parameter && "Not a parameter");
284 return (Parameter & 1);
287 /// \brief Retrieve the base specifier.
288 CXXBaseSpecifier *getBaseSpecifier() const {
289 assert(getKind() == EK_Base && "Not a base specifier");
290 return reinterpret_cast<CXXBaseSpecifier *>(Base & ~0x1);
293 /// \brief Return whether the base is an inherited virtual base.
294 bool isInheritedVirtualBase() const {
295 assert(getKind() == EK_Base && "Not a base specifier");
299 /// \brief Determine the location of the 'return' keyword when initializing
300 /// the result of a function call.
301 SourceLocation getReturnLoc() const {
302 assert(getKind() == EK_Result && "No 'return' location!");
303 return SourceLocation::getFromRawEncoding(LocAndNRVO.Location);
306 /// \brief Determine the location of the 'throw' keyword when initializing
307 /// an exception object.
308 SourceLocation getThrowLoc() const {
309 assert(getKind() == EK_Exception && "No 'throw' location!");
310 return SourceLocation::getFromRawEncoding(LocAndNRVO.Location);
313 /// \brief If this is already the initializer for an array or vector
314 /// element, sets the element index.
315 void setElementIndex(unsigned Index) {
316 assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
322 /// \brief Describes the kind of initialization being performed, along with
323 /// location information for tokens related to the initialization (equal sign,
325 class InitializationKind {
327 /// \brief The kind of initialization being performed.
329 IK_Direct, ///< Direct initialization
330 IK_Copy, ///< Copy initialization
331 IK_Default, ///< Default initialization
332 IK_Value ///< Value initialization
336 /// \brief The kind of initialization that we're storing.
337 enum StoredInitKind {
338 SIK_Direct = IK_Direct, ///< Direct initialization
339 SIK_Copy = IK_Copy, ///< Copy initialization
340 SIK_Default = IK_Default, ///< Default initialization
341 SIK_Value = IK_Value, ///< Value initialization
342 SIK_ImplicitValue, ///< Implicit value initialization
343 SIK_DirectCast, ///< Direct initialization due to a cast
344 /// \brief Direct initialization due to a C-style cast.
345 SIK_DirectCStyleCast,
346 /// \brief Direct initialization due to a functional-style cast.
347 SIK_DirectFunctionalCast
350 /// \brief The kind of initialization being performed.
353 /// \brief The source locations involved in the initialization.
354 SourceLocation Locations[3];
356 InitializationKind(StoredInitKind Kind, SourceLocation Loc1,
357 SourceLocation Loc2, SourceLocation Loc3)
366 /// \brief Create a direct initialization.
367 static InitializationKind CreateDirect(SourceLocation InitLoc,
368 SourceLocation LParenLoc,
369 SourceLocation RParenLoc) {
370 return InitializationKind(SIK_Direct, InitLoc, LParenLoc, RParenLoc);
373 /// \brief Create a direct initialization due to a cast that isn't a C-style
374 /// or functional cast.
375 static InitializationKind CreateCast(SourceRange TypeRange) {
376 return InitializationKind(SIK_DirectCast,
377 TypeRange.getBegin(), TypeRange.getBegin(),
381 /// \brief Create a direct initialization for a C-style cast.
382 static InitializationKind CreateCStyleCast(SourceLocation StartLoc,
383 SourceRange TypeRange) {
384 return InitializationKind(SIK_DirectCStyleCast,
385 StartLoc, TypeRange.getBegin(),
389 /// \brief Create a direct initialization for a functional cast.
390 static InitializationKind CreateFunctionalCast(SourceRange TypeRange) {
391 return InitializationKind(SIK_DirectFunctionalCast,
392 TypeRange.getBegin(), TypeRange.getBegin(),
396 /// \brief Create a copy initialization.
397 static InitializationKind CreateCopy(SourceLocation InitLoc,
398 SourceLocation EqualLoc) {
399 return InitializationKind(SIK_Copy, InitLoc, EqualLoc, EqualLoc);
402 /// \brief Create a default initialization.
403 static InitializationKind CreateDefault(SourceLocation InitLoc) {
404 return InitializationKind(SIK_Default, InitLoc, InitLoc, InitLoc);
407 /// \brief Create a value initialization.
408 static InitializationKind CreateValue(SourceLocation InitLoc,
409 SourceLocation LParenLoc,
410 SourceLocation RParenLoc,
411 bool isImplicit = false) {
412 return InitializationKind(isImplicit? SIK_ImplicitValue : SIK_Value,
413 InitLoc, LParenLoc, RParenLoc);
416 /// \brief Determine the initialization kind.
417 InitKind getKind() const {
418 if (Kind > SIK_ImplicitValue)
420 if (Kind == SIK_ImplicitValue)
423 return (InitKind)Kind;
426 /// \brief Determine whether this initialization is an explicit cast.
427 bool isExplicitCast() const {
428 return Kind == SIK_DirectCast ||
429 Kind == SIK_DirectCStyleCast ||
430 Kind == SIK_DirectFunctionalCast;
433 /// \brief Determine whether this initialization is a C-style cast.
434 bool isCStyleOrFunctionalCast() const {
435 return Kind == SIK_DirectCStyleCast || Kind == SIK_DirectFunctionalCast;
438 /// brief Determine whether this is a C-style cast.
439 bool isCStyleCast() const {
440 return Kind == SIK_DirectCStyleCast;
443 /// brief Determine whether this is a functional-style cast.
444 bool isFunctionalCast() const {
445 return Kind == SIK_DirectFunctionalCast;
448 /// \brief Determine whether this initialization is an implicit
449 /// value-initialization, e.g., as occurs during aggregate
451 bool isImplicitValueInit() const { return Kind == SIK_ImplicitValue; }
453 /// \brief Retrieve the location at which initialization is occurring.
454 SourceLocation getLocation() const { return Locations[0]; }
456 /// \brief Retrieve the source range that covers the initialization.
457 SourceRange getRange() const {
458 return SourceRange(Locations[0], Locations[2]);
461 /// \brief Retrieve the location of the equal sign for copy initialization
463 SourceLocation getEqualLoc() const {
464 assert(Kind == SIK_Copy && "Only copy initialization has an '='");
468 bool isCopyInit() const { return Kind == SIK_Copy; }
470 /// \brief Retrieve the source range containing the locations of the open
471 /// and closing parentheses for value and direct initializations.
472 SourceRange getParenRange() const {
473 assert((getKind() == IK_Direct || Kind == SIK_Value) &&
474 "Only direct- and value-initialization have parentheses");
475 return SourceRange(Locations[1], Locations[2]);
479 /// \brief Describes the sequence of initializations required to initialize
480 /// a given object or reference with a set of arguments.
481 class InitializationSequence {
483 /// \brief Describes the kind of initialization sequence computed.
485 /// \brief A failed initialization sequence. The failure kind tells what
489 /// \brief A dependent initialization, which could not be
490 /// type-checked due to the presence of dependent types or
491 /// dependently-typed expressions.
494 /// \brief A normal sequence.
498 /// \brief Describes the kind of a particular step in an initialization
501 /// \brief Resolve the address of an overloaded function to a specific
502 /// function declaration.
503 SK_ResolveAddressOfOverloadedFunction,
504 /// \brief Perform a derived-to-base cast, producing an rvalue.
505 SK_CastDerivedToBaseRValue,
506 /// \brief Perform a derived-to-base cast, producing an xvalue.
507 SK_CastDerivedToBaseXValue,
508 /// \brief Perform a derived-to-base cast, producing an lvalue.
509 SK_CastDerivedToBaseLValue,
510 /// \brief Reference binding to an lvalue.
512 /// \brief Reference binding to a temporary.
513 SK_BindReferenceToTemporary,
514 /// \brief An optional copy of a temporary object to another
515 /// temporary object, which is permitted (but not required) by
516 /// C++98/03 but not C++0x.
517 SK_ExtraneousCopyToTemporary,
518 /// \brief Perform a user-defined conversion, either via a conversion
519 /// function or via a constructor.
521 /// \brief Perform a qualification conversion, producing an rvalue.
522 SK_QualificationConversionRValue,
523 /// \brief Perform a qualification conversion, producing an xvalue.
524 SK_QualificationConversionXValue,
525 /// \brief Perform a qualification conversion, producing an lvalue.
526 SK_QualificationConversionLValue,
527 /// \brief Perform an implicit conversion sequence.
528 SK_ConversionSequence,
529 /// \brief Perform list-initialization without a constructor
530 SK_ListInitialization,
531 /// \brief Perform list-initialization with a constructor.
532 SK_ListConstructorCall,
533 /// \brief Perform initialization via a constructor.
534 SK_ConstructorInitialization,
535 /// \brief Zero-initialize the object
536 SK_ZeroInitialization,
537 /// \brief C assignment
539 /// \brief Initialization by string
541 /// \brief An initialization that "converts" an Objective-C object
542 /// (not a point to an object) to another Objective-C object type.
543 SK_ObjCObjectConversion,
544 /// \brief Array initialization (from an array rvalue).
545 /// This is a GNU C extension.
547 /// \brief Pass an object by indirect copy-and-restore.
548 SK_PassByIndirectCopyRestore,
549 /// \brief Pass an object by indirect restore.
550 SK_PassByIndirectRestore,
551 /// \brief Produce an Objective-C object pointer.
555 /// \brief A single step in the initialization sequence.
558 /// \brief The kind of conversion or initialization step we are taking.
561 // \brief The type that results from this initialization.
565 /// \brief When Kind == SK_ResolvedOverloadedFunction or Kind ==
566 /// SK_UserConversion, the function that the expression should be
567 /// resolved to or the conversion function to call, respectively.
568 /// When Kind == SK_ConstructorInitialization or SK_ListConstruction,
569 /// the constructor to be called.
571 /// Always a FunctionDecl, plus a Boolean flag telling if it was
572 /// selected from an overloaded set having size greater than 1.
573 /// For conversion decls, the naming class is the source type.
574 /// For construct decls, the naming class is the target type.
576 bool HadMultipleCandidates;
577 FunctionDecl *Function;
578 DeclAccessPair FoundDecl;
581 /// \brief When Kind = SK_ConversionSequence, the implicit conversion
583 ImplicitConversionSequence *ICS;
590 /// \brief The kind of initialization sequence computed.
591 enum SequenceKind SequenceKind;
593 /// \brief Steps taken by this initialization.
594 SmallVector<Step, 4> Steps;
597 /// \brief Describes why initialization failed.
599 /// \brief Too many initializers provided for a reference.
600 FK_TooManyInitsForReference,
601 /// \brief Array must be initialized with an initializer list.
602 FK_ArrayNeedsInitList,
603 /// \brief Array must be initialized with an initializer list or a
605 FK_ArrayNeedsInitListOrStringLiteral,
606 /// \brief Array type mismatch.
607 FK_ArrayTypeMismatch,
608 /// \brief Non-constant array initializer
609 FK_NonConstantArrayInit,
610 /// \brief Cannot resolve the address of an overloaded function.
611 FK_AddressOfOverloadFailed,
612 /// \brief Overloading due to reference initialization failed.
613 FK_ReferenceInitOverloadFailed,
614 /// \brief Non-const lvalue reference binding to a temporary.
615 FK_NonConstLValueReferenceBindingToTemporary,
616 /// \brief Non-const lvalue reference binding to an lvalue of unrelated
618 FK_NonConstLValueReferenceBindingToUnrelated,
619 /// \brief Rvalue reference binding to an lvalue.
620 FK_RValueReferenceBindingToLValue,
621 /// \brief Reference binding drops qualifiers.
622 FK_ReferenceInitDropsQualifiers,
623 /// \brief Reference binding failed.
624 FK_ReferenceInitFailed,
625 /// \brief Implicit conversion failed.
627 /// \brief Implicit conversion failed.
628 FK_ConversionFromPropertyFailed,
629 /// \brief Too many initializers for scalar
630 FK_TooManyInitsForScalar,
631 /// \brief Reference initialization from an initializer list
632 FK_ReferenceBindingToInitList,
633 /// \brief Initialization of some unused destination type with an
634 /// initializer list.
635 FK_InitListBadDestinationType,
636 /// \brief Overloading for a user-defined conversion failed.
637 FK_UserConversionOverloadFailed,
638 /// \brief Overloaded for initialization by constructor failed.
639 FK_ConstructorOverloadFailed,
640 /// \brief Default-initialization of a 'const' object.
641 FK_DefaultInitOfConst,
642 /// \brief Initialization of an incomplete type.
644 /// \brief List initialization failed at some point.
645 FK_ListInitializationFailed
649 /// \brief The reason why initialization failed.
652 /// \brief The failed result of overload resolution.
653 OverloadingResult FailedOverloadResult;
655 /// \brief The candidate set created when initialization failed.
656 OverloadCandidateSet FailedCandidateSet;
658 /// \brief Prints a follow-up note that highlights the location of
659 /// the initialized entity, if it's remote.
660 void PrintInitLocationNote(Sema &S, const InitializedEntity &Entity);
663 /// \brief Try to perform initialization of the given entity, creating a
664 /// record of the steps required to perform the initialization.
666 /// The generated initialization sequence will either contain enough
667 /// information to diagnose
669 /// \param S the semantic analysis object.
671 /// \param Entity the entity being initialized.
673 /// \param Kind the kind of initialization being performed.
675 /// \param Args the argument(s) provided for initialization.
677 /// \param NumArgs the number of arguments provided for initialization.
678 InitializationSequence(Sema &S,
679 const InitializedEntity &Entity,
680 const InitializationKind &Kind,
684 ~InitializationSequence();
686 /// \brief Perform the actual initialization of the given entity based on
687 /// the computed initialization sequence.
689 /// \param S the semantic analysis object.
691 /// \param Entity the entity being initialized.
693 /// \param Kind the kind of initialization being performed.
695 /// \param Args the argument(s) provided for initialization, ownership of
696 /// which is transferred into the routine.
698 /// \param ResultType if non-NULL, will be set to the type of the
699 /// initialized object, which is the type of the declaration in most
700 /// cases. However, when the initialized object is a variable of
701 /// incomplete array type and the initializer is an initializer
702 /// list, this type will be set to the completed array type.
704 /// \returns an expression that performs the actual object initialization, if
705 /// the initialization is well-formed. Otherwise, emits diagnostics
706 /// and returns an invalid expression.
707 ExprResult Perform(Sema &S,
708 const InitializedEntity &Entity,
709 const InitializationKind &Kind,
711 QualType *ResultType = 0);
713 /// \brief Diagnose an potentially-invalid initialization sequence.
715 /// \returns true if the initialization sequence was ill-formed,
717 bool Diagnose(Sema &S,
718 const InitializedEntity &Entity,
719 const InitializationKind &Kind,
720 Expr **Args, unsigned NumArgs);
722 /// \brief Determine the kind of initialization sequence computed.
723 enum SequenceKind getKind() const { return SequenceKind; }
725 /// \brief Set the kind of sequence computed.
726 void setSequenceKind(enum SequenceKind SK) { SequenceKind = SK; }
728 /// \brief Determine whether the initialization sequence is valid.
729 operator bool() const { return !Failed(); }
731 /// \brief Determine whether the initialization sequence is invalid.
732 bool Failed() const { return SequenceKind == FailedSequence; }
734 typedef SmallVector<Step, 4>::const_iterator step_iterator;
735 step_iterator step_begin() const { return Steps.begin(); }
736 step_iterator step_end() const { return Steps.end(); }
738 /// \brief Determine whether this initialization is a direct reference
739 /// binding (C++ [dcl.init.ref]).
740 bool isDirectReferenceBinding() const;
742 /// \brief Determine whether this initialization failed due to an ambiguity.
743 bool isAmbiguous() const;
745 /// \brief Determine whether this initialization is direct call to a
747 bool isConstructorInitialization() const;
749 /// \brief Returns whether the last step in this initialization sequence is a
750 /// narrowing conversion, defined by C++0x [dcl.init.list]p7.
752 /// If this function returns true, *isInitializerConstant will be set to
753 /// describe whether *Initializer was a constant expression. If
754 /// *isInitializerConstant is set to true, *ConstantValue will be set to the
755 /// evaluated value of *Initializer.
756 bool endsWithNarrowing(ASTContext &Ctx, const Expr *Initializer,
757 bool *isInitializerConstant,
758 APValue *ConstantValue) const;
760 /// \brief Add a new step in the initialization that resolves the address
761 /// of an overloaded function to a specific function declaration.
763 /// \param Function the function to which the overloaded function reference
765 void AddAddressOverloadResolutionStep(FunctionDecl *Function,
766 DeclAccessPair Found);
768 /// \brief Add a new step in the initialization that performs a derived-to-
771 /// \param BaseType the base type to which we will be casting.
773 /// \param IsLValue true if the result of this cast will be treated as
775 void AddDerivedToBaseCastStep(QualType BaseType,
776 ExprValueKind Category);
778 /// \brief Add a new step binding a reference to an object.
780 /// \param BindingTemporary True if we are binding a reference to a temporary
781 /// object (thereby extending its lifetime); false if we are binding to an
782 /// lvalue or an lvalue treated as an rvalue.
784 /// \param UnnecessaryCopy True if we should check for a copy
785 /// constructor for a completely unnecessary but
786 void AddReferenceBindingStep(QualType T, bool BindingTemporary);
788 /// \brief Add a new step that makes an extraneous copy of the input
789 /// to a temporary of the same class type.
791 /// This extraneous copy only occurs during reference binding in
792 /// C++98/03, where we are permitted (but not required) to introduce
793 /// an extra copy. At a bare minimum, we must check that we could
794 /// call the copy constructor, and produce a diagnostic if the copy
795 /// constructor is inaccessible or no copy constructor matches.
797 /// \param T The type of the temporary being created.
798 void AddExtraneousCopyToTemporary(QualType T);
800 /// \brief Add a new step invoking a conversion function, which is either
801 /// a constructor or a conversion function.
802 void AddUserConversionStep(FunctionDecl *Function,
803 DeclAccessPair FoundDecl,
806 /// \brief Add a new step that performs a qualification conversion to the
808 void AddQualificationConversionStep(QualType Ty,
809 ExprValueKind Category);
811 /// \brief Add a new step that applies an implicit conversion sequence.
812 void AddConversionSequenceStep(const ImplicitConversionSequence &ICS,
815 /// \brief Add a list-initialiation step.
816 void AddListInitializationStep(QualType T);
818 /// \brief Add a constructor-initialization step.
819 void AddConstructorInitializationStep(CXXConstructorDecl *Constructor,
820 AccessSpecifier Access,
823 /// \brief Add a zero-initialization step.
824 void AddZeroInitializationStep(QualType T);
826 /// \brief Add a C assignment step.
828 // FIXME: It isn't clear whether this should ever be needed;
829 // ideally, we would handle everything needed in C in the common
830 // path. However, that isn't the case yet.
831 void AddCAssignmentStep(QualType T);
833 /// \brief Add a string init step.
834 void AddStringInitStep(QualType T);
836 /// \brief Add an Objective-C object conversion step, which is
838 void AddObjCObjectConversionStep(QualType T);
840 /// \brief Add an array initialization step.
841 void AddArrayInitStep(QualType T);
843 /// \brief Add a step to pass an object by indirect copy-restore.
844 void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy);
846 /// \brief Add a step to "produce" an Objective-C object (by
848 void AddProduceObjCObjectStep(QualType T);
850 /// \brief Note that this initialization sequence failed.
851 void SetFailed(FailureKind Failure) {
852 SequenceKind = FailedSequence;
853 this->Failure = Failure;
856 /// \brief Note that this initialization sequence failed due to failed
857 /// overload resolution.
858 void SetOverloadFailure(FailureKind Failure, OverloadingResult Result);
860 /// \brief Retrieve a reference to the candidate set when overload
861 /// resolution fails.
862 OverloadCandidateSet &getFailedCandidateSet() {
863 return FailedCandidateSet;
866 /// brief Get the overloading result, for when the initialization
867 /// sequence failed due to a bad overload.
868 OverloadingResult getFailedOverloadResult() const {
869 return FailedOverloadResult;
872 /// \brief Determine why initialization failed.
873 FailureKind getFailureKind() const {
874 assert(Failed() && "Not an initialization failure!");
878 /// \brief Dump a representation of this initialization sequence to
879 /// the given stream, for debugging purposes.
880 void dump(raw_ostream &OS) const;
882 /// \brief Dump a representation of this initialization sequence to
883 /// standard error, for debugging purposes.
887 } // end namespace clang
889 #endif // LLVM_CLANG_SEMA_INITIALIZATION_H