Bug 21976 – importC: does not distinguish between cast-expression and unary-expression correctly
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-05-25T18:32:53Z
Last change time
2021-06-03T21:32:25Z
Keywords
ImportC, pull, rejects-valid
Assigned to
No Owner
Creator
Iain Buclaw
Comments
Comment #0 by ibuclaw — 2021-05-25T18:32:53Z
C99 6.7.2.2-1 syntax says the grammar is:
enumerator:
enumeration-constant
enumeration-constant = constant-expression
And C99 6.6 says:
constant-expression:
conditional-expression
This works
---
enum constant_expression
{
ce_first,
ce_second = ce_first == 0 ? 1 : 0,
};
---
And yet, this fails:
---
enum constant_expression
{
ce_first,
ce_second = (ce_first == 0) ? 1 : 0,
};
---
With the message:
---
Error: found `==` when expecting `)`
Error: found `)` when expecting `}`
Error: `=`, `;` or `,` expected
Comment #1 by ibuclaw — 2021-05-25T18:34:43Z
Likewise, this fails to compile:
---
enum constant_expression
{
ce_first,
ce_second = (int) ((1UL << (ce_first)) << 24),
};
Comment #2 by ibuclaw — 2021-06-03T10:00:36Z
This is the full example from `wctype.h`.
---
enum
{
__ISwupper = 0,
_ISwupper = ((__ISwupper) < 8
? (int) ((1UL << (__ISwupper)) << 24)
: ((__ISwupper) < 16
? (int) ((1UL << (__ISwupper)) << 8)
: ((__ISwupper) < 24
? (int) ((1UL << (__ISwupper)) >> 8)
: (int) ((1UL << (__ISwupper)) >> 24)))),
};
---
Comment #3 by dlang-bot — 2021-06-03T20:00:24Z
@WalterBright updated dlang/dmd pull request #12627 "fix Issue 21976 - importC: does not distinguish between cast-expression and unary-expression correctly" fixing this issue:
- fix Issue 21976 ImportC: does not distinguish between cast-expression and unary-expression correctly
https://github.com/dlang/dmd/pull/12627
Comment #4 by dlang-bot — 2021-06-03T21:32:25Z
dlang/dmd pull request #12627 "fix Issue 21976 - importC: does not distinguish between cast-expression and unary-expression correctly" was merged into master:
- 36d2635f2212cba91c737a87710602e800f25e5e by Walter Bright:
fix Issue 21976 ImportC: does not distinguish between cast-expression and unary-expression correctly
https://github.com/dlang/dmd/pull/12627