[Issue 24276] ImportC: typedef aliases not emitted correctly in .di files
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Dec 12 06:49:45 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=24276
--- Comment #2 from Walter Bright <bugzilla at digitalmars.com> ---
Simplifying:
typedef union S
{
int x;
} S;
typedef S T;
Produces the .di file:
// D import file generated from 'test.i'
extern (C)
{
union S
{
int x = void;
}
union S;
alias T = S; // this line is missing
}
I can fix it to emit the missing `alias T` line. But getting rid of the extra
`union S;` is a problem. The trouble is, the .di file is generated before the
symbol table is built, and so doesn't know about the collision. D and C have
different semantics (in C you can redeclare a tag name as many times as you
want, but not in D).
A .di file is compiled as a D file, not a C. The impedance mismatch between C
and D is taken care of in the semantic routines, but the .di file has not
undergone semantic analysis.
This looks like this will be one of those cases where human tweaking of the .di
file or the C file will be needed. Either delete the `union S;` from the .di
file, or remove the first typedef, or don't name the typedef the same as the
tag name.
In general, C=>D translation problems are inevitable when using a C symbol with
the same name as a C tag symbol. These problems exist for every source
translation program, which is why ImportC is a compiler not a translator, and
why importing the C code works fine, as you reported.
--
More information about the Digitalmars-d-bugs
mailing list