[PATCH] D131528: [Clang] Restrict non fixed enum to a value outside the range of the enumeration values warning to context requiring a constant expression

Gulfem Savrun Yeniceri via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 11 15:00:07 PDT 2022


gulfem added a comment.

In D131528#3717509 <https://reviews.llvm.org/D131528#3717509>, @shafik wrote:

> In D131528#3717141 <https://reviews.llvm.org/D131528#3717141>, @gulfem wrote:
>
>> Can somebody please clarify this? Is the following code results in `undefined` behavior?
>>
>>   enum E1 {e11=-4, e12=4};
>>   E1 x2b = static_cast<E1>(8);
>>
>> `constexpr E1 x2 = static_cast<E1>(8)` seems like `undefined`, so `-Wenum-constexpr-conversion` is triggered.
>> We started seeing `-Wenum-constexpr-conversion` in our codebase after https://reviews.llvm.org/D131307, but we stopped seeing them after this review.
>> Is the first example that I show above still undefined, but `-Wenum-constexpr-conversion` is not going to warn in such cases?
>
> Yes, this is indeed undefined behavior. The initial patch effected a lot of users and several third party packages and so I am trying to narrow the impact by restricting the error to those cases that are constant expression contexts only.
>
> So you may indeed less diagnostics now.

Thanks for your response @shafik. This is something temporary to ease the transition, but we will enable `-Wenum-constexpr-conversion` for non-const expressions at some point, right?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131528/new/

https://reviews.llvm.org/D131528



More information about the cfe-commits mailing list