[PATCH] D131307: [Clang] Allow downgrading to a warning the diagnostic for setting a non fixed enum to a value outside the range of the enumeration values

Alexander Yermolovich via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 11 09:49:16 PDT 2022


ayermolo added a comment.

In D131307#3714629 <https://reviews.llvm.org/D131307#3714629>, @shafik wrote:

> In D131307#3713011 <https://reviews.llvm.org/D131307#3713011>, @sberg wrote:
>
>> With this commit,
>>
>>   $ cat test.cc
>>   #include "boost/numeric/conversion/cast.hpp"
>>   int main() { return boost::numeric_cast<int>(0L); }
>>   
>>   $ clang++ test.cc
>>
>> succeeds without any diagnostic, while with its parent commit https://github.com/llvm/llvm-project/commit/b3645353041818f61e2580635409ddb81ff5a272 " [Clang] Diagnose ill-formed constant expression when setting a non fixed enum to a value outside the range of the enumeration values" it had started to fail with
>
> Yes, that is intended. When modifying the change to allow it to be turned into a warning it started applying outside of constant expression contexts and that broke a lot more stuff.
>
> I am planning on adding a default to a warning diagnostic for the non-constant expression cases but that will be done separately. I wanted to help folks unbreak their builds first.

I think after this change we started to see
protobuf/protobuf/src/google/protobuf/wire_format_lite.cc:103:9: error: integer value -1 is outside the valid range of values [0, 7] for this enumeration type [-Wenum-constexpr-conversion]

  static_cast<WireFormatLite::WireType>(-1),  // invalid

Can I add a flag to turn this back in to a note?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131307



More information about the cfe-commits mailing list