gcc can compile the following code in c++ 98 and 0x modes. clang only in 98: class Value { }; struct MoveRef { operator Value &() const ; }; MoveRef Move(int); void growTo() { Value x = Move(0); Value y(Move(0)); // no viable conversion from 'MoveRef' to 'Value' }
Debugging this and reading the spec it looks like the problem is: * clang is trying to initialize a rvalue reference (isLValueRef is false in TryReferenceInitialization). * the conversion rule that ends up failing is: --- has a class type (i.e., T2 is a class type), where T1 is not reference-related to T2, and can be implicitly converted to an xvalue, class prvalue, or function lvalue of type “cv3 T3”, where “cv1 T1” is reference-compatible with “cv3 T3 --- since we have a conversion to a non function lvalue.
In other words, I think this is a gcc bug, but it would be nice for someone with more c++ experience to take a look.
Hmm... I think clang is messing up here: it's somehow picking the Value(Value&&) constructor, but realizes it isn't viable when it actually tries to perform the conversion in question.
(In reply to comment #3) > Hmm... I think clang is messing up here: it's somehow picking the > Value(Value&&) constructor, but realizes it isn't viable when it actually tries > to perform the conversion in question. Eli is correct. We shouldn't have allowed the binding to the rvalue reference in the first place. Fixed in Clang r141137.