]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Define <bits/functexcept.h> functions for freestanding [PR107135]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 3 Oct 2022 19:53:35 +0000 (20:53 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 4 Oct 2022 14:03:28 +0000 (15:03 +0100)
We don't compile src/c++11/functexcept.cc for freestanding, so just
define the functions used by freestanding entities as inline calls to
std::terminate.

libstdc++-v3/ChangeLog:

PR libstdc++/107135
* include/bits/functexcept.h [!_GLIBCXX_HOSTED]
(__throw_invalid_argument, __throw_out_of_range)
(__throw_out_of_range_fmt, __throw_runtime_error)
(__throw_overflow_error): Define inline.
* include/std/bitset (_M_copy_from_ptr) [!_GLIBCXX_HOSTED]:
Replace __builtin_abort with __throw_invalid_argument.

libstdc++-v3/include/bits/functexcept.h
libstdc++-v3/include/std/bitset

index a78a17b2e049588418e05ae94380c7d5f1b06a3a..7fad4b13316cbccbaa5c02b342e9cb97c647b749 100644 (file)
@@ -43,6 +43,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
+#if _GLIBCXX_HOSTED
   // Helper for exception objects in <except>
   void
   __throw_bad_exception(void) __attribute__((__noreturn__));
@@ -112,6 +113,30 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   void
   __throw_bad_function_call() __attribute__((__noreturn__));
 
+#else // ! HOSTED
+
+  __attribute__((__noreturn__)) inline void
+  __throw_invalid_argument(const char*)
+  { std::__terminate(); }
+
+  __attribute__((__noreturn__)) inline void
+  __throw_out_of_range(const char*)
+  { std::__terminate(); }
+
+  __attribute__((__noreturn__)) inline void
+  __throw_out_of_range_fmt(const char*, ...)
+  { std::__terminate(); }
+
+  __attribute__((__noreturn__)) inline void
+  __throw_runtime_error(const char*)
+  { std::__terminate(); }
+
+  __attribute__((__noreturn__)) inline void
+  __throw_overflow_error(const char*)
+  { std::__terminate(); }
+
+#endif // HOSTED
+
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
 
index afabeb4ba019e4092b06d74a73ba8426d3f60497..1f3f68fefce29fea99bf0268daf88bd9e949f5a6 100644 (file)
@@ -1514,13 +1514,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
            else if (_Traits::eq(__c, __one))
              _Unchecked_set(__i - 1);
            else
-             {
-#if _GLIBCXX_HOSTED
-               __throw_invalid_argument(__N("bitset::_M_copy_from_ptr"));
-#else
-               __builtin_abort();
-#endif
-             }
+             __throw_invalid_argument(__N("bitset::_M_copy_from_ptr"));
          }
       }