public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] libstdc++: Add preprocessor conditions for freestanding [PR106953]
@ 2022-09-16 22:36 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2022-09-16 22:36 UTC (permalink / raw)
  To: libstdc++, gcc-patches

Tested x86_64-linux, pushed to trunk.

This doesn't actually change anything for the freestanding build, so is
effectively a no-op. _GLIBCXX_HOSTED is always defined to 1 when these
headers are included. However, somebody else is working on installing the
additional headers for freestanding, so this is a prerequisite for that.

-- >8 --

This adds checks for _GLIBCXX_HOSTED to a number of headers which are
not currently installed for freestanding, but need to be for P1642R11
support. For example, <iterator> needs to be installed for C++23
freestanding mode, but without stream iterators and streambuf iterators.
Similarly, <memory> needs to be installed, but without std::allocator
and std::shared_ptr. This change disables the non-freestanding parts of
those headers.

libstdc++-v3/ChangeLog:

	PR libstdc++/106953
	* include/backward/auto_ptr.h [!_GLIBCXX_HOSTED]: Do not define
	shared_ptr members.
	* include/bits/alloc_traits.h [!_GLIBCXX_HOSTED]: Do not declare
	std::allocator_traits<std::allocator<T>> specializations for
	freestanding.
	* include/bits/memoryfwd.h [!_GLIBCXX_HOSTED] (allocator): Do
	not declare for freestanding.
	* include/bits/stl_algo.h [!_GLIBCXX_HOSTED] (stable_partition):
	Do not define for freestanding.
	[!_GLIBCXX_HOSTED] (merge, stable_sort): Do not use temporary
	buffers for freestanding.
	* include/bits/stl_algobase.h [!_GLIBCXX_HOSTED]: Do not declare
	streambuf iterators and overloaded algorithms using them.
	* include/bits/stl_uninitialized.h [!_GLIBCXX_HOSTED]: Do not
	define specialized overloads for std::allocator.
	* include/bits/unique_ptr.h [!_GLIBCXX_HOSTED] (make_unique)
	(make_unique_for_overwrite, operator<<): Do not define for
	freestanding.
	* include/c_global/cstdlib [!_GLIBCXX_HOSTED] (_Exit): Declare.
	Use _GLIBCXX_NOTHROW instead of throw().
	* include/debug/assertions.h [!_GLIBCXX_HOSTED]: Ignore
	_GLIBCXX_DEBUG for freestanding.
	* include/debug/debug.h [!_GLIBCXX_DEBUG]: Likewise.
	* include/std/bit [!_GLIBCXX_HOSTED]: Do not use the custom
	__int_traits if <ext/numeric_traits.h> is available.
	* include/std/functional [!_GLIBCXX_HOSTED]: Do not include
	headers that aren't valid for freestanding.
	(boyer_moore_searcher, boyer_moore_horspool_searcher): Do not
	define for freestanding.
	* include/std/iterator [!_GLIBCXX_HOSTED]: Do not include
	headers that aren't valid for freestanding.
	* include/std/memory [!_GLIBCXX_HOSTED]: Likewise.
	* include/std/ranges [!_GLIBCXX_HOSTED] (istream_view): Do not
	define for freestanding.
	(views::__detail::__is_basic_string_view) [!_GLIBCXX_HOSTED]:
	Do not define partial specialization for freestanding.
---
 libstdc++-v3/include/backward/auto_ptr.h      |  4 ++-
 libstdc++-v3/include/bits/alloc_traits.h      | 13 +++++++++-
 libstdc++-v3/include/bits/memoryfwd.h         |  2 ++
 libstdc++-v3/include/bits/stl_algo.h          | 25 ++++++++++++++-----
 libstdc++-v3/include/bits/stl_algobase.h      |  4 +++
 libstdc++-v3/include/bits/stl_uninitialized.h | 17 ++++++++++---
 libstdc++-v3/include/bits/unique_ptr.h        | 14 ++++++-----
 libstdc++-v3/include/c_global/cstdlib         | 24 ++++++++++--------
 libstdc++-v3/include/debug/assertions.h       | 16 ++++++------
 libstdc++-v3/include/debug/debug.h            |  2 +-
 libstdc++-v3/include/std/bit                  |  2 +-
 libstdc++-v3/include/std/functional           | 22 ++++++++++------
 libstdc++-v3/include/std/iterator             |  6 +++--
 libstdc++-v3/include/std/memory               | 11 +++++---
 libstdc++-v3/include/std/ranges               |  4 +++
 15 files changed, 114 insertions(+), 52 deletions(-)

diff --git a/libstdc++-v3/include/backward/auto_ptr.h b/libstdc++-v3/include/backward/auto_ptr.h
index 184ab403466..093db5260fc 100644
--- a/libstdc++-v3/include/backward/auto_ptr.h
+++ b/libstdc++-v3/include/backward/auto_ptr.h
@@ -300,6 +300,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     } _GLIBCXX11_DEPRECATED;
 
 #if __cplusplus >= 201103L
+#if _GLIBCXX_HOSTED
   template<_Lock_policy _Lp>
   template<typename _Tp>
     inline
@@ -325,13 +326,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     inline
     shared_ptr<_Tp>::shared_ptr(std::auto_ptr<_Tp1>&& __r)
     : __shared_ptr<_Tp>(std::move(__r)) { }
+#endif // HOSTED
 
   template<typename _Tp, typename _Dp>
   template<typename _Up, typename>
     inline
     unique_ptr<_Tp, _Dp>::unique_ptr(auto_ptr<_Up>&& __u) noexcept
     : _M_t(__u.release(), deleter_type()) { }
-#endif
+#endif // C++11
 
 #pragma GCC diagnostic pop
 
diff --git a/libstdc++-v3/include/bits/alloc_traits.h b/libstdc++-v3/include/bits/alloc_traits.h
index 35bdf6ecf98..507e8f1b6b2 100644
--- a/libstdc++-v3/include/bits/alloc_traits.h
+++ b/libstdc++-v3/include/bits/alloc_traits.h
@@ -33,9 +33,11 @@
 #include <bits/stl_construct.h>
 #include <bits/memoryfwd.h>
 #if __cplusplus >= 201103L
-# include <bits/allocator.h>
 # include <bits/ptr_traits.h>
 # include <ext/numeric_traits.h>
+# if _GLIBCXX_HOSTED
+#  include <bits/allocator.h>
+# endif
 #endif
 
 namespace std _GLIBCXX_VISIBILITY(default)
@@ -402,6 +404,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       { return _S_select(__rhs, 0); }
     };
 
+#if _GLIBCXX_HOSTED
+
 #if __cplusplus > 201703L
 # define __cpp_lib_constexpr_dynamic_alloc 201907L
 #endif
@@ -660,6 +664,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       select_on_container_copy_construction(const allocator_type& __rhs)
       { return __rhs; }
     };
+#endif
 
   /// @cond undocumented
 #if __cplusplus < 201703L
@@ -774,11 +779,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 				 typename _Alloc::value_type const&>::type
     { };
 
+#if _GLIBCXX_HOSTED
   // std::allocator<_Tp> just requires CopyConstructible
   template<typename _Tp>
     struct __is_copy_insertable<allocator<_Tp>>
     : is_copy_constructible<_Tp>
     { };
+#endif
 
   // true if _Alloc::value_type is MoveInsertable into containers using _Alloc
   // (might be wrong if _Alloc::construct exists but is not constrained,
@@ -788,11 +795,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     : __is_alloc_insertable_impl<_Alloc, typename _Alloc::value_type>::type
     { };
 
+#if _GLIBCXX_HOSTED
   // std::allocator<_Tp> just requires MoveConstructible
   template<typename _Tp>
     struct __is_move_insertable<allocator<_Tp>>
     : is_move_constructible<_Tp>
     { };
+#endif
 
   // Trait to detect Allocator-like types.
   template<typename _Alloc, typename = void>
@@ -893,6 +902,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
     }
 
+#if _GLIBCXX_HOSTED
   template<typename _ForwardIterator, typename _Tp>
     _GLIBCXX20_CONSTEXPR
     inline void
@@ -901,6 +911,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     {
       _Destroy(__first, __last);
     }
+#endif
   /// @endcond
 
 _GLIBCXX_END_NAMESPACE_VERSION
diff --git a/libstdc++-v3/include/bits/memoryfwd.h b/libstdc++-v3/include/bits/memoryfwd.h
index 751329c0c22..ae164fa7b5a 100644
--- a/libstdc++-v3/include/bits/memoryfwd.h
+++ b/libstdc++-v3/include/bits/memoryfwd.h
@@ -60,11 +60,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    * @{
    */
 
+#if _GLIBCXX_HOSTED
   template<typename>
     class allocator;
 
   template<>
     class allocator<void>;
+#endif
 
 #if __cplusplus >= 201103L
   /// Declare uses_allocator so it can be specialized in `<queue>` etc.
diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h
index 9cb708ab2fd..e63fe66852e 100644
--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -59,15 +59,17 @@
 #include <bits/algorithmfwd.h>
 #include <bits/stl_algobase.h>
 #include <bits/stl_heap.h>
-#include <bits/stl_tempbuf.h>  // for _Temporary_buffer
 #include <bits/predefined_ops.h>
 
 #if __cplusplus >= 201103L
 #include <bits/uniform_int_dist.h>
 #endif
 
-#if _GLIBCXX_HOSTED && (__cplusplus <= 201103L || _GLIBCXX_USE_DEPRECATED)
-#include <cstdlib>	     // for rand
+#if _GLIBCXX_HOSTED
+# include <bits/stl_tempbuf.h>  // for _Temporary_buffer
+# if (__cplusplus <= 201103L || _GLIBCXX_USE_DEPRECATED)
+#  include <cstdlib>	     // for rand
+# endif
 #endif
 
 // See concept_check.h for the __glibcxx_*_requires macros.
@@ -1492,6 +1494,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
 	}
     }
 
+#if _GLIBCXX_HOSTED
   // partition
 
   /// This is a helper function...
@@ -1617,6 +1620,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
       return std::__stable_partition(__first, __last,
 				     __gnu_cxx::__ops::__pred_iter(__pred));
     }
+#endif // HOSTED
 
   /// @cond undocumented
 
@@ -2527,7 +2531,6 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
 	  _ValueType;
       typedef typename iterator_traits<_BidirectionalIterator>::difference_type
 	  _DistanceType;
-      typedef _Temporary_buffer<_BidirectionalIterator, _ValueType> _TmpBuf;
 
       if (__first == __middle || __middle == __last)
 	return;
@@ -2535,6 +2538,8 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
       const _DistanceType __len1 = std::distance(__first, __middle);
       const _DistanceType __len2 = std::distance(__middle, __last);
 
+#if _GLIBCXX_HOSTED
+      typedef _Temporary_buffer<_BidirectionalIterator, _ValueType> _TmpBuf;
       // __merge_adaptive will use a buffer for the smaller of
       // [first,middle) and [middle,last).
       _TmpBuf __buf(__first, std::min(__len1, __len2));
@@ -2549,6 +2554,10 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
 	std::__merge_adaptive_resize
 	  (__first, __middle, __last, __len1, __len2, __buf.begin(),
 	   _DistanceType(__buf.size()), __comp);
+#else
+      std::__merge_without_buffer
+	(__first, __middle, __last, __len1, __len2, __comp);
+#endif
     }
 
   /**
@@ -4585,7 +4594,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
 	      std::iter_swap(__i, __j);
 	  }
     }
-#endif
+#endif // HOSTED
 
   /**
    *  @brief Shuffle the elements of a sequence using a random number
@@ -5017,11 +5026,12 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
 	_ValueType;
       typedef typename iterator_traits<_RandomAccessIterator>::difference_type
 	_DistanceType;
-      typedef _Temporary_buffer<_RandomAccessIterator, _ValueType> _TmpBuf;
 
       if (__first == __last)
 	return;
 
+#if _GLIBCXX_HOSTED
+      typedef _Temporary_buffer<_RandomAccessIterator, _ValueType> _TmpBuf;
       // __stable_sort_adaptive sorts the range in two halves,
       // so the buffer only needs to fit half the range at once.
       _TmpBuf __buf(__first, (__last - __first + 1) / 2);
@@ -5035,6 +5045,9 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
       else
 	std::__stable_sort_adaptive_resize(__first, __last, __buf.begin(),
 					   _DistanceType(__buf.size()), __comp);
+#else
+      std::__inplace_stable_sort(__first, __last, __comp);
+#endif
     }
 
   /**
diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h
index 84a1f9e98f6..ae898ed3706 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -442,6 +442,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 
 _GLIBCXX_END_NAMESPACE_CONTAINER
 
+#if _GLIBCXX_HOSTED
   // Helpers for streambuf iterators (either istream or ostream).
   // NB: avoid including <iosfwd>, relatively large.
   template<typename _CharT>
@@ -479,6 +480,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
 	istreambuf_iterator<_CharT, char_traits<_CharT> >,
 	istreambuf_iterator<_CharT, char_traits<_CharT> >,
 	_GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>);
+#endif // HOSTED
 
   template<bool _IsMove, typename _II, typename _OI>
     _GLIBCXX20_CONSTEXPR
@@ -574,6 +576,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
       return __result;
     }
 
+#if _GLIBCXX_HOSTED
   template<typename _CharT, typename _Size>
     typename __gnu_cxx::__enable_if<
       __is_char<_CharT>::__value, _CharT*>::__type
@@ -587,6 +590,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
     __copy_n_a(istreambuf_iterator<_CharT, char_traits<_CharT> >, _Size,
 	       _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>,
 	       bool);
+#endif
 
   /**
    *  @brief Copies the range [first,last) into result.
diff --git a/libstdc++-v3/include/bits/stl_uninitialized.h b/libstdc++-v3/include/bits/stl_uninitialized.h
index 7ed69f53f7d..0b32074e5e9 100644
--- a/libstdc++-v3/include/bits/stl_uninitialized.h
+++ b/libstdc++-v3/include/bits/stl_uninitialized.h
@@ -359,6 +359,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	}
     }
 
+#if _GLIBCXX_HOSTED
   template<typename _InputIterator, typename _ForwardIterator, typename _Tp>
     _GLIBCXX20_CONSTEXPR
     inline _ForwardIterator
@@ -371,6 +372,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
       return std::uninitialized_copy(__first, __last, __result);
     }
+#endif
 
   template<typename _InputIterator, typename _ForwardIterator,
 	   typename _Allocator>
@@ -418,6 +420,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	}
     }
 
+#if _GLIBCXX_HOSTED
   template<typename _ForwardIterator, typename _Tp, typename _Tp2>
     _GLIBCXX20_CONSTEXPR
     inline void
@@ -430,6 +433,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
       std::uninitialized_fill(__first, __last, __x);
     }
+#endif
 
   template<typename _ForwardIterator, typename _Size, typename _Tp,
 	   typename _Allocator>
@@ -453,6 +457,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	}
     }
 
+#if _GLIBCXX_HOSTED
   template<typename _ForwardIterator, typename _Size, typename _Tp,
 	   typename _Tp2>
     _GLIBCXX20_CONSTEXPR
@@ -466,7 +471,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
       return std::uninitialized_fill_n(__first, __n, __x);
     }
-
+#endif
 
   // Extensions: __uninitialized_copy_move, __uninitialized_move_copy,
   // __uninitialized_fill_move, __uninitialized_move_fill.
@@ -725,13 +730,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	}
     }
 
+#if _GLIBCXX_HOSTED
   template<typename _ForwardIterator, typename _Tp>
     inline void
     __uninitialized_default_a(_ForwardIterator __first,
 			      _ForwardIterator __last,
 			      allocator<_Tp>&)
     { std::__uninitialized_default(__first, __last); }
-
+#endif
 
   // __uninitialized_default_n_a
   // Fills [first, first + n) with value_types constructed by the allocator
@@ -756,6 +762,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	}
     }
 
+#if _GLIBCXX_HOSTED
   // __uninitialized_default_n_a specialization for std::allocator,
   // which ignores the allocator and value-initializes the elements.
   template<typename _ForwardIterator, typename _Size, typename _Tp>
@@ -764,6 +771,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
 				allocator<_Tp>&)
     { return std::__uninitialized_default_n(__first, __n); }
+#endif
 
   template<bool _TrivialValueType>
     struct __uninitialized_default_novalue_1
@@ -1094,6 +1102,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       return __cur;
     }
 
+#if _GLIBCXX_HOSTED
   template <typename _Tp, typename _Up>
     _GLIBCXX20_CONSTEXPR
     inline __enable_if_t<std::__is_bitwise_relocatable<_Tp>::value, _Tp*>
@@ -1118,7 +1127,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	}
       return __result + __count;
     }
-
+#endif
 
   template <typename _InputIterator, typename _ForwardIterator,
 	    typename _Allocator>
@@ -1136,7 +1145,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     }
 
   /// @endcond
-#endif
+#endif // C++11
 
   /// @} group memory
 
diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h
index e1ad7721a59..1086f408374 100644
--- a/libstdc++-v3/include/bits/unique_ptr.h
+++ b/libstdc++-v3/include/bits/unique_ptr.h
@@ -36,9 +36,11 @@
 #include <tuple>
 #include <bits/stl_function.h>
 #include <bits/functional_hash.h>
-#if __cplusplus > 201703L
+#if __cplusplus >= 202002L
 # include <compare>
-# include <ostream>
+# if _GLIBCXX_HOSTED
+#  include <ostream>
+# endif
 #endif
 
 #if __cplusplus > 202002L && __cpp_constexpr_dynamic_alloc
@@ -1031,7 +1033,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       public __uniq_ptr_hash<unique_ptr<_Tp, _Dp>>
     { };
 
-#if __cplusplus >= 201402L
+#if __cplusplus >= 201402L && _GLIBCXX_HOSTED
 #define __cpp_lib_make_unique 201304L
 
   /// @cond undocumented
@@ -1131,9 +1133,9 @@ namespace __detail
     make_unique_for_overwrite(_Args&&...) = delete;
 #endif // C++20
 
-#endif // C++14
+#endif // C++14 && HOSTED
 
-#if __cplusplus > 201703L && __cpp_concepts
+#if __cplusplus > 201703L && __cpp_concepts && _GLIBCXX_HOSTED
   // _GLIBCXX_RESOLVE_LIB_DEFECTS
   // 2948. unique_ptr does not define operator<< for stream output
   /// Stream output operator for unique_ptr
@@ -1148,7 +1150,7 @@ namespace __detail
       __os << __p.get();
       return __os;
     }
-#endif // C++20
+#endif // C++20 && HOSTED
 
   /// @} group pointer_abstractions
 
diff --git a/libstdc++-v3/include/c_global/cstdlib b/libstdc++-v3/include/c_global/cstdlib
index 8a832aff0f9..0f7362e263f 100644
--- a/libstdc++-v3/include/c_global/cstdlib
+++ b/libstdc++-v3/include/c_global/cstdlib
@@ -51,19 +51,23 @@
 
 #define EXIT_SUCCESS 0
 #define EXIT_FAILURE 1
+#define NULL __null
 
 namespace std
 {
-  extern "C" void abort(void) throw () _GLIBCXX_NORETURN;
-  extern "C" int atexit(void (*)(void)) throw ();
-  extern "C" void exit(int) throw () _GLIBCXX_NORETURN;
+  extern "C" void abort(void) _GLIBCXX_NOTHROW _GLIBCXX_NORETURN;
+  extern "C" int atexit(void (*)(void)) _GLIBCXX_NOTHROW;
+  extern "C" void exit(int) _GLIBCXX_NOTHROW _GLIBCXX_NORETURN;
 #if __cplusplus >= 201103L
 # ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
-  extern "C" int at_quick_exit(void (*)(void)) throw ();
+  extern "C" int at_quick_exit(void (*)(void)) _GLIBCXX_NOTHROW;
 # endif
 # ifdef _GLIBCXX_HAVE_QUICK_EXIT
-  extern "C" void quick_exit(int) throw() _GLIBCXX_NORETURN;
+  extern "C" void quick_exit(int) _GLIBCXX_NOTHROW_GLIBCXX_NORETURN;
 # endif
+#if _GLIBCXX_USE_C99_STDLIB
+  extern "C" void _Exit(int) _GLIBCXX_NOTHROW _GLIBCXX_NORETURN;
+#endif
 #endif
 } // namespace std
 
@@ -174,7 +178,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #ifndef __CORRECT_ISO_CPP_STDLIB_H_PROTO
   inline ldiv_t
-  div(long __i, long __j) { return ldiv(__i, __j); }
+  div(long __i, long __j) _GLIBCXX_NOTHROW { return ldiv(__i, __j); }
 #endif
 
 
@@ -200,7 +204,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   using ::lldiv_t;
 #endif
 #if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
-  extern "C" void (_Exit)(int) throw () _GLIBCXX_NORETURN;
+  extern "C" void (_Exit)(int) _GLIBCXX_NOTHROW _GLIBCXX_NORETURN;
 #endif
 #if !_GLIBCXX_USE_C99_DYNAMIC
   using ::_Exit;
@@ -217,11 +221,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 
 #if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
-  extern "C" long long int (atoll)(const char *) throw ();
+  extern "C" long long int (atoll)(const char *) _GLIBCXX_NOTHROW;
   extern "C" long long int
-    (strtoll)(const char * __restrict, char ** __restrict, int) throw ();
+    (strtoll)(const char * __restrict, char ** __restrict, int) _GLIBCXX_NOTHROW;
   extern "C" unsigned long long int
-    (strtoull)(const char * __restrict, char ** __restrict, int) throw ();
+    (strtoull)(const char * __restrict, char ** __restrict, int) _GLIBCXX_NOTHROW;
 #endif
 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
   using ::atoll;
diff --git a/libstdc++-v3/include/debug/assertions.h b/libstdc++-v3/include/debug/assertions.h
index 57c0ab2c3cf..c3b5ad01d4f 100644
--- a/libstdc++-v3/include/debug/assertions.h
+++ b/libstdc++-v3/include/debug/assertions.h
@@ -31,14 +31,6 @@
 
 #include <bits/c++config.h>
 
-#ifndef _GLIBCXX_DEBUG
-
-# define _GLIBCXX_DEBUG_ASSERT(_Condition)
-# define _GLIBCXX_DEBUG_PEDASSERT(_Condition)
-# define _GLIBCXX_DEBUG_ONLY(_Statement)
-
-#endif
-
 #ifndef _GLIBCXX_ASSERTIONS
 # define __glibcxx_requires_non_empty_range(_First,_Last)
 # define __glibcxx_requires_nonempty()
@@ -55,7 +47,8 @@
   __glibcxx_assert(!this->empty())
 #endif
 
-#ifdef _GLIBCXX_DEBUG
+#if defined _GLIBCXX_DEBUG && _GLIBCXX_HOSTED
+
 # define _GLIBCXX_DEBUG_ASSERT(_Condition) __glibcxx_assert(_Condition)
 
 # ifdef _GLIBCXX_DEBUG_PEDANTIC
@@ -65,6 +58,11 @@
 # endif
 
 # define _GLIBCXX_DEBUG_ONLY(_Statement) _Statement
+
+#else
+# define _GLIBCXX_DEBUG_ASSERT(_Condition)
+# define _GLIBCXX_DEBUG_PEDASSERT(_Condition)
+# define _GLIBCXX_DEBUG_ONLY(_Statement)
 #endif
 
 #endif // _GLIBCXX_DEBUG_ASSERTIONS
diff --git a/libstdc++-v3/include/debug/debug.h b/libstdc++-v3/include/debug/debug.h
index f4233760426..78546d76123 100644
--- a/libstdc++-v3/include/debug/debug.h
+++ b/libstdc++-v3/include/debug/debug.h
@@ -61,7 +61,7 @@ namespace __gnu_debug
     struct _Safe_iterator;
 }
 
-#ifndef _GLIBCXX_DEBUG
+#if ! defined _GLIBCXX_DEBUG || ! _GLIBCXX_HOSTED
 
 # define __glibcxx_requires_cond(_Cond,_Msg)
 # define __glibcxx_requires_valid_range(_First,_Last)
diff --git a/libstdc++-v3/include/std/bit b/libstdc++-v3/include/std/bit
index ef19d649e32..2fd80187210 100644
--- a/libstdc++-v3/include/std/bit
+++ b/libstdc++-v3/include/std/bit
@@ -35,7 +35,7 @@
 
 #include <type_traits>
 
-#if _GLIBCXX_HOSTED
+#if _GLIBCXX_HOSTED || __has_include(<ext/numeric_traits.h>)
 # include <ext/numeric_traits.h>
 #else
 # include <limits>
diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional
index 685a3e167ee..c4f75880fd8 100644
--- a/libstdc++-v3/include/std/functional
+++ b/libstdc++-v3/include/std/functional
@@ -56,18 +56,22 @@
 #include <bits/functional_hash.h>
 #include <bits/invoke.h>
 #include <bits/refwrap.h>	// std::reference_wrapper and _Mem_fn_traits
-#include <bits/std_function.h>	// std::function
-#if __cplusplus > 201402L
-# include <unordered_map>
-# include <vector>
-# include <array>
-# include <bits/stl_algo.h>
+#if _GLIBCXX_HOSTED
+# include <bits/std_function.h>	// std::function
+#endif
+#if __cplusplus >= 201703L
+# if _GLIBCXX_HOSTED
+#  include <unordered_map>
+#  include <vector>
+#  include <array>
+# endif
+# include <bits/stl_algo.h> // std::search
 #endif
 #if __cplusplus > 201703L
 # include <bits/ranges_cmp.h>
 # include <compare>
 #endif
-#if __cplusplus > 202002L
+#if __cplusplus > 202002L && _GLIBCXX_HOSTED
 # include <bits/move_only_function.h>
 #endif
 
@@ -238,7 +242,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /**
    * @brief Trait that identifies a bind expression.
-   * 
+   *
    * Determines if the given type `_Tp` is a function object that
    * should be treated as a subexpression when evaluating calls to
    * function objects returned by `std::bind`.
@@ -1117,6 +1121,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       tuple<_ForwardIterator1, _ForwardIterator1, _BinaryPredicate> _M_m;
     };
 
+#if _GLIBCXX_HOSTED
   template<typename _Key, typename _Tp, typename _Hash, typename _Pred>
     struct __boyer_moore_map_base
     {
@@ -1359,6 +1364,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	}
       return std::make_pair(__last, __last);
     }
+#endif // HOSTED
 
 #endif // C++17
 #endif // C++14
diff --git a/libstdc++-v3/include/std/iterator b/libstdc++-v3/include/std/iterator
index 2da2fb6e4a3..fb2a47c0dbb 100644
--- a/libstdc++-v3/include/std/iterator
+++ b/libstdc++-v3/include/std/iterator
@@ -61,8 +61,10 @@
 #include <bits/stl_iterator_base_types.h>
 #include <bits/stl_iterator_base_funcs.h>
 #include <bits/stl_iterator.h>
-#include <bits/stream_iterator.h>
-#include <bits/streambuf_iterator.h>
+#if _GLIBCXX_HOSTED
+# include <bits/stream_iterator.h>
+# include <bits/streambuf_iterator.h>
+#endif
 #include <bits/range_access.h>
 
 #if __cplusplus >= 201402L && ! defined _GLIBCXX_DEBUG // PR libstdc++/70303
diff --git a/libstdc++-v3/include/std/memory b/libstdc++-v3/include/std/memory
index 20a55020a36..3eff12108f1 100644
--- a/libstdc++-v3/include/std/memory
+++ b/libstdc++-v3/include/std/memory
@@ -60,7 +60,10 @@
  * Smart pointers, etc.
  */
 
-#include <bits/allocator.h>
+#include <bits/memoryfwd.h>
+#if _GLIBCXX_HOSTED
+# include <bits/allocator.h>
+#endif
 #include <bits/stl_construct.h>
 #include <bits/stl_uninitialized.h>
 #include <bits/stl_tempbuf.h>
@@ -73,8 +76,10 @@
 #  include <bits/alloc_traits.h>
 #  include <debug/debug.h>
 #  include <bits/unique_ptr.h>
+# if _GLIBCXX_HOSTED
 #  include <bits/shared_ptr.h>
 #  include <bits/shared_ptr_atomic.h>
+# endif
 #endif
 
 #if __cplusplus < 201103L || _GLIBCXX_USE_DEPRECATED
@@ -86,7 +91,7 @@
 #  include <bits/uses_allocator_args.h>
 #endif
 
-#if __cplusplus >= 201103L && __cplusplus <= 202002L
+#if __cplusplus >= 201103L && __cplusplus <= 202002L && _GLIBCXX_HOSTED
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -133,7 +138,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
 #endif // C++11 to C++20
 
-#if __cplusplus >= 201703L
+#if __cplusplus >= 201703L && _GLIBCXX_HOSTED
 // Parallel STL algorithms
 # if _PSTL_EXECUTION_POLICIES_DEFINED
 // If <execution> has already been included, pull in implementations
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 53093a3762f..c2eacdebe28 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -701,6 +701,7 @@ namespace views
   inline constexpr _Iota iota{};
 } // namespace views
 
+#if _GLIBCXX_HOSTED
   namespace __detail
   {
     template<typename _Val, typename _CharT, typename _Traits>
@@ -804,6 +805,7 @@ namespace views
   template<typename _Tp>
     inline constexpr _Istream<_Tp> istream;
 }
+#endif // HOSTED
 
   // C++20 24.7 [range.adaptors] Range adaptors
 
@@ -2234,9 +2236,11 @@ namespace views::__adaptor
       template<typename _Range>
 	inline constexpr bool __is_basic_string_view = false;
 
+#if _GLIBCXX_HOSTED
       template<typename _CharT, typename _Traits>
 	inline constexpr bool __is_basic_string_view<basic_string_view<_CharT, _Traits>>
 	  = true;
+#endif
 
       template<typename _Range>
 	inline constexpr bool __is_subrange = false;
-- 
2.37.3


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-09-16 22:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-16 22:36 [committed] libstdc++: Add preprocessor conditions for freestanding [PR106953] Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).