I am writing a simple wrapper class and I want to provide explicit conversion operators to a wrapped type. The following code compiles withgcc
class wrap
{
double value;
public:
explicit wrap(double x) : value(x) {}
explicit operator double&&() && { return std::move(value); }
};
int main() {
wrap w(5);
double && x (std::move(w) );
double && y = static_cast<double&&>(std::move(w));
}
But clangreports error: cannot cast from lvalue of type 'typename std::remove_reference<wrap &>::type' (aka 'wrap') to rvalue reference type 'double &&'; types are not compatible.
As far as I know (see the last draft, 5.2.9 §4 ) it static_cast<T>(e)has the same semantics T t(e), but clang does not abandon the latter.
Which compiler is right?
source
share