This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Added bugprone-inc-dec-in-conditions check
ClosedPublic

Authored by PiotrZSL on Apr 23 2023, 2:43 AM.

Details

Summary

Detects when a variable is both incremented/decremented and referenced inside a
complex condition and suggests moving them outside to avoid ambiguity in the
variable's value.

Diff Detail

Event Timeline

PiotrZSL created this revision.Apr 23 2023, 2:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 23 2023, 2:43 AM
Herald added a subscriber: xazax.hun. · View Herald Transcript
PiotrZSL requested review of this revision.Apr 23 2023, 2:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 23 2023, 2:43 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
PiotrZSL updated this revision to Diff 516140.Apr 23 2023, 3:06 AM

Undo change for cppcoreguidelines-use-default-member-init

xgupta added a subscriber: xgupta.Jul 27 2023, 11:56 PM
xgupta added inline comments.
clang-tools-extra/clang-tidy/bugprone/IncDecInConditionsCheck.cpp
31

OperatorMacher missing t in its spelling.

clang-tools-extra/clang-tidy/utils/Matchers.h
143

A comment can be here for this struct.

152

A comment can be here for this matcher.

clang-tools-extra/docs/clang-tidy/checks/bugprone/inc-dec-in-conditions.rst
63

If it is false then the second statement will be evaluated, right?

PiotrZSL added inline comments.Jul 28 2023, 12:10 AM
clang-tools-extra/docs/clang-tidy/checks/bugprone/inc-dec-in-conditions.rst
63

Yes my bad, I will correct this.

PiotrZSL updated this revision to Diff 545371.Jul 29 2023, 7:12 AM
PiotrZSL marked 4 inline comments as done.
PiotrZSL edited the summary of this revision. (Show Details)

Rebase + Fix review comments

xgupta accepted this revision.Jul 29 2023, 8:01 AM

LGTM!

This revision is now accepted and ready to land.Jul 29 2023, 8:01 AM
This revision was automatically updated to reflect the committed changes.