* [PATCH] c++: DR 1722: Make lambda to function pointer conv noexcept [PR90583]
@ 2020-09-21 19:57 Marek Polacek
2020-09-21 21:48 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2020-09-21 19:57 UTC (permalink / raw)
To: Jason Merrill, GCC Patches
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: DR 1722: Make lambda to function pointer conv noexcept [PR90583]
2020-09-21 19:57 [PATCH] c++: DR 1722: Make lambda to function pointer conv noexcept [PR90583] Marek Polacek
@ 2020-09-21 21:48 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2020-09-21 21:48 UTC (permalink / raw)
To: Marek Polacek, GCC Patches
On 9/21/20 3:57 PM, Marek Polacek wrote:
> 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?
OK.
> 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
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-09-21 21:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-21 19:57 [PATCH] c++: DR 1722: Make lambda to function pointer conv noexcept [PR90583] Marek Polacek
2020-09-21 21:48 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).