Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: allow noexcept lambdas in C++17. Fix #4565 (#4593)
Browse files Browse the repository at this point in the history
* bugfix: allow noexcept lambdas in CPP17. Fix #4565

* Remove unused code from test case

* Fix clang-tidy error

* Address reviewer comment
Skylion007 authored Mar 28, 2023
1 parent 66f12df commit 1e8b52a
Showing 3 changed files with 17 additions and 1 deletion.
11 changes: 10 additions & 1 deletion include/pybind11/detail/common.h
Original file line number Diff line number Diff line change
@@ -754,7 +754,16 @@ template <typename C, typename R, typename... A>
struct remove_class<R (C::*)(A...) const> {
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
template <typename T>
struct intrinsic_type {
3 changes: 3 additions & 0 deletions tests/test_constants_and_functions.cpp
Original file line number Diff line number Diff line change
@@ -148,4 +148,7 @@ TEST_SUBMODULE(constants_and_functions, m) {
py::arg_v("y", 42, "<the answer>"),
py::arg_v("z", default_value));
});

// test noexcept(true) lambda (#4565)
m.def("l1", []() noexcept(true) { return 0; });
}
4 changes: 4 additions & 0 deletions tests/test_constants_and_functions.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1e8b52a

Please sign in to comment.