diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index cab7661898b9..27d58b23101b 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/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(Best->Function)->isImplicit()) { + !cast(Best->Function)->isUserProvided()) { Sequence.SetFailed(InitializationSequence::FK_DefaultInitOfConst); return; } diff --git a/clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp b/clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp index a4dffda1f9aa..783aba182319 100644 --- a/clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp +++ b/clang/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))), ""); 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/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp b/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp index f00297332a54..641760e7e540 100644 --- a/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp +++ b/clang/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)