[PATCH] D130058: [Clang] Diagnose ill-formed constant expression when setting a non fixed enum to a value outside the range of the enumeration values

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 29 11:59:51 PDT 2022


erichkeane added a comment.

In D130058#3688049 <https://reviews.llvm.org/D130058#3688049>, @thakis wrote:

> Here's a reduced repro of one case:
>
>   % cat test.cc
>   typedef enum VkResult {
>       VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS = -1000257000,
>       VK_RESULT_MAX_ENUM = 0x7FFFFFFF
>   } VkResult;
>   
>   constexpr VkResult VK_FAKE_DEVICE_OOM_FOR_TESTING = static_cast<VkResult>(VK_RESULT_MAX_ENUM - 1);
>   
>   % out/gn/bin/clang -c test.cc -std=c++17
>   test.cc:6:20: error: constexpr variable 'VK_FAKE_DEVICE_OOM_FOR_TESTING' must be initialized by a constant expression
>   constexpr VkResult VK_FAKE_DEVICE_OOM_FOR_TESTING = static_cast<VkResult>(VK_RESULT_MAX_ENUM - 1);
>                      ^                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   test.cc:6:53: note: integer value 2147483646 is outside the valid range of values [-2147483648, -2147483648) for this enumeration type
>   constexpr VkResult VK_FAKE_DEVICE_OOM_FOR_TESTING = static_cast<VkResult>(VK_RESULT_MAX_ENUM - 1);
>                                                       ^
>   1 error generated.
>
> Isn't `valid range of values [-2147483648, -2147483648)` just wrong here?

That range with the leading negative looks wrong to me, but perhaps that is a diagnostic problem?  Either way, this test case SHOULD work, that range should be correct.


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

https://reviews.llvm.org/D130058



More information about the cfe-commits mailing list