Boost C++ Libraries: Ticket #2776: [fix in git] Failed to wrap classes with virtual inheritance https://svn.boost.org/trac10/ticket/2776 <p> Hi! </p> <p> 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. </p> <p> Error log is below, source and generated files are in attachment. </p> <p> % 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&lt;T, Fn&gt;::must_be_derived_class_member(const Default&amp;) [with Default = void (Petq_wrapper::*)(), T = Petq_wrapper, Fn = void (Vasq::*)()]': /usr/include/boost/python/class.hpp:565: instantiated from `void boost::python::class_&lt;T, X1, X2, X3&gt;::def_default(const char*, Fn, const Helper&amp;, mpl_::bool_&lt;true&gt;) [with Fn = void (Vasq::*)(), Helper = boost::python::detail::def_helper&lt;void (Petq_wrapper::*)(), boost::python::detail::not_specified, boost::python::detail::not_specified, boost::python::detail::not_specified&gt;, W = Petq_wrapper, X1 = boost::python::bases&lt;Vasq, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_&gt;, X2 = boost::noncopyable_::noncopyable, X3 = boost::python::detail::not_specified]' /usr/include/boost/python/class.hpp:548: instantiated from `void boost::python::class_&lt;T, X1, X2, X3&gt;::def_impl(T*, const char*, Fn, const Helper&amp;, ...) [with T = Petq, Fn = void (Vasq::*)(), Helper = boost::python::detail::def_helper&lt;void (Petq_wrapper::*)(), boost::python::detail::not_specified, boost::python::detail::not_specified, boost::python::detail::not_specified&gt;, W = Petq_wrapper, X1 = boost::python::bases&lt;Vasq, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_&gt;, X2 = boost::noncopyable_::noncopyable, X3 = boost::python::detail::not_specified]' /usr/include/boost/python/class.hpp:608: instantiated from `void boost::python::class_&lt;T, X1, X2, X3&gt;::def_maybe_overloads(const char*, Fn, const A1&amp;, ...) [with Fn = void (Vasq::*)(), A1 = void (Petq_wrapper::*)(), W = Petq_wrapper, X1 = boost::python::bases&lt;Vasq, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_&gt;, X2 = boost::noncopyable_::noncopyable, X3 = boost::python::detail::not_specified]' /usr/include/boost/python/class.hpp:244: instantiated from `boost::python::class_&lt;T, X1, X2, X3&gt;&amp; boost::python::class_&lt;T, X1, X2, X3&gt;::def(const char*, A1, const A2&amp;) [with A1 = void (Vasq::*)(), A2 = void (Petq_wrapper::*)(), W = Petq_wrapper, X1 = boost::python::bases&lt;Vasq, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_&gt;, 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' </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2776 Trac 1.4.3 Alexander Kogan <alexander@…> Wed, 18 Feb 2009 12:03:07 GMT attachment set https://svn.boost.org/trac10/ticket/2776 https://svn.boost.org/trac10/ticket/2776 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test.hxx</span> </li> </ul> Ticket Alexander Kogan <alexander@…> Wed, 18 Feb 2009 12:03:28 GMT attachment set https://svn.boost.org/trac10/ticket/2776 https://svn.boost.org/trac10/ticket/2776 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test.cxx</span> </li> </ul> Ticket anonymous Wed, 18 Feb 2009 20:31:40 GMT attachment set https://svn.boost.org/trac10/ticket/2776 https://svn.boost.org/trac10/ticket/2776 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">virtual_inheritance.cpp</span> </li> </ul> Ticket anonymous Wed, 18 Feb 2009 20:32:00 GMT attachment set https://svn.boost.org/trac10/ticket/2776 https://svn.boost.org/trac10/ticket/2776 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">virtual_inheritance_to_be_exported.hpp</span> </li> </ul> Ticket roman.yakovenko@… Wed, 18 Feb 2009 20:32:34 GMT <link>https://svn.boost.org/trac10/ticket/2776#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2776#comment:1</guid> <description> <p> The bug description: </p> <p> The user has two classes: </p> <p> struct base{ </p> <blockquote> <p> virtual void do_smth() {} </p> </blockquote> <p> }; </p> <p> struct derived : virtual public base {}; </p> <p> and exposes them using the following code: </p> <p> namespace bp = boost::python; </p> <p> struct base_wrapper : base, bp::wrapper&lt; base &gt; { </p> <blockquote> <p> &lt;&lt;&lt; constructors &gt;&gt;&gt; virtual void do_smth() {...} void default_do_smth( ) {...} </p> </blockquote> <p> }; </p> <p> struct derived_wrapper : derived, bp::wrapper&lt; derived &gt; { </p> <blockquote> <p> &lt;&lt;&lt; constructors &gt;&gt;&gt; </p> </blockquote> <blockquote> <p> virtual void do_smth() {...} void default_do_smth() {...} </p> </blockquote> <p> }; </p> <p> BOOST_PYTHON_MODULE(virtual_inheritance){ </p> <blockquote> <p> bp::class_&lt; base_wrapper &gt;( "base" ) </p> <blockquote> <p> .def( </p> <blockquote> <p> "do_smth" , (void ( ::base::* )( ) )(&amp;::base::do_smth) , (void ( base_wrapper::* )( ) )(&amp;base_wrapper::default_do_smth) ); </p> </blockquote> </blockquote> </blockquote> <blockquote> <p> bp::class_&lt; derived_wrapper, bp::bases&lt; base &gt; &gt;( "derived" ) </p> <blockquote> <p> .def( </p> <blockquote> <p> "do_smth" , (void ( ::base::* )( ) )(&amp;::base::do_smth) , (void ( derived_wrapper::* )( ) </p> </blockquote> </blockquote> </blockquote> <p> )(&amp;derived_wrapper::default_do_smth) ); <em>compiler complains to this line } </em></p> <p> GCC 4.1.3 and MSVC 7.1 complain on the last line. If the user removes "virtual" from inheritance everything works fine. </p> <p> In the past, a bug similar to this one was already fixed: <a class="ext-link" href="http://mail.python.org/pipermail/cplusplus-sig/2003-September/005197.html"><span class="icon">​</span>http://mail.python.org/pipermail/cplusplus-sig/2003-September/005197.html</a> </p> <p> I also attach source code and generated code. It is pretty close to "minimum". </p> </description> <category>Ticket</category> </item> <item> <dc:creator>troy d. straszheim</dc:creator> <pubDate>Fri, 25 Sep 2009 04:46:45 GMT</pubDate> <title>summary changed https://svn.boost.org/trac10/ticket/2776#comment:2 https://svn.boost.org/trac10/ticket/2776#comment:2 <ul> <li><strong>summary</strong> <span class="trac-field-old">Failed to wrap classes with virtual inheritance</span> → <span class="trac-field-new">[fix in git] Failed to wrap classes with virtual inheritance</span> </li> </ul> <p> Fix here: </p> <p> <a class="ext-link" href="http://gitorious.org/~straszheim/boost/straszheim/commit/ce46ee7984344e32983330d5bc4b910002d1cdcc"><span class="icon">​</span>http://gitorious.org/~straszheim/boost/straszheim/commit/ce46ee7984344e32983330d5bc4b910002d1cdcc</a> </p> <p> 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. </p> <p> This fix will make its way back up to svn trunk eventually. </p> Ticket