Bug 23034 – importC: head-const struct confused with multiple files on command line

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-04-18T00:23:04Z
Last change time
2022-04-20T08:30:43Z
Keywords
ImportC, pull, rejects-valid
Assigned to
No Owner
Creator
duser
See also
https://issues.dlang.org/show_bug.cgi?id=23030

Comments

Comment #0 by duser — 2022-04-18T00:23:04Z
// file1.c struct S1 { int field1; }; struct S1 *const unused; // file2.c struct S2 { int field2; }; void fn() { struct S2 *const s; int x = s->field2; // here } compile: dmd file1.c file2.c file2.c(7): Error: `field2` is not a member of `const(S1)` similar to issue 23030 but not caused by the same PR (this exists on stable v2.099.1 too)
Comment #1 by bugzilla — 2022-04-20T04:40:09Z
Ah, took me hours to track this one. The trouble is addSTC() to add in a `const`. In D, this works because type names are identifiers, and mangling is skipped for TypeIdentifier. In C, these come through as a TypeTag, which does get mangled, but semantic() hasn't been run, so S1 and S2 both mangle as "x@" and are therefore treated as the same type.
Comment #2 by dlang-bot — 2022-04-20T04:55:38Z
@WalterBright created dlang/dmd pull request #14016 "fix Issue 23034 - importC: head-const struct confused with multiple f…" fixing this issue: - fix Issue 23034 - importC: head-const struct confused with multiple files on command line https://github.com/dlang/dmd/pull/14016
Comment #3 by dlang-bot — 2022-04-20T08:30:43Z
dlang/dmd pull request #14016 "fix Issue 23034 - importC: head-const struct confused with multiple f…" was merged into master: - 62c0846dd48cef8cf032a552c3e43c18565c42ea by Walter Bright: fix Issue 23034 - importC: head-const struct confused with multiple files on command line https://github.com/dlang/dmd/pull/14016