From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by sourceware.org (Postfix) with ESMTPS id C46BB3858CDA; Tue, 10 Jan 2023 16:30:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C46BB3858CDA 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 smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (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-102.mailbox.org (Postfix) with ESMTPS id 4NrxB10bRGz9scf; Tue, 10 Jan 2023 17:30:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aarsen.me; s=MBO0001; t=1673368217; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=amOEeMkM92/ktu3L4odvDPONG/IlRRJ8aU/VSJJcyiQ=; b=lwDiKwO4r6Y7X4w3hy1aaNxQdjs17XVCNKrFAWEtP/7Yon/3OuFx6kqdr28aUNK8gJHJkN cus9VjA51+pz1gHwNymSpr8SclZ1PFJEYhT+xX8HxPkzZ+9eGebAAwMZ5ecrbUhXm17Sp2 PMkv+tUhba9NWdt2xvoJU3AwysxlhwL8cTvwk0CZ4PLYdU2Gmd4sbG9FewXH+o9Owfc8EB ho/MVqQdpbZxfxsHxEObHM3q5Y6BMUNZMZao83Y0gdbvx40f+ySiMPw3ewhp3mYX4eKH95 LxO3OTJZ7zWglbQ4opJAaIVBu3pDPAnQfxLFa02I7v5NpdknZyouefAaRU0ymg== References: <20230110100305.1420589-1-arsen@aarsen.me> From: Arsen =?utf-8?Q?Arsenovi=C4=87?= To: Jonathan Wakely Cc: libstdc++ , gcc-patches Subject: Re: [PATCH 1/2] libstdc++: Enable string_view in freestanding Date: Tue, 10 Jan 2023 17:19:46 +0100 In-reply-to: Message-ID: <86mt6q4ajt.fsf@aarsen.me> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-Rspamd-Queue-Id: 4NrxB10bRGz9scf X-Spam-Status: No, score=-11.4 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: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Hi Jonathan, Jonathan Wakely writes: > Sorry for the top post. > > -#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 > > That should say "not freestanding", right? Whoops, yes. Here's the fixed-up patch. --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=0001-libstdc-Enable-string_view-in-freestanding.patch Content-Transfer-Encoding: quoted-printable Content-Description: Fixed up patch From=2007cac07fc88994ced9f3ea97c4e03f8c719c4ee4 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Arsen=3D20Arsenovi=3DC4=3D87?=3D Date: Thu, 15 Dec 2022 00:53:37 +0100 Subject: [PATCH 1/2] libstdc++: Enable string_view in freestanding 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. =2D-- 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/Makefi= le.am index e91f4ddd4de..bf566082a8c 100644 =2D-- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -46,6 +46,7 @@ std_freestanding =3D \ ${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 =3D \ ${std_srcdir}/stop_token \ ${std_srcdir}/streambuf \ ${std_srcdir}/string \ =2D ${std_srcdir}/string_view \ ${std_srcdir}/system_error \ ${std_srcdir}/thread \ ${std_srcdir}/unordered_map \ @@ -120,6 +120,7 @@ bits_freestanding =3D \ ${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 =3D \ ${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 =3D \ ${bits_srcdir}/basic_ios.tcc \ ${bits_srcdir}/basic_string.h \ ${bits_srcdir}/basic_string.tcc \ =2D ${bits_srcdir}/char_traits.h \ ${bits_srcdir}/charconv.h \ ${bits_srcdir}/chrono.h \ ${bits_srcdir}/chrono_io.h \ @@ -256,7 +257,6 @@ bits_headers =3D \ ${bits_srcdir}/streambuf_iterator.h \ ${bits_srcdir}/streambuf.tcc \ ${bits_srcdir}/stringfwd.h \ =2D ${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/Makefi= le.in index 06589d53856..36e35e13806 100644 =2D-- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -404,6 +404,7 @@ std_freestanding =3D \ ${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 =3D \ @GLIBCXX_HOSTED_TRUE@ ${std_srcdir}/stop_token \ @GLIBCXX_HOSTED_TRUE@ ${std_srcdir}/streambuf \ @GLIBCXX_HOSTED_TRUE@ ${std_srcdir}/string \ =2D@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 =3D \ ${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 =3D \ ${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 =3D \ @GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/basic_ios.tcc \ @GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/basic_string.h \ @GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/basic_string.tcc \ =2D@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 =3D \ @GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/streambuf_iterator.h \ @GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/streambuf.tcc \ @GLIBCXX_HOSTED_TRUE@ ${bits_srcdir}/stringfwd.h \ =2D@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..6b54f0dde20 100644 =2D-- a/libstdc++-v3/include/bits/char_traits.h +++ b/libstdc++-v3/include/bits/char_traits.h @@ -36,8 +36,16 @@ =20 #pragma GCC system_header =20 =2D#include // For streampos =2D#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 >=3D 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 }; =20 =20 @@ -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 =3D 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 =3D=3D __c2; } =20 +#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) }; =20 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 =3D strong_ordering; #endif @@ -451,6 +467,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION eq_int_type(const int_type& __c1, const int_type& __c2) _GLIBCXX_NOE= XCEPT { return __c1 =3D=3D __c2; } =20 +#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 =3D=3D eof()) ? 0 : __c; } +#endif // defined(_GLIBCXX_STDIO_EOF) }; =20 =20 @@ -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 =3D strong_ordering; #endif @@ -576,6 +596,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION eq_int_type(const int_type& __c1, const int_type& __c2) _GLIBCXX_NOE= XCEPT { return __c1 =3D=3D __c2; } =20 +#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 =3D strong_ordering; #endif @@ -707,6 +731,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION eq_int_type(const int_type& __c1, const int_type& __c2) _GLIBCXX_NOE= XCEPT { return __c1 =3D=3D __c2; } =20 +#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 =20 @@ -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 =3D strong_ordering; #endif @@ -830,14 +858,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION to_char_type(const int_type& __c) noexcept { return char_type(__c); } =20 + static constexpr bool + eq_int_type(const int_type& __c1, const int_type& __c2) noexcept + { return __c1 =3D=3D __c2; } + +#if _GLIBCXX_HOSTED static constexpr int_type to_int_type(const char_type& __c) noexcept { return __c =3D=3D eof() ? int_type(0xfffd) : int_type(__c); } =20 =2D static constexpr bool =2D eq_int_type(const int_type& __c1, const int_type& __c2) noexcept =2D { return __c1 =3D=3D __c2; } =2D 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 }; =20 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 =3D 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 =3D=3D __c2; } =20 +#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 }; =20 #if __cpp_lib_three_way_comparison diff --git a/libstdc++-v3/include/precompiled/stdc++.h b/libstdc++-v3/inclu= de/precompiled/stdc++.h index b447feb844f..7d21bc256b6 100644 =2D-- a/libstdc++-v3/include/precompiled/stdc++.h +++ b/libstdc++-v3/include/precompiled/stdc++.h @@ -79,6 +79,7 @@ // #include #include #include +#include #endif =20 #if __cplusplus >=3D 202002L @@ -100,7 +101,6 @@ #endif #endif =20 =2D #if _GLIBCXX_HOSTED // C #ifndef _GLIBCXX_NO_ASSERT @@ -201,7 +201,6 @@ #include #include #include =2D#include #include #endif =20 diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ran= ges index dce7867e977..dc015ac7356 100644 =2D-- 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 =3D false; =20 =2D#if _GLIBCXX_HOSTED template inline constexpr bool __is_basic_string_view> =3D true; =2D#endif =20 template inline constexpr bool __is_subrange =3D false; diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/st= d/string_view index f42045dd6f1..60a4c260e80 100644 =2D-- a/libstdc++-v3/include/std/string_view +++ b/libstdc++-v3/include/std/string_view @@ -37,12 +37,10 @@ =20 #if __cplusplus >=3D 201703L =20 =2D#include #include #include #include #include =2D#include #include #include =20 @@ -50,11 +48,19 @@ # include #endif =20 +#if _GLIBCXX_HOSTED +# include +# include +#endif + namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION =20 +#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 =20 #if __cplusplus > 202002L =2D#define __cpp_lib_string_contains 202011L +#if _GLIBCXX_HOSTED + // This FTM is not freestanding 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) >=3D 0; } #endif // three-way comparison =20 +#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()); } =2D +#endif // HOSTED =20 // basic_string_view typedef names =20 diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/ve= rsion index 5730357793d..9e1a14e4dad 100644 =2D-- 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 =2D#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 =2D#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 =2D-- 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 =20 =2D#ifndef __cpp_lib_boyer_moore_searcher =2D# error "Feature-test macro for searchers missing" =2D#elif __cpp_lib_boyer_moore_searcher < 201603 =2D# error "Feature-test macro for searchers has wrong value" =2D#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 =20 using std::default_searcher; +#if __STDC_HOSTED__ using std::boyer_moore_searcher; using std::boyer_moore_horspool_searcher; +#endif // HOSTED =20 void test01() @@ -51,8 +55,10 @@ test01() auto nlen =3D std::strlen(n); auto ne =3D 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 =3D h + std::strlen(h); @@ -63,6 +69,8 @@ test01() VERIFY( d_res.second =3D=3D d_res.first ); else VERIFY( d_res.second =3D=3D (d_res.first + nlen) ); + +#if __STDC_HOSTED__ auto bm_res =3D bm(h, he); VERIFY( bm_res.first =3D=3D res ); if (res =3D=3D he) @@ -75,6 +83,7 @@ test01() VERIFY( bmh_res.second =3D=3D bmh_res.first ); else VERIFY( bmh_res.second =3D=3D (bmh_res.first + nlen) ); +#endif } } } @@ -96,8 +105,10 @@ test02() auto nlen =3D std::char_traits::length(n); auto ne =3D 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 =3D h + std::char_traits::length(h); @@ -108,6 +119,7 @@ test02() VERIFY( d_res.second =3D=3D d_res.first ); else VERIFY( d_res.second =3D=3D (d_res.first + nlen) ); +#if __STDC_HOSTED__ auto bm_res =3D bm(h, he); VERIFY( bm_res.first =3D=3D res ); if (res =3D=3D he) @@ -120,6 +132,7 @@ test02() VERIFY( bmh_res.second =3D=3D bmh_res.first ); else VERIFY( bmh_res.second =3D=3D (bmh_res.first + nlen) ); +#endif // HOSTED } } } @@ -147,8 +160,10 @@ test03() const char* he =3D haystack + std::strlen(haystack); =20 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 =20 auto res =3D std::search(haystack, he, needle, ne, eq); auto d_res =3D d(haystack, he); @@ -157,6 +172,7 @@ test03() VERIFY( d_res.second =3D=3D d_res.first ); else VERIFY( d_res.second =3D=3D (d_res.first + nlen) ); +#if __STDC_HOSTED__ auto bm_res =3D bm(haystack, he); VERIFY( bm_res.first =3D=3D res ); if (res =3D=3D he) @@ -169,6 +185,7 @@ test03() VERIFY( bmh_res.second =3D=3D bmh_res.first ); else VERIFY( bmh_res.second =3D=3D (bmh_res.first + nlen) ); +#endif // HOSTED } =20 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 =2D-- 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 =20=20=20=20=20=20=20 static void=20 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 =2D-- 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. =20 #include =2D#include #include #include =20 +#if __STDC_HOSTED__ +# include +#endif // HOSTED + void test01() { @@ -53,10 +56,12 @@ test01() VERIFY( str05.length() =3D=3D len_lit01 ); VERIFY( str05.data() =3D=3D str_lit01 ); =20 +#if __STDC_HOSTED__ // basic_string_view(basic_string& s) std::string istr07(10, 'z'); std::string_view str07{istr07}; VERIFY( str07.length() =3D=3D 10 ); +#endif // HOSTED } =20 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 =2D-- 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 @@ =20 #include #include =2D#include #include =20 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 =2D-- 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. =20 #include =2D#include #include =20 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/ra= nge.cc index bda35dcb8e9..5b61b901e60 100644 =2D-- 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 } } =20 #include =2D#include #include #include =20 +#if __STDC_HOSTED__ +# include +#endif // HOSTED + constexpr char str[] =3D "abcdefg"; constexpr std::basic_string_view s(std::begin(str), std::cend(str) -= 1); static_assert( s =3D=3D 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() =3D=3D v.data() ); std::basic_string_view ctad(v.begin(), v.end()); VERIFY( ctad =3D=3D s ); +#endif // HOSTED } =20 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 =2D-- 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. =20 #include =2D#include +#if __STDC_HOSTED__ +# include +#endif // HOSTED #include #include =20 @@ -53,10 +55,12 @@ test01() VERIFY( str05.length() =3D=3D len_lit01 ); VERIFY( str05.data() =3D=3D str_lit01 ); =20 +#if __STDC_HOSTED__ // basic_string_view(basic_string& s) std::wstring istr07(10, L'z'); std::wstring_view str07{istr07}; VERIFY( str07.length() =3D=3D 10 ); +#endif // HOSTED } =20 int diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_ac= cess/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/elemen= t_access/char/1.cc index b27e7d7dcfc..baba9843c9c 100644 =2D-- 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/ch= ar/1.cc @@ -20,9 +20,12 @@ // basic_string element access =20 #include =2D#include #include =20 +#if __STDC_HOSTED__ +# include +#endif // HOSTED + void test01() { @@ -43,6 +46,7 @@ test01() //cref cref2 =3D str01[csz01]; //VERIFY( cref2 =3D=3D char() ); =20 +#if __STDC_HOSTED__ // const_reference at(size_type pos) const; csz01 =3D str01.size(); cref cref3 =3D str01.at(csz01 - 1); @@ -60,6 +64,7 @@ test01() { VERIFY( false ); } +#endif // HOSTED } =20 int diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_ac= cess/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/ele= ment_access/wchar_t/1.cc index e9df8720fdc..3d3b513d069 100644 =2D-- 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/wc= har_t/1.cc @@ -20,7 +20,9 @@ // basic_string_view element access =20 #include =2D#include +#if __STDC_HOSTED__ +# include +#endif // HOSTED #include =20 void @@ -43,6 +45,7 @@ test01() //cref cref2 =3D str01[csz01]; //VERIFY( cref2 =3D=3D wchar_t() ); =20 +#if __STDC_HOSTED__ // const_reference at(size_type pos) const; csz01 =3D str01.size(); cref cref3 =3D str01.at(csz01 - 1); @@ -60,6 +63,7 @@ test01() { VERIFY( false ); } +#endif // HOSTED } =20 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/o= perations/contains/char/2.cc index 3501006150b..c106a553f40 100644 =2D-- a/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/cont= ains/char/2.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/contai= ns/char/2.cc @@ -1,6 +1,5 @@ // { dg-options "-std=3Dgnu++23" } // { dg-do compile { target c++23 } } =2D// { dg-require-effective-target hosted } =20 // 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/opera= tions/substr/char.cc index f1e3f3cc006..a652e643f67 100644 =2D-- a/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/subs= tr/char.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/substr= /char.cc @@ -20,9 +20,12 @@ // basic_string_view::substr =20 #include =2D#include #include =20 +#if __STDC_HOSTED__ +# include +#endif + void test01() { @@ -43,6 +46,7 @@ test01() str02 =3D str01.substr(10); VERIFY( str02 =3D=3D "pacifica" ); =20 +#if __STDC_HOSTED__ try { str02 =3D str01.substr(csz01 + 1); @@ -68,6 +72,7 @@ test01() { VERIFY( false ); } +#endif // HOSTED } =20 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/op= erations/substr/wchar_t.cc index dbe1745c89d..a02a61c9b4c 100644 =2D-- a/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/subs= tr/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 =20 #include =2D#include #include =20 +#if __STDC_HOSTED__ +# include +#endif + void test01() { @@ -43,6 +46,7 @@ test01() str02 =3D str01.substr(10); VERIFY( str02 =3D=3D L"pacifica" ); =20 +#if __STDC_HOSTED__ try { str02 =3D str01.substr(csz01 + 1); @@ -68,6 +72,7 @@ test01() { VERIFY( false ); } +#endif // HOSTED } =20 int =2D-=20 2.39.0 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable =2D-=20 Arsen Arsenovi=C4=87 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iOYEARYKAI4WIQT+4rPRE/wAoxYtYGFSwpQwHqLEkwUCY72Sll8UgAAAAAAuAChp c3N1ZXItZnByQG5vdGF0aW9ucy5vcGVucGdwLmZpZnRoaG9yc2VtYW4ubmV0RkVF MkIzRDExM0ZDMDBBMzE2MkQ2MDYxNTJDMjk0MzAxRUEyQzQ5MxAcYXJzZW5AYWFy c2VuLm1lAAoJEFLClDAeosSTdWsA/AmBwIvf5z6oRxpujW4CrevJ3NAXNv6q0UB7 qmCRq2eyAQCJqNztkIeFgO7L8ZqzpxSqlUFKnMHsfJW4UV6/9kKzAA== =hZRI -----END PGP SIGNATURE----- --==-=-=--