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

@ -829,7 +829,8 @@ inline constexpr auto max_v = (count_v<E, S> > 0) ? static_cast<U>(values_v<E, S
template <typename E, enum_subtype S, std::size_t... I>
constexpr auto names(std::index_sequence<I...>) noexcept {
return std::array<string_view, sizeof...(I)>{{enum_name_v<E, values_v<E, S>[I]>...}};
constexpr auto result = std::array<string_view, sizeof...(I)>{{enum_name_v<E, values_v<E, S>[I]>...}};
return result;
}
template <typename E, enum_subtype S>