__rvalref overloads causing ambiguities

chris jefferson caj@cs.york.ac.uk
Thu Jul 21 09:33:00 GMT 2005


Jonathan Wakely wrote:

>Hi Chris,
>
>It looks like your rvalue references that provide move semantics
>can cause ambiguous overloads.
>
>  
>
Woops, I missed this. I've been planning to try to get boost to compile
/ test for a while..

>...

>
>Could you add another level of indirection, so that going from A to
>rvalref<vector> would require two user-defined conversions (which won't
>happen implicitly) ?
>
>  
>
We can't add another level of indirection like you say. I believe we can
use some templates to confuse the compiler into ignoring the problem
however. I'm currently testing something very much like:

template<class T,class U = void>
struct __rvalref;

...

(inside vector)
template<class U>
vector(__rvalref<vector,U>);

This should make sure that you never automatically try this constructor
(or operator=, which is defined similarily), but only use them when you
have a "real" __rvalref.

It is of course just a little hacky, but compiles away to no extra
overhead (modulo a random "void" appearing in the debug information").

I'll run through a testsuite, and see if anything else crops up. Thanks
for finding this :)

Chris



More information about the Libstdc++ mailing list