diff --git a/src/cpyrt/CPPMethod.cxx b/src/cpyrt/CPPMethod.cxx index 3fe3e37..00c451d 100644 --- a/src/cpyrt/CPPMethod.cxx +++ b/src/cpyrt/CPPMethod.cxx @@ -1165,6 +1165,11 @@ PyObject* cpyrt::CPPMethod::GetSignatureTypes() { PyDict_SetItem(signature_types_dict, cpyrt_PyText_FromString("input_types"), parameter_types); + // Const-qualification of the method itself (always false for free + // functions and static methods). + PyDict_SetItem(signature_types_dict, cpyrt_PyText_FromString("is_const"), + PyBool_FromLong(IsConst())); + return signature_types_dict; } diff --git a/src/cpyrt/CPPOverload.cxx b/src/cpyrt/CPPOverload.cxx index 49778df..df0eb24 100644 --- a/src/cpyrt/CPPOverload.cxx +++ b/src/cpyrt/CPPOverload.cxx @@ -300,6 +300,9 @@ static PyObject* mp_func_overloads_names(CPPOverload* pymeth) { * ('float',), 'return_type': 'float'}, 'int ::foo(int a)': {'input_types': * ('int',), 'return_type': 'int'}, 'int ::foo(int a, float b)': {'input_types': * ('int', 'float'), 'return_type': 'int'}} + * + * Each overload's value dict also carries 'is_const': the method's own + * const-qualification (always False for free functions and static methods). */ static PyObject* mp_func_overloads_types(CPPOverload* pymeth) { diff --git a/test/test_overloads.py b/test/test_overloads.py index f736c8a..ef395a2 100644 --- a/test/test_overloads.py +++ b/test/test_overloads.py @@ -440,3 +440,43 @@ def test16_voidp_does_not_outrank_conversion(self): h = ns.make_handle() assert ns.kept_value(h) assert ns.kept_value(ns.make_handle()) + + def test17_func_overloads_types_reports_constness(self): + """Verify func_overloads_types carries per-overload const-qualification.""" + + import cppjit + + cppjit.cppdef(""" + namespace OverloadConstness { + struct Probe { + int v = 0; + int get_const() const { return v; } + void set_nonconst(int x) { v = x; } + int mixed(int x) const { return x + v; } + double mixed(double x) { return x; } + static int static_fn(int x) { return x; } + }; + }""") + + cls = cppjit.gbl.OverloadConstness.Probe + + def constness(name): + return { + sig: info["is_const"] + for sig, info in cls.__dict__[name].func_overloads_types.items() + } + + assert constness("get_const") == { + "int OverloadConstness::Probe::get_const()": True + } + assert constness("set_nonconst") == { + "void OverloadConstness::Probe::set_nonconst(int x)": False + } + # constness is per overload, not per method name + assert constness("mixed") == { + "int OverloadConstness::Probe::mixed(int x)": True, + "double OverloadConstness::Probe::mixed(double x)": False, + } + assert constness("static_fn") == { + "static int OverloadConstness::Probe::static_fn(int x)": False + }