From patchwork Wed Feb 28 19:26:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 207990 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3567379dyb; Wed, 28 Feb 2024 11:36:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXEOHNocXVs0XJaZ/UyA8bd3rGwg9s+qgdEG0V72e/7hMxihDdwN6rKlraPtvY+E7ODSnxsMW1HYr54VGe96OhkIn+gdA== X-Google-Smtp-Source: AGHT+IEwp2cUzwLU4LddOMuFJh/Et42ItjNMwd5cbjYx+/qfN3xHVzSDC9w5p8jCKqtW7vmiDzIG X-Received: by 2002:a05:622a:1b9f:b0:42d:dd8a:e63c with SMTP id bp31-20020a05622a1b9f00b0042ddd8ae63cmr16137768qtb.5.1709148992204; Wed, 28 Feb 2024 11:36:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709148992; cv=pass; d=google.com; s=arc-20160816; b=XrCpMJTmIO+Kk3ylVIApFKYtetexaVRD3RqvxRHWvhoGzZg4UGA6ftU2VGM25otRz+ pr34mxx1iCxwZfdS0U3uR7RWeeyHZzd+DGDD/QGfF+BZWWY/zi2qouZf1aZ6lFAmM9wM GAFMTKXogk8Umc3aj3e8qvVWUl4vPGRcSb+ti2wblBR08H+feaNYjjb+ZWOsior71GrV z+0ThAQkDjPkSFQB3QaV+uA/R/kYijMmy/PQcwVbVwR1eqm9e6GGWxEOwLpFpaW9nYPt blPbcxtBuAwyKcaorcHSQYvuQ7lvFkPs/RTj4UJ5+ztCnilqk+D28HfG3aRRZY+ocJs0 oFWw== 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=tKvRVq7l6vwbsPH6YkVrujeRBKeLUCM65oxAufp3rDY=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=mIjDxrkBaqdloqgFCWV3ao/NieCilwc8J2t9F0q0fLCHHRPxSVbJizxeLqoWUVUKlP /Uu6mMzw5MAOk8yb59ILQvomI6Kz59WvnES6tb0PlAU6yjpjRnCjfz4dK6b0/BjOWLA5 l/FIz3+resR5zKdjNK0ukADBhvBtm7ZWODjIuYxqghOiDncG5E84l85+8pdAWCxRJmlI pOtDvjlE5VI9EpQTL+EE6VgO5Cw3yrQ7dkEzylLeHJ7mDTJAyXNmAyv3nZUpGCN6p4dl 2BBL1sfYKMLGl9SeweQpjoz7b4n48Mg1dhCo99vpX19RKjr+p2I4nMQgwf40pHb2s1W5 a0sQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=U9WvT9Bi; 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 v6-20020ac87486000000b0042e8b562c2csi118049qtq.425.2024.02.28.11.36.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:36:32 -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=U9WvT9Bi; 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 C2E0A3858438 for ; Wed, 28 Feb 2024 19:36:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C2E0A3858438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709148991; bh=tKvRVq7l6vwbsPH6YkVrujeRBKeLUCM65oxAufp3rDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=U9WvT9BiA5YlRn8jI0p3yVdCphPM7Cuenrb51wbiL0yQGAcUAfhtxZVqyHZen7Xyl ozJZfGAMH4vbo2LhW0LVlZ5tBi3BEdRmPfcK81ph/+WX9IQ1rTS1TwxdDoQxsJN08u 6NXVXZCWbo1UZLTW6sm/Xp5ler0mnZUC0qOTYlUM= 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 A103F385800D; Wed, 28 Feb 2024 19:29:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A103F385800D 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 A103F385800D 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=1709148573; cv=none; b=VpplyUISFtfUEQeqvENKIy0UERv8If4w7ImAi8k+dcq6jsME0ajGGWYlBeCwbbUWTUP4TMNoow3OAfMg0kmUnOKLlWWbe5PbR5Fw2V+gVepyLINwbVB+s6r+cjKx9oSV6/abwga3NEqCrl39OVcylxms4EFKmk6qA8RP5Hl38Rc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148573; c=relaxed/simple; bh=T+eF/ckLGijloNSkdNnsGtm2fWD7Gp2Q3TVqEDOcdTI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=kIjIotMtVFnsHhqrn3NT09cP5oz5B96NrmM5KSWLZrI1XejtKd/ELGsFYw6ltunBnlmZCGkrqFi5TnnqcvdXspltKiOGzUe/z8tPRwNFxe2gEjDfV7nQY74MFPdA/jh0TqeOlZulyUaFHKpMbs/Xn+wl4kmdUwM2NpJdR2quwFo= 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 41SJDFPa021389; Wed, 28 Feb 2024 19:29:21 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj9nb90vn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:29:21 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSpe2019399 (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 41SJSoTX015429 (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 15/26] c++: Implement __add_lvalue_reference built-in trait Date: Wed, 28 Feb 2024 11:26:20 -0800 Message-ID: <20240228192843.188979-16-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: hSk_dRoubolV20U8LjAiY3dMWb9xU-yN X-Proofpoint-ORIG-GUID: hSk_dRoubolV20U8LjAiY3dMWb9xU-yN 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 suspectscore=0 impostorscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 clxscore=1034 mlxlogscore=769 mlxscore=0 spamscore=0 phishscore=0 malwarescore=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: 1791501217722010132 X-GMAIL-MSGID: 1792172613946966146 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