| 1 |
// REQUIRED_ARGS: -d |
| 2 |
/* |
| 3 |
TEST_OUTPUT: |
| 4 |
--- |
| 5 |
fail_compilation/fail156.d(35): Error: overlapping initialization for field `x` and `y` |
| 6 |
fail_compilation/fail156.d(35): `struct` initializers that contain anonymous unions must initialize only the first member of a `union`. All subsequent non-overlapping fields are default initialized |
| 7 |
fail_compilation/fail156.d(42): Error: overlapping initialization for field `x` and `y` |
| 8 |
fail_compilation/fail156.d(42): `struct` initializers that contain anonymous unions must initialize only the first member of a `union`. All subsequent non-overlapping fields are default initialized |
| 9 |
--- |
| 10 |
*/ |
| 11 |
|
| 12 |
alias int myint; |
| 13 |
|
| 14 |
struct S |
| 15 |
{ |
| 16 |
int i; |
| 17 |
union |
| 18 |
{ |
| 19 |
int x = 2; |
| 20 |
int y; |
| 21 |
} |
| 22 |
int j = 3; |
| 23 |
myint k = 4; |
| 24 |
} |
| 25 |
|
| 26 |
void main() |
| 27 |
{ |
| 28 |
S s = S( 1, 5 ); |
| 29 |
assert(s.i == 1); |
| 30 |
assert(s.x == 5); |
| 31 |
assert(s.y == 5); |
| 32 |
assert(s.j == 3); |
| 33 |
assert(s.k == 4); |
| 34 |
|
| 35 |
static S t = S( 1, 6, 6 ); |
| 36 |
assert(t.i == 1); |
| 37 |
assert(t.x == 6); |
| 38 |
assert(t.y == 6); |
| 39 |
assert(t.j == 3); |
| 40 |
assert(t.k == 4); |
| 41 |
|
| 42 |
S u = S( 1, 5, 6 ); |
| 43 |
assert(u.i == 1); |
| 44 |
assert(u.x == 5); |
| 45 |
assert(u.y == 5); |
| 46 |
assert(u.j == 3); |
| 47 |
assert(u.k == 4); |
| 48 |
} |