[Issue 23189] importC: __builtin_offsetof without struct/union/enum should emit proper error message

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Oct 28 00:51:13 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=23189

--- Comment #6 from ryuukk_ <ryuukk.dev at gmail.com> ---
Here is a reduced code:



```
#define NK_OFFSETOF(st,m) (__builtin_offsetof(st,m))
#define NK_ALIGNOF(t) NK_OFFSETOF(struct {char c; t _h;}, _h)

struct nk_command{};

void test()
{
    const int align = NK_ALIGNOF(struct nk_command);
}
```



// using cpp -P -E 


```
void test()
{
    const int align = (__builtin_offsetof(struct {char c; struct nk_command
_h;},_h));
} 
```




This code compile with GCC, but not with D importc:




bar.c(4): Error: expression expected, not `struct`
bar.c(4): Error: found `{` when expecting `)`
bar.c(4): Error: found `char` when expecting `)`
bar.c(4): Error: missing comma or semicolon after declaration of `extern ()`,
found `c` instead
bar.c(4): Error: identifier or `(` expected
bar.c(5): Error: identifier or `(` expected

--


More information about the Digitalmars-d-bugs mailing list