Opened 16 years ago

Closed 16 years ago

#770 closed Bugs (Invalid)

static assert for boost::python::make_constructor

Reported by: jfalk Owned by: david_abrahams
Milestone: Component: python USE GITHUB
Version: Boost 1.34.0 Severity:
Keywords: Cc:

Description

You get a static assertion when using
boost::python::make_constructor together
with the call policy
return_value_policy<manage_new_object>()

Test case:
=====================================================
#include <boost/python.hpp>

namespace Test {
  using namespace boost::python;

  class Foo {
  };

  Foo *fooCreator() { return new Foo(); }

  BOOST_PYTHON_MODULE(Test)
  {
    class_<Foo>("Foo")
      .def("__init__", make_constructor(fooCreator,
return_value_policy<manage_new_object>()));
  }

} /* namespace Test */

Failure:
=====================================================
/usr/include/boost/python/make_constructor.hpp: In
instantiation of
`boost::python::detail::constructor_policy<boost::python::return_value_policy<boost::python::manage_new_object,
boost::python::default_call_policies> >':
/usr/include/boost/python/make_constructor.hpp:150:  
instantiated from `boost::python::api::object
boost::python::detail::make_constructor_aux(F, const
CallPolicies&, const Sig&) [with F = Test::Foo*(*)(),
CallPolicies =
boost::python::return_value_policy<boost::python::manage_new_object,
boost::python::default_call_policies>, Sig =
boost::mpl::vector1<Test::Foo*>]'
/usr/include/boost/python/make_constructor.hpp:236:  
instantiated from `boost::python::api::object
boost::python::make_constructor(F, const CallPolicies&)
[with F = Test::Foo*(*)(), CallPolicies =
boost::python::return_value_policy<boost::python::manage_new_object,
boost::python::default_call_policies>]'
boost-python-test.cpp:14:   instantiated from here
/usr/include/boost/python/make_constructor.hpp:106:
error: incomplete type `
   boost::STATIC_ASSERTION_FAILURE<false>' does not
have member `value'

Expected Result:
=====================================================
Should compile

Change History (1)

comment:1 by david_abrahams, 16 years ago

Status: assignedclosed
Logged In: YES 
user_id=52572

That's the expected behavior.  make_constructor supplies its
own return value policy that does the right thing, and the
assertion exists to let you know that any return value
policy you supply will be ignored. 

Admittedly the error message could be better, but we didn't
have the technology to make that improvement when the code
was written.

Note: See TracTickets for help on using tickets.