From StackOverflow https://stackoverflow.com/questions/72068948/is-stdfrom-chars-supposed-to-handle-uppercase-hexadecimal-exponents/72069971#72069971 testsuite: https://godbolt.org/z/ad1es7eE6
floating_from_chars.cc#L667 // Parse the written exponent. int written_exponent = 0; if (first != last && *first == 'p') { // Tentatively consume the 'p' and try to parse a decimal number. const char* const fallback_first = first; it seems like it should be if (first != last && std::tolower((unsigned char)*first) == 'p')
Thanks for reporting and analyzing this! (In reply to 康桓瑋 from comment #2) > floating_from_chars.cc#L667 > > // Parse the written exponent. > int written_exponent = 0; > if (first != last && *first == 'p') > { > // Tentatively consume the 'p' and try to parse a decimal number. > const char* const fallback_first = first; > > it seems like it should be > > if (first != last && std::tolower((unsigned char)*first) == 'p') I'm not sure we can use tolower here because it's locale dependent and charconv isn't. So we should just test for 'p' and 'P' directly. And we should probably replace the existing use of tolower in find_end_of_float. I wonder why the SO user is seeing this bug with GCC 11.2? The new hexfloat parser (r12-6645-gcc3bf3404e4b1c) is GCC 12 only.
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>: https://gcc.gnu.org/g:576f975cabb0fd9843de152a2d247d486a967b08 commit r13-69-g576f975cabb0fd9843de152a2d247d486a967b08 Author: Patrick Palka <ppalka@redhat.com> Date: Mon May 2 07:00:48 2022 -0400 libstdc++: case-sensitivity in hexfloat std::from_chars [PR105441] The hexfloat parser for binary32/64 added in r12-6645-gcc3bf3404e4b1c overlooked that the exponent part can also begin with an uppercase 'P'. PR libstdc++/105441 libstdc++-v3/ChangeLog: * src/c++17/floating_from_chars.cc (__floating_from_chars_hex): Also accept 'P' as the start of the exponent. * testsuite/20_util/from_chars/7.cc: Add corresponding testcase.
The releases/gcc-12 branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>: https://gcc.gnu.org/g:4a6d7da796e456115bbac92e056123f095a3780c commit r12-8327-g4a6d7da796e456115bbac92e056123f095a3780c Author: Patrick Palka <ppalka@redhat.com> Date: Mon May 2 07:00:48 2022 -0400 libstdc++: case-sensitivity in hexfloat std::from_chars [PR105441] The hexfloat parser for binary32/64 added in r12-6645-gcc3bf3404e4b1c overlooked that the exponent part can also begin with an uppercase 'P'. PR libstdc++/105441 libstdc++-v3/ChangeLog: * src/c++17/floating_from_chars.cc (__floating_from_chars_hex): Also accept 'P' as the start of the exponent. * testsuite/20_util/from_chars/7.cc: Add corresponding testcase. (cherry picked from commit 576f975cabb0fd9843de152a2d247d486a967b08)
Should be fixed. Replacing the use of std::tolower was done in the subsequent commit r13-70-g86d821ddf5615e.