https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109921
Bug ID: 109921 Summary: c++17/floating_from_chars.cc: compile error: ‘from_chars_strtod’ was not declared in this scope Product: gcc Version: 13.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: br015 at umbiko dot net Target Milestone: --- This was observed in 13.1.0, but code is the same as git master. Line numbers and code snippets refer to git master. /observed error/ Cross-compiling gcc 13.1 for a system without locales, libstdc++ fails to build with the following error: >Making all in c++17 >/bin/bash ../../libtool --tag CXX --tag disable-shared --mode=compile >/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/./gcc/xgcc >-shared-libgcc >-B/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/./gcc >-nostdinc++ >-L/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/x86_64-buildroot-linux-uclibc/libstdc++-v3/src > >-L/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/x86_64-buildroot-linux-uclibc/libstdc++-v3/src/.libs > >-L/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/x86_64-buildroot-linux-uclibc/libstdc++-v3/libsupc++/.libs > -B/home/data/buildroot.x86_64/host/x86_64-buildroot-linux-uclibc/bin/ >-B/home/data/buildroot.x86_64/host/x86_64-buildroot-linux-uclibc/lib/ -isystem >/home/data/buildroot.x86_64/host/x86_64-buildroot-linux-uclibc/include >-isystem >/home/data/buildroot.x86_64/host/x86_64-buildroot-linux-uclibc/sys-include >-I/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/libstdc++-v3/../libgcc > >-I/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/x86_64-buildroot-linux-uclibc/libstdc++-v3/include/x86_64-buildroot-linux-uclibc > >-I/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/x86_64-buildroot-linux-uclibc/libstdc++-v3/include > >-I/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/libstdc++-v3/libsupc++ > -std=gnu++17 -nostdinc++ -prefer-pic -D_GLIBCXX_SHARED >-fno-implicit-templates -Wall -Wextra -Wwrite-strings -Wcast-qual -Wabi=2 >-fdiagnostics-show-location=once -ffunction-sections -fdata-sections >-frandom-seed=floating_from_chars.lo -fimplicit-templates -D_LARGEFILE_SOURCE >-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g0 -D_GNU_SOURCE >-fcf-protection -mshstk -c -o floating_from_chars.lo >../../../../../libstdc++-v3/src/c++17/floating_from_chars.cc >libtool: compile: >/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/./gcc/xgcc >-shared-libgcc >-B/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/./gcc >-nostdinc++ >-L/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/x86_64-buildroot-linux-uclibc/libstdc++-v3/src > >-L/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/x86_64-buildroot-linux-uclibc/libstdc++-v3/src/.libs > >-L/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/x86_64-buildroot-linux-uclibc/libstdc++-v3/libsupc++/.libs > -B/home/data/buildroot.x86_64/host/x86_64-buildroot-linux-uclibc/bin/ >-B/home/data/buildroot.x86_64/host/x86_64-buildroot-linux-uclibc/lib/ -isystem >/home/data/buildroot.x86_64/host/x86_64-buildroot-linux-uclibc/include >-isystem >/home/data/buildroot.x86_64/host/x86_64-buildroot-linux-uclibc/sys-include >-I/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/libstdc++-v3/../libgcc > >-I/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/x86_64-buildroot-linux-uclibc/libstlibtool: > compile: >/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/./gcc/xgcc >-shared-libgcc >-B/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/./gcc >-nostdinc++ >-L/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/x86_64-buildroot-linux-uclibc/libstdc++-v3/src > >-L/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/x86_64-buildroot-linux-uclibc/libstdc++-v3/src/.libs > >-L/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/x86_64-buildroot-linux-uclibc/libstdc++-v3/libsupc++/.libs > -B/home/data/buildroot.x86_64/host/x86_64-buildroot-linux-uclibc/bin/ >-B/home/data/buildroot.x86_64/host/x86_64-buildroot-linux-uclibc/lib/ -isystem >/home/data/buildroot.x86_64/host/x86_64-buildroot-linux-uclibc/include >-isystem >/home/data/buildroot.x86_64/host/x86_64-buildroot-linux-uclibc/sys-include >-I/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/libstdc++-v3/../libgcc > >-I/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/x86_64-buildroot-linux-uclibc/libstdc++-v3/include/x86_64-buildroot-linux-uclibc > >-I/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/build/x86_64-buildroot-linux-uclibc/libstdc++-v3/include > >-I/home/data/buildroot.x86_64/build/host-gcc-final-13.1.0/libstdc++-v3/libsupc++ > -std=gnu++17 -nostdinc++ -D_GLIBCXX_SHARED -fno-implicit-templates -Wall >-Wextra -Wwrite-strings -Wcast-qual -Wabi=2 -fdiagnostics-show-location=once >-ffunction-sections -fdata-sections -frandom-seed=floating_from_chars.lo >-fimplicit-templates -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE >-D_FILE_OFFSET_BITS=64 -O2 -g0 -D_GNU_SOURCE -fcf-protection -mshstk -c >../../../../../libstdc++-v3/src/c++17/floating_from_chars.cc -fPIC -DPIC >-D_GLIBCXX_SHARED -o floating_from_chars.o >../../../../../libstdc++-v3/src/c++17/floating_from_chars.cc: In function >‘std::from_chars_result std::from_chars(const char*, const char*, _Float128&, >chars_format)’: >../../../../../libstdc++-v3/src/c++17/floating_from_chars.cc:1281:10: error: >‘from_chars_strtod’ was not declared in this scope > 1281 | return from_chars_strtod(first, last, value, fmt); > | ^~~~~~~~~~~~~~~~~ >make[7]: *** [Makefile:587: floating_from_chars.lo] Error 1 /root cause analysis/ The symbol USE_STRTOD_FOR_FROM_CHARS is initially unknown. Since the target system does not use locales, it will not be defined within the scope of floating_to_chars.cc [1]: >#if _GLIBCXX_HAVE_USELOCALE >// FIXME: This should be reimplemented so it doesn't use strtod and newlocale. >// That will avoid the need for any memory allocation, meaning that the >// non-conforming errc::not_enough_memory result cannot happen. ># define USE_STRTOD_FOR_FROM_CHARS 1 >#endif This results in code for from_chars_strtod() not being generated (lines 366 to 794) [2]. from_chars() implementation is generated either if USE_LIB_FAST_FLOAT or USE_STRTOD_FOR_FROM_CHARS is enabled [3]. Within this section is code that relies on USE_STRTOD_FOR_FROM_CHARS, but omits to check if the functionality is available [4] >#elif defined(USE_STRTOF128_FOR_FROM_CHARS) >from_chars_result >from_chars(const char* first, const char* last, _Float128& value, > chars_format fmt) noexcept >{ > // fast_float doesn't support IEEE binary128 format, but we can use strtold. > return from_chars_strtod(first, last, value, fmt); >} >#endif which results in the observed compilation error. /proposed change/ Check if USE_STRTOD_FOR_FROM_CHARS is set before using from_chars_strtod(): --- a/libstdc++-v3/src/c++17/floating_from_chars.cc 2023-04-26 09:09:43.000000000 +0200 +++ b/libstdc++-v3/src/c++17/floating_from_chars.cc 2023-05-19 07:56:56.754330183 +0200 @@ -1264,6 +1264,8 @@ __attribute__((alias ("_ZSt10from_charsPKcS0_RdSt12chars_format"))); #endif +#if defined(USE_STRTOD_FOR_FROM_CHARS) +// otherwise there is no from_chars_strtod #ifdef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT from_chars_result from_chars(const char* first, const char* last, __ieee128& value, @@ -1282,6 +1284,8 @@ } #endif +#endif // USE_STRTOD_FOR_FROM_CHARS + #endif // USE_LIB_FAST_FLOAT || USE_STRTOD_FOR_FROM_CHARS _GLIBCXX_END_NAMESPACE_VERSION [1] https://github.com/gcc-mirror/gcc/blob/7f3df8e65c71e5df01fe7fe7de577bb9ff48f37b/libstdc%2B%2B-v3/src/c%2B%2B17/floating_from_chars.cc#L53-L58 [2] https://github.com/gcc-mirror/gcc/blob/7f3df8e65c71e5df01fe7fe7de577bb9ff48f37b/libstdc%2B%2B-v3/src/c%2B%2B17/floating_from_chars.cc#L366-L794 [3] https://github.com/gcc-mirror/gcc/blob/7f3df8e65c71e5df01fe7fe7de577bb9ff48f37b/libstdc%2B%2B-v3/src/c%2B%2B17/floating_from_chars.cc#L1230-L1342 [4] https://github.com/gcc-mirror/gcc/blob/7f3df8e65c71e5df01fe7fe7de577bb9ff48f37b/libstdc%2B%2B-v3/src/c%2B%2B17/floating_from_chars.cc#L1317-L1340