From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by sourceware.org (Postfix) with ESMTPS id 297A03858CDA; Tue, 10 Jan 2023 10:03:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 297A03858CDA Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=aarsen.me Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=aarsen.me Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4NrmbQ38tvz9sld; Tue, 10 Jan 2023 11:03:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aarsen.me; s=MBO0001; t=1673344994; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=TO72vxgQ/WzjkkUTSsTQddgu1CLvvl0VBYK6N06nOGs=; b=MjrB++2HqwXz93llJ/CSdQ6bSQnGvQRgbacXMsIqkWXNP9YxW84p4stBhZStKcMbos+3BX 7WmB9AGdfMD9iZWbd0E4bJ5Zg0koO1gmitPm2BsZvhlmhAD003t2/vSvgZOxqfBH1b8Vh6 zkKgEsW3+8nYk3+H7askMoUA8ljLm/fKsnFBBwxdkdWu0IU5RoXCQCoSj4TpuOvOf59RPP i1WsmqSYczyg+pHhd9nfA5pIam7Bi74RYzbWFzls11bK41qRxl/MiDptAar/LVL6S/f8ro nX2UjgwUxNs4YzEfundb3uXs9w/R7hBD4U7/5DDAFfhTY5YvBAKfpB45j/5Wzw== From: =?UTF-8?q?Arsen=20Arsenovi=C4=87?= To: libstdc++@gcc.gnu.org Cc: gcc-patches@gcc.gnu.org, =?UTF-8?q?Arsen=20Arsenovi=C4=87?= Subject: [PATCH 1/2] libstdc++: Enable string_view in freestanding Date: Tue, 10 Jan 2023 11:03:04 +0100 Message-Id: <20230110100305.1420589-1-arsen@aarsen.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_INFOUSMEBIZ,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 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 directly. * include/precompiled/stdc++.h: Include 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 -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 include. * testsuite/21_strings/basic_string_view/cons/char/3.cc: Remove unused include. * testsuite/21_strings/basic_string_view/cons/char/range.cc: Guard related testing behind __STDC_HOSTED__. * testsuite/21_strings/basic_string_view/cons/wchar_t/1.cc: Guard 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 tests behind __STDC_HOSTED__. * testsuite/21_strings/basic_string_view/operations/contains/char/2.cc: Enable test on freestanding, guard bits behind __STDC_HOSTED__. * testsuite/21_strings/basic_string_view/operations/substr/char.cc: Guard 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 // For streampos -#include // For WEOF, wmemmove, wmemset, etc. +#include + +#if _GLIBCXX_HOSTED +# include // For streampos +#endif // HOSTED + +#ifdef _GLIBCXX_USE_WCHAR_T +# include // For WEOF, wmemmove, wmemset, etc. +#endif // USE_WCHAR_T + #if __cplusplus >= 201103L # include #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(_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 @@ -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(_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(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(-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::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(-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::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(-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 #include #include +#include #endif #if __cplusplus >= 202002L @@ -100,7 +101,6 @@ #endif #endif - #if _GLIBCXX_HOSTED // C #ifndef _GLIBCXX_NO_ASSERT @@ -201,7 +201,6 @@ #include #include #include -#include #include #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 #include #include +#include #include #if __cplusplus > 202002L #include @@ -2242,11 +2243,9 @@ namespace views::__adaptor template inline constexpr bool __is_basic_string_view = false; -#if _GLIBCXX_HOSTED template inline constexpr bool __is_basic_string_view> = true; -#endif template 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 #include #include #include #include -#include #include #include @@ -50,11 +48,19 @@ # include #endif +#if _GLIBCXX_HOSTED +# include +# include +#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 support, + // and 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 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 #include -#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::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::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 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 -#include #include #include +#if __STDC_HOSTED__ +# include +#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 #include -#include #include 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 -#include #include 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 -#include #include #include +#if __STDC_HOSTED__ +# include +#endif // HOSTED + constexpr char str[] = "abcdefg"; constexpr std::basic_string_view s(std::begin(str), std::cend(str) - 1); static_assert( s == str ); @@ -38,11 +41,13 @@ static_assert( ! noexcept(std::basic_string_view(I{}, I{})) ); void test01() { +#if __STDC_HOSTED__ std::vector v{'a', 'b', 'c'}; std::basic_string_view 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 -#include +#if __STDC_HOSTED__ +# include +#endif // HOSTED #include #include @@ -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 -#include #include +#if __STDC_HOSTED__ +# include +#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 -#include +#if __STDC_HOSTED__ +# include +#endif // HOSTED #include 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 -#include #include +#if __STDC_HOSTED__ +# include +#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 -#include #include +#if __STDC_HOSTED__ +# include +#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