From 60734e063eec18f066d599e7e29591d96928e25d Mon Sep 17 00:00:00 2001 From: HedgehogInTheCPP Date: Fri, 21 Aug 2026 19:56:09 +0300 Subject: [PATCH] Improvements detection of features, part 5. --- CMakeLists.txt | 15 ++++---- include/fast_float/constexpr_feature_detect.h | 37 +++++++------------ 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0f3907..f8e5d2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ else(FASTFLOAT_TEST) endif(FASTFLOAT_TEST) option(FASTFLOAT_SANITIZE "Sanitize addresses" OFF) -if (NOT CMAKE_BUILD_TYPE) +if(NOT CMAKE_BUILD_TYPE) if(FASTFLOAT_SANITIZE) set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE) else() @@ -67,16 +67,15 @@ if(FASTFLOAT_SANITIZE) -fsanitize=undefined -fno-sanitize-recover=all ) - if (CMAKE_COMPILER_IS_GNUCC) + if(CMAKE_COMPILER_IS_GNUCC) target_link_libraries(fast_float INTERFACE -fuse-ld=gold) endif() endif() -target_compile_options( - fast_float - INTERFACE - $<$,$,19.10>>:/permissive-> -) +if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" + AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.10) + target_compile_options(fast_float INTERFACE /permissive-) +endif() if(FASTFLOAT_INSTALL) include(CMakePackageConfigHelpers) @@ -85,7 +84,7 @@ if(FASTFLOAT_INSTALL) set(FASTFLOAT_PROJECT_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/module/FastFloatConfig.cmake") set(FASTFLOAT_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATAROOTDIR}/cmake/FastFloat") - if(${CMAKE_VERSION} VERSION_LESS "3.14") + if(CMAKE_VERSION VERSION_LESS "3.14") write_basic_package_version_file( "${FASTFLOAT_VERSION_CONFIG}" VERSION ${PROJECT_VERSION} diff --git a/include/fast_float/constexpr_feature_detect.h b/include/fast_float/constexpr_feature_detect.h index 9a3b754..e4ce70d 100644 --- a/include/fast_float/constexpr_feature_detect.h +++ b/include/fast_float/constexpr_feature_detect.h @@ -8,16 +8,12 @@ #endif // C++14 constexpr -#if defined(_MSC_VER) -#if defined(_MSVC_LANG) && _MSVC_LANG >= 201402L -#define FASTFLOAT_CONSTEXPR14 constexpr -#else -#define FASTFLOAT_CONSTEXPR14 -#endif -#elif defined(__cpp_constexpr) && __cpp_constexpr >= 201304L +#if defined(__cpp_constexpr) && __cpp_constexpr >= 201304L #define FASTFLOAT_CONSTEXPR14 constexpr #elif defined(__cplusplus) && __cplusplus >= 201402L #define FASTFLOAT_CONSTEXPR14 constexpr +#elif defined(_MSC_VER) && defined(_MSVC_LANG) && _MSVC_LANG >= 201402L +#define FASTFLOAT_CONSTEXPR14 constexpr #else #define FASTFLOAT_CONSTEXPR14 #endif @@ -58,6 +54,7 @@ #define FASTFLOAT_INLINE_VARIABLE static constexpr #endif +// Before C++17, constexpr variables may need an out-of-class definition. #if (defined(__cplusplus) && __cplusplus >= 201703L) || \ (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) #define FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE 0 @@ -72,33 +69,27 @@ #define FASTFLOAT_HAS_BIT_CAST 0 #endif +// C++20 std::is_constant_evaluated #if defined(__cpp_lib_is_constant_evaluated) && \ __cpp_lib_is_constant_evaluated >= 201811L #define FASTFLOAT_HAS_IS_CONSTANT_EVALUATED 1 -#else -#define FASTFLOAT_HAS_IS_CONSTANT_EVALUATED 0 -#endif - -// C++20 consteval -#if defined(__cpp_consteval) && __cpp_consteval >= 201811L #define FASTFLOAT_CONSTEVAL consteval #else +#define FASTFLOAT_HAS_IS_CONSTANT_EVALUATED 0 #define FASTFLOAT_CONSTEVAL FASTFLOAT_CONSTEXPR14 #endif -// C++20 constexpr function support -#if defined(_MSC_VER) -#if defined(_MSVC_LANG) && _MSVC_LANG >= 202002L -#define FASTFLOAT_CONSTEXPR20 constexpr -#else -#define FASTFLOAT_CONSTEXPR20 -#endif -#elif defined(__cpp_constexpr) && __cpp_constexpr >= 201907L -#define FASTFLOAT_CONSTEXPR20 constexpr -#elif defined(__cplusplus) && __cplusplus >= 202002L +// C++20 constexpr library support, including std::is_constant_evaluated(), +// std::bit_cast(), and constexpr algorithms. Therefore all required library +// feature macros must be present. +#if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED && FASTFLOAT_HAS_BIT_CAST && \ + defined(__cpp_lib_constexpr_algorithms) && \ + __cpp_lib_constexpr_algorithms >= 201806L #define FASTFLOAT_CONSTEXPR20 constexpr +#define FASTFLOAT_IS_CONSTEXPR 1 #else #define FASTFLOAT_CONSTEXPR20 +#define FASTFLOAT_IS_CONSTEXPR 0 #endif // C++20 std::byteswap