aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-12-22 22:17:25 +0000
committerDouglas Gregor <dgregor@apple.com>2009-12-22 22:17:25 +0000
commit90f9382b3e97afa55e6aaaa4ab31c7473a8c7bb9 (patch)
treec332ccc4b54b3b5cc4a878b951f352fc064ac022
parent38ac4f504bf8ed514520b5a82be538bdb0860687 (diff)
Switch Sema::AddCXXDirectInitializerToDecl over to InitializationSequence
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91927 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/Sema.h2
-rw-r--r--lib/Sema/SemaDeclCXX.cpp67
-rw-r--r--lib/Sema/SemaExprCXX.cpp8
-rw-r--r--test/CXX/basic/basic.lookup/basic.lookup.unqual/p14.cpp2
-rw-r--r--test/SemaCXX/copy-constructor-error.cpp7
-rw-r--r--test/SemaCXX/default2.cpp4
-rw-r--r--test/SemaCXX/direct-initializer.cpp2
-rw-r--r--utils/C++Tests/LLVM-Code-Compile/lit.local.cfg1
-rw-r--r--utils/C++Tests/LLVM-Code-Syntax/lit.local.cfg1
9 files changed, 50 insertions, 44 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 2d86b5e1b6..87a33642a0 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -1985,7 +1985,7 @@ public:
/// non-empty, will create a new CXXExprWithTemporaries expression.
/// Otherwise, just returs the passed in expression.
Expr *MaybeCreateCXXExprWithTemporaries(Expr *SubExpr);
-
+ OwningExprResult MaybeCreateCXXExprWithTemporaries(OwningExprResult SubExpr);
FullExpr CreateFullExpr(Expr *SubExpr);
virtual OwningExprResult ActOnFinishFullExpr(ExprArg Expr);
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index dfb3532810..9e30af8f18 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -3927,53 +3927,50 @@ void Sema::AddCXXDirectInitializerToDecl(DeclPtrTy Dcl,
if (const ArrayType *Array = Context.getAsArrayType(DeclInitType))
DeclInitType = Context.getBaseElementType(Array);
- // FIXME: This isn't the right place to complete the type.
if (RequireCompleteType(VDecl->getLocation(), VDecl->getType(),
diag::err_typecheck_decl_incomplete_type)) {
VDecl->setInvalidDecl();
return;
}
- if (VDecl->getType()->isRecordType()) {
- ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(*this);
-
- CXXConstructorDecl *Constructor
- = PerformInitializationByConstructor(DeclInitType,
- move(Exprs),
- VDecl->getLocation(),
- SourceRange(VDecl->getLocation(),
- RParenLoc),
- VDecl->getDeclName(),
- InitializationKind::CreateDirect(VDecl->getLocation(),
- LParenLoc,
- RParenLoc),
- ConstructorArgs);
- if (!Constructor)
- RealDecl->setInvalidDecl();
- else {
- VDecl->setCXXDirectInitializer(true);
- if (InitializeVarWithConstructor(VDecl, Constructor,
- move_arg(ConstructorArgs)))
- RealDecl->setInvalidDecl();
- FinalizeVarWithDestructor(VDecl, DeclInitType);
- }
+ // The variable can not have an abstract class type.
+ if (RequireNonAbstractType(VDecl->getLocation(), VDecl->getType(),
+ diag::err_abstract_type_in_decl,
+ AbstractVariableType))
+ VDecl->setInvalidDecl();
+
+ const VarDecl *Def = 0;
+ if (VDecl->getDefinition(Def)) {
+ Diag(VDecl->getLocation(), diag::err_redefinition)
+ << VDecl->getDeclName();
+ Diag(Def->getLocation(), diag::note_previous_definition);
+ VDecl->setInvalidDecl();
return;
}
-
- if (NumExprs > 1) {
- Diag(CommaLocs[0], diag::err_builtin_direct_init_more_than_one_arg)
- << SourceRange(VDecl->getLocation(), RParenLoc);
- RealDecl->setInvalidDecl();
+
+ // Capture the variable that is being initialized and the style of
+ // initialization.
+ InitializedEntity Entity = InitializedEntity::InitializeVariable(VDecl);
+
+ // FIXME: Poor source location information.
+ InitializationKind Kind
+ = InitializationKind::CreateDirect(VDecl->getLocation(),
+ LParenLoc, RParenLoc);
+
+ InitializationSequence InitSeq(*this, Entity, Kind,
+ (Expr**)Exprs.get(), Exprs.size());
+ OwningExprResult Result = InitSeq.Perform(*this, Entity, Kind, move(Exprs));
+ if (Result.isInvalid()) {
+ VDecl->setInvalidDecl();
return;
}
-
- // Let clients know that initialization was done with a direct initializer.
+
+ Result = MaybeCreateCXXExprWithTemporaries(move(Result));
+ VDecl->setInit(Context, Result.takeAs<Expr>());
VDecl->setCXXDirectInitializer(true);
- assert(NumExprs == 1 && "Expected 1 expression");
- // Set the init expression, handles conversions.
- AddInitializerToDecl(Dcl, ExprArg(*this, Exprs.release()[0]),
- /*DirectInit=*/true);
+ if (VDecl->getType()->getAs<RecordType>())
+ FinalizeVarWithDestructor(VDecl, DeclInitType);
}
/// \brief Add the applicable constructor candidates for an initialization
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index 92a94daea6..dd3d2ea2ce 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -2097,6 +2097,14 @@ Expr *Sema::MaybeCreateCXXExprWithTemporaries(Expr *SubExpr) {
return E;
}
+Sema::OwningExprResult
+Sema::MaybeCreateCXXExprWithTemporaries(OwningExprResult SubExpr) {
+ if (SubExpr.isInvalid())
+ return ExprError();
+
+ return Owned(MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>()));
+}
+
FullExpr Sema::CreateFullExpr(Expr *SubExpr) {
unsigned FirstTemporary = ExprEvalContexts.back().NumTemporaries;
assert(ExprTemporaries.size() >= FirstTemporary);
diff --git a/test/CXX/basic/basic.lookup/basic.lookup.unqual/p14.cpp b/test/CXX/basic/basic.lookup/basic.lookup.unqual/p14.cpp
index 2ed87b4e68..0fa4f650b0 100644
--- a/test/CXX/basic/basic.lookup/basic.lookup.unqual/p14.cpp
+++ b/test/CXX/basic/basic.lookup/basic.lookup.unqual/p14.cpp
@@ -15,4 +15,4 @@ namespace N {
int i = 2;
N::S N::j = i;
-N::S N::j(i);
+N::S N::j2(i);
diff --git a/test/SemaCXX/copy-constructor-error.cpp b/test/SemaCXX/copy-constructor-error.cpp
index bdf635d02f..9cae77504b 100644
--- a/test/SemaCXX/copy-constructor-error.cpp
+++ b/test/SemaCXX/copy-constructor-error.cpp
@@ -1,13 +1,12 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
-struct S { // expected-note {{candidate function}}
- S (S); // expected-error {{copy constructor must pass its first argument by reference}} \\
- // expected-note {{candidate function}}
+struct S {
+ S (S); // expected-error {{copy constructor must pass its first argument by reference}}
};
S f();
void g() {
- S a( f() ); // expected-error {{call to constructor of 'a' is ambiguous}}
+ S a( f() );
}
diff --git a/test/SemaCXX/default2.cpp b/test/SemaCXX/default2.cpp
index eda4be2919..880255e453 100644
--- a/test/SemaCXX/default2.cpp
+++ b/test/SemaCXX/default2.cpp
@@ -90,12 +90,12 @@ public:
}
void test_Z(const Z& z) {
- Z z2(z); // expected-error{{no matching constructor for initialization of 'z2'}}
+ Z z2(z); // expected-error{{no matching constructor for initialization of 'class Z'}}
}
};
void test_Z(const Z& z) {
- Z z2(z); // expected-error{{no matching constructor for initialization of 'z2'}}
+ Z z2(z); // expected-error{{no matching constructor for initialization of 'class Z'}}
}
struct ZZ {
diff --git a/test/SemaCXX/direct-initializer.cpp b/test/SemaCXX/direct-initializer.cpp
index 1a87a3edf3..03a5da3a30 100644
--- a/test/SemaCXX/direct-initializer.cpp
+++ b/test/SemaCXX/direct-initializer.cpp
@@ -28,7 +28,7 @@ public:
void g() {
X x1(5);
X x2(1.0, 3, 4.2);
- X x3(1.0, 1.0); // expected-error{{no matching constructor for initialization of 'x3'; candidates are:}}
+ X x3(1.0, 1.0); // expected-error{{no matching constructor for initialization of 'class X'}}
Y y(1.0);
X x4(3.14, y);
diff --git a/utils/C++Tests/LLVM-Code-Compile/lit.local.cfg b/utils/C++Tests/LLVM-Code-Compile/lit.local.cfg
index 6676e311e3..b9931144a3 100644
--- a/utils/C++Tests/LLVM-Code-Compile/lit.local.cfg
+++ b/utils/C++Tests/LLVM-Code-Compile/lit.local.cfg
@@ -11,6 +11,7 @@ root = getRoot(config)
# testFormat: The test format to use to interpret tests.
target_obj_root = root.llvm_obj_root
+target_obj_root = '/Users/dgregor/Projects/llvm-build-autotools'
cxxflags = ['-D__STDC_LIMIT_MACROS',
'-D__STDC_CONSTANT_MACROS',
'-Wno-sign-compare',
diff --git a/utils/C++Tests/LLVM-Code-Syntax/lit.local.cfg b/utils/C++Tests/LLVM-Code-Syntax/lit.local.cfg
index 6e679659c4..edcd266fe5 100644
--- a/utils/C++Tests/LLVM-Code-Syntax/lit.local.cfg
+++ b/utils/C++Tests/LLVM-Code-Syntax/lit.local.cfg
@@ -11,6 +11,7 @@ root = getRoot(config)
# testFormat: The test format to use to interpret tests.
target_obj_root = root.llvm_obj_root
+target_obj_root = '/Users/dgregor/Projects/llvm-build-autotools'
cxxflags = ['-D__STDC_LIMIT_MACROS',
'-D__STDC_CONSTANT_MACROS',
'-I%s/include' % root.llvm_src_root,