Skip to content

Commit 1e8b52a

Browse files
authored
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
1 parent 66f12df commit 1e8b52a

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

include/pybind11/detail/common.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,16 @@ template <typename C, typename R, typename... A>
754754
struct remove_class<R (C::*)(A...) const> {
755755
using type = R(A...);
756756
};
757-
757+
#ifdef __cpp_noexcept_function_type
758+
template <typename C, typename R, typename... A>
759+
struct remove_class<R (C::*)(A...) noexcept> {
760+
using type = R(A...);
761+
};
762+
template <typename C, typename R, typename... A>
763+
struct remove_class<R (C::*)(A...) const noexcept> {
764+
using type = R(A...);
765+
};
766+
#endif
758767
/// Helper template to strip away type modifiers
759768
template <typename T>
760769
struct intrinsic_type {

tests/test_constants_and_functions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,7 @@ TEST_SUBMODULE(constants_and_functions, m) {
148148
py::arg_v("y", 42, "<the answer>"),
149149
py::arg_v("z", default_value));
150150
});
151+
152+
// test noexcept(true) lambda (#4565)
153+
m.def("l1", []() noexcept(true) { return 0; });
151154
}

tests/test_constants_and_functions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ def __repr__(self):
5050
m.register_large_capture_with_invalid_arguments(m)
5151
with pytest.raises(RuntimeError):
5252
m.register_with_raising_repr(m, RaisingRepr())
53+
54+
55+
def test_noexcept_lambda():
56+
assert m.l1() == 0

0 commit comments

Comments
 (0)