[PATCH] D130058: [Clang] Diagnose ill-formed constant expression when setting a non fixed enum to a value outside the range of the enumeration values
Shafik Yaghmour via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 29 12:29:59 PDT 2022
shafik 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 is a bug, I am looking at possible fixes right now and if I can't figure out something good in the next day otherwise I will revert.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D130058/new/
https://reviews.llvm.org/D130058
More information about the cfe-commits
mailing list