This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Add additional diagnostic to misc-use-after-move
ClosedPublic

Authored by mboehme on Oct 14 2016, 5:38 AM.

Details

Summary

This adds a diagnostic to the misc-use-after-move check that is output when the
use happens on a later loop iteration than the move, for example:

A a;
for (int i = 0; i < 10; ++i) {
  a.foo();
  std::move(a);
}

This situation can be confusing to users because, in terms of source code
location, the use is above the move. This can make it look as if the warning
is a false positive, particularly if the loop is long but the use and move are
close together.

In cases like these, misc-use-after-move will now output an additional
diagnostic:

a.cpp:393:7: note: the use happens in a later loop iteration than the move

Event Timeline

mboehme updated this revision to Diff 74664.Oct 14 2016, 5:38 AM
mboehme retitled this revision from to [clang-tidy] Add additional diagnostic to misc-use-after-move.
mboehme updated this object.
mboehme added a reviewer: hokein.
mboehme added a subscriber: cfe-commits.
hokein accepted this revision.Oct 14 2016, 6:00 AM
hokein edited edge metadata.

The code looks good.

clang-tidy/misc/UseAfterMoveCheck.cpp
579

A space after if.

This revision is now accepted and ready to land.Oct 14 2016, 6:00 AM
mboehme updated this revision to Diff 74671.Oct 14 2016, 6:13 AM
mboehme edited edge metadata.
  • Responses to reviewer comments
mboehme marked an inline comment as done.Oct 14 2016, 6:13 AM
This revision was automatically updated to reflect the committed changes.