| 1 |
/* |
| 2 |
TEST_OUTPUT: |
| 3 |
--- |
| 4 |
fail_compilation/fail11151.d(30): Error: overlapping initialization for field `a` and `y` |
| 5 |
--- |
| 6 |
*/ |
| 7 |
|
| 8 |
//extern(C) int printf(const char*, ...); |
| 9 |
|
| 10 |
union U |
| 11 |
{ |
| 12 |
struct |
| 13 |
{ |
| 14 |
align(1) long a; |
| 15 |
align(1) int b; |
| 16 |
} |
| 17 |
struct |
| 18 |
{ |
| 19 |
align(1) int x; |
| 20 |
align(1) long y; |
| 21 |
} |
| 22 |
} |
| 23 |
void main() |
| 24 |
{ |
| 25 |
static assert(U.a.offsetof == 0); |
| 26 |
static assert(U.b.offsetof == 8); |
| 27 |
static assert(U.x.offsetof == 0); |
| 28 |
static assert(U.y.offsetof == 4); |
| 29 |
|
| 30 |
U u = {a:1, y:2}; // overlapped initializing U.a and U.y |
| 31 |
|
| 32 |
//printf("u.a = %lld\n", u.a); // 8589934593 , Wrong! |
| 33 |
//printf("u.b = %d\n", u.b); // 0 |
| 34 |
//printf("u.x = %d\n", u.x); // 1 |
| 35 |
//printf("u.y = %lld\n", u.y); // 2 |
| 36 |
} |