From: "Arsen Arsenović" <arsen@aarsen.me>
To: libstdc++@gcc.gnu.org
Cc: gcc-patches@gcc.gnu.org, "Arsen Arsenović" <arsen@aarsen.me>
Subject: [PATCH 1/2] libstdc++: Enable string_view in freestanding
Date: Tue, 10 Jan 2023 11:03:04 +0100 [thread overview]
Message-ID: <20230110100305.1420589-1-arsen@aarsen.me> (raw)
This enables the default contract handler in freestanding environments,
and, of course, provides freestanding users with string_view.
libstdc++-v3/ChangeLog:
* include/Makefile.am: Install bits/char_traits.h,
std/string_view
* include/Makefile.in: Regenerate.
* include/bits/char_traits.h: Gate hosted-only, wchar-only and
mbstate-only bits behind appropriate #ifs.
* include/std/string_view: Gate <iostream> functionality behind
HOSTED.
* include/std/version: Enable __cpp_lib_constexpr_string_view
and __cpp_lib_starts_ends_with in !HOSTED.
* include/std/ranges: Re-enable __is_basic_string_view on
freestanding, include <string_view> directly.
* include/precompiled/stdc++.h: Include <string_view> when
!HOSTED too.
* testsuite/20_util/function_objects/searchers.cc: Skip testing
boyer_moore searchers on freestanding
* testsuite/21_strings/basic_string_view/capacity/1.cc: Guard
<string>-related tests behind __STDC_HOSTED__.
* testsuite/21_strings/basic_string_view/cons/char/1.cc: Ditto.
* testsuite/21_strings/basic_string_view/cons/char/2.cc: Remove
unused <stdexcept> include.
* testsuite/21_strings/basic_string_view/cons/char/3.cc: Remove
unused <vector> include.
* testsuite/21_strings/basic_string_view/cons/char/range.cc:
Guard <string> related testing behind __STDC_HOSTED__.
* testsuite/21_strings/basic_string_view/cons/wchar_t/1.cc:
Guard <stdexcept> related tests behind __STDC_HOSTED__.
* testsuite/21_strings/basic_string_view/element_access/char/1.cc:
Ditto.
* testsuite/21_strings/basic_string_view/element_access/wchar_t/1.cc:
Guard <stdexcept> tests behind __STDC_HOSTED__.
* testsuite/21_strings/basic_string_view/operations/contains/char/2.cc:
Enable test on freestanding, guard <stdexcept> bits behind
__STDC_HOSTED__.
* testsuite/21_strings/basic_string_view/operations/substr/char.cc:
Guard <stdexcept> bits behind __STDC_HOSTED__.
* testsuite/21_strings/basic_string_view/operations/substr/wchar_t.cc:
Ditto.
---
Morning (so much for submitting it last night eh? :D),
This patchset enables the use of std::string_view in freestanding
environments. This permits freestanding programs to use contracts, and
fixes building libstdc++.* on freestanding with one of the patches I
sent previously.
I also included fixes for some new test failures on unix/-ffreestanding.
I hope to get some time to set up a dedicated runner for re-spinning
-ffreestanding libstdc++ every so often in the near future..
I haven't built Managarm with frg::string_view made into an alias for
std::string_view yet, I can also do that before the merge, if so
desired, as a little use-case test, but that might take a few days.
Before NYE, I tested a full x86_64-pc-linux-gnu bootstrap, but I haven't
had a chance to do that today after a rebase, though I did verify that
--target_board='unix/{,-ffreestanding}' passes fine. I can do that
tonight and update this thread if need be.
Thanks in advance, have a great day.
libstdc++-v3/include/Makefile.am | 6 +--
libstdc++-v3/include/Makefile.in | 6 +--
libstdc++-v3/include/bits/char_traits.h | 50 ++++++++++++++++---
libstdc++-v3/include/precompiled/stdc++.h | 3 +-
libstdc++-v3/include/std/ranges | 3 +-
libstdc++-v3/include/std/string_view | 19 +++++--
libstdc++-v3/include/std/version | 4 +-
.../20_util/function_objects/searchers.cc | 27 ++++++++--
.../basic_string_view/capacity/1.cc | 2 +
.../basic_string_view/cons/char/1.cc | 7 ++-
.../basic_string_view/cons/char/2.cc | 1 -
.../basic_string_view/cons/char/3.cc | 1 -
.../basic_string_view/cons/char/range.cc | 7 ++-
.../basic_string_view/cons/wchar_t/1.cc | 6 ++-
.../element_access/char/1.cc | 7 ++-
.../element_access/wchar_t/1.cc | 6 ++-
.../operations/contains/char/2.cc | 1 -
.../operations/substr/char.cc | 7 ++-
.../operations/substr/wchar_t.cc | 7 ++-
19 files changed, 133 insertions(+), 37 deletions(-)
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index e91f4ddd4de..bf566082a8c 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -46,6 +46,7 @@ std_freestanding = \
${std_srcdir}/scoped_allocator \
${std_srcdir}/source_location \
${std_srcdir}/span \
+ ${std_srcdir}/string_view \
${std_srcdir}/tuple \
${std_srcdir}/type_traits \
${std_srcdir}/typeindex \
@@ -100,7 +101,6 @@ std_headers = \
${std_srcdir}/stop_token \
${std_srcdir}/streambuf \
${std_srcdir}/string \
- ${std_srcdir}/string_view \
${std_srcdir}/system_error \
${std_srcdir}/thread \
${std_srcdir}/unordered_map \
@@ -120,6 +120,7 @@ bits_freestanding = \
${bits_srcdir}/c++0x_warning.h \
${bits_srcdir}/boost_concept_check.h \
${bits_srcdir}/concept_check.h \
+ ${bits_srcdir}/char_traits.h \
${bits_srcdir}/cpp_type_traits.h \
${bits_srcdir}/enable_special_members.h \
${bits_srcdir}/functexcept.h \
@@ -153,6 +154,7 @@ bits_freestanding = \
${bits_srcdir}/stl_raw_storage_iter.h \
${bits_srcdir}/stl_relops.h \
${bits_srcdir}/stl_uninitialized.h \
+ ${bits_srcdir}/string_view.tcc \
${bits_srcdir}/uniform_int_dist.h \
${bits_srcdir}/unique_ptr.h \
${bits_srcdir}/uses_allocator.h \
@@ -172,7 +174,6 @@ bits_headers = \
${bits_srcdir}/basic_ios.tcc \
${bits_srcdir}/basic_string.h \
${bits_srcdir}/basic_string.tcc \
- ${bits_srcdir}/char_traits.h \
${bits_srcdir}/charconv.h \
${bits_srcdir}/chrono.h \
${bits_srcdir}/chrono_io.h \
@@ -256,7 +257,6 @@ bits_headers = \
${bits_srcdir}/streambuf_iterator.h \
${bits_srcdir}/streambuf.tcc \
${bits_srcdir}/stringfwd.h \
- ${bits_srcdir}/string_view.tcc \
${bits_srcdir}/this_thread_sleep.h \
${bits_srcdir}/unique_lock.h \
${bits_srcdir}/unordered_map.h \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index 06589d53856..36e35e13806 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -404,6 +404,7 @@ std_freestanding = \
${std_srcdir}/scoped_allocator \
${std_srcdir}/source_location \
${std_srcdir}/span \
+ ${std_srcdir}/string_view \
${std_srcdir}/tuple \
${std_srcdir}/type_traits \
${std_srcdir}/typeindex \
@@ -456,7 +457,6 @@ std_freestanding = \
@GLIBCXX_HOSTED_TRUE@ ${std_srcdir}/stop_token \
@GLIBCXX_HOSTED_TRUE@ ${std_srcdir}/streambuf \
@GLIBCXX_HOSTED_TRUE@ ${std_srcdir}/string \
-@GLIBCXX_HOSTED_TRUE@ ${std_srcdir}/string_view \
@GLIBCXX_HOSTED_TRUE@ ${std_srcdir}/system_error \
@GLIBCXX_HOSTED_TRUE@ ${std_srcdir}/thread \
@GLIBCXX_HOSTED_TRUE@ ${std_srcdir}/unordered_map \
@@ -475,6 +475,7 @@ bits_freestanding = \
${bits_srcdir}/c++0x_warning.h \
${bits_srcdir}/boost_concept_check.h \
${bits_srcdir}/concept_check.h \
+ ${bits_srcdir}/char_traits.h \
${bits_srcdir}/cpp_type_traits.h \
${bits_srcdir}/enable_special_members.h \
${bits_srcdir}/functexcept.h \
@@ -508,6 +509,7 @@ bits_freestanding = \
${bits_srcdir}/stl_raw_storage_iter.h \
${bits_srcdir}/stl_relops.h \
${bits_srcdir}/stl_uninitialized.h \
+ ${bits_srcdir}/string_view.tcc \
${bits_srcdir}/uniform_int_dist.h \
${bits_srcdir}/unique_ptr.h \
${bits_srcdir}/uses_allocator.h \
@@ -525,7 +527,6 @@ bits_freestanding = \
@GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/basic_ios.tcc \
@GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/basic_string.h \
@GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/basic_string.tcc \
-@GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/char_traits.h \
@GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/charconv.h \
@GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/chrono.h \
@GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/chrono_io.h \
@@ -609,7 +610,6 @@ bits_freestanding = \
@GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/streambuf_iterator.h \
@GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/streambuf.tcc \
@GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/stringfwd.h \
-@GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/string_view.tcc \
@GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/this_thread_sleep.h \
@GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/unique_lock.h \
@GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/unordered_map.h \
diff --git a/libstdc++-v3/include/bits/char_traits.h b/libstdc++-v3/include/bits/char_traits.h
index 965ff29b75c..9c283ca7963 100644
--- a/libstdc++-v3/include/bits/char_traits.h
+++ b/libstdc++-v3/include/bits/char_traits.h
@@ -36,8 +36,16 @@
#pragma GCC system_header
-#include <bits/postypes.h> // For streampos
-#include <cwchar> // For WEOF, wmemmove, wmemset, etc.
+#include <bits/c++config.h>
+
+#if _GLIBCXX_HOSTED
+# include <bits/postypes.h> // For streampos
+#endif // HOSTED
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+# include <cwchar> // For WEOF, wmemmove, wmemset, etc.
+#endif // USE_WCHAR_T
+
#if __cplusplus >= 201103L
# include <type_traits>
#if !defined __UINT_LEAST16_TYPE__ || !defined __UINT_LEAST32_TYPE__
@@ -76,9 +84,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct _Char_types
{
typedef unsigned long int_type;
+#if _GLIBCXX_HOSTED
typedef std::streampos pos_type;
typedef std::streamoff off_type;
typedef std::mbstate_t state_type;
+#endif // HOSTED
};
@@ -102,9 +112,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
typedef _CharT char_type;
typedef typename _Char_types<_CharT>::int_type int_type;
+#if _GLIBCXX_HOSTED
typedef typename _Char_types<_CharT>::pos_type pos_type;
typedef typename _Char_types<_CharT>::off_type off_type;
typedef typename _Char_types<_CharT>::state_type state_type;
+#endif // HOSTED
#if __cpp_lib_three_way_comparison
using comparison_category = std::strong_ordering;
#endif
@@ -158,6 +170,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
eq_int_type(const int_type& __c1, const int_type& __c2)
{ return __c1 == __c2; }
+#ifdef _GLIBCXX_STDIO_EOF
static _GLIBCXX_CONSTEXPR int_type
eof()
{ return static_cast<int_type>(_GLIBCXX_STDIO_EOF); }
@@ -165,6 +178,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static _GLIBCXX_CONSTEXPR int_type
not_eof(const int_type& __c)
{ return !eq_int_type(__c, eof()) ? __c : to_int_type(char_type()); }
+#endif // defined(_GLIBCXX_STDIO_EOF)
};
template<typename _CharT>
@@ -330,9 +344,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
typedef char char_type;
typedef int int_type;
+#if _GLIBCXX_HOSTED
typedef streampos pos_type;
typedef streamoff off_type;
typedef mbstate_t state_type;
+#endif // HOSTED
#if __cpp_lib_three_way_comparison
using comparison_category = strong_ordering;
#endif
@@ -451,6 +467,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
eq_int_type(const int_type& __c1, const int_type& __c2) _GLIBCXX_NOEXCEPT
{ return __c1 == __c2; }
+#ifdef _GLIBCXX_STDIO_EOF
static _GLIBCXX_CONSTEXPR int_type
eof() _GLIBCXX_NOEXCEPT
{ return static_cast<int_type>(_GLIBCXX_STDIO_EOF); }
@@ -458,6 +475,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static _GLIBCXX_CONSTEXPR int_type
not_eof(const int_type& __c) _GLIBCXX_NOEXCEPT
{ return (__c == eof()) ? 0 : __c; }
+#endif // defined(_GLIBCXX_STDIO_EOF)
};
@@ -468,9 +486,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
typedef wchar_t char_type;
typedef wint_t int_type;
+#if _GLIBCXX_HOSTED
typedef streamoff off_type;
typedef wstreampos pos_type;
typedef mbstate_t state_type;
+#endif // HOSTED
#if __cpp_lib_three_way_comparison
using comparison_category = strong_ordering;
#endif
@@ -576,6 +596,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
eq_int_type(const int_type& __c1, const int_type& __c2) _GLIBCXX_NOEXCEPT
{ return __c1 == __c2; }
+#if _GLIBCXX_HOSTED
static _GLIBCXX_CONSTEXPR int_type
eof() _GLIBCXX_NOEXCEPT
{ return static_cast<int_type>(WEOF); }
@@ -583,6 +604,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static _GLIBCXX_CONSTEXPR int_type
not_eof(const int_type& __c) _GLIBCXX_NOEXCEPT
{ return eq_int_type(__c, eof()) ? 0 : __c; }
+#endif // HOSTED
};
#else // _GLIBCXX_USE_WCHAR_T
template<>
@@ -596,9 +618,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
typedef char8_t char_type;
typedef unsigned int int_type;
+#if _GLIBCXX_HOSTED
typedef u8streampos pos_type;
typedef streamoff off_type;
typedef mbstate_t state_type;
+#endif // HOSTED
#if __cpp_lib_three_way_comparison
using comparison_category = strong_ordering;
#endif
@@ -707,6 +731,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
eq_int_type(const int_type& __c1, const int_type& __c2) _GLIBCXX_NOEXCEPT
{ return __c1 == __c2; }
+#if _GLIBCXX_HOSTED
static _GLIBCXX_CONSTEXPR int_type
eof() _GLIBCXX_NOEXCEPT
{ return static_cast<int_type>(-1); }
@@ -714,6 +739,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static _GLIBCXX_CONSTEXPR int_type
not_eof(const int_type& __c) _GLIBCXX_NOEXCEPT
{ return eq_int_type(__c, eof()) ? 0 : __c; }
+#endif // HOSTED
};
#endif //_GLIBCXX_USE_CHAR8_T
@@ -737,9 +763,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#else
typedef make_unsigned<char16_t>::type int_type;
#endif
+#if _GLIBCXX_HOSTED
typedef streamoff off_type;
typedef u16streampos pos_type;
typedef mbstate_t state_type;
+#endif // HOSTED
#if __cpp_lib_three_way_comparison
using comparison_category = strong_ordering;
#endif
@@ -830,14 +858,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
to_char_type(const int_type& __c) noexcept
{ return char_type(__c); }
+ static constexpr bool
+ eq_int_type(const int_type& __c1, const int_type& __c2) noexcept
+ { return __c1 == __c2; }
+
+#if _GLIBCXX_HOSTED
static constexpr int_type
to_int_type(const char_type& __c) noexcept
{ return __c == eof() ? int_type(0xfffd) : int_type(__c); }
- static constexpr bool
- eq_int_type(const int_type& __c1, const int_type& __c2) noexcept
- { return __c1 == __c2; }
-
static constexpr int_type
eof() noexcept
{ return static_cast<int_type>(-1); }
@@ -845,6 +874,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static constexpr int_type
not_eof(const int_type& __c) noexcept
{ return eq_int_type(__c, eof()) ? 0 : __c; }
+#else // !HOSTED
+ static constexpr int_type
+ to_int_type(const char_type& __c) noexcept
+ { return int_type(__c); }
+#endif // !HOSTED
};
template<>
@@ -858,9 +892,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#else
typedef make_unsigned<char32_t>::type int_type;
#endif
+#if _GLIBCXX_HOSTED
typedef streamoff off_type;
typedef u32streampos pos_type;
typedef mbstate_t state_type;
+#endif // HOSTED
#if __cpp_lib_three_way_comparison
using comparison_category = strong_ordering;
#endif
@@ -959,6 +995,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
eq_int_type(const int_type& __c1, const int_type& __c2) noexcept
{ return __c1 == __c2; }
+#if _GLIBCXX_HOSTED
static constexpr int_type
eof() noexcept
{ return static_cast<int_type>(-1); }
@@ -966,6 +1003,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static constexpr int_type
not_eof(const int_type& __c) noexcept
{ return eq_int_type(__c, eof()) ? 0 : __c; }
+#endif // HOSTED
};
#if __cpp_lib_three_way_comparison
diff --git a/libstdc++-v3/include/precompiled/stdc++.h b/libstdc++-v3/include/precompiled/stdc++.h
index b447feb844f..7d21bc256b6 100644
--- a/libstdc++-v3/include/precompiled/stdc++.h
+++ b/libstdc++-v3/include/precompiled/stdc++.h
@@ -79,6 +79,7 @@
// #include <execution>
#include <optional>
#include <variant>
+#include <string_view>
#endif
#if __cplusplus >= 202002L
@@ -100,7 +101,6 @@
#endif
#endif
-
#if _GLIBCXX_HOSTED
// C
#ifndef _GLIBCXX_NO_ASSERT
@@ -201,7 +201,6 @@
#include <filesystem>
#include <optional>
#include <memory_resource>
-#include <string_view>
#include <variant>
#endif
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index dce7867e977..dc015ac7356 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -43,6 +43,7 @@
#include <iterator>
#include <optional>
#include <span>
+#include <string_view>
#include <tuple>
#if __cplusplus > 202002L
#include <variant>
@@ -2242,11 +2243,9 @@ 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;
diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view
index f42045dd6f1..55769237894 100644
--- a/libstdc++-v3/include/std/string_view
+++ b/libstdc++-v3/include/std/string_view
@@ -37,12 +37,10 @@
#if __cplusplus >= 201703L
-#include <iosfwd>
#include <bits/char_traits.h>
#include <bits/functexcept.h>
#include <bits/functional_hash.h>
#include <bits/range_access.h>
-#include <bits/ostream_insert.h>
#include <bits/stl_algobase.h>
#include <ext/numeric_traits.h>
@@ -50,11 +48,19 @@
# include <bits/ranges_base.h>
#endif
+#if _GLIBCXX_HOSTED
+# include <iosfwd>
+# include <bits/ostream_insert.h>
+#endif
+
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
+#if _GLIBCXX_HOSTED
# define __cpp_lib_string_view 201803L
+#endif
+
#if __cplusplus > 201703L
# define __cpp_lib_constexpr_string_view 201811L
#endif
@@ -413,7 +419,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif // C++20
#if __cplusplus > 202002L
-#define __cpp_lib_string_contains 202011L
+#if _GLIBCXX_HOSTED
+ // This FTM is not hosted as it also implies matching <string> support,
+ // and <string> is omitted from the freestanding subset.
+# define __cpp_lib_string_contains 202011L
+#endif // HOSTED
[[nodiscard]]
constexpr bool
contains(basic_string_view __x) const noexcept
@@ -743,13 +753,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return __x.compare(__y) >= 0; }
#endif // three-way comparison
+#if _GLIBCXX_HOSTED
// [string.view.io], Inserters and extractors
template<typename _CharT, typename _Traits>
inline basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os,
basic_string_view<_CharT,_Traits> __str)
{ return __ostream_insert(__os, __str.data(), __str.size()); }
-
+#endif // HOSTED
// basic_string_view typedef names
diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version
index 5730357793d..9e1a14e4dad 100644
--- a/libstdc++-v3/include/std/version
+++ b/libstdc++-v3/include/std/version
@@ -191,6 +191,7 @@
#define __cpp_lib_atomic_ref 201806L
#define __cpp_lib_atomic_value_initialization 201911L
#define __cpp_lib_bind_front 201907L
+#define __cpp_lib_starts_ends_with 201711L
#if __has_builtin(__builtin_bit_cast)
# define __cpp_lib_bit_cast 201806L
#endif
@@ -203,6 +204,7 @@
#if __cpp_impl_destroying_delete
# define __cpp_lib_destroying_delete 201806L
#endif
+#define __cpp_lib_constexpr_string_view 201811L
#define __cpp_lib_endian 201907L
#define __cpp_lib_int_pow2 202002L
#define __cpp_lib_integer_comparison_functions 202002L
@@ -271,7 +273,6 @@
# define __cpp_lib_constexpr_string 201811L
# endif
#endif
-#define __cpp_lib_constexpr_string_view 201811L
#define __cpp_lib_constexpr_tuple 201811L
#define __cpp_lib_constexpr_utility 201811L
#define __cpp_lib_constexpr_vector 201907L
@@ -295,7 +296,6 @@
#define __cpp_lib_shared_ptr_arrays 201707L
#define __cpp_lib_shift 201806L
#define __cpp_lib_smart_ptr_for_overwrite 202002L
-#define __cpp_lib_starts_ends_with 201711L
# if _GLIBCXX_USE_CXX11_ABI
// Only supported with cxx11-abi
# define __cpp_lib_syncbuf 201803L
diff --git a/libstdc++-v3/testsuite/20_util/function_objects/searchers.cc b/libstdc++-v3/testsuite/20_util/function_objects/searchers.cc
index 940bf036564..2e77a6314b7 100644
--- a/libstdc++-v3/testsuite/20_util/function_objects/searchers.cc
+++ b/libstdc++-v3/testsuite/20_util/function_objects/searchers.cc
@@ -24,15 +24,19 @@
#include <algorithm>
#include <testsuite_hooks.h>
-#ifndef __cpp_lib_boyer_moore_searcher
-# error "Feature-test macro for searchers missing"
-#elif __cpp_lib_boyer_moore_searcher < 201603
-# error "Feature-test macro for searchers has wrong value"
-#endif
+#if __STDC_HOSTED__
+# ifndef __cpp_lib_boyer_moore_searcher
+# error "Feature-test macro for searchers missing"
+# elif __cpp_lib_boyer_moore_searcher < 201603
+# error "Feature-test macro for searchers has wrong value"
+# endif
+#endif // HOSTED
using std::default_searcher;
+#if __STDC_HOSTED__
using std::boyer_moore_searcher;
using std::boyer_moore_horspool_searcher;
+#endif // HOSTED
void
test01()
@@ -51,8 +55,10 @@ test01()
auto nlen = std::strlen(n);
auto ne = n + nlen;
default_searcher d(n, ne);
+#if __STDC_HOSTED__
boyer_moore_searcher bm(n, ne);
boyer_moore_horspool_searcher bmh(n, ne);
+#endif // HOSTED
for (auto h : haystacks)
{
auto he = h + std::strlen(h);
@@ -63,6 +69,8 @@ test01()
VERIFY( d_res.second == d_res.first );
else
VERIFY( d_res.second == (d_res.first + nlen) );
+
+#if __STDC_HOSTED__
auto bm_res = bm(h, he);
VERIFY( bm_res.first == res );
if (res == he)
@@ -75,6 +83,7 @@ test01()
VERIFY( bmh_res.second == bmh_res.first );
else
VERIFY( bmh_res.second == (bmh_res.first + nlen) );
+#endif
}
}
}
@@ -96,8 +105,10 @@ test02()
auto nlen = std::char_traits<wchar_t>::length(n);
auto ne = n + nlen;
default_searcher d(n, ne);
+#if __STDC_HOSTED__
boyer_moore_searcher bm(n, ne);
boyer_moore_horspool_searcher bmh(n, ne);
+#endif // HOSTED
for (auto h : haystacks)
{
auto he = h + std::char_traits<wchar_t>::length(h);
@@ -108,6 +119,7 @@ test02()
VERIFY( d_res.second == d_res.first );
else
VERIFY( d_res.second == (d_res.first + nlen) );
+#if __STDC_HOSTED__
auto bm_res = bm(h, he);
VERIFY( bm_res.first == res );
if (res == he)
@@ -120,6 +132,7 @@ test02()
VERIFY( bmh_res.second == bmh_res.first );
else
VERIFY( bmh_res.second == (bmh_res.first + nlen) );
+#endif // HOSTED
}
}
}
@@ -147,8 +160,10 @@ test03()
const char* he = haystack + std::strlen(haystack);
default_searcher d(needle, ne, eq);
+#if __STDC_HOSTED__
boyer_moore_searcher bm(needle, ne, eq, eq);
boyer_moore_horspool_searcher bmh(needle, ne, eq, eq);
+#endif
auto res = std::search(haystack, he, needle, ne, eq);
auto d_res = d(haystack, he);
@@ -157,6 +172,7 @@ test03()
VERIFY( d_res.second == d_res.first );
else
VERIFY( d_res.second == (d_res.first + nlen) );
+#if __STDC_HOSTED__
auto bm_res = bm(haystack, he);
VERIFY( bm_res.first == res );
if (res == he)
@@ -169,6 +185,7 @@ test03()
VERIFY( bmh_res.second == bmh_res.first );
else
VERIFY( bmh_res.second == (bmh_res.first + nlen) );
+#endif // HOSTED
}
int
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/capacity/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/capacity/1.cc
index 3d162c60667..eb39a5ffdc2 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string_view/capacity/1.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/capacity/1.cc
@@ -45,9 +45,11 @@ namespace std
typedef A<B> char_type;
// Unsigned as wint_t in unsigned.
typedef unsigned long int_type;
+#if __STDC_HOSTED__
typedef streampos pos_type;
typedef streamoff off_type;
typedef mbstate_t state_type;
+#endif // HOSTED
static void
assign(char_type& __c1, const char_type& __c2)
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/1.cc
index 61d12635a4a..014d6335efa 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/1.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/1.cc
@@ -20,10 +20,13 @@
// basic_string_view constructors.
#include <string_view>
-#include <string>
#include <cstring>
#include <testsuite_hooks.h>
+#if __STDC_HOSTED__
+# include <string>
+#endif // HOSTED
+
void
test01()
{
@@ -53,10 +56,12 @@ test01()
VERIFY( str05.length() == len_lit01 );
VERIFY( str05.data() == str_lit01 );
+#if __STDC_HOSTED__
// basic_string_view(basic_string& s)
std::string istr07(10, 'z');
std::string_view str07{istr07};
VERIFY( str07.length() == 10 );
+#endif // HOSTED
}
int
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/2.cc
index 0f2a0a15076..48dff0e3de7 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/2.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/2.cc
@@ -21,7 +21,6 @@
#include <new>
#include <string_view>
-#include <stdexcept>
#include <testsuite_hooks.h>
void
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/3.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/3.cc
index 9dcdbe3720e..2aac45a90c0 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/3.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/3.cc
@@ -20,7 +20,6 @@
// basic_string_view constructors.
#include <string_view>
-#include <vector>
#include <testsuite_hooks.h>
void
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/range.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/range.cc
index bda35dcb8e9..5b61b901e60 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/range.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/range.cc
@@ -19,10 +19,13 @@
// { dg-do run { target c++20 } }
#include <string_view>
-#include <vector>
#include <testsuite_hooks.h>
#include <testsuite_iterators.h>
+#if __STDC_HOSTED__
+# include <vector>
+#endif // HOSTED
+
constexpr char str[] = "abcdefg";
constexpr std::basic_string_view<char> s(std::begin(str), std::cend(str) - 1);
static_assert( s == str );
@@ -38,11 +41,13 @@ static_assert( ! noexcept(std::basic_string_view<char>(I{}, I{})) );
void
test01()
{
+#if __STDC_HOSTED__
std::vector<char> v{'a', 'b', 'c'};
std::basic_string_view<char> s(v.begin(), v.end());
VERIFY( s.data() == v.data() );
std::basic_string_view ctad(v.begin(), v.end());
VERIFY( ctad == s );
+#endif // HOSTED
}
int
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/wchar_t/1.cc
index 29a04fd2321..ef6825a7c4e 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/wchar_t/1.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/wchar_t/1.cc
@@ -20,7 +20,9 @@
// basic_string_view constructors.
#include <string_view>
-#include <string>
+#if __STDC_HOSTED__
+# include <string>
+#endif // HOSTED
#include <cwchar>
#include <testsuite_hooks.h>
@@ -53,10 +55,12 @@ test01()
VERIFY( str05.length() == len_lit01 );
VERIFY( str05.data() == str_lit01 );
+#if __STDC_HOSTED__
// basic_string_view(basic_string& s)
std::wstring istr07(10, L'z');
std::wstring_view str07{istr07};
VERIFY( str07.length() == 10 );
+#endif // HOSTED
}
int
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/1.cc
index b27e7d7dcfc..baba9843c9c 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/1.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/1.cc
@@ -20,9 +20,12 @@
// basic_string element access
#include <string_view>
-#include <stdexcept>
#include <testsuite_hooks.h>
+#if __STDC_HOSTED__
+# include <stdexcept>
+#endif // HOSTED
+
void
test01()
{
@@ -43,6 +46,7 @@ test01()
//cref cref2 = str01[csz01];
//VERIFY( cref2 == char() );
+#if __STDC_HOSTED__
// const_reference at(size_type pos) const;
csz01 = str01.size();
cref cref3 = str01.at(csz01 - 1);
@@ -60,6 +64,7 @@ test01()
{
VERIFY( false );
}
+#endif // HOSTED
}
int
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/1.cc
index e9df8720fdc..3d3b513d069 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/1.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/1.cc
@@ -20,7 +20,9 @@
// basic_string_view element access
#include <string_view>
-#include <stdexcept>
+#if __STDC_HOSTED__
+# include <stdexcept>
+#endif // HOSTED
#include <testsuite_hooks.h>
void
@@ -43,6 +45,7 @@ test01()
//cref cref2 = str01[csz01];
//VERIFY( cref2 == wchar_t() );
+#if __STDC_HOSTED__
// const_reference at(size_type pos) const;
csz01 = str01.size();
cref cref3 = str01.at(csz01 - 1);
@@ -60,6 +63,7 @@ test01()
{
VERIFY( false );
}
+#endif // HOSTED
}
int
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/contains/char/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/contains/char/2.cc
index 3501006150b..c106a553f40 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/contains/char/2.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/contains/char/2.cc
@@ -1,6 +1,5 @@
// { dg-options "-std=gnu++23" }
// { dg-do compile { target c++23 } }
-// { dg-require-effective-target hosted }
// Copyright (C) 2021-2022 Free Software Foundation, Inc.
//
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/substr/char.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/substr/char.cc
index f1e3f3cc006..a652e643f67 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/substr/char.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/substr/char.cc
@@ -20,9 +20,12 @@
// basic_string_view::substr
#include <string_view>
-#include <stdexcept>
#include <testsuite_hooks.h>
+#if __STDC_HOSTED__
+# include <stdexcept>
+#endif
+
void
test01()
{
@@ -43,6 +46,7 @@ test01()
str02 = str01.substr(10);
VERIFY( str02 == "pacifica" );
+#if __STDC_HOSTED__
try
{
str02 = str01.substr(csz01 + 1);
@@ -68,6 +72,7 @@ test01()
{
VERIFY( false );
}
+#endif // HOSTED
}
int
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/substr/wchar_t.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/substr/wchar_t.cc
index dbe1745c89d..a02a61c9b4c 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/substr/wchar_t.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/substr/wchar_t.cc
@@ -20,9 +20,12 @@
// basic_string_view::substr
#include <string_view>
-#include <stdexcept>
#include <testsuite_hooks.h>
+#if __STDC_HOSTED__
+# include <stdexcept>
+#endif
+
void
test01()
{
@@ -43,6 +46,7 @@ test01()
str02 = str01.substr(10);
VERIFY( str02 == L"pacifica" );
+#if __STDC_HOSTED__
try
{
str02 = str01.substr(csz01 + 1);
@@ -68,6 +72,7 @@ test01()
{
VERIFY( false );
}
+#endif // HOSTED
}
int
--
2.39.0
next reply other threads:[~2023-01-10 10:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-10 10:03 Arsen Arsenović [this message]
2023-01-10 10:03 ` [PATCH 2/2] libstdc++: Fix a few !HOSTED test regressions Arsen Arsenović
2023-01-13 14:17 ` Jonathan Wakely
2023-01-10 14:26 ` [PATCH 1/2] libstdc++: Enable string_view in freestanding Jonathan Wakely
2023-01-10 16:19 ` Arsen Arsenović
2023-01-13 14:17 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230110100305.1420589-1-arsen@aarsen.me \
--to=arsen@aarsen.me \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).