[Bug c++/85043] -Wuseless-cast false positive for temporary objects
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Mar 23 11:38:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85043
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Maybe we could suppress the warning for explicit type conversions using
functional notation, i.e. A(a), when the copy constructor is user-provided.
It's not a perfect heuristic. It would still warn for (A)a and
static_cast<A>(a) which have identical semantics according to the standard. And
suppressing the warning for user-provided copy constructors would mean we still
warn for a type like struct B : A { }; even though it should probably be
treated just like A. Suppressing the warning for non-trivial copy constructors
would miss warnings for anything including a std::string or other non-trivial
type, even though the copy might really be useless.
But at least there would be a way to alter code to avoid the warning, which
could be documented.
More information about the Gcc-bugs
mailing list