From 159589d3562f20a9ddc4190ac7142c6ffcc33cb7 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Fri, 30 Aug 2024 09:57:14 -0500 Subject: [PATCH] remove out-of-line defns of constexpr static data members under c++17 Address warnings of this form under c++17 when building with `-Werror -Wdeprecated`: ``` fast_float/float_common.h:446:58: error: out-of-line definition of constexpr static data member is redundant in C++17 and is deprecated [-Werror,-Wdeprecated] constexpr double binary_format_lookup_tables::powers_of_ten[]; ^ ``` --- include/fast_float/bigint.h | 4 ++++ include/fast_float/constexpr_feature_detect.h | 6 ++++++ include/fast_float/fast_table.h | 4 ++++ include/fast_float/float_common.h | 16 ++++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/include/fast_float/bigint.h b/include/fast_float/bigint.h index 92c3d5b1..03a5caa4 100644 --- a/include/fast_float/bigint.h +++ b/include/fast_float/bigint.h @@ -404,12 +404,16 @@ template struct pow5_tables { #endif }; +#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE + template constexpr uint32_t pow5_tables::large_step; template constexpr uint64_t pow5_tables::small_power_of_5[]; template constexpr limb pow5_tables::large_power_of_5[]; +#endif + // big integer type. implements a small subset of big integer // arithmetic, using simple algorithms since asymptotically // faster algorithms are slower for a small number of limbs. diff --git a/include/fast_float/constexpr_feature_detect.h b/include/fast_float/constexpr_feature_detect.h index 18daf409..7624beaf 100644 --- a/include/fast_float/constexpr_feature_detect.h +++ b/include/fast_float/constexpr_feature_detect.h @@ -37,4 +37,10 @@ #define FASTFLOAT_IS_CONSTEXPR 0 #endif +#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) +#define FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE 0 +#else +#define FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE 1 +#endif + #endif // FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H diff --git a/include/fast_float/fast_table.h b/include/fast_float/fast_table.h index 097e27b1..69f9b2c9 100644 --- a/include/fast_float/fast_table.h +++ b/include/fast_float/fast_table.h @@ -693,10 +693,14 @@ template struct powers_template { }; }; +#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE + template constexpr uint64_t powers_template::power_of_five_128[number_of_entries]; +#endif + using powers = powers_template<>; } // namespace fast_float diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index ddee4ce6..ea73a199 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -442,12 +442,16 @@ template struct binary_format_lookup_tables { constant_55555 * 5 * 5 * 5 * 5)}; }; +#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE + template constexpr double binary_format_lookup_tables::powers_of_ten[]; template constexpr uint64_t binary_format_lookup_tables::max_mantissa[]; +#endif + template struct binary_format_lookup_tables { static constexpr float powers_of_ten[] = {1e0f, 1e1f, 1e2f, 1e3f, 1e4f, 1e5f, 1e6f, 1e7f, 1e8f, 1e9f, 1e10f}; @@ -469,12 +473,16 @@ template struct binary_format_lookup_tables { 0x1000000 / (constant_55555 * constant_55555 * 5)}; }; +#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE + template constexpr float binary_format_lookup_tables::powers_of_ten[]; template constexpr uint64_t binary_format_lookup_tables::max_mantissa[]; +#endif + template <> inline constexpr int binary_format::min_exponent_fast_path() { #if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0) @@ -677,8 +685,12 @@ template struct space_lut { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; }; +#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE + template constexpr bool space_lut::value[]; +#endif + inline constexpr bool is_space(uint8_t c) { return space_lut<>::value[c]; } #endif @@ -759,12 +771,16 @@ template struct int_luts { 3379220508056640625, 4738381338321616896}; }; +#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE + template constexpr uint8_t int_luts::chdigit[]; template constexpr size_t int_luts::maxdigits_u64[]; template constexpr uint64_t int_luts::min_safe_u64[]; +#endif + template fastfloat_really_inline constexpr uint8_t ch_to_digit(UC c) { return int_luts<>::chdigit[static_cast(c)];