September 19, 2022
https://issues.dlang.org/show_bug.cgi?id=23345

          Issue ID: 23345
           Summary: ImportC: out of order designated initializers
                    initialize to wrong value
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: ImportC, wrong-code
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: dave287091@gmail.com

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;
}

--