[C++-sig] Re: Boost: virtual inheritance

Jacek Generowicz jacek.generowicz at cern.ch
Mon Sep 15 16:49:48 CEST 2003


David Abrahams <dave at boost-consulting.com> writes:

> David Abrahams <dave at boost-consulting.com> writes:
> > The quick workaround is:
> >
> >   .def("name", object(&Class::name))

Thanks for your quick response (unfortunately I was away last week, so
we were not able to continue this work for a while).

This allows us to proceed a bit further, however when we make
Item::name return a _reference_ to std::string, it all goes wrong
again; firstly, we are (quite rightly) asked to specify a return
policy. Complying with the request, we are faced with the following error:

/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/class.hpp:383: `sizeof'
   applied to incomplete type `boost::STATIC_ASSERTION_FAILURE<false>'

(Full error message included at the bottom, for completeness,
once again.)

Here's our (updated) minimal test case:

====================================================================
#include <string>

struct Item {
  std::string m_name;
  Item(const std::string& name):m_name(name) {}
  const std::string& name() const { return m_name; }
  virtual ~Item() {};
};

struct Class :  virtual public Item {
  Class():Item("hello"){}
};


#include <boost/python.hpp>
using namespace boost::python;

BOOST_PYTHON_MODULE( btry ) {


  class_<Item>("Item", no_init);
    
  class_<Class, bases<Item> >("Class")
  .def("name", object(&Class::name), return_value_policy<copy_const_reference>());
}
====================================================================

> This problem is now fixed in CVS.

Great. As we must present our work on our centrally installed version
of Boost (currently 1.30.2), we can't really take advantage of this
yet. If you believe that all our problems will go away by using the
CVS version, then say the word, and we'll find sufficient motivation
to install a (locally) non-standard version ... otherwise we'll keep
trying to use workarounds, for now.

Thanks


gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/ -I../../../../Dictionary/Reflection -I/afs/cern.ch/sw/lcg/external/Python/2.2.2/rh73_gcc32/include/python2.2 -c boosttry.cpp -o build/temp.linux-i686-2.2/boosttry.o -g
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/class.hpp: In 
   member function `void boost::python::class_<T, X1, X2, X3>::def_impl(const 
   char*, F, const boost::python::detail::def_helper<A1, 
   boost::python::detail::not_specified, boost::python::detail::not_specified, 
   boost::python::detail::not_specified>&, const boost::python::api::object*) 
   [with F = boost::python::api::object, A1 = 
   boost::python::return_value_policy<boost::python::copy_const_reference, 
   boost::python::default_call_policies>, T = Class, X1 = 
   boost::python::bases<Item, boost::mpl::void_, boost::mpl::void_, 
   boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, 
   boost::mpl::void_, boost::mpl::void_, boost::mpl::void_>, X2 = 
   boost::python::detail::not_specified, X3 = 
   boost::python::detail::not_specified]':
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/class.hpp:459:   instantiated from `void boost::python::class_<T, X1, X2, X3>::def_maybe_overloads(const char*, Fn, const A1&, ...) [with Fn = boost::python::api::object, A1 = boost::python::return_value_policy<boost::python::copy_const_reference, boost::python::default_call_policies>, T = Class, X1 = boost::python::bases<Item, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_>, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]'
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/class.hpp:253:   instantiated from `boost::python::class_<T, X1, X2, X3>& boost::python::class_<T, X1, X2, X3>::def(const char*, A1, const A2&) [with A1 = boost::python::api::object, A2 = boost::python::return_value_policy<boost::python::copy_const_reference, boost::python::default_call_policies>, T = Class, X1 = boost::python::bases<Item, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_>, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]'
boosttry.cpp:24:   instantiated from here
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/class.hpp:383: `sizeof'
   applied to incomplete type `boost::STATIC_ASSERTION_FAILURE<false>'
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/detail/invoke.hpp: In
   function `PyObject* 
   boost::python::detail::invoke(boost::python::detail::mem_fn_tag, RC*, F&, 
   TC&) [with RC = 
   boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning<const
   std::string&>, F = const std::string&(Item::*)() const, TC = 
   boost::python::detail::nullary<boost::python::arg_from_python<Item&> >]':
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/detail/caller.hpp:162:   instantiated from `PyObject* boost::python::detail::caller_arity<1>::impl<F, ConverterGenerators, Policies, Sig>::operator()(PyObject*, PyObject*) [with F = const std::string&(Item::*)() const, ConverterGenerators = boost::python::detail::args_from_python, Policies = boost::python::default_call_policies, Sig = boost::mpl::list2<const std::string&, Item&>]'
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/function/function_template.hpp:117:   instantiated from `static R boost::detail::function::function_obj_invoker2<FunctionObj, R, T0, T1>::invoke(boost::detail::function::any_pointer, T0, T1) [with FunctionObj = boost::python::detail::caller<const std::string&(Item::*)() const, boost::python::detail::args_from_python, boost::python::default_call_policies, boost::mpl::list2<const std::string&, Item&> >, R = PyObject*, T0 = PyObject*, T1 = PyObject*]'
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/function/function_template.hpp:481:   instantiated from `void boost::function2<R, T0, T1, Allocator>::assign_to(FunctionObj, boost::detail::function::function_obj_tag) [with FunctionObj = boost::python::detail::caller<const std::string&(Item::*)() const, boost::python::detail::args_from_python, boost::python::default_call_policies, boost::mpl::list2<const std::string&, Item&> >, R = PyObject*, T0 = PyObject*, T1 = PyObject*, Allocator = std::allocator<boost::function_base>]'
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/function/function_template.hpp:432:   instantiated from `void boost::function2<R, T0, T1, Allocator>::assign_to(Functor) [with Functor = boost::python::detail::caller<const std::string&(Item::*)() const, boost::python::detail::args_from_python, boost::python::default_call_policies, boost::mpl::list2<const std::string&, Item&> >, R = PyObject*, T0 = PyObject*, T1 = PyObject*, Allocator = std::allocator<boost::function_base>]'
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/function/function_template.hpp:293:   instantiated from `boost::function2<R, T0, T1, Allocator>::function2(Functor, boost::detail::function::enable_if<boost::type_traits::ice_not<boost::is_same<Functor, int>::value>::value, int>::type) [with Functor = boost::python::detail::caller<const std::string&(Item::*)() const, boost::python::detail::args_from_python, boost::python::default_call_policies, boost::mpl::list2<const std::string&, Item&> >, R = PyObject*, T0 = PyObject*, T1 = PyObject*, Allocator = std::allocator<boost::function_base>]'
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/object/function_handle.hpp:27:   instantiated from `boost::python::handle<PyObject> boost::python::objects::function_handle(const F&, Signature) [with F = const std::string&(Item::*)() const, Signature = boost::mpl::list2<const std::string&, Item&>]'
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/object/function_handle.hpp:39:   instantiated from `boost::python::handle<PyObject> boost::python::objects::make_function_handle(F) [with F = const std::string&(Item::*)() const]'
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/converter/arg_to_python.hpp:205:   instantiated from `boost::python::converter::detail::function_arg_to_python<T>::function_arg_to_python(const T&) [with T = const std::string&(Item::*)() const]'
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/converter/arg_to_python.hpp:258:   instantiated from `boost::python::converter::arg_to_python<T>::arg_to_python(const T&) [with T = const std::string&(Item::*)() const]'
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/object_core.hpp:282:   instantiated from `static PyObject* boost::python::api::object_initializer<is_proxy, is_object_manager>::get(const T*, int*) [with T = const std::string&(Item::*)() const, bool is_proxy = false, bool is_object_manager = false]'
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/object_core.hpp:225:   instantiated from `boost::python::api::object::object(const T&) [with T = const std::string&(Item::*)() const]'
boosttry.cpp:24:   instantiated from here
/afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/detail/invoke.hpp:93: no
   match for call to `(
   boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning<const
   std::string&>) (const std::basic_string<char, std::char_traits<char>, 
   std::allocator<char> >&)'
error: command 'gcc' failed with exit status 1





More information about the Cplusplus-sig mailing list