From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by sourceware.org (Postfix) with ESMTPS id A0B2938432FA; Tue, 10 Jan 2023 14:29:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A0B2938432FA Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x52f.google.com with SMTP id j16so17791042edw.11; Tue, 10 Jan 2023 06:29:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Rug0W7otIR/FgZcQa67puDdmGMmVO1bH4KCuvd7F7ns=; b=Z65EIRl0gloyEKfezA2qIWGtrLNBs62DkrJ8dyi4MeV4z9xF4QzYmc+26Pio0XLNkR lO8GPLWDYsOAANKos/AR5i/ru9pMiVbO/800uE5i0v4zzOtfqtKrKhkhPmVL/5r4zkQY IZIkSTIkjt59jHpee6usXXpMh5yMNW0OfniKbVIRawxN4WH6MJIhLXUwtjKWTl2wWmEc NF6eUtMRTmU3GrZg3glx45EPjCRIN7IQv8R1TTl8eP2pw2vhP1o4Y6gi9HALJc2Q8T00 fBeY+fys3h0jYkCRl9fIh+PPlsBaE6580alWq5jPwlYcxFk/QoTKD1XjGJAYr0ZNvjp6 nApQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Rug0W7otIR/FgZcQa67puDdmGMmVO1bH4KCuvd7F7ns=; b=K88iFt2PmQf30I5ijS3MWcv6EQHFoZLCbe6XHoT69kbc+cla3o6e4tAwIYHy4tcK56 UnI7XnaVsmBHB8hcOPPUBT24egYRGy4QJzPoEF6btcdFbBhsuSM6Z25N+olPGrjPda4R knMonybgDRdB9ZXR/NKD/7Shbn6TazuX/ya+neKU6D+NIRmn8JiQ1hLFM8f3axIbdGIw Zuq8QhLx8CMYs2acLUReayaWxs2DHj68ek9H9/h8HnmbjkWMJP9lqQPy2KNq2DvehtqL qMbhnr3yGmIXtugMdwpLPkBFFGvcVpffNAlQsfqCV8RxCin9UzZ+eHTRd1cASG1etslN EozQ== X-Gm-Message-State: AFqh2kp5NUFwEpInhmPWYoh8H5zz87v/BAvkf1J0rkdhzF0BB/Y95O0i qANVZllYfLJ+dJCD9ADqGZfGq/xw6Tf0Nhlh9dc= X-Google-Smtp-Source: AMrXdXs2fQe2oTsVtX1V8BaJp76oq85TlJP0bB9x+FQxQ0XQPwilgWKx7DQA8K7Jya6Bd0opt1iXFxD/gs7ly8JvmVA= X-Received: by 2002:aa7:cb03:0:b0:499:c265:752a with SMTP id s3-20020aa7cb03000000b00499c265752amr502086edt.257.1673360952102; Tue, 10 Jan 2023 06:29:12 -0800 (PST) MIME-Version: 1.0 References: <20230110100305.1420589-1-arsen@aarsen.me> In-Reply-To: <20230110100305.1420589-1-arsen@aarsen.me> From: Jonathan Wakely Date: Tue, 10 Jan 2023 14:26:54 +0000 Message-ID: Subject: Re: [PATCH 1/2] libstdc++: Enable string_view in freestanding To: =?UTF-8?Q?Arsen_Arsenovi=C4=87?= Cc: "libstdc++" , gcc-patches Content-Type: multipart/alternative; boundary="00000000000021994305f1e9b556" X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,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: --00000000000021994305f1e9b556 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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? On Tue, 10 Jan 2023, 10:04 Arsen Arsenovi=C4=87 via Libstdc++, < libstdc++@gcc.gnu.org> wrote: > 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.c= c: > 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=3D'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 =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 \ > - ${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 \ > - ${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 \ > - ${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 =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 \ > -@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 \ > -@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 \ > -@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 >=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 > }; > > > @@ -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; } > > +#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 =3D 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 =3D=3D __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 =3D=3D 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 =3D 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 =3D=3D __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 =3D 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 =3D=3D __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 =3D 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 =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); } > > - static constexpr bool > - eq_int_type(const int_type& __c1, const int_type& __c2) noexcept > - { return __c1 =3D=3D __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 =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; } > > +#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 >=3D 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 =3D false; > > -#if _GLIBCXX_HOSTED > template > inline constexpr bool > __is_basic_string_view> > =3D true; > -#endif > > template > inline constexpr bool __is_subrange =3D 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 >=3D 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) >=3D 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 =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); > > 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 =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 > } > > 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() =3D=3D len_lit01 ); > VERIFY( str05.data() =3D=3D str_lit01 ); > > +#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 > } > > 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[] =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 > } > > 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() =3D=3D len_lit01 ); > VERIFY( str05.data() =3D=3D 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() =3D=3D 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 =3D str01[csz01]; > //VERIFY( cref2 =3D=3D char() ); > > +#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 > } > > int > diff --git > a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wcha= r_t/1.cc > b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wcha= r_t/1.cc > index e9df8720fdc..3d3b513d069 100644 > --- > a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wcha= r_t/1.cc > +++ > b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wcha= r_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 =3D str01[csz01]; > //VERIFY( cref2 =3D=3D wchar_t() ); > > +#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 > } > > 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=3Dgnu++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/c= har.cc > b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/substr/c= har.cc > index f1e3f3cc006..a652e643f67 100644 > --- > a/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/substr/c= har.cc > +++ > b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/substr/c= har.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 =3D str01.substr(10); > VERIFY( str02 =3D=3D "pacifica" ); > > +#if __STDC_HOSTED__ > try > { > str02 =3D 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/w= char_t.cc > b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/substr/w= char_t.cc > index dbe1745c89d..a02a61c9b4c 100644 > --- > a/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/substr/w= char_t.cc > +++ > b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/substr/w= char_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 =3D str01.substr(10); > VERIFY( str02 =3D=3D L"pacifica" ); > > +#if __STDC_HOSTED__ > try > { > str02 =3D str01.substr(csz01 + 1); > @@ -68,6 +72,7 @@ test01() > { > VERIFY( false ); > } > +#endif // HOSTED > } > > int > -- > 2.39.0 > > --00000000000021994305f1e9b556--