From patchwork Tue Sep 12 02:38:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 137949 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp135257vqx; Mon, 11 Sep 2023 19:52:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0bH9h7c1DvVCzEbHdUqhW9gx0KW38LiADUEi2XQ2FNt03EyTH7BTMEQOzlh1TDmq5HCW7 X-Received: by 2002:a17:906:31c6:b0:9a6:7fee:8258 with SMTP id f6-20020a17090631c600b009a67fee8258mr9634474ejf.19.1694487163632; Mon, 11 Sep 2023 19:52:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694487163; cv=none; d=google.com; s=arc-20160816; b=OecUkVZ80fQs8W/ox82OagntJswtyjvKC2dk3I3nDQ/Rx2dNTPifAo8Kh7T+2oNUHg 7V7ZOUlb4+Et2v+TsJ5t8qKMht/Zrxav7r4DWm4dMW2UyJQYWqRcA9gdpO8yJAmRhRE/ bcLsKNLVhAONPVhjk/6yuoRs6skXjtwbOnMXNnDyKT49exIAO0GpiLiERwxdixQ+dTF5 2Zj4ndmAAxZYk+lZ1pISsL9RZ2KDn4Vz6fk1uQijgvm/L8j5Eiq5hfDRiqse9+uXHo/O TxLZ60Eddpr6dRVubXYhew++7F87dZaJ1OEP/Y9gFmacB5+idyqZTEi0m6l0hqDRGwJo 3mSQ== 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=cuNzmIhQd/pTjxlYCpKnogvLcNXc9gN/Z+a0sMsH9NA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=YgShMz4rYahKXiHYetMVFFrwxL8QX2l1dlt9g4e3cNyO9RLyozrbrVjAUAdFsxEJ0D Y+U1R1egrqIYvSJs3zrr4zmHJGfzSQpRHMNjewg7vLr2mSs4au2WxSuZRlKC54Sdh+s0 bdehmF7c4MEVhujaQnlMpcwtWWA0bSJJX8cwLU42gusDtiDP0MphqjncGnyJ6PDPkMzV 2viX2fU/4Emy8VaLxOms/irP6+ZQ/Qcc8Cn5g4RnsIKvLnecpvnvRnqC3M8P06FraYjg CXi9uJL0MkOyTyLIXWk0KZ2FFjMc0221t/RwYYr/QG1LzkI31WdhKb05Ytxs76u0EVYP 5BVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BHLZoh3O; 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id p7-20020a170906b20700b0099c49a11e7asi7475615ejz.976.2023.09.11.19.52.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 19:52: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=BHLZoh3O; 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 669DA3850221 for ; Tue, 12 Sep 2023 02:51:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 669DA3850221 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694487096; bh=cuNzmIhQd/pTjxlYCpKnogvLcNXc9gN/Z+a0sMsH9NA=; 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=BHLZoh3O4AnKF3zdbnn1nvgnO4mGP9+gIMPAKZvYkCf/s/kk4mkk54JPs8kEN5Ksw 5hd0GPSrGkbwHsILHk8WBx+EwzNWi8jw4/cg3IfsH0sfASrGuK4N8J5uMCDUCes2VE 1y27gn+lutF32n/84on3pep+h1CJw5I/8yPokEz4= 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 4E973385842C; Tue, 12 Sep 2023 02:50:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4E973385842C 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 38C2iIC8021059; Tue, 12 Sep 2023 02:50:22 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t2d4krqe4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 12 Sep 2023 02:50:21 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38C2oB2s023250 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Sep 2023 19:50:11 -0700 X-Auth-Received: from localhost.localdomain ([10.154.74.234]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38C2nMd3024758 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Mon, 11 Sep 2023 19:50:11 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH 1/2] c++: Implement __is_bounded_array built-in trait Date: Mon, 11 Sep 2023 19:38:38 -0700 Message-ID: <20230912024920.55120-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230912024920.55120-1-kmatsui@gcc.gnu.org> References: <20230912024920.55120-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: GeDTm7moeGOvosTtPqHh0A_Se-SDDkZM X-Proofpoint-GUID: GeDTm7moeGOvosTtPqHh0A_Se-SDDkZM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-11_19,2023-09-05_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 impostorscore=0 adultscore=0 mlxscore=0 mlxlogscore=695 suspectscore=0 malwarescore=0 spamscore=0 bulkscore=0 clxscore=1034 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309120021 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_LOW, 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: , 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: INBOX X-GMAIL-THRID: 1776798572144844156 X-GMAIL-MSGID: 1776798572144844156 This patch implements built-in trait for std::is_bounded_array. gcc/cp/ChangeLog: * cp-trait.def (IS_BOUNDED_ARRAY): Define __is_bounded_array. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_BOUNDED_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_bounded_array. * g++.dg/ext/is_bounded_array.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_bounded_array.C | 38 +++++++++++++++++++++ 5 files changed, 49 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_bounded_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c9e4e7043cd..4db9acade65 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3760,6 +3760,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_ASSIGNABLE: inform (loc, " %qT is not assignable from %qT", t1, t2); break; + case CPTK_IS_BOUNDED_ARRAY: + inform (loc, " %qT is not a bounded array", t1); + break; case CPTK_IS_TRIVIALLY_ASSIGNABLE: inform (loc, " %qT is not trivially assignable from %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 8b7fece0cc8..d50ca8a7781 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -61,6 +61,7 @@ DEFTRAIT_EXPR (IS_ABSTRACT, "__is_abstract", 1) DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) +DEFTRAIT_EXPR (IS_BOUNDED_ARRAY, "__is_bounded_array", 1) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) DEFTRAIT_EXPR (IS_CONSTRUCTIBLE, "__is_constructible", -1) DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 0f7f4e87ae4..87eeed34068 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12142,6 +12142,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_ENUM: return type_code1 == ENUMERAL_TYPE; + case CPTK_IS_BOUNDED_ARRAY: + return type_code1 == ARRAY_TYPE && TYPE_DOMAIN (type1); + case CPTK_IS_FINAL: return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1); @@ -12359,6 +12362,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_BOUNDED_ARRAY: 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..04db7756a26 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_bounded_array) +# error "__has_builtin (__is_bounded_array) failed" +#endif diff --git a/gcc/testsuite/g++.dg/ext/is_bounded_array.C b/gcc/testsuite/g++.dg/ext/is_bounded_array.C new file mode 100644 index 00000000000..346790eba12 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_bounded_array.C @@ -0,0 +1,38 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CONST(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_bounded_array, int[2], true); +SA_TEST_CATEGORY(__is_bounded_array, int[], false); +SA_TEST_CATEGORY(__is_bounded_array, int[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, int[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, float*[2], true); +SA_TEST_CATEGORY(__is_bounded_array, float*[], false); +SA_TEST_CATEGORY(__is_bounded_array, float*[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, float*[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[2], true); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[], false); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, int(*)[2], false); +SA_TEST_CATEGORY(__is_bounded_array, int(*)[], false); +SA_TEST_CATEGORY(__is_bounded_array, int(&)[2], false); +SA_TEST_CONST(__is_bounded_array, int(&)[], false); + +// Sanity check. +SA_TEST_CATEGORY(__is_bounded_array, ClassType, false); +SA_TEST_CONST(__is_bounded_array, void(), false);