Bug 24375 – ImportC: .di generator outputs C expression with `->` operator

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-02-08T20:34:15Z
Last change time
2024-07-29T13:51:25Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
dave287091

Attachments

IDFilenameSummaryContent-TypeSize
1916remove_arrow.patchremove generation of '->' in .di filestext/plain552

Comments

Comment #0 by dave287091 — 2024-02-08T20:34:15Z
C code: struct foo { int x; }; typedef int weird[sizeof(((struct foo *)((void*)0))->x)]; outputs: extern(C) { // ... struct foo { int x = void; } alias weird = int[(cast(foo*)cast(void*)0)->x.sizeof]; // ... } Encountered something like this in an SDL header.
Comment #1 by michaelate — 2024-07-29T08:13:36Z
Created attachment 1916 remove generation of '->' in .di files Should '->' be generated at all in a .di file? It is not a valid D operator and .di should contain only D code. This patch removes output of '->' from compiler/src/dmd/hdrgen.d which fixes the issue.
Comment #2 by michaelate — 2024-07-29T08:16:35Z
This issue also appears when C-code has macros accessing struct elements via pointer to struct. C-code: #define access_ptr(b,y) ((b)->x=(y)) ouptuts: auto access_ptr(__MP20, __MP21)(__MP20 b, __MP21 y) { return b->x = y; // Doesn't compile. Should be b.x = y }
Comment #3 by dlang-bot — 2024-07-29T12:11:39Z
@dkorpel created dlang/dmd pull request #16757 "Fix bugzilla 24375 - ImportC: .di generator outputs C expression with…" fixing this issue: - Fix bugzilla 24375 - ImportC: .di generator outputs C expression with `->` operator https://github.com/dlang/dmd/pull/16757
Comment #4 by dlang-bot — 2024-07-29T13:51:25Z
dlang/dmd pull request #16757 "Fix bugzilla 24375 - ImportC: .di generator outputs C expression with…" was merged into master: - a0be561061991d58eddd8ec9f3a63e993363b3b9 by Dennis Korpel: Fix bugzilla 24375 - ImportC: .di generator outputs C expression with `->` operator https://github.com/dlang/dmd/pull/16757