From patchwork Mon Oct 10 11:20:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1857 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1524693wrs; Mon, 10 Oct 2022 04:21:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7ZY6Fq6fO0Uqats9uRw+SdXUsCiku1TXQr5TKAHz2a1M3DHR9FLSXeNGuAbk+InZEFkgPC X-Received: by 2002:a17:907:75e5:b0:78d:cb12:6dcc with SMTP id jz5-20020a17090775e500b0078dcb126dccmr1298936ejc.550.1665400912191; Mon, 10 Oct 2022 04:21:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665400912; cv=none; d=google.com; s=arc-20160816; b=XviedNj3SEsej2jS+y0k7hueiS2tHlMz5OJHjihqXmFAylCvxlX1icfSKjyTDEyO8z A0LuNPcbNm5Fwqb3TNHIPsxZM3q09lZIGWDon0GtZ/NruERPc47f7ZtzFr97LIxp4ebR o8uimlMWRDKB0nLNhQKAzjdpMipzK2DuaA6CyFuIc5zRifFz2dad7atbInz28giAKXRY 13rvvoxpIR87Diecx7/Wl/k50rmw+nz4ZFSOOS+dfPlOtX5oRmtkkyDixiMTI0onf2LC RCbWT7W47xJhnVbvrrtqxjTKFWAb/PwytKrtli7Kks6gxjs1GR6gGlZphC9FjPutiwJr a9pg== 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=pUIP8isJkHwAxS9ld8xCsg3SqpSSopBhttWudmIOsZY=; b=UaMvWWu9KZDi1t8nfaFrsCQUXYGoj4n3mCDiJvvaKbLakwT3VZQ/LqRpOXyIqz+U+q w1Qf2JaVGlabDR/WklwUifQmYah/cM38DDq1NgBoYYq0h9B3ZewNedp1lggqeY7Qqnvr tMEbgqZ1/6e2EpVglHAO7L8KIHhZQ5eniB6R8a/+/RWpaqePgYA9ZEweyXqodJT6kiHT +Pvhao0FW28bPBBOacz0l4cZ/r2JC1YwU+ZWwDZazLVMrAO2YjJ5tx1OBTyNwVSlb+mo hB3bCd7rU7y+VelR0fHjxYPS44iMeX9BFtvf1LBPK3S1jIvTXmhYT4u1vn640tfbaQZc 3mcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=O6YJXKCc; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id hq29-20020a1709073f1d00b0077979f8d3dbsi12457536ejc.838.2022.10.10.04.21.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 04:21:52 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=O6YJXKCc; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 467E43854830 for ; Mon, 10 Oct 2022 11:20:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 467E43854830 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665400854; bh=pUIP8isJkHwAxS9ld8xCsg3SqpSSopBhttWudmIOsZY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=O6YJXKCcdMGjasz8mEvaETKoxCLJfrp1PS3Q/htNG3vqu28q2KQPKqZiDTCNwrKvY PdC+5xOaNkl0nkNbeJ2Yjkg95g2JBiECoZw5Cg/hx08tXbzCG0eAJQkJMMXoO/ZzBE 4GAzpJIDYI+j7Wlv6ZOEJU3t8/NwRRq8klXGMPbE= 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 E45253857C4A for ; Mon, 10 Oct 2022 11:20:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E45253857C4A 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-192-MkQNTrhpNLWkKoDHb3eJqg-1; Mon, 10 Oct 2022 07:20:06 -0400 X-MC-Unique: MkQNTrhpNLWkKoDHb3eJqg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 38AC585A59D; Mon, 10 Oct 2022 11:20:06 +0000 (UTC) Received: from localhost (unknown [10.33.36.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2792112D16C; Mon, 10 Oct 2022 11:20:05 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: std::make_signed_t should be ill-formed Date: Mon, 10 Oct 2022 12:20:05 +0100 Message-Id: <20221010112005.1523979-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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, KAM_SHORT, 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?1746299426710211138?= X-GMAIL-MSGID: =?utf-8?q?1746299426710211138?= Tested powerpc64le-linux. Pushed to trunk. -- >8 -- Currently we only reject std::make_signed_t but not cv bool. Similarly for std::make_unsigned_t. As well as making those ill-formed, this adds a requires-clause to the make_signed and make_unsigned primary templates. This makes non-integral, non-enum cases fail immediately with a clear error, rather than giving an error about __make_signed_selector being incomplete. libstdc++-v3/ChangeLog: * include/std/type_traits (make_signed, make_unsigned): Add specializations for cv bool. Add requires-clause for C++20 to improve diagnostics for non-integral, non-enum cases. * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Check cv bool. * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Likewise. * testsuite/24_iterators/range_access/range_access_cpp20_neg.cc: Adjust expected errors for C++20 and later. * testsuite/lib/prune.exp: Prune "in requirements [with ...]" lines from diagnostics. --- libstdc++-v3/include/std/type_traits | 18 ++++++++++--- .../make_signed/requirements/typedefs_neg.cc | 27 +++++++++---------- .../requirements/typedefs_neg.cc | 25 ++++++++--------- .../range_access/range_access_cpp20_neg.cc | 3 ++- libstdc++-v3/testsuite/lib/prune.exp | 1 + 5 files changed, 40 insertions(+), 34 deletions(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index b74565eb521..6108b98aa6a 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -1802,12 +1802,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Primary template. /// make_unsigned template +#if __cpp_concepts + requires is_integral<_Tp>::value || __is_enum(_Tp) +#endif struct make_unsigned { typedef typename __make_unsigned_selector<_Tp>::__type type; }; // Integral, but don't define. - template<> - struct make_unsigned; + template<> struct make_unsigned; + template<> struct make_unsigned; + template<> struct make_unsigned; + template<> struct make_unsigned; /// @cond undocumented @@ -1932,12 +1937,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Primary template. /// make_signed template +#if __cpp_concepts + requires is_integral<_Tp>::value || __is_enum(_Tp) +#endif struct make_signed { typedef typename __make_signed_selector<_Tp>::__type type; }; // Integral, but don't define. - template<> - struct make_signed; + template<> struct make_signed; + template<> struct make_signed; + template<> struct make_signed; + template<> struct make_signed; #if __cplusplus > 201103L /// Alias template for make_signed diff --git a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc index 051bb64c710..88b8ae887ef 100644 --- a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc +++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc @@ -20,31 +20,28 @@ // . #include -#include -enum test_enum { first_selection }; +struct pod_class { }; void test01() { using std::make_signed; // Negative tests. - typedef make_signed::type test1_type; + using T1 = make_signed::type; // { dg-error "incomplete" } + using T2 = make_signed::type; // { dg-error "incomplete" } + using T3 = make_signed::type; // { dg-error "incomplete" } + using T4 = make_signed::type; // { dg-error "incomplete" } - typedef make_signed<__gnu_test::pod_uint>::type test2_type; + using T5 = make_signed::type; // { dg-error "here" } - typedef make_signed::type test3_type; + using T6 = make_signed::type; // { dg-error "here" } - typedef void (fn_type) (); - typedef make_signed::type test4_type; + using fn_type = void (); + using T7 = make_signed::type; // { dg-error "here" } - typedef make_signed::type test5_type; + using T8 = make_signed::type; // { dg-error "here" } } -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 32 } -// { dg-error "required from here" "" { target *-*-* } 34 } -// { dg-error "required from here" "" { target *-*-* } 36 } -// { dg-error "required from here" "" { target *-*-* } 39 } -// { dg-error "required from here" "" { target *-*-* } 41 } - -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 0 } +// { dg-error "invalid use of incomplete type" "" { target c++17_down } 0 } +// { dg-error "constraint failure" "" { target c++20 } 0 } diff --git a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc index ff98cc42ef7..50f15e7037c 100644 --- a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc +++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc @@ -21,7 +21,6 @@ #include -enum test_enum { first_selection }; struct pod_class { }; void test01() @@ -29,22 +28,20 @@ void test01() using std::make_unsigned; // Negative tests. - typedef make_unsigned::type test1_type; + using T1 = make_unsigned::type; // { dg-error "incomplete" } + using T2 = make_unsigned::type; // { dg-error "incomplete" } + using T3 = make_unsigned::type; // { dg-error "incomplete" } + using T4 = make_unsigned::type; // { dg-error "incomplete" } - typedef make_unsigned::type test2_type; + using T5 = make_unsigned::type; // { dg-error "here" } - typedef make_unsigned::type test3_type; + using T6 = make_unsigned::type; // { dg-error "here" } - typedef void (fn_type) (); - typedef make_unsigned::type test4_type; + using fn_type = void (); + using T7 = make_unsigned::type; // { dg-error "here" } - typedef make_unsigned::type test5_type; + using T8 = make_unsigned::type; // { dg-error "here" } } -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 32 } -// { dg-error "required from here" "" { target *-*-* } 34 } -// { dg-error "required from here" "" { target *-*-* } 36 } -// { dg-error "required from here" "" { target *-*-* } 39 } -// { dg-error "required from here" "" { target *-*-* } 41 } - -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 0 } +// { dg-error "invalid use of incomplete type" "" { target c++17_down } 0 } +// { dg-error "constraint failure" "" { target c++20 } 0 } diff --git a/libstdc++-v3/testsuite/24_iterators/range_access/range_access_cpp20_neg.cc b/libstdc++-v3/testsuite/24_iterators/range_access/range_access_cpp20_neg.cc index c0825a58587..26c8ae0ee1e 100644 --- a/libstdc++-v3/testsuite/24_iterators/range_access/range_access_cpp20_neg.cc +++ b/libstdc++-v3/testsuite/24_iterators/range_access/range_access_cpp20_neg.cc @@ -46,4 +46,5 @@ test03() C c; std::ssize(c); // { dg-error "no matching function" } } -// { dg-error "incomplete type .*make_signed.*S" "" { target *-*-* } 0 } +// { dg-error "incomplete type .*make_signed.*S" "" { target c++17_down } 0 } +// { dg-error "constraint failure" "" { target c++20 } 0 } diff --git a/libstdc++-v3/testsuite/lib/prune.exp b/libstdc++-v3/testsuite/lib/prune.exp index d457e975218..6d0b77a8ccd 100644 --- a/libstdc++-v3/testsuite/lib/prune.exp +++ b/libstdc++-v3/testsuite/lib/prune.exp @@ -51,6 +51,7 @@ proc libstdc++-dg-prune { system text } { regsub -all "(^|\n)\[^\n\]*: (recursively )?required \[^\n\]*" $text "" text regsub -all "(^|\n)\[^\n\]*: . skipping \[0-9\]* instantiation contexts \[^\n\]*" $text "" text regsub -all "(^|\n)\[^\n\]*: in .constexpr. expansion \[^\n\]*" $text "" text + regsub -all "(^|\n)\[^\n\]*: in requirements .with\[^\n\]*" $text "" text regsub -all "(^|\n) inlined from \[^\n\]*" $text "" text # Why doesn't GCC need these to strip header context? regsub -all "(^|\n)In file included from \[^\n\]*" $text "" text