D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21976 - importC: does not distinguish between cast-expression and unary-expression correctly
Summary: importC: does not distinguish between cast-expression and unary-expression co...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 major
Assignee: No Owner
URL:
Keywords: ImportC, pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2021-05-25 18:32 UTC by Iain Buclaw
Modified: 2021-06-03 21:32 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Iain Buclaw 2021-05-25 18:32:53 UTC
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 Iain Buclaw 2021-05-25 18:34:43 UTC
Likewise, this fails to compile:
---
enum constant_expression
{
  ce_first,
  ce_second = (int) ((1UL << (ce_first)) << 24),
};
Comment 2 Iain Buclaw 2021-06-03 10:00:36 UTC
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 Dlang Bot 2021-06-03 20:00:24 UTC
@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 Dlang Bot 2021-06-03 21:32:25 UTC
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