libstdc++: Make some tests work on freestanding [PR103626]

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.
This commit is contained in:
Arsen Arsenović 2022-09-30 16:53:18 +02:00 committed by Jonathan Wakely
parent 6885e7e4ee
commit 46eb286094
13 changed files with 104 additions and 64 deletions

View 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

View File

@ -20,40 +20,50 @@
#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
}

View File

@ -20,42 +20,45 @@
#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
{

View File

@ -23,42 +23,45 @@
#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
{

View File

@ -25,6 +25,8 @@ namespace gnu
using std::atexit;
using std::exit;
#if __STDC_HOSTED__
using std::getenv;
using std::system;
#endif
}

View 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 {

View 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>>;
}

View 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
}

View 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;

View 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>>();
}

View 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
}

View File

@ -18,6 +18,7 @@
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <iterator>
#include <algorithm>
#include <functional>

View 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" }