Skip to content

Commit 8ed32a8

Browse files
committed
Add test for calling a static member function via a derived instance
From wlav@6c90057 and root-project/root@f30e8fd
1 parent 727169d commit 8ed32a8

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

test/test_overloads.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,38 @@ class E: public D {};
288288

289289
assert ns.myfunc2(ns.E()) == "E"
290290
assert ns.myfunc2(ns.D()) == "D"
291-
292291

293-
def test12_disallow_functor_to_function_pointer(self):
292+
def test12_static_call_from_derived_instance(self):
293+
"""Test calling a static member function via a derived instance."""
294+
295+
import cppyy
296+
297+
cppyy.cppdef("""
298+
class Base {
299+
public:
300+
static int StaticMethod() {
301+
return 42;
302+
}
303+
};
304+
305+
class Derived : public Base {
306+
};
307+
""")
308+
309+
d = cppyy.gbl.Derived()
310+
311+
# Call static method through base class directly
312+
result_direct = cppyy.gbl.Base.StaticMethod()
313+
314+
# Call static method through instance
315+
result_instance = d.StaticMethod()
316+
317+
assert result_instance == result_direct
318+
319+
def test13_disallow_functor_to_function_pointer(self):
294320
"""Make sure we're no allowing to convert C++ functors to function
295321
pointers, extending the C++ language in an unnatural way that can lead
296322
to wrong overload resolutions."""
297-
298323
import cppyy
299324

300325
cppyy.cppdef("""
@@ -334,7 +359,7 @@ class Test14Functor {
334359
# The "baz" function has a std::function overload, which should be selected
335360
assert cppyy.gbl.test14_baz(functor) == 2 # should resolve to baz(std::function)
336361

337-
def test13_explicit_constructor_in_implicit_conversion(self):
362+
def test14_explicit_constructor_in_implicit_conversion(self):
338363
"""Check that explicit constructors are not used in implicit conversion."""
339364

340365
import cppyy

0 commit comments

Comments
 (0)