Explicitly defaulted constructors cannot be used for default initialization.

llvm-svn: 161088
This commit is contained in:
Aaron Ballman 2012-07-31 22:40:31 +00:00
parent 34df220410
commit 899b9c6666
3 changed files with 17 additions and 6 deletions

View File

@ -2906,7 +2906,7 @@ static void TryConstructorInitialization(Sema &S,
// user-provided default constructor.
if (Kind.getKind() == InitializationKind::IK_Default &&
Entity.getType().isConstQualified() &&
cast<CXXConstructorDecl>(Best->Function)->isImplicit()) {
!cast<CXXConstructorDecl>(Best->Function)->isUserProvided()) {
Sequence.SetFailed(InitializationSequence::FK_DefaultInitOfConst);
return;
}

View File

@ -27,7 +27,7 @@ struct S2 {
// -- it is implicitly considered to be constexpr if the implicit declaration
// would be
struct S3 {
S3() = default; // expected-note {{here}}
S3() = default;
S3(const S3&) = default;
S3(S3&&) = default;
constexpr S3(int n) : n(n) {}
@ -36,7 +36,7 @@ struct S3 {
constexpr S3 s3a = S3(0);
constexpr S3 s3b = s3a;
constexpr S3 s3c = S3();
constexpr S3 s3d; // expected-error {{constant expression}} expected-note {{non-constexpr constructor}}
constexpr S3 s3d; // expected-error {{default initialization of an object of const type 'const S3' requires a user-provided default constructor}}
struct S4 {
S4() = default;
@ -44,7 +44,7 @@ struct S4 {
S4(S4&&) = default; // expected-note {{here}}
NoCopyMove ncm;
};
constexpr S4 s4a; // ok
constexpr S4 s4a{}; // ok
constexpr S4 s4b = S4(); // expected-error {{constant expression}} expected-note {{non-constexpr constructor}}
constexpr S4 s4c = s4a; // expected-error {{constant expression}} expected-note {{non-constexpr constructor}}
@ -112,3 +112,13 @@ static_assert(!noexcept(E5(static_cast<E5&&>(e5))), "");
static_assert(!noexcept(E5(e5)), "");
static_assert(!noexcept(e5 = E5()), "");
static_assert(!noexcept(e5 = e5), "");
namespace PR13492 {
struct B {
B() = default;
};
void f() {
const B b; // expected-error {{default initialization of an object of const type 'const PR13492::B' requires a user-provided default constructor}}
}
}

View File

@ -24,7 +24,8 @@ void fn1 () {
non_const_copy ncc;
non_const_copy ncc2 = ncc;
ncc = ncc2;
const non_const_copy cncc;
const non_const_copy cncc{};
const non_const_copy cncc1; // expected-error {{default initialization of an object of const type 'const non_const_copy' requires a user-provided default constructor}}
non_const_copy ncc3 = cncc; // expected-error {{no matching}}
ncc = cncc; // expected-error {{no viable overloaded}}
};