Bug 24200 – ImportC: .di file collected macro conflicts with Special Token
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-10-25T05:51:30Z
Last change time
2023-11-22T09:42:04Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
dave287091
Comments
Comment #0 by dave287091 — 2023-10-25T05:51:30Z
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
Comment #1 by bugzilla — 2023-10-27T20:40:25Z
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.
Comment #2 by dave287091 — 2023-10-27T22:38:02Z
(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.
Comment #3 by bugzilla — 2023-11-06T18:32:42Z
(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.
Comment #4 by dlang-bot — 2023-11-11T05:36:39Z
@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
Comment #5 by dlang-bot — 2023-11-22T09:42:04Z
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