aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/AST/ExprCXX.h20
-rw-r--r--lib/AST/ExprCXX.cpp11
-rw-r--r--lib/Sema/Sema.h26
-rw-r--r--lib/Sema/SemaDeclCXX.cpp8
-rw-r--r--lib/Sema/SemaInit.cpp13
5 files changed, 50 insertions, 28 deletions
diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h
index d26efa7296..250e09af53 100644
--- a/include/clang/AST/ExprCXX.h
+++ b/include/clang/AST/ExprCXX.h
@@ -630,12 +630,20 @@ public:
/// CXXConstructExpr - Represents a call to a C++ constructor.
class CXXConstructExpr : public Expr {
+public:
+ enum ConstructionKind {
+ CK_Complete,
+ CK_NonVirtualBase,
+ CK_VirtualBase
+ };
+
+private:
CXXConstructorDecl *Constructor;
SourceLocation Loc;
bool Elidable : 1;
bool ZeroInitialization : 1;
- bool BaseInitialization : 1;
+ unsigned ConstructKind : 2;
Stmt **Args;
unsigned NumArgs;
@@ -645,7 +653,7 @@ protected:
CXXConstructorDecl *d, bool elidable,
Expr **args, unsigned numargs,
bool ZeroInitialization = false,
- bool BaseInitialization = false);
+ ConstructionKind ConstructKind = CK_Complete);
~CXXConstructExpr() { }
virtual void DoDestroy(ASTContext &C);
@@ -682,8 +690,12 @@ public:
/// \brief Determines whether this constructor is actually constructing
/// a base class (rather than a complete object).
- bool isBaseInitialization() const { return BaseInitialization; }
- void setBaseInitialization(bool BI) { BaseInitialization = BI; }
+ bool isBaseInitialization() const {
+ return ConstructKind != CK_Complete;
+ }
+ void setConstructionKind(ConstructionKind CK) {
+ ConstructKind = CK;
+ }
typedef ExprIterator arg_iterator;
typedef ConstExprIterator const_arg_iterator;
diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp
index 592d887d31..1b94aa0ca3 100644
--- a/lib/AST/ExprCXX.cpp
+++ b/lib/AST/ExprCXX.cpp
@@ -474,22 +474,23 @@ CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T,
bool BaseInitialization) {
return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D,
Elidable, Args, NumArgs, ZeroInitialization,
- BaseInitialization);
+ BaseInitialization ? CK_NonVirtualBase :
+ CK_Complete);
}
CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
SourceLocation Loc,
CXXConstructorDecl *D, bool elidable,
Expr **args, unsigned numargs,
- bool ZeroInitialization,
- bool BaseInitialization)
+ bool ZeroInitialization,
+ ConstructionKind ConstructKind)
: Expr(SC, T,
T->isDependentType(),
(T->isDependentType() ||
CallExpr::hasAnyValueDependentArguments(args, numargs))),
Constructor(D), Loc(Loc), Elidable(elidable),
- ZeroInitialization(ZeroInitialization),
- BaseInitialization(BaseInitialization), Args(0), NumArgs(numargs)
+ ZeroInitialization(ZeroInitialization), ConstructKind(ConstructKind),
+ Args(0), NumArgs(numargs)
{
if (NumArgs) {
Args = new (C) Stmt*[NumArgs];
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 1c82baf617..8a9be3ab01 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -25,6 +25,7 @@
#include "clang/AST/Decl.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
#include "clang/AST/FullExpr.h"
#include "clang/Parse/Action.h"
#include "clang/Sema/SemaDiagnostic.h"
@@ -2140,22 +2141,21 @@ public:
/// BuildCXXConstructExpr - Creates a complete call to a constructor,
/// including handling of its default argument expressions.
- OwningExprResult BuildCXXConstructExpr(SourceLocation ConstructLoc,
- QualType DeclInitType,
- CXXConstructorDecl *Constructor,
- MultiExprArg Exprs,
- bool RequiresZeroInit = false,
- bool BaseInitialization = false);
+ OwningExprResult
+ BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
+ CXXConstructorDecl *Constructor, MultiExprArg Exprs,
+ bool RequiresZeroInit = false,
+ CXXConstructExpr::ConstructionKind ConstructKind =
+ CXXConstructExpr::CK_Complete);
// FIXME: Can re remove this and have the above BuildCXXConstructExpr check if
// the constructor can be elidable?
- OwningExprResult BuildCXXConstructExpr(SourceLocation ConstructLoc,
- QualType DeclInitType,
- CXXConstructorDecl *Constructor,
- bool Elidable,
- MultiExprArg Exprs,
- bool RequiresZeroInit = false,
- bool BaseInitialization = false);
+ OwningExprResult
+ BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
+ CXXConstructorDecl *Constructor, bool Elidable,
+ MultiExprArg Exprs, bool RequiresZeroInit = false,
+ CXXConstructExpr::ConstructionKind ConstructKind =
+ CXXConstructExpr::CK_Complete);
/// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating
/// the default expr if needed.
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index e4a154d400..d628d44077 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -4579,7 +4579,7 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
CXXConstructorDecl *Constructor,
MultiExprArg ExprArgs,
bool RequiresZeroInit,
- bool BaseInitialization) {
+ CXXConstructExpr::ConstructionKind ConstructKind) {
bool Elidable = false;
// C++0x [class.copy]p34:
@@ -4601,7 +4601,7 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
return BuildCXXConstructExpr(ConstructLoc, DeclInitType, Constructor,
Elidable, move(ExprArgs), RequiresZeroInit,
- BaseInitialization);
+ ConstructKind);
}
/// BuildCXXConstructExpr - Creates a complete call to a constructor,
@@ -4611,14 +4611,14 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
CXXConstructorDecl *Constructor, bool Elidable,
MultiExprArg ExprArgs,
bool RequiresZeroInit,
- bool BaseInitialization) {
+ CXXConstructExpr::ConstructionKind ConstructKind) {
unsigned NumExprs = ExprArgs.size();
Expr **Exprs = (Expr **)ExprArgs.release();
MarkDeclarationReferenced(ConstructLoc, Constructor);
return Owned(CXXConstructExpr::Create(Context, DeclInitType, ConstructLoc,
Constructor, Elidable, Exprs, NumExprs,
- RequiresZeroInit, BaseInitialization));
+ RequiresZeroInit, ConstructKind));
}
bool Sema::InitializeVarWithConstructor(VarDecl *VD,
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index 4678822413..5e6aa2c0a6 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -3747,12 +3747,21 @@ InitializationSequence::Perform(Sema &S,
NumExprs,
Kind.getParenRange().getEnd(),
ConstructorInitRequiresZeroInit));
- } else
+ } else {
+ CXXConstructExpr::ConstructionKind ConstructKind =
+ CXXConstructExpr::CK_Complete;
+
+ if (Entity.getKind() == InitializedEntity::EK_Base) {
+ ConstructKind = Entity.getBaseSpecifier()->isVirtual() ?
+ CXXConstructExpr::CK_VirtualBase :
+ CXXConstructExpr::CK_NonVirtualBase;
+ }
CurInit = S.BuildCXXConstructExpr(Loc, Entity.getType(),
Constructor,
move_arg(ConstructorArgs),
ConstructorInitRequiresZeroInit,
- Entity.getKind() == InitializedEntity::EK_Base);
+ ConstructKind);
+ }
if (CurInit.isInvalid())
return S.ExprError();