From 1e8b52a9acea1aa7a322fe6a87049c4828e439f9 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Mon, 27 Mar 2023 20:21:06 -0400 Subject: [PATCH] bugfix: allow noexcept lambdas in C++17. Fix #4565 (#4593) * bugfix: allow noexcept lambdas in CPP17. Fix #4565 * Remove unused code from test case * Fix clang-tidy error * Address reviewer comment --- include/pybind11/detail/common.h | 11 ++++++++++- tests/test_constants_and_functions.cpp | 3 +++ tests/test_constants_and_functions.py | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index 1032293d21..129039252f 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -754,7 +754,16 @@ template struct remove_class { using type = R(A...); }; - +#ifdef __cpp_noexcept_function_type +template +struct remove_class { + using type = R(A...); +}; +template +struct remove_class { + using type = R(A...); +}; +#endif /// Helper template to strip away type modifiers template struct intrinsic_type { diff --git a/tests/test_constants_and_functions.cpp b/tests/test_constants_and_functions.cpp index 922375c5ea..312edca9e0 100644 --- a/tests/test_constants_and_functions.cpp +++ b/tests/test_constants_and_functions.cpp @@ -148,4 +148,7 @@ TEST_SUBMODULE(constants_and_functions, m) { py::arg_v("y", 42, ""), py::arg_v("z", default_value)); }); + + // test noexcept(true) lambda (#4565) + m.def("l1", []() noexcept(true) { return 0; }); } diff --git a/tests/test_constants_and_functions.py b/tests/test_constants_and_functions.py index 5da0b84b8e..a1142461c0 100644 --- a/tests/test_constants_and_functions.py +++ b/tests/test_constants_and_functions.py @@ -50,3 +50,7 @@ def __repr__(self): m.register_large_capture_with_invalid_arguments(m) with pytest.raises(RuntimeError): m.register_with_raising_repr(m, RaisingRepr()) + + +def test_noexcept_lambda(): + assert m.l1() == 0