Opened 11 years ago

Closed 11 years ago

#5803 closed Bugs (fixed)

MPL assertion does not allow python to override protected virtual methods

Reported by: mathstuf@… Owned by: Ralf W. Grosse-Kunstleve
Milestone: To Be Determined Component: python USE GITHUB
Version: Boost 1.47.0 Severity: Problem
Keywords: Cc:

Description

When wrapping a class with virtual protected methods, the following MPL assertion is hit in boost::python::detail::error::virtual_function_default<> (python/class.hpp:141):

assertion<mpl::not_<is_same<Default,Fn> > >

The way I've been exposing the protected method so that the Python can override it is:

class Base { protected: virtual void foo(); };
class BaseWrap : public Base, public wrapper<Base> { public: void foo(); void base_foo(); };
// ...
class_<BaseWrap, boost::noncopyable>("PythonBase")
    .def("foo", &BaseWrap::foo, &BaseWrap::base_foo);

The assertion is *supposed* to be (following the function names) testing that &BaseWrap::base_foo is a method of the wrapped class (BaseWrap), but it does it in a way that precludes the main overriding function from *also* being from BaseWrap which isn't really correct.

Change History (4)

comment:1 by Ralf W. Grosse-Kunstleve, 11 years ago

We could simply remove the assertion. Does that make sense?

comment:2 by mathstuf@…, 11 years ago

Sleeping on it, that would probably make the most sense.

In the meantime, is there a workaround that might work?

in reply to:  2 comment:3 by Ralf W. Grosse-Kunstleve, 11 years ago

Replying to mathstuf@…:

Sleeping on it, that would probably make the most sense.

OK, I'll remove the assertion on the trunk (and later on the release branch).

In the meantime, is there a workaround that might work?

If you cannot modify the class.hpp header I don't know. You could ask the Python-C++ SIG.

comment:4 by Ralf W. Grosse-Kunstleve, 11 years ago

Resolution: fixed
Status: newclosed

boost svn trunk rev. 74020: commenting out assertion

Note: See TracTickets for help on using tickets.