This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] don't warn when returning the result for bugprone-standalone-empty
ClosedPublic

Authored by v1nh1shungry on Jan 5 2023, 8:38 PM.

Details

Summary

Relevant issue: https://github.com/llvm/llvm-project/issues/59517

Currently this check will warn when the result is used in a return
statement, e.g.

bool foobar() {
  std::vector<int> v;
  return v.empty();
  // will get a warning here, which makes no sense IMO
}

Diff Detail

Event Timeline

v1nh1shungry created this revision.Jan 5 2023, 8:38 PM
Herald added a project: Restricted Project. · View Herald Transcript
v1nh1shungry requested review of this revision.Jan 5 2023, 8:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 5 2023, 8:38 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
cjdb added a reviewer: denik.Jan 6 2023, 10:43 AM
cjdb added a comment.Jan 6 2023, 10:48 AM

LGTM, thanks for fixing!

Please be sure to have your commit message have Fixes #59517 instead of a link to the issue, as this will close the bug upon merging.

clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
886–890

Please add additional cases similar to what's above (e.g. a case with absl::empty, an ADL-invoked case, etc.).

add more tests

v1nh1shungry marked an inline comment as done.Jan 6 2023, 8:45 PM

Thank you for reviewing and giving suggestions! @cjdb

Hope there are enough test cases now, and not too many tests.

cjdb accepted this revision.Jan 10 2023, 9:44 AM

Excellent, let's wait for @denik's feedback before merging, but this LGTM. Thank you for the patch!

This revision is now accepted and ready to land.Jan 10 2023, 9:44 AM
denik accepted this revision.Jan 10 2023, 10:15 AM

Thanks @v1nh1shungry for the fix!
The change and test cases look good to me.

Thank you for reviewing, @cjdb and @denik! If this patch is okay to land, could you please help me commit it? Thanks a lot!