From patchwork Wed Feb 28 19:26:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 208014 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3570413dyb; Wed, 28 Feb 2024 11:42:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUcTb5IlmOWDuJxtEVQnqISAZhsPWPMCPSSmjRNhorNX68EbNoZFXD61YXZA22XmxxkkiYG4Fq+tC0DaWRCaWRWMNyeOQ== X-Google-Smtp-Source: AGHT+IHo7VpoAvOje386QJLxhap9+tL4Jm3p71mLBQT6P8m+AA7cCjppjmumdAlJ+DbY3QnfwNwV X-Received: by 2002:a67:b44b:0:b0:470:54fa:b37b with SMTP id c11-20020a67b44b000000b0047054fab37bmr477983vsm.35.1709149376244; Wed, 28 Feb 2024 11:42:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149376; cv=pass; d=google.com; s=arc-20160816; b=ttGALUtG3L5rfh9gVWBL+6o2YxTTOcMdfdvndJa9IvdZ802q0PwDRBFaTtQW9i1YWk nstZFUO4R1drTE7zhf0/vu07KjBjO0kVIwAJeB3URgIkq8pBveLAKAFCri5sWPJCZAlY pcHLGUhatJFdafv5JheKtwKTsyi7isJ6ThXM2z+xWy2Q4O0bFPR6rg1+LCwQrmfcEHdl Z3FhE3yOZBs4JaQfzHEILYpBo4ourZXmGkaFJYAgNSOrYEyYHcUWwndpZG9nFt5WgXJb +WOtVAP5Mbp/tz0jJqj0fEaRv/v82z9unuH2WxGsFRJGQ49vez3PCAQBNW7AWrMqS4pd P0Mw== 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=ojQrwrUDSh4TIReeQbQMTeMyDmid3s/o5ImN5+m1U8M=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=X9kstDx5kkWbCsc/xZ9tHvLY6rgLRrFEJRRoI6Yea9yBd4tpJ9KrPtXRA3EfJlgAqc RtMNcJqiYyV5L94F8Onw14AlQfpgsOWTCmas6ncLhWUw45gOGgGaywCS92f2lxvG+AZz 7r7u9r8mMaW+NGMZMHDI8L40aRN4dm2juDuICOQzoEJSWkqANrSvT7WDrkpyZwuTFcaI /aKxCliPlxdcL5HLS5Tdu0x0MI1TjeqjIar4Ede95Cxk10gMinqrgzuGrcEL/9rmiGL3 6VTLeDFYh1uUWY0Ng849O3vDZJ/1nNXsiGLCfGzXj+Bz/ygPLBEem5ZBidATVlhiwbq+ WQGw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=suOe0k3H; arc=pass (i=1); 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 s26-20020a05622a1a9a00b0042de974538asi146963qtc.236.2024.02.28.11.42.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:42:56 -0800 (PST) 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=suOe0k3H; arc=pass (i=1); 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 DC5CC385800A for ; Wed, 28 Feb 2024 19:42:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC5CC385800A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149375; bh=ojQrwrUDSh4TIReeQbQMTeMyDmid3s/o5ImN5+m1U8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=suOe0k3H9CND28cEA32supejCdrk84qp32Lrh7V2oAyPDNMeve/bwOENboFpqIZqV 7WOvc5oulN8FlMorPACtoUCQSAXVIbHV1KZNCdnVp67C+0T3qZ3D2qWOyZV5YOO/AJ gvOwAW+MFlPlrKAnYjzmnw9jBELNg8nShg1htA6o= 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 579AB385800D; Wed, 28 Feb 2024 19:32:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 579AB385800D 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 579AB385800D 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=1709148727; cv=none; b=yGGYvsurdHA7w0LhdKN8AGLS603EkZN3qwpzOcWWodseK+mvwgp9HsHXvGyONAAnd0vJqKtWlW32g8myFRJgSnDG0Q/ZM4fZNahhWtdjA8XqB26evnBvdKFcce7d7vKNcnn0YKwWTAvG4/skug1xXKGWCqnthv1ju1LspVcAnEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148727; c=relaxed/simple; bh=2IcNCwYFjJS2/+7jFd3egy7vP2hEqpSX6M9lHtv3I2g=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=DaJw4ACU6Wsl6YEvGT1xjYE0mp7DYh9KnXzM7w3OUtTltcXfFgQZDa+cTDoaaHmVBzczXSJZhSg62O5pzJ/B6Ab368KaHFFjF0XlHWxLjT/Yv3tqBviMh1a3YztfqCWzc8ObXuYyyPkFhj71SdtCsFG7ohsAg6O7kZNLsLlKURo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJI6jf022810; Wed, 28 Feb 2024 19:32:05 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3whxdj4wbc-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:32:04 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSq77025231 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:52 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTb015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:51 -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 v14 19/26] c++: Implement __decay built-in trait Date: Wed, 28 Feb 2024 11:26:24 -0800 Message-ID: <20240228192843.188979-20-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: pP_KAcF0bDIz15CxYZPmKklZTldijAlb X-Proofpoint-ORIG-GUID: pP_KAcF0bDIz15CxYZPmKklZTldijAlb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 bulkscore=0 spamscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1034 impostorscore=0 priorityscore=1501 mlxlogscore=405 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.4 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, 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: 1791500851546587803 X-GMAIL-MSGID: 1792173016092194278 This patch implements built-in trait for std::decay. gcc/cp/ChangeLog: * cp-trait.def: Define __decay. * semantics.cc (finish_trait_type): Handle CPTK_DECAY. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __decay. * g++.dg/ext/decay.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 12 ++++++++++++ gcc/testsuite/g++.dg/ext/decay.C | 22 ++++++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ 4 files changed, 38 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/decay.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 173818adf79..2d1cb7c227c 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -51,6 +51,7 @@ DEFTRAIT_TYPE (ADD_LVALUE_REFERENCE, "__add_lvalue_reference", 1) DEFTRAIT_TYPE (ADD_POINTER, "__add_pointer", 1) DEFTRAIT_TYPE (ADD_RVALUE_REFERENCE, "__add_rvalue_reference", 1) +DEFTRAIT_TYPE (DECAY, "__decay", 1) DEFTRAIT_EXPR (HAS_NOTHROW_ASSIGN, "__has_nothrow_assign", 1) DEFTRAIT_EXPR (HAS_NOTHROW_CONSTRUCTOR, "__has_nothrow_constructor", 1) DEFTRAIT_EXPR (HAS_NOTHROW_COPY, "__has_nothrow_copy", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 19d6f87a9ea..45dc509855a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12801,6 +12801,18 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, return type1; return cp_build_reference_type (type1, /*rval=*/true); + case CPTK_DECAY: + if (TYPE_REF_P (type1)) + type1 = TREE_TYPE (type1); + + if (TREE_CODE (type1) == ARRAY_TYPE) + return finish_trait_type (CPTK_ADD_POINTER, TREE_TYPE (type1), type2, + complain); + else if (TREE_CODE (type1) == FUNCTION_TYPE) + return finish_trait_type (CPTK_ADD_POINTER, type1, type2, complain); + else + return cv_unqualified (type1); + case CPTK_REMOVE_ALL_EXTENTS: return strip_array_types (type1); diff --git a/gcc/testsuite/g++.dg/ext/decay.C b/gcc/testsuite/g++.dg/ext/decay.C new file mode 100644 index 00000000000..8adedfeefe6 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/decay.C @@ -0,0 +1,22 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +// Positive tests. +using test1_type = __decay(bool); +SA(__is_same(test1_type, bool)); + +// NB: DR 705. +using test2_type = __decay(const int); +SA(__is_same(test2_type, int)); + +using test3_type = __decay(int[4]); +SA(__is_same(test3_type, __remove_extent(int[4])*)); + +using fn_type = void (); +using test4_type = __decay(fn_type); +SA(__is_same(test4_type, __add_pointer(fn_type))); + +using cfn_type = void () const; +using test5_type = __decay(cfn_type); +SA(__is_same(test5_type, cfn_type)); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index c2503c5d82b..3aca273aad6 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -11,6 +11,9 @@ #if !__has_builtin (__add_rvalue_reference) # error "__has_builtin (__add_rvalue_reference) failed" #endif +#if !__has_builtin (__decay) +# error "__has_builtin (__decay) failed" +#endif #if !__has_builtin (__builtin_addressof) # error "__has_builtin (__builtin_addressof) failed" #endif