Bug 24639 – ImportC: defines of negative constants not detected for enum conversion
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-06-30T03:19:20Z
Last change time
2024-08-17T14:14:11Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
Steven Schveighoffer
Comments
Comment #0 by schveiguy — 2024-06-30T03:19:20Z
file2.c:
#define blah -1
#define blah2 (-1)
#define blah3 (0 - 1)
file1.d:
import file2;
unittest
{
assert(blah == -1); // can't find blah
assert(blah2 == -1); // can't find blah2
assert(blah3 == -1); // OK!
}
I think the issue is that the parser does not see the `-` sign as a number, and so skips this definition. But it does work for an expression that starts with a number inside parentheses.
Comment #1 by dlang-bot — 2024-08-17T12:37:50Z
@tim-dlang created dlang/dmd pull request #16789 "Fix bugzilla 24639 - ImportC: defines of negative constants not detec…" fixing this issue:
- Fix bugzilla 24639 - ImportC: defines of negative constants not detected for enum conversion
Negative expressions inside parens are already supported. This adds
support for defines with negative numbers without parens, but not more
complex expressions. Defines for negative numbers are often used as
error codes in C.
https://github.com/dlang/dmd/pull/16789
Comment #2 by dlang-bot — 2024-08-17T14:14:11Z
dlang/dmd pull request #16789 "Fix bugzilla 24639 - ImportC: defines of negative constants not detec…" was merged into master:
- cf3bdf684c0fd2fede464af7e64496b6bad48709 by Tim Schendekehl:
Fix bugzilla 24639 - ImportC: defines of negative constants not detected for enum conversion
Negative expressions inside parens are already supported. This adds
support for defines with negative numbers without parens, but not more
complex expressions. Defines for negative numbers are often used as
error codes in C.
https://github.com/dlang/dmd/pull/16789