@@ -101,6 +101,23 @@ using parse_options = parse_options_t<char>;
101101#include < bit>
102102#endif
103103
104+ namespace fast_float {
105+ template <typename To, typename From>
106+ FASTFLOAT_CONSTEXPR20 To bit_cast (const From &from) {
107+ #if FASTFLOAT_HAS_BIT_CAST
108+ return std::bit_cast<To>(from);
109+ #else
110+ // Implementation of std::bit_cast for pre-C++20.
111+ static_assert (sizeof (To) == sizeof (From),
112+ " bit_cast requires source and destination to be the same size" );
113+ auto to = To ();
114+ // The cast suppresses a bogus -Wclass-memaccess on GCC.
115+ std::memcpy (static_cast <void *>(&to), &from, sizeof (to));
116+ return to;
117+ #endif
118+ }
119+ } // namespace fast_float
120+
104121#if (defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
105122 defined (__amd64) || defined(__aarch64__) || defined(_M_ARM64) || \
106123 defined(__MINGW64__) || defined(__s390x__) || \
@@ -1029,6 +1046,7 @@ binary_format<double>::hidden_bit_mask() {
10291046 return 0x0010000000000000 ;
10301047}
10311048
1049+ // Fix for C2672: Ensure bit_cast is called with explicit template arguments
10321050template <typename T>
10331051fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void to_float (
10341052#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
@@ -1043,15 +1061,7 @@ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void to_float(
10431061 word =
10441062 equiv_uint (word | equiv_uint (negative) << binary_format<T>::sign_index ());
10451063#endif
1046- #if FASTFLOAT_HAS_BIT_CAST
1047- value =
1048- #if FASTFLOAT_HAS_BIT_CAST == 1
1049- std::
1050- #endif
1051- bit_cast<T>(word);
1052- #else
1053- ::memcpy (&value, &word, sizeof (T));
1054- #endif
1064+ value = bit_cast<T, equiv_uint>(word);
10551065}
10561066
10571067#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
0 commit comments