From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 74734384AB65; Thu, 2 May 2024 16:16:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 74734384AB65 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 74734384AB65 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=1714666609; cv=none; b=e9+4SIwGy0HQdmnRfJnedlGcOVi8aAgYcUQHR0ioOmPk1chITIUTf3KHijo19XOeM8p3NAogMpoGneg3vPCdZo0JNxj6uoXVzXCpEizCD2RhYU0YYEkBYyAg0oVVunXqhK+uwyqnlhtm7bNusNbzI+NyioFZ922HstD2iiwMD6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666609; c=relaxed/simple; bh=rBbkLefTMxWrza9oDQXdAbRBnvIw7ce2q0/l0wik0Bg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=t1Za4C1kxyzvBwflsNVOlZp8//FXcgBbvW1QdKfGSf2s2NvTWguMAcC+ksdkf7Xv0aMJLuXbQmz/QJ7tz1LorUglWALRak+9DQ2rnfXcJxSMeaMR3ToITugQJDt9SYViOwWgbxhXIQP/bckbBtNyiZyiaS9pHvqX59y2S6U3khs= 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.18.1.2/8.18.1.2) with ESMTP id 442GEW0G022508; Thu, 2 May 2024 16:16:38 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e3behd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:37 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGOe024920 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFou023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 17/26] c++: Implement __builtin_add_rvalue_reference trait Date: Thu, 2 May 2024 09:13:43 -0700 Message-ID: <20240502161614.3705912-18-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-ORIG-GUID: Gqe_n6pPIrb4AMorRgspce-HPhi6avr2 X-Proofpoint-GUID: Gqe_n6pPIrb4AMorRgspce-HPhi6avr2 X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 malwarescore=0 suspectscore=0 phishscore=0 impostorscore=0 spamscore=0 clxscore=1034 bulkscore=0 lowpriorityscore=0 mlxlogscore=666 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 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 List-Id: This patch implements built-in trait for std::add_rvalue_reference. gcc/cp/ChangeLog: * cp-trait.def: Define __builtin_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 __builtin_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 | 6 ++++++ .../g++.dg/ext/add_rvalue_reference.C | 20 +++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ 4 files changed, 30 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 228df46e3e4..c6fb2aa5f1e 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -50,6 +50,7 @@ DEFTRAIT_TYPE (ADD_LVALUE_REFERENCE, "__builtin_add_lvalue_reference", 1) DEFTRAIT_TYPE (ADD_POINTER, "__builtin_add_pointer", 1) +DEFTRAIT_TYPE (ADD_RVALUE_REFERENCE, "__builtin_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 9f2220a1a91..fd6d9fc1dc5 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12936,6 +12936,12 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, } return type1; + case CPTK_ADD_RVALUE_REFERENCE: + /* [meta.trans.ref]. */ + if (referenceable_type_p (type1)) + return cp_build_reference_type (type1, /*rval=*/true); + return type1; + 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..3c09c5b05d6 --- /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(__builtin_add_rvalue_reference(int), int&&)); +SA(__is_same(__builtin_add_rvalue_reference(int&&), int&&)); +SA(__is_same(__builtin_add_rvalue_reference(int&), int&)); +SA(__is_same(__builtin_add_rvalue_reference(const int), const int&&)); +SA(__is_same(__builtin_add_rvalue_reference(int*), int*&&)); +SA(__is_same(__builtin_add_rvalue_reference(ClassType&&), ClassType&&)); +SA(__is_same(__builtin_add_rvalue_reference(ClassType), ClassType&&)); +SA(__is_same(__builtin_add_rvalue_reference(int(int)), int(&&)(int))); +SA(__is_same(__builtin_add_rvalue_reference(void), void)); +SA(__is_same(__builtin_add_rvalue_reference(const void), const void)); +SA(__is_same(__builtin_add_rvalue_reference(bool(int) const), bool(int) const)); +SA(__is_same(__builtin_add_rvalue_reference(bool(int) &), bool(int) &)); +SA(__is_same(__builtin_add_rvalue_reference(bool(int) const &&), bool(int) const &&)); +SA(__is_same(__builtin_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 77c65f9c920..fc66c816887 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 (__builtin_add_pointer) # error "__has_builtin (__builtin_add_pointer) failed" #endif +#if !__has_builtin (__builtin_add_rvalue_reference) +# error "__has_builtin (__builtin_add_rvalue_reference) failed" +#endif #if !__has_builtin (__builtin_bit_cast) # error "__has_builtin (__builtin_bit_cast) failed" #endif -- 2.44.0