[C++-sig] Re: How to expose virtual function with defaultarguments in boost.python ?

Baptiste Lepilleur gaiacrtn at free.fr
Wed Dec 8 10:05:10 CET 2004


----- Original Message ----- 
From: "David Abrahams" <dave at boost-consulting.com>
To: <c++-sig at python.org>
Sent: Wednesday, December 08, 2004 4:50 AM
Subject: [C++-sig] Re: How to expose virtual function with defaultarguments
in boost.python ?


> Baptiste Lepilleur wrote:
> >>
> >> Why not just
> >>
> >>                return call< const Ogre::String& >( f.ptr());
> >
> >>
> >> ??
> >>
> >> >         return Ogre::BillboardSet::getMaterialName();
> >> >     }
> >> > ---
> >> >
> >> > Do you have any idea on how to "remove" this warning?
> >>
> >> The warning is a compiler bug; I reported it late in the vc7.1 release
> >> cycle and they were not inclined to fix it.
> >
> >
> > I changed the generator to generate the "vc6/7 work-around" code. I
wanted
> > to see if there was a difference, and there is !
>
> What sort of a difference?

You don't get the warning anymore. In addition to that, I have run into a
case where you get a compilation error. So the vc6/7 work-around also apply
to vc7.1. Here is the code generating the error:
    Ogre::ConfigOptionMap& getConfigOptions() {
        return this->get_override("getConfigOptions")();   // << error there
    }

build\pyogre_\RenderSystem.cpp(29) : error C2440: 'return' : cannot convert
from 'boost::python::detail::method_result'
to 'Ogre::ConfigOptionMap &'
        A reference that is not to 'const' cannot be bound to a non-lvalue

It compiles without error when using the work-around syntax.

> > There should definitely be
> > a note about this warning in either the tutorial or the reference
> > documentation.
>
> Where, precisely, do you think the note could go that would be helpful?
>  The warning shows up in all kinds of places, and not only with
> Boost.Python.  If it will be helpful, I'm all for adding a note, but in
> general I'm disinclined to devote much attention to suppressing buggy
> warnings.  I don't want the documentation to become a pile of notes
> about quirky compiler bugs.

I never run into that bugged warning before. Given the compilation error I
run into above, I would simply suggest that the work-around should be used
on vc6/7/7.1.

> > It worries me that such a serious warning is bugged. It's one of a few
that
> > I really look out for. By the way, how do you manage to return a
reference
> > on something that is temporary (return value of the python function
call) ?
> > I'm curious...
>
> I am not returning a reference to a temporary; that's why I say the
> warning is a compiler bug.  The warning is just incorrect.

I understood that you were not returning a reference to a temporary. My
question is how you managed to achieve that, since a return value is by
essence temporary.

> [...]
> > The virtual member function renderSingleObject is defined has protected
in
> > the wrapped class Ogre::SceneManager. This means that we can't call the
base
> > class member function using "self.". I'm not aware of any tricks to work
> > around this, do you know any ?
>
>
> Nope.  As with private non-pure virtual functions, this may be one of
> those corner cases where you have to forcibly violate the encapsulation
> of the code you're wrapping (usually by adding friend declarations).

OK. I have disabled support for default parameters for protected virtual
member functions (those are very rare anyway).

Baptiste.




More information about the Cplusplus-sig mailing list