Skip to content

Commit 034026a

Browse files
committed
[clang-tidy] Ignore non-math operators in readability-math-missing-parentheses
Do not emit warnings for non-math operators. Closes #92516
1 parent 429e5be commit 034026a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ static void addParantheses(const BinaryOperator *BinOp,
5757
int Precedence1 = getPrecedence(BinOp);
5858
int Precedence2 = getPrecedence(ParentBinOp);
5959

60-
if (ParentBinOp != nullptr && Precedence1 != Precedence2) {
60+
if (ParentBinOp != nullptr && Precedence1 != Precedence2 && Precedence1 > 0 &&
61+
Precedence2 > 0) {
6162
const clang::SourceLocation StartLoc = BinOp->getBeginLoc();
6263
const clang::SourceLocation EndLoc =
6364
clang::Lexer::getLocForEndOfToken(BinOp->getEndLoc(), 0, SM, LangOpts);

clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,20 @@ void f(){
140140
//CHECK-MESSAGES: :[[@LINE+1]]:13: warning: '*' has higher precedence than '+'; add parentheses to explicitly specify the order of operations [readability-math-missing-parentheses]
141141
int v = FUN5(0 + 1);
142142
}
143+
144+
namespace PR92516 {
145+
void f(int i) {
146+
int j, k;
147+
for (j = i + 1, k = 0; j < 1; ++j) {}
148+
}
149+
150+
void f2(int i) {
151+
int j;
152+
for (j = i + 1; j < 1; ++j) {}
153+
}
154+
155+
void f3(int i) {
156+
int j;
157+
for (j = i + 1, 2; j < 1; ++j) {}
158+
}
159+
}

0 commit comments

Comments
 (0)