Bug 22611 – ImportC: Need better error messages involving structs
Status
RESOLVED
Resolution
INVALID
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-12-19T16:19:42Z
Last change time
2023-04-01T23:50:21Z
Keywords
ImportC
Assigned to
No Owner
Creator
Lance Bachmeier
Comments
Comment #0 by lance — 2021-12-19T16:19:42Z
C code:
typedef struct
{
unsigned char c[4];
} stb_easy_font_color;
stb_easy_font_color c = { 255,255,255,255 }; // use structure copying to avoid needing depending on memcpy()
DMD output:
Error: 3 extra initializer(s) for `struct __tag21`
__tag21 is generated by the compiler, so the alias stb_easy_font_color should be reported instead.
Forum thread: https://forum.dlang.org/post/[email protected]
Internally, the compiler does not keep track of which typedefs are pointing to a struct tag, so it's kinda awkward to fix.
Comment #3 by lance — 2022-02-02T13:01:10Z
The line number is reported with the error, so that's not a big issue. Something like
Error: 3 extra initializer(s) in struct
would be better than
Error: 3 extra initializer(s) for `struct __tag21`
because __tag21 is not known to the programmer.
Comment #4 by bugzilla — 2023-04-01T23:50:21Z
C11 allows extra initializers (gcc warns about them), but ImportC doesn't do warnings.
The error message no longer appears.