[PATCH] D131704: [Clang] Tighten restrictions on enum out of range diagnostic

Shafik Yaghmour via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 11 17:24:13 PDT 2022


shafik added a comment.

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`


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