From patchwork Tue Sep 3 15:18:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1980105 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=g5tHI++9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wyq7z5rPPz1yg9 for ; Wed, 4 Sep 2024 01:20:47 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9C881384F01B for ; Tue, 3 Sep 2024 15:20:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 682D9385840D for ; Tue, 3 Sep 2024 15:19:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 682D9385840D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 682D9385840D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725376771; cv=none; b=l9bf39ZP9zyFr9CHw1x6sfYjiB8k5yuNNoH+o7NEX722fc8ulWzVFRPyrUsMNLCCFp+FLuT5mk24YIze+dXbOSezZlTvilJsqjwFEEY5ft/94f9dui0NurRmFQ2B1z1dDPeR85HViA/xx3P59YszmWQDMfvdOUgEDs+abdqULaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725376771; c=relaxed/simple; bh=OxAeFm3nSW5UWe2AR6DCb82kDhYRK7YgXJtk4Zs1/88=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tHGdYVAd93nYW7xc3gBw4j0CLvRa7mTUs3G/Y1b/sWp7m+C4ipO+zv4hylIXCHzEUoINxa8/0f852ChDxdURN6FqYQ0L+UK+g5wfKAZV2g9WspY/PLWgVF/pkiNwBD344u73/vaa3KrT4FnCSXUEZeJlnSOjz6owwNE8LZ58BbQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725376762; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=D+N+FV5o1XN8m8qm5uadAv4aetUbzYv6jjLEDeL6OHc=; b=g5tHI++9eEQCGGrzshub7P9RHlgjsJkTq4oUSygaAHzh1SGLh6IaBQVBr+KolGaDcgq8NM v+OUVLMUhLjCZd0rAwQ47fvkhg6SMqp3GzAvlUyLsZvAY1yEQCiTVOAf5x3sbfE0Z3D2C7 4KlOtqS2H2kNr6Stl8YlTckVm9/8QjM= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-694-EKcYiC29O6OFNHld2OTnow-1; Tue, 03 Sep 2024 11:19:18 -0400 X-MC-Unique: EKcYiC29O6OFNHld2OTnow-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B95FD18BC72F; Tue, 3 Sep 2024 15:19:17 +0000 (UTC) Received: from localhost (unknown [10.42.28.101]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EA59B1955F1B; Tue, 3 Sep 2024 15:19:15 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Specialize std::disable_sized_sentinel_for for std::move_iterator [PR116549] Date: Tue, 3 Sep 2024 16:18:55 +0100 Message-ID: <20240903151914.2701791-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.5 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, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. Pushed to trunk. -- >8 -- LWG 3736 added a partial specialization of this variable template for two std::move_iterator types. This is needed for the case where the types satisfy std::sentinel_for and are subtractable, but do not model the semantics requirements of std::sized_sentinel_for. libstdc++-v3/ChangeLog: PR libstdc++/116549 * include/bits/stl_iterator.h (disable_sized_sentinel_for): Define specialization for two move_iterator types, as per LWG 3736. * testsuite/24_iterators/move_iterator/lwg3736.cc: New test. --- libstdc++-v3/include/bits/stl_iterator.h | 8 +++ .../24_iterators/move_iterator/lwg3736.cc | 52 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3736.cc diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index d3823057270..20c0319f3a7 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -1822,6 +1822,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return _ReturnType(__i); } #if __cplusplus > 201703L && __glibcxx_concepts + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3736. move_iterator missing disable_sized_sentinel_for specialization + template + requires (!sized_sentinel_for<_Iterator1, _Iterator2>) + inline constexpr bool + disable_sized_sentinel_for, + move_iterator<_Iterator2>> = true; + // [iterators.common] Common iterators namespace __detail diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3736.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3736.cc new file mode 100644 index 00000000000..eaf791b3089 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3736.cc @@ -0,0 +1,52 @@ +// { dg-do compile { target c++20 } } + +// 3736. move_iterator missing disable_sized_sentinel_for specialization + +#include + +template using MoveIter = std::move_iterator; + +using std::sized_sentinel_for; +using std::disable_sized_sentinel_for; + +// These assertions always passed, even without LWG 3736: +static_assert(sized_sentinel_for, MoveIter>); +static_assert(sized_sentinel_for, MoveIter>); +static_assert(not sized_sentinel_for, MoveIter>); +static_assert(not sized_sentinel_for, std::default_sentinel_t>); +static_assert(not disable_sized_sentinel_for, MoveIter>); + +// These types don't satisfy sized_sentinel_for anyway (because the subtraction +// is ill-formed) but LWG 3736 makes the variable template explicitly false: +static_assert(disable_sized_sentinel_for, MoveIter>); + +struct Iter +{ + using iterator_category = std::random_access_iterator_tag; + using value_type = int; + using pointer = int*; + using reference = int&; + using difference_type = long; + + Iter() = default; + Iter& operator++(); + Iter operator++(int); + Iter& operator--(); + Iter operator--(int); + reference operator*() const; + pointer operator->() const; + Iter& operator+=(difference_type); + Iter& operator-=(difference_type); + friend Iter operator+(Iter, difference_type); + friend Iter operator+(difference_type, Iter); + friend Iter operator-(Iter, difference_type); + friend difference_type operator-(Iter, Iter); + bool operator==(Iter) const; +}; + +// Specialize the variable template so that Iter is not its own sized sentinel: +template<> constexpr bool std::disable_sized_sentinel_for = true; +static_assert( not sized_sentinel_for ); + +// LWG 3736 means that affects std::move_iterator as well: +static_assert( not sized_sentinel_for, MoveIter> );