[PATCH] New warning -Wpessimizing-move to catch when removing calls to std::move in return statements will result in NRVO

Kim Gräsman kim.grasman at gmail.com
Mon Feb 23 21:55:41 PST 2015


Mikael, all,

I've wanted that as well. As you say, it might turn up a lot of
warnings in a code base, so it'd be nice to be able to decorate
per-function whether you assume NRVO should kick in. Something like:

  [[clang::assume_nrvo]]
  public std::string GetValue() {
     return value_;
  }

But this is something else than pessimizing-move, so it probably
belongs in a separate thread.

FWIW,
- Kim


On Tue, Feb 24, 2015 at 12:32 AM, Mikael Persson
<mikael.s.persson at gmail.com> wrote:
> Hi,
>
> I came upon this patch as I was looking for a way to get the compiler to
> warn about any function that is written in a way that thwarts RVO, and I
> thought that I would suggest that maybe this warning could be generalized to
> something like "Wpessimizing-no-rvo". In other words, this warning could
> warn about any function that returns something by value but is written in
> such a way that Clang (and similarly, any other reasonably competent
> optimizing compiler) is not able to apply (N)RVO to it. Of course, this
> would include catching pessimizing uses of std::move in a return statement
> (which could be part of the diagnostic message as the explanation of what
> prevented clang from applying RVO).
>
> I understand that this could be problematic in some ways, and that it's not
> an option that should be enabled by default or through other all-in-one
> warnings (-Wall, -Wpedantic, ...), because it could unnecessarily dirty-up a
> lot of builds if it was. But I think such a general option would be really
> nice to have, and even if Clang's RVO is still a bit too "dumb" at the
> moment (as Richard mentioned), it would just make that warning a bit too
> conservative, which would just lead people to modify their code to make it
> very easy for any "dumb" compiler to apply RVO to.
>
> I just thought I would bring that up.
> Mikael.
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>



More information about the cfe-commits mailing list