From patchwork Tue Oct 24 02:00:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 157221 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1671609vqx; Mon, 23 Oct 2023 19:17:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHF50xivRRbNOIwBEvFZnBAfmAWbcLlNwfgNeIToQJyk1oe3jnD7vW/ydn3EWF6WhwY2ObJ X-Received: by 2002:ad4:5d69:0:b0:66d:2e59:4fc2 with SMTP id fn9-20020ad45d69000000b0066d2e594fc2mr12693057qvb.40.1698113845840; Mon, 23 Oct 2023 19:17:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698113845; cv=pass; d=google.com; s=arc-20160816; b=kKd1Au/gIEnGTmV2VJ+YZwsWh+QlXV2Xt+FnE7ks8f4//KZWOK0kx8cgF9t1nGept1 PLrk3v+rozSnWWPOjrOHdA8Tg39ARoGzMyNGqFtoiipUH4AhLXXdvw6cIx6nn3g6WD5H BeJiO31QYmaJbybnJ1BLZXQ+kzin+l9wGLzTAJJX69ikBEc24w0DmU2GqkxuwIygddqT puTH0jxKsAIDi144RAYXbGYmWBE0lg9zhpQhKmNbi6w/CJx3PRR7WrRg9vD8O7RAVOsa oi80CxBS9/ecTOV7xkNU54DEW/KCaur2l08URMLhVp/RxU6QvM/t+69dWAm4Ldzp0iRN iImw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to: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 :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=Cso/FtexxCiFEW7sUyIeyxqu1ojPa1wHttZDbhWCEJY=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=CvTJzkOG+DJRmg/1/SldKShHkNs5Kkvb5B1mZl3lQiO0LSTUPrpftBnnst3caO5dtG Y5xkIJmCvXnzJAGSnKnDAst6+yTQRANHRHS/LDrHihg6BE0j9jaA7PK7ttyRxpPGfabN iEb+89Y9+D4gs+cKxW1zRzDTI0xGcdgw9TS1KrT7XQnKre0K8eqJ1e9mvG0CFnDjgN+R NWDKyNYbviEmgFnXPOKqBvS+KpW7x4gRV8Y0NISYxFUHhdAuF+GlXepjokWt2JO2W1Yf DVNDm1+MICQB5smMiDCj0i4u/dYEnSZ3xGlFiWpyIjpYuA7Ogam3yQ0zY1hATlYMI9yT VHnQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BhPkYbeW; arc=pass (i=1); 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id cu15-20020a05621417cf00b0065b1f75bf6esi6275403qvb.23.2023.10.23.19.17.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 19:17:25 -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=BhPkYbeW; arc=pass (i=1); 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 89CD7385770F for ; Tue, 24 Oct 2023 02:17:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89CD7385770F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1698113845; bh=Cso/FtexxCiFEW7sUyIeyxqu1ojPa1wHttZDbhWCEJY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=BhPkYbeWb1s2/92ic7zZDM95dyD61yFMdEITmSJ9GzMTC+oqvfc4+9SEGxuk4QdgM 2XzTQewc9ayJ8DmD3Etyvzn/m0PIP9d1XOYPV1r+3HXeftc81jmMMt1bB3sN4i6PGc fLaShJakPfpx9oS7odK4N7t5HTe/Pde7CNOz/2FE= 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 5A5B33856DEA; Tue, 24 Oct 2023 02:05:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5A5B33856DEA Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5A5B33856DEA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698113113; cv=none; b=Z0IQfcWfsRuDjSHP95Qj828jBYE9UrepqzCNl1yGac3NEyo69Gq/wIpbs9lf/ugrAsY1QsvajY3SZJEFOb70/lCLu+r0N78Pa+ewwvnkaEENUCDUjfONBS3gKVNRqGecUtpjxsoTV1Aa6gZRVcM8t0tskFaj4ndckU+Y6QYYV+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698113113; c=relaxed/simple; bh=U12ejN9OEapuwKUF+leGLYxwEoDM3ZZw1xaoF2+CcI8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=vrT2FflABqC7hRO3CnhIvIw9JVVh+8BLPdxPmzp/LIsNAbv5PxhAgudA7IozlJBiZKRbkZLG/Mv5T0/X/QCvq30PzsWbTXfBHglsmyAImQdd/TkFFJ5YaKuRW8Gm+2RmdNm6t98E7fa1Hp7cMQbadaxYexUUC+Vj4xYSDL38yGE= ARC-Authentication-Results: i=1; server2.sourceware.org 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 39O1xIdI025819; Tue, 24 Oct 2023 02:05:09 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3twvvam89b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 24 Oct 2023 02:05:09 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39O24fEp006170 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Oct 2023 19:04:41 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39O24TmE031305 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Oct 2023 19:04:41 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v25 16/33] c++: Implement __is_member_pointer built-in trait Date: Mon, 23 Oct 2023 19:00:59 -0700 Message-ID: <20231024020424.699427-17-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231024020424.699427-1-kmatsui@gcc.gnu.org> References: <20231020162115.2307797-1-kmatsui@gcc.gnu.org> <20231024020424.699427-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 9M02MUi4lVLejZoCsaum0NjE-94f9PiC X-Proofpoint-ORIG-GUID: 9M02MUi4lVLejZoCsaum0NjE-94f9PiC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-24_01,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 phishscore=0 clxscore=1034 mlxscore=0 malwarescore=0 impostorscore=0 mlxlogscore=859 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310240017 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780601423962986500 X-GMAIL-MSGID: 1780601423962986500 This patch implements built-in trait for std::is_member_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_member_pointer. * g++.dg/ext/is_member_pointer.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_member_pointer.C | 30 ++++++++++++++++++++ 5 files changed, 41 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_member_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 2b46e3afa97..a969a069db4 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3757,6 +3757,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_LITERAL_TYPE: inform (loc, " %qT is not a literal type", t1); break; + case CPTK_IS_MEMBER_POINTER: + inform (loc, " %qT is not a member pointer", t1); + break; case CPTK_IS_NOTHROW_ASSIGNABLE: inform (loc, " %qT is not nothrow assignable from %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index e0e3fe1d23f..26087da3bdf 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -72,6 +72,7 @@ DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) +DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 9f0e468f489..5ca05dde75d 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12184,6 +12184,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: return literal_type_p (type1); + case CPTK_IS_MEMBER_POINTER: + return TYPE_PTRMEM_P (type1); + case CPTK_IS_NOTHROW_ASSIGNABLE: return is_nothrow_xible (MODIFY_EXPR, type1, type2); @@ -12393,6 +12396,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index ba97beea3c3..994873f14e9 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -95,6 +95,9 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_member_pointer) +# error "__has_builtin (__is_member_pointer) failed" +#endif #if !__has_builtin (__is_nothrow_assignable) # error "__has_builtin (__is_nothrow_assignable) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_pointer.C new file mode 100644 index 00000000000..7ee2e3ab90c --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_pointer.C @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_NON_VOLATILE(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#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_member_pointer, int (ClassType::*), true); +SA_TEST_CATEGORY(__is_member_pointer, ClassType (ClassType::*), true); + +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(int), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(int) const, true); +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(float, ...), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, ClassType (ClassType::*)(ClassType), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, + float (ClassType::*)(int, float, int[], int&), true); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_pointer, ClassType, false);