[PATCH] D131704: [Clang] Tighten restrictions on enum out of range diagnostic
Nico Weber via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 12 16:34:22 PDT 2022
thakis added a comment.
In D131704#3717950 <https://reviews.llvm.org/D131704#3717950>, @shafik wrote:
> In D131704#3717774 <https://reviews.llvm.org/D131704#3717774>, @akhuang wrote:
>
>> We're seeing this warning in code with global constants, e.g.
>>
>> const Enum x = static_cast<Enum>(-1);
>>
>> is this intended?
>
> This is constant initialization, so this is indeed expected.
>
> Depending on your situation you can fix this by using a fixed underlying type e.g. : `enum A : int` or by making it a scoped enum `enum class A` or by extending the enumerators themselves to include the value you are using.
>
> If this not your code you can also turn the error into a warning using `-Wno-error=enum-constexpr-conversion`
Another question about this. The diag name and all the wording so far was about "constexpr". The expression Amy pasted is constant initialization, but _not_ constexpr.
Is this really intentional? This is quite an increase in scope for the diag, if so. we did a full cleanup for the original diag, but after the recent tweaks it fires in many many more places.
Can we put this under a different warning flag for non-constexpr cases if this is really intentional? I'm assuming the non-constexpr case won't become an unconditional error later? It probably also shouldn't be mapped to an error?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D131704/new/
https://reviews.llvm.org/D131704
More information about the cfe-commits
mailing list