Modify

Ticket #2776 (new Bugs)

Opened 5 years ago

Last modified 5 years ago

[fix in git] Failed to wrap classes with virtual inheritance

Reported by: Alexander Kogan <alexander@…> Owned by: dave
Milestone: Boost 1.39.0 Component: Python
Version: Severity: Problem
Keywords: Cc:

Description

Hi!

I've just generated a wrapper for the simple classes with virtual function and virtual inheritance with Py++ and generated code is failed to compile. Without virtual inheritance everything is ok.

Error log is below, source and generated files are in attachment.

% c++ -I/usr/include/python2.5 -lboost_python -shared -o test.so test.cxx /usr/include/boost/python/class.hpp: In static member function `static void boost::python::detail::error::virtual_function_default<T, Fn>::must_be_derived_class_member(const Default&) [with Default = void (Petq_wrapper::*)(), T = Petq_wrapper, Fn = void (Vasq::*)()]': /usr/include/boost/python/class.hpp:565: instantiated from `void boost::python::class_<T, X1, X2, X3>::def_default(const char*, Fn, const Helper&, mpl_::bool_<true>) [with Fn = void (Vasq::*)(), Helper = boost::python::detail::def_helper<void (Petq_wrapper::*)(), boost::python::detail::not_specified, boost::python::detail::not_specified, boost::python::detail::not_specified>, W = Petq_wrapper, X1 = boost::python::bases<Vasq, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_>, X2 = boost::noncopyable_::noncopyable, X3 = boost::python::detail::not_specified]' /usr/include/boost/python/class.hpp:548: instantiated from `void boost::python::class_<T, X1, X2, X3>::def_impl(T*, const char*, Fn, const Helper&, ...) [with T = Petq, Fn = void (Vasq::*)(), Helper = boost::python::detail::def_helper<void (Petq_wrapper::*)(), boost::python::detail::not_specified, boost::python::detail::not_specified, boost::python::detail::not_specified>, W = Petq_wrapper, X1 = boost::python::bases<Vasq, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_>, X2 = boost::noncopyable_::noncopyable, X3 = boost::python::detail::not_specified]' /usr/include/boost/python/class.hpp:608: instantiated from `void boost::python::class_<T, X1, X2, X3>::def_maybe_overloads(const char*, Fn, const A1&, ...) [with Fn = void (Vasq::*)(), A1 = void (Petq_wrapper::*)(), W = Petq_wrapper, X1 = boost::python::bases<Vasq, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_>, X2 = boost::noncopyable_::noncopyable, X3 = boost::python::detail::not_specified]' /usr/include/boost/python/class.hpp:244: instantiated from `boost::python::class_<T, X1, X2, X3>& boost::python::class_<T, X1, X2, X3>::def(const char*, A1, const A2&) [with A1 = void (Vasq::*)(), A2 = void (Petq_wrapper::*)(), W = Petq_wrapper, X1 = boost::python::bases<Vasq, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_>, X2 = boost::noncopyable_::noncopyable, X3 = boost::python::detail::not_specified]' test.cxx:52: instantiated from here /usr/include/boost/python/class.hpp:146: error: pointer to member conversion via virtual base `Vasq'

Attachments

test.hxx Download (99 bytes) - added by Alexander Kogan <alexander@…> 5 years ago.
test.cxx Download (1.2 KB) - added by Alexander Kogan <alexander@…> 5 years ago.
virtual_inheritance.cpp Download (2.1 KB) - added by anonymous 5 years ago.
virtual_inheritance_to_be_exported.hpp Download (462 bytes) - added by anonymous 5 years ago.

Change History

Changed 5 years ago by Alexander Kogan <alexander@…>

Changed 5 years ago by Alexander Kogan <alexander@…>

Changed 5 years ago by anonymous

Changed 5 years ago by anonymous

comment:1 Changed 5 years ago by roman.yakovenko@…

The bug description:

The user has two classes:

struct base{

virtual void do_smth() {}

};

struct derived : virtual public base {};

and exposes them using the following code:

namespace bp = boost::python;

struct base_wrapper : base, bp::wrapper< base > {

<<< constructors >>> virtual void do_smth() {...} void default_do_smth( ) {...}

};

struct derived_wrapper : derived, bp::wrapper< derived > {

<<< constructors >>>

virtual void do_smth() {...} void default_do_smth() {...}

};

BOOST_PYTHON_MODULE(virtual_inheritance){

bp::class_< base_wrapper >( "base" )

.def(

"do_smth" , (void ( ::base::* )( ) )(&::base::do_smth) , (void ( base_wrapper::* )( ) )(&base_wrapper::default_do_smth) );

bp::class_< derived_wrapper, bp::bases< base > >( "derived" )

.def(

"do_smth" , (void ( ::base::* )( ) )(&::base::do_smth) , (void ( derived_wrapper::* )( )

)(&derived_wrapper::default_do_smth) ); compiler complains to this line }

GCC 4.1.3 and MSVC 7.1 complain on the last line. If the user removes "virtual" from inheritance everything works fine.

In the past, a bug similar to this one was already fixed:  http://mail.python.org/pipermail/cplusplus-sig/2003-September/005197.html

I also attach source code and generated code. It is pretty close to "minimum".

comment:2 Changed 5 years ago by troy

  • Summary changed from Failed to wrap classes with virtual inheritance to [fix in git] Failed to wrap classes with virtual inheritance

Fix here:

 http://gitorious.org/~straszheim/boost/straszheim/commit/ce46ee7984344e32983330d5bc4b910002d1cdcc

Instead of checking the virtual function by constructing the function we're passed (which isn't possible), we just check if it will be possible out in type_traits and function_types land.

This fix will make its way back up to svn trunk eventually.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as new
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.