From patchwork Sun Apr 2 07:53:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 78188 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1621325vqo; Sun, 2 Apr 2023 00:57:43 -0700 (PDT) X-Google-Smtp-Source: AKy350ae0s2RcpmINptFgGIk+k+6BQysseDcBAIQPM6GZ4ygu7ejdvo3bwIJ8qjDf2mve03EdQ/n X-Received: by 2002:a17:907:7fa9:b0:947:791b:fdcb with SMTP id qk41-20020a1709077fa900b00947791bfdcbmr10033255ejc.21.1680422263220; Sun, 02 Apr 2023 00:57:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680422263; cv=none; d=google.com; s=arc-20160816; b=MY4WoBzF67G8AZ5ZS+h7Ca2NTAvRL9pMadqgKdrJg7WP5OGoRbxxzlhYCDnj0Gbc+T L+jYNP4I+xiIwyHQIXVEIv18kVQhaid6uKnIei4O7RyLY4bUzdIj18Wmq4beg7SFrnO6 ZK6RVv8vE5oTeAOdOVvcJ86ff2/JnkwPyrQlHpvjDUFCmoEwrCVhCPFPuLRaX2xyULLE jh0/rr7taKcjSMu+e2U2OQQN7fwhhPBg/op9+9JKHMnCYvcoX5fYWaZdDBlRuaFG81SE S966RvalBqJB6qz+/11OdPhD2hJuyxn2TRkdoQH47arbjNM19rDIqr/azvG4M8Zxg1wu sxRA== 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:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=k5sJeQS2RfmXH9Xm/FQCUyUb86OK11Em0ZX6oU5JQTA=; b=DZIVBTZb3C0mPSa/hymlFwBlC2xvN5w40ly2aZvSZWDh+VKaqltNhA57vszp12Lo3e +v6GK9XIDy0XVxZykGmt98R21IO9DKxqLAcqAslX7gPWnvsw9pXKqUCsN9nnmqlUX8cO eoZPLCXpzVM6NLIT0Ctc33K6zTlnzsKpQLV9hdEbGgbAngNIh6cKZL32zKFgklU9jeD+ Z4iyRP8psMuf9ZPeW9Sva97On5sRq1s5Vs+JPQNH+XU8LL+Z2hEVZMhjq45UJM0x+O5w DZKu9bu8x3kDbsBUgklnuT55CVp2F6qOB7pwk0vDta+oNtpBOygnIrzQ6ukekHGpFjpl FlJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bmI+HwxZ; 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 u13-20020a17090657cd00b0093e842cedb4si2105352ejr.195.2023.04.02.00.57.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Apr 2023 00:57:43 -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=bmI+HwxZ; 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 54A1C3882643 for ; Sun, 2 Apr 2023 07:56:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 54A1C3882643 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680422167; bh=k5sJeQS2RfmXH9Xm/FQCUyUb86OK11Em0ZX6oU5JQTA=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=bmI+HwxZfKFtaEk+kz/G17MhwscMdhJqCx5ALM7DpVkjA+3fm3/TYfCbV0OFNt+tl U+3iWUeUz0x6vcwXHF65NkbfNLelz3CHdzlSdoZOrhbWR2cs+ZCUD0wPBCCyrpmevm K6quIJpmLT3CrQE0kMK6bWngOPOWhuMtohNLTBCI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id DD4083858409; Sun, 2 Apr 2023 07:54:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DD4083858409 Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3327lhvL001770; Sun, 2 Apr 2023 07:54:20 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3ppxp91dpj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 02 Apr 2023 07:54:20 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 3327s3Zs021607 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 2 Apr 2023 00:54:04 -0700 X-Auth-Received: from localhost.localdomain ([10.154.74.245]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3327rKKg003104 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Sun, 2 Apr 2023 00:54:03 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v3 1/6] c++: implement __is_reference built-in trait Date: Sun, 2 Apr 2023 00:53:09 -0700 Message-Id: <20230402075314.39853-2-kmatsui@cs.washington.edu> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230402075314.39853-1-kmatsui@cs.washington.edu> References: <20230330183911.12640-1-kmatsui@cs.washington.edu> <20230402075314.39853-1-kmatsui@cs.washington.edu> MIME-Version: 1.0 X-Proofpoint-GUID: UQMNvWTsiOHm1RXYcbhCxlZlyuHky2Dd X-Proofpoint-ORIG-GUID: UQMNvWTsiOHm1RXYcbhCxlZlyuHky2Dd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-31_07,2023-03-31_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxlogscore=965 spamscore=0 priorityscore=1501 phishscore=0 mlxscore=0 lowpriorityscore=0 adultscore=0 bulkscore=0 malwarescore=0 impostorscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304020070 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui 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?1761403504084199226?= X-GMAIL-MSGID: =?utf-8?q?1762050454937105234?= This patch implements built-in trait for std::is_reference. gcc/cp/ChangeLog: * cp-trait.def: Define __is_reference. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_REFERENCE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_reference. * g++.dg/ext/is_reference.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/is_reference.C | 34 ++++++++++++++++++++++++ 5 files changed, 45 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_reference.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 273d15ab097..23e5bc24dbb 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3701,6 +3701,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_HAS_VIRTUAL_DESTRUCTOR: inform (loc, " %qT does not have a virtual destructor", t1); break; + case CPTK_IS_REFERENCE: + inform (loc, " %qT is not a reference", t1); + break; case CPTK_IS_ABSTRACT: inform (loc, " %qT is not an abstract class", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index bac593c0094..63a64152ce6 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -67,6 +67,7 @@ DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) +DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 99a76e3ed65..b17fbf8005d 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -11996,6 +11996,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_FINAL: return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1); + case CPTK_IS_REFERENCE: + return type_code1 == REFERENCE_TYPE; + case CPTK_IS_LAYOUT_COMPATIBLE: return layout_compatible_type_p (type1, type2); @@ -12201,6 +12204,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_ENUM: case CPTK_IS_UNION: case CPTK_IS_SAME: + case CPTK_IS_REFERENCE: break; case CPTK_IS_LAYOUT_COMPATIBLE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index f343e153e56..b697673790c 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -146,3 +146,6 @@ #if !__has_builtin (__remove_cvref) # error "__has_builtin (__remove_cvref) failed" #endif +#if !__has_builtin (__is_reference) +# error "__has_builtin (__is_reference) failed" +#endif diff --git a/gcc/testsuite/g++.dg/ext/is_reference.C b/gcc/testsuite/g++.dg/ext/is_reference.C new file mode 100644 index 00000000000..b5ce4db7afd --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_reference.C @@ -0,0 +1,34 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_CATEGORY(__is_reference, int&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&, true); +SA(__is_reference(int(&)(int))); +SA_TEST_CATEGORY(__is_reference, int&&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&&, true); +SA(__is_reference(int(&&)(int))); +SA_TEST_CATEGORY(__is_reference, IncompleteClass&, true); + +// Negative tests +SA_TEST_CATEGORY(__is_reference, void, false); +SA_TEST_CATEGORY(__is_reference, int*, false); +SA_TEST_CATEGORY(__is_reference, int[3], false); +SA(!__is_reference(int(int))); +SA(!__is_reference(int(*const)(int))); +SA(!__is_reference(int(*volatile)(int))); +SA(!__is_reference(int(*const volatile)(int))); + +// Sanity check. +SA_TEST_CATEGORY(__is_reference, ClassType, false); +SA_TEST_CATEGORY(__is_reference, IncompleteClass, false); From patchwork Sun Apr 2 07:53:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 78187 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1621195vqo; Sun, 2 Apr 2023 00:57:10 -0700 (PDT) X-Google-Smtp-Source: AKy350b03yUyuMsM/AU9FINV9GfVrQyV/vcE094Kfp9BrnjI9v9XMXaw+Q4olY6N0bY7wedkFqCQ X-Received: by 2002:a17:907:7ba1:b0:8b1:820a:7b60 with SMTP id ne33-20020a1709077ba100b008b1820a7b60mr40528899ejc.6.1680422230765; Sun, 02 Apr 2023 00:57:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680422230; cv=none; d=google.com; s=arc-20160816; b=zuOxPpHvOrfr2y1vrEgC1Qa7LgJ4KEn+mvvnjevWXdslBGsZ6AVd2XMdbwdPaC2d3j z79FnFh/bQ4JBCqzDHwC5LeVyBY1vc0egT//Tki1fSCvMWmSYKkvLnqq6Oa+nYQtC0Pe MOZGv9ubIp4AhbJDWvv5nvtTtq4OOu96r06BKciWU9C4vdVy5jah/Ta6EGYgQ0PG89ni 64hBT3KZGjn/UJIyQakuNLdVRHPqCCv+XpScvDgoOi8mWobUHAqT1jsoHyhY8f5an3pi cw6aPmGFo77YKcaMPcdxY7D2KMqopcGEBhc+DU/b4b95e2sjwulfEnCHOU5pttP+sFxc tVbg== 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:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=4zrZyB1zbEnVwSSdh8XJaqCcaf0J30tW3G7P66vpp00=; b=wY8XB1iRoVza5GKwJHyPDdsufUd3r+9TPsKNyw0OU1D4eZDoSv9VnyPkzUeTYYuwRl nr3xM+VvlEaT8//qQ5nZLEEON7MWYchpZXDBzVpmX2ShQzTzJ+2H45hP0EpPr31cdzNM Xe+7EHudwK2Dqsg8ABkdxAvFagU8fykwMe3ozGgurQawVu0I2kZjEqWDxlM+TtqN2p7f 067d1PV50WB6JJEkGwPImCctraI0/ZFDa/PWyWDEV3crGFwJwq1HR9zU4xpJBE1ozPzb Z5n5fX7Aqv545RqsjOccYS1qWfxRMv/Fy3rxLcmJ2B4YgqyOycfmDB1xw1jUu99LmTTg Zcog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=atzQlazH; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id gu26-20020a170906f29a00b0091f2869a9d5si2820360ejb.691.2023.04.02.00.57.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Apr 2023 00:57:10 -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=atzQlazH; 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 64E75384D1A5 for ; Sun, 2 Apr 2023 07:55:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 64E75384D1A5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680422149; bh=4zrZyB1zbEnVwSSdh8XJaqCcaf0J30tW3G7P66vpp00=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=atzQlazHNMFC4KlXVq2YsLxec2UbI0v3xQp6O/z+wyHrfqNogmycH52OiedrXnTI1 3BCSXxZYBFy0diw2WPSWDtdCgtUZRnB/aGhHkE1Yn+Q2PG3vmNOAiO7jd334gsyrAk RJGaWcuyy061vNxJAPMNOEybXoXKQtDhxCvFbxjQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id C496C3850208; Sun, 2 Apr 2023 07:55:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C496C3850208 Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3327sm05025589; Sun, 2 Apr 2023 07:55:03 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3ppby85pd1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 02 Apr 2023 07:55:03 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 3327sY7I019634 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 2 Apr 2023 00:54:34 -0700 X-Auth-Received: from localhost.localdomain ([10.154.74.245]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3327rKKh003104 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Sun, 2 Apr 2023 00:54:34 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v3 2/6] libstdc++: use new built-in trait __is_reference for std::is_reference Date: Sun, 2 Apr 2023 00:53:10 -0700 Message-Id: <20230402075314.39853-3-kmatsui@cs.washington.edu> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230402075314.39853-1-kmatsui@cs.washington.edu> References: <20230330183911.12640-1-kmatsui@cs.washington.edu> <20230402075314.39853-1-kmatsui@cs.washington.edu> MIME-Version: 1.0 X-Proofpoint-GUID: a5_4Vdv9IHitzNz1G-05ycKsr5_7h71d X-Proofpoint-ORIG-GUID: a5_4Vdv9IHitzNz1G-05ycKsr5_7h71d X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-31_07,2023-03-31_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 bulkscore=0 adultscore=0 phishscore=0 mlxscore=0 impostorscore=0 priorityscore=1501 spamscore=0 clxscore=1015 mlxlogscore=833 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304020071 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui 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?1761403419712597188?= X-GMAIL-MSGID: =?utf-8?q?1762050421092781355?= This patch gets std::is_reference to dispatch to new built-in trait __is_reference. libstdc++-v3/ChangeLog: * include/std/type_traits (is_reference): Use __is_reference built-in trait. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 2bd607a8b8f..58a732735c8 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -639,6 +639,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Composite type categories. /// is_reference +#if __has_builtin(__is_reference) + template + struct is_reference + : public __bool_constant<__is_reference(_Tp)> + { }; +#else template struct is_reference : public false_type @@ -653,6 +659,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_reference<_Tp&&> : public true_type { }; +#endif /// is_arithmetic template From patchwork Sun Apr 2 07:53:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 78186 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1621095vqo; Sun, 2 Apr 2023 00:56:50 -0700 (PDT) X-Google-Smtp-Source: AKy350bGaregk8ib+OZmZBCCn9dg3+6ZQ0+jvrQxIUlVfFBJhLATcPHAMOX/Fs6qBGU3G+1Y1hrW X-Received: by 2002:a17:906:785:b0:92a:7178:ab56 with SMTP id l5-20020a170906078500b0092a7178ab56mr30900766ejc.39.1680422210849; Sun, 02 Apr 2023 00:56:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680422210; cv=none; d=google.com; s=arc-20160816; b=o8TC3uYSICNrayjKCIctAmfcy2J3MuNFEikPSgzDAm70JAvPmyHstZbQycrJyqs+jQ HCH0Xa7wmDSF+lH7DecL2nTBPNXYUMTTwBZ1q0ZGOmqJNDPkWTH1R3eR6SzNDCgeFjSq bZ6h72b3I6b/XZUx8JpsEcblBT2kejjQ6J5anSTdXfO9qwlVk0BIQIc4aGJiocBkp94o 970U9KB7IUNeXGYi4AM3SkurYEFVKNHojzAzohRUo2QV/I/hl4jj8zFJpKQekBTv8ikq 2Cu9KsUXatBUoN71hy3bJaWPxtd0l43ydhug7hpRf9CQPkcS0cRntA6GYt120cz6EPUc jX+A== 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:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=URulY5/XP16H8n0OjjPkxC/uBfrf9GNzBknUkZ9qOlw=; b=lZKDmkuewhkLveBHKA3ZHSacc1bVCTFCzcaZtrg4NyyqPtjiKMRpXGKQAGjsHtgI6a 8jt2i7cVJ5Ds52GCPN+oLMZilfjUx+GU1IYm6SqQ22Y4mi5hAt9uN/2Utu7gvQyzVcYv XPwCUn3c6+7q9Dhjdk2iAle5Usmlkod0Aas3VfafHuyHbWgscjafj6zAJywRVodMrTPs jOPcy9MSTJ8MHHxYTCKJqOI36Uj+U6nmWGbTylaAmX9cXtudPyCCRt1OFijIxjyp8qtx dj49srSfiYr0sJxSBgpZPO9veM4HUKbXpXYsN6p6oSOnB2ImzYZPmEIsmovC7Qww1xQB II6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=SeHZlTD+; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id v18-20020aa7dbd2000000b005002e6f0f60si2663134edt.576.2023.04.02.00.56.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Apr 2023 00:56:50 -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=SeHZlTD+; 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 A5DA73858024 for ; Sun, 2 Apr 2023 07:55:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A5DA73858024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680422137; bh=URulY5/XP16H8n0OjjPkxC/uBfrf9GNzBknUkZ9qOlw=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=SeHZlTD+3ukxR5cX9V5FI9vaqHEV4pPd8S8hMbOX5QvMxsnyt9cHJy57ZuTiSeY/6 yRkBko5RzmU6s0B9YETzlC1K4Pp0cekDG9i9oflMYJc+9yiwmOLwYuYEIpFX7+Lv9J Z0rHK9mYsrgE95G2M26BbwNIrf4Mx8ntB7mDdQ8k= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 9753A385B51C; Sun, 2 Apr 2023 07:54:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9753A385B51C Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3327iZmQ019659; Sun, 2 Apr 2023 07:54:52 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3ppx45hgqq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 02 Apr 2023 07:54:51 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 3327smMn021410 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 2 Apr 2023 00:54:48 -0700 X-Auth-Received: from localhost.localdomain ([10.154.74.245]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3327rKKi003104 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Sun, 2 Apr 2023 00:54:48 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v3 3/6] c++: implement __is_function built-in trait Date: Sun, 2 Apr 2023 00:53:11 -0700 Message-Id: <20230402075314.39853-4-kmatsui@cs.washington.edu> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230402075314.39853-1-kmatsui@cs.washington.edu> References: <20230330183911.12640-1-kmatsui@cs.washington.edu> <20230402075314.39853-1-kmatsui@cs.washington.edu> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: MDiTf2sZKoxMhazU8fPVC32WAcN3A3lt X-Proofpoint-GUID: MDiTf2sZKoxMhazU8fPVC32WAcN3A3lt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-31_07,2023-03-31_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 mlxlogscore=973 clxscore=1015 lowpriorityscore=0 adultscore=0 suspectscore=0 malwarescore=0 priorityscore=1501 spamscore=0 mlxscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304020071 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui 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?1761403931159934367?= X-GMAIL-MSGID: =?utf-8?q?1762050400125915691?= This patch implements built-in trait for std::is_function. gcc/cp/ChangeLog: * cp-trait.def: Define __is_function. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_FUNCTION. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_function. * g++.dg/ext/is_function.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_function.C | 58 ++++++++++++++++++++++++ 5 files changed, 69 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_function.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 23e5bc24dbb..500ac9177c7 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3750,6 +3750,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; + case CPTK_IS_FUNCTION: + inform (loc, " %qT is not a function", t1); + break; case CPTK_IS_AGGREGATE: inform (loc, " %qT is not an aggregate", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 63a64152ce6..99195201676 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -83,6 +83,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) +DEFTRAIT_EXPR (IS_FUNCTION, "__is_function", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) /* FIXME Added space to avoid direct usage in GCC 13. */ diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index b17fbf8005d..36fe370da2d 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -11993,6 +11993,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_ENUM: return type_code1 == ENUMERAL_TYPE; + case CPTK_IS_FUNCTION: + return type_code1 == FUNCTION_TYPE; + case CPTK_IS_FINAL: return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1); @@ -12205,6 +12208,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: case CPTK_IS_SAME: case CPTK_IS_REFERENCE: + case CPTK_IS_FUNCTION: break; case CPTK_IS_LAYOUT_COMPATIBLE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index b697673790c..90eb00ebf2d 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -149,3 +149,6 @@ #if !__has_builtin (__is_reference) # error "__has_builtin (__is_reference) failed" #endif +#if !__has_builtin (__is_function) +# error "__has_builtin (__is_function) failed" +#endif diff --git a/gcc/testsuite/g++.dg/ext/is_function.C b/gcc/testsuite/g++.dg/ext/is_function.C new file mode 100644 index 00000000000..2e1594b12ad --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_function.C @@ -0,0 +1,58 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +struct A +{ void fn(); }; + +template +struct AHolder { }; + +template +struct AHolder +{ using type = U; }; + +// Positive tests. +SA(__is_function(int (int))); +SA(__is_function(ClassType (ClassType))); +SA(__is_function(float (int, float, int[], int&))); +SA(__is_function(int (int, ...))); +SA(__is_function(bool (ClassType) const)); +SA(__is_function(AHolder::type)); + +void fn(); +SA(__is_function(decltype(fn))); + +// Negative tests. +SA_TEST_CATEGORY(__is_function, int, false); +SA_TEST_CATEGORY(__is_function, int*, false); +SA_TEST_CATEGORY(__is_function, int&, false); +SA_TEST_CATEGORY(__is_function, void, false); +SA_TEST_CATEGORY(__is_function, void*, false); +SA_TEST_CATEGORY(__is_function, void**, false); +SA_TEST_CATEGORY(__is_function, std::nullptr_t, false); + +SA_TEST_CATEGORY(__is_function, AbstractClass, false); +SA(!__is_function(int(&)(int))); +SA(!__is_function(int(*)(int))); + +SA_TEST_CATEGORY(__is_function, A, false); +SA_TEST_CATEGORY(__is_function, decltype(&A::fn), false); + +struct FnCallOverload +{ void operator()(); }; +SA_TEST_CATEGORY(__is_function, FnCallOverload, false); + +// Sanity check. +SA_TEST_CATEGORY(__is_function, ClassType, false); +SA_TEST_CATEGORY(__is_function, IncompleteClass, false); +SA_TEST_CATEGORY(__is_function, IncompleteUnion, false); From patchwork Sun Apr 2 07:53:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 78190 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1621824vqo; Sun, 2 Apr 2023 00:59:34 -0700 (PDT) X-Google-Smtp-Source: AKy350az+n1Yw4bVg8SEPLBsl4dSBla3dbVMNUQD5O/bRQfupCCq1sX+Nv44tRj5+f1cefxSdguP X-Received: by 2002:a05:6402:50c6:b0:502:1d1b:5bef with SMTP id h6-20020a05640250c600b005021d1b5befmr14326776edb.14.1680422374284; Sun, 02 Apr 2023 00:59:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680422374; cv=none; d=google.com; s=arc-20160816; b=eCwASm4ghzahl6TFNQuIAqvNQosTYELFSUYcyr4/Auj9HUavJ/hOruJYq08h9aqm4z GCUu2yLrYG71iLrwgEg0uprZkVeyu44DboLovHescI+hUL1FkdDVmbkI9VRrvSA6SyAu cgVzxKMsHZA62Mm4sQ3xSfG1eF82tCCJjm4j5zoBLaZV7xaS3gh2APjfjecTioBd5KoD +WGlyJ4Rm9nyyQCzWex3NmhzwYtfeB7hTPtCrCAWq5tmPJD8w+K1VmhcENmKfdjKQgA7 Gpv8LRBRhtxyYMTQfpDxjii2AV+SHzyc14BeAchNrJIA4Ij/6QOOG9d17zHrutzn/NR4 7sgg== 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:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=zc+jb1Gp+ZRJHMnBS/rJODegAFXiCeDJJUt3Ep5dDdw=; b=afcbsUMH6FxjEjZethmEBCIEykX6MKPPxRZRQC6mcLWHpLuPWt7T0FuW/kwbE3wmST s9ByPbInoOp7ahJbAFWzMto8FBihgtUpH53Ta/86FvmlYuIPa1/atuRKIiWCtAft9M1c aZyOmIcVXtbzFuRbUuGJ5eBL6LHcFA2j05MWrB3OJhWsuQ7/HwP+vZp8Lt3bQHxbcGvL upIznM8CdX/0a2Jnq0o3gN0K/7uZBVq+95TP6LOOsjHq8jNWqhngIJDY7dZhm/G/GEkC RNmVTYi9VRY9fUOCAZc9xKazeOLacwgqnvbkoubfzNisx+lLHINFLMwUnTYjQKQYPxiw TXPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VH2icy1L; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id v15-20020a056402184f00b004fe96b95bbbsi5497682edy.570.2023.04.02.00.59.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Apr 2023 00:59:34 -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=VH2icy1L; 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 48A903858298 for ; Sun, 2 Apr 2023 07:57:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 48A903858298 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680422258; bh=zc+jb1Gp+ZRJHMnBS/rJODegAFXiCeDJJUt3Ep5dDdw=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=VH2icy1LZI28HQgECK386dGFNkUeQWqOTyUhbse6/wHWiT3V2qo5nAIzK41XwfERN YKpx2G0aTi8ZgltOw9TI5LWSjXKalH5Vj9mlTUqum9TtILtM3F8VThHtUsRGc8HhqK d3OCYdZeIAmAf04dcNX76Pdbd0p/a6R9J3GZ+0Sc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 963363850426; Sun, 2 Apr 2023 07:55:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 963363850426 Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3327XXf8012922; Sun, 2 Apr 2023 07:55:27 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3ppby85pe2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 02 Apr 2023 07:55:27 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 3327tOm1016539 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 2 Apr 2023 00:55:24 -0700 X-Auth-Received: from localhost.localdomain ([10.154.74.245]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3327rKKj003104 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Sun, 2 Apr 2023 00:55:24 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v3 4/6] libstdc++: use new built-in trait __is_function for std::is_function Date: Sun, 2 Apr 2023 00:53:12 -0700 Message-Id: <20230402075314.39853-5-kmatsui@cs.washington.edu> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230402075314.39853-1-kmatsui@cs.washington.edu> References: <20230330183911.12640-1-kmatsui@cs.washington.edu> <20230402075314.39853-1-kmatsui@cs.washington.edu> MIME-Version: 1.0 X-Proofpoint-GUID: hJqcDK0_oP3bSKSszGYUyajH3n0IgvSp X-Proofpoint-ORIG-GUID: hJqcDK0_oP3bSKSszGYUyajH3n0IgvSp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-31_07,2023-03-31_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 bulkscore=0 adultscore=0 phishscore=0 mlxscore=0 impostorscore=0 priorityscore=1501 spamscore=0 clxscore=1015 mlxlogscore=843 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304020071 X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui 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?1761403780011068317?= X-GMAIL-MSGID: =?utf-8?q?1762050571253708516?= This patch gets std::is_function to dispatch to new built-in trait __is_function. libstdc++-v3/ChangeLog: * include/std/type_traits (is_function): Use __is_function built-in trait. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 58a732735c8..9eafd6b16f2 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -594,6 +594,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_function +#if __has_builtin(__is_function) + template + struct is_function + : public __bool_constant<__is_function(_Tp)> + { }; +#else template struct is_function : public __bool_constant::value> { }; @@ -605,6 +611,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_function<_Tp&&> : public false_type { }; +#endif #define __cpp_lib_is_null_pointer 201309L From patchwork Sun Apr 2 07:53:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 78189 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1621474vqo; Sun, 2 Apr 2023 00:58:10 -0700 (PDT) X-Google-Smtp-Source: AKy350Z542WErkaiVDujtriD2o9Mrp+KSCXc2uuiLC3BasTgisUVSATYQ/yczMiLIy7GXMkz0VQ4 X-Received: by 2002:a05:6402:194:b0:4fe:9bba:1d65 with SMTP id r20-20020a056402019400b004fe9bba1d65mr38352051edv.21.1680422290602; Sun, 02 Apr 2023 00:58:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680422290; cv=none; d=google.com; s=arc-20160816; b=GfYqxDpInAdVfUoQs3p/CzumcrXdhtXcL3YOk2lg4+O+jz0xKVgmdEnfXGfDZUh6hP i+ovpvbwIDi54iH2QdalyCZN1jmPiihDbXpRlfjXrXbVeootUQgNse2ebqi1MaHKwRES 2/2Sj7KpuR38CfnM18px4PL1LWH5Qzcb+eJcRtZBKVlZKW42V6xsbwwAnWxiI1V7O4a5 5FEWeRVez5a3qtcJOZUIOWr/3VjupjDJU1HAktDXLYq2rVzOdr+KIBV8/6o4GahV0w5K AZ/8Q68bg3z6X9Q9/heXidkLm5wvgR4iVc9F7uAsbzExz9FOvvFDO4U72xUZy1chmDPR k6VQ== 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:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=rFik+YFIiThENSwYigAsb1fjz2+hGUDGBrad12e+ly4=; b=IkN4610M9E694vwh1LhKufqzoHQNxtUchb7VLHSQpDPju1OKWyQlIzNjyU2N5itS/8 86IzcpTB0vLonFil6FvciGKQqHN3VurEXOUE0A5Y8dKucuVqS2MF0j8/tQ9YTArG+sUJ M//VBOwiR/bqtS/f+VlMhiSP7OsW9x9ZXcd7kU8aKTFenW6K1iVqS5EM1k4UzpLE+I34 vv2yTrzWKrChFak+imXYcrFg1WELAfr6InLOFKOX4V/E81gN6fw6wb6wUw2saYKlxNNX KxvHL5eDWTncxTnF5n2UhbtnnRSleF8ERrR71S/O1Z8WpU+R+iJW1g5EnuYOv8MsxIYr S4hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yVHErO5G; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id j1-20020aa7de81000000b004acc7a0756fsi5822919edv.457.2023.04.02.00.58.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Apr 2023 00:58:10 -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=yVHErO5G; 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 BB6453851C04 for ; Sun, 2 Apr 2023 07:56:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB6453851C04 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680422189; bh=rFik+YFIiThENSwYigAsb1fjz2+hGUDGBrad12e+ly4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=yVHErO5G8nr3U2HcZ5jVz8ja6/Q5L3Xd8+judhXXmiYEo4tDD4cbJLv8FrgPTfG1l /R2j+K/4FuT5Bsq7j5Y9pCudF+6fUhcutQl7YsLrwgDe4G5pM19vXOyUH6PoP5GJYX /Kwa6QPEYlMjFeAqnMD9IqEqPeXZYhBhVSC1hKE0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id DA3BF3881D3D; Sun, 2 Apr 2023 07:55:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DA3BF3881D3D Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3327lG4A030085; Sun, 2 Apr 2023 07:55:42 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3ppxyh1bmg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 02 Apr 2023 07:55:41 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 3327tdTC009373 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 2 Apr 2023 00:55:39 -0700 X-Auth-Received: from localhost.localdomain ([10.154.74.245]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3327rKKk003104 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Sun, 2 Apr 2023 00:55:39 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v3 5/6] c++, libstdc++: implement __is_void built-in trait Date: Sun, 2 Apr 2023 00:53:13 -0700 Message-Id: <20230402075314.39853-6-kmatsui@cs.washington.edu> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230402075314.39853-1-kmatsui@cs.washington.edu> References: <20230330183911.12640-1-kmatsui@cs.washington.edu> <20230402075314.39853-1-kmatsui@cs.washington.edu> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: xVz_A2NrjLOy-Uv-VVTJLqYXD_8-Rdim X-Proofpoint-GUID: xVz_A2NrjLOy-Uv-VVTJLqYXD_8-Rdim X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-31_07,2023-03-31_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 bulkscore=0 malwarescore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 spamscore=0 priorityscore=1501 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304020071 X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui 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?1761819584195766596?= X-GMAIL-MSGID: =?utf-8?q?1762050483781424292?= This patch implements built-in trait for std::is_void. Since the new built-in name is __is_void, to avoid unintentional macro replacement, this patch also involves the removal of the existing __is_void in helper_functions.h and cpp_type_traits.h and renaming __is_void to ____is_void in the test file, pr46567.C. gcc/cp/ChangeLog: * cp-trait.def: Define __is_void. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_VOID. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/tm/pr46567.C (__is_void): Rename to ... (____is_void): ... this. * g++.dg/ext/has-builtin-1.C: Test existence of __is_void. * g++.dg/ext/is_void.C: New test. libstdc++-v3/ChangeLog: * include/debug/helper_functions.h (_DiffTraits): Stop using __is_void. * include/bits/cpp_type_traits.h (__is_void): Remove unused __is_void. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_void.C | 35 +++++++++++++++++++ gcc/testsuite/g++.dg/tm/pr46567.C | 6 ++-- libstdc++-v3/include/bits/cpp_type_traits.h | 15 -------- libstdc++-v3/include/debug/helper_functions.h | 5 ++- 8 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_void.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 500ac9177c7..e67c0ffeaac 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3753,6 +3753,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_FUNCTION: inform (loc, " %qT is not a function", t1); break; + case CPTK_IS_VOID: + inform (loc, " %qT is not a void type", t1); + break; case CPTK_IS_AGGREGATE: inform (loc, " %qT is not an aggregate", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 99195201676..6284924630a 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -84,6 +84,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (IS_FUNCTION, "__is_function", 1) +DEFTRAIT_EXPR (IS_VOID, "__is_void", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) /* FIXME Added space to avoid direct usage in GCC 13. */ diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 36fe370da2d..a6598fedfbc 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -11996,6 +11996,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_FUNCTION: return type_code1 == FUNCTION_TYPE; + case CPTK_IS_VOID: + return VOID_TYPE_P (type1); + case CPTK_IS_FINAL: return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1); @@ -12209,6 +12212,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: case CPTK_IS_REFERENCE: case CPTK_IS_FUNCTION: + case CPTK_IS_VOID: break; case CPTK_IS_LAYOUT_COMPATIBLE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 90eb00ebf2d..b96cc9e6f50 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -152,3 +152,6 @@ #if !__has_builtin (__is_function) # error "__has_builtin (__is_function) failed" #endif +#if !__has_builtin (__is_void) +# error "__has_builtin (__is_void) failed" +#endif diff --git a/gcc/testsuite/g++.dg/ext/is_void.C b/gcc/testsuite/g++.dg/ext/is_void.C new file mode 100644 index 00000000000..707f0d6875b --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_void.C @@ -0,0 +1,35 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_void, void, true); + +SA_TEST_CATEGORY(__is_void, char, false); +SA_TEST_CATEGORY(__is_void, signed char, false); +SA_TEST_CATEGORY(__is_void, unsigned char, false); +SA_TEST_CATEGORY(__is_void, wchar_t, false); +SA_TEST_CATEGORY(__is_void, short, false); +SA_TEST_CATEGORY(__is_void, unsigned short, false); +SA_TEST_CATEGORY(__is_void, int, false); +SA_TEST_CATEGORY(__is_void, unsigned int, false); +SA_TEST_CATEGORY(__is_void, long, false); +SA_TEST_CATEGORY(__is_void, unsigned long, false); +SA_TEST_CATEGORY(__is_void, long long, false); +SA_TEST_CATEGORY(__is_void, unsigned long long, false); +SA_TEST_CATEGORY(__is_void, float, false); +SA_TEST_CATEGORY(__is_void, double, false); +SA_TEST_CATEGORY(__is_void, long double, false); + +// Sanity check. +SA_TEST_CATEGORY(__is_void, ClassType, false); +SA_TEST_CATEGORY(__is_void, IncompleteClass, false); +SA_TEST_CATEGORY(__is_void, IncompleteUnion, false); diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C index 6d791484448..e689e293bd4 100644 --- a/gcc/testsuite/g++.dg/tm/pr46567.C +++ b/gcc/testsuite/g++.dg/tm/pr46567.C @@ -72,13 +72,13 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef __true_type __type; }; template - struct __is_void + struct ____is_void { enum { __value = 0 }; typedef __false_type __type; }; template<> - struct __is_void + struct ____is_void { enum { __value = 1 }; typedef __true_type __type; @@ -222,7 +222,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { { }; template struct __is_fundamental - : public __traitor<__is_void<_Tp>, __is_arithmetic<_Tp> > + : public __traitor<____is_void<_Tp>, __is_arithmetic<_Tp> > { }; template struct __is_scalar diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 4312f32a4e0..d329bc5b208 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -105,21 +105,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef __true_type __type; }; - // Holds if the template-argument is a void type. - template - struct __is_void - { - enum { __value = 0 }; - typedef __false_type __type; - }; - - template<> - struct __is_void - { - enum { __value = 1 }; - typedef __true_type __type; - }; - // // Integer types // diff --git a/libstdc++-v3/include/debug/helper_functions.h b/libstdc++-v3/include/debug/helper_functions.h index dccf8e9e5e6..66b4e9e1ecf 100644 --- a/libstdc++-v3/include/debug/helper_functions.h +++ b/libstdc++-v3/include/debug/helper_functions.h @@ -66,13 +66,12 @@ namespace __gnu_debug typedef typename std::iterator_traits<_Iterator>::difference_type _ItDiffType; - template::__type> + template struct _DiffTraits { typedef _DiffType __type; }; template - struct _DiffTraits<_DiffType, std::__true_type> + struct _DiffTraits<_DiffType, void> { typedef std::ptrdiff_t __type; }; typedef typename _DiffTraits<_ItDiffType>::__type _DiffType; From patchwork Sun Apr 2 07:53:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 78191 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1622515vqo; Sun, 2 Apr 2023 01:01:03 -0700 (PDT) X-Google-Smtp-Source: AKy350ZNZ1F7hlVMqLZblbsgxfGU2sn/f86RATMpYfW2NxE+m5JNxm7W3ylxKtqOw2qq/hD+Mgjn X-Received: by 2002:a17:907:6f0d:b0:946:b942:ad6a with SMTP id sy13-20020a1709076f0d00b00946b942ad6amr21992424ejc.38.1680422463812; Sun, 02 Apr 2023 01:01:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680422463; cv=none; d=google.com; s=arc-20160816; b=b3m3euo+vlL9VBjjCb1Ef36RiurGclMXefiPzImJX2LzGn5nO9VAJpEIXxGbcRskEA QmHaxhK2hR+YrMqgShc3p9skuDAbbIRhRZgYSzzr9y7Ck/+HfG1NOs9+ErWvv3gzFHWe lnRfiVV+WjdEZJIURWgbvi0BaQKgT7ErIxwjtizPEUb+dYk703nCHC/cMmeiOMT531+2 VfjnkznodHA1lG4mDCioB2Om11Pgt+Jj3sgmppNWhXHSFEDxbsvREXoZMPZSG03Qp0Ze J4VYImgrXwCO/nHkp2PD/Cb2WT7/TP3iAhV2nGZ0QlwJjwzR71AdB4dMok2cU8tL06cc ietA== 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:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=q1bXxGJAiB+RjfDo3SbcIGfeVWCNBACsEJRRxtoWRxM=; b=pFavTxQXA5v4HgdpwHQUbpgcuXsKnThHH2x3I5tk4e6AVPHcXPMmcWBinBhuYqgb1N f2aWogSNTO5ctM2HPYVwSSFUnuG+1Ukt5REbFceghHuSwyyu/pJCricdjiOclC4UT9RC dYeuTaUraRU5+aeYMQoiwOpISTlpvBdrS03AVoig+/gZR2+3t8yZvQJ7sjiPYiMjeoJ7 XNqRcm/1uRjgES0U7Az3mXOYgzP3bO4fbDIQkWbfYLwSEc/0edwClghr8COxLOjMaI/h i5oaI9GHgkHrYZVwtmBFUGiSec0Uw0hLg++Pv7UlStblX7MXyymfen57RZX7KUOopnd6 7Tyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pWCw5JcI; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u5-20020a056402064500b004acc992d6f7si2347464edx.257.2023.04.02.01.01.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Apr 2023 01:01:03 -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=pWCw5JcI; 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 1718F385084B for ; Sun, 2 Apr 2023 07:59:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1718F385084B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680422391; bh=q1bXxGJAiB+RjfDo3SbcIGfeVWCNBACsEJRRxtoWRxM=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=pWCw5JcI2xOSkIN2OQ4kWkJBwqcAvsqXqvwlcSoc7uVcPhqk0DG1hrh1cMmB9dSip Iob1TgLBVFSWpbfBPwHUmymbsG8zMc+J1sW+lxEXK6YJKE/lUJcsfL010M5ZhDF8qd hXZpZ+vP/Pzm8X+6yK4L8ujd3v/Qr6SOsVQm8nwk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id EC0D2388266F; Sun, 2 Apr 2023 07:56:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC0D2388266F Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3327slER001951; Sun, 2 Apr 2023 07:56:29 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3ppdyu5dau-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 02 Apr 2023 07:56:29 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 3327uDil021650 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 2 Apr 2023 00:56:13 -0700 X-Auth-Received: from localhost.localdomain ([10.154.74.245]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3327rKKl003104 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Sun, 2 Apr 2023 00:56:13 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v3 6/6] libstdc++: make std::is_object dispatch to new built-in traits Date: Sun, 2 Apr 2023 00:53:14 -0700 Message-Id: <20230402075314.39853-7-kmatsui@cs.washington.edu> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230402075314.39853-1-kmatsui@cs.washington.edu> References: <20230330183911.12640-1-kmatsui@cs.washington.edu> <20230402075314.39853-1-kmatsui@cs.washington.edu> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: yOOgjmRoIEkywyAthMjieUTBWph8JLQZ X-Proofpoint-GUID: yOOgjmRoIEkywyAthMjieUTBWph8JLQZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-31_07,2023-03-31_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 phishscore=0 malwarescore=0 clxscore=1015 mlxlogscore=923 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304020071 X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui 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?1761403850642973368?= X-GMAIL-MSGID: =?utf-8?q?1762050665457409078?= This patch gets std::is_object to dispatch to new built-in traits, __is_function, __is_reference, and __is_void. libstdc++-v3/ChangeLog: * include/std/type_traits (is_object): Use new built-in traits, __is_function, __is_reference, and __is_void. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 9eafd6b16f2..c1691336e0f 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -682,11 +682,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_object +#if __has_builtin(__is_function) && __has_builtin(__is_reference) \ + && __has_builtin(__is_void) + template + struct is_object + : public __bool_constant + { }; +#else template struct is_object : public __not_<__or_, is_reference<_Tp>, is_void<_Tp>>>::type { }; +#endif template struct is_member_pointer;