Roman Yakovenko wrote:
> On Wed, Sep 30, 2009 at 6:18 PM, Christopher Bruns <cmbruns at stanford.edu> 
> wrote:
> > I suspect I can manually adjust the implicitly_convertible tag
> > generation using the "allow_implicit_conversion" flag in pyplusplus.
> > Is there a way to tell pyplusplus to avoid generating an
> > implicitly_convertible tag for all explicit constructors?
>
> I don't think so. I attached gccxml generated file for your code. As
> you can see both constructors ( Foo and Bar )  have "explitic=1". So
> Py++ has no way to find out whether a constructor explicit or not.

I disagree.  Py++ does have a way to find out.  The only time
"explicit" matters is when a constructor takes exactly one argument.
gccxml sets "explicit=1" in all cases when the number of arguments is
other than 1.  That is why you saw "explicit=1" in all of the
constructors in the previous example.  However, in the case where
there is exactly one argument, gccxml does the right thing.  Consider
the following case:

### test.h ####
struct Foo1 {};
struct Foo2 {};

struct Bar {
    explicit Bar(Foo1&); // no implicit conversion
    Bar(Foo2&); // allows implicit conversion
};
#############


### fragment of resulting xml file from gccxml ###
  <Constructor id="_10" name="Bar" explicit="1" context="_3"
access="public" mangled="_ZN3BarC1ER4Foo1 *INTERNAL* "
demangled="Bar::Bar(Foo1&amp;)" location="f0:5" file="f0" line="5"
extern="1">
    <Argument type="_22" location="f0:5" file="f0" line="5"/>
  </Constructor>
  <Constructor id="_11" name="Bar" context="_3" access="public"
mangled="_ZN3BarC1ER4Foo2 *INTERNAL* " demangled="Bar::Bar(Foo2&amp;)"
location="f0:6" file="f0" line="6" extern="1">
    <Argument type="_23" location="f0:6" file="f0" line="6"/>
  </Constructor>
#######################

Notice that gccxml sets "explicit=1" for the first Bar constructor,
but not for the second.

However, Py++ sets "allow_implicit_conversion" to True for both
constructors.  I think gccxml is doing the right thing here.  But I am
not so sure about Py++ behavior.  I would have assumed that the first
Bar constructor would have "allow_implicit_conversion" set to False.
I was wrong about being able to use "allow_implicit_conversion" for
this task.  Is there another way to get at the "explicit" xml tag from
the module_builder object?  Or do I need to parse the xml file or
source code separately to discover this information?

Thank you Roman for your diligent feedback.  I sincerely appreciate
the quick and thoughtful feedback you provide to everyone on this
mailing list.

Chris Bruns
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to