1
0
Fork 0
mirror of https://github.com/Neargye/magic_enum.git synced 2026-01-09 23:34:23 +00:00

Explicitly mark the result of detail::names as constexpr (#305)

It might make no sense, but on MSVC it can generate a compile-time
error, especially if an enumerator's value is out of range.

Example:
error C3615: constexpr function 'magic_enum::detail::names' cannot
result in a constant expression
...
note: failure was caused by call of undefined function or one not
declared 'constexpr'
...
note: see usage of '__builtin_array_init_helper'
This commit is contained in:
Vitaly 2023-11-09 11:09:37 +01:00 committed by GitHub
parent 5cf4eb3a53
commit 5523803cfc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View file

@ -510,6 +510,11 @@ class a_foo2 {
};
} // namespace
enum class LargeNumbers {
First = -1024,
Second = 1024
};
TEST_CASE("enum_name") {
SECTION("automatic storage") {
constexpr Color cr = Color::RED;
@ -646,6 +651,13 @@ TEST_CASE("enum_name") {
REQUIRE(enum_name<Binary::ONE>() == "ONE");
REQUIRE(enum_name<MaxUsedAsInvalid::ONE>() == "ONE");
}
SECTION("empty if the value is out of range") {
const auto ln_value = GENERATE(LargeNumbers::First, LargeNumbers::Second);
const auto ln_name = enum_name(ln_value);
REQUIRE(ln_name.empty());
}
}
TEST_CASE("enum_names") {