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 ESMTPS id 390E93858C52 for ; Wed, 20 Jul 2022 23:00:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 390E93858C52 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-458-BqNoneFfMNyVnzDiXNAj0Q-1; Wed, 20 Jul 2022 19:00:14 -0400 X-MC-Unique: BqNoneFfMNyVnzDiXNAj0Q-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A86CC185A7BA; Wed, 20 Jul 2022 23:00:13 +0000 (UTC) Received: from localhost (unknown [10.33.36.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7565F492C3B; Wed, 20 Jul 2022 23:00:13 +0000 (UTC) From: Jonathan Wakely 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 Message-Id: <20220720230011.2732391-3-jwakely@redhat.com> In-Reply-To: <20220720230011.2732391-1-jwakely@redhat.com> References: <20220720230011.2732391-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, URI_HEX autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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, 20 Jul 2022 23:00:24 -0000 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()) + 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 #include +void +test_triviality() +{ + using I = std::common_iterator; + + // Cannot be trivial, because it has to initialize members. + static_assert( ! std::is_trivially_default_constructible_v ); + + static_assert( std::is_trivially_destructible_v ); + static_assert( std::is_trivially_copy_constructible_v ); + static_assert( std::is_trivially_copy_assignable_v ); + static_assert( std::is_trivially_move_constructible_v ); + static_assert( std::is_trivially_move_assignable_v ); +} + void test_valueless_assignment() { -- 2.34.3