C++ PATCH for c++/86981, implement -Wpessimizing-move
Marek Polacek
polacek@redhat.com
Tue Aug 21 14:01:00 GMT 2018
On Mon, Aug 20, 2018 at 07:42:10PM -0400, David Malcolm wrote:
> On Mon, 2018-08-20 at 18:54 -0400, Marek Polacek wrote:
> > On Mon, Aug 20, 2018 at 05:18:49PM -0400, David Malcolm wrote:
> > > As of r263675 it's now possible to tell the diagnostics subsystem
> > > that
> > > the warning and note are related by using an auto_diagnostic_group
> > > instance [1], so please can this read:
> > >
> > > if (can_do_nrvo_p (arg, functype))
> > > {
> > > auto_diagnostic_group d;
> > > if (warning (OPT_Wpessimizing_move, "moving a local
> > > object "
> > > "in a return statement prevents copy
> > > elision"))
> > > inform (input_location, "remove %<std::move%>
> > > call");
> > > }
> >
> > Sure:
> >
> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> Thanks! The changed part looks good, but I can't really speak to the
> rest of the patch.
>
> (BTW, could we emit a fix-it hint as part of that "inform" call? How
> good is the location information at this point?)
Thanks, I can actually use location_of (retval) so that we get:
Wpessimizing-move1.C:43:20: warning: moving a local object in a return statement prevents copy elision [-Wpessimizing-move]
43 | return std::move (t);
| ~~~~~~~~~~^~~
certainly better than what input_location offers. I'll go with that but
I'll be touching the code today anyway and I'll look into using a fix-it
hint.
Marek
More information about the Gcc-patches
mailing list