Skip to content

Create a check to look for bitwise operators used on boolean operands #40307

@LegalizeAdulthood

Description

@LegalizeAdulthood
Bugzilla Link 40962
Version unspecified
OS All

Extended Description

Sometimes people write code like this:

bool invalid = false; invalid |= x > limit.x; invalid |= y > limit.y; invalid |= z > limit.z; if (invalid) { // error handling } 

However, we don't get short circuit evaluation in this case; all limits are checked even if the first limit is violated.

The alternative is to use logical operations instead of bitwise operations:

bool invalid = false; invalid = x > limit.x; invalid = invalid || y > limit.x; invalid = invalid || z > limit.z; if (invalid) { // error handling } 

Create a check that transforms bitwise operators on boolean quantities to logical operators.

Metadata

Metadata

Assignees

Labels

bugzillaIssues migrated from bugzillacheck-requestRequest for a new check in clang-tidyclang-tidy

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions