[llvm-bugs] [Bug 49413] New: elaborated-enum-base incompatible with NS_ENUM

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 3 09:02:35 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=49413

            Bug ID: 49413
           Summary: elaborated-enum-base incompatible with NS_ENUM
           Product: clang
           Version: 11.0
          Hardware: All
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: lhunath at lyndir.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Related to
https://github.com/llvm/llvm-project/commit/c90e198107431f64b73686bdce31c293e3380ac7

The new `-Welaborated-enum-base` appears to be incompatible with macros to
define nonfixed type enums.

One such example is Apple's NS_ENUM, which effectively translates:

```
typedef NS_ENUM( X, unsigned int) {
...
}
```

into:

```
typedef enum X : unsigned int X;
enum X : unsigned int {
```

Which triggers:

```
fatal error: non-defining declaration of enumeration with a fixed underlying
type is only permitted as a standalone declaration; missing list of
enumerators? [-Welaborated-enum-base]
```

The idea behind macros such as `NS_ENUM` is that they type the enum if
supported by the compiler, as well as hide the `enum` type keyword.

Unfortunately, the only way to do this now would be to remove the nonfixed type
from the typedef, but this causes another problem:

```
error: enumeration previously declared with nonfixed underlying type
```

This can only be addressed by moving the typedef below the enum declaration,
but unfortunately it appears that this is impossible to achieve with a macro.

Consequently, `clang` can no longer compile `NS_ENUM`-style macros, and there
is no path for resolving the issue other than by disabling
`elaborated-enum-base`.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210303/b71ff057/attachment.html>


More information about the llvm-bugs mailing list