-
-
Notifications
You must be signed in to change notification settings - Fork 606
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add __traits getBitfieldOffset and getBitfieldWidth (#17043)
- Loading branch information
1 parent
e17cc3a
commit b70e660
Showing
5 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Add __traits getBitfieldOffset and getBitfieldWidth | ||
|
||
This completes the introspection capabilities of builtin bitfields. For example: | ||
|
||
--- | ||
struct S | ||
{ | ||
int a,b; | ||
int :2, c:3; | ||
} | ||
|
||
static assert(__traits(getBitfieldOffset, S.b) == 0); | ||
static assert(__traits(getBitfieldOffset, S.c) == 2); | ||
static assert(__traits(getBitfieldWidth, S.b) == 32); | ||
static assert(__traits(getBitfieldWidth, S.c) == 3); | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* REQUIRED_ARGS: -preview=bitfields | ||
* TEST_OUTPUT: | ||
--- | ||
fail_compilation/biterrors5.d(23): Error: bitfield symbol expected not struct `biterrors5.S` | ||
fail_compilation/biterrors5.d(24): Error: bitfield symbol expected not variable `biterrors5.test0.i` | ||
--- | ||
*/ | ||
|
||
struct S | ||
{ | ||
int a,b; | ||
int :2, c:3; | ||
} | ||
|
||
static assert(__traits(getBitfieldOffset, S.b) == 0); | ||
static assert(__traits(getBitfieldWidth, S.b) == 32); | ||
static assert(__traits(getBitfieldOffset, S.c) == 2); | ||
static assert(__traits(getBitfieldWidth, S.c) == 3); | ||
|
||
void test0() | ||
{ | ||
int i; | ||
i = __traits(getBitfieldOffset, S); | ||
i = __traits(getBitfieldOffset, i); | ||
} |