[Bug c++/67906] Missing warning about std::move without effect
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Aug 29 14:34:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67906
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I don't think this is a useful enhancement request as currently written.
What are the precise semantics of the new warning that you want? Which cases
should warn, and which should not?
"std::move with no effect" is not clear enough, because the intended effect of
std::move is simply to cast to an rvalue, and it always does that. A type that
only has a copy constructor and no move constructor could be used in generic
code, where that case "has no effect" but that doesn't mean it should warn e.g.
struct A {
A { }
A(const X&) { }
};
template<typename T> struct identity { using type = T; };
template<typename T>
bool f(typename identity<T>::type&& t)
{
T other = std::move(t);
/* ... */
return true;
}
A a;
bool b = f<A>(a);
This presumably shouldn't warn.
Should there be a warning for the following code?
struct X {
X() { }
X(const X&) { }
X(const X&&) { }
};
const X x;
const X y = std::move(x);
Although constructors taking a const rvalue reference are rare and not useful
in practice, this code has entirely well-defined meaning. Should there be a
warning?
More information about the Gcc-bugs
mailing list