swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.61k stars 10.37k forks source link

[SR-12788] Top-of-tree clang is more strict about enum parsing #55233

Open davezarzycki opened 4 years ago

davezarzycki commented 4 years ago
Previous ID SR-12788
Radar None
Original Reporter @davezarzycki
Type Bug
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: c7e068f9466beb551a4952670fa49116

Issue Description:

As a heads up to the indexstore.h DRI, top-of-tree clang is more strict about enum parsing and semantic validation:

StoreUtils.cpp.o -c /home/dave/s/y/toolchain/llvm-project/clang/lib/Index/IndexDataStoreUtils.cpp
In file included from /home/dave/s/y/toolchain/llvm-project/clang/lib/Index/IndexDataStoreUtils.cpp:10:
In file included from /home/dave/s/y/toolchain/llvm-project/clang/include/clang/Index/IndexDataStoreSymbolUtils.h:13:
/home/dave/s/y/toolchain/llvm-project/clang/include/indexstore/indexstore.h:290:9: 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]
typedef INDEXSTORE_OPTIONS(uint64_t, indexstore_symbol_property_t) {
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/dave/s/y/toolchain/llvm-project/clang/include/indexstore/indexstore.h:103:79: note: expanded from macro 'INDEXSTORE_OPTIONS'
# define INDEXSTORE_OPTIONS(_type, _name) enum INDEXSTORE_OPTIONS_ATTRS _name : _type _name; enum INDEXSTORE_OPTIONS_ATTRS _name : _type
 ^~~~~~~
/home/dave/s/y/toolchain/llvm-project/clang/include/indexstore/indexstore.h:310:9: 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]
typedef INDEXSTORE_OPTIONS(uint64_t, indexstore_symbol_role_t) {
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/dave/s/y/toolchain/llvm-project/clang/include/indexstore/indexstore.h:103:79: note: expanded from macro 'INDEXSTORE_OPTIONS'
# define INDEXSTORE_OPTIONS(_type, _name) enum INDEXSTORE_OPTIONS_ATTRS _name : _type _name; enum INDEXSTORE_OPTIONS_ATTRS _name : _type
 ^~~~~~~
2 errors generated.

See llvm-project commit d6425e2c14370ecb5e2a4be4cfdef65f8ae69bd0 and notably the commit message:

Properly implement 'enum class' parsing.
The 'class' or 'struct' keyword is only permitted as part of either an
 enum definition or a standalone opaque-enum-declaration, not as part of
 an elaborated type specifier. We previously failed to diagnose this, and
 generally didn't properly implement the restrictions on elaborated type
 specifiers for enumeration types.
In passing, also fixed incorrect parsing for enum-bases, which we
 previously parsed as a type-name, but are actually a type-specifier-seq.
 This matters for cases like 'enum E : int *p;', which is valid as a
 Microsoft extension.
Plus some minor parse diagnostic improvements.
Bumped the recently-added ExtWarn for 'enum E : int x;' to be
 DefaultError; this is not an intentional extension, so producing an
 error by default seems appropriate, but the warning flag to disable it
 may still be useful for code written against old Clang. The same
 treatment is given here to the diagnostic for 'enum class E x;', which
 we similarly have incorrectly accepted for many years. These diagnostics
 continue to be suppressed under -fms-extensions and when compiling
 Objective-C code. We will need to decide separately whether Objective-C
 should follow the C++ rules or the (older) MSVC rules.
swift-ci commented 4 years ago

Comment by Ryan (JIRA)

This breaks the build on Fedora 33 which is shipping with LLVM 11.

davezarzycki commented 4 years ago

Just compile with -Wno-error=elaborated-enum-base as a workaround.

As an aside for the Swift compiler engineers that still have sway with the clang engineers: What on earth is going on with this warning? I've never seen a warning that defaults to `-Werror` and therefore one must use `-Wno-error=` to veto the default.