[Bug c++/85043] -Wuseless-cast false positive for temporary objects
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Mar 23 15:38:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85043
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #4)
> Why would user-provided copy ctor matter? In this testcase there is no
> user-provided copy ctor, what matters is that the static cast is handled
> through
> perform_direct_initialization_if_possible as direct initialization of a
> temporary, without the cast there is no temporary.
>
> -Wuseless-cast complains about all these below, and none of the casts are
> useless, all of them create a temporary. So perhaps not warn at all if
> CLASS_TYPE_P (type)?
Yes I suppose you're right. For a non-class type all operators that modify the
operand also have non-modifying forms, i.e. ++i can be replaced by (i + 1), and
i+=n can be replaced with i+n, so there's no need to perform a useless cast to
create a temporary. So creatinga not-useless temporary is only necessary for
class types.
More information about the Gcc-bugs
mailing list