From patchwork Wed Feb 21 09:36:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 204084 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp931556dyc; Wed, 21 Feb 2024 01:44:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUEVEHPVK2qdGOXl571YoHtWn5oV4b/wiIJ7l6lWQDsKNQtoOWzfUUEx8ecOwCggGM3+HrbVsWERRnTjzkGARHNhhhF6Q== X-Google-Smtp-Source: AGHT+IE7VNLyq8CyMx1Uw8ZBGBrxfjOZ3aoxiJUzjMekOlHic2h9NqBs82EboW48NAlSTjgW4A9M X-Received: by 2002:a0c:aad1:0:b0:68f:5fce:66f1 with SMTP id g17-20020a0caad1000000b0068f5fce66f1mr5525989qvb.46.1708508699411; Wed, 21 Feb 2024 01:44:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708508699; cv=pass; d=google.com; s=arc-20160816; b=XPiCQzAFxehO7quPKE5UUyGbcUJDE+IIWj64bzPrLSeXgRy85SmXGB/97GGElCfXsy et7GOJu9wpRT5TLfk68qznmLYEUaTp3HNqUPnAolNC+UN/edBWaEqZwBopzFq4C1yrJl f0XaBKHjxUoR+KNbvc+xDHf0VfGL84SSzC5+Qe1JLVbCXOnFB2LV8hepmYy6g9JF1bkf jO/6J+rIlR3wynm9oCz/msHiiwxbL2BbZ+gqooAEQf7Y0Oda45arVJdu5UZkqeMK3Rp7 YMeDoeb7qgli2v3Z5YHRmEpXwjjnEtHupyyrAw1nFUIi5v8G50qAUF/2gDGjIv4jsIQI tzzA== 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=GDtFMAilfS5gi2cQB1DByGMTWM/wn1wLdvCJkd2amIQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=L6cHjOhiGMRt17OlCANlUwC88tGLMZUGJ9rz/r8fS+IIym+Va8Z67hZCwPKsRJlNb2 4GQ+57ZkiGDdB/fOR/sTKdQY6IEjURYwsmagif5JCYquRS/EJSV4p8gJWNxHht2eXY99 tfrP6xQg9+MnnCUWgRSJhGtHXDxjDYxL4J18ukLEcJcHtjXLtmw1jz/w0n0LZ7trG0Mz 4hV+SalUa0ZUDWF91we9hTUcOzLz/9DIFPpxtFpsKjRfJ9uf0X7pyB+iNiEQ0DB5VlCP TB1YgKI4G+2gihMprYtOyHWnOzrmSRznb3BJab6ZlEs3lz5YbMHHZ1NIXP3Dcje04EbW qrOg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ySY6YSRU; 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 r3-20020ad45763000000b0068fa92b8f5dsi472520qvx.427.2024.02.21.01.44.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 01:44:59 -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=ySY6YSRU; 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 04A7E3858426 for ; Wed, 21 Feb 2024 09:44:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 04A7E3858426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708508699; bh=GDtFMAilfS5gi2cQB1DByGMTWM/wn1wLdvCJkd2amIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ySY6YSRUrABZlMiy61mm5sKTS5Tpd5A81GrR+ZScGst5Dvs5yFU8n717orguwg475 RVvax/BvoW+snDgeVoBsDQCthziKbdNG7kzLVni3QKfB/410tgtwXep8nylIObqdL1 UETjp6MjyzO5c8aPtLR3UO7Hdv6geCD6uh+BxXOU= 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 D8C2C3858C3A; Wed, 21 Feb 2024 09:36:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8C2C3858C3A 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 D8C2C3858C3A 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=1708508198; cv=none; b=t5/kJFdTQFimOSzhMN2lWVnBwqsPdZIIYl/w+t6SeP0tRbl203w62HtxiQGfXEIwsEJf6HKlKDjQCF5zo051wi1HuzYUv7zjfLrn8LAD0qRzE2oM2Wt4vYTSrH+OIFYJ6Xdte21fyiGkk/CDm844T5c6UXpwCbX4+Oeqf+doQVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708508198; c=relaxed/simple; bh=ALiH/t72ZeLC0Tc+KDQhGfZYYsI/l+YYTlZOHR142YE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=tjAHhjVNeN939d8xvJW4BjrHYxKefEdH8AQ1IU4JDN/qcmcBHeg0sOSM3idKG98T4/dp9dAdUnbK1AsRcavOlVuUlH3HSq+MeJP1IfVHCI+thit91h8ZACIWsFUpZQwTng+KenN2YwKNrtqC19B+2bHsn/mmIiv6mP+pqCoV1DQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247473.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41L9PL7E031762; Wed, 21 Feb 2024 09:36:35 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wd56dbe52-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Feb 2024 09:36:34 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41L9aK9G019130 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Feb 2024 01:36:20 -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 41L9aJVf002942 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Feb 2024 01:36:20 -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 v13 15/26] c++: Implement __add_lvalue_reference built-in trait Date: Wed, 21 Feb 2024 01:36:05 -0800 Message-ID: <20240221093616.4001742-15-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> References: <20240221085142.3779280-26-kmatsui@gcc.gnu.org> <20240221093616.4001742-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: K4lv5eEoql_WdcGQtyEfNAWuUAxc2jXh X-Proofpoint-GUID: K4lv5eEoql_WdcGQtyEfNAWuUAxc2jXh 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-20_06,2024-02-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=769 suspectscore=0 malwarescore=0 bulkscore=0 adultscore=0 spamscore=0 phishscore=0 impostorscore=0 mlxscore=0 lowpriorityscore=0 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402210074 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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: 1791501217722010132 X-GMAIL-MSGID: 1791501217722010132 This patch implements built-in trait for std::add_lvalue_reference. gcc/cp/ChangeLog: * cp-trait.def: Define __add_lvalue_reference. * semantics.cc (finish_trait_type): Handle CPTK_ADD_LVALUE_REFERENCE. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __add_lvalue_reference. * g++.dg/ext/add_lvalue_reference.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 8 +++++++ .../g++.dg/ext/add_lvalue_reference.C | 21 +++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ 4 files changed, 33 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/add_lvalue_reference.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 933c8bcbe68..9a27dca4ea3 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -48,6 +48,7 @@ #define DEFTRAIT_TYPE_DEFAULTED #endif +DEFTRAIT_TYPE (ADD_LVALUE_REFERENCE, "__add_lvalue_reference", 1) DEFTRAIT_TYPE (ADD_POINTER, "__add_pointer", 1) DEFTRAIT_EXPR (HAS_NOTHROW_ASSIGN, "__has_nothrow_assign", 1) DEFTRAIT_EXPR (HAS_NOTHROW_CONSTRUCTOR, "__has_nothrow_constructor", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 078424dac23..05f5b62f9df 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12776,6 +12776,14 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, switch (kind) { + case CPTK_ADD_LVALUE_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=*/false); + case CPTK_ADD_POINTER: if (FUNC_OR_METHOD_TYPE_P (type1) && (type_memfn_quals (type1) != TYPE_UNQUALIFIED diff --git a/gcc/testsuite/g++.dg/ext/add_lvalue_reference.C b/gcc/testsuite/g++.dg/ext/add_lvalue_reference.C new file mode 100644 index 00000000000..8fe1e0300e5 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/add_lvalue_reference.C @@ -0,0 +1,21 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__add_lvalue_reference(int), int&)); +SA(__is_same(__add_lvalue_reference(int&), int&)); +SA(__is_same(__add_lvalue_reference(const int), const int&)); +SA(__is_same(__add_lvalue_reference(int*), int*&)); +SA(__is_same(__add_lvalue_reference(ClassType&), ClassType&)); +SA(__is_same(__add_lvalue_reference(ClassType), ClassType&)); +SA(__is_same(__add_lvalue_reference(int(int)), int(&)(int))); +SA(__is_same(__add_lvalue_reference(int&&), int&)); +SA(__is_same(__add_lvalue_reference(ClassType&&), ClassType&)); +SA(__is_same(__add_lvalue_reference(void), void)); +SA(__is_same(__add_lvalue_reference(const void), const void)); +SA(__is_same(__add_lvalue_reference(bool(int) const), bool(int) const)); +SA(__is_same(__add_lvalue_reference(bool(int) &), bool(int) &)); +SA(__is_same(__add_lvalue_reference(bool(int) const &&), bool(int) const &&)); +SA(__is_same(__add_lvalue_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 85b74bd676b..3fca9cfabcc 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -2,6 +2,9 @@ // { dg-do compile } // Verify that __has_builtin gives the correct answer for C++ built-ins. +#if !__has_builtin (__add_lvalue_reference) +# error "__has_builtin (__add_lvalue_reference) failed" +#endif #if !__has_builtin (__add_pointer) # error "__has_builtin (__add_pointer) failed" #endif