-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang-tidy][NFC]clean ConstCorrectnessCheck #130493
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][NFC]clean ConstCorrectnessCheck #130493
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@llvm/pr-subscribers-clang-tools-extra Author: Congcong Cai (HerrCai0907) ChangesFull diff: https://github.com/llvm/llvm-project/pull/130493.diff 1 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index 6e412e576e5f9..dbe59233df699 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -136,16 +136,14 @@ void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) {
return;
VariableCategory VC = VariableCategory::Value;
- if (Variable->getType()->isReferenceType())
+ const QualType VT = Variable->getType();
+ if (VT->isReferenceType())
VC = VariableCategory::Reference;
- if (Variable->getType()->isPointerType())
+ else if (VT->isPointerType())
VC = VariableCategory::Pointer;
- if (Variable->getType()->isArrayType()) {
- if (const auto *ArrayT = dyn_cast<ArrayType>(Variable->getType())) {
- if (ArrayT->getElementType()->isPointerType())
- VC = VariableCategory::Pointer;
- }
- }
+ else if (const auto *ArrayT = dyn_cast<ArrayType>(VT))
+ if (ArrayT->getElementType()->isPointerType())
+ VC = VariableCategory::Pointer;
// Each variable can only be in one category: Value, Pointer, Reference.
// Analysis can be controlled for every category.
|
@llvm/pr-subscribers-clang-tidy Author: Congcong Cai (HerrCai0907) ChangesFull diff: https://github.com/llvm/llvm-project/pull/130493.diff 1 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index 6e412e576e5f9..dbe59233df699 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -136,16 +136,14 @@ void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) {
return;
VariableCategory VC = VariableCategory::Value;
- if (Variable->getType()->isReferenceType())
+ const QualType VT = Variable->getType();
+ if (VT->isReferenceType())
VC = VariableCategory::Reference;
- if (Variable->getType()->isPointerType())
+ else if (VT->isPointerType())
VC = VariableCategory::Pointer;
- if (Variable->getType()->isArrayType()) {
- if (const auto *ArrayT = dyn_cast<ArrayType>(Variable->getType())) {
- if (ArrayT->getElementType()->isPointerType())
- VC = VariableCategory::Pointer;
- }
- }
+ else if (const auto *ArrayT = dyn_cast<ArrayType>(VT))
+ if (ArrayT->getElementType()->isPointerType())
+ VC = VariableCategory::Pointer;
// Each variable can only be in one category: Value, Pointer, Reference.
// Analysis can be controlled for every category.
|
VC = VariableCategory::Pointer; | ||
} | ||
} | ||
else if (const auto *ArrayT = dyn_cast<ArrayType>(VT)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this allowed by out current guidelines? This else if
blocks contains 2 lines. I think this is rather fragile and can easily break in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My reading of the guidelines is that we should use braces in the outer if
if there is a nested if
, like in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will be fixed in upstack PR
No description provided.