| 1 |
// PR c++/100252 |
| 2 |
// { dg-do run { target c++14 } } |
| 3 |
|
| 4 |
#define SA(X) static_assert ((X),#X) |
| 5 |
|
| 6 |
struct A { |
| 7 |
int x; |
| 8 |
int y = x; |
| 9 |
const A* p = this; |
| 10 |
}; |
| 11 |
|
| 12 |
struct B { |
| 13 |
int x = 42; |
| 14 |
A a = A{x}; |
| 15 |
}; |
| 16 |
|
| 17 |
constexpr B b; |
| 18 |
SA(b.a.p == &b.a); |
| 19 |
SA(b.x == 42); |
| 20 |
B b2 = { }; |
| 21 |
B b3 = { 42 }; |
| 22 |
|
| 23 |
struct C { |
| 24 |
int x = 42; |
| 25 |
B b = B{x}; |
| 26 |
}; |
| 27 |
|
| 28 |
constexpr C c; |
| 29 |
C c2; |
| 30 |
C c3; |
| 31 |
|
| 32 |
struct D { |
| 33 |
int x = 42; |
| 34 |
A a = (true, A{x}); |
| 35 |
}; |
| 36 |
|
| 37 |
constexpr D d; |
| 38 |
SA(d.a.p == &d.a); |
| 39 |
SA(d.x == 42); |
| 40 |
D d2 = { }; |
| 41 |
D d3 = { 42 }; |
| 42 |
|
| 43 |
struct E { |
| 44 |
int x = 42; |
| 45 |
A a = (A{x}); |
| 46 |
}; |
| 47 |
|
| 48 |
constexpr E e; |
| 49 |
SA(e.a.p == &e.a); |
| 50 |
SA(e.x == 42); |
| 51 |
E e2 = { }; |
| 52 |
E e3 = { 42 }; |
| 53 |
|
| 54 |
struct F { |
| 55 |
int x = 42; |
| 56 |
A a = true ? A{x} : A{x}; |
| 57 |
}; |
| 58 |
|
| 59 |
constexpr F f; |
| 60 |
SA (f.a.p == &f.a); |
| 61 |
SA (e.x == 42); |
| 62 |
F f2 = { }; |
| 63 |
F f3 = { 42 }; |
| 64 |
|
| 65 |
static void |
| 66 |
test_b (B b4 = B{}, B b5 = B{ 42 }) |
| 67 |
{ |
| 68 |
if (b2.x != 42 || b2.a.x != 42 || b2.a.y != b2.a.x) |
| 69 |
__builtin_abort (); |
| 70 |
if (b3.x != 42 || b3.a.x != 42 || b3.a.y != b3.a.x) |
| 71 |
__builtin_abort (); |
| 72 |
if (b4.x != 42 || b4.a.x != 42 || b4.a.y != b4.a.x) |
| 73 |
__builtin_abort (); |
| 74 |
if (b5.x != 42 || b5.a.x != 42 || b5.a.y != b5.a.x) |
| 75 |
__builtin_abort (); |
| 76 |
} |
| 77 |
|
| 78 |
static void |
| 79 |
test_c (C c4 = C{}, C c5 = C{ 42 }) |
| 80 |
{ |
| 81 |
if (c2.b.x != 42 || c2.b.a.x != 42 || c2.b.a.y != c2.b.a.x) |
| 82 |
__builtin_abort (); |
| 83 |
if (c3.b.x != 42 || c3.b.a.x != 42 || c3.b.a.y != c3.b.a.x) |
| 84 |
__builtin_abort (); |
| 85 |
if (c4.b.x != 42 || c4.b.a.x != 42 || c4.b.a.y != c4.b.a.x) |
| 86 |
__builtin_abort (); |
| 87 |
if (c5.b.x != 42 || c5.b.a.x != 42 || c5.b.a.y != c5.b.a.x) |
| 88 |
__builtin_abort (); |
| 89 |
} |
| 90 |
|
| 91 |
static void |
| 92 |
test_d (D d4 = D{}, D d5 = D{ 42 }) |
| 93 |
{ |
| 94 |
if (d2.x != 42 || d2.a.x != 42 || d2.a.y != d2.a.x) |
| 95 |
__builtin_abort (); |
| 96 |
if (d3.x != 42 || d3.a.x != 42 || d3.a.y != d3.a.x) |
| 97 |
__builtin_abort (); |
| 98 |
if (d4.x != 42 || d4.a.x != 42 || d4.a.y != d4.a.x) |
| 99 |
__builtin_abort (); |
| 100 |
if (d5.x != 42 || d5.a.x != 42 || d5.a.y != d5.a.x) |
| 101 |
__builtin_abort (); |
| 102 |
} |
| 103 |
|
| 104 |
static void |
| 105 |
test_e (E e4 = E{}, E e5 = E{ 42 }) |
| 106 |
{ |
| 107 |
if (e2.x != 42 || e2.a.x != 42 || e2.a.y != e2.a.x) |
| 108 |
__builtin_abort (); |
| 109 |
if (e3.x != 42 || e3.a.x != 42 || e3.a.y != e3.a.x) |
| 110 |
__builtin_abort (); |
| 111 |
if (e4.x != 42 || e4.a.x != 42 || e4.a.y != e4.a.x) |
| 112 |
__builtin_abort (); |
| 113 |
if (e5.x != 42 || e5.a.x != 42 || e5.a.y != e5.a.x) |
| 114 |
__builtin_abort (); |
| 115 |
} |
| 116 |
|
| 117 |
static void |
| 118 |
test_f (F f4 = F{}, F f5 = F{ 42 }) |
| 119 |
{ |
| 120 |
if (f2.x != 42 || f2.a.x != 42 || f2.a.y != f2.a.x) |
| 121 |
__builtin_abort (); |
| 122 |
if (f3.x != 42 || f3.a.x != 42 || f3.a.y != f3.a.x) |
| 123 |
__builtin_abort (); |
| 124 |
if (f4.x != 42 || f4.a.x != 42 || f4.a.y != f4.a.x) |
| 125 |
__builtin_abort (); |
| 126 |
if (f5.x != 42 || f5.a.x != 42 || f5.a.y != f5.a.x) |
| 127 |
__builtin_abort (); |
| 128 |
} |
| 129 |
int |
| 130 |
main () |
| 131 |
{ |
| 132 |
test_b (); |
| 133 |
test_c (); |
| 134 |
test_d (); |
| 135 |
test_e (); |
| 136 |
test_f (); |
| 137 |
} |