On Tue, 2018-08-21 at 10:01 -0400, Marek Polacek wrote: > 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.
Thanks. Sorry if this is a bit of a digression from the main point of the patch; I see this all as bonus material - maybe as a followup assuming/once the real part of the patch is reviewed. Am I right in thinking that the above code here ought to be simply: return t; If so, then presumably we need the location of the start of parens, so that we can suggest deletion from the start of the "std::move" through to the open paren, and deletion of the close paren. For a testcase for the fix-it hint, it's better to use something with a length > 1 for the argument (to verify the range is correct), so it would be something like: Wpessimizing-move1.C:43:20: note: remove 'std::move' call: 43 | return std::move (foo); | ~~~~~~~~~~^~~~~ | ----------- - (which admittedly isn't the most readable presentation of that data, but maybe that's fixable in diagnostic-show-locus.c).