I am writing a simple wrapper class, and I want to provide explicit conversion operators to the wrapped type. The following code compiles fine with gcc
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) ); //ok
double && y = static_cast<double&&>(std::move(w)); //clang reports an error here
}
But clang
reports an 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 latest draft, 5.2.9 §4) static_cast<T>(e)
has the same semantic has T t(e)
, but clang does not refuse the latter.
Which compiler is right?
Aucun commentaire:
Enregistrer un commentaire