diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2023-03-22 11:36:06 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2023-03-22 17:48:19 +0000 |
commit | 9ae1108196ed65647846a7c06052317e8fa4852d (patch) | |
tree | 5957b4014e2afc2e7d7f132c3b9dfeddaf55de82 /libstdc++-v3/testsuite/28_regex | |
parent | ad0b9cf1a076fb9a802d9ba7fa2223aa3166dca2 (diff) | |
download | gcc-9ae1108196ed65647846a7c06052317e8fa4852d.zip gcc-9ae1108196ed65647846a7c06052317e8fa4852d.tar.gz gcc-9ae1108196ed65647846a7c06052317e8fa4852d.tar.bz2 |
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.
Diffstat (limited to 'libstdc++-v3/testsuite/28_regex')
-rw-r--r-- | libstdc++-v3/testsuite/28_regex/match_results/ctors/char/alloc.cc | 56 |
1 files changed, 56 insertions, 0 deletions
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 0000000..bb5e7a9 --- /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 <regex> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// 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<std::cmatch, + const std::cmatch&, + const Alloc&>(), + "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<std::cmatch, + std::cmatch, + const Alloc&>(), + "Allocator-extended move ctor is non-throwing" ); +} + +void +test02() +{ + using Alloc = __gnu_test::uneq_allocator<std::csub_match>; + using MR = std::match_results<const char*, Alloc>; + + MR m1(Alloc(1)); + MR m2(m1, Alloc(2)); + VERIFY( m2 == m1 ); + + static_assert( ! std::is_nothrow_constructible<MR, const MR&, const Alloc&>(), + "Allocator-extended copy ctor is potentially-throwing" ); + + MR m3(std::move(m1), Alloc(3)); + VERIFY( m3 == m2 ); + + static_assert( ! std::is_nothrow_constructible<MR, MR, const Alloc&>(), + "Allocator-extended move ctor is potentially-throwing" ); +} + +int main() +{ + test01(); + test02(); +} |