LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 11003 - clang cannot find a conversion in c++0x mode
Summary: clang cannot find a conversion in c++0x mode
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: C++11 (show other bugs)
Version: unspecified
Hardware: PC Linux
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-23 22:14 PDT by Rafael Ávila de Espíndola
Modified: 2011-10-04 19:18 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rafael Ávila de Espíndola 2011-09-23 22:14:43 PDT
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'
}
Comment 1 Rafael Ávila de Espíndola 2011-09-25 16:20:02 PDT
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.
Comment 2 Rafael Ávila de Espíndola 2011-09-25 17:07:50 PDT
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.
Comment 3 Eli Friedman 2011-09-26 21:48:24 PDT
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.
Comment 4 Douglas Gregor 2011-10-04 19:18:50 PDT
(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.