MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_noexcept_overload_cast

Function test_noexcept_overload_cast

tests/test_methods_and_attributes.py:603–618  ·  view source on GitHub ↗

Test issue #2234: overload_cast must handle noexcept member and free function pointers. In C++17 noexcept is part of the function type, so overload_cast_impl needs dedicated operator() overloads for noexcept free functions and non-const/const member functions.

()

Source from the content-addressed store, hash-verified

601
602
603def test_noexcept_overload_cast():
604 """Test issue #2234: overload_cast must handle noexcept member and free function pointers.
605
606 In C++17 noexcept is part of the function type, so overload_cast_impl needs dedicated
607 operator() overloads for noexcept free functions and non-const/const member functions.
608 """
609 obj = m.NoexceptOverloaded()
610 # overload_cast_impl::operator()(Return (Class::*)(Args...) noexcept, false_type)
611 assert obj.method(1) == "(int)"
612 # overload_cast_impl::operator()(Return (Class::*)(Args...) const noexcept, true_type)
613 assert obj.method_const(2) == "(int) const"
614 # overload_cast_impl::operator()(Return (Class::*)(Args...) noexcept, false_type) float
615 assert obj.method_float(3.0) == "(float)"
616 # overload_cast_impl::operator()(Return (*)(Args...) noexcept)
617 assert m.noexcept_free_func(10) == 11
618 assert m.noexcept_free_func_float(10.0) == 12
619
620
621def test_ref_qualified_overload_cast():

Callers

nothing calls this directly

Calls 1

methodMethod · 0.95

Tested by

no test coverage detected