Bug 22576 – ImportC: cannot implicitly convert expression S(0) of type S to int in an S array

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-12-07T07:24:00Z
Last change time
2021-12-19T03:32:35Z
Keywords
ImportC, pull, rejects-valid
Assigned to
No Owner
Creator
dave287091

Comments

Comment #0 by dave287091 — 2021-12-07T07:24:00Z
The following C program fails to compile: // compound.c typedef struct S { int x; } S; int main(int argc, char** argv){ S s = (S){0}; // ok S a0[] = {{0}}; // ok S a1[] = {(S){0}}; // Error: cannot implicitly convert expression `S(0)` of type `S` to `int` struct S a2[] = {(struct S){0}}; // Error: cannot implicitly convert expression `S(0)` of type `S` to `int` struct S a3[1] = {(struct S){0}}; // Error: cannot implicitly convert expression `S(0)` of type `S` to `int` }
Comment #1 by bugzilla — 2021-12-17T08:14:54Z
More succinctly: typedef struct S { int x; } S; void test() { int i; int a[1] = { i }; // ok S s; S b[1] = { s }; // fails }
Comment #2 by dlang-bot — 2021-12-17T10:19:38Z
@WalterBright created dlang/dmd pull request #13437 "fix Issue 22576 - ImportC: cannot implicitly convert expression S(0) …" fixing this issue: - fix Issue 22576 - ImportC: cannot implicitly convert expression S(0) of type S to int in an S array https://github.com/dlang/dmd/pull/13437
Comment #3 by dlang-bot — 2021-12-19T03:32:35Z
dlang/dmd pull request #13437 "fix Issue 22576 - ImportC: cannot implicitly convert expression S(0) …" was merged into stable: - 6e0d332d1f82f9cc3596180d76ad9814677b046f by Walter Bright: fix Issue 22576 - ImportC: cannot implicitly convert expression S(0) of type S to int in an S array https://github.com/dlang/dmd/pull/13437