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 r13-7009] libstdc++: Define std::sub_match::swap member function (LWG 3204) Date: Wed, 5 Apr 2023 11:24:03 +0000 (GMT) [thread overview] Message-ID: <20230405112403.AB8D13858D20@sourceware.org> (raw) https://gcc.gnu.org/g:44e17b8d8999a658af9f86681504d74a119a5f6f commit r13-7009-g44e17b8d8999a658af9f86681504d74a119a5f6f Author: Jonathan Wakely <jwakely@redhat.com> Date: Tue Apr 4 20:28:59 2023 +0100 libstdc++: Define std::sub_match::swap member function (LWG 3204) This was approved at the C++ meeting in February. libstdc++-v3/ChangeLog: * include/bits/regex.h (sub_match::swap): New function. * testsuite/28_regex/sub_match/lwg3204.cc: New test. Diff: --- libstdc++-v3/include/bits/regex.h | 10 ++++++ .../testsuite/28_regex/sub_match/lwg3204.cc | 38 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/libstdc++-v3/include/bits/regex.h b/libstdc++-v3/include/bits/regex.h index 79903fad1e5..26ac6a21c31 100644 --- a/libstdc++-v3/include/bits/regex.h +++ b/libstdc++-v3/include/bits/regex.h @@ -1006,6 +1006,16 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 { return this->_M_str().compare({__s, __n}); } /// @endcond + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3204. sub_match::swap only swaps the base class + /// Swap the values of two sub_match objects. + void + swap(sub_match& __s) noexcept(__is_nothrow_swappable<_BiIter>::value) + { + this->pair<_BiIter, _BiIter>::swap(__s); + std::swap(matched, __s.matched); + } + private: // Simplified basic_string_view for C++11 struct __string_view diff --git a/libstdc++-v3/testsuite/28_regex/sub_match/lwg3204.cc b/libstdc++-v3/testsuite/28_regex/sub_match/lwg3204.cc new file mode 100644 index 00000000000..58ef0df58a1 --- /dev/null +++ b/libstdc++-v3/testsuite/28_regex/sub_match/lwg3204.cc @@ -0,0 +1,38 @@ +// { dg-do run { target c++11 } } +#include <regex> +#include <testsuite_hooks.h> + +// LWG 3204. sub_match::swap only swaps the base class + +int main() +{ + std::sub_match<const char*> a, b; + a.matched = true; + a.swap(b); + VERIFY( ! a.matched ); + VERIFY( b.matched ); +} + +struct iter +{ + using value_type = char; + using difference_type = long; + using pointer = const char*; + using reference = const char&; + using iterator_category = std::bidirectional_iterator_tag; + + iter(); + iter(const iter&) noexcept(false); + + iter& operator++(); + iter operator++(int); + iter& operator--(); + iter operator--(int); + reference operator*() const; + pointer operator->() const; +}; + +using CS = std::csub_match; +static_assert( noexcept(std::declval<CS&>().swap(std::declval<CS&>())) ); +using IS = std::sub_match<iter>; +static_assert( ! noexcept(std::declval<IS&>().swap(std::declval<IS&>())) );
reply other threads:[~2023-04-05 11:24 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=20230405112403.AB8D13858D20@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).