[PATCH] D130058: [Clang] Diagnose ill-formed constant expression when setting a non fixed enum to a value outside the range of the enumeration values
Nico Weber via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 29 11:29:04 PDT 2022
thakis added a comment.
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?
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D130058/new/
https://reviews.llvm.org/D130058
More information about the cfe-commits
mailing list