Boost logo

Boost Users :

Subject: Re: [Boost-users] [Variant] recursive_wrapper and ambiguous convert_construct()
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2012-04-09 14:23:31


On Mon, Apr 9, 2012 at 8:48 AM, Florian Goujeon <florian.goujeon_at_[hidden]
> wrote:

> Hello,
>
> I'm modelizing a syntax tree using boost::variant, std::tuple and
> std::vector. This syntax tree has a lot of cyclic dependencies, so I have
> to use boost::recursive_wrapper along with forward declarations.
>
> I've encountered a case that my compiler (GCC 4.7) refuses to build.
> Here is the source code: http://pastebin.com/3a5xU06x (it's pretty short)
> Here is the compilation error message: http://pastebin.com/Zpa3TCp2
>
> (Of course, reordering the declarations would solve the problem in this
> example, but it's not the point. This is a constraint I can't get rid of
> in my whole project.)
>
> The compiler complains about an ambiguous call of convert_construct() in
> Boost's source code, where a comment says:
> NOTE TO USER :
> Compile error here indicates that the given type is not
> unambiguously convertible to one of the variant's types
> (or that no conversion exists).
>
> c can be converted to boost::recursive_wrapper<c_fwd> though.
> Where is the ambiguity?
>
> I really don't know what to do. Help would be appreciated.
> Thank you.
>

It *looks* like it's getting confused with the conversion constructor that
constructs one variant type from another.

Let's see, it's trying to match

convert_construct(c_fwd&, long int)

and the candidates it's considering are

variant< rw<c_fwd> >::convert_construct(c_fwd&, int, mpl_::false_)
variant< rw<?_fwd> >::convert_construct(variant<double,char*>&, long int)
variant< rw<c_fwd> >::convert_construct(const variant<double,char*>&, long
int)

[rw == recursive_variant; looks like there were problems with your copy
paste but I'm guessing ?_fwd == c_fwd.]

c_fwd inherits from c, which is the variant<double,char*> that pops up
above. So yeah, there's definitely an ambiguity there.

I don't know if that's an error in the implementation of variant, or an
error on your side, but does that help you diagnose the problem in any way?
Sorry, the chain of stuff that's suppose to happen in the statement "a
a_node(b_node);" is too much for me to wrap my head around at the moment,
with all the recursively defined a's, b's, and c's :/

- Jeff



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net