]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Make some tests work on freestanding [PR103626]
authorArsen Arsenović <arsen@aarsen.me>
Fri, 30 Sep 2022 14:53:18 +0000 (16:53 +0200)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 3 Oct 2022 14:43:49 +0000 (15:43 +0100)
PR libstdc++/103626 - _GLIBCXX_HOSTED should respect -ffreestanding

Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

PR libstdc++/103626
* testsuite/17_intro/headers/c++1998/stdc++.cc [!__STDC_HOSTED__]:
Do not include C headers that aren't valid for freestanding.
* testsuite/17_intro/tag_type_explicit_ctor.cc [!__STDC_HOSTED__]:
Do not test tag types that aren't defined for freestanding.
* testsuite/18_support/headers/cstdlib/functions_std.cc: Do not
check for std::getenv and std::system for freestanding.
* testsuite/17_intro/using_namespace_std_exp_neg.cc [!__STDC_HOSTED__]:
Do not test hosted parts of the standard library.
* testsuite/17_intro/using_namespace_std_tr1_neg.cc [!__STDC_HOSTED__]:
Likewise.
* testsuite/20_util/allocator_traits/members/rebind_alloc.cc [!__STDC_HOSTED__]:
Likewise.
* testsuite/20_util/allocator_traits/requirements/explicit_instantiation.cc [!HOSTED]:
Likewise.
* testsuite/20_util/headers/bitset/synopsis.cc [!__STDC_HOSTED__]: Likewise.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc [!__STDC_HOSTED__]:
Likewise.
* testsuite/20_util/pointer_traits/requirements/typedefs.cc [!__STDC_HOSTED__]:
Likewise.
* testsuite/20_util/tuple/cons/deduction.cc [!__STDC_HOSTED__]: Likewise.
* testsuite/25_algorithms/move/93872.cc [!__STDC_HOSTED__]: Likewise.
* testsuite/std/ranges/adaptors/100577.cc [!__STDC_HOSTED__]: Likewise.

13 files changed:
libstdc++-v3/testsuite/17_intro/headers/c++1998/stdc++.cc
libstdc++-v3/testsuite/17_intro/tag_type_explicit_ctor.cc
libstdc++-v3/testsuite/17_intro/using_namespace_std_exp_neg.cc
libstdc++-v3/testsuite/17_intro/using_namespace_std_tr1_neg.cc
libstdc++-v3/testsuite/18_support/headers/cstdlib/functions_std.cc
libstdc++-v3/testsuite/20_util/allocator_traits/members/rebind_alloc.cc
libstdc++-v3/testsuite/20_util/allocator_traits/requirements/explicit_instantiation.cc
libstdc++-v3/testsuite/20_util/headers/bitset/synopsis.cc
libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc
libstdc++-v3/testsuite/20_util/pointer_traits/requirements/typedefs.cc
libstdc++-v3/testsuite/20_util/tuple/cons/deduction.cc
libstdc++-v3/testsuite/25_algorithms/move/93872.cc
libstdc++-v3/testsuite/std/ranges/adaptors/100577.cc

index 4776c18e1ed25360d4adc1653d9a926e86498518..e362dfee32913e1d837719b38d628ed6ec9adec3 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <bits/stdc++.h>
 
+#if __STDC_HOSTED__
 // "C" compatibility headers
 #include <assert.h>
 #include <ctype.h>
@@ -47,3 +48,4 @@
 #ifdef _GLIBCXX_HAVE_WCTYPE_H
 #include <wctype.h>
 #endif
+#endif
index 262fc9a04d1b767b33b61e2919566c290913a171..410142d3974c7ba4cd828c0cc06f59a141bc6526 100644 (file)
 #include <new>
 #include <utility>
 #include <memory>
-#include <mutex>
+
+#if __STDC_HOSTED__
+#  include <mutex>
+#endif
 
 void f1(std::nothrow_t);
 void f2(std::piecewise_construct_t);
 void f3(std::allocator_arg_t);
+#if __STDC_HOSTED__
 void f4(std::defer_lock_t);
 void f5(std::try_to_lock_t);
 void f6(std::adopt_lock_t);
-
+#endif
 
 int main()
 {
   std::nothrow_t v1;
   std::piecewise_construct_t v2;
   std::allocator_arg_t v3;
+#if __STDC_HOSTED__
   std::defer_lock_t v4;
   std::try_to_lock_t v5;
   std::try_to_lock_t v6;
+#endif
   std::nothrow_t v7 = {}; // { dg-error "explicit" }
   std::piecewise_construct_t v8 = {}; // { dg-error "explicit" }
   std::allocator_arg_t v9 = {}; // { dg-error "explicit" }
-  std::defer_lock_t v10 = {}; // { dg-error "explicit" }
-  std::try_to_lock_t v11 = {}; // { dg-error "explicit" }
-  std::try_to_lock_t v12 = {}; // { dg-error "explicit" }
+#if __STDC_HOSTED__
+  std::defer_lock_t v10 = {};  // { dg-error "explicit" "" { target hosted } }
+  std::try_to_lock_t v11 = {}; // { dg-error "explicit" "" { target hosted } }
+  std::try_to_lock_t v12 = {}; // { dg-error "explicit" "" { target hosted } }
+#endif
   f1(std::nothrow_t{});
   f2(std::piecewise_construct_t{});
   f3(std::allocator_arg_t{});
-  f4(std::defer_lock_t{});
-  f5(std::try_to_lock_t{});
-  f6(std::adopt_lock_t{});
   f1({}); // { dg-error "explicit" }
   f2({}); // { dg-error "explicit" }
   f3({}); // { dg-error "explicit" }
-  f4({}); // { dg-error "explicit" }
-  f5({}); // { dg-error "explicit" }
-  f6({}); // { dg-error "explicit" }
+#if __STDC_HOSTED__
+  f4(std::defer_lock_t{});
+  f5(std::try_to_lock_t{});
+  f6(std::adopt_lock_t{});
+  f4({}); // { dg-error "explicit" "" { target hosted } }
+  f5({}); // { dg-error "explicit" "" { target hosted } }
+  f6({}); // { dg-error "explicit" "" { target hosted } }
+#endif
 }
index cdec24e9f7f445319a46111ae75c0394bb6d7b63..9fadafdbccf3c94e1c28a41ca7929cb0b50a1b09 100644 (file)
 #include <algorithm>
 #include <array>
 #include <bitset>
-#include <complex>
-#include <deque>
 #include <exception>
-#include <fstream>
 #include <functional>
-#include <iomanip>
-#include <ios>
-#include <iosfwd>
-#include <iostream>
-#include <istream>
 #include <iterator>
 #include <limits>
-#include <list>
-#include <locale>
-#include <map>
 #include <memory>
 #include <new>
 #include <numeric>
-#include <ostream>
-#include <queue>
-#include <random>
-#include <regex>
-#include <set>
-#include <sstream>
-#include <stack>
-#include <stdexcept>
-#include <streambuf>
-#include <string>
 #include <tuple>
 #include <typeinfo>
 #include <type_traits>
-#include <unordered_map>
-#include <unordered_set>
 #include <utility>
-#include <valarray>
-#include <vector>
+
+#if __STDC_HOSTED__
+#  include <complex>
+#  include <deque>
+#  include <fstream>
+#  include <iomanip>
+#  include <ios>
+#  include <iosfwd>
+#  include <iostream>
+#  include <istream>
+#  include <list>
+#  include <locale>
+#  include <map>
+#  include <ostream>
+#  include <queue>
+#  include <random>
+#  include <regex>
+#  include <set>
+#  include <sstream>
+#  include <stack>
+#  include <stdexcept>
+#  include <streambuf>
+#  include <string>
+#  include <unordered_map>
+#  include <unordered_set>
+#  include <valarray>
+#  include <vector>
+#endif
 
 namespace gnu
 {
index 31c2589da4f06f18f938c7cefa1299ac50d7e952..4d08cc5bc91d081874c7ca060e5c5f8df47c6be8 100644 (file)
 #include <algorithm>
 #include <array>
 #include <bitset>
-#include <complex>
-#include <deque>
 #include <exception>
-#include <fstream>
 #include <functional>
-#include <iomanip>
-#include <ios>
-#include <iosfwd>
-#include <iostream>
-#include <istream>
 #include <iterator>
 #include <limits>
-#include <list>
-#include <locale>
-#include <map>
 #include <memory>
 #include <new>
 #include <numeric>
-#include <ostream>
-#include <queue>
-#include <random>
-#include <regex>
-#include <set>
-#include <sstream>
-#include <stack>
-#include <stdexcept>
-#include <streambuf>
-#include <string>
 #include <tuple>
 #include <typeinfo>
 #include <type_traits>
-#include <unordered_map>
-#include <unordered_set>
 #include <utility>
-#include <valarray>
-#include <vector>
+
+#if __STDC_HOSTED__
+#  include <complex>
+#  include <deque>
+#  include <fstream>
+#  include <iomanip>
+#  include <ios>
+#  include <iosfwd>
+#  include <iostream>
+#  include <istream>
+#  include <list>
+#  include <locale>
+#  include <map>
+#  include <ostream>
+#  include <queue>
+#  include <random>
+#  include <regex>
+#  include <set>
+#  include <sstream>
+#  include <stack>
+#  include <stdexcept>
+#  include <streambuf>
+#  include <string>
+#  include <unordered_map>
+#  include <unordered_set>
+#  include <valarray>
+#  include <vector>
+#endif
 
 namespace gnu
 {
index e7738899ea06a190b5bfa7edff964fda02364aec..af1ed6a86528fe04a8dc2d0b3932ff765f4bf83b 100644 (file)
@@ -25,6 +25,8 @@ namespace gnu
   using std::atexit;
   using std::exit;
 
+#if __STDC_HOSTED__
   using std::getenv;
   using std::system;
+#endif
 }
index 32caf53c988c4540bbd1df193e6d019a32216260..ca2a8044665d3024d0e40a4eb50f81fe445d0b72 100644 (file)
@@ -24,6 +24,7 @@ using std::is_same;
 template<typename T, typename U>
   using Rebind = typename std::allocator_traits<T>::template rebind_alloc<U>;
 
+#if __STDC_HOSTED__
 template<typename T>
   struct HasRebind {
     using value_type = T;
@@ -33,6 +34,7 @@ template<typename T>
 static_assert(is_same<Rebind<HasRebind<int>, long>,
                      std::allocator<long>>::value,
              "nested alias template is used");
+#endif
 
 template<typename T>
   struct NoRebind0 {
index 42a2091cf47f62073db17f87ba7bd2aea00029e6..8f7c191e94a82a4a9ef50d3c3d8a816cb705d379 100644 (file)
@@ -36,6 +36,8 @@ template<typename T>
 
 namespace std
 {
+#if __STDC_HOSTED__
   template struct allocator_traits<std::allocator<test_type>>;
+#endif
   template struct allocator_traits<minimal_allocator<test_type>>;
 }
index ed5604b6b2291e1b14f86a0d40ba024989330f83..094f0f268b3b22bd1f52b1239beb7cb701c60d3f 100644 (file)
@@ -49,6 +49,7 @@ namespace std {
     CONSTEXPR
     bitset<N> operator^(const bitset<N>&, const bitset<N>&) NOTHROW;
 
+#if __STDC_HOSTED__
   template <class charT, class traits, size_t N>
     basic_istream<charT, traits>&
     operator>>(basic_istream<charT, traits>& is, bitset<N>& x);
@@ -56,4 +57,5 @@ namespace std {
   template <class charT, class traits, size_t N>
     basic_ostream<charT, traits>&
     operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x);
+#endif
 }
index 9eebbc400b03f146e89f7d319b7b6085b52caf7f..ff98cc42ef7b262f401a031d3eb26e98b0e8a4eb 100644 (file)
@@ -20,9 +20,9 @@
 // <http://www.gnu.org/licenses/>.
 
 #include <type_traits>
-#include <testsuite_character.h>
 
 enum test_enum { first_selection };
+struct pod_class { };
 
 void test01()
 {
@@ -31,7 +31,7 @@ void test01()
   // Negative tests.
   typedef make_unsigned<bool>::type            test1_type;
 
-  typedef make_unsigned<__gnu_test::pod_uint>::type            test2_type;
+  typedef make_unsigned<pod_class>::type       test2_type;
 
   typedef make_unsigned<int[4]>::type     test3_type;
 
index 93c8a369c25dd11d35dbb32cc497b8cd75453c7d..a88372c4d3a2e2d18d5233dda8b34003c89e9f3f 100644 (file)
@@ -37,8 +37,10 @@ int main()
 {
   test01<int*>();
   test01<void*>();
+#if __STDC_HOSTED__
   test01<std::shared_ptr<int>>();
   test01<std::shared_ptr<void>>();
+#endif
   test01<std::unique_ptr<int>>();
   test01<std::unique_ptr<void>>();
 }
index 8b9393dd334f2a7af55f5576e7f6fcc075dad793..c4b5a5c1eaf39ce84dbe722ab7b68bd5b6918cc1 100644 (file)
@@ -145,6 +145,7 @@ test04()
 void
 test05()
 {
+#if __STDC_HOSTED__
   std::allocator<double> a;
   std::tuple x{std::allocator_arg, a, 1};
   check_type<std::tuple<int>>(x);
@@ -161,4 +162,5 @@ test05()
   check_type<decltype(x)>(x5);
   std::tuple x6{std::allocator_arg, a, std::move(x)};
   check_type<decltype(x)>(x6);
+#endif
 }
index 4b0c81051719d527d4a0996c15534040a7d2318d..8496a22106362b59fd02c5e7d614007027228319 100644 (file)
@@ -18,6 +18,7 @@
 // { dg-options "-std=gnu++2a" }
 // { dg-do compile { target c++2a } }
 
+#include <iterator>
 #include <algorithm>
 #include <functional>
 
index 97401dae39c110fa646be4a8a7e75aa72e8d1a9a..c900553743b8034170a9521b2f25c3615ba9365a 100644 (file)
@@ -22,6 +22,9 @@
 
 #include <ranges>
 #include <functional>
+#if __STDC_HOSTED__
+#include <string>
+#endif
 
 namespace ranges = std::ranges;
 namespace views = std::ranges::views;
@@ -38,9 +41,11 @@ test01()
   static_assert(__adaptor_has_simple_extra_args<decltype(views::take), int>);
   static_assert(__adaptor_has_simple_extra_args<decltype(views::take_while), identity>);
   static_assert(__adaptor_has_simple_extra_args<decltype(views::drop_while), identity>);
-  static_assert(__adaptor_has_simple_extra_args<decltype(views::lazy_split), std::string_view>);
   static_assert(__adaptor_has_simple_extra_args<decltype(views::lazy_split), char>);
+#if __STDC_HOSTED__
+  static_assert(__adaptor_has_simple_extra_args<decltype(views::lazy_split), std::string_view>);
   static_assert(!__adaptor_has_simple_extra_args<decltype(views::lazy_split), std::string>);
+#endif
 
   using views::__adaptor::__closure_has_simple_call_op;
   __closure_has_simple_call_op auto a00 = views::all;
@@ -60,6 +65,7 @@ test01()
   __closure_has_simple_call_op auto b
     = (a00 | a01) | (a02 | a03) | (a04 | a05 | a06) | (a07 | a08 | a09 | a10) | a11;
 
+#if __STDC_HOSTED__
   // Verify views::lazy_split(non_view_range) is an exception.
   extern std::string s;
   auto a12 = views::lazy_split(s);
@@ -72,6 +78,7 @@ test01()
   static_assert(!__closure_has_simple_call_op<decltype(a12a)>);
   static_assert(!__closure_has_simple_call_op<decltype(a12a | a00)>);
   static_assert(!__closure_has_simple_call_op<decltype(a00 | a12a)>);
+#endif
 }
 
 void
@@ -129,6 +136,7 @@ test03()
 void
 test04()
 {
+#if __STDC_HOSTED__
   // Non-trivially-copyable extra arguments make a closure not simple.
   using F = std::function<bool(bool)>;
   static_assert(!std::is_trivially_copyable_v<F>);
@@ -137,6 +145,7 @@ test04()
   static_assert(!__closure_has_simple_call_op<decltype(views::drop_while(std::declval<F>()))>);
   static_assert(!__closure_has_simple_call_op<decltype(views::filter(std::declval<F>()))>);
   static_assert(!__closure_has_simple_call_op<decltype(views::transform(std::declval<F>()))>);
+#endif
 }
 
 // { dg-prune-output "in requirements" }