diff options
author | Nico Weber <nicolasweber@gmx.de> | 2016-02-24 20:58:14 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2016-02-24 20:58:14 +0000 |
commit | 2f89cf41352f6e87f68f12ff25466970482729e3 (patch) | |
tree | a15c6f6640096644cfc22c0c36ea788b051943a6 /test/SemaCXX/cxx0x-cursory-default-delete.cpp | |
parent | 209acc3e3dae1499aca767441406403f77ccc8ee (diff) | |
download | clang-2f89cf41352f6e87f68f12ff25466970482729e3.tar.gz |
Fix rejects-valid caused by r261297.
r261297 called hasUserProvidedDefaultConstructor() to check if defining a
const object is ok. This is incorrect for this example:
struct X { template<typename ...T> X(T...); int n; };
const X x; // formerly OK, now bogus error
Instead, track if a class has a defaulted default constructor, and disallow
a const object for classes that either have defaulted default constructors or
if they need an implicit constructor.
Bug report and fix approach by Richard Smith, thanks!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@261770 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/cxx0x-cursory-default-delete.cpp')
-rw-r--r-- | test/SemaCXX/cxx0x-cursory-default-delete.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/SemaCXX/cxx0x-cursory-default-delete.cpp b/test/SemaCXX/cxx0x-cursory-default-delete.cpp index f671bd190e..17215fedf0 100644 --- a/test/SemaCXX/cxx0x-cursory-default-delete.cpp +++ b/test/SemaCXX/cxx0x-cursory-default-delete.cpp @@ -74,6 +74,33 @@ struct some_init_container_ctor { struct no_fields_container { no_fields nf; }; +struct param_pack_ctor { + template <typename... T> + param_pack_ctor(T...); + int n; +}; +struct param_pack_ctor_field { + param_pack_ctor ndc; +}; +struct multi_param_pack_ctor { + template <typename... T, typename... U> + multi_param_pack_ctor(T..., U..., int f = 0); + int n; +}; +struct ignored_template_ctor_and_def { + template <class T> ignored_template_ctor_and_def(T* f = nullptr); + ignored_template_ctor_and_def() = default; + int field; +}; +template<bool, typename = void> struct enable_if {}; +template<typename T> struct enable_if<true, T> { typedef T type; }; +struct multi_param_pack_and_defaulted { + template <typename... T, + typename enable_if<sizeof...(T) != 0>::type* = nullptr> + multi_param_pack_and_defaulted(T...); + multi_param_pack_and_defaulted() = default; + int n; +}; void constobjs() { const no_fields nf; // ok @@ -88,6 +115,12 @@ void constobjs() { const some_init_container sicon; // expected-error {{default initialization of an object of const type 'const some_init_container' without a user-provided default constructor}} const some_init_container_ctor siconc; // ok const no_fields_container nfc; // ok + const param_pack_ctor ppc; // ok + const param_pack_ctor_field ppcf; // ok + const multi_param_pack_ctor mppc; // ok + const multi_param_pack_and_defaulted mppad; // expected-error {{default initialization of an object of const type 'const multi_param_pack_and_defaulted' without a user-provided default constructor}} + const ignored_template_ctor_and_def itcad; // expected-error {{default initialization of an object of const type 'const ignored_template_ctor_and_def' without a user-provided default constructor}} + } struct non_const_derived : non_const_copy { |