From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id DAA243858C56 for ; Tue, 30 Apr 2024 21:09:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DAA243858C56 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DAA243858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714511383; cv=none; b=RntcGpE5+AH9KLfSPyl1fGvAMaI9M7CMxagBezCPHPyJU2pLu0rccaAQ9GbOdK9Vk9SmIE+jgW5iYaubhLy3j3qMyF8VQGxWDRUduVrEb9iesSZe/8RWnjQjtQ6ruVmmGIowwk/SaUTe0XY+v+nabOUn/6kcMk3VSm7kXDSkCXE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714511383; c=relaxed/simple; bh=o94i4YGCqpDN66w2HjoyNCRbsBCWWQHBzq827JNtZKQ=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=lM1pvVpUxsrTGntKCw0gREEjryEYV+RO6INHXtCRjiLaykxXHriIsdek7RQhwJ6xRQIAFON4fPG09804GYuymtliIX+FIq5AmDB6Qf60A+mPLOKCEJ8jVDDPXOCjqhy/0YkO7O+yJ04WpN4hBiuco0LBo114c83eAFauhV3/W6g= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714511381; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jl+2YwL9JzA+yNS03qpkWLUo3c1qxjaTZMxtz/71iEk=; b=Zo1rgw4R155fVCGoEYWw13Yt74W1q/J0iOB0S+j5GVPGI097iePXCV7HSWr4EwvQ2p73Yd Ntkj239QmhU3U7QoCipgb+4T5a22Duu++2p3Ssc6HZtScTrcHnWmRTWUKIPgeS74c/72rW 6bGl10JOg03iqRucbmiW31+hRH5vUts= Received: from mail-yw1-f200.google.com (mail-yw1-f200.google.com [209.85.128.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-150-Fo07E9WEOOKKEMIBy2KJDg-1; Tue, 30 Apr 2024 17:09:39 -0400 X-MC-Unique: Fo07E9WEOOKKEMIBy2KJDg-1 Received: by mail-yw1-f200.google.com with SMTP id 00721157ae682-61c9675ae5aso14143787b3.0 for ; Tue, 30 Apr 2024 14:09:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714511377; x=1715116177; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jl+2YwL9JzA+yNS03qpkWLUo3c1qxjaTZMxtz/71iEk=; b=c21/T3uN65PP0k5vO4zkTCHQyJVq1nbVuViNKUNTUZ+L0SPLZJUT7/tdoUfoQs5/ZZ 4a9jOEo0iVFhz50XvDN7/PGdqXx3r0EW0a0RTTGgq+KqOj9NvgdtBn0UNW0gRT3TzeYD ab15I8GsWJ4Lc8ynO4H/2dtpsYkIa984jl5FxYoMbh3LRl2OpFy6rAf4YBE3dfA/lXN/ zlbEmqdKnZXvH/IWvc/9Fbwfo63OtCYmEH0LbnTybo0moSuzLs0nRF9aXLCQdMy4jqwA gELK15NOghNBVYtj4mkfMkiPpwhCwtEjb+Wg5TjzufRpH6CRTPtS4Wr5uX27qha5uaaa mOsw== X-Gm-Message-State: AOJu0YxV5aGxpEEKR4KAqNEzt2v4+MnS32VXEEHpscswo9TCoEjpoBJV /BMR/3MnHzM/TCCHNNXJa5jsaxZJekVUKecqTtOBPRIykxj26rfshqRcsfPE+n1PK57Kd4Aewwo MAVN6tiMrARmqhYUxKwn06IhcYZ8lYik+GN2yTCUvbpNnOtM0Tr8u X-Received: by 2002:a05:690c:4d43:b0:61b:1c75:2077 with SMTP id iy3-20020a05690c4d4300b0061b1c752077mr924810ywb.7.1714511377647; Tue, 30 Apr 2024 14:09:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGBXBoRYGAf31JwHte+6PyAO2cp+OLthj9Q4ViWmonWrwcevJ8Of0ksIsXKBUieKvmkKDDyCA== X-Received: by 2002:a05:690c:4d43:b0:61b:1c75:2077 with SMTP id iy3-20020a05690c4d4300b0061b1c752077mr924792ywb.7.1714511377342; Tue, 30 Apr 2024 14:09:37 -0700 (PDT) Received: from [192.168.1.130] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id 13-20020ac8564d000000b00434d86fb403sm11715137qtt.86.2024.04.30.14.09.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Apr 2024 14:09:36 -0700 (PDT) Message-ID: Date: Tue, 30 Apr 2024 17:09:36 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v14 25/26] c++: Implement __is_nothrow_invocable built-in trait To: Ken Matsui , gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240228192843.188979-26-kmatsui@gcc.gnu.org> From: Jason Merrill In-Reply-To: <20240228192843.188979-26-kmatsui@gcc.gnu.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2/28/24 11:26, Ken Matsui wrote: > This patch implements built-in trait for std::is_nothrow_invocable. OK after addressing comments on other traits. > 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) );