summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2016-02-19 01:52:46 +0000
committerNico Weber <nicolasweber@gmx.de>2016-02-19 01:52:46 +0000
commit6a6376b17cdf6c0adf8e52a298beff75079d932a (patch)
tree28db16259c8b63d08c36b6519f9503652f35b37f /clang/test/SemaCXX
parent74f5b282110eb6a548f93738e67b707d654b0882 (diff)
downloadbcm5719-llvm-6a6376b17cdf6c0adf8e52a298beff75079d932a.tar.gz
bcm5719-llvm-6a6376b17cdf6c0adf8e52a298beff75079d932a.zip
Implement the likely resolution of core issue 253.
C++11 requires const objects to have a user-provided constructor, even for classes without any fields. DR 253 relaxes this to say "If the implicit default constructor initializes all subobjects, no initializer should be required." clang is currently the only compiler that implements this C++11 rule, and e.g. libstdc++ relies on something like DR 253 to compile in newer versions. This change makes it possible to build code that says `const vector<int> v;' again when using libstdc++5.2 and _GLIBCXX_DEBUG (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60284). Fixes PR23381. http://reviews.llvm.org/D16552 llvm-svn: 261297
Diffstat (limited to 'clang/test/SemaCXX')
-rw-r--r--clang/test/SemaCXX/attr-selectany.cpp4
-rw-r--r--clang/test/SemaCXX/constexpr-value-init.cpp2
-rw-r--r--clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp60
-rw-r--r--clang/test/SemaCXX/illegal-member-initialization.cpp1
4 files changed, 65 insertions, 2 deletions
diff --git a/clang/test/SemaCXX/attr-selectany.cpp b/clang/test/SemaCXX/attr-selectany.cpp
index 058f2fcb84a..9dc14b3c381 100644
--- a/clang/test/SemaCXX/attr-selectany.cpp
+++ b/clang/test/SemaCXX/attr-selectany.cpp
@@ -39,7 +39,9 @@ __declspec(selectany) auto x8 = Internal(); // expected-error {{'selectany' can
// The D3D11 headers do something like this. MSVC doesn't error on this at
// all, even without the __declspec(selectany), in violation of the standard.
// We fall back to a warning for selectany to accept headers.
-struct SomeStruct {};
+struct SomeStruct {
+ int foo;
+};
extern const __declspec(selectany) SomeStruct some_struct; // expected-warning {{default initialization of an object of const type 'const SomeStruct' without a user-provided default constructor is a Microsoft extension}}
// It should be possible to redeclare variables that were defined
diff --git a/clang/test/SemaCXX/constexpr-value-init.cpp b/clang/test/SemaCXX/constexpr-value-init.cpp
index 06511113355..3528fdcd881 100644
--- a/clang/test/SemaCXX/constexpr-value-init.cpp
+++ b/clang/test/SemaCXX/constexpr-value-init.cpp
@@ -14,7 +14,7 @@ void f() {
constexpr A a; // expected-error {{constant expression}} expected-note {{in call to 'A()'}}
}
-constexpr B b1; // expected-error {{without a user-provided default constructor}}
+constexpr B b1; // ok
constexpr B b2 = B(); // ok
static_assert(b2.a.a == 1, "");
static_assert(b2.a.b == 2, "");
diff --git a/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp b/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp
index dfca17ad7cd..f671bd190ec 100644
--- a/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp
+++ b/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp
@@ -11,6 +11,7 @@ struct non_const_copy {
non_const_copy& operator = (non_const_copy&) &;
non_const_copy& operator = (non_const_copy&) &&;
non_const_copy() = default; // expected-note {{not viable}}
+ int uninit_field;
};
non_const_copy::non_const_copy(non_const_copy&) = default; // expected-note {{not viable}}
non_const_copy& non_const_copy::operator = (non_const_copy&) & = default; // expected-note {{not viable}}
@@ -30,6 +31,65 @@ void fn1 () {
ncc = cncc; // expected-error {{no viable overloaded}}
};
+struct no_fields { };
+struct all_init {
+ int a = 0;
+ int b = 0;
+};
+struct some_init {
+ int a = 0;
+ int b;
+ int c = 0;
+};
+struct some_init_mutable {
+ int a = 0;
+ mutable int b;
+ int c = 0;
+};
+struct some_init_def {
+ some_init_def() = default;
+ int a = 0;
+ int b;
+ int c = 0;
+};
+struct some_init_ctor {
+ some_init_ctor();
+ int a = 0;
+ int b;
+ int c = 0;
+};
+struct sub_some_init : public some_init_def { };
+struct sub_some_init_ctor : public some_init_def {
+ sub_some_init_ctor();
+};
+struct sub_some_init_ctor2 : public some_init_ctor {
+};
+struct some_init_container {
+ some_init_def sid;
+};
+struct some_init_container_ctor {
+ some_init_container_ctor();
+ some_init_def sid;
+};
+struct no_fields_container {
+ no_fields nf;
+};
+
+void constobjs() {
+ const no_fields nf; // ok
+ const all_init ai; // ok
+ const some_init si; // expected-error {{default initialization of an object of const type 'const some_init' without a user-provided default constructor}}
+ const some_init_mutable sim; // ok
+ const some_init_def sid; // expected-error {{default initialization of an object of const type 'const some_init_def' without a user-provided default constructor}}
+ const some_init_ctor sic; // ok
+ const sub_some_init ssi; // expected-error {{default initialization of an object of const type 'const sub_some_init' without a user-provided default constructor}}
+ const sub_some_init_ctor ssic; // ok
+ const sub_some_init_ctor2 ssic2; // ok
+ 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
+}
+
struct non_const_derived : non_const_copy {
non_const_derived(const non_const_derived&) = default; // expected-error {{requires it to be non-const}}
non_const_derived& operator =(non_const_derived&) = default;
diff --git a/clang/test/SemaCXX/illegal-member-initialization.cpp b/clang/test/SemaCXX/illegal-member-initialization.cpp
index 87069efaacc..17faed7eff7 100644
--- a/clang/test/SemaCXX/illegal-member-initialization.cpp
+++ b/clang/test/SemaCXX/illegal-member-initialization.cpp
@@ -7,6 +7,7 @@ struct A {
};
struct B {
+ int field;
};
struct X {
OpenPOWER on IntegriCloud