From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id D7A0C385840D; Mon, 18 Mar 2024 14:05:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D7A0C385840D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1710770743; bh=XQsASREftvfYWUySZvk894NkkYh5DzYK2f9TYlp0f/w=; h=From:To:Subject:Date:From; b=MKM8k5PlwbOyVnBVfmHDusJPqhPFjwZxdU3xzwpwXUWwozKSrnXZdK08fb8j82/W7 mz2kL1AX31KIqiN4yD3dJSN8rPi/JNt9YN/uTNrjVPLcNI+WJv1RfOixeL75bk9I7n 2Dp90MXTEY7/TwgBnhhhrYKtTWq93l5LnJGGp3qk= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-10248] libstdc++: Add allocator-extended constructors to std::match_results (LWG 2195) X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: ec9735922b6f28cf704c8a7850a34aed82675b91 X-Git-Newrev: 3d7dc8f0ae9ee812f142556a3e827cd5ea115748 Message-Id: <20240318140543.D7A0C385840D@sourceware.org> Date: Mon, 18 Mar 2024 14:05:42 +0000 (GMT) List-Id: https://gcc.gnu.org/g:3d7dc8f0ae9ee812f142556a3e827cd5ea115748 commit r12-10248-g3d7dc8f0ae9ee812f142556a3e827cd5ea115748 Author: Jonathan Wakely Date: Wed Mar 22 11:36:06 2023 +0000 libstdc++: Add allocator-extended constructors to std::match_results (LWG 2195) This was approved in Issaquah last month. libstdc++-v3/ChangeLog: * include/bits/regex.h (match_results): Add allocator-extended copy and move constructors, as per LWG 2195. * testsuite/28_regex/match_results/ctors/char/alloc.cc: New test. (cherry picked from commit 9ae1108196ed65647846a7c06052317e8fa4852d) Diff: --- libstdc++-v3/include/bits/regex.h | 10 ++++ .../28_regex/match_results/ctors/char/alloc.cc | 56 ++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/libstdc++-v3/include/bits/regex.h b/libstdc++-v3/include/bits/regex.h index 097ebf5a266..04dad2c663a 100644 --- a/libstdc++-v3/include/bits/regex.h +++ b/libstdc++-v3/include/bits/regex.h @@ -1807,6 +1807,16 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 */ ~match_results() = default; + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2195. Missing constructors for match_results + + match_results(const match_results& __m, const _Alloc& __a) + : _Base_type(__m, __a) { } + + match_results(match_results&& __m, const _Alloc& __a) + noexcept(noexcept(_Base_type(std::move(__m), __a))) + : _Base_type(std::move(__m), __a) { } + ///@} // 28.10.2, state: diff --git a/libstdc++-v3/testsuite/28_regex/match_results/ctors/char/alloc.cc b/libstdc++-v3/testsuite/28_regex/match_results/ctors/char/alloc.cc new file mode 100644 index 00000000000..bb5e7a91bd7 --- /dev/null +++ b/libstdc++-v3/testsuite/28_regex/match_results/ctors/char/alloc.cc @@ -0,0 +1,56 @@ +// { dg-do run { target c++11 } } + +#include +#include +#include + +// LWG 2195. Missing constructors for match_results + +void +test01() +{ + using Alloc = std::cmatch::allocator_type; + std::cmatch m1; + std::cmatch m2(m1, m1.get_allocator()); + VERIFY( m2 == m1 ); + + static_assert( ! std::is_nothrow_constructible(), + "Allocator-extended copy ctor is potentially-throwing" ); + + std::cmatch m3(std::move(m1), m2.get_allocator()); + VERIFY( m3 == m2 ); + + // Libstdc++ extension: + static_assert( std::is_nothrow_constructible(), + "Allocator-extended move ctor is non-throwing" ); +} + +void +test02() +{ + using Alloc = __gnu_test::uneq_allocator; + using MR = std::match_results; + + MR m1(Alloc(1)); + MR m2(m1, Alloc(2)); + VERIFY( m2 == m1 ); + + static_assert( ! std::is_nothrow_constructible(), + "Allocator-extended copy ctor is potentially-throwing" ); + + MR m3(std::move(m1), Alloc(3)); + VERIFY( m3 == m2 ); + + static_assert( ! std::is_nothrow_constructible(), + "Allocator-extended move ctor is potentially-throwing" ); +} + +int main() +{ + test01(); + test02(); +}