summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/constant-expression-cxx2a.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/SemaCXX/constant-expression-cxx2a.cpp')
-rw-r--r--clang/test/SemaCXX/constant-expression-cxx2a.cpp119
1 files changed, 0 insertions, 119 deletions
diff --git a/clang/test/SemaCXX/constant-expression-cxx2a.cpp b/clang/test/SemaCXX/constant-expression-cxx2a.cpp
index dba877ff211..cc6b1960481 100644
--- a/clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -414,125 +414,6 @@ namespace TypeId {
static_assert(side_effects());
}
-namespace Union {
- struct Base {
- int y; // expected-note {{here}}
- };
- struct A : Base {
- int x;
- int arr[3];
- union { int p, q; };
- };
- union B {
- A a;
- int b;
- };
- constexpr int read_wrong_member() { // expected-error {{never produces a constant}}
- B b = {.b = 1};
- return b.a.x; // expected-note {{read of member 'a' of union with active member 'b'}}
- }
- constexpr int change_member() {
- B b = {.b = 1};
- b.a.x = 1;
- return b.a.x;
- }
- static_assert(change_member() == 1);
- constexpr int change_member_then_read_wrong_member() { // expected-error {{never produces a constant}}
- B b = {.b = 1};
- b.a.x = 1;
- return b.b; // expected-note {{read of member 'b' of union with active member 'a'}}
- }
- constexpr int read_wrong_member_indirect() { // expected-error {{never produces a constant}}
- B b = {.b = 1};
- int *p = &b.a.y;
- return *p; // expected-note {{read of member 'a' of union with active member 'b'}}
- }
- constexpr int read_uninitialized() {
- B b = {.b = 1};
- int *p = &b.a.y;
- b.a.x = 1;
- return *p; // expected-note {{read of uninitialized object}}
- }
- static_assert(read_uninitialized() == 0); // expected-error {{constant}} expected-note {{in call}}
- constexpr void write_wrong_member_indirect() { // expected-error {{never produces a constant}}
- B b = {.b = 1};
- int *p = &b.a.y;
- *p = 1; // expected-note {{assignment to member 'a' of union with active member 'b'}}
- }
- constexpr int write_uninitialized() {
- B b = {.b = 1};
- int *p = &b.a.y;
- b.a.x = 1;
- *p = 1;
- return *p;
- }
- static_assert(write_uninitialized() == 1);
- constexpr int change_member_indirectly() {
- B b = {.b = 1};
- b.a.arr[1] = 1;
- int &r = b.a.y;
- r = 123;
-
- b.b = 2;
- b.a.y = 3;
- b.a.arr[2] = 4;
- return b.a.arr[2];
- }
- static_assert(change_member_indirectly() == 4);
- constexpr B return_uninit() {
- B b = {.b = 1};
- b.a.x = 2;
- return b;
- }
- constexpr B uninit = return_uninit(); // expected-error {{constant expression}} expected-note {{subobject of type 'int' is not initialized}}
- static_assert(return_uninit().a.x == 2);
- constexpr A return_uninit_struct() {
- B b = {.b = 1};
- b.a.x = 2;
- return b.a;
- }
- // FIXME: It's unclear that this should be valid. Copying a B involves
- // copying the object representation of the union, but copying an A invokes a
- // copy constructor that copies the object elementwise, and reading from
- // b.a.y is undefined.
- static_assert(return_uninit_struct().x == 2);
- constexpr B return_init_all() {
- B b = {.b = 1};
- b.a.x = 2;
- b.a.y = 3;
- b.a.arr[0] = 4;
- b.a.arr[1] = 5;
- b.a.arr[2] = 6;
- return b;
- }
- static_assert(return_init_all().a.x == 2);
- static_assert(return_init_all().a.y == 3);
- static_assert(return_init_all().a.arr[0] == 4);
- static_assert(return_init_all().a.arr[1] == 5);
- static_assert(return_init_all().a.arr[2] == 6);
- static_assert(return_init_all().a.p == 7); // expected-error {{}} expected-note {{read of member 'p' of union with no active member}}
- static_assert(return_init_all().a.q == 8); // expected-error {{}} expected-note {{read of member 'q' of union with no active member}}
- constexpr B init_all = return_init_all();
-
- constexpr bool test_no_member_change = []{
- union U { char dummy = {}; };
- U u1;
- U u2;
- u1 = u2;
- return true;
- }();
-
- struct S1 {
- int n;
- };
- struct S2 : S1 {};
- struct S3 : S2 {};
- void f() {
- S3 s;
- s.n = 0;
- }
-}
-
namespace TwosComplementShifts {
using uint32 = __UINT32_TYPE__;
using int32 = __INT32_TYPE__;
OpenPOWER on IntegriCloud