dmd icon indicating copy to clipboard operation
dmd copied to clipboard

ImportC: .di generator can output invalid aliases

Open dlangBugzillaToGithub opened this issue 2 years ago • 1 comments

dave287091 reported this on 2024-02-08T20:23:24Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=24373

Description

Example c file:

typedef unsigned int uint;
typedef unsigned short ushort;

If you then convert to a .di file, you get something like:

extern(C)
{
 // ... bunch of junk
	alias uint = uint;
	alias ushort = ushort;
 // ...
}

Which are not valid alias declarations.

dlangBugzillaToGithub avatar Feb 08 '24 20:02 dlangBugzillaToGithub

Typedefs are converted to aliases in importC. so the only doable thing here is to maybe avoid using D type identifiers in your C typedefs.

but in cases where changes can't be made, maybe we can check if type ids are D keywords then we prepend _ when creating D symbols. so then we get alias _uint = uint;. could avoid complexity in trying to hack through semantics.

Emmankoko avatar Nov 26 '25 07:11 Emmankoko