Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:37:00

0001 //===- Initialization.h - Semantic Analysis for Initializers ----*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file provides supporting data types for initialization of objects.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CLANG_SEMA_INITIALIZATION_H
0014 #define LLVM_CLANG_SEMA_INITIALIZATION_H
0015 
0016 #include "clang/AST/ASTContext.h"
0017 #include "clang/AST/Attr.h"
0018 #include "clang/AST/Decl.h"
0019 #include "clang/AST/DeclAccessPair.h"
0020 #include "clang/AST/DeclarationName.h"
0021 #include "clang/AST/Expr.h"
0022 #include "clang/AST/Type.h"
0023 #include "clang/Basic/IdentifierTable.h"
0024 #include "clang/Basic/LLVM.h"
0025 #include "clang/Basic/LangOptions.h"
0026 #include "clang/Basic/SourceLocation.h"
0027 #include "clang/Basic/Specifiers.h"
0028 #include "clang/Sema/Overload.h"
0029 #include "clang/Sema/Ownership.h"
0030 #include "llvm/ADT/ArrayRef.h"
0031 #include "llvm/ADT/SmallVector.h"
0032 #include "llvm/ADT/StringRef.h"
0033 #include "llvm/ADT/iterator_range.h"
0034 #include "llvm/Support/Casting.h"
0035 #include <cassert>
0036 #include <cstdint>
0037 #include <string>
0038 
0039 namespace clang {
0040 
0041 class CXXBaseSpecifier;
0042 class CXXConstructorDecl;
0043 class ObjCMethodDecl;
0044 class Sema;
0045 
0046 /// Describes an entity that is being initialized.
0047 class alignas(8) InitializedEntity {
0048 public:
0049   /// Specifies the kind of entity being initialized.
0050   enum EntityKind {
0051     /// The entity being initialized is a variable.
0052     EK_Variable,
0053 
0054     /// The entity being initialized is a function parameter.
0055     EK_Parameter,
0056 
0057     /// The entity being initialized is a non-type template parameter.
0058     EK_TemplateParameter,
0059 
0060     /// The entity being initialized is the result of a function call.
0061     EK_Result,
0062 
0063     /// The entity being initialized is the result of a statement expression.
0064     EK_StmtExprResult,
0065 
0066     /// The entity being initialized is an exception object that
0067     /// is being thrown.
0068     EK_Exception,
0069 
0070     /// The entity being initialized is a non-static data member
0071     /// subobject.
0072     EK_Member,
0073 
0074     /// The entity being initialized is an element of an array.
0075     EK_ArrayElement,
0076 
0077     /// The entity being initialized is an object (or array of
0078     /// objects) allocated via new.
0079     EK_New,
0080 
0081     /// The entity being initialized is a temporary object.
0082     EK_Temporary,
0083 
0084     /// The entity being initialized is a base member subobject.
0085     EK_Base,
0086 
0087     /// The initialization is being done by a delegating constructor.
0088     EK_Delegating,
0089 
0090     /// The entity being initialized is an element of a vector.
0091     /// or vector.
0092     EK_VectorElement,
0093 
0094     /// The entity being initialized is a field of block descriptor for
0095     /// the copied-in c++ object.
0096     EK_BlockElement,
0097 
0098     /// The entity being initialized is a field of block descriptor for the
0099     /// copied-in lambda object that's used in the lambda to block conversion.
0100     EK_LambdaToBlockConversionBlockElement,
0101 
0102     /// The entity being initialized is the real or imaginary part of a
0103     /// complex number.
0104     EK_ComplexElement,
0105 
0106     /// The entity being initialized is the field that captures a
0107     /// variable in a lambda.
0108     EK_LambdaCapture,
0109 
0110     /// The entity being initialized is the initializer for a compound
0111     /// literal.
0112     EK_CompoundLiteralInit,
0113 
0114     /// The entity being implicitly initialized back to the formal
0115     /// result type.
0116     EK_RelatedResult,
0117 
0118     /// The entity being initialized is a function parameter; function
0119     /// is member of group of audited CF APIs.
0120     EK_Parameter_CF_Audited,
0121 
0122     /// The entity being initialized is a structured binding of a
0123     /// decomposition declaration.
0124     EK_Binding,
0125 
0126     /// The entity being initialized is a non-static data member subobject of an
0127     /// object initialized via parenthesized aggregate initialization.
0128     EK_ParenAggInitMember,
0129 
0130     // Note: err_init_conversion_failed in DiagnosticSemaKinds.td uses this
0131     // enum as an index for its first %select.  When modifying this list,
0132     // that diagnostic text needs to be updated as well.
0133   };
0134 
0135 private:
0136   /// The kind of entity being initialized.
0137   EntityKind Kind;
0138 
0139   /// If non-NULL, the parent entity in which this
0140   /// initialization occurs.
0141   const InitializedEntity *Parent = nullptr;
0142 
0143   /// The type of the object or reference being initialized.
0144   QualType Type;
0145 
0146   /// The mangling number for the next reference temporary to be created.
0147   mutable unsigned ManglingNumber = 0;
0148 
0149   struct LN {
0150     /// When Kind == EK_Result, EK_Exception, EK_New, the
0151     /// location of the 'return', 'throw', or 'new' keyword,
0152     /// respectively. When Kind == EK_Temporary, the location where
0153     /// the temporary is being created.
0154     SourceLocation Location;
0155 
0156     /// Whether the entity being initialized may end up using the
0157     /// named return value optimization (NRVO).
0158     bool NRVO;
0159   };
0160 
0161   struct VD {
0162     /// The VarDecl, FieldDecl, or BindingDecl being initialized.
0163     ValueDecl *VariableOrMember;
0164 
0165     /// When Kind == EK_Member, whether this is an implicit member
0166     /// initialization in a copy or move constructor. These can perform array
0167     /// copies.
0168     bool IsImplicitFieldInit;
0169 
0170     /// When Kind == EK_Member, whether this is the initial initialization
0171     /// check for a default member initializer.
0172     bool IsDefaultMemberInit;
0173   };
0174 
0175   struct C {
0176     /// The name of the variable being captured by an EK_LambdaCapture.
0177     IdentifierInfo *VarID;
0178 
0179     /// The source location at which the capture occurs.
0180     SourceLocation Location;
0181   };
0182 
0183   union {
0184     /// When Kind == EK_Variable, EK_Member, EK_Binding, or
0185     /// EK_TemplateParameter, the variable, binding, or template parameter.
0186     VD Variable;
0187 
0188     /// When Kind == EK_RelatedResult, the ObjectiveC method where
0189     /// result type was implicitly changed to accommodate ARC semantics.
0190     ObjCMethodDecl *MethodDecl;
0191 
0192     /// When Kind == EK_Parameter, the ParmVarDecl, with the
0193     /// integer indicating whether the parameter is "consumed".
0194     llvm::PointerIntPair<ParmVarDecl *, 1> Parameter;
0195 
0196     /// When Kind == EK_Temporary or EK_CompoundLiteralInit, the type
0197     /// source information for the temporary.
0198     TypeSourceInfo *TypeInfo;
0199 
0200     struct LN LocAndNRVO;
0201 
0202     /// When Kind == EK_Base, the base specifier that provides the
0203     /// base class. The integer specifies whether the base is an inherited
0204     /// virtual base.
0205     llvm::PointerIntPair<const CXXBaseSpecifier *, 1> Base;
0206 
0207     /// When Kind == EK_ArrayElement, EK_VectorElement, or
0208     /// EK_ComplexElement, the index of the array or vector element being
0209     /// initialized.
0210     unsigned Index;
0211 
0212     struct C Capture;
0213   };
0214 
0215   InitializedEntity() {}
0216 
0217   /// Create the initialization entity for a variable.
0218   InitializedEntity(VarDecl *Var, EntityKind EK = EK_Variable)
0219       : Kind(EK), Type(Var->getType()), Variable{Var, false, false} {}
0220 
0221   /// Create the initialization entity for the result of a
0222   /// function, throwing an object, performing an explicit cast, or
0223   /// initializing a parameter for which there is no declaration.
0224   InitializedEntity(EntityKind Kind, SourceLocation Loc, QualType Type,
0225                     bool NRVO = false)
0226       : Kind(Kind), Type(Type) {
0227     new (&LocAndNRVO) LN;
0228     LocAndNRVO.Location = Loc;
0229     LocAndNRVO.NRVO = NRVO;
0230   }
0231 
0232   /// Create the initialization entity for a member subobject.
0233   InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent,
0234                     bool Implicit, bool DefaultMemberInit,
0235                     bool IsParenAggInit = false)
0236       : Kind(IsParenAggInit ? EK_ParenAggInitMember : EK_Member),
0237         Parent(Parent), Type(Member->getType()),
0238         Variable{Member, Implicit, DefaultMemberInit} {}
0239 
0240   /// Create the initialization entity for an array element.
0241   InitializedEntity(ASTContext &Context, unsigned Index,
0242                     const InitializedEntity &Parent);
0243 
0244   /// Create the initialization entity for a lambda capture.
0245   InitializedEntity(IdentifierInfo *VarID, QualType FieldType, SourceLocation Loc)
0246       : Kind(EK_LambdaCapture), Type(FieldType) {
0247     new (&Capture) C;
0248     Capture.VarID = VarID;
0249     Capture.Location = Loc;
0250   }
0251 
0252 public:
0253   /// Create the initialization entity for a variable.
0254   static InitializedEntity InitializeVariable(VarDecl *Var) {
0255     return InitializedEntity(Var);
0256   }
0257 
0258   /// Create the initialization entity for a parameter.
0259   static InitializedEntity InitializeParameter(ASTContext &Context,
0260                                                ParmVarDecl *Parm) {
0261     return InitializeParameter(Context, Parm, Parm->getType());
0262   }
0263 
0264   /// Create the initialization entity for a parameter, but use
0265   /// another type.
0266   static InitializedEntity
0267   InitializeParameter(ASTContext &Context, ParmVarDecl *Parm, QualType Type) {
0268     bool Consumed = (Context.getLangOpts().ObjCAutoRefCount &&
0269                      Parm->hasAttr<NSConsumedAttr>());
0270 
0271     InitializedEntity Entity;
0272     Entity.Kind = EK_Parameter;
0273     Entity.Type =
0274       Context.getVariableArrayDecayedType(Type.getUnqualifiedType());
0275     Entity.Parent = nullptr;
0276     Entity.Parameter = {Parm, Consumed};
0277     return Entity;
0278   }
0279 
0280   /// Create the initialization entity for a parameter that is
0281   /// only known by its type.
0282   static InitializedEntity InitializeParameter(ASTContext &Context,
0283                                                QualType Type,
0284                                                bool Consumed) {
0285     InitializedEntity Entity;
0286     Entity.Kind = EK_Parameter;
0287     Entity.Type = Context.getVariableArrayDecayedType(Type);
0288     Entity.Parent = nullptr;
0289     Entity.Parameter = {nullptr, Consumed};
0290     return Entity;
0291   }
0292 
0293   /// Create the initialization entity for a template parameter.
0294   static InitializedEntity
0295   InitializeTemplateParameter(QualType T, NonTypeTemplateParmDecl *Param) {
0296     InitializedEntity Entity;
0297     Entity.Kind = EK_TemplateParameter;
0298     Entity.Type = T;
0299     Entity.Parent = nullptr;
0300     Entity.Variable = {Param, false, false};
0301     return Entity;
0302   }
0303 
0304   /// Create the initialization entity for the result of a function.
0305   static InitializedEntity InitializeResult(SourceLocation ReturnLoc,
0306                                             QualType Type) {
0307     return InitializedEntity(EK_Result, ReturnLoc, Type);
0308   }
0309 
0310   static InitializedEntity InitializeStmtExprResult(SourceLocation ReturnLoc,
0311                                             QualType Type) {
0312     return InitializedEntity(EK_StmtExprResult, ReturnLoc, Type);
0313   }
0314 
0315   static InitializedEntity InitializeBlock(SourceLocation BlockVarLoc,
0316                                            QualType Type) {
0317     return InitializedEntity(EK_BlockElement, BlockVarLoc, Type);
0318   }
0319 
0320   static InitializedEntity InitializeLambdaToBlock(SourceLocation BlockVarLoc,
0321                                                    QualType Type) {
0322     return InitializedEntity(EK_LambdaToBlockConversionBlockElement,
0323                              BlockVarLoc, Type);
0324   }
0325 
0326   /// Create the initialization entity for an exception object.
0327   static InitializedEntity InitializeException(SourceLocation ThrowLoc,
0328                                                QualType Type) {
0329     return InitializedEntity(EK_Exception, ThrowLoc, Type);
0330   }
0331 
0332   /// Create the initialization entity for an object allocated via new.
0333   static InitializedEntity InitializeNew(SourceLocation NewLoc, QualType Type) {
0334     return InitializedEntity(EK_New, NewLoc, Type);
0335   }
0336 
0337   /// Create the initialization entity for a temporary.
0338   static InitializedEntity InitializeTemporary(QualType Type) {
0339     return InitializeTemporary(nullptr, Type);
0340   }
0341 
0342   /// Create the initialization entity for a temporary.
0343   static InitializedEntity InitializeTemporary(ASTContext &Context,
0344                                                TypeSourceInfo *TypeInfo) {
0345     QualType Type = TypeInfo->getType();
0346     if (Context.getLangOpts().OpenCLCPlusPlus) {
0347       assert(!Type.hasAddressSpace() && "Temporary already has address space!");
0348       Type = Context.getAddrSpaceQualType(Type, LangAS::opencl_private);
0349     }
0350 
0351     return InitializeTemporary(TypeInfo, Type);
0352   }
0353 
0354   /// Create the initialization entity for a temporary.
0355   static InitializedEntity InitializeTemporary(TypeSourceInfo *TypeInfo,
0356                                                QualType Type) {
0357     InitializedEntity Result(EK_Temporary, SourceLocation(), Type);
0358     Result.TypeInfo = TypeInfo;
0359     return Result;
0360   }
0361 
0362   /// Create the initialization entity for a related result.
0363   static InitializedEntity InitializeRelatedResult(ObjCMethodDecl *MD,
0364                                                    QualType Type) {
0365     InitializedEntity Result(EK_RelatedResult, SourceLocation(), Type);
0366     Result.MethodDecl = MD;
0367     return Result;
0368   }
0369 
0370   /// Create the initialization entity for a base class subobject.
0371   static InitializedEntity
0372   InitializeBase(ASTContext &Context, const CXXBaseSpecifier *Base,
0373                  bool IsInheritedVirtualBase,
0374                  const InitializedEntity *Parent = nullptr);
0375 
0376   /// Create the initialization entity for a delegated constructor.
0377   static InitializedEntity InitializeDelegation(QualType Type) {
0378     return InitializedEntity(EK_Delegating, SourceLocation(), Type);
0379   }
0380 
0381   /// Create the initialization entity for a member subobject.
0382   static InitializedEntity
0383   InitializeMember(FieldDecl *Member,
0384                    const InitializedEntity *Parent = nullptr,
0385                    bool Implicit = false) {
0386     return InitializedEntity(Member, Parent, Implicit, false);
0387   }
0388 
0389   /// Create the initialization entity for a member subobject.
0390   static InitializedEntity
0391   InitializeMember(IndirectFieldDecl *Member,
0392                    const InitializedEntity *Parent = nullptr,
0393                    bool Implicit = false) {
0394     return InitializedEntity(Member->getAnonField(), Parent, Implicit, false);
0395   }
0396 
0397   /// Create the initialization entity for a member subobject initialized via
0398   /// parenthesized aggregate init.
0399   static InitializedEntity InitializeMemberFromParenAggInit(FieldDecl *Member) {
0400     return InitializedEntity(Member, /*Parent=*/nullptr, /*Implicit=*/false,
0401                              /*DefaultMemberInit=*/false,
0402                              /*IsParenAggInit=*/true);
0403   }
0404 
0405   /// Create the initialization entity for a default member initializer.
0406   static InitializedEntity
0407   InitializeMemberFromDefaultMemberInitializer(FieldDecl *Member) {
0408     return InitializedEntity(Member, nullptr, false, true);
0409   }
0410 
0411   /// Create the initialization entity for an array element.
0412   static InitializedEntity InitializeElement(ASTContext &Context,
0413                                              unsigned Index,
0414                                              const InitializedEntity &Parent) {
0415     return InitializedEntity(Context, Index, Parent);
0416   }
0417 
0418   /// Create the initialization entity for a structured binding.
0419   static InitializedEntity InitializeBinding(VarDecl *Binding) {
0420     return InitializedEntity(Binding, EK_Binding);
0421   }
0422 
0423   /// Create the initialization entity for a lambda capture.
0424   ///
0425   /// \p VarID The name of the entity being captured, or nullptr for 'this'.
0426   static InitializedEntity InitializeLambdaCapture(IdentifierInfo *VarID,
0427                                                    QualType FieldType,
0428                                                    SourceLocation Loc) {
0429     return InitializedEntity(VarID, FieldType, Loc);
0430   }
0431 
0432   /// Create the entity for a compound literal initializer.
0433   static InitializedEntity InitializeCompoundLiteralInit(TypeSourceInfo *TSI) {
0434     InitializedEntity Result(EK_CompoundLiteralInit, SourceLocation(),
0435                              TSI->getType());
0436     Result.TypeInfo = TSI;
0437     return Result;
0438   }
0439 
0440   /// Determine the kind of initialization.
0441   EntityKind getKind() const { return Kind; }
0442 
0443   /// Retrieve the parent of the entity being initialized, when
0444   /// the initialization itself is occurring within the context of a
0445   /// larger initialization.
0446   const InitializedEntity *getParent() const { return Parent; }
0447 
0448   /// Retrieve type being initialized.
0449   QualType getType() const { return Type; }
0450 
0451   /// Retrieve complete type-source information for the object being
0452   /// constructed, if known.
0453   TypeSourceInfo *getTypeSourceInfo() const {
0454     if (Kind == EK_Temporary || Kind == EK_CompoundLiteralInit)
0455       return TypeInfo;
0456 
0457     return nullptr;
0458   }
0459 
0460   /// Retrieve the name of the entity being initialized.
0461   DeclarationName getName() const;
0462 
0463   /// Retrieve the variable, parameter, or field being
0464   /// initialized.
0465   ValueDecl *getDecl() const;
0466 
0467   /// Retrieve the ObjectiveC method being initialized.
0468   ObjCMethodDecl *getMethodDecl() const { return MethodDecl; }
0469 
0470   /// Determine whether this initialization allows the named return
0471   /// value optimization, which also applies to thrown objects.
0472   bool allowsNRVO() const;
0473 
0474   bool isParameterKind() const {
0475     return (getKind() == EK_Parameter  ||
0476             getKind() == EK_Parameter_CF_Audited);
0477   }
0478 
0479   bool isParamOrTemplateParamKind() const {
0480     return isParameterKind() || getKind() == EK_TemplateParameter;
0481   }
0482 
0483   /// Determine whether this initialization consumes the
0484   /// parameter.
0485   bool isParameterConsumed() const {
0486     assert(isParameterKind() && "Not a parameter");
0487     return Parameter.getInt();
0488   }
0489 
0490   /// Retrieve the base specifier.
0491   const CXXBaseSpecifier *getBaseSpecifier() const {
0492     assert(getKind() == EK_Base && "Not a base specifier");
0493     return Base.getPointer();
0494   }
0495 
0496   /// Return whether the base is an inherited virtual base.
0497   bool isInheritedVirtualBase() const {
0498     assert(getKind() == EK_Base && "Not a base specifier");
0499     return Base.getInt();
0500   }
0501 
0502   /// Determine whether this is an array new with an unknown bound.
0503   bool isVariableLengthArrayNew() const {
0504     return getKind() == EK_New && isa_and_nonnull<IncompleteArrayType>(
0505                                       getType()->getAsArrayTypeUnsafe());
0506   }
0507 
0508   /// Is this the implicit initialization of a member of a class from
0509   /// a defaulted constructor?
0510   bool isImplicitMemberInitializer() const {
0511     return getKind() == EK_Member && Variable.IsImplicitFieldInit;
0512   }
0513 
0514   /// Is this the default member initializer of a member (specified inside
0515   /// the class definition)?
0516   bool isDefaultMemberInitializer() const {
0517     return getKind() == EK_Member && Variable.IsDefaultMemberInit;
0518   }
0519 
0520   /// Determine the location of the 'return' keyword when initializing
0521   /// the result of a function call.
0522   SourceLocation getReturnLoc() const {
0523     assert(getKind() == EK_Result && "No 'return' location!");
0524     return LocAndNRVO.Location;
0525   }
0526 
0527   /// Determine the location of the 'throw' keyword when initializing
0528   /// an exception object.
0529   SourceLocation getThrowLoc() const {
0530     assert(getKind() == EK_Exception && "No 'throw' location!");
0531     return LocAndNRVO.Location;
0532   }
0533 
0534   /// If this is an array, vector, or complex number element, get the
0535   /// element's index.
0536   unsigned getElementIndex() const {
0537     assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
0538            getKind() == EK_ComplexElement);
0539     return Index;
0540   }
0541 
0542   /// If this is already the initializer for an array or vector
0543   /// element, sets the element index.
0544   void setElementIndex(unsigned Index) {
0545     assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
0546            getKind() == EK_ComplexElement);
0547     this->Index = Index;
0548   }
0549 
0550   /// For a lambda capture, return the capture's name.
0551   StringRef getCapturedVarName() const {
0552     assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
0553     return Capture.VarID ? Capture.VarID->getName() : "this";
0554   }
0555 
0556   /// Determine the location of the capture when initializing
0557   /// field from a captured variable in a lambda.
0558   SourceLocation getCaptureLoc() const {
0559     assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
0560     return Capture.Location;
0561   }
0562 
0563   void setParameterCFAudited() {
0564     Kind = EK_Parameter_CF_Audited;
0565   }
0566 
0567   unsigned allocateManglingNumber() const { return ++ManglingNumber; }
0568 
0569   /// Dump a representation of the initialized entity to standard error,
0570   /// for debugging purposes.
0571   void dump() const;
0572 
0573 private:
0574   unsigned dumpImpl(raw_ostream &OS) const;
0575 };
0576 
0577 /// Describes the kind of initialization being performed, along with
0578 /// location information for tokens related to the initialization (equal sign,
0579 /// parentheses).
0580 class InitializationKind {
0581 public:
0582   /// The kind of initialization being performed.
0583   enum InitKind {
0584     /// Direct initialization
0585     IK_Direct,
0586 
0587     /// Direct list-initialization
0588     IK_DirectList,
0589 
0590     /// Copy initialization
0591     IK_Copy,
0592 
0593     /// Default initialization
0594     IK_Default,
0595 
0596     /// Value initialization
0597     IK_Value
0598   };
0599 
0600 private:
0601   /// The context of the initialization.
0602   enum InitContext {
0603     /// Normal context
0604     IC_Normal,
0605 
0606     /// Normal context, but allows explicit conversion functions
0607     IC_ExplicitConvs,
0608 
0609     /// Implicit context (value initialization)
0610     IC_Implicit,
0611 
0612     /// Static cast context
0613     IC_StaticCast,
0614 
0615     /// C-style cast context
0616     IC_CStyleCast,
0617 
0618     /// Functional cast context
0619     IC_FunctionalCast
0620   };
0621 
0622   /// The kind of initialization being performed.
0623   InitKind Kind : 8;
0624 
0625   /// The context of the initialization.
0626   InitContext Context : 8;
0627 
0628   /// The source locations involved in the initialization.
0629   SourceLocation Locations[3];
0630 
0631   InitializationKind(InitKind Kind, InitContext Context, SourceLocation Loc1,
0632                      SourceLocation Loc2, SourceLocation Loc3)
0633       : Kind(Kind), Context(Context) {
0634     Locations[0] = Loc1;
0635     Locations[1] = Loc2;
0636     Locations[2] = Loc3;
0637   }
0638 
0639 public:
0640   /// Create a direct initialization.
0641   static InitializationKind CreateDirect(SourceLocation InitLoc,
0642                                          SourceLocation LParenLoc,
0643                                          SourceLocation RParenLoc) {
0644     return InitializationKind(IK_Direct, IC_Normal,
0645                               InitLoc, LParenLoc, RParenLoc);
0646   }
0647 
0648   static InitializationKind CreateDirectList(SourceLocation InitLoc) {
0649     return InitializationKind(IK_DirectList, IC_Normal, InitLoc, InitLoc,
0650                               InitLoc);
0651   }
0652 
0653   static InitializationKind CreateDirectList(SourceLocation InitLoc,
0654                                              SourceLocation LBraceLoc,
0655                                              SourceLocation RBraceLoc) {
0656     return InitializationKind(IK_DirectList, IC_Normal, InitLoc, LBraceLoc,
0657                               RBraceLoc);
0658   }
0659 
0660   /// Create a direct initialization due to a cast that isn't a C-style
0661   /// or functional cast.
0662   static InitializationKind CreateCast(SourceRange TypeRange) {
0663     return InitializationKind(IK_Direct, IC_StaticCast, TypeRange.getBegin(),
0664                               TypeRange.getBegin(), TypeRange.getEnd());
0665   }
0666 
0667   /// Create a direct initialization for a C-style cast.
0668   static InitializationKind CreateCStyleCast(SourceLocation StartLoc,
0669                                              SourceRange TypeRange,
0670                                              bool InitList) {
0671     // C++ cast syntax doesn't permit init lists, but C compound literals are
0672     // exactly that.
0673     return InitializationKind(InitList ? IK_DirectList : IK_Direct,
0674                               IC_CStyleCast, StartLoc, TypeRange.getBegin(),
0675                               TypeRange.getEnd());
0676   }
0677 
0678   /// Create a direct initialization for a functional cast.
0679   static InitializationKind CreateFunctionalCast(SourceRange TypeRange,
0680                                                  bool InitList) {
0681     return InitializationKind(InitList ? IK_DirectList : IK_Direct,
0682                               IC_FunctionalCast, TypeRange.getBegin(),
0683                               TypeRange.getBegin(), TypeRange.getEnd());
0684   }
0685 
0686   /// Create a copy initialization.
0687   static InitializationKind CreateCopy(SourceLocation InitLoc,
0688                                        SourceLocation EqualLoc,
0689                                        bool AllowExplicitConvs = false) {
0690     return InitializationKind(IK_Copy,
0691                               AllowExplicitConvs? IC_ExplicitConvs : IC_Normal,
0692                               InitLoc, EqualLoc, EqualLoc);
0693   }
0694 
0695   /// Create a default initialization.
0696   static InitializationKind CreateDefault(SourceLocation InitLoc) {
0697     return InitializationKind(IK_Default, IC_Normal, InitLoc, InitLoc, InitLoc);
0698   }
0699 
0700   /// Create a value initialization.
0701   static InitializationKind CreateValue(SourceLocation InitLoc,
0702                                         SourceLocation LParenLoc,
0703                                         SourceLocation RParenLoc,
0704                                         bool isImplicit = false) {
0705     return InitializationKind(IK_Value, isImplicit ? IC_Implicit : IC_Normal,
0706                               InitLoc, LParenLoc, RParenLoc);
0707   }
0708 
0709   /// Create an initialization from an initializer (which, for direct
0710   /// initialization from a parenthesized list, will be a ParenListExpr).
0711   static InitializationKind CreateForInit(SourceLocation Loc, bool DirectInit,
0712                                           Expr *Init) {
0713     if (!Init) return CreateDefault(Loc);
0714     if (!DirectInit)
0715       return CreateCopy(Loc, Init->getBeginLoc());
0716     if (isa<InitListExpr>(Init))
0717       return CreateDirectList(Loc, Init->getBeginLoc(), Init->getEndLoc());
0718     return CreateDirect(Loc, Init->getBeginLoc(), Init->getEndLoc());
0719   }
0720 
0721   /// Determine the initialization kind.
0722   InitKind getKind() const {
0723     return Kind;
0724   }
0725 
0726   /// Determine whether this initialization is an explicit cast.
0727   bool isExplicitCast() const {
0728     return Context >= IC_StaticCast;
0729   }
0730 
0731   /// Determine whether this initialization is a static cast.
0732   bool isStaticCast() const { return Context == IC_StaticCast; }
0733 
0734   /// Determine whether this initialization is a C-style cast.
0735   bool isCStyleOrFunctionalCast() const {
0736     return Context >= IC_CStyleCast;
0737   }
0738 
0739   /// Determine whether this is a C-style cast.
0740   bool isCStyleCast() const {
0741     return Context == IC_CStyleCast;
0742   }
0743 
0744   /// Determine whether this is a functional-style cast.
0745   bool isFunctionalCast() const {
0746     return Context == IC_FunctionalCast;
0747   }
0748 
0749   /// Determine whether this initialization is an implicit
0750   /// value-initialization, e.g., as occurs during aggregate
0751   /// initialization.
0752   bool isImplicitValueInit() const { return Context == IC_Implicit; }
0753 
0754   /// Retrieve the location at which initialization is occurring.
0755   SourceLocation getLocation() const { return Locations[0]; }
0756 
0757   /// Retrieve the source range that covers the initialization.
0758   SourceRange getRange() const {
0759     return SourceRange(Locations[0], Locations[2]);
0760   }
0761 
0762   /// Retrieve the location of the equal sign for copy initialization
0763   /// (if present).
0764   SourceLocation getEqualLoc() const {
0765     assert(Kind == IK_Copy && "Only copy initialization has an '='");
0766     return Locations[1];
0767   }
0768 
0769   bool isCopyInit() const { return Kind == IK_Copy; }
0770 
0771   /// Retrieve whether this initialization allows the use of explicit
0772   ///        constructors.
0773   bool AllowExplicit() const { return !isCopyInit(); }
0774 
0775   /// Retrieve whether this initialization allows the use of explicit
0776   /// conversion functions when binding a reference. If the reference is the
0777   /// first parameter in a copy or move constructor, such conversions are
0778   /// permitted even though we are performing copy-initialization.
0779   bool allowExplicitConversionFunctionsInRefBinding() const {
0780     return !isCopyInit() || Context == IC_ExplicitConvs;
0781   }
0782 
0783   /// Determine whether this initialization has a source range containing the
0784   /// locations of open and closing parentheses or braces.
0785   bool hasParenOrBraceRange() const {
0786     return Kind == IK_Direct || Kind == IK_Value || Kind == IK_DirectList;
0787   }
0788 
0789   /// Retrieve the source range containing the locations of the open
0790   /// and closing parentheses or braces for value, direct, and direct list
0791   /// initializations.
0792   SourceRange getParenOrBraceRange() const {
0793     assert(hasParenOrBraceRange() && "Only direct, value, and direct-list "
0794                                      "initialization have parentheses or "
0795                                      "braces");
0796     return SourceRange(Locations[1], Locations[2]);
0797   }
0798 };
0799 
0800 /// Describes the sequence of initializations required to initialize
0801 /// a given object or reference with a set of arguments.
0802 class InitializationSequence {
0803 public:
0804   /// Describes the kind of initialization sequence computed.
0805   enum SequenceKind {
0806     /// A failed initialization sequence. The failure kind tells what
0807     /// happened.
0808     FailedSequence = 0,
0809 
0810     /// A dependent initialization, which could not be
0811     /// type-checked due to the presence of dependent types or
0812     /// dependently-typed expressions.
0813     DependentSequence,
0814 
0815     /// A normal sequence.
0816     NormalSequence
0817   };
0818 
0819   /// Describes the kind of a particular step in an initialization
0820   /// sequence.
0821   enum StepKind {
0822     /// Resolve the address of an overloaded function to a specific
0823     /// function declaration.
0824     SK_ResolveAddressOfOverloadedFunction,
0825 
0826     /// Perform a derived-to-base cast, producing an rvalue.
0827     SK_CastDerivedToBasePRValue,
0828 
0829     /// Perform a derived-to-base cast, producing an xvalue.
0830     SK_CastDerivedToBaseXValue,
0831 
0832     /// Perform a derived-to-base cast, producing an lvalue.
0833     SK_CastDerivedToBaseLValue,
0834 
0835     /// Reference binding to an lvalue.
0836     SK_BindReference,
0837 
0838     /// Reference binding to a temporary.
0839     SK_BindReferenceToTemporary,
0840 
0841     /// An optional copy of a temporary object to another
0842     /// temporary object, which is permitted (but not required) by
0843     /// C++98/03 but not C++0x.
0844     SK_ExtraneousCopyToTemporary,
0845 
0846     /// Direct-initialization from a reference-related object in the
0847     /// final stage of class copy-initialization.
0848     SK_FinalCopy,
0849 
0850     /// Perform a user-defined conversion, either via a conversion
0851     /// function or via a constructor.
0852     SK_UserConversion,
0853 
0854     /// Perform a qualification conversion, producing a prvalue.
0855     SK_QualificationConversionPRValue,
0856 
0857     /// Perform a qualification conversion, producing an xvalue.
0858     SK_QualificationConversionXValue,
0859 
0860     /// Perform a qualification conversion, producing an lvalue.
0861     SK_QualificationConversionLValue,
0862 
0863     /// Perform a function reference conversion, see [dcl.init.ref]p4.
0864     SK_FunctionReferenceConversion,
0865 
0866     /// Perform a conversion adding _Atomic to a type.
0867     SK_AtomicConversion,
0868 
0869     /// Perform an implicit conversion sequence.
0870     SK_ConversionSequence,
0871 
0872     /// Perform an implicit conversion sequence without narrowing.
0873     SK_ConversionSequenceNoNarrowing,
0874 
0875     /// Perform list-initialization without a constructor.
0876     SK_ListInitialization,
0877 
0878     /// Unwrap the single-element initializer list for a reference.
0879     SK_UnwrapInitList,
0880 
0881     /// Rewrap the single-element initializer list for a reference.
0882     SK_RewrapInitList,
0883 
0884     /// Perform initialization via a constructor.
0885     SK_ConstructorInitialization,
0886 
0887     /// Perform initialization via a constructor, taking arguments from
0888     /// a single InitListExpr.
0889     SK_ConstructorInitializationFromList,
0890 
0891     /// Zero-initialize the object
0892     SK_ZeroInitialization,
0893 
0894     /// C assignment
0895     SK_CAssignment,
0896 
0897     /// Initialization by string
0898     SK_StringInit,
0899 
0900     /// An initialization that "converts" an Objective-C object
0901     /// (not a point to an object) to another Objective-C object type.
0902     SK_ObjCObjectConversion,
0903 
0904     /// Array indexing for initialization by elementwise copy.
0905     SK_ArrayLoopIndex,
0906 
0907     /// Array initialization by elementwise copy.
0908     SK_ArrayLoopInit,
0909 
0910     /// Array initialization (from an array rvalue).
0911     SK_ArrayInit,
0912 
0913     /// Array initialization (from an array rvalue) as a GNU extension.
0914     SK_GNUArrayInit,
0915 
0916     /// Array initialization from a parenthesized initializer list.
0917     /// This is a GNU C++ extension.
0918     SK_ParenthesizedArrayInit,
0919 
0920     /// Pass an object by indirect copy-and-restore.
0921     SK_PassByIndirectCopyRestore,
0922 
0923     /// Pass an object by indirect restore.
0924     SK_PassByIndirectRestore,
0925 
0926     /// Produce an Objective-C object pointer.
0927     SK_ProduceObjCObject,
0928 
0929     /// Construct a std::initializer_list from an initializer list.
0930     SK_StdInitializerList,
0931 
0932     /// Perform initialization via a constructor taking a single
0933     /// std::initializer_list argument.
0934     SK_StdInitializerListConstructorCall,
0935 
0936     /// Initialize an OpenCL sampler from an integer.
0937     SK_OCLSamplerInit,
0938 
0939     /// Initialize an opaque OpenCL type (event_t, queue_t, etc.) with zero
0940     SK_OCLZeroOpaqueType,
0941 
0942     /// Initialize an aggreagate with parenthesized list of values.
0943     /// This is a C++20 feature.
0944     SK_ParenthesizedListInit
0945   };
0946 
0947   /// A single step in the initialization sequence.
0948   class Step {
0949   public:
0950     /// The kind of conversion or initialization step we are taking.
0951     StepKind Kind;
0952 
0953     // The type that results from this initialization.
0954     QualType Type;
0955 
0956     struct F {
0957       bool HadMultipleCandidates;
0958       FunctionDecl *Function;
0959       DeclAccessPair FoundDecl;
0960     };
0961 
0962     union {
0963       /// When Kind == SK_ResolvedOverloadedFunction or Kind ==
0964       /// SK_UserConversion, the function that the expression should be
0965       /// resolved to or the conversion function to call, respectively.
0966       /// When Kind == SK_ConstructorInitialization or SK_ListConstruction,
0967       /// the constructor to be called.
0968       ///
0969       /// Always a FunctionDecl, plus a Boolean flag telling if it was
0970       /// selected from an overloaded set having size greater than 1.
0971       /// For conversion decls, the naming class is the source type.
0972       /// For construct decls, the naming class is the target type.
0973       struct F Function;
0974 
0975       /// When Kind = SK_ConversionSequence, the implicit conversion
0976       /// sequence.
0977       ImplicitConversionSequence *ICS;
0978 
0979       /// When Kind = SK_RewrapInitList, the syntactic form of the
0980       /// wrapping list.
0981       InitListExpr *WrappingSyntacticList;
0982     };
0983 
0984     void Destroy();
0985   };
0986 
0987 private:
0988   /// The kind of initialization sequence computed.
0989   enum SequenceKind SequenceKind;
0990 
0991   /// Steps taken by this initialization.
0992   SmallVector<Step, 4> Steps;
0993 
0994 public:
0995   /// Describes why initialization failed.
0996   enum FailureKind {
0997     /// Too many initializers provided for a reference.
0998     FK_TooManyInitsForReference,
0999 
1000     /// Reference initialized from a parenthesized initializer list.
1001     FK_ParenthesizedListInitForReference,
1002 
1003     /// Array must be initialized with an initializer list.
1004     FK_ArrayNeedsInitList,
1005 
1006     /// Array must be initialized with an initializer list or a
1007     /// string literal.
1008     FK_ArrayNeedsInitListOrStringLiteral,
1009 
1010     /// Array must be initialized with an initializer list or a
1011     /// wide string literal.
1012     FK_ArrayNeedsInitListOrWideStringLiteral,
1013 
1014     /// Initializing a wide char array with narrow string literal.
1015     FK_NarrowStringIntoWideCharArray,
1016 
1017     /// Initializing char array with wide string literal.
1018     FK_WideStringIntoCharArray,
1019 
1020     /// Initializing wide char array with incompatible wide string
1021     /// literal.
1022     FK_IncompatWideStringIntoWideChar,
1023 
1024     /// Initializing char8_t array with plain string literal.
1025     FK_PlainStringIntoUTF8Char,
1026 
1027     /// Initializing char array with UTF-8 string literal.
1028     FK_UTF8StringIntoPlainChar,
1029 
1030     /// Array type mismatch.
1031     FK_ArrayTypeMismatch,
1032 
1033     /// Non-constant array initializer
1034     FK_NonConstantArrayInit,
1035 
1036     /// Cannot resolve the address of an overloaded function.
1037     FK_AddressOfOverloadFailed,
1038 
1039     /// Overloading due to reference initialization failed.
1040     FK_ReferenceInitOverloadFailed,
1041 
1042     /// Non-const lvalue reference binding to a temporary.
1043     FK_NonConstLValueReferenceBindingToTemporary,
1044 
1045     /// Non-const lvalue reference binding to a bit-field.
1046     FK_NonConstLValueReferenceBindingToBitfield,
1047 
1048     /// Non-const lvalue reference binding to a vector element.
1049     FK_NonConstLValueReferenceBindingToVectorElement,
1050 
1051     /// Non-const lvalue reference binding to a matrix element.
1052     FK_NonConstLValueReferenceBindingToMatrixElement,
1053 
1054     /// Non-const lvalue reference binding to an lvalue of unrelated
1055     /// type.
1056     FK_NonConstLValueReferenceBindingToUnrelated,
1057 
1058     /// Rvalue reference binding to an lvalue.
1059     FK_RValueReferenceBindingToLValue,
1060 
1061     /// Reference binding drops qualifiers.
1062     FK_ReferenceInitDropsQualifiers,
1063 
1064     /// Reference with mismatching address space binding to temporary.
1065     FK_ReferenceAddrspaceMismatchTemporary,
1066 
1067     /// Reference binding failed.
1068     FK_ReferenceInitFailed,
1069 
1070     /// Implicit conversion failed.
1071     FK_ConversionFailed,
1072 
1073     /// Implicit conversion failed.
1074     FK_ConversionFromPropertyFailed,
1075 
1076     /// Too many initializers for scalar
1077     FK_TooManyInitsForScalar,
1078 
1079     /// Scalar initialized from a parenthesized initializer list.
1080     FK_ParenthesizedListInitForScalar,
1081 
1082     /// Reference initialization from an initializer list
1083     FK_ReferenceBindingToInitList,
1084 
1085     /// Initialization of some unused destination type with an
1086     /// initializer list.
1087     FK_InitListBadDestinationType,
1088 
1089     /// Overloading for a user-defined conversion failed.
1090     FK_UserConversionOverloadFailed,
1091 
1092     /// Overloading for initialization by constructor failed.
1093     FK_ConstructorOverloadFailed,
1094 
1095     /// Overloading for list-initialization by constructor failed.
1096     FK_ListConstructorOverloadFailed,
1097 
1098     /// Default-initialization of a 'const' object.
1099     FK_DefaultInitOfConst,
1100 
1101     /// Initialization of an incomplete type.
1102     FK_Incomplete,
1103 
1104     /// Variable-length array must not have an initializer.
1105     FK_VariableLengthArrayHasInitializer,
1106 
1107     /// List initialization failed at some point.
1108     FK_ListInitializationFailed,
1109 
1110     /// Initializer has a placeholder type which cannot be
1111     /// resolved by initialization.
1112     FK_PlaceholderType,
1113 
1114     /// Trying to take the address of a function that doesn't support
1115     /// having its address taken.
1116     FK_AddressOfUnaddressableFunction,
1117 
1118     /// List-copy-initialization chose an explicit constructor.
1119     FK_ExplicitConstructor,
1120 
1121     /// Parenthesized list initialization failed at some point.
1122     /// This is a C++20 feature.
1123     FK_ParenthesizedListInitFailed,
1124 
1125     // A designated initializer was provided for a non-aggregate type.
1126     FK_DesignatedInitForNonAggregate,
1127   };
1128 
1129 private:
1130   /// The reason why initialization failed.
1131   FailureKind Failure;
1132 
1133   /// The failed result of overload resolution.
1134   OverloadingResult FailedOverloadResult;
1135 
1136   /// The candidate set created when initialization failed.
1137   OverloadCandidateSet FailedCandidateSet;
1138 
1139   /// The incomplete type that caused a failure.
1140   QualType FailedIncompleteType;
1141 
1142   /// The fixit that needs to be applied to make this initialization
1143   /// succeed.
1144   std::string ZeroInitializationFixit;
1145   SourceLocation ZeroInitializationFixitLoc;
1146 
1147 public:
1148   /// Call for initializations are invalid but that would be valid
1149   /// zero initialzations if Fixit was applied.
1150   void SetZeroInitializationFixit(const std::string& Fixit, SourceLocation L) {
1151     ZeroInitializationFixit = Fixit;
1152     ZeroInitializationFixitLoc = L;
1153   }
1154 
1155 private:
1156   /// Prints a follow-up note that highlights the location of
1157   /// the initialized entity, if it's remote.
1158   void PrintInitLocationNote(Sema &S, const InitializedEntity &Entity);
1159 
1160 public:
1161   /// Try to perform initialization of the given entity, creating a
1162   /// record of the steps required to perform the initialization.
1163   ///
1164   /// The generated initialization sequence will either contain enough
1165   /// information to diagnose
1166   ///
1167   /// \param S the semantic analysis object.
1168   ///
1169   /// \param Entity the entity being initialized.
1170   ///
1171   /// \param Kind the kind of initialization being performed.
1172   ///
1173   /// \param Args the argument(s) provided for initialization.
1174   ///
1175   /// \param TopLevelOfInitList true if we are initializing from an expression
1176   ///        at the top level inside an initializer list. This disallows
1177   ///        narrowing conversions in C++11 onwards.
1178   /// \param TreatUnavailableAsInvalid true if we want to treat unavailable
1179   ///        as invalid.
1180   InitializationSequence(Sema &S,
1181                          const InitializedEntity &Entity,
1182                          const InitializationKind &Kind,
1183                          MultiExprArg Args,
1184                          bool TopLevelOfInitList = false,
1185                          bool TreatUnavailableAsInvalid = true);
1186   void InitializeFrom(Sema &S, const InitializedEntity &Entity,
1187                       const InitializationKind &Kind, MultiExprArg Args,
1188                       bool TopLevelOfInitList, bool TreatUnavailableAsInvalid);
1189 
1190   ~InitializationSequence();
1191 
1192   /// Perform the actual initialization of the given entity based on
1193   /// the computed initialization sequence.
1194   ///
1195   /// \param S the semantic analysis object.
1196   ///
1197   /// \param Entity the entity being initialized.
1198   ///
1199   /// \param Kind the kind of initialization being performed.
1200   ///
1201   /// \param Args the argument(s) provided for initialization, ownership of
1202   /// which is transferred into the routine.
1203   ///
1204   /// \param ResultType if non-NULL, will be set to the type of the
1205   /// initialized object, which is the type of the declaration in most
1206   /// cases. However, when the initialized object is a variable of
1207   /// incomplete array type and the initializer is an initializer
1208   /// list, this type will be set to the completed array type.
1209   ///
1210   /// \returns an expression that performs the actual object initialization, if
1211   /// the initialization is well-formed. Otherwise, emits diagnostics
1212   /// and returns an invalid expression.
1213   ExprResult Perform(Sema &S,
1214                      const InitializedEntity &Entity,
1215                      const InitializationKind &Kind,
1216                      MultiExprArg Args,
1217                      QualType *ResultType = nullptr);
1218 
1219   /// Diagnose an potentially-invalid initialization sequence.
1220   ///
1221   /// \returns true if the initialization sequence was ill-formed,
1222   /// false otherwise.
1223   bool Diagnose(Sema &S,
1224                 const InitializedEntity &Entity,
1225                 const InitializationKind &Kind,
1226                 ArrayRef<Expr *> Args);
1227 
1228   /// Determine the kind of initialization sequence computed.
1229   enum SequenceKind getKind() const { return SequenceKind; }
1230 
1231   /// Set the kind of sequence computed.
1232   void setSequenceKind(enum SequenceKind SK) { SequenceKind = SK; }
1233 
1234   /// Determine whether the initialization sequence is valid.
1235   explicit operator bool() const { return !Failed(); }
1236 
1237   /// Determine whether the initialization sequence is invalid.
1238   bool Failed() const { return SequenceKind == FailedSequence; }
1239 
1240   using step_iterator = SmallVectorImpl<Step>::const_iterator;
1241 
1242   step_iterator step_begin() const { return Steps.begin(); }
1243   step_iterator step_end()   const { return Steps.end(); }
1244 
1245   using step_range = llvm::iterator_range<step_iterator>;
1246 
1247   step_range steps() const { return {step_begin(), step_end()}; }
1248 
1249   /// Determine whether this initialization is a direct reference
1250   /// binding (C++ [dcl.init.ref]).
1251   bool isDirectReferenceBinding() const;
1252 
1253   /// Determine whether this initialization failed due to an ambiguity.
1254   bool isAmbiguous() const;
1255 
1256   /// Determine whether this initialization is direct call to a
1257   /// constructor.
1258   bool isConstructorInitialization() const;
1259 
1260   /// Add a new step in the initialization that resolves the address
1261   /// of an overloaded function to a specific function declaration.
1262   ///
1263   /// \param Function the function to which the overloaded function reference
1264   /// resolves.
1265   void AddAddressOverloadResolutionStep(FunctionDecl *Function,
1266                                         DeclAccessPair Found,
1267                                         bool HadMultipleCandidates);
1268 
1269   /// Add a new step in the initialization that performs a derived-to-
1270   /// base cast.
1271   ///
1272   /// \param BaseType the base type to which we will be casting.
1273   ///
1274   /// \param Category Indicates whether the result will be treated as an
1275   /// rvalue, an xvalue, or an lvalue.
1276   void AddDerivedToBaseCastStep(QualType BaseType,
1277                                 ExprValueKind Category);
1278 
1279   /// Add a new step binding a reference to an object.
1280   ///
1281   /// \param BindingTemporary True if we are binding a reference to a temporary
1282   /// object (thereby extending its lifetime); false if we are binding to an
1283   /// lvalue or an lvalue treated as an rvalue.
1284   void AddReferenceBindingStep(QualType T, bool BindingTemporary);
1285 
1286   /// Add a new step that makes an extraneous copy of the input
1287   /// to a temporary of the same class type.
1288   ///
1289   /// This extraneous copy only occurs during reference binding in
1290   /// C++98/03, where we are permitted (but not required) to introduce
1291   /// an extra copy. At a bare minimum, we must check that we could
1292   /// call the copy constructor, and produce a diagnostic if the copy
1293   /// constructor is inaccessible or no copy constructor matches.
1294   //
1295   /// \param T The type of the temporary being created.
1296   void AddExtraneousCopyToTemporary(QualType T);
1297 
1298   /// Add a new step that makes a copy of the input to an object of
1299   /// the given type, as the final step in class copy-initialization.
1300   void AddFinalCopy(QualType T);
1301 
1302   /// Add a new step invoking a conversion function, which is either
1303   /// a constructor or a conversion function.
1304   void AddUserConversionStep(FunctionDecl *Function,
1305                              DeclAccessPair FoundDecl,
1306                              QualType T,
1307                              bool HadMultipleCandidates);
1308 
1309   /// Add a new step that performs a qualification conversion to the
1310   /// given type.
1311   void AddQualificationConversionStep(QualType Ty,
1312                                      ExprValueKind Category);
1313 
1314   /// Add a new step that performs a function reference conversion to the
1315   /// given type.
1316   void AddFunctionReferenceConversionStep(QualType Ty);
1317 
1318   /// Add a new step that performs conversion from non-atomic to atomic
1319   /// type.
1320   void AddAtomicConversionStep(QualType Ty);
1321 
1322   /// Add a new step that applies an implicit conversion sequence.
1323   void AddConversionSequenceStep(const ImplicitConversionSequence &ICS,
1324                                  QualType T, bool TopLevelOfInitList = false);
1325 
1326   /// Add a list-initialization step.
1327   void AddListInitializationStep(QualType T);
1328 
1329   /// Add a constructor-initialization step.
1330   ///
1331   /// \param FromInitList The constructor call is syntactically an initializer
1332   /// list.
1333   /// \param AsInitList The constructor is called as an init list constructor.
1334   void AddConstructorInitializationStep(DeclAccessPair FoundDecl,
1335                                         CXXConstructorDecl *Constructor,
1336                                         QualType T,
1337                                         bool HadMultipleCandidates,
1338                                         bool FromInitList, bool AsInitList);
1339 
1340   /// Add a zero-initialization step.
1341   void AddZeroInitializationStep(QualType T);
1342 
1343   /// Add a C assignment step.
1344   //
1345   // FIXME: It isn't clear whether this should ever be needed;
1346   // ideally, we would handle everything needed in C in the common
1347   // path. However, that isn't the case yet.
1348   void AddCAssignmentStep(QualType T);
1349 
1350   /// Add a string init step.
1351   void AddStringInitStep(QualType T);
1352 
1353   /// Add an Objective-C object conversion step, which is
1354   /// always a no-op.
1355   void AddObjCObjectConversionStep(QualType T);
1356 
1357   /// Add an array initialization loop step.
1358   void AddArrayInitLoopStep(QualType T, QualType EltTy);
1359 
1360   /// Add an array initialization step.
1361   void AddArrayInitStep(QualType T, bool IsGNUExtension);
1362 
1363   /// Add a parenthesized array initialization step.
1364   void AddParenthesizedArrayInitStep(QualType T);
1365 
1366   /// Add a step to pass an object by indirect copy-restore.
1367   void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy);
1368 
1369   /// Add a step to "produce" an Objective-C object (by
1370   /// retaining it).
1371   void AddProduceObjCObjectStep(QualType T);
1372 
1373   /// Add a step to construct a std::initializer_list object from an
1374   /// initializer list.
1375   void AddStdInitializerListConstructionStep(QualType T);
1376 
1377   /// Add a step to initialize an OpenCL sampler from an integer
1378   /// constant.
1379   void AddOCLSamplerInitStep(QualType T);
1380 
1381   /// Add a step to initialzie an OpenCL opaque type (event_t, queue_t, etc.)
1382   /// from a zero constant.
1383   void AddOCLZeroOpaqueTypeStep(QualType T);
1384 
1385   void AddParenthesizedListInitStep(QualType T);
1386 
1387   /// Only used when initializing structured bindings from an array with
1388   /// direct-list-initialization. Unwrap the initializer list to get the array
1389   /// for array copy.
1390   void AddUnwrapInitListInitStep(InitListExpr *Syntactic);
1391 
1392   /// Add steps to unwrap a initializer list for a reference around a
1393   /// single element and rewrap it at the end.
1394   void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
1395 
1396   /// Note that this initialization sequence failed.
1397   void SetFailed(FailureKind Failure) {
1398     SequenceKind = FailedSequence;
1399     this->Failure = Failure;
1400     assert((Failure != FK_Incomplete || !FailedIncompleteType.isNull()) &&
1401            "Incomplete type failure requires a type!");
1402   }
1403 
1404   /// Note that this initialization sequence failed due to failed
1405   /// overload resolution.
1406   void SetOverloadFailure(FailureKind Failure, OverloadingResult Result);
1407 
1408   /// Retrieve a reference to the candidate set when overload
1409   /// resolution fails.
1410   OverloadCandidateSet &getFailedCandidateSet() {
1411     return FailedCandidateSet;
1412   }
1413 
1414   /// Get the overloading result, for when the initialization
1415   /// sequence failed due to a bad overload.
1416   OverloadingResult getFailedOverloadResult() const {
1417     return FailedOverloadResult;
1418   }
1419 
1420   /// Note that this initialization sequence failed due to an
1421   /// incomplete type.
1422   void setIncompleteTypeFailure(QualType IncompleteType) {
1423     FailedIncompleteType = IncompleteType;
1424     SetFailed(FK_Incomplete);
1425   }
1426 
1427   /// Determine why initialization failed.
1428   FailureKind getFailureKind() const {
1429     assert(Failed() && "Not an initialization failure!");
1430     return Failure;
1431   }
1432 
1433   /// Dump a representation of this initialization sequence to
1434   /// the given stream, for debugging purposes.
1435   void dump(raw_ostream &OS) const;
1436 
1437   /// Dump a representation of this initialization sequence to
1438   /// standard error, for debugging purposes.
1439   void dump() const;
1440 };
1441 
1442 } // namespace clang
1443 
1444 #endif // LLVM_CLANG_SEMA_INITIALIZATION_H