]> granicus.if.org Git - clang/commitdiff
Explicitly defaulted constructors cannot be used for default initialization.
authorAaron Ballman <aaron@aaronballman.com>
Tue, 31 Jul 2012 22:40:31 +0000 (22:40 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Tue, 31 Jul 2012 22:40:31 +0000 (22:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161088 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaInit.cpp
test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
test/SemaCXX/cxx0x-cursory-default-delete.cpp

index cab7661898b94d6dfd6bfd91129476da6be458f3..27d58b23101bfede6f5ecd2a2784f83f401109cf 100644 (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;
   }
index a4dffda1f9aa7ba99ae4c9e58c53b3e338e8f99b..783aba182319542262c62bd4d0467dffaf1a9e5e 100644 (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}}
+  }
+}
index f00297332a54625b94033fddf355159cd4f57bf8..641760e7e54016629d0e297bdb033e1fbfb28a09 100644 (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}}
 };
@@ -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)