From patchwork Wed Feb 28 19:26:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 207996 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3568263dyb; Wed, 28 Feb 2024 11:38:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVCAD2MCUsnNbrE9KzyzOiO5z5WyimIMf/X3t2lSKHtvBjK1UrkZAmaOdceZBQ8TC9vQLVBqOUlVLBldCEUEt4678QjVA== X-Google-Smtp-Source: AGHT+IFb1wSTfCEbvHkz5b2VM7b2mH7yJH05Jj2tZBF/DNLdEJgrbbL+Z/dqa2gb4qjKB3VxS53l X-Received: by 2002:a05:620a:3712:b0:787:32a2:ac24 with SMTP id de18-20020a05620a371200b0078732a2ac24mr26486qkb.59.1709149107750; Wed, 28 Feb 2024 11:38:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149107; cv=pass; d=google.com; s=arc-20160816; b=LaXhNrPK+d1K3uWEV6zt+iTcmWvFkgp7N4NqbY9qLfURXau9iQoZTDCe95nHhgNeAf iA7aMzBbA33HiHA8xxQJ2/Qcn4pHjQuQ199XvYUIjEZhN92ixTjrA6/AsraiVlIaX7AL 8uPlo77LLQyNj6X7ts7oqpajHv1Rneec2Ubs7J9RFOYjbfdRmSNj4kiUZuMKYjKp18CB ByMsSdrctN4E2SgiyP1NuZiCTedE/N3m3lb0y6sreWcezTTBlZ4VaVL7DxBrsRRaRh42 wB4LFzp4uVEKZXrBXymOR3Oxtp5AGi5Qfzy4SYwalRYMtjoMo5WDKFGBf4X9q3bIUYdQ a2Jw== 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=3EZuA1B/ksPpfjZ2xh9r7uKZL3aWvZmmSEkF39VTjSc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=IPc4wixSnIuOVtLik1NBOo6Ti1+hIQP5cXKf/0HrCvxQY5X/iFInqqrNj21t0Z6W2V GpX0nPW21pheYN2H7YARepFGUJoeWRdqQA7UNRprKN1Cpa/i+DSHd9SCJCO61PPJms+f ATN//+rar5SDzhg5ooSyCjO+UUZ5F1w8mSCa8G06kcZOP80Uv0emV4u/QRZXAwYwjYA4 443cM67/psysYqyfUDCW1fexOJF68yK3cRdpQlY78ZMN5HMakfuggYYgAV2JtSY2zvC0 EcmSE170xbqYDwoffv+ogQAt3QVVHuou/w0xlzXfD4cvoqQEo0GOOL+Civ+qwOxBRiD/ +WIQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hgDPOe4L; 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 po9-20020a05620a384900b007874ee5955esi187852qkn.475.2024.02.28.11.38.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:38:27 -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=hgDPOe4L; 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 4994B385842C for ; Wed, 28 Feb 2024 19:38:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4994B385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149107; bh=3EZuA1B/ksPpfjZ2xh9r7uKZL3aWvZmmSEkF39VTjSc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=hgDPOe4LsWoVwsYWfhKpJuMoxhLpoGtOJG38sxOiZJuKHuApjwBN1NnRc+Ds5GSuQ ZwUdmAIV7Yy7Fovwu0u6UJTuVu+gi8FtX9tazXo0JYquMSCJBtLuk7qZaPjf0r98kg EeY9Fj2bqWlXG8CF4Z6PxTG2V9NEDVhT2/CyC+HA= 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 A45EF38582B7; Wed, 28 Feb 2024 19:29:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A45EF38582B7 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 A45EF38582B7 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148551; cv=none; b=Yu//ImiIi+4vo/wYRJxEGXb3cXX+7ZmzInX73jBMD/FgFUCl9hwoZLkqCAX0rvy2ZCOxFi7eaEwlGeoOSoqrYHH3u+EAqwrmqy+/dzq1/nKoLDeBlzW2JzIkyx026GhnM1PpJPp64pHMnCTzkzusOz7l4n3ctlawURWka7DAcY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148551; c=relaxed/simple; bh=Cy52qonx7cmWVT63RHPOoDcdAI6F8a0OdY6rJhb75IQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=S7zFVetQ3QugaFctVkOIxszfTeRWaqCj5fV3a8vztlU69sLdoEzPsvpQtBbvHvlOkn1LL/fYYORQQ16sVMYQyZ8QIEYhLCBUeyMXZ3cyB+Z2H+wUYh+iJIUCQuhJq8JF+wqWVNng8Eh+/LQCM8m8zr+PEfwmLOyaogfpNvM6/jc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJSh9F001591; Wed, 28 Feb 2024 19:29:05 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj9n6h219-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:29:05 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSppM010162 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:51 -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 41SJSoTZ015429 (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 17/26] c++: Implement __add_rvalue_reference built-in trait Date: Wed, 28 Feb 2024 11:26:22 -0800 Message-ID: <20240228192843.188979-18-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: 1mdR-SRJFrRQTnTiIHeQ1m7leZToe-BX X-Proofpoint-ORIG-GUID: 1mdR-SRJFrRQTnTiIHeQ1m7leZToe-BX 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 clxscore=1034 suspectscore=0 malwarescore=0 phishscore=0 impostorscore=0 spamscore=0 mlxlogscore=324 bulkscore=0 priorityscore=1501 lowpriorityscore=0 mlxscore=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.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, 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: 1791500829273767658 X-GMAIL-MSGID: 1792172735075390129 This patch implements built-in trait for std::add_rvalue_reference. gcc/cp/ChangeLog: * cp-trait.def: Define __add_rvalue_reference. * semantics.cc (finish_trait_type): Handle CPTK_ADD_RVALUE_REFERENCE. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __add_rvalue_reference. * g++.dg/ext/add_rvalue_reference.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 8 ++++++++ .../g++.dg/ext/add_rvalue_reference.C | 20 +++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ 4 files changed, 32 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/add_rvalue_reference.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 9a27dca4ea3..173818adf79 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -50,6 +50,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_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 05f5b62f9df..19d6f87a9ea 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12793,6 +12793,14 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, type1 = TREE_TYPE (type1); return build_pointer_type (type1); + case CPTK_ADD_RVALUE_REFERENCE: + if (VOID_TYPE_P (type1) + || (FUNC_OR_METHOD_TYPE_P (type1) + && (type_memfn_quals (type1) != TYPE_UNQUALIFIED + || type_memfn_rqual (type1) != REF_QUAL_NONE))) + return type1; + return cp_build_reference_type (type1, /*rval=*/true); + case CPTK_REMOVE_ALL_EXTENTS: return strip_array_types (type1); diff --git a/gcc/testsuite/g++.dg/ext/add_rvalue_reference.C b/gcc/testsuite/g++.dg/ext/add_rvalue_reference.C new file mode 100644 index 00000000000..c92fe6bfa17 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/add_rvalue_reference.C @@ -0,0 +1,20 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__add_rvalue_reference(int), int&&)); +SA(__is_same(__add_rvalue_reference(int&&), int&&)); +SA(__is_same(__add_rvalue_reference(int&), int&)); +SA(__is_same(__add_rvalue_reference(const int), const int&&)); +SA(__is_same(__add_rvalue_reference(int*), int*&&)); +SA(__is_same(__add_rvalue_reference(ClassType&&), ClassType&&)); +SA(__is_same(__add_rvalue_reference(ClassType), ClassType&&)); +SA(__is_same(__add_rvalue_reference(int(int)), int(&&)(int))); +SA(__is_same(__add_rvalue_reference(void), void)); +SA(__is_same(__add_rvalue_reference(const void), const void)); +SA(__is_same(__add_rvalue_reference(bool(int) const), bool(int) const)); +SA(__is_same(__add_rvalue_reference(bool(int) &), bool(int) &)); +SA(__is_same(__add_rvalue_reference(bool(int) const &&), bool(int) const &&)); +SA(__is_same(__add_rvalue_reference(bool(int)), bool(&&)(int))); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 3fca9cfabcc..c2503c5d82b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -8,6 +8,9 @@ #if !__has_builtin (__add_pointer) # error "__has_builtin (__add_pointer) failed" #endif +#if !__has_builtin (__add_rvalue_reference) +# error "__has_builtin (__add_rvalue_reference) failed" +#endif #if !__has_builtin (__builtin_addressof) # error "__has_builtin (__builtin_addressof) failed" #endif