My generated .di file includes the following: enum __VERSION__ = "Apple LLVM 15.0.0 (clang-1500.0.40.1)"; This leads to an error, as __VERSION__ is a special token in D. __VERSION__ is also pre-defined by the preprocessor. If the macros include any of the special tokens (https://dlang.org/spec/lex.html#specialtokens), you will get errors. For example, if your c file looks like: #define __DATE__ 1 #define __TIME__ 1 #define __TIMESTAMP__ 1 #define __VENDOR__ 1 #define __EOF__ 1 Then, after converting to a .di file, you will get some enums that look like: enum int __DATE__ = 1; enum int __TIME__ = 1; enum int __TIMESTAMP__ = 1; enum int __VENDOR__ = 1; enum int __EOF__ = 1; which will all error out
I don't really know what to do about that. D has a different set of keywords than C does, and if D keywords are used in C code, how can it be translated into D code? I expect that such generated .di files will need to be tweaked by hand.
(In reply to Walter Bright from comment #1) > I don't really know what to do about that. D has a different set of keywords > than C does, and if D keywords are used in C code, how can it be translated > into D code? > > I expect that such generated .di files will need to be tweaked by hand. I think it’d be acceptable to just not emit them into the .di file. The __VERSION__ one especially as clang pre-defines that one and no one will want to use them. No one will want the conflicting macros anyway, but they currently prevent the .di file from being parsed.
(In reply to dave287091 from comment #2) > I think it’d be acceptable to just not emit them into the .di file. The > __VERSION__ one especially as clang pre-defines that one and no one will > want to use them. No one will want the conflicting macros anyway, but they > currently prevent the .di file from being parsed. I'm a bit reluctant to do that - silently removing things that don't work. The user should be aware of what is not working so they can make appropriate changes. I'll think about it some more.
@WalterBright created dlang/dmd pull request #15797 "fix Issue 24200 - ImportC: .di file collected macro conflicts with Sp…" fixing this issue: - fix Issue 24200 - ImportC: .di file collected macro conflicts with Special Token https://github.com/dlang/dmd/pull/15797
dlang/dmd pull request #15797 "fix Issue 24200 - ImportC: .di file collected macro conflicts with Sp…" was merged into master: - db28d2195c13cb661b266d93d70a1337d562cb17 by Walter Bright: fix Issue 24200 - ImportC: .di file collected macro conflicts with Special Token https://github.com/dlang/dmd/pull/15797