From patchwork Sat Jan 6 05:05:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 185586 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp6619286dyb; Fri, 5 Jan 2024 21:11:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IEopWZZfAYB2xRJKZiv1Nut30bOOWTxD/ESbjTVyKkLZErrSM2BuktYlFxtxWwrzN3/UptX X-Received: by 2002:a05:620a:12fb:b0:781:5e61:fb88 with SMTP id f27-20020a05620a12fb00b007815e61fb88mr483627qkl.3.1704517906667; Fri, 05 Jan 2024 21:11:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704517906; cv=pass; d=google.com; s=arc-20160816; b=qO5PY+5TTwwwaIJ/SdMX87YdrOWXQn7j04qp7O2jVIAYepEBBaeWYUwWK/8NU61dnH 15jyWHzGAfOqd/lancU0zIGfUpKLrX3w4lBTvCi0bC6l+u+9hoTfNt+kQqfm+oR7tsT8 tCxCidvIAF36fMrLr+1IUxAvvShONLHSZDa2RwF2NZIeiwI4pIso5NeNku+86C3smA/H l6YbyCNsECgnGz4hxXixSUBSFZvWdUEq5ikv5cP+S0Ui3EENF7BZuo96Ppc5z4kfWWAD RooC1+YOvtfCOE6g0XBfYM7NuOnlZI4F5saeMeVvHxk9op8ky6eoQjeV0/aOueHUcF5Z 8UFQ== 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=7AD/WLx2rB0idblU9CokzxJ4k39jyANRIuLGvH2QsK4=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=x4aPFzuczSzOPg6fjj3LbcbdfGd2hIr3P6f/lG7QIIro8AGK6urrxSoGgPPy5x9rMu jOXMJ/d/SLu3WDj3jyhEdMBYLKM3OUgaX8PsZBlAlvzPdqNjIIMnjTkYjRKUeI1yfHGt Wbs82rCz9KulF7HHXuP5q0b1hnPA+Jt0dddLgcuovvxIOBK4vCW/7u4JKrcs6RtuVZy7 91j/uBBObc+R2Ah7dQsC40UfqgddHSmLJK9G59podM7qFACBHJ6VZdAJUvlaCsb1VCOx mHQ8NQofU+Bhlc3S0xHgVZkP2CNGv0SCnCdNm53fV8hQy3B7GP9ujSLWM+Xxj0jb220j 5kcg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Lnk165+I; 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 g10-20020a05620a40ca00b00781cac19c05si3547319qko.612.2024.01.05.21.11.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 21:11:46 -0800 (PST) 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=Lnk165+I; 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 519AF384CB8F for ; Sat, 6 Jan 2024 05:11:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 519AF384CB8F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704517906; bh=7AD/WLx2rB0idblU9CokzxJ4k39jyANRIuLGvH2QsK4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Lnk165+Ivx9MP/UEWtvvBcom3I+/sNpdQWhtA+UYESGB0TBdeCg6FDSITbw5d1ZG/ VK0tXVZaA/RpbtK5xICmJ7LvD0mv5uOmAFs6wMM1ATn9lHnnmrMrTx3DKbhCazmXvw m7xOKtB8G4m6Hcuhz/rQLQE5AyvC4uxXRIsUTtdk= 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 7A8D1384F020; Sat, 6 Jan 2024 05:08:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7A8D1384F020 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 7A8D1384F020 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=1704517738; cv=none; b=mSw6sVptQpRwthyaQS2c4AYXZcicMX3SEORf+QIRntLFWDZ3lJPZwqdUYgwcEJA1lcmJaJKqAr5Td938nk3r9SmJeEPITwLCSVuNsFXIRtOyirQuL06Z+xwpTcoCM/55HURGRU6iRPAVYu5HCDwQql+dMyohosTUwOEbxvJ9SuU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704517738; c=relaxed/simple; bh=g04JkD8oS95FNF+8YCi5+rHYw1/3jdrnuQlz2ktvtiI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=NJ8U2leCFd6djiFB04kvMlY/Iv5SX1tkH8IHhozz6VWa7vxxBEhtohlubdilGrSHhbXmJ9Jjjd+KLJfkbljNZBFzYg4+0Fr7C6F5bXDo1Kdn4DOnL+wEnyIGNu2KnTz1cr7WCumBKpQPyFpZGo86g161kzS5ljq2zxW5Izeb2aI= ARC-Authentication-Results: i=1; server2.sourceware.org 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 40657q1e008138; Sat, 6 Jan 2024 05:08:56 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3vexq30b0v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 06 Jan 2024 05:08:55 +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 40658gni007595 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 5 Jan 2024 21:08:42 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.143]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 406580HA000483 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 5 Jan 2024 21:08:42 -0800 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 v3 5/8] c++: Implement __is_pointer built-in trait Date: Fri, 5 Jan 2024 21:05:39 -0800 Message-ID: <20240106050754.3054782-6-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> References: <20231223220432.712093-1-kmatsui@gcc.gnu.org> <20240106050754.3054782-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: OerAY82cTOVZTlLuGSYni9zP4NVdP6kk X-Proofpoint-GUID: OerAY82cTOVZTlLuGSYni9zP4NVdP6kk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-05_08,2024-01-05_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 clxscore=1034 impostorscore=0 bulkscore=0 spamscore=0 priorityscore=1501 suspectscore=0 malwarescore=0 mlxlogscore=722 adultscore=0 lowpriorityscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401060033 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786112185994066034 X-GMAIL-MSGID: 1787316568465666456 This patch implements built-in trait for std::is_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_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_pointer. * g++.dg/ext/is_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_pointer.C | 51 ++++++++++++++++++++++++ 5 files changed, 62 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 6f13546b9b2..3d7c0509f6b 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3795,6 +3795,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_POD: inform (loc, " %qT is not a POD type", t1); break; + case CPTK_IS_POINTER: + inform (loc, " %qT is not a pointer", t1); + break; case CPTK_IS_POLYMORPHIC: inform (loc, " %qT is not a polymorphic type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index e9347453829..18e2d0f3480 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) DEFTRAIT_EXPR (IS_OBJECT, "__is_object", 1) DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2) DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) +DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 0f304cdc642..4b75ff744d4 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12471,6 +12471,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POD: return pod_type_p (type1); + case CPTK_IS_POINTER: + return TYPE_PTR_P (type1); + case CPTK_IS_POLYMORPHIC: return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1); @@ -12670,6 +12673,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: case CPTK_IS_OBJECT: + case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index b2e2f2f694d..96b7a89e4f1 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -125,6 +125,9 @@ #if !__has_builtin (__is_pod) # error "__has_builtin (__is_pod) failed" #endif +#if !__has_builtin (__is_pointer) +# error "__has_builtin (__is_pointer) failed" +#endif #if !__has_builtin (__is_polymorphic) # error "__has_builtin (__is_polymorphic) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_pointer.C b/gcc/testsuite/g++.dg/ext/is_pointer.C new file mode 100644 index 00000000000..d6e39565950 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(!__is_pointer(int)); +SA(__is_pointer(int*)); +SA(__is_pointer(int**)); + +SA(__is_pointer(const int*)); +SA(__is_pointer(const int**)); +SA(__is_pointer(int* const)); +SA(__is_pointer(int** const)); +SA(__is_pointer(int* const* const)); + +SA(__is_pointer(volatile int*)); +SA(__is_pointer(volatile int**)); +SA(__is_pointer(int* volatile)); +SA(__is_pointer(int** volatile)); +SA(__is_pointer(int* volatile* volatile)); + +SA(__is_pointer(const volatile int*)); +SA(__is_pointer(const volatile int**)); +SA(__is_pointer(const int* volatile)); +SA(__is_pointer(volatile int* const)); +SA(__is_pointer(int* const volatile)); +SA(__is_pointer(const int** volatile)); +SA(__is_pointer(volatile int** const)); +SA(__is_pointer(int** const volatile)); +SA(__is_pointer(int* const* const volatile)); +SA(__is_pointer(int* volatile* const volatile)); +SA(__is_pointer(int* const volatile* const volatile)); + +SA(!__is_pointer(int&)); +SA(!__is_pointer(const int&)); +SA(!__is_pointer(volatile int&)); +SA(!__is_pointer(const volatile int&)); + +SA(!__is_pointer(int&&)); +SA(!__is_pointer(const int&&)); +SA(!__is_pointer(volatile int&&)); +SA(!__is_pointer(const volatile int&&)); + +SA(!__is_pointer(int[3])); +SA(!__is_pointer(const int[3])); +SA(!__is_pointer(volatile int[3])); +SA(!__is_pointer(const volatile int[3])); + +SA(!__is_pointer(int(int))); +SA(__is_pointer(int(*const)(int))); +SA(__is_pointer(int(*volatile)(int))); +SA(__is_pointer(int(*const volatile)(int)));