This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Never consider assignments as equivalent in `misc-redundant-expression` check
ClosedPublic

Authored by fwolff on Mar 26 2022, 2:49 PM.

Details

Summary

Attempts to fix #35853. This issue is about side-effectful function calls, but since almost every function call potentially causes side effects and would therefore prevent any misc-redundant-expression warnings, I have focused on assignments instead, which would also fix the example in #35853.

We already have special treatment of unary increment/decrement here, even though this can also lead to false negatives. Replacing i++ with i = i + 1 currently changes the behavior of the misc-redundant-expression check, whereas the change proposed here prevents any warnings about redundant expressions if assignments are involved. This can cause false negatives, though (whereas the current implementation causes false positives), so let me know whether you think this is a sensible change to make.

Diff Detail

Event Timeline

fwolff created this revision.Mar 26 2022, 2:49 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 26 2022, 2:49 PM
fwolff requested review of this revision.Mar 26 2022, 2:49 PM
aaron.ballman accepted this revision.Mar 28 2022, 3:00 PM

LGTM; can you add a release note when you land?

This revision is now accepted and ready to land.Mar 28 2022, 3:00 PM

FWIW, False negatives are more tolerable than false positives in clang tidy.