diff --git a/flang/include/flang/Common/enum-class.h b/flang/include/flang/Common/enum-class.h index 0635a0c85be05..9f9134ee3ff7a 100644 --- a/flang/include/flang/Common/enum-class.h +++ b/flang/include/flang/Common/enum-class.h @@ -62,14 +62,13 @@ constexpr std::array EnumNames(const char *p) { enum class NAME { __VA_ARGS__ }; \ [[maybe_unused]] static constexpr std::size_t NAME##_enumSize{ \ ::Fortran::common::CountEnumNames(#__VA_ARGS__)}; \ - [[maybe_unused]] static constexpr std::array NAME##_names{ \ - ::Fortran::common::EnumNames(#__VA_ARGS__)}; \ [[maybe_unused]] static inline std::size_t EnumToInt(NAME e) { \ return static_cast(e); \ } \ [[maybe_unused]] static inline std::string_view EnumToString(NAME e) { \ - return NAME##_names[static_cast(e)]; \ + static const constexpr auto names{ \ + ::Fortran::common::EnumNames(#__VA_ARGS__)}; \ + return names[static_cast(e)]; \ } \ [[maybe_unused]] inline void ForEach##NAME(std::function f) { \ for (std::size_t i{0}; i < NAME##_enumSize; ++i) { \