c++: DR 1722: Make lambda to function pointer conv noexcept [PR90583]
authorMarek Polacek <polacek@redhat.com>
Mon, 21 Sep 2020 17:24:25 +0000 (13:24 -0400)
committerMarek Polacek <polacek@redhat.com>
Mon, 21 Sep 2020 22:13:37 +0000 (18:13 -0400)
DR 1722 clarifies that the conversion function from lambda to pointer to
function should be noexcept(true).

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
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv14.C [new file with mode: 0644]

index 364a3e9f6b9e7056c999a86ba47e7f98911a83c3..7fccccc6e14ea634f963549786882cc907c8c5b1 100644 (file)
@@ -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 (file)
index 0000000..869e0d5
--- /dev/null
@@ -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)), "");
+}