| 1 |
/* REQUIRED_ARGS: -preview=bitfields |
| 2 |
*/ |
| 3 |
|
| 4 |
struct S |
| 5 |
{ |
| 6 |
int a; |
| 7 |
int b:5, c:6; |
| 8 |
} |
| 9 |
|
| 10 |
static if (0) |
| 11 |
{ |
| 12 |
pragma(msg, __traits(isBitfield, S.a)); |
| 13 |
pragma(msg, __traits(isBitfield, S.b)); |
| 14 |
pragma(msg, S.b.bitoffsetof); |
| 15 |
pragma(msg, S.b.bitwidth); |
| 16 |
pragma(msg, S.c.bitoffsetof); |
| 17 |
pragma(msg, S.c.bitwidth); |
| 18 |
pragma(msg, S.a.bitoffsetof); |
| 19 |
pragma(msg, S.a.bitwidth); |
| 20 |
} |
| 21 |
|
| 22 |
static assert(__traits(isBitfield, S.a) == false); |
| 23 |
static assert(__traits(isBitfield, S.b) == true); |
| 24 |
static assert(S.b.bitoffsetof == 0); |
| 25 |
static assert(S.b.bitwidth == 5); |
| 26 |
static assert(S.c.bitoffsetof == 5); |
| 27 |
static assert(S.c.bitwidth == 6); |
| 28 |
|
| 29 |
/* TEST_OUTPUT: |
| 30 |
--- |
| 31 |
fail_compilation/bitintro.d(6): Error: `a` is not a bitfield, cannot apply `bitoffsetof` |
| 32 |
fail_compilation/bitintro.d(37): while evaluating: `static assert(a.bitoffsetof)` |
| 33 |
fail_compilation/bitintro.d(6): Error: `a` is not a bitfield, cannot apply `bitwidth` |
| 34 |
fail_compilation/bitintro.d(38): while evaluating: `static assert(a.bitwidth)` |
| 35 |
--- |
| 36 |
*/ |
| 37 |
static assert(S.a.bitoffsetof); |
| 38 |
static assert(S.a.bitwidth); |