diff options
Diffstat (limited to 'ext/pybind11/tests/test_constants_and_functions.cpp')
-rw-r--r-- | ext/pybind11/tests/test_constants_and_functions.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/ext/pybind11/tests/test_constants_and_functions.cpp b/ext/pybind11/tests/test_constants_and_functions.cpp index c8c0392c9..653bdf6b6 100644 --- a/ext/pybind11/tests/test_constants_and_functions.cpp +++ b/ext/pybind11/tests/test_constants_and_functions.cpp @@ -41,6 +41,26 @@ std::string print_bytes(py::bytes bytes) { return ret; } +// Test that we properly handle C++17 exception specifiers (which are part of the function signature +// in C++17). These should all still work before C++17, but don't affect the function signature. +namespace test_exc_sp { +int f1(int x) noexcept { return x+1; } +int f2(int x) noexcept(true) { return x+2; } +int f3(int x) noexcept(false) { return x+3; } +int f4(int x) throw() { return x+4; } // Deprecated equivalent to noexcept(true) +struct C { + int m1(int x) noexcept { return x-1; } + int m2(int x) const noexcept { return x-2; } + int m3(int x) noexcept(true) { return x-3; } + int m4(int x) const noexcept(true) { return x-4; } + int m5(int x) noexcept(false) { return x-5; } + int m6(int x) const noexcept(false) { return x-6; } + int m7(int x) throw() { return x-7; } + int m8(int x) const throw() { return x-8; } +}; +} + + test_initializer constants_and_functions([](py::module &m) { m.attr("some_constant") = py::int_(14); @@ -63,4 +83,22 @@ test_initializer constants_and_functions([](py::module &m) { m.def("return_bytes", &return_bytes); m.def("print_bytes", &print_bytes); + + using namespace test_exc_sp; + py::module m2 = m.def_submodule("exc_sp"); + py::class_<C>(m2, "C") + .def(py::init<>()) + .def("m1", &C::m1) + .def("m2", &C::m2) + .def("m3", &C::m3) + .def("m4", &C::m4) + .def("m5", &C::m5) + .def("m6", &C::m6) + .def("m7", &C::m7) + .def("m8", &C::m8) + ; + m2.def("f1", f1); + m2.def("f2", f2); + m2.def("f3", f3); + m2.def("f4", f4); }); |