Bug 24495 – ImportC: Struct initialization expression fails to initialize field
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2024-04-10T07:01:43Z
Last change time
2024-04-23T14:24:14Z
Keywords
pull
Assigned to
No Owner
Creator
artha
Comments
Comment #0 by artha — 2024-04-10T07:01:43Z
I encountered this while working on Tree Sitter (which is C11-compliant) with ImportC: https://tree-sitter.github.io/
---
#include <stdio.h>
struct Item {
int a;
struct {
int b1;
int b2;
};
};
int main() {
struct Item first = {
.a = 1,
.b1 = 2,
.b2 = 3,
};
struct Item second = {
.a = 1,
{
.b1 = 2,
.b2 = 3,
}
};
printf("first: %d, { %d, %d }\n", first.a, first.b1, first.b2);
printf("second: %d, { %d, %d }\n", second.a, second.b1, second.b2);
return 0;
}
---
$ gcc example.c && ./a.out
first: 1, { 2, 3 }
second: 1, { 2, 3 }
$ dmd example.c && ./example
first: 1, { 2, 3 }
second: 1, { 2, 0 }
DMD fails to initialize the second field of the inner struct if the struct is instantiated explicitly.
Comment #1 by dlang-bot — 2024-04-10T09:58:15Z
@ArthaTi updated dlang/dmd pull request #16369 "Fix bugzilla issue 24495 - ImportC: Struct initialization expression fails to initialize field" fixing this issue:
- Fix bugzilla issue 24495 - ImportC: Struct initialization expression fails to initialize field
Makes it possible to use multiple designated initializers for anonymous
structs in expressions like `{{ .b = 2, .c = 3 }}`. This previously
worked only if there was one initializer.
https://github.com/dlang/dmd/pull/16369
Comment #2 by dlang-bot — 2024-04-10T22:15:50Z
dlang/dmd pull request #16369 "Fix bugzilla issue 24495 - ImportC: Struct initialization expression fails to initialize field" was merged into stable:
- 20cd1869b086b36e88033be09f8bb1376aebbf5d by Artha:
Fix bugzilla issue 24495 - ImportC: Struct initialization expression fails to initialize field
Makes it possible to use multiple designated initializers for anonymous
structs in expressions like `{{ .b = 2, .c = 3 }}`. This previously
worked only if there was one initializer.
https://github.com/dlang/dmd/pull/16369
Comment #3 by dkorpel — 2024-04-11T09:20:13Z
*** Issue 24277 has been marked as a duplicate of this issue. ***
Comment #4 by dlang-bot — 2024-04-23T14:24:14Z
dlang/dmd pull request #16406 "Merge stable" was merged into master:
- 4f69ba59f3e9bb8fe012cba701700792a5ab4982 by Artha:
Fix bugzilla issue 24495 - ImportC: Struct initialization expression fails to initialize field
Makes it possible to use multiple designated initializers for anonymous
structs in expressions like `{{ .b = 2, .c = 3 }}`. This previously
worked only if there was one initializer.
https://github.com/dlang/dmd/pull/16406