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
This commit is contained in:
Aaron Gokaslan 2023-03-27 20:21:06 -04:00 committed by GitHub
parent 66f12df03b
commit 1e8b52a9ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View File

@ -754,7 +754,16 @@ template <typename C, typename R, typename... A>
struct remove_class<R (C::*)(A...) const> { struct remove_class<R (C::*)(A...) const> {
using type = R(A...); using type = R(A...);
}; };
#ifdef __cpp_noexcept_function_type
template <typename C, typename R, typename... A>
struct remove_class<R (C::*)(A...) noexcept> {
using type = R(A...);
};
template <typename C, typename R, typename... A>
struct remove_class<R (C::*)(A...) const noexcept> {
using type = R(A...);
};
#endif
/// Helper template to strip away type modifiers /// Helper template to strip away type modifiers
template <typename T> template <typename T>
struct intrinsic_type { struct intrinsic_type {

View File

@ -148,4 +148,7 @@ TEST_SUBMODULE(constants_and_functions, m) {
py::arg_v("y", 42, "<the answer>"), py::arg_v("y", 42, "<the answer>"),
py::arg_v("z", default_value)); py::arg_v("z", default_value));
}); });
// test noexcept(true) lambda (#4565)
m.def("l1", []() noexcept(true) { return 0; });
} }

View File

@ -50,3 +50,7 @@ def test_function_record_leaks():
m.register_large_capture_with_invalid_arguments(m) m.register_large_capture_with_invalid_arguments(m)
with pytest.raises(RuntimeError): with pytest.raises(RuntimeError):
m.register_with_raising_repr(m, RaisingRepr()) m.register_with_raising_repr(m, RaisingRepr())
def test_noexcept_lambda():
assert m.l1() == 0