From patchwork Mon Sep 26 22:49:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1476 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp45012wrt; Mon, 26 Sep 2022 15:50:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4fpxvNPQiV5bEIL5QrBgHOcKsqG3iKsWJ/ZRu1+4AQwDCPUaHesWyBUQvvw53IC+css2Hy X-Received: by 2002:a17:907:2c74:b0:77d:5a0e:bb8f with SMTP id ib20-20020a1709072c7400b0077d5a0ebb8fmr19552269ejc.579.1664232637274; Mon, 26 Sep 2022 15:50:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664232637; cv=none; d=google.com; s=arc-20160816; b=uK2awG3xbSGLse5qy/00FeVVt2uNIBDwiquzKy4uRH44Ik5Z7ZFH9lwEIrPawD8ee+ lNN1UzXe5c02M1h+bTvxmbErZ61/Jy68VbvBHCIfq6o5oR2QKz9Xz8zB1Vuxsg3L+dJR ZA3lVHDZ2Xe1IZNapgzzlEUmV0+CPz9RupLs0PVHED6j3xY5Gs84C5Z0efl3c6NtWjmg AKkcLc40bfe+jvItF1h90bGCCO4wXIlyZAEsBTJxSEWZsIyjYQyrXePXIf7K/O1yBSkU NqBVrX8PSjyxn7aeHCo4jHsxM9he8dp0U82FFB7V1m/UyzV3+kcgO2I5Fk2Y2t+9r7Qb SuPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=cXYQsWsppyH22M7EF9zYf/VZaW5JcaFs0qShQRD1uW4=; b=rjqLzFhxOPVMzBiM38n0ddiw1PGPFlfqqEbspB0b/sk1xgVN+651SYF9ldyLWcsH0o rflkBaYTbRI7Qtu+al5XVz/fD5aPF9KDDvm3YPwBr057ZAvKn41yaNoud7KtLfuyQjex 62XHpgKT7j/Pu+XARWB5PPGEgR4J5LrXKm5wUvVNf3/XhC3mJACaZyZCL15qHhRNh+sh oZZz+sH+6qt0kze4PGg3d10Dtvfcr/yLznkSzrzPLVUQNzZn6p8Q4QzLFuMiN8JeouAD yIq0zXVkdd9HEqiqLKRvgLtwHWn5uWv3hSJNqDDcSeDAn8vnBsUWs03R64FB0fFq17aW VSyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=csOYqAvv; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id nc5-20020a1709071c0500b0078276be53d5si1369528ejc.0.2022.09.26.15.50.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 15:50:37 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=csOYqAvv; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1DCCB3858C2D for ; Mon, 26 Sep 2022 22:50:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1DCCB3858C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664232602; bh=cXYQsWsppyH22M7EF9zYf/VZaW5JcaFs0qShQRD1uW4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=csOYqAvv/TR8HvPT1bKalTMNCqHQL/QrPsVLUVsPqL5UdGlLnLlCjNs5qwABZhluB M5zXA9/GwSS7Fb6c+yt1nlKnTApPN7EPj++eMcWJkhe7zZUes7YVYvoWT0P/QBHhpG 22v7wgxtD9r2x0PbbX0Oq9tOEPbYZD54tdJ8ifP4= 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 ESMTPS id 01D603858406 for ; Mon, 26 Sep 2022 22:49:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 01D603858406 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-594-6yj1dd9CMN25I-CXtn8d-A-1; Mon, 26 Sep 2022 18:49:11 -0400 X-MC-Unique: 6yj1dd9CMN25I-CXtn8d-A-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 6E79780029D; Mon, 26 Sep 2022 22:49:10 +0000 (UTC) Received: from localhost (unknown [10.33.36.214]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34FC2492B04; Mon, 26 Sep 2022 22:49:10 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Update std::pointer_traits to match new LWG 3545 wording Date: Mon, 26 Sep 2022 23:49:09 +0100 Message-Id: <20220926224909.2235959-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 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 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745074401975295318?= X-GMAIL-MSGID: =?utf-8?q?1745074401975295318?= Tested powerpc64le-linux. Pushed to trunk. -- >8 -- It was pointed out in recent LWG 3545 discussion that having a constrained partial specialization of std::pointer_traits can cause ambiguities with program-defined specializations. For example, the addition to the testcase has: template requires std::derived_from; This would be ambiguous with the library's own constrained partial specialization: template requires requires { typename Ptr::element_type; } struct std::pointer_traits; Neither specialization is more specialized than the other for a type that is derived from base_type and also has an element_type member. The solution is to remove the library's partial specialization, and do the check for Ptr::element_type in the __ptr_traits_elem helper (which is what we already do for !__cpp_concepts anyway). libstdc++-v3/ChangeLog: * include/bits/ptr_traits.h (__ptr_traits_elem) [__cpp_concepts]: Also define the __ptr_traits_elem class template for the concepts case. (pointer_traits): Remove constrained partial specialization. * testsuite/20_util/pointer_traits/lwg3545.cc: Check for ambiguitiy with program-defined partial specialization. --- libstdc++-v3/include/bits/ptr_traits.h | 20 ++++++------------- .../20_util/pointer_traits/lwg3545.cc | 17 ++++++++++++++++ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/libstdc++-v3/include/bits/ptr_traits.h b/libstdc++-v3/include/bits/ptr_traits.h index ae8810706ab..71370ff4fc9 100644 --- a/libstdc++-v3/include/bits/ptr_traits.h +++ b/libstdc++-v3/include/bits/ptr_traits.h @@ -73,25 +73,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __replace_first_arg<_SomeTemplate<_Tp, _Types...>, _Up> { using type = _SomeTemplate<_Up, _Types...>; }; -#if __cpp_concepts - // When concepts are supported detection of _Ptr::element_type is done - // by a requires-clause, so __ptr_traits_elem_t only needs to do this: - template - using __ptr_traits_elem_t = typename __get_first_arg<_Ptr>::type; -#else // Detect the element type of a pointer-like type. template struct __ptr_traits_elem : __get_first_arg<_Ptr> { }; // Use _Ptr::element_type if is a valid type. +#if __cpp_concepts + template requires requires { typename _Ptr::element_type; } + struct __ptr_traits_elem<_Ptr, void> + { using type = typename _Ptr::element_type; }; +#else template struct __ptr_traits_elem<_Ptr, __void_t> { using type = typename _Ptr::element_type; }; +#endif template using __ptr_traits_elem_t = typename __ptr_traits_elem<_Ptr>::type; -#endif /// @endcond @@ -182,13 +181,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct pointer_traits : __ptr_traits_impl<_Ptr, __ptr_traits_elem_t<_Ptr>> { }; -#if __cpp_concepts - template requires requires { typename _Ptr::element_type; } - struct pointer_traits<_Ptr> - : __ptr_traits_impl<_Ptr, typename _Ptr::element_type> - { }; -#endif - /** * @brief Partial specialization for built-in pointers. * @headerfile memory diff --git a/libstdc++-v3/testsuite/20_util/pointer_traits/lwg3545.cc b/libstdc++-v3/testsuite/20_util/pointer_traits/lwg3545.cc index 08c3ed01b75..93c64a353bd 100644 --- a/libstdc++-v3/testsuite/20_util/pointer_traits/lwg3545.cc +++ b/libstdc++-v3/testsuite/20_util/pointer_traits/lwg3545.cc @@ -99,3 +99,20 @@ static_assert( is_same, clever_ptr>::value, "" ); static_assert( is_same, std::ptrdiff_t>::value, "" ); static_assert( is_same, clever_ptr>::value, "" ); static_assert( is_same, clever_ptr>::value, "" ); + +#ifdef __cpp_concepts +struct ptr_base { }; + +// Program-defined specialization must not be ambiguous with primary template. +template requires std::derived_from +struct std::pointer_traits

+{ + using element_type = int; + using difference_type = long; + using pointer = P; +}; + +struct Ptr : ptr_base { using element_type = int; }; + +using E = std::pointer_traits::element_type; +#endif