[committed] libstdc++: Use preprocessor conditions in std module [PR118177]

Message ID 20250108130212.262934-1-jwakely@redhat.com
State New
Headers
Series [committed] libstdc++: Use preprocessor conditions in std module [PR118177] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply

Commit Message

Jonathan Wakely Jan. 8, 2025, 1:01 p.m. UTC
  The std-clib.cc module definition file assumes that all names are
available unconditionally, but that's not true for all targets. Use the
same preprocessor conditions as are present in the <cxxx> headers.

A similar change is needed in std.cc.in for the <chrono> features that
depend on the SSO std::string, guarded with a __cpp_lib_chrono value
indicating full C++20 support.

The conditions for <cmath> are omitted from this change, as there are a
large number of them. That probably needs to be fixed.

libstdc++-v3/ChangeLog:

	PR libstdc++/118177
	* src/c++23/std-clib.cc.in: Use preprocessor conditions for
	names which are not always defined.
	* src/c++23/std.cc.in: Likewise.
---

Tested x86_64-linux. Pushed to trunk.

 libstdc++-v3/src/c++23/std-clib.cc.in | 46 +++++++++++++++++++++++++++
 libstdc++-v3/src/c++23/std.cc.in      |  2 ++
 2 files changed, 48 insertions(+)
  

Patch

diff --git a/libstdc++-v3/src/c++23/std-clib.cc.in b/libstdc++-v3/src/c++23/std-clib.cc.in
index 9d175b4bb4d1..6809ad229d7c 100644
--- a/libstdc++-v3/src/c++23/std-clib.cc.in
+++ b/libstdc++-v3/src/c++23/std-clib.cc.in
@@ -17,7 +17,9 @@  export C_LIB_NAMESPACE
 {
   using std::isalnum;
   using std::isalpha;
+#ifdef _GLIBCXX_USE_C99_CTYPE
   using std::isblank;
+#endif
   using std::iscntrl;
   using std::isdigit;
   using std::isgraph;
@@ -37,6 +39,7 @@  export C_LIB_NAMESPACE
 // 28.3 <cfenv>
 export C_LIB_NAMESPACE
 {
+#ifdef _GLIBCXX_USE_C99_FENV
   using std::feclearexcept;
   using std::fegetenv;
   using std::fegetexceptflag;
@@ -50,6 +53,7 @@  export C_LIB_NAMESPACE
   using std::fetestexcept;
   using std::feupdateenv;
   using std::fexcept_t;
+#endif
 }
 
 // 17.3.7 <cfloat> [cfloat.syn]
@@ -58,13 +62,17 @@  export C_LIB_NAMESPACE
 // 31.13.2 <cinttypes>
 export C_LIB_NAMESPACE
 {
+#ifdef _GLIBCXX_USE_C99_INTTYPES
   using std::imaxabs;
   using std::imaxdiv;
   using std::imaxdiv_t;
   using std::strtoimax;
   using std::strtoumax;
+#if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_C99_INTTYPES_WCHAR_T
   using std::wcstoimax;
   using std::wcstoumax;
+#endif
+#endif
 }
 
 // 17.3.6 <climits> [climits.syn]
@@ -463,7 +471,9 @@  export C_LIB_NAMESPACE
   using std::sprintf;
   using std::sscanf;
   using std::tmpfile;
+#if _GLIBCXX_USE_TMPNAM
   using std::tmpnam;
+#endif
   using std::ungetc;
   using std::vfprintf;
   using std::vfscanf;
@@ -480,8 +490,12 @@  export C_LIB_NAMESPACE
   using std::_Exit;
   using std::abort;
   using std::abs;
+#ifdef _GLIBCXX_HAVE_ALIGNED_ALLOC
   using std::aligned_alloc;
+#endif
+#ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
   using std::at_quick_exit;
+#endif
   using std::atexit;
   using std::atof;
   using std::atoi;
@@ -501,11 +515,15 @@  export C_LIB_NAMESPACE
   using std::lldiv;
   using std::lldiv_t;
   using std::malloc;
+#ifdef _GLIBCXX_HAVE_MBSTATE_T
   using std::mblen;
   using std::mbstowcs;
   using std::mbtowc;
+#endif
   using std::qsort;
+#ifdef _GLIBCXX_HAVE_QUICK_EXIT
   using std::quick_exit;
+#endif
   using std::rand;
   using std::realloc;
   using std::size_t;
@@ -518,8 +536,10 @@  export C_LIB_NAMESPACE
   using std::strtoul;
   using std::strtoull;
   using std::system;
+#ifdef _GLIBCXX_USE_WCHAR_T
   using std::wcstombs;
   using std::wctomb;
+#endif
 }
 
 // 23.5.3 <cstring>
@@ -567,20 +587,27 @@  export C_LIB_NAMESPACE
   using std::time_t;
   using std::timespec;
   using std::tm;
+#ifdef _GLIBCXX_HAVE_TIMESPEC_GET
   using std::timespec_get;
+#endif
 }
 
 // 23.5.5 <cuchar>
 export C_LIB_NAMESPACE
 {
+#if _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_CXX20
   using std::mbrtoc8;
   using std::c8rtomb;
+#endif
+#if _GLIBCXX_USE_C11_UCHAR_CXX11
   using std::mbrtoc16;
   using std::c16rtomb;
   using std::mbrtoc32;
   using std::c32rtomb;
+#endif
 }
 
+#if _GLIBCXX_USE_WCHAR_T
 // 23.5.4 <cwchar>
 export C_LIB_NAMESPACE
 {
@@ -607,11 +634,19 @@  export C_LIB_NAMESPACE
   using std::tm;
   using std::ungetwc;
   using std::vfwprintf;
+# if _GLIBCXX_HAVE_VFWSCANF
   using std::vfwscanf;
+#endif
+#ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
   using std::vswprintf;
+#endif
+# if _GLIBCXX_HAVE_VSWSCANF
   using std::vswscanf;
+#endif
   using std::vwprintf;
+# if _GLIBCXX_HAVE_VWSCANF
   using std::vwscanf;
+#endif
   using std::wcrtomb;
   using std::wcscat;
   using std::wcschr;
@@ -630,13 +665,19 @@  export C_LIB_NAMESPACE
   using std::wcsspn;
   using std::wcsstr;
   using std::wcstod;
+#if _GLIBCXX_HAVE_WCSTOF
   using std::wcstof;
+#endif
   using std::wcstok;
   using std::wcstol;
+#if _GLIBCXX_USE_C99_WCHAR
   using std::wcstold;
   using std::wcstoll;
+#endif
   using std::wcstoul;
+#if _GLIBCXX_USE_C99_WCHAR
   using std::wcstoull;
+#endif
   using std::wcsxfrm;
   using std::wctob;
   using std::wint_t;
@@ -648,13 +689,17 @@  export C_LIB_NAMESPACE
   using std::wprintf;
   using std::wscanf;
 }
+#endif
 
+#if _GLIBCXX_USE_WCHAR_T
 // 23.5.2 <cwctype>
 export C_LIB_NAMESPACE
 {
   using std::iswalnum;
   using std::iswalpha;
+#if _GLIBCXX_HAVE_ISWBLANK
   using std::iswblank;
+#endif
   using std::iswcntrl;
   using std::iswctype;
   using std::iswdigit;
@@ -674,3 +719,4 @@  export C_LIB_NAMESPACE
   using std::wctype_t;
   using std::wint_t;
 }
+#endif
diff --git a/libstdc++-v3/src/c++23/std.cc.in b/libstdc++-v3/src/c++23/std.cc.in
index 0e5b41c5b3b8..dcba343426c6 100644
--- a/libstdc++-v3/src/c++23/std.cc.in
+++ b/libstdc++-v3/src/c++23/std.cc.in
@@ -806,6 +806,7 @@  export namespace std
     using chrono::parse;
     using chrono::from_stream;
     using chrono::clock_time_conversion;
+#if __cpp_lib_chrono >= 201907L
     using chrono::tzdb;
     using chrono::tzdb_list;
     using chrono::get_tzdb;
@@ -828,6 +829,7 @@  export namespace std
     using chrono::get_leap_second_info;
     using chrono::time_zone_link;
     using chrono::local_time_format;
+#endif
     using chrono::is_clock;
     using chrono::is_clock_v;
   }