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

Mikael Persson mikael.s.persson at gmail.com
Mon Feb 23 15:32:39 PST 2015


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150223/ddbd0a2d/attachment.html>


More information about the cfe-commits mailing list