-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang-tidy] Ignore non-math operators in readability-math-missing-parentheses #94654
Merged
PiotrZSL
merged 1 commit into
llvm:main
from
PiotrZSL:92516-clang-tidy-unexpected-readability-math-missing-parentheses-warnings-for-assignment
Jun 9, 2024
Merged
[clang-tidy] Ignore non-math operators in readability-math-missing-parentheses #94654
PiotrZSL
merged 1 commit into
llvm:main
from
PiotrZSL:92516-clang-tidy-unexpected-readability-math-missing-parentheses-warnings-for-assignment
Jun 9, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@11happy You may want to take a look. |
@llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clang-tidy Author: Piotr Zegar (PiotrZSL) ChangesDo not emit warnings for non-math operators. Closes #92516 Full diff: https://github.com/llvm/llvm-project/pull/94654.diff 2 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
index 65fd296094915..64ce94e3fc1db 100644
--- a/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
@@ -57,7 +57,8 @@ static void addParantheses(const BinaryOperator *BinOp,
int Precedence1 = getPrecedence(BinOp);
int Precedence2 = getPrecedence(ParentBinOp);
- if (ParentBinOp != nullptr && Precedence1 != Precedence2) {
+ if (ParentBinOp != nullptr && Precedence1 != Precedence2 && Precedence1 > 0 &&
+ Precedence2 > 0) {
const clang::SourceLocation StartLoc = BinOp->getBeginLoc();
const clang::SourceLocation EndLoc =
clang::Lexer::getLocForEndOfToken(BinOp->getEndLoc(), 0, SM, LangOpts);
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
index a6045c079a482..4face0bb3fe68 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
@@ -140,3 +140,20 @@ void f(){
//CHECK-MESSAGES: :[[@LINE+1]]:13: warning: '*' has higher precedence than '+'; add parentheses to explicitly specify the order of operations [readability-math-missing-parentheses]
int v = FUN5(0 + 1);
}
+
+namespace PR92516 {
+ void f(int i) {
+ int j, k;
+ for (j = i + 1, k = 0; j < 1; ++j) {}
+ }
+
+ void f2(int i) {
+ int j;
+ for (j = i + 1; j < 1; ++j) {}
+ }
+
+ void f3(int i) {
+ int j;
+ for (j = i + 1, 2; j < 1; ++j) {}
+ }
+}
|
…rentheses Do not emit warnings for non-math operators. Closes llvm#92516
PiotrZSL
force-pushed
the
92516-clang-tidy-unexpected-readability-math-missing-parentheses-warnings-for-assignment
branch
from
June 8, 2024 10:35
034026a
to
5d37ba1
Compare
5chmidti
approved these changes
Jun 8, 2024
11happy
approved these changes
Jun 9, 2024
PiotrZSL
deleted the
92516-clang-tidy-unexpected-readability-math-missing-parentheses-warnings-for-assignment
branch
June 9, 2024 07:01
nekoshirro
pushed a commit
to nekoshirro/Alchemist-LLVM
that referenced
this pull request
Jun 9, 2024
…rentheses (llvm#94654) Do not emit warnings for non-math operators. Closes llvm#92516 Signed-off-by: Hafidz Muzakky <ais.muzakky@gmail.com>
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Do not emit warnings for non-math operators.
Closes #92516