diff --git a/examples/foo.cc b/examples/foo.cc index 7cecc58..c7ccb3c 100644 --- a/examples/foo.cc +++ b/examples/foo.cc @@ -37,3 +37,16 @@ int SomeObject::get_int (double from_float) { return (int) from_float; } + + +class HiddenClass : public Bar +{ +}; + + +Foo* +get_hidden_subclass_pointer () +{ + return new HiddenClass; +} + diff --git a/examples/foo.h b/examples/foo.h index 3bde1e1..19254db 100644 --- a/examples/foo.h +++ b/examples/foo.h @@ -49,6 +49,8 @@ public: virtual ~Bar() {} }; +// caller owns return +Foo* get_hidden_subclass_pointer (); class Zbr { diff --git a/examples/foomodulegen.py b/examples/foomodulegen.py index ede106d..531d72d 100755 --- a/examples/foomodulegen.py +++ b/examples/foomodulegen.py @@ -68,6 +68,10 @@ def my_module_gen(out_file): Bar.add_method(CppMethod(ReturnValue.new('std::string'), 'Hooray', [], is_static=True)) mod.add_class(Bar) + ## to test RTTI with a hidden subclass + mod.add_function(Function(ReturnValue.new('Foo*', caller_owns_return=True), + 'get_hidden_subclass_pointer', [])) + ## Zbr is a reference counted class Zbr = CppClass('Zbr', incref_method='Ref', decref_method='Unref') diff --git a/examples/footest.py b/examples/footest.py index 0124f18..ff7a0a9 100644 --- a/examples/footest.py +++ b/examples/footest.py @@ -133,5 +133,10 @@ class TestFoo(unittest.TestCase): foo2 = obj.get_foo_ptr() self.assertEqual(type(foo2), foo.Bar) + def test_type_narrowing_hidden_subclass(self): + """This test only works with GCC >= 3.0 (and not with other compilers)""" + obj = foo.get_hidden_subclass_pointer() + self.assertEqual(type(obj), foo.Bar) + if __name__ == '__main__': unittest.main()