www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21976] New: importC: enumeration constants rejects

https://issues.dlang.org/show_bug.cgi?id=21976

          Issue ID: 21976
           Summary: importC: enumeration constants rejects conditional
                    expressions in parentheses
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ibuclaw gdcproject.org

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

--
May 25 2021