From 810d1750f1579f19d842b6f3ca6671f714375444 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 11 Jan 2024 21:06:40 -0800 Subject: [PATCH] Cleanup constexpr detection --- include/fmt/base.h | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index c5d57c4b..137dc1c4 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -101,14 +101,6 @@ #define FMT_HAS_CPP17_ATTRIBUTE(attribute) \ (FMT_CPLUSPLUS >= 201703L && FMT_HAS_CPP_ATTRIBUTE(attribute)) -#ifdef FMT_DEPRECATED -// Use the provided definition. -#elif FMT_HAS_CPP14_ATTRIBUTE(deprecated) -# define FMT_DEPRECATED [[deprecated]] -#else -# define FMT_DEPRECATED /* deprecated */ -#endif - // Detect C++14 relaxed constexpr. #ifdef FMT_USE_CONSTEXPR // Use the provided definition. @@ -129,12 +121,18 @@ # define FMT_CONSTEXPR #endif -#if (FMT_CPLUSPLUS >= 202002L || \ - (FMT_CPLUSPLUS >= 201709L && FMT_GCC_VERSION >= 1002)) && \ - ((!FMT_GLIBCXX_RELEASE || FMT_GLIBCXX_RELEASE >= 10) && \ - (!FMT_LIBCPP_VERSION || FMT_LIBCPP_VERSION >= 10000) && \ - (!FMT_MSC_VERSION || FMT_MSC_VERSION >= 1928)) && \ - defined(__cpp_lib_is_constant_evaluated) +// Detect C++20 extensions to constexpr and std::is_constant_evaluated. +#ifndef __cpp_lib_is_constant_evaluated +# define FMT_CONSTEXPR20 +#elif FMT_GLIBCXX_RELEASE && FMT_GLIBCXX_RELEASE < 10 +# define FMT_CONSTEXPR20 +#elif FMT_LIBCPP_VERSION && FMT_LIBCPP_VERSION < 10000 +# define FMT_CONSTEXPR20 +#elif FMT_MSC_VERSION && FMT_MSC_VERSION < 1928 +# define FMT_CONSTEXPR20 +#elif FMT_CPLUSPLUS >= 202002L +# define FMT_CONSTEXPR20 constexpr +#elif FMT_CPLUSPLUS >= 201709L && FMT_GCC_VERSION >= 1002 # define FMT_CONSTEXPR20 constexpr #else # define FMT_CONSTEXPR20 @@ -156,6 +154,14 @@ # endif #endif +#ifdef FMT_DEPRECATED +// Use the provided definition. +#elif FMT_HAS_CPP14_ATTRIBUTE(deprecated) +# define FMT_DEPRECATED [[deprecated]] +#else +# define FMT_DEPRECATED /* deprecated */ +#endif + // Disable [[noreturn]] on MSVC/NVCC because of bogus unreachable code warnings. #if FMT_EXCEPTIONS && FMT_HAS_CPP_ATTRIBUTE(noreturn) && !FMT_MSC_VERSION && \ !defined(__NVCC__)