public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-9148] libstdc++: Add noexcept-specifier to basic_string_view(It, End) Date: Wed, 13 Oct 2021 20:54:35 +0000 (GMT) [thread overview] Message-ID: <20211013205435.D97DF385841D@sourceware.org> (raw) https://gcc.gnu.org/g:3eac45a2a13b959166806f132aea756026c9b8cb commit r11-9148-g3eac45a2a13b959166806f132aea756026c9b8cb Author: Jonathan Wakely <jwakely@redhat.com> Date: Wed Jul 14 11:03:17 2021 +0100 libstdc++: Add noexcept-specifier to basic_string_view(It, End) This adds a conditional noexcept to the C++20 constructor. The std::to_address call cannot throw, so only taking the difference of the two iterators can throw. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * include/std/string_view (basic_string_view(It, End)): Add noexcept-specifier. * testsuite/21_strings/basic_string_view/cons/char/range.cc: Check noexcept-specifier. Also check construction without CTAD. (cherry picked from commit f9c2ce1dae270d8d5dc261a57a21f96a1da5ea2d) Diff: --- libstdc++-v3/include/std/string_view | 1 + .../21_strings/basic_string_view/cons/char/range.cc | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view index 4ea72c6cef2..d8cbee9bee0 100644 --- a/libstdc++-v3/include/std/string_view +++ b/libstdc++-v3/include/std/string_view @@ -144,6 +144,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION && (!convertible_to<_End, size_type>) constexpr basic_string_view(_It __first, _End __last) + noexcept(noexcept(__last - __first)) : _M_len(__last - __first), _M_str(std::to_address(__first)) { } 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 39fcaf52925..7376e2fa3f4 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 @@ -15,24 +15,34 @@ // with this library; see the file COPYING3. If not see // <http://www.gnu.org/licenses/>. -// { dg-options "-std=gnu++2a" } -// { dg-do run { target c++2a } } +// { dg-options "-std=gnu++20" } +// { dg-do run { target c++20 } } #include <string_view> #include <vector> #include <testsuite_hooks.h> +#include <testsuite_iterators.h> constexpr char str[] = "abcdefg"; -constexpr std::basic_string_view s(std::begin(str), std::cend(str) - 1); +constexpr std::basic_string_view<char> s(std::begin(str), std::cend(str) - 1); static_assert( s == str ); static_assert( s.data() == str ); +constexpr std::basic_string_view ctad(std::begin(str), std::cend(str) - 1); +static_assert( ctad == s ); + +// The standard does not require this constructor to have a noexcept-specifier. +static_assert( noexcept(std::basic_string_view<char>(str, str)) ); +using I = __gnu_test::contiguous_iterator_wrapper<char>; +static_assert( ! noexcept(std::basic_string_view<char>(I{}, I{})) ); void test01() { std::vector<char> v{'a', 'b', 'c'}; - std::basic_string_view s(v.begin(), v.end()); + std::basic_string_view<char> s(v.begin(), v.end()); VERIFY( s.data() == v.data() ); + std::basic_string_view ctad(v.begin(), v.end()); + VERIFY( ctad == s ); } int
reply other threads:[~2021-10-13 20:54 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211013205435.D97DF385841D@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).