1ecfcd5655758955d8958dc2a7a7b2c8eff2395b7Sebastian Redl//===--- Initialization.h - Semantic Analysis for Initializers --*- C++ -*-===//
220093b4bf698f292c664676987541d5103b65b15Douglas Gregor//
320093b4bf698f292c664676987541d5103b65b15Douglas Gregor//                     The LLVM Compiler Infrastructure
420093b4bf698f292c664676987541d5103b65b15Douglas Gregor//
520093b4bf698f292c664676987541d5103b65b15Douglas Gregor// This file is distributed under the University of Illinois Open Source
620093b4bf698f292c664676987541d5103b65b15Douglas Gregor// License. See LICENSE.TXT for details.
720093b4bf698f292c664676987541d5103b65b15Douglas Gregor//
820093b4bf698f292c664676987541d5103b65b15Douglas Gregor//===----------------------------------------------------------------------===//
920093b4bf698f292c664676987541d5103b65b15Douglas Gregor//
1020093b4bf698f292c664676987541d5103b65b15Douglas Gregor// This file provides supporting data types for initialization of objects.
1120093b4bf698f292c664676987541d5103b65b15Douglas Gregor//
1220093b4bf698f292c664676987541d5103b65b15Douglas Gregor//===----------------------------------------------------------------------===//
13e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#ifndef LLVM_CLANG_SEMA_INITIALIZATION_H
14e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#define LLVM_CLANG_SEMA_INITIALIZATION_H
1520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
16120d63cd4465230c2cd56508c7cd8e0ad00848e7John McCall#include "clang/Sema/Ownership.h"
17e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#include "clang/Sema/Overload.h"
18471c8b49982d1132f30b0b0da27fef94fd6e4f67Benjamin Kramer#include "clang/AST/ASTContext.h"
19d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor#include "clang/AST/Type.h"
20b13b737a2450167c82e148590e8019b839ce6b98John McCall#include "clang/AST/UnresolvedSet.h"
2120093b4bf698f292c664676987541d5103b65b15Douglas Gregor#include "clang/Basic/SourceLocation.h"
2220093b4bf698f292c664676987541d5103b65b15Douglas Gregor#include "llvm/ADT/PointerIntPair.h"
2320093b4bf698f292c664676987541d5103b65b15Douglas Gregor#include "llvm/ADT/SmallVector.h"
2420093b4bf698f292c664676987541d5103b65b15Douglas Gregor#include <cassert>
2520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
2620093b4bf698f292c664676987541d5103b65b15Douglas Gregornamespace clang {
2720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
2820093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass CXXBaseSpecifier;
2920093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass DeclaratorDecl;
3020093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass DeclaratorInfo;
3120093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass FieldDecl;
3220093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass FunctionDecl;
3320093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass ParmVarDecl;
3420093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass Sema;
3520093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass TypeLoc;
3620093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass VarDecl;
3720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
3820093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// \brief Describes an entity that is being initialized.
3920093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass InitializedEntity {
4020093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
4120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Specifies the kind of entity being initialized.
4220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum EntityKind {
4320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The entity being initialized is a variable.
4420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    EK_Variable,
4520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The entity being initialized is a function parameter.
4620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    EK_Parameter,
4720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The entity being initialized is the result of a function call.
4820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    EK_Result,
4920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The entity being initialized is an exception object that
5020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// is being thrown.
5120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    EK_Exception,
52a729bbb739ca97a8dc52b6b0495725590a0367dcAnders Carlsson    /// \brief The entity being initialized is a non-static data member
53a729bbb739ca97a8dc52b6b0495725590a0367dcAnders Carlsson    /// subobject.
54a729bbb739ca97a8dc52b6b0495725590a0367dcAnders Carlsson    EK_Member,
55a729bbb739ca97a8dc52b6b0495725590a0367dcAnders Carlsson    /// \brief The entity being initialized is an element of an array.
56a729bbb739ca97a8dc52b6b0495725590a0367dcAnders Carlsson    EK_ArrayElement,
5718ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    /// \brief The entity being initialized is an object (or array of
5818ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    /// objects) allocated via new.
5918ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    EK_New,
6020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The entity being initialized is a temporary object.
6120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    EK_Temporary,
6220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The entity being initialized is a base member subobject.
6320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    EK_Base,
644171766318a2564fbc9a739be0a2851f441c0d29Sean Hunt    /// \brief The initialization is being done by a delegating constructor.
65059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt    EK_Delegating,
66d3d824d45c32d457493e7cb79cc34a4761afb760Anders Carlsson    /// \brief The entity being initialized is an element of a vector.
67cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor    /// or vector.
68310b1c421665241d9b135c517d5031716d4a3221Fariborz Jahanian    EK_VectorElement,
69310b1c421665241d9b135c517d5031716d4a3221Fariborz Jahanian    /// \brief The entity being initialized is a field of block descriptor for
70310b1c421665241d9b135c517d5031716d4a3221Fariborz Jahanian    /// the copied-in c++ object.
710c706c29f20b6fa36759fa41333b9c3ec0bd2969Eli Friedman    EK_BlockElement,
720c706c29f20b6fa36759fa41333b9c3ec0bd2969Eli Friedman    /// \brief The entity being initialized is the real or imaginary part of a
730c706c29f20b6fa36759fa41333b9c3ec0bd2969Eli Friedman    /// complex number.
744773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    EK_ComplexElement,
754773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    /// \brief The entity being initialized is the field that captures a
764773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    /// variable in a lambda.
774773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    EK_LambdaCapture
7820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
7920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
8020093b4bf698f292c664676987541d5103b65b15Douglas Gregorprivate:
8120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The kind of entity being initialized.
8220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  EntityKind Kind;
8320093b4bf698f292c664676987541d5103b65b15Douglas Gregor
84cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief If non-NULL, the parent entity in which this
85cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// initialization occurs.
86cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  const InitializedEntity *Parent;
87cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
88d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor  /// \brief The type of the object or reference being initialized.
89d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor  QualType Type;
9020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
9120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  union {
924773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    /// \brief When Kind == EK_Variable, or EK_Member, the VarDecl or
93f85e193739c953358c865005855253af4f68a497John McCall    /// FieldDecl, respectively.
9420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    DeclaratorDecl *VariableOrMember;
95f85e193739c953358c865005855253af4f68a497John McCall
96f85e193739c953358c865005855253af4f68a497John McCall    /// \brief When Kind == EK_Parameter, the ParmVarDecl, with the
97f85e193739c953358c865005855253af4f68a497John McCall    /// low bit indicating whether the parameter is "consumed".
98f85e193739c953358c865005855253af4f68a497John McCall    uintptr_t Parameter;
9920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
100ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    /// \brief When Kind == EK_Temporary, the type source information for
101ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    /// the temporary.
102ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    TypeSourceInfo *TypeInfo;
103ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
1043c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor    struct {
1054773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor      /// \brief When Kind == EK_Result, EK_Exception, EK_New, the
1063c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor      /// location of the 'return', 'throw', or 'new' keyword,
1073c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor      /// respectively. When Kind == EK_Temporary, the location where
1083c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor      /// the temporary is being created.
1093c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor      unsigned Location;
1103c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor
1114926d832aa2f0af9d7c00633727d49e7967eb978Douglas Gregor      /// \brief Whether the entity being initialized may end up using the
1124926d832aa2f0af9d7c00633727d49e7967eb978Douglas Gregor      /// named return value optimization (NRVO).
1133c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor      bool NRVO;
1143c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor    } LocAndNRVO;
11520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
11620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief When Kind == EK_Base, the base specifier that provides the
117711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson    /// base class. The lower bit specifies whether the base is an inherited
118711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson    /// virtual base.
119711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson    uintptr_t Base;
120cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
1210c706c29f20b6fa36759fa41333b9c3ec0bd2969Eli Friedman    /// \brief When Kind == EK_ArrayElement, EK_VectorElement, or
1220c706c29f20b6fa36759fa41333b9c3ec0bd2969Eli Friedman    /// EK_ComplexElement, the index of the array or vector element being
1230c706c29f20b6fa36759fa41333b9c3ec0bd2969Eli Friedman    /// initialized.
124cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor    unsigned Index;
1254773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor
1264773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    struct {
1274773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor      /// \brief The variable being captured by an EK_LambdaCapture.
1284773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor      VarDecl *Var;
1294773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor
1304773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor      /// \brief The source location at which the capture occurs.
1314773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor      unsigned Location;
1324773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    } Capture;
13320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
13420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
13520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  InitializedEntity() { }
13620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
13720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for a variable.
13820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  InitializedEntity(VarDecl *Var)
139d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor    : Kind(EK_Variable), Parent(0), Type(Var->getType()),
140606f65665421d594458e1409b4413005fb521c25Francois Pichet      VariableOrMember(Var) { }
14120093b4bf698f292c664676987541d5103b65b15Douglas Gregor
142a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor  /// \brief Create the initialization entity for the result of a
143a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor  /// function, throwing an object, performing an explicit cast, or
144a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor  /// initializing a parameter for which there is no declaration.
1453c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor  InitializedEntity(EntityKind Kind, SourceLocation Loc, QualType Type,
1463c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor                    bool NRVO = false)
1473c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor    : Kind(Kind), Parent(0), Type(Type)
1483c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor  {
1493c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor    LocAndNRVO.Location = Loc.getRawEncoding();
1503c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor    LocAndNRVO.NRVO = NRVO;
1513c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor  }
15220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
15320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for a member subobject.
154cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent)
155d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor    : Kind(EK_Member), Parent(Parent), Type(Member->getType()),
156606f65665421d594458e1409b4413005fb521c25Francois Pichet      VariableOrMember(Member) { }
15720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
158cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief Create the initialization entity for an array element.
159cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  InitializedEntity(ASTContext &Context, unsigned Index,
160cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                    const InitializedEntity &Parent);
161cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
1624773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  /// \brief Create the initialization entity for a lambda capture.
1634773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  InitializedEntity(VarDecl *Var, FieldDecl *Field, SourceLocation Loc)
1644773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    : Kind(EK_LambdaCapture), Parent(0), Type(Field->getType())
1654773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  {
1664773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    Capture.Var = Var;
1674773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    Capture.Location = Loc.getRawEncoding();
1684773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  }
1694773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor
17020093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
17120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for a variable.
17220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializedEntity InitializeVariable(VarDecl *Var) {
17320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return InitializedEntity(Var);
17420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
17520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
17620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for a parameter.
177745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian  static InitializedEntity InitializeParameter(ASTContext &Context,
178745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian                                               ParmVarDecl *Parm) {
1794e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie    bool Consumed = (Context.getLangOpts().ObjCAutoRefCount &&
180f85e193739c953358c865005855253af4f68a497John McCall                     Parm->hasAttr<NSConsumedAttr>());
181f85e193739c953358c865005855253af4f68a497John McCall
182f85e193739c953358c865005855253af4f68a497John McCall    InitializedEntity Entity;
183f85e193739c953358c865005855253af4f68a497John McCall    Entity.Kind = EK_Parameter;
184f85e193739c953358c865005855253af4f68a497John McCall    Entity.Type = Context.getVariableArrayDecayedType(
185f85e193739c953358c865005855253af4f68a497John McCall                                       Parm->getType().getUnqualifiedType());
186f85e193739c953358c865005855253af4f68a497John McCall    Entity.Parent = 0;
18782d1cc06ea533267e24ffe8b5885062ca062b479John McCall    Entity.Parameter
18882d1cc06ea533267e24ffe8b5885062ca062b479John McCall      = (static_cast<uintptr_t>(Consumed) | reinterpret_cast<uintptr_t>(Parm));
189f85e193739c953358c865005855253af4f68a497John McCall    return Entity;
19020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
19120093b4bf698f292c664676987541d5103b65b15Douglas Gregor
192a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor  /// \brief Create the initialization entity for a parameter that is
193a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor  /// only known by its type.
194745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian  static InitializedEntity InitializeParameter(ASTContext &Context,
195f85e193739c953358c865005855253af4f68a497John McCall                                               QualType Type,
196f85e193739c953358c865005855253af4f68a497John McCall                                               bool Consumed) {
197688fc9b9b4323a294f5bf4f8a83f7c365edec573Douglas Gregor    InitializedEntity Entity;
198688fc9b9b4323a294f5bf4f8a83f7c365edec573Douglas Gregor    Entity.Kind = EK_Parameter;
199745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian    Entity.Type = Context.getVariableArrayDecayedType(Type);
200688fc9b9b4323a294f5bf4f8a83f7c365edec573Douglas Gregor    Entity.Parent = 0;
201f85e193739c953358c865005855253af4f68a497John McCall    Entity.Parameter = (Consumed);
202688fc9b9b4323a294f5bf4f8a83f7c365edec573Douglas Gregor    return Entity;
203a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor  }
204a188ff2d8a18140541fcd5884deda4552dac71a7Douglas Gregor
20520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for the result of a function.
20620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializedEntity InitializeResult(SourceLocation ReturnLoc,
2073c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor                                            QualType Type, bool NRVO) {
2083c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor    return InitializedEntity(EK_Result, ReturnLoc, Type, NRVO);
20920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
21020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
211310b1c421665241d9b135c517d5031716d4a3221Fariborz Jahanian  static InitializedEntity InitializeBlock(SourceLocation BlockVarLoc,
212310b1c421665241d9b135c517d5031716d4a3221Fariborz Jahanian                                           QualType Type, bool NRVO) {
213310b1c421665241d9b135c517d5031716d4a3221Fariborz Jahanian    return InitializedEntity(EK_BlockElement, BlockVarLoc, Type, NRVO);
214310b1c421665241d9b135c517d5031716d4a3221Fariborz Jahanian  }
215310b1c421665241d9b135c517d5031716d4a3221Fariborz Jahanian
21620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for an exception object.
21720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializedEntity InitializeException(SourceLocation ThrowLoc,
2183c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor                                               QualType Type, bool NRVO) {
2193c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor    return InitializedEntity(EK_Exception, ThrowLoc, Type, NRVO);
22020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
22118ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor
22218ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  /// \brief Create the initialization entity for an object allocated via new.
223d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor  static InitializedEntity InitializeNew(SourceLocation NewLoc, QualType Type) {
224d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor    return InitializedEntity(EK_New, NewLoc, Type);
22518ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  }
22620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
22720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for a temporary.
228d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor  static InitializedEntity InitializeTemporary(QualType Type) {
2296e4a0af697eec5b0c47ccf96dff170af56df826dRichard Smith    InitializedEntity Result(EK_Temporary, SourceLocation(), Type);
2306e4a0af697eec5b0c47ccf96dff170af56df826dRichard Smith    Result.TypeInfo = 0;
2316e4a0af697eec5b0c47ccf96dff170af56df826dRichard Smith    return Result;
23220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
233ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
234ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// \brief Create the initialization entity for a temporary.
235ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  static InitializedEntity InitializeTemporary(TypeSourceInfo *TypeInfo) {
236ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    InitializedEntity Result(EK_Temporary, SourceLocation(),
237ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                             TypeInfo->getType());
238ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    Result.TypeInfo = TypeInfo;
239ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return Result;
240ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  }
241ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
24220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create the initialization entity for a base class subobject.
24320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializedEntity InitializeBase(ASTContext &Context,
244711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson                                          CXXBaseSpecifier *Base,
245711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson                                          bool IsInheritedVirtualBase);
2464171766318a2564fbc9a739be0a2851f441c0d29Sean Hunt
2474171766318a2564fbc9a739be0a2851f441c0d29Sean Hunt  /// \brief Create the initialization entity for a delegated constructor.
2484171766318a2564fbc9a739be0a2851f441c0d29Sean Hunt  static InitializedEntity InitializeDelegation(QualType Type) {
249059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt    return InitializedEntity(EK_Delegating, SourceLocation(), Type);
2504171766318a2564fbc9a739be0a2851f441c0d29Sean Hunt  }
25120093b4bf698f292c664676987541d5103b65b15Douglas Gregor
252cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief Create the initialization entity for a member subobject.
253cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  static InitializedEntity InitializeMember(FieldDecl *Member,
254cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                                          const InitializedEntity *Parent = 0) {
255cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor    return InitializedEntity(Member, Parent);
25620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
25720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
25800eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet  /// \brief Create the initialization entity for a member subobject.
25900eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet  static InitializedEntity InitializeMember(IndirectFieldDecl *Member,
26000eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet                                      const InitializedEntity *Parent = 0) {
26100eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet    return InitializedEntity(Member->getAnonField(), Parent);
26200eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet  }
26300eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet
264cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief Create the initialization entity for an array element.
265cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  static InitializedEntity InitializeElement(ASTContext &Context,
266cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                                             unsigned Index,
267cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                                             const InitializedEntity &Parent) {
268cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor    return InitializedEntity(Context, Index, Parent);
269cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  }
270cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
2714773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  /// \brief Create the initialization entity for a lambda capture.
2724773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  static InitializedEntity InitializeLambdaCapture(VarDecl *Var,
2734773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor                                                   FieldDecl *Field,
2744773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor                                                   SourceLocation Loc) {
2754773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    return InitializedEntity(Var, Field, Loc);
2764773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  }
2774773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor
27820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine the kind of initialization.
27920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  EntityKind getKind() const { return Kind; }
28020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
281cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief Retrieve the parent of the entity being initialized, when
282fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner  /// the initialization itself is occurring within the context of a
283cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// larger initialization.
284cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  const InitializedEntity *getParent() const { return Parent; }
285cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
28620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Retrieve type being initialized.
287d6542d8efcf8389c3aab764f9e29ac284e16eda6Douglas Gregor  QualType getType() const { return Type; }
28820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
289ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// \brief Retrieve complete type-source information for the object being
290ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// constructed, if known.
291ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const {
292ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    if (Kind == EK_Temporary)
293ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      return TypeInfo;
294ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
295ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return 0;
296ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  }
297ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
29899a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  /// \brief Retrieve the name of the entity being initialized.
29999a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  DeclarationName getName() const;
3007abfbdbc97ad8e7f340789f751df1e32b10118b4Douglas Gregor
3017abfbdbc97ad8e7f340789f751df1e32b10118b4Douglas Gregor  /// \brief Retrieve the variable, parameter, or field being
3027abfbdbc97ad8e7f340789f751df1e32b10118b4Douglas Gregor  /// initialized.
3037abfbdbc97ad8e7f340789f751df1e32b10118b4Douglas Gregor  DeclaratorDecl *getDecl() const;
3047abfbdbc97ad8e7f340789f751df1e32b10118b4Douglas Gregor
3053c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor  /// \brief Determine whether this initialization allows the named return
3063c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor  /// value optimization, which also applies to thrown objects.
3073c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor  bool allowsNRVO() const;
308f85e193739c953358c865005855253af4f68a497John McCall
309f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Determine whether this initialization consumes the
310f85e193739c953358c865005855253af4f68a497John McCall  /// parameter.
311f85e193739c953358c865005855253af4f68a497John McCall  bool isParameterConsumed() const {
312f85e193739c953358c865005855253af4f68a497John McCall    assert(getKind() == EK_Parameter && "Not a parameter");
313f85e193739c953358c865005855253af4f68a497John McCall    return (Parameter & 1);
314f85e193739c953358c865005855253af4f68a497John McCall  }
3153c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor
3169db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  /// \brief Retrieve the base specifier.
3179db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  CXXBaseSpecifier *getBaseSpecifier() const {
3189db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor    assert(getKind() == EK_Base && "Not a base specifier");
319711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson    return reinterpret_cast<CXXBaseSpecifier *>(Base & ~0x1);
320711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson  }
321711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson
322711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson  /// \brief Return whether the base is an inherited virtual base.
323711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson  bool isInheritedVirtualBase() const {
324711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson    assert(getKind() == EK_Base && "Not a base specifier");
325711f34adb886cce8ba86c7b1b6513a1eaaf63bb5Anders Carlsson    return Base & 0x1;
3269db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  }
3279db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor
32820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine the location of the 'return' keyword when initializing
32920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// the result of a function call.
33020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceLocation getReturnLoc() const {
33120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    assert(getKind() == EK_Result && "No 'return' location!");
3323c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor    return SourceLocation::getFromRawEncoding(LocAndNRVO.Location);
33320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
334f85e193739c953358c865005855253af4f68a497John McCall
33520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine the location of the 'throw' keyword when initializing
33620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// an exception object.
33720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceLocation getThrowLoc() const {
33820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    assert(getKind() == EK_Exception && "No 'throw' location!");
3393c9034cb7ff1d6c1e4ecd1b44c98f553df013c7cDouglas Gregor    return SourceLocation::getFromRawEncoding(LocAndNRVO.Location);
34020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
341cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
342cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief If this is already the initializer for an array or vector
343cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// element, sets the element index.
344cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  void setElementIndex(unsigned Index) {
3450c706c29f20b6fa36759fa41333b9c3ec0bd2969Eli Friedman    assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
346eb52f86a62db523e3c993686b3ed92c55d59d53cDavid Blaikie           getKind() == EK_ComplexElement);
347cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor    this->Index = Index;
348cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  }
3494773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor
3504773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  /// \brief Retrieve the variable for a captured variable in a lambda.
3514773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  VarDecl *getCapturedVar() const {
3524773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
3534773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    return Capture.Var;
3544773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  }
3554773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor
3564773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  /// \brief Determine the location of the capture when initializing
3574773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  /// field from a captured variable in a lambda.
3584773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  SourceLocation getCaptureLoc() const {
3594773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
3604773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor    return SourceLocation::getFromRawEncoding(Capture.Location);
3614773654f2700d6fbb20612fbb6763b35860fa74dDouglas Gregor  }
36220093b4bf698f292c664676987541d5103b65b15Douglas Gregor};
36320093b4bf698f292c664676987541d5103b65b15Douglas Gregor
36420093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// \brief Describes the kind of initialization being performed, along with
36520093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// location information for tokens related to the initialization (equal sign,
36620093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// parentheses).
36720093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass InitializationKind {
36820093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
36920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The kind of initialization being performed.
37020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum InitKind {
371ed878af7914df535b32d64f555fa118413186672Douglas Gregor    IK_Direct,       ///< Direct initialization
372ed878af7914df535b32d64f555fa118413186672Douglas Gregor    IK_DirectList,   ///< Direct list-initialization
373ed878af7914df535b32d64f555fa118413186672Douglas Gregor    IK_Copy,         ///< Copy initialization
374ed878af7914df535b32d64f555fa118413186672Douglas Gregor    IK_Default,      ///< Default initialization
375ed878af7914df535b32d64f555fa118413186672Douglas Gregor    IK_Value         ///< Value initialization
37620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
37720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
37820093b4bf698f292c664676987541d5103b65b15Douglas Gregorprivate:
3793a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  /// \brief The context of the initialization.
3803a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  enum InitContext {
3813a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    IC_Normal,         ///< Normal context
382ed878af7914df535b32d64f555fa118413186672Douglas Gregor    IC_ExplicitConvs,  ///< Normal context, but allows explicit conversion funcs
3833a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    IC_Implicit,       ///< Implicit context (value initialization)
3843a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    IC_StaticCast,     ///< Static cast context
3853a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    IC_CStyleCast,     ///< C-style cast context
3863a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    IC_FunctionalCast  ///< Functional cast context
38720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
38820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
38920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The kind of initialization being performed.
3903a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  InitKind Kind : 8;
3913a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl
3923a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  /// \brief The context of the initialization.
3933a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  InitContext Context : 8;
39420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
39520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The source locations involved in the initialization.
39620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceLocation Locations[3];
39720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
3983a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  InitializationKind(InitKind Kind, InitContext Context, SourceLocation Loc1,
39920093b4bf698f292c664676987541d5103b65b15Douglas Gregor                     SourceLocation Loc2, SourceLocation Loc3)
4003a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    : Kind(Kind), Context(Context)
40120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  {
40220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    Locations[0] = Loc1;
40320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    Locations[1] = Loc2;
40420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    Locations[2] = Loc3;
40520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
40620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
40720093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
40820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create a direct initialization.
40920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializationKind CreateDirect(SourceLocation InitLoc,
41020093b4bf698f292c664676987541d5103b65b15Douglas Gregor                                         SourceLocation LParenLoc,
41120093b4bf698f292c664676987541d5103b65b15Douglas Gregor                                         SourceLocation RParenLoc) {
4123a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return InitializationKind(IK_Direct, IC_Normal,
4133a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl                              InitLoc, LParenLoc, RParenLoc);
41420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
41520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
4165b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  static InitializationKind CreateDirectList(SourceLocation InitLoc) {
4173a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return InitializationKind(IK_DirectList, IC_Normal,
4183a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl                              InitLoc, InitLoc, InitLoc);
4195b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  }
4205b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl
421f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Create a direct initialization due to a cast that isn't a C-style
422f85e193739c953358c865005855253af4f68a497John McCall  /// or functional cast.
423c8d7f586180995ba33d03c0f6115b6a7bdefe326Richard Smith  static InitializationKind CreateCast(SourceRange TypeRange) {
4243a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return InitializationKind(IK_Direct, IC_StaticCast, TypeRange.getBegin(),
4253a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl                              TypeRange.getBegin(), TypeRange.getEnd());
42620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
42720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
428f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Create a direct initialization for a C-style cast.
429f85e193739c953358c865005855253af4f68a497John McCall  static InitializationKind CreateCStyleCast(SourceLocation StartLoc,
4303a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl                                             SourceRange TypeRange,
4313a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl                                             bool InitList) {
4323a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    // C++ cast syntax doesn't permit init lists, but C compound literals are
4333a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    // exactly that.
4343a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return InitializationKind(InitList ? IK_DirectList : IK_Direct,
4353a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl                              IC_CStyleCast, StartLoc, TypeRange.getBegin(),
436f85e193739c953358c865005855253af4f68a497John McCall                              TypeRange.getEnd());
437f85e193739c953358c865005855253af4f68a497John McCall  }
438f85e193739c953358c865005855253af4f68a497John McCall
439f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Create a direct initialization for a functional cast.
4403a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  static InitializationKind CreateFunctionalCast(SourceRange TypeRange,
4413a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl                                                 bool InitList) {
4423a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return InitializationKind(InitList ? IK_DirectList : IK_Direct,
4433a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl                              IC_FunctionalCast, TypeRange.getBegin(),
4443a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl                              TypeRange.getBegin(), TypeRange.getEnd());
445f85e193739c953358c865005855253af4f68a497John McCall  }
446f85e193739c953358c865005855253af4f68a497John McCall
44720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create a copy initialization.
44820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializationKind CreateCopy(SourceLocation InitLoc,
449ed878af7914df535b32d64f555fa118413186672Douglas Gregor                                       SourceLocation EqualLoc,
450ed878af7914df535b32d64f555fa118413186672Douglas Gregor                                       bool AllowExplicitConvs = false) {
451ed878af7914df535b32d64f555fa118413186672Douglas Gregor    return InitializationKind(IK_Copy,
452ed878af7914df535b32d64f555fa118413186672Douglas Gregor                              AllowExplicitConvs? IC_ExplicitConvs : IC_Normal,
453ed878af7914df535b32d64f555fa118413186672Douglas Gregor                              InitLoc, EqualLoc, EqualLoc);
45420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
45520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
45620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create a default initialization.
45720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializationKind CreateDefault(SourceLocation InitLoc) {
4583a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return InitializationKind(IK_Default, IC_Normal, InitLoc, InitLoc, InitLoc);
45920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
46020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
46120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Create a value initialization.
46220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  static InitializationKind CreateValue(SourceLocation InitLoc,
46320093b4bf698f292c664676987541d5103b65b15Douglas Gregor                                        SourceLocation LParenLoc,
464cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                                        SourceLocation RParenLoc,
465cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                                        bool isImplicit = false) {
4663a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return InitializationKind(IK_Value, isImplicit ? IC_Implicit : IC_Normal,
467cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor                              InitLoc, LParenLoc, RParenLoc);
46820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
46920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
47020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine the initialization kind.
47120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  InitKind getKind() const {
4723a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return Kind;
47320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
47420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
47520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine whether this initialization is an explicit cast.
47620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  bool isExplicitCast() const {
4773a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return Context >= IC_StaticCast;
47820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
47920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
48020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine whether this initialization is a C-style cast.
48120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  bool isCStyleOrFunctionalCast() const {
4823a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return Context >= IC_CStyleCast;
483f85e193739c953358c865005855253af4f68a497John McCall  }
484f85e193739c953358c865005855253af4f68a497John McCall
4853a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  /// \brief Determine whether this is a C-style cast.
486f85e193739c953358c865005855253af4f68a497John McCall  bool isCStyleCast() const {
4873a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return Context == IC_CStyleCast;
488f85e193739c953358c865005855253af4f68a497John McCall  }
489f85e193739c953358c865005855253af4f68a497John McCall
4903a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  /// \brief Determine whether this is a functional-style cast.
491f85e193739c953358c865005855253af4f68a497John McCall  bool isFunctionalCast() const {
4923a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    return Context == IC_FunctionalCast;
49320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
494cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
495cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// \brief Determine whether this initialization is an implicit
496cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// value-initialization, e.g., as occurs during aggregate
497cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor  /// initialization.
4983a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  bool isImplicitValueInit() const { return Context == IC_Implicit; }
499cb57fb9f91e0976f4a3382b89a2734ffa50eb6fbDouglas Gregor
50020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Retrieve the location at which initialization is occurring.
50120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceLocation getLocation() const { return Locations[0]; }
50220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
50320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Retrieve the source range that covers the initialization.
50420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceRange getRange() const {
50571d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor    return SourceRange(Locations[0], Locations[2]);
50620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
50720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
50820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Retrieve the location of the equal sign for copy initialization
50920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// (if present).
51020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceLocation getEqualLoc() const {
5113a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    assert(Kind == IK_Copy && "Only copy initialization has an '='");
51220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return Locations[1];
51320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
514168319c81b8f4e7addf36ad15ef24919faf23504Sebastian Redl
5153a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl  bool isCopyInit() const { return Kind == IK_Copy; }
516168319c81b8f4e7addf36ad15ef24919faf23504Sebastian Redl
517168319c81b8f4e7addf36ad15ef24919faf23504Sebastian Redl  /// \brief Retrieve whether this initialization allows the use of explicit
518168319c81b8f4e7addf36ad15ef24919faf23504Sebastian Redl  ///        constructors.
519168319c81b8f4e7addf36ad15ef24919faf23504Sebastian Redl  bool AllowExplicit() const { return !isCopyInit(); }
520168319c81b8f4e7addf36ad15ef24919faf23504Sebastian Redl
521ed878af7914df535b32d64f555fa118413186672Douglas Gregor  /// \brief Retrieve whether this initialization allows the use of explicit
522ed878af7914df535b32d64f555fa118413186672Douglas Gregor  /// conversion functions.
523ed878af7914df535b32d64f555fa118413186672Douglas Gregor  bool allowExplicitConversionFunctions() const {
524ed878af7914df535b32d64f555fa118413186672Douglas Gregor    return !isCopyInit() || Context == IC_ExplicitConvs;
525ed878af7914df535b32d64f555fa118413186672Douglas Gregor  }
526ed878af7914df535b32d64f555fa118413186672Douglas Gregor
52720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Retrieve the source range containing the locations of the open
52820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// and closing parentheses for value and direct initializations.
52920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  SourceRange getParenRange() const {
5303a45c0e61dfc19f27b8ebcb15dd70159a36f1f9aSebastian Redl    assert((Kind == IK_Direct || Kind == IK_Value) &&
53120093b4bf698f292c664676987541d5103b65b15Douglas Gregor           "Only direct- and value-initialization have parentheses");
53220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return SourceRange(Locations[1], Locations[2]);
53320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
53420093b4bf698f292c664676987541d5103b65b15Douglas Gregor};
53520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
53620093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// \brief Describes the sequence of initializations required to initialize
53720093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// a given object or reference with a set of arguments.
53820093b4bf698f292c664676987541d5103b65b15Douglas Gregorclass InitializationSequence {
53920093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
54020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Describes the kind of initialization sequence computed.
54120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum SequenceKind {
54220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief A failed initialization sequence. The failure kind tells what
54320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// happened.
54420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FailedSequence = 0,
5457491c499e826682e128a400038361ebcbde30eecSebastian Redl
54620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief A dependent initialization, which could not be
54720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// type-checked due to the presence of dependent types or
5487491c499e826682e128a400038361ebcbde30eecSebastian Redl    /// dependently-typed expressions.
54920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    DependentSequence,
55020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
5517491c499e826682e128a400038361ebcbde30eecSebastian Redl    /// \brief A normal sequence.
5523b80232b50c29b245e674f5aa02047b408e41018Sebastian Redl    NormalSequence
55320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
55420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
55520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Describes the kind of a particular step in an initialization
55620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// sequence.
55720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum StepKind {
55820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Resolve the address of an overloaded function to a specific
55920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// function declaration.
56020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_ResolveAddressOfOverloadedFunction,
56120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Perform a derived-to-base cast, producing an rvalue.
56220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_CastDerivedToBaseRValue,
563906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl    /// \brief Perform a derived-to-base cast, producing an xvalue.
564906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl    SK_CastDerivedToBaseXValue,
56520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Perform a derived-to-base cast, producing an lvalue.
56620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_CastDerivedToBaseLValue,
56720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Reference binding to an lvalue.
56820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_BindReference,
56920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Reference binding to a temporary.
57020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_BindReferenceToTemporary,
571523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor    /// \brief An optional copy of a temporary object to another
572523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor    /// temporary object, which is permitted (but not required) by
573523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor    /// C++98/03 but not C++0x.
574523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor    SK_ExtraneousCopyToTemporary,
57520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Perform a user-defined conversion, either via a conversion
57620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// function or via a constructor.
57720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_UserConversion,
57820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Perform a qualification conversion, producing an rvalue.
57920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_QualificationConversionRValue,
580906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl    /// \brief Perform a qualification conversion, producing an xvalue.
581906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl    SK_QualificationConversionXValue,
58220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Perform a qualification conversion, producing an lvalue.
58320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SK_QualificationConversionLValue,
58420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Perform an implicit conversion sequence.
585d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    SK_ConversionSequence,
5868713d4e874f2adc2928ebfb86c845574a14e3b3eSebastian Redl    /// \brief Perform list-initialization without a constructor
58751c56d6c8a944c2e49dd714db65a780d9f627e15Douglas Gregor    SK_ListInitialization,
5888713d4e874f2adc2928ebfb86c845574a14e3b3eSebastian Redl    /// \brief Perform list-initialization with a constructor.
5898713d4e874f2adc2928ebfb86c845574a14e3b3eSebastian Redl    SK_ListConstructorCall,
59013dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl    /// \brief Unwrap the single-element initializer list for a reference.
59113dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl    SK_UnwrapInitList,
59213dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl    /// \brief Rewrap the single-element initializer list for a reference.
59313dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl    SK_RewrapInitList,
59451c56d6c8a944c2e49dd714db65a780d9f627e15Douglas Gregor    /// \brief Perform initialization via a constructor.
59571d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor    SK_ConstructorInitialization,
59671d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor    /// \brief Zero-initialize the object
59718ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    SK_ZeroInitialization,
59818ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor    /// \brief C assignment
599cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman    SK_CAssignment,
600cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman    /// \brief Initialization by string
601569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor    SK_StringInit,
602569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor    /// \brief An initialization that "converts" an Objective-C object
603569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor    /// (not a point to an object) to another Objective-C object type.
604cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor    SK_ObjCObjectConversion,
605cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor    /// \brief Array initialization (from an array rvalue).
606cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor    /// This is a GNU C extension.
607f85e193739c953358c865005855253af4f68a497John McCall    SK_ArrayInit,
6080f163e964289bc18e9bc1ec37a6a01018ba62640Richard Smith    /// \brief Array initialization from a parenthesized initializer list.
6090f163e964289bc18e9bc1ec37a6a01018ba62640Richard Smith    /// This is a GNU C++ extension.
6100f163e964289bc18e9bc1ec37a6a01018ba62640Richard Smith    SK_ParenthesizedArrayInit,
611f85e193739c953358c865005855253af4f68a497John McCall    /// \brief Pass an object by indirect copy-and-restore.
612f85e193739c953358c865005855253af4f68a497John McCall    SK_PassByIndirectCopyRestore,
613f85e193739c953358c865005855253af4f68a497John McCall    /// \brief Pass an object by indirect restore.
614f85e193739c953358c865005855253af4f68a497John McCall    SK_PassByIndirectRestore,
615f85e193739c953358c865005855253af4f68a497John McCall    /// \brief Produce an Objective-C object pointer.
6162b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl    SK_ProduceObjCObject,
6172b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl    /// \brief Construct a std::initializer_list from an initializer list.
6182b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl    SK_StdInitializerList
61920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
62020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
62120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief A single step in the initialization sequence.
62220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  class Step {
62320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  public:
62420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief The kind of conversion or initialization step we are taking.
62520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    StepKind Kind;
62620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
62720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    // \brief The type that results from this initialization.
62820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    QualType Type;
62920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
63020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    union {
63120093b4bf698f292c664676987541d5103b65b15Douglas Gregor      /// \brief When Kind == SK_ResolvedOverloadedFunction or Kind ==
63220093b4bf698f292c664676987541d5103b65b15Douglas Gregor      /// SK_UserConversion, the function that the expression should be
63320093b4bf698f292c664676987541d5103b65b15Douglas Gregor      /// resolved to or the conversion function to call, respectively.
6348713d4e874f2adc2928ebfb86c845574a14e3b3eSebastian Redl      /// When Kind == SK_ConstructorInitialization or SK_ListConstruction,
6358713d4e874f2adc2928ebfb86c845574a14e3b3eSebastian Redl      /// the constructor to be called.
636b13b737a2450167c82e148590e8019b839ce6b98John McCall      ///
6377cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara      /// Always a FunctionDecl, plus a Boolean flag telling if it was
6387cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara      /// selected from an overloaded set having size greater than 1.
639b13b737a2450167c82e148590e8019b839ce6b98John McCall      /// For conversion decls, the naming class is the source type.
640b13b737a2450167c82e148590e8019b839ce6b98John McCall      /// For construct decls, the naming class is the target type.
6419aa472c45d2bd81b7b52c225e8acc560d716db97John McCall      struct {
6427cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara        bool HadMultipleCandidates;
6439aa472c45d2bd81b7b52c225e8acc560d716db97John McCall        FunctionDecl *Function;
6449aa472c45d2bd81b7b52c225e8acc560d716db97John McCall        DeclAccessPair FoundDecl;
6459aa472c45d2bd81b7b52c225e8acc560d716db97John McCall      } Function;
6468713d4e874f2adc2928ebfb86c845574a14e3b3eSebastian Redl
64720093b4bf698f292c664676987541d5103b65b15Douglas Gregor      /// \brief When Kind = SK_ConversionSequence, the implicit conversion
64813dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl      /// sequence.
64920093b4bf698f292c664676987541d5103b65b15Douglas Gregor      ImplicitConversionSequence *ICS;
65013dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl
65113dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl      /// \brief When Kind = SK_RewrapInitList, the syntactic form of the
65213dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl      /// wrapping list.
65313dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl      InitListExpr *WrappingSyntacticList;
65420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    };
6558713d4e874f2adc2928ebfb86c845574a14e3b3eSebastian Redl
65620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    void Destroy();
65720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
65820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
65920093b4bf698f292c664676987541d5103b65b15Douglas Gregorprivate:
66020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The kind of initialization sequence computed.
66120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum SequenceKind SequenceKind;
66220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
66320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Steps taken by this initialization.
664686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<Step, 4> Steps;
66520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
66620093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
66720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Describes why initialization failed.
66820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum FailureKind {
66920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Too many initializers provided for a reference.
67020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_TooManyInitsForReference,
67120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Array must be initialized with an initializer list.
67220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_ArrayNeedsInitList,
67320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Array must be initialized with an initializer list or a
67420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// string literal.
67520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_ArrayNeedsInitListOrStringLiteral,
676cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor    /// \brief Array type mismatch.
677cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor    FK_ArrayTypeMismatch,
678cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor    /// \brief Non-constant array initializer
679cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor    FK_NonConstantArrayInit,
68020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Cannot resolve the address of an overloaded function.
68120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_AddressOfOverloadFailed,
68220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Overloading due to reference initialization failed.
68320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_ReferenceInitOverloadFailed,
68420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Non-const lvalue reference binding to a temporary.
68520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_NonConstLValueReferenceBindingToTemporary,
68620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Non-const lvalue reference binding to an lvalue of unrelated
68720093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// type.
68820093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_NonConstLValueReferenceBindingToUnrelated,
68920093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Rvalue reference binding to an lvalue.
69020093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_RValueReferenceBindingToLValue,
69120093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Reference binding drops qualifiers.
69220093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_ReferenceInitDropsQualifiers,
69320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Reference binding failed.
69420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    FK_ReferenceInitFailed,
69520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    /// \brief Implicit conversion failed.
696d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    FK_ConversionFailed,
697429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    /// \brief Implicit conversion failed.
698429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    FK_ConversionFromPropertyFailed,
699d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    /// \brief Too many initializers for scalar
700d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    FK_TooManyInitsForScalar,
701d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    /// \brief Reference initialization from an initializer list
702d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    FK_ReferenceBindingToInitList,
703d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    /// \brief Initialization of some unused destination type with an
704d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor    /// initializer list.
7054a520a2bd8a6b79fa5d4771f02e34e7bd6bc461dDouglas Gregor    FK_InitListBadDestinationType,
7064a520a2bd8a6b79fa5d4771f02e34e7bd6bc461dDouglas Gregor    /// \brief Overloading for a user-defined conversion failed.
70751c56d6c8a944c2e49dd714db65a780d9f627e15Douglas Gregor    FK_UserConversionOverloadFailed,
708cf15cef8447e8b3ae08e81ad25ae9eb443038acfSebastian Redl    /// \brief Overloading for initialization by constructor failed.
70999a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor    FK_ConstructorOverloadFailed,
710cf15cef8447e8b3ae08e81ad25ae9eb443038acfSebastian Redl    /// \brief Overloading for list-initialization by constructor failed.
711cf15cef8447e8b3ae08e81ad25ae9eb443038acfSebastian Redl    FK_ListConstructorOverloadFailed,
71299a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor    /// \brief Default-initialization of a 'const' object.
71372a43bbf6802c8fcfd04dcb2be8eafcb0b8fe29cDouglas Gregor    FK_DefaultInitOfConst,
71472a43bbf6802c8fcfd04dcb2be8eafcb0b8fe29cDouglas Gregor    /// \brief Initialization of an incomplete type.
7158713d4e874f2adc2928ebfb86c845574a14e3b3eSebastian Redl    FK_Incomplete,
71673076431605556fdbf28d287d084a73a24a8b8d4John McCall    /// \brief Variable-length array must not have an initializer.
71773076431605556fdbf28d287d084a73a24a8b8d4John McCall    FK_VariableLengthArrayHasInitializer,
7188713d4e874f2adc2928ebfb86c845574a14e3b3eSebastian Redl    /// \brief List initialization failed at some point.
7195acb0c98b363400f6ade0ae7250f0102224e806bJohn McCall    FK_ListInitializationFailed,
7205acb0c98b363400f6ade0ae7250f0102224e806bJohn McCall    /// \brief Initializer has a placeholder type which cannot be
7215acb0c98b363400f6ade0ae7250f0102224e806bJohn McCall    /// resolved by initialization.
7222b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl    FK_PlaceholderType,
7232b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl    /// \brief Failed to initialize a std::initializer_list because copy
7242b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl    /// construction of some element failed.
72570e24fccc8ef4aa8be03a778e9655bfcfa79dd14Sebastian Redl    FK_InitListElementCopyFailure,
72670e24fccc8ef4aa8be03a778e9655bfcfa79dd14Sebastian Redl    /// \brief List-copy-initialization chose an explicit constructor.
72770e24fccc8ef4aa8be03a778e9655bfcfa79dd14Sebastian Redl    FK_ExplicitConstructor
72820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  };
72920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
73020093b4bf698f292c664676987541d5103b65b15Douglas Gregorprivate:
7315d3d41d0873d51b405972baf38e1f3a7ef5b49e0Sebastian Redl  /// \brief The reason why initialization failed.
73220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  FailureKind Failure;
73320093b4bf698f292c664676987541d5103b65b15Douglas Gregor
73420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The failed result of overload resolution.
73520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  OverloadingResult FailedOverloadResult;
73620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
73720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief The candidate set created when initialization failed.
73820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  OverloadCandidateSet FailedCandidateSet;
739a41a8c5972c2632247ae7913cf6ce65d45f7e702Douglas Gregor
74069a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor  /// \brief The incomplete type that caused a failure.
74169a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor  QualType FailedIncompleteType;
74269a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor
743a41a8c5972c2632247ae7913cf6ce65d45f7e702Douglas Gregor  /// \brief Prints a follow-up note that highlights the location of
744a41a8c5972c2632247ae7913cf6ce65d45f7e702Douglas Gregor  /// the initialized entity, if it's remote.
745a41a8c5972c2632247ae7913cf6ce65d45f7e702Douglas Gregor  void PrintInitLocationNote(Sema &S, const InitializedEntity &Entity);
746a41a8c5972c2632247ae7913cf6ce65d45f7e702Douglas Gregor
74720093b4bf698f292c664676987541d5103b65b15Douglas Gregorpublic:
74820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Try to perform initialization of the given entity, creating a
74920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// record of the steps required to perform the initialization.
75020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
75120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// The generated initialization sequence will either contain enough
75220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// information to diagnose
75320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
75420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param S the semantic analysis object.
75520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
75620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Entity the entity being initialized.
75720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
75820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Kind the kind of initialization being performed.
75920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
76020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Args the argument(s) provided for initialization.
76120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
76220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param NumArgs the number of arguments provided for initialization.
76320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  InitializationSequence(Sema &S,
76420093b4bf698f292c664676987541d5103b65b15Douglas Gregor                         const InitializedEntity &Entity,
76520093b4bf698f292c664676987541d5103b65b15Douglas Gregor                         const InitializationKind &Kind,
76620093b4bf698f292c664676987541d5103b65b15Douglas Gregor                         Expr **Args,
76720093b4bf698f292c664676987541d5103b65b15Douglas Gregor                         unsigned NumArgs);
76820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
76920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ~InitializationSequence();
77020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
77120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Perform the actual initialization of the given entity based on
77220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// the computed initialization sequence.
77320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
77420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param S the semantic analysis object.
77520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
77620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Entity the entity being initialized.
77720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
77820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Kind the kind of initialization being performed.
77920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
78020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Args the argument(s) provided for initialization, ownership of
781fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner  /// which is transferred into the routine.
78220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
783d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  /// \param ResultType if non-NULL, will be set to the type of the
784d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  /// initialized object, which is the type of the declaration in most
785d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  /// cases. However, when the initialized object is a variable of
786d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  /// incomplete array type and the initializer is an initializer
787d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  /// list, this type will be set to the completed array type.
788d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  ///
78920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \returns an expression that performs the actual object initialization, if
79020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// the initialization is well-formed. Otherwise, emits diagnostics
79120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// and returns an invalid expression.
79260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Perform(Sema &S,
79360d7b3a319d84d688752be3870615ac0f111fb16John McCall                     const InitializedEntity &Entity,
79460d7b3a319d84d688752be3870615ac0f111fb16John McCall                     const InitializationKind &Kind,
795120d63cd4465230c2cd56508c7cd8e0ad00848e7John McCall                     MultiExprArg Args,
79660d7b3a319d84d688752be3870615ac0f111fb16John McCall                     QualType *ResultType = 0);
79720093b4bf698f292c664676987541d5103b65b15Douglas Gregor
79820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Diagnose an potentially-invalid initialization sequence.
79920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
80020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \returns true if the initialization sequence was ill-formed,
80120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// false otherwise.
80220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  bool Diagnose(Sema &S,
80320093b4bf698f292c664676987541d5103b65b15Douglas Gregor                const InitializedEntity &Entity,
80420093b4bf698f292c664676987541d5103b65b15Douglas Gregor                const InitializationKind &Kind,
80520093b4bf698f292c664676987541d5103b65b15Douglas Gregor                Expr **Args, unsigned NumArgs);
80620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
80720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine the kind of initialization sequence computed.
80820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  enum SequenceKind getKind() const { return SequenceKind; }
80920093b4bf698f292c664676987541d5103b65b15Douglas Gregor
81020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Set the kind of sequence computed.
81120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  void setSequenceKind(enum SequenceKind SK) { SequenceKind = SK; }
81220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
81320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine whether the initialization sequence is valid.
8147491c499e826682e128a400038361ebcbde30eecSebastian Redl  operator bool() const { return !Failed(); }
815383616cd2e61131a534afd9364ef53f643e1f834Sebastian Redl
816383616cd2e61131a534afd9364ef53f643e1f834Sebastian Redl  /// \brief Determine whether the initialization sequence is invalid.
817383616cd2e61131a534afd9364ef53f643e1f834Sebastian Redl  bool Failed() const { return SequenceKind == FailedSequence; }
81820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
819686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<Step, 4>::const_iterator step_iterator;
82020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  step_iterator step_begin() const { return Steps.begin(); }
82120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  step_iterator step_end()   const { return Steps.end(); }
82220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
823b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor  /// \brief Determine whether this initialization is a direct reference
824b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor  /// binding (C++ [dcl.init.ref]).
825b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor  bool isDirectReferenceBinding() const;
826b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor
827b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor  /// \brief Determine whether this initialization failed due to an ambiguity.
828b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor  bool isAmbiguous() const;
829b70cf44bf1b1956e0c6b98373c4f69b23afa0052Douglas Gregor
830d6e44a3c4193bd422bfa78c8086fb16bb2168e34Douglas Gregor  /// \brief Determine whether this initialization is direct call to a
831d6e44a3c4193bd422bfa78c8086fb16bb2168e34Douglas Gregor  /// constructor.
832d6e44a3c4193bd422bfa78c8086fb16bb2168e34Douglas Gregor  bool isConstructorInitialization() const;
833191591336f639dad1504e863733fb831645c1644Jeffrey Yasskin
8345d3d41d0873d51b405972baf38e1f3a7ef5b49e0Sebastian Redl  /// \brief Returns whether the last step in this initialization sequence is a
8355d3d41d0873d51b405972baf38e1f3a7ef5b49e0Sebastian Redl  /// narrowing conversion, defined by C++0x [dcl.init.list]p7.
8365d3d41d0873d51b405972baf38e1f3a7ef5b49e0Sebastian Redl  ///
8375d3d41d0873d51b405972baf38e1f3a7ef5b49e0Sebastian Redl  /// If this function returns true, *isInitializerConstant will be set to
8385d3d41d0873d51b405972baf38e1f3a7ef5b49e0Sebastian Redl  /// describe whether *Initializer was a constant expression.  If
8395d3d41d0873d51b405972baf38e1f3a7ef5b49e0Sebastian Redl  /// *isInitializerConstant is set to true, *ConstantValue will be set to the
8405d3d41d0873d51b405972baf38e1f3a7ef5b49e0Sebastian Redl  /// evaluated value of *Initializer.
841191591336f639dad1504e863733fb831645c1644Jeffrey Yasskin  bool endsWithNarrowing(ASTContext &Ctx, const Expr *Initializer,
842191591336f639dad1504e863733fb831645c1644Jeffrey Yasskin                         bool *isInitializerConstant,
843191591336f639dad1504e863733fb831645c1644Jeffrey Yasskin                         APValue *ConstantValue) const;
844191591336f639dad1504e863733fb831645c1644Jeffrey Yasskin
84520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Add a new step in the initialization that resolves the address
84620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// of an overloaded function to a specific function declaration.
84720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
84820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param Function the function to which the overloaded function reference
84920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// resolves.
8506bb8017bb9e828d118e15e59d71c66bba323c364John McCall  void AddAddressOverloadResolutionStep(FunctionDecl *Function,
85122c107b2b99887b5aec6d1fd38210031e944e31fAbramo Bagnara                                        DeclAccessPair Found,
85222c107b2b99887b5aec6d1fd38210031e944e31fAbramo Bagnara                                        bool HadMultipleCandidates);
85322c107b2b99887b5aec6d1fd38210031e944e31fAbramo Bagnara
85420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Add a new step in the initialization that performs a derived-to-
85520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// base cast.
85620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
85720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \param BaseType the base type to which we will be casting.
85820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
859efce31f51d6e7e31e125f96c20f6cdab3ead0a47James Dennett  /// \param Category Indicates whether the result will be treated as an
860efce31f51d6e7e31e125f96c20f6cdab3ead0a47James Dennett  /// rvalue, an xvalue, or an lvalue.
861906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl  void AddDerivedToBaseCastStep(QualType BaseType,
8625baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall                                ExprValueKind Category);
86320093b4bf698f292c664676987541d5103b65b15Douglas Gregor
86420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Add a new step binding a reference to an object.
86520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  ///
866523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// \param BindingTemporary True if we are binding a reference to a temporary
86720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// object (thereby extending its lifetime); false if we are binding to an
86820093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// lvalue or an lvalue treated as an rvalue.
86920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  void AddReferenceBindingStep(QualType T, bool BindingTemporary);
870523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor
871523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// \brief Add a new step that makes an extraneous copy of the input
872523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// to a temporary of the same class type.
873523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  ///
874523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// This extraneous copy only occurs during reference binding in
875523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// C++98/03, where we are permitted (but not required) to introduce
876523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// an extra copy. At a bare minimum, we must check that we could
877523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// call the copy constructor, and produce a diagnostic if the copy
878523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// constructor is inaccessible or no copy constructor matches.
879523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  //
880523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  /// \param T The type of the temporary being created.
881523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor  void AddExtraneousCopyToTemporary(QualType T);
882523d46af407f32fc53861e6f068e8076d4fe84a8Douglas Gregor
88320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Add a new step invoking a conversion function, which is either
88420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// a constructor or a conversion function.
885b13b737a2450167c82e148590e8019b839ce6b98John McCall  void AddUserConversionStep(FunctionDecl *Function,
8869aa472c45d2bd81b7b52c225e8acc560d716db97John McCall                             DeclAccessPair FoundDecl,
88722c107b2b99887b5aec6d1fd38210031e944e31fAbramo Bagnara                             QualType T,
88822c107b2b99887b5aec6d1fd38210031e944e31fAbramo Bagnara                             bool HadMultipleCandidates);
88922c107b2b99887b5aec6d1fd38210031e944e31fAbramo Bagnara
89020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Add a new step that performs a qualification conversion to the
89120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// given type.
892906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl  void AddQualificationConversionStep(QualType Ty,
8935baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall                                     ExprValueKind Category);
89420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
89520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Add a new step that applies an implicit conversion sequence.
89620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  void AddConversionSequenceStep(const ImplicitConversionSequence &ICS,
89720093b4bf698f292c664676987541d5103b65b15Douglas Gregor                                 QualType T);
898d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor
89910f04a6267eb07d3be00db1fd0369e1398f5d0a8Sebastian Redl  /// \brief Add a list-initialization step.
900d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor  void AddListInitializationStep(QualType T);
901d87b61f6398bab21176f73818a8d11ca1c3632c8Douglas Gregor
90271d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor  /// \brief Add a constructor-initialization step.
9036cd03dbb310f472b14b8d6d69d8c9b5b7f1200e2Sebastian Redl  ///
9046cd03dbb310f472b14b8d6d69d8c9b5b7f1200e2Sebastian Redl  /// \arg FromInitList The constructor call is syntactically an initializer
9056cd03dbb310f472b14b8d6d69d8c9b5b7f1200e2Sebastian Redl  /// list.
9066cd03dbb310f472b14b8d6d69d8c9b5b7f1200e2Sebastian Redl  /// \arg AsInitList The constructor is called as an init list constructor.
90751c56d6c8a944c2e49dd714db65a780d9f627e15Douglas Gregor  void AddConstructorInitializationStep(CXXConstructorDecl *Constructor,
908b13b737a2450167c82e148590e8019b839ce6b98John McCall                                        AccessSpecifier Access,
90922c107b2b99887b5aec6d1fd38210031e944e31fAbramo Bagnara                                        QualType T,
91010f04a6267eb07d3be00db1fd0369e1398f5d0a8Sebastian Redl                                        bool HadMultipleCandidates,
9116cd03dbb310f472b14b8d6d69d8c9b5b7f1200e2Sebastian Redl                                        bool FromInitList, bool AsInitList);
91271d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor
91371d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor  /// \brief Add a zero-initialization step.
91471d1740c94060b424bb745d6c6973ff27cfdee06Douglas Gregor  void AddZeroInitializationStep(QualType T);
91510f04a6267eb07d3be00db1fd0369e1398f5d0a8Sebastian Redl
91618ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  /// \brief Add a C assignment step.
91718ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  //
91818ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  // FIXME: It isn't clear whether this should ever be needed;
91918ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  // ideally, we would handle everything needed in C in the common
92018ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  // path. However, that isn't the case yet.
92118ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor  void AddCAssignmentStep(QualType T);
92218ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor
923cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman  /// \brief Add a string init step.
924cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman  void AddStringInitStep(QualType T);
925cfdc81a83467973b14e4ea5e9e9af1690f135415Eli Friedman
926569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  /// \brief Add an Objective-C object conversion step, which is
927569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  /// always a no-op.
928569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  void AddObjCObjectConversionStep(QualType T);
929569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor
930cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor  /// \brief Add an array initialization step.
931cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor  void AddArrayInitStep(QualType T);
932cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor
9330f163e964289bc18e9bc1ec37a6a01018ba62640Richard Smith  /// \brief Add a parenthesized array initialization step.
9340f163e964289bc18e9bc1ec37a6a01018ba62640Richard Smith  void AddParenthesizedArrayInitStep(QualType T);
9350f163e964289bc18e9bc1ec37a6a01018ba62640Richard Smith
936f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Add a step to pass an object by indirect copy-restore.
937f85e193739c953358c865005855253af4f68a497John McCall  void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy);
938f85e193739c953358c865005855253af4f68a497John McCall
939f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Add a step to "produce" an Objective-C object (by
940f85e193739c953358c865005855253af4f68a497John McCall  /// retaining it).
941f85e193739c953358c865005855253af4f68a497John McCall  void AddProduceObjCObjectStep(QualType T);
942f85e193739c953358c865005855253af4f68a497John McCall
9432b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl  /// \brief Add a step to construct a std::initializer_list object from an
9442b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl  /// initializer list.
9452b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl  void AddStdInitializerListConstructionStep(QualType T);
9462b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl
94713dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl  /// \brief Add steps to unwrap a initializer list for a reference around a
94813dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl  /// single element and rewrap it at the end.
94913dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl  void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
95013dc8f98f6108dca8aaa9721567ed5a2d9911e0fSebastian Redl
95120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Note that this initialization sequence failed.
95220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  void SetFailed(FailureKind Failure) {
95320093b4bf698f292c664676987541d5103b65b15Douglas Gregor    SequenceKind = FailedSequence;
95420093b4bf698f292c664676987541d5103b65b15Douglas Gregor    this->Failure = Failure;
95569a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor    assert((Failure != FK_Incomplete || !FailedIncompleteType.isNull()) &&
95669a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor           "Incomplete type failure requires a type!");
95720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
95820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
95920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Note that this initialization sequence failed due to failed
96020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// overload resolution.
96120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  void SetOverloadFailure(FailureKind Failure, OverloadingResult Result);
96220093b4bf698f292c664676987541d5103b65b15Douglas Gregor
96320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Retrieve a reference to the candidate set when overload
96420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// resolution fails.
96520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  OverloadCandidateSet &getFailedCandidateSet() {
96620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return FailedCandidateSet;
96720093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
96820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
9692b916b8b55aaf0152ab9ad630c8454bf6373b085Sebastian Redl  /// \brief Get the overloading result, for when the initialization
97079ab2c8104ef5df233d271560ccc734836738e56John McCall  /// sequence failed due to a bad overload.
97179ab2c8104ef5df233d271560ccc734836738e56John McCall  OverloadingResult getFailedOverloadResult() const {
97279ab2c8104ef5df233d271560ccc734836738e56John McCall    return FailedOverloadResult;
97379ab2c8104ef5df233d271560ccc734836738e56John McCall  }
97479ab2c8104ef5df233d271560ccc734836738e56John McCall
97569a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor  /// \brief Note that this initialization sequence failed due to an
97669a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor  /// incomplete type.
97769a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor  void setIncompleteTypeFailure(QualType IncompleteType) {
97869a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor    FailedIncompleteType = IncompleteType;
97969a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor    SetFailed(FK_Incomplete);
98069a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor  }
98169a30b838c723cb1850de55cfa48a402cfeeb6e0Douglas Gregor
98220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  /// \brief Determine why initialization failed.
98320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  FailureKind getFailureKind() const {
984d695d6bb7323672e29dbb1556a3dafde3d3b2732Sebastian Redl    assert(Failed() && "Not an initialization failure!");
98520093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return Failure;
98620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  }
98779ab2c8104ef5df233d271560ccc734836738e56John McCall
988de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  /// \brief Dump a representation of this initialization sequence to
989de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  /// the given stream, for debugging purposes.
9908cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void dump(raw_ostream &OS) const;
991de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor
992de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  /// \brief Dump a representation of this initialization sequence to
993de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  /// standard error, for debugging purposes.
994de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  void dump() const;
99520093b4bf698f292c664676987541d5103b65b15Douglas Gregor};
99620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
99720093b4bf698f292c664676987541d5103b65b15Douglas Gregor} // end namespace clang
99820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
999e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#endif // LLVM_CLANG_SEMA_INITIALIZATION_H
1000