diff --git a/src/core/include/mp-units/framework/dimension.h b/src/core/include/mp-units/framework/dimension.h index c1279ce4..2a65aa9e 100644 --- a/src/core/include/mp-units/framework/dimension.h +++ b/src/core/include/mp-units/framework/dimension.h @@ -305,18 +305,22 @@ constexpr Out dimension_symbol_to(Out out, D d, const dimension_symbol_formattin // TODO Refactor to `dimension_symbol(D, fmt)` when P1045: constexpr Function Parameters is available MP_UNITS_EXPORT template +#if defined MP_UNITS_COMP_CLANG && MP_UNITS_COMP_CLANG <= 18 [[nodiscard]] constexpr auto dimension_symbol(D) +#else +[[nodiscard]] consteval auto dimension_symbol(D) +#endif { - auto get_symbol_text = []() consteval { - detail::inplace_vector text; // TODO can we improve here? + constexpr auto oversized_symbol_text = []() consteval { + detail::inplace_vector text; // TODO can we improve here? dimension_symbol_to(std::back_inserter(text), D{}, fmt); return text; - }; - constexpr auto text = get_symbol_text(); + }(); #if MP_UNITS_API_STRING_VIEW_RET // Permitting static constexpr variables in constexpr functions - static constexpr basic_fixed_string buffer(std::from_range, text); - return buffer.view(); + static constexpr basic_fixed_string storage(std::from_range, + oversized_symbol_text); + return storage.view(); #else return basic_fixed_string(std::from_range, text); #endif diff --git a/src/core/include/mp-units/framework/unit.h b/src/core/include/mp-units/framework/unit.h index cc285d2a..d1b58e56 100644 --- a/src/core/include/mp-units/framework/unit.h +++ b/src/core/include/mp-units/framework/unit.h @@ -816,18 +816,22 @@ constexpr Out unit_symbol_to(Out out, U u, const unit_symbol_formatting& fmt = u // TODO Refactor to `unit_symbol(U, fmt)` when P1045: constexpr Function Parameters is available MP_UNITS_EXPORT template +#if defined MP_UNITS_COMP_CLANG && MP_UNITS_COMP_CLANG <= 18 [[nodiscard]] constexpr auto unit_symbol(U) +#else +[[nodiscard]] consteval auto unit_symbol(U) +#endif { - auto get_symbol_text = []() consteval { - detail::inplace_vector text; // TODO can we improve here? + constexpr auto oversized_symbol_text = []() consteval { + detail::inplace_vector text; // TODO can we improve here? unit_symbol_to(std::back_inserter(text), U{}, fmt); return text; - }; - constexpr auto text = get_symbol_text(); + }(); #if MP_UNITS_API_STRING_VIEW_RET // Permitting static constexpr variables in constexpr functions - static constexpr basic_fixed_string buffer(std::from_range, text); - return buffer.view(); + static constexpr basic_fixed_string storage(std::from_range, + oversized_symbol_text); + return storage.view(); #else return basic_fixed_string(std::from_range, text); #endif