Page MenuHomePhabricator

[clang-tidy] Fix `bugprone-use-after-move` check to also consider moves in constructor initializers
ClosedPublic

Authored by fwolff on Nov 11 2021, 1:10 PM.

Details

Summary

Fixes PR#38187. Constructors are actually already checked, but only as functions, i.e. the check only looks at the constructor body and not at the initializers, which misses the (common) case where constructor parameters are moved as part of an initializer expression.

One remaining false negative is when both the move and the use-after-move occur in constructor initializers. This is a lot more difficult to handle, though, because the bugprone-use-after-move check is currently based on a CFG that only takes the body into account, not the initializers, so e.g. initialization order would have to manually be considered. I will file a follow-up issue for this once PR#38187 is closed.

Diff Detail

Event Timeline

fwolff created this revision.Nov 11 2021, 1:10 PM
fwolff requested review of this revision.Nov 11 2021, 1:10 PM
carlosgalvezp accepted this revision.Nov 14 2021, 7:36 AM

Looks good! I'm not sure if it's OK to write "dead tests" though (the one with the TODO comment). Would it make sense to remove it from this patch, and add it in the patch where the issue is fixed?

This revision is now accepted and ready to land.Nov 14 2021, 7:36 AM
fwolff updated this revision to Diff 387116.Nov 14 2021, 11:18 AM

Thanks for reviewing this @carlosgalvezp! I have removed the "dead" test and put it into a follow-up issue (PR#52502).

If you are otherwise happy with the changes, could you commit them for me?

carlosgalvezp accepted this revision.Nov 14 2021, 12:31 PM

Awesome, thanks! Sure, I'm quite new here as well so I'll need to take some time to figure out how to commit on behalf of someone else, bear with me :)

carlosgalvezp added a comment.EditedNov 14 2021, 2:16 PM

I will push tomorrow so I have time to keep an eye on the bots ;) Btw @fwolff could you post your name and email so I add it to the commit?