summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2012-07-31 22:40:31 +0000
committerAaron Ballman <aaron@aaronballman.com>2012-07-31 22:40:31 +0000
commit5121781d756e7814168b4255a57545d5ca497ec3 (patch)
tree8207185582a4dc572ac3921c9a3a7a97d4fa65ae
parent96b098674908eaa59a9128f3305cda6fbbdad563 (diff)
Explicitly defaulted constructors cannot be used for default initialization.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161088 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaInit.cpp2
-rw-r--r--test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp16
-rw-r--r--test/SemaCXX/cxx0x-cursory-default-delete.cpp5
3 files changed, 17 insertions, 6 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index cab7661898..27d58b2310 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -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;
}
diff --git a/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp b/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
index a4dffda1f9..783aba1823 100644
--- a/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
+++ b/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
@@ -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}}
+ }
+}
diff --git a/test/SemaCXX/cxx0x-cursory-default-delete.cpp b/test/SemaCXX/cxx0x-cursory-default-delete.cpp
index f00297332a..641760e7e5 100644
--- a/test/SemaCXX/cxx0x-cursory-default-delete.cpp
+++ b/test/SemaCXX/cxx0x-cursory-default-delete.cpp
@@ -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}}
};
@@ -69,7 +70,7 @@ struct except_spec_d_mismatch : except_spec_a, except_spec_b {
};
struct except_spec_d_match : except_spec_a, except_spec_b {
except_spec_d_match() throw(A, B) = default;
-};
+};
// gcc-compatibility: allow attributes on default definitions
// (but not normal definitions)