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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 851A73857C40 for ; Mon, 21 Sep 2020 19:57:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 851A73857C40 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-27-0wOQrT0BPw65ebUxmeJ7uQ-1; Mon, 21 Sep 2020 15:57:31 -0400 X-MC-Unique: 0wOQrT0BPw65ebUxmeJ7uQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5E62F909CAC for ; Mon, 21 Sep 2020 19:57:30 +0000 (UTC) Received: from pdp-11.redhat.com (ovpn-119-66.rdu2.redhat.com [10.10.119.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE9B778823; Mon, 21 Sep 2020 19:57:29 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: DR 1722: Make lambda to function pointer conv noexcept [PR90583] Date: Mon, 21 Sep 2020 15:57:25 -0400 Message-Id: <20200921195725.2820224-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.6 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_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Sep 2020 19:57:34 -0000 DR 1722 clarifies that the conversion function from lambda to pointer to function should be noexcept(true). Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? gcc/cp/ChangeLog: PR c++/90583 DR 1722 * lambda.c (maybe_add_lambda_conv_op): Mark the conversion function as noexcept. gcc/testsuite/ChangeLog: PR c++/90583 DR 1722 * g++.dg/cpp0x/lambda/lambda-conv14.C: New test. --- gcc/cp/lambda.c | 2 ++ gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv14.C | 10 ++++++++++ 2 files changed, 12 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv14.C diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index c94fe8edb8e..c34d68d3da3 100644 --- a/gcc/cp/lambda.c +++ b/gcc/cp/lambda.c @@ -1189,6 +1189,8 @@ maybe_add_lambda_conv_op (tree type) tree name = make_conv_op_name (rettype); tree thistype = cp_build_qualified_type (type, TYPE_QUAL_CONST); tree fntype = build_method_type_directly (thistype, rettype, void_list_node); + /* DR 1722: The conversion function should be noexcept. */ + fntype = build_exception_variant (fntype, noexcept_true_spec); tree convfn = build_lang_decl (FUNCTION_DECL, name, fntype); SET_DECL_LANGUAGE (convfn, lang_cplusplus); tree fn = convfn; diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv14.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv14.C new file mode 100644 index 00000000000..869e0d51d2b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv14.C @@ -0,0 +1,10 @@ +// PR c++/90583 +// DR 1722: Lambda to function pointer conversion should be noexcept. +// { dg-do compile { target c++11 } } + +void +foo () +{ + auto l = [](int){ return 42; }; + static_assert(noexcept((int (*)(int))(l)), ""); +} base-commit: b0c990f2661a2979c68c840781847efe27a0779b -- 2.26.2