[PATCH] Enable libstdc++ numeric conversions on Cygwin
A number of functions in libstdc++ are guarded by the _GLIBCXX_USE_C99 preprocessor macro, which is only defined on systems that pass all of the checks for a large set of C99 functions. Consequently, on systems which lack any of the required C99 facilities (e.g. Cygwin, which lacks some C99 complex math functions), the numeric conversion functions (std::stoi(), std::stol(), std::to_string(), etc.) are not defined—a rather silly outcome, as none of the numeric conversion functions are implemented using C99 math functions. This patch enables numeric conversion functions on the aforementioned systems by splitting the checks for C99 support and defining several new macros (_GLIBCXX_USE_C99_STDIO, _GLIBCXX_USE_C99_STDLIB, and _GLIBCXX_USE_C99_WCHAR), which replace the use of _GLIBCXX_USE_C99 in #if conditionals where appropriate. Tested on x86_64-pc-cygwin. Note: Several of the testcases that are newly enabled by the patch fail on Cygwin due to defects in newlib (e.g. strtof() and wcstof() do not set errno, strtold() and wcstold() do not handle trailing non-numeric characters in input strings correctly, etc.). Also, at least one testcase may fail due to PR 66530 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66530> (to circumvent, install the build tree or add the directory containing the built DLL and import library to PATH). libstdc++-v3/ChangeLog: 2015-09-18 Jennifer Yao PR libstdc++/58393 PR libstdc++/61580 * acinclude.m4 (GLIBCXX_ENABLE_C99, GLIBCXX_CHECK_C99_TR1): Use -std=c++0x instead of -std=c++98 in CXXFLAGS. Cache the results of checking for complex math and wide character functions. Define preprocessor macros _GLIBCXX_USE_C99_STDIO, _GLIBCXX_USE_C99_STDLIB, and _GLIBCXX_USE_C99_WCHAR. Reformat to improve readability. * config.h.in: Regenerate. * config/locale/dragonfly/c_locale.h (std::__convert_from_v): Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_STDIO. * config/locale/generic/c_locale.h (std::__convert_from_v): Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_STDIO. * config/locale/gnu/c_locale.h (std::__convert_from_v): Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_STDIO. * config/os/bsd/dragonfly/os_defines.h: Define _GLIBCXX_USE_C99_STDIO, _GLIBCXX_USE_C99_STDLIB, and _GLIBCXX_USE_C99_WCHAR. * configure: Regenerate. * include/bits/basic_string.h: Change and add preprocessor #if conditionals so that numeric conversion functions are defined when _GLIBCXX_USE_C99_STDIO, _GLIBCXX_USE_C99_STDLIB, or _GLIBCXX_USE_C99_WCHAR are defined, instead of _GLIBCXX_USE_C99. * include/bits/locale_facets.tcc (std::num_put::_M_insert_float): Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_STDIO. * include/bits/locale_facets_nonio.tcc (std::money_put::do_put): Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_STDIO. * include/c_compatibility/math.h: Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_MATH. * include/c_compatibility/wchar.h: Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_WCHAR. * include/c_global/cstdio: Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_STDIO. * include/c_global/cstdlib: Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_STDLIB. * include/c_global/cwchar: Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_WCHAR. * include/c_std/cstdio: Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_STDIO. * include/c_std/cstdlib: Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_STDLIB. * include/c_std/cwchar: Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_WCHAR. * include/ext/vstring.h: Change and add preprocessor #if conditionals so that numeric conversion functions are defined when _GLIBCXX_USE_C99_STDIO, _GLIBCXX_USE_C99_STDLIB, or _GLIBCXX_USE_C99_WCHAR are defined, instead of _GLIBCXX_USE_C99. * include/tr1/cstdio: Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_STDIO. * include/tr1/cstdlib: Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_STDLIB. * include/tr1/cwchar: Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_WCHAR. * include/tr1/stdlib.h: Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_STDLIB. * src/c++11/debug.cc (__gnu_debug::_Error_formatter::_M_format_word): Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_STDIO. * src/c++98/locale_facets.cc (std::__num_base::_S_format_float): Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_STDIO. * testsuite/18_support/exception_ptr/60612-terminate.cc: Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_STDLIB. * testsuite/18_support/exception_ptr/60612-unexpected.cc: Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_STDLIB. * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stod.cc (test01): Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_WCHAR. * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stof.cc (test01): Replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_WCHAR. * testsuite/21_s
Re: Fwd: [PATCH] Enable libstdc++ numeric conversions on Cygwin
> Do you already have a copyright assignment for GCC? > > If not, would you be willing to complete one? No, but I would be willing to complete one, yes. Are you willing to send me the appropriate forms, or should I contact someone else? > N.B. I don't see a patch attached to your mail, but that's not a > problem for now as I don't want to look at it until I know the status > of your copyright assignment (if we don't end up using your patch and > I do it myself then I don't want to plagiarise your work!) I included the patch in a reply to my original message to libstd...@gcc.gnu.org, but I'll attach it here as well. By the way, the changes that I made are not really that extensive; I even (unknowingly!) duplicated much of an earlier patch that was submitted on Bugzilla <https://gcc.gnu.org/bugzilla/attachment.cgi?id=33060>, although the poster apparently never got around to testing it. > THanks for doing this work, it will help several other platforms, not > only Cygwin. No problem. ^.^ On Fri, Sep 18, 2015 at 11:49 AM, Jonathan Wakely wrote: > On 18/09/15 11:17 -0400, Jennifer Yao wrote: >> >> A number of functions in libstdc++ are guarded by the _GLIBCXX_USE_C99 >> preprocessor macro, which is only defined on systems that pass all of >> the checks for a large set of C99 functions. Consequently, on systems >> which lack any of the required C99 facilities (e.g. Cygwin, which >> lacks some C99 complex math functions), the numeric conversion >> functions (std::stoi(), std::stol(), std::to_string(), etc.) are not >> defined—a rather silly outcome, as none of the numeric conversion >> functions are implemented using C99 math functions. >> >> This patch enables numeric conversion functions on the aforementioned >> systems by splitting the checks for C99 support and defining several >> new macros (_GLIBCXX_USE_C99_STDIO, _GLIBCXX_USE_C99_STDLIB, and >> _GLIBCXX_USE_C99_WCHAR), which replace the use of _GLIBCXX_USE_C99 in >> #if conditionals where appropriate. > > > Awesome! This has been on my TODO list for ages, but I've not made > much progress. I *definitely* want to see this change happen, but > there are some legal prerequisites that need to be met before that can > happen, see > https://gcc.gnu.org/onlinedocs/libstdc++/manual/appendix_contributing.html#contrib.list > > Do you already have a copyright assignment for GCC? > > If not, would you be willing to complete one? > > THanks for doing this work, it will help several other platforms, not > only Cygwin. > > > N.B. I don't see a patch attached to your mail, but that's not a > problem for now as I don't want to look at it until I know the status > of your copyright assignment (if we don't end up using your patch and > I do it myself then I don't want to plagiarise your work!) > > > libstdc++-numeric-conversions.patch Description: Binary data
Re: [PATCH] Enable libstdc++ numeric conversions on Cygwin
> On 12/11/15 13:39 +, Jonathan Wakely wrote: >> >> One downside of this change is that we introduce some (hopefully safe) >> ODR violations, where inline functions and templates that depend on >> _GLIBCXX_USE_C99_FOO might now be defined differently in C++98 and >> C++11 code. Previously they had the same definition, even though in >> C++11 mode the value of the _GLIBCXX_USE_C99_FOO macro might have been >> sub-optimal (i.e. the C99 features were usable, but the macro said >> they weren't). Those ODR violatiosn could be avoided if needed, by >> always using the _GLIBCXX98_USE_C99_FOO macro in code that can be >> included from either C++98 or C++11. We could still use the >> _GLIBCXX11_USE_C99_FOO macro in pure C++11 code (such as the numeric >> conversion functions) and get most of the benefit of this change. > > > This patch (relative to the previous one) would avoid the ODR > problems, by only using the C++98 macro in code that gets used in > C++98 and later, and using the _GLIBCXX11_XXX ones in code that is > never compiled as C++98 (specifically, the numeric conversion > functions). > > Maybe this is a safer, more conservative change. I haven't tested either of your patches yet (the testsuite runs rally slowly on Cygwin T___T), but I just wanted to express my approval of the proposed changes (more specifically, the second patch you posted). Also, I was not aware that we had to worry about C++03 compatibility. Sounds tedious.
Re: [PATCH] Enable libstdc++ numeric conversions on Cygwin
> Hi, this commit makes the GCC build to fail for targets using newlib > (I tested arm-none-eabi and aarch64-none-elf) > > I'm seeing errors such as: > In file included from > /tmp/9122162_8.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-aarch64_be-none-elf/gcc3/aarch64_be-none-elf/libstdc++-v3/include/string:52:0, > from > /tmp/9122162_8.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-aarch64_be-none-elf/gcc3/aarch64_be-none-elf/libstdc++-v3/include/bits/locale_classes.h:40, > from > /tmp/9122162_8.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-aarch64_be-none-elf/gcc3/aarch64_be-none-elf/libstdc++-v3/include/bits/ios_base.h:41, > from > /tmp/9122162_8.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-aarch64_be-none-elf/gcc3/aarch64_be-none-elf/libstdc++-v3/include/ios:42, > from > /tmp/9122162_8.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-aarch64_be-none-elf/gcc3/aarch64_be-none-elf/libstdc++-v3/include/istream:38, > from > /tmp/9122162_8.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-aarch64_be-none-elf/gcc3/aarch64_be-none-elf/libstdc++-v3/include/sstream:38, > from > /tmp/9122162_8.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-aarch64_be-none-elf/gcc3/aarch64_be-none-elf/libstdc++-v3/include/complex:45, > from > /tmp/9122162_8.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-aarch64_be-none-elf/gcc3/aarch64_be-none-elf/libstdc++-v3/include/ccomplex:38, > from > /tmp/9122162_8.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libstdc++-v3/include/precompiled/stdc++.h:52: > /tmp/9122162_8.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-aarch64_be-none-elf/gcc3/aarch64_be-none-elf/libstdc++-v3/include/bits/basic_string.h: > In function 'long long int std::__cxx11::stoll(const wstring&, > std::size_t*, int)': > /tmp/9122162_8.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-aarch64_be-none-elf/gcc3/aarch64_be-none-elf/libstdc++-v3/include/bits/basic_string.h:5524:31: > error: 'wcstoll' is not a member of 'std' >{ return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(), >^ > Sorry I can't provide more details until Monday. I just finished running the testsuite on x86_64-pc-cygwin for Jonathan's latest patch and compared the results against an older (about two months old) run, and so far I'm not seeing any regressions. Granted, this is strictly preliminary; I'm currently re-running the testsuite on the up-to-date, unpatched build tree to see if there are any differences. I'll update when I have more information.
Re: [PATCH] Enable libstdc++ numeric conversions on Cygwin
> I just finished running the testsuite on x86_64-pc-cygwin for > Jonathan's latest patch and compared the results against an older > (about two months old) run, and so far I'm not seeing any regressions. > Granted, this is strictly preliminary; I'm currently re-running the > testsuite on the up-to-date, unpatched build tree to see if there are > any differences. I'll update when I have more information. Finally finished testing the patch that was committed to trunk on Nov. 13. No regressions to report for x86_64-pc-cygwin.