A union can have a constexpr defaulted default constructor, if it has an
in-class initializer for one of its fields. Value-initialization of such
a type should use the in-class initializer!
The former was just a bug, the latter is a (reported) standard defect.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156274 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/CXX/special/class.ctor/p6-0x.cpp b/test/CXX/special/class.ctor/p6-0x.cpp
index 8c8800f..9860317 100644
--- a/test/CXX/special/class.ctor/p6-0x.cpp
+++ b/test/CXX/special/class.ctor/p6-0x.cpp
@@ -55,3 +55,42 @@
struct B {
friend A::A(); // expected-error {{non-constexpr declaration of 'A' follows constexpr declaration}}
};
+
+namespace UnionCtors {
+ union A { // expected-note {{here}}
+ int a;
+ int b;
+ };
+ union B {
+ int a;
+ int b = 5;
+ };
+ union C {
+ int a = 5;
+ int b;
+ };
+ struct D {
+ union {
+ int a = 5;
+ int b;
+ };
+ union {
+ int c;
+ int d = 5;
+ };
+ };
+ struct E { // expected-note {{here}}
+ union {
+ int a;
+ int b;
+ };
+ };
+
+ struct Test {
+ friend constexpr A::A() noexcept; // expected-error {{follows non-constexpr declaration}}
+ friend constexpr B::B() noexcept;
+ friend constexpr C::C() noexcept;
+ friend constexpr D::D() noexcept;
+ friend constexpr E::E() noexcept; // expected-error {{follows non-constexpr declaration}}
+ };
+}
diff --git a/test/CodeGenCXX/const-init-cxx11.cpp b/test/CodeGenCXX/const-init-cxx11.cpp
index 62a345a..d1b91ba 100644
--- a/test/CodeGenCXX/const-init-cxx11.cpp
+++ b/test/CodeGenCXX/const-init-cxx11.cpp
@@ -49,6 +49,17 @@
// CHECK: @_ZN11StructUnion1fE = global {{.*}} { i32 5 }
D f;
+
+ union E {
+ int a;
+ void *b = &f;
+ };
+
+ // CHECK: @_ZN11StructUnion1gE = global {{.*}} @_ZN11StructUnion1fE
+ E g;
+
+ // CHECK: @_ZN11StructUnion1hE = global {{.*}} @_ZN11StructUnion1fE
+ E h = E();
}
namespace BaseClass {
diff --git a/test/CodeGenCXX/member-init-anon-union.cpp b/test/CodeGenCXX/member-init-anon-union.cpp
index 1ff7537..4db31f0 100644
--- a/test/CodeGenCXX/member-init-anon-union.cpp
+++ b/test/CodeGenCXX/member-init-anon-union.cpp
@@ -2,8 +2,10 @@
// PR10531.
+int make_a();
+
static union {
- int a = 42;
+ int a = make_a();
char *b;
};
@@ -32,4 +34,4 @@
// CHECK: define {{.*}}@"[[CONSTRUCT_GLOBAL]]C2Ev"
// CHECK-NOT: }
-// CHECK: store i32 42
+// CHECK: call {{.*}}@_Z6make_a