From patchwork Wed Feb 28 19:26:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 207982 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3565706dyb; Wed, 28 Feb 2024 11:33:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW3Ra4FIQ5TwAmlBYLtnzpMTrtQgQKl15F+nAgvczFf6LYdHIjww/VQhiiOeP8ixTYHFWqkqxCv0pCYgpkAQwO5d4x1sQ== X-Google-Smtp-Source: AGHT+IHfWK4AfApH8iFtfOeovjMNNcchhAtBc/YtiArODMs2I/R0+LpeqHA635HOvpcPJQSI8iER X-Received: by 2002:ad4:44a7:0:b0:690:696:6031 with SMTP id n7-20020ad444a7000000b0069006966031mr34791qvt.57.1709148787445; Wed, 28 Feb 2024 11:33:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709148787; cv=pass; d=google.com; s=arc-20160816; b=xBrYd28F77TZAqgO+bMU3qAX1cCUrnvDj0NO+R+3Tq8mSgGdpgKj1tuOb6O/D9vwMR IJZrJLpUQ+bYWRBO8LKVsqBjyh9mawUjxvLa0HZhfFmeXpnykishnllYzO+m98rwrYD8 JhpidqfIA4uSCOxtPYOMSAGlCQiwcrD85+0xcF7VY+5a+HwzXdiFmJxCJTBQL0OvwzMs ZDQAzhvhjftkwjaKy+v6f4mnr90DGSPVE0OjLYAXHIGY4ttQijcVI+1ID6pSACpt7Zgr I6jKD8laMAo90UIai7ym3qIfJbRwld+zceUAlaIQfsVdm/iKs/JEmT4ofNmpDAyJiSue Si1Q== 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=54vhQvY9u89chF+BfVzqqGMOWm35HeE38x6xc0xZHIY=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=THFJC1Z46AoVwVWymlB46WFGKM22Ei9lrVBSUyQcgWrmxsNu6cjsDl7G2ovGK1fj4U re9TKKUYMQWnpjq0QMIln7D0nphhsVhvG8Ea+b18tq+vGYhyiK7ZtrhYfG0of6n2XLG5 XQ0trrEkrnv/IwgjlqSwFtZgD26ib47jIL/RVS8m0ChEG5ZgITSirLVmoCTF99d40pYZ W8W2Ro+HbkfTjrl8I6PgtVwFDNsXm2V0EFK5JqVXXdossX08aHeYP2U/nfZULuxqaY0x zl/bOwzOmx+obxMKgNCA8Q70opXDiPtpfu6tttU2BA29WwrOUBzESCc3x9Mw/q/DXGvp xgqg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FdUH8CGl; 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 jt15-20020a05621427ef00b0068ffe744a27si201992qvb.63.2024.02.28.11.33.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:33:07 -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=FdUH8CGl; 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 059D8385828C for ; Wed, 28 Feb 2024 19:33:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 059D8385828C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709148787; bh=54vhQvY9u89chF+BfVzqqGMOWm35HeE38x6xc0xZHIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=FdUH8CGlmqzNgB/Qo51QLLHAGWh6QQZcIjcrpKORQ4yp8245WmZMEWaWtHqUSV9/3 LxZ4rbcCZLr3Llfz/RrkehYXyU3RuUviSgNVQLJCFkdcLoFzYc1Fcm+zEHJn6W9F7h fMAf0t3HxxqghiM1mLACu9SemXlQxwMAF1fKMQyw= 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 9B8FD385842C; Wed, 28 Feb 2024 19:29:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9B8FD385842C 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 9B8FD385842C 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=1709148545; cv=none; b=cD9XPDyeVif1Fx4pe4qld/1Mnk3BjnKmxBdCKI0s22Wl2eLP0ox+vhFvMNGHtBkp9w5x376BpCLAANEb/tP7szumue6A08K350LP3YFPTfkHnoALzwSslWYzOhN7IBKv+zz0t+XP7UHk1fEC/oJg7czn3xadUP9uR4bqnFm8mls= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148545; c=relaxed/simple; bh=fR5N/yEaZh3DXAV+m49zSFdR2KDSPVlC/3ioevoYGVo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=CvSiBDTQi/t2xBzkheK7aKi86mBQ1EeW1l2jN1peWhk7KLgiXjGGzYTZNHlSiUXJ1MaQ3g6MK21jaZUOYUtoz81jSaEd1AZ6GZx21fNthkwZSr98DOFQQyl776VOODaVkA2yzo67sBh67iL3+nuvYzW59loaeiDTQPWmNv1B/6g= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJSLAF012810; Wed, 28 Feb 2024 19:29:01 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj80r9yq8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:29:01 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSq29032387 (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 41SJSoTh015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:52 -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 25/26] c++: Implement __is_nothrow_invocable built-in trait Date: Wed, 28 Feb 2024 11:26:30 -0800 Message-ID: <20240228192843.188979-26-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: ZpYWMXcRSEzqwEwu1wm01IUa0poh1xuF X-Proofpoint-ORIG-GUID: ZpYWMXcRSEzqwEwu1wm01IUa0poh1xuF 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 lowpriorityscore=0 phishscore=0 bulkscore=0 malwarescore=0 impostorscore=0 priorityscore=1501 mlxlogscore=856 mlxscore=0 adultscore=0 spamscore=0 clxscore=1034 suspectscore=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: 1791501072886437442 X-GMAIL-MSGID: 1792172399100528702 This patch implements built-in trait for std::is_nothrow_invocable. gcc/cp/ChangeLog: * cp-trait.def: Define __is_nothrow_invocable. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_NOTHROW_INVOCABLE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_nothrow_invocable. * g++.dg/ext/is_nothrow_invocable.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 6 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + .../g++.dg/ext/is_nothrow_invocable.C | 62 +++++++++++++++++++ 5 files changed, 76 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_nothrow_invocable.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c87b126fdb1..43d4f2102d6 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3824,6 +3824,12 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_NOTHROW_CONVERTIBLE: inform (loc, " %qT is not nothrow convertible from %qE", t2, t1); break; + case CPTK_IS_NOTHROW_INVOCABLE: + if (!t2) + inform (loc, " %qT is not nothrow invocable", t1); + else + inform (loc, " %qT is not nothrow invocable by %qE", t1, t2); + break; case CPTK_IS_OBJECT: inform (loc, " %qT is not an object type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 6cb2b55f4ea..a9714921e94 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -84,6 +84,7 @@ DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) +DEFTRAIT_EXPR (IS_NOTHROW_INVOCABLE, "__is_nothrow_invocable", -1) DEFTRAIT_EXPR (IS_OBJECT, "__is_object", 1) DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2) DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 149c0631d62..dba7b43a109 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12494,6 +12494,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_NOTHROW_CONVERTIBLE: return is_nothrow_convertible (type1, type2); + case CPTK_IS_NOTHROW_INVOCABLE: + return expr_noexcept_p (build_invoke (type1, type2, tf_none), tf_none); + case CPTK_IS_OBJECT: return (type_code1 != FUNCTION_TYPE && type_code1 != REFERENCE_TYPE @@ -12689,6 +12692,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_NOTHROW_ASSIGNABLE: case CPTK_IS_NOTHROW_CONSTRUCTIBLE: case CPTK_IS_NOTHROW_CONVERTIBLE: + case CPTK_IS_NOTHROW_INVOCABLE: case CPTK_IS_TRIVIALLY_ASSIGNABLE: case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index d2a7ebdf25c..624d3525f27 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -131,6 +131,9 @@ #if !__has_builtin (__is_nothrow_convertible) # error "__has_builtin (__is_nothrow_convertible) failed" #endif +#if !__has_builtin (__is_nothrow_invocable) +# error "__has_builtin (__is_nothrow_invocable) failed" +#endif #if !__has_builtin (__is_object) # error "__has_builtin (__is_object) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_nothrow_invocable.C b/gcc/testsuite/g++.dg/ext/is_nothrow_invocable.C new file mode 100644 index 00000000000..2f9b40e5538 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_nothrow_invocable.C @@ -0,0 +1,62 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +using func_type = void(*)(); +SA( ! __is_nothrow_invocable(func_type) ); + +#if __cpp_noexcept_function_type +using func_type_nt = void(*)() noexcept; +SA( __is_nothrow_invocable(func_type_nt) ); +#endif + +struct X { }; +using mem_type = int X::*; + +SA( ! __is_nothrow_invocable(mem_type) ); +SA( ! __is_nothrow_invocable(mem_type, int) ); +SA( ! __is_nothrow_invocable(mem_type, int&) ); +SA( __is_nothrow_invocable(mem_type, X&) ); + +using memfun_type = int (X::*)(); + +SA( ! __is_nothrow_invocable(memfun_type) ); +SA( ! __is_nothrow_invocable(memfun_type, int) ); +SA( ! __is_nothrow_invocable(memfun_type, int&) ); +SA( ! __is_nothrow_invocable(memfun_type, X&) ); +SA( ! __is_nothrow_invocable(memfun_type, X*) ); + +#if __cpp_noexcept_function_type +using memfun_type_nt = int (X::*)() noexcept; + +SA( ! __is_nothrow_invocable(memfun_type_nt) ); +SA( ! __is_nothrow_invocable(memfun_type_nt, int) ); +SA( ! __is_nothrow_invocable(memfun_type_nt, int&) ); +SA( __is_nothrow_invocable(memfun_type_nt, X&) ); +SA( __is_nothrow_invocable(memfun_type_nt, X*) ); +#endif + +struct F { + int& operator()(); + long& operator()() const noexcept; + short& operator()(int) &&; + char& operator()(int) const& noexcept; +private: + void operator()(int, int) noexcept; +}; +using CF = const F; + +SA( ! __is_nothrow_invocable(F ) ); +SA( __is_nothrow_invocable(CF) ); + +SA( ! __is_nothrow_invocable(F, int) ); +SA( __is_nothrow_invocable(F&, int) ); + +SA( __is_nothrow_invocable(CF, int) ); +SA( __is_nothrow_invocable(CF&, int) ); +SA( ! __is_nothrow_invocable(F, int, int) ); + +struct FX { + X operator()() const noexcept { return {}; } +}; +SA( __is_nothrow_invocable(FX) );