From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 28DA7385E44A for ; Wed, 14 Jul 2021 11:24:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 28DA7385E44A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-600-_E6PEcVlNvqkErQe1XLviA-1; Wed, 14 Jul 2021 07:24:08 -0400 X-MC-Unique: _E6PEcVlNvqkErQe1XLviA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0A6978042FE; Wed, 14 Jul 2021 11:24:08 +0000 (UTC) Received: from localhost (unknown [10.33.37.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F946106F940; Wed, 14 Jul 2021 11:24:07 +0000 (UTC) Date: Wed, 14 Jul 2021 12:24:06 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add noexcept-specifier to basic_string_view(It, End) Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="Ur/4nrtasAner4rl" Content-Disposition: inline X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Jul 2021 11:24:13 -0000 --Ur/4nrtasAner4rl Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 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. Tested powerpc64le-linux. Committed to trunk. --Ur/4nrtasAner4rl Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" commit f9c2ce1dae270d8d5dc261a57a21f96a1da5ea2d Author: Jonathan Wakely Date: Wed Jul 14 11:03:17 2021 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 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. 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 // . -// { dg-options "-std=gnu++2a" } -// { dg-do run { target c++2a } } +// { dg-options "-std=gnu++20" } +// { dg-do run { target c++20 } } #include #include #include +#include constexpr char str[] = "abcdefg"; -constexpr std::basic_string_view s(std::begin(str), std::cend(str) - 1); +constexpr std::basic_string_view 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(str, str)) ); +using I = __gnu_test::contiguous_iterator_wrapper; +static_assert( ! noexcept(std::basic_string_view(I{}, I{})) ); void test01() { std::vector v{'a', 'b', 'c'}; - std::basic_string_view s(v.begin(), v.end()); + 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 ); } int --Ur/4nrtasAner4rl--