[webkit-dev] -Wpessimizing-move and -Wredundant-move

Andy Estes aestes at apple.com
Mon Mar 18 14:43:25 PDT 2019


Hi Michael,

> On Mar 18, 2019, at 2:35 PM, Michael Catanzaro <mcatanzaro at igalia.com> wrote:
> 
> Hi,
> 
> GCC 9 has new -Wpessimizing-move ("warning: moving a local object in a return statement prevents copy elision") and -Wredundant-move ("warning: redundant move in return statement") warnings. These are enabled by -Wextra (which we use) and will be triggered by code like:
> 
> return WTFMove(foo);
> 
> when foo is a copyable type. This idiom is only appropriate if foo is a noncopyable (move-only) type. We have many, many instances of such code. I'm trying to fix them. Please don't add more! (It's easy enough to disable the warnings, but they're there for a reason.)

It might not even be appropriate for move-only types because of NRVO.

FWIW, Apple’s ports use the equivalent clang warning for pessimizing and redundant moves, and we cleaned up a bunch of these mistakes in our ports a few years ago. Hopefully you aren’t finding any of these mistakes in shared code.

(WTFMove was written to accommodate these warnings, in fact.)

Really glad you’re turning these warnings on!

Andy


More information about the webkit-dev mailing list