Bug 23345 – ImportC: out of order designated initializers initialize to wrong value

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-09-19T01:05:37Z
Last change time
2022-09-26T02:29:09Z
Keywords
ImportC, pull, wrong-code
Assigned to
No Owner
Creator
dave287091

Comments

Comment #0 by dave287091 — 2022-09-19T01:05:37Z
The issue is demonstrated with the following C program: struct String { unsigned long length; const char* ptr; }; extern void abort(void); int printf(const char*, ...); void assert_(_Bool cond, int line){ if(!cond) { printf("assertion at line %d failed\n", line); abort(); } } int main(){ struct String a = { .length = sizeof("hello")-1, .ptr = "hello", }; struct String b = { .ptr = "hello", .length = sizeof("hello")-1, }; assert_(a.length == 5, __LINE__); assert_(b.length == 5, __LINE__); // this one fails return 0; }
Comment #1 by bugzilla — 2022-09-23T09:18:00Z
A much simpler test case: struct S { int a, b; }; struct S s = { .b = 3, .a = 2 }; The initialization is a=0, b=3
Comment #2 by dlang-bot — 2022-09-24T04:47:25Z
@WalterBright created dlang/dmd pull request #14480 "fix Issue 23345 - ImportC: out of order designated initializers initi…" fixing this issue: - fix Issue 23345 - ImportC: out of order designated initializers initialize to wrong value https://github.com/dlang/dmd/pull/14480
Comment #3 by dlang-bot — 2022-09-26T02:29:09Z
dlang/dmd pull request #14480 "fix Issue 23345 - ImportC: out of order designated initializers initi…" was merged into master: - 03581fc72d138f27101c31efc8933692b0552487 by Walter Bright: fix Issue 23345 - ImportC: out of order designated initializers initialize to wrong value https://github.com/dlang/dmd/pull/14480