Skip to content

[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

Merged

Conversation

HerrCai0907
Copy link
Contributor

No description provided.

Copy link
Contributor Author

@llvmbot
Copy link
Member

llvmbot commented Mar 9, 2025

@llvm/pr-subscribers-clang-tools-extra

Author: Congcong Cai (HerrCai0907)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/130493.diff

1 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp (+6-8)
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.

@llvmbot
Copy link
Member

llvmbot commented Mar 9, 2025

@llvm/pr-subscribers-clang-tidy

Author: Congcong Cai (HerrCai0907)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/130493.diff

1 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp (+6-8)
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.

Copy link
Contributor Author

HerrCai0907 commented Mar 11, 2025

Merge activity

  • Mar 11, 2:51 AM EDT: A user started a stack merge that includes this pull request via Graphite.
  • Mar 11, 2:53 AM EDT: A user merged this pull request with Graphite.

@HerrCai0907 HerrCai0907 merged commit 5cfc37b into main Mar 11, 2025
16 checks passed
@HerrCai0907 HerrCai0907 deleted the users/ccc/03-09-_clang-tidy_nfc_clean_constcorrectnesscheck branch March 11, 2025 06:53
VC = VariableCategory::Pointer;
}
}
else if (const auto *ArrayT = dyn_cast<ArrayType>(VT))
Copy link
Contributor

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.

Copy link
Contributor

@carlosgalvezp carlosgalvezp Mar 11, 2025

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.

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants