From 59040a4c8a3485eb32527293eac0abba5be7023b Mon Sep 17 00:00:00 2001 From: SnapperTT <4939563+SnapperTT@users.noreply.github.com> Date: Sat, 20 Sep 2025 01:41:32 +0930 Subject: [PATCH 1/2] Make FMT_USE_CONSTEVAL optional #4545 --- include/fmt/base.h | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index 42e192aca6a0..83129ef5b7d6 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -114,24 +114,26 @@ #endif // Detect consteval, C++20 constexpr extensions and std::is_constant_evaluated. -#if !defined(__cpp_lib_is_constant_evaluated) -# define FMT_USE_CONSTEVAL 0 -#elif FMT_CPLUSPLUS < 201709L -# define FMT_USE_CONSTEVAL 0 -#elif FMT_GLIBCXX_RELEASE && FMT_GLIBCXX_RELEASE < 10 -# define FMT_USE_CONSTEVAL 0 -#elif FMT_LIBCPP_VERSION && FMT_LIBCPP_VERSION < 10000 -# define FMT_USE_CONSTEVAL 0 -#elif defined(__apple_build_version__) && __apple_build_version__ < 14000029L -# define FMT_USE_CONSTEVAL 0 // consteval is broken in Apple clang < 14. -#elif FMT_MSC_VERSION && FMT_MSC_VERSION < 1929 -# define FMT_USE_CONSTEVAL 0 // consteval is broken in MSVC VS2019 < 16.10. -#elif defined(__cpp_consteval) -# define FMT_USE_CONSTEVAL 1 -#elif FMT_GCC_VERSION >= 1002 || FMT_CLANG_VERSION >= 1101 -# define FMT_USE_CONSTEVAL 1 -#else -# define FMT_USE_CONSTEVAL 0 +#ifndef FMT_USE_CONSTEVAL +# if !defined(__cpp_lib_is_constant_evaluated) +# define FMT_USE_CONSTEVAL 0 +# elif FMT_CPLUSPLUS < 201709L +# define FMT_USE_CONSTEVAL 0 +# elif FMT_GLIBCXX_RELEASE && FMT_GLIBCXX_RELEASE < 10 +# define FMT_USE_CONSTEVAL 0 +# elif FMT_LIBCPP_VERSION && FMT_LIBCPP_VERSION < 10000 +# define FMT_USE_CONSTEVAL 0 +# elif defined(__apple_build_version__) && __apple_build_version__ < 14000029L +# define FMT_USE_CONSTEVAL 0 // consteval is broken in Apple clang < 14. +# elif FMT_MSC_VERSION && FMT_MSC_VERSION < 1929 +# define FMT_USE_CONSTEVAL 0 // consteval is broken in MSVC VS2019 < 16.10. +# elif defined(__cpp_consteval) +# define FMT_USE_CONSTEVAL 1 +# elif FMT_GCC_VERSION >= 1002 || FMT_CLANG_VERSION >= 1101 +# define FMT_USE_CONSTEVAL 1 +# else +# define FMT_USE_CONSTEVAL 0 +# endif #endif #if FMT_USE_CONSTEVAL # define FMT_CONSTEVAL consteval @@ -359,6 +361,10 @@ template FMT_CONSTEXPR void ignore_unused(const T&...) {} constexpr auto is_constant_evaluated(bool default_value = false) noexcept -> bool { +// If FMT_USE_CONSTEVAL is disabled then this cannot be true +#if !FMT_USE_CONSTEVAL + return false; +#endif // Workaround for incompatibility between clang 14 and libstdc++ consteval-based // std::is_constant_evaluated: https://github.com/fmtlib/fmt/issues/3247. #if FMT_CPLUSPLUS >= 202002L && FMT_GLIBCXX_RELEASE >= 12 && \ From 4f620c69e545f3d2a91de79102f6cac5a18e7d9f Mon Sep 17 00:00:00 2001 From: SnapperTT <4939563+SnapperTT@users.noreply.github.com> Date: Wed, 24 Sep 2025 12:13:49 +0930 Subject: [PATCH 2/2] Requested changes to #ifdef FMT_USE_CONSTEVAL --- include/fmt/base.h | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index 2ce0ece82e9a..4b687a8f6b2f 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -114,26 +114,26 @@ #endif // Detect consteval, C++20 constexpr extensions and std::is_constant_evaluated. -#ifndef FMT_USE_CONSTEVAL -# if !defined(__cpp_lib_is_constant_evaluated) -# define FMT_USE_CONSTEVAL 0 -# elif FMT_CPLUSPLUS < 201709L -# define FMT_USE_CONSTEVAL 0 -# elif FMT_GLIBCXX_RELEASE && FMT_GLIBCXX_RELEASE < 10 -# define FMT_USE_CONSTEVAL 0 -# elif FMT_LIBCPP_VERSION && FMT_LIBCPP_VERSION < 10000 -# define FMT_USE_CONSTEVAL 0 -# elif defined(__apple_build_version__) && __apple_build_version__ < 14000029L -# define FMT_USE_CONSTEVAL 0 // consteval is broken in Apple clang < 14. -# elif FMT_MSC_VERSION && FMT_MSC_VERSION < 1929 -# define FMT_USE_CONSTEVAL 0 // consteval is broken in MSVC VS2019 < 16.10. -# elif defined(__cpp_consteval) -# define FMT_USE_CONSTEVAL 1 -# elif FMT_GCC_VERSION >= 1002 || FMT_CLANG_VERSION >= 1101 -# define FMT_USE_CONSTEVAL 1 -# else -# define FMT_USE_CONSTEVAL 0 -# endif +#ifdef FMT_USE_CONSTEVAL +// Use the provided definition. +#elif !defined(__cpp_lib_is_constant_evaluated) +# define FMT_USE_CONSTEVAL 0 +#elif FMT_CPLUSPLUS < 201709L +# define FMT_USE_CONSTEVAL 0 +#elif FMT_GLIBCXX_RELEASE && FMT_GLIBCXX_RELEASE < 10 +# define FMT_USE_CONSTEVAL 0 +#elif FMT_LIBCPP_VERSION && FMT_LIBCPP_VERSION < 10000 +# define FMT_USE_CONSTEVAL 0 +#elif defined(__apple_build_version__) && __apple_build_version__ < 14000029L +# define FMT_USE_CONSTEVAL 0 // consteval is broken in Apple clang < 14. +#elif FMT_MSC_VERSION && FMT_MSC_VERSION < 1929 +# define FMT_USE_CONSTEVAL 0 // consteval is broken in MSVC VS2019 < 16.10. +#elif defined(__cpp_consteval) +# define FMT_USE_CONSTEVAL 1 +#elif FMT_GCC_VERSION >= 1002 || FMT_CLANG_VERSION >= 1101 +# define FMT_USE_CONSTEVAL 1 +#else +# define FMT_USE_CONSTEVAL 0 #endif #if FMT_USE_CONSTEVAL # define FMT_CONSTEVAL consteval @@ -361,10 +361,6 @@ template FMT_CONSTEXPR void ignore_unused(const T&...) {} constexpr auto is_constant_evaluated(bool default_value = false) noexcept -> bool { -// If FMT_USE_CONSTEVAL is disabled then this cannot be true -#if !FMT_USE_CONSTEVAL - return false; -#endif // Workaround for incompatibility between clang 14 and libstdc++ consteval-based // std::is_constant_evaluated: https://github.com/fmtlib/fmt/issues/3247. #if FMT_CPLUSPLUS >= 202002L && FMT_GLIBCXX_RELEASE >= 12 && \