From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed 3/3] libstdc++: Fix std::common_iterator triviality [PR100823]
Date: Thu, 21 Jul 2022 00:00:11 +0100 [thread overview]
Message-ID: <20220720230011.2732391-3-jwakely@redhat.com> (raw)
In-Reply-To: <20220720230011.2732391-1-jwakely@redhat.com>
Tested powerpc64le-linux, pushed to trunk.
-- >8 --
This fixes the remaining problem reported in the PR, that the special
members should be trivial. This can be done by constraining the
non-trivial versions and adding defaulted overloads that will be used
when the union members are trivial.
Making these members trivial alters the argument passing ABI and so
isn't suitable for backporting to release branches.
libstdc++-v3/ChangeLog:
PR libstdc++/100823
* include/bits/stl_iterator.h (common_iterator): Define
destructor, copy constructor and move constructor as trivial
when the underlying types allow.
* testsuite/24_iterators/common_iterator/100823.cc: Check
triviality of special members.
---
libstdc++-v3/include/bits/stl_iterator.h | 15 +++++++++++++++
.../24_iterators/common_iterator/100823.cc | 15 +++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h
index a913c04deaa..9cd262cd1d9 100644
--- a/libstdc++-v3/include/bits/stl_iterator.h
+++ b/libstdc++-v3/include/bits/stl_iterator.h
@@ -1925,9 +1925,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
}
+ common_iterator(const common_iterator&) = default;
+
constexpr
common_iterator(const common_iterator& __x)
noexcept(_S_noexcept<const _It&, const _Sent&>())
+ requires (!is_trivially_copyable_v<_It> || !is_trivially_copyable_v<_Sent>)
: _M_valueless(), _M_index(__x._M_index)
{
if (_M_index == 0)
@@ -1946,9 +1949,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
}
+ common_iterator(common_iterator&&) = default;
+
constexpr
common_iterator(common_iterator&& __x)
noexcept(_S_noexcept<_It, _Sent>())
+ requires (!is_trivially_copyable_v<_It> || !is_trivially_copyable_v<_Sent>)
: _M_valueless(), _M_index(__x._M_index)
{
if (_M_index == 0)
@@ -2017,8 +2023,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return *this;
}
+#if __cpp_concepts >= 202002L // Constrained special member functions
+ ~common_iterator() = default;
+
constexpr
~common_iterator()
+ requires (!is_trivially_destructible_v<_It>
+ || !is_trivially_destructible_v<_Sent>)
+#else
+ constexpr
+ ~common_iterator()
+#endif
{
if (_M_index == 0)
_M_it.~_It();
diff --git a/libstdc++-v3/testsuite/24_iterators/common_iterator/100823.cc b/libstdc++-v3/testsuite/24_iterators/common_iterator/100823.cc
index 4f2b23de8cc..b42dd087ab2 100644
--- a/libstdc++-v3/testsuite/24_iterators/common_iterator/100823.cc
+++ b/libstdc++-v3/testsuite/24_iterators/common_iterator/100823.cc
@@ -4,6 +4,21 @@
#include <testsuite_iterators.h>
#include <testsuite_hooks.h>
+void
+test_triviality()
+{
+ using I = std::common_iterator<int*, const int*>;
+
+ // Cannot be trivial, because it has to initialize members.
+ static_assert( ! std::is_trivially_default_constructible_v<I> );
+
+ static_assert( std::is_trivially_destructible_v<I> );
+ static_assert( std::is_trivially_copy_constructible_v<I> );
+ static_assert( std::is_trivially_copy_assignable_v<I> );
+ static_assert( std::is_trivially_move_constructible_v<I> );
+ static_assert( std::is_trivially_move_assignable_v<I> );
+}
+
void
test_valueless_assignment()
{
--
2.34.3
prev parent reply other threads:[~2022-07-20 23:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-20 23:00 [committed 1/3] libstdc++: Fix minor bugs in std::common_iterator Jonathan Wakely
2022-07-20 23:00 ` [committed 2/3] libstdc++: Fix std::common_iterator assignment [PR100823] Jonathan Wakely
2022-07-20 23:00 ` Jonathan Wakely [this message]
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=20220720230011.2732391-3-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@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: link
Be 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).