[clang-tools-extra] [clang-tidy][NFC]clean ConstCorrectnessCheck (PR #130493)

Congcong Cai via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 9 09:20:15 PDT 2025


https://github.com/HerrCai0907 created https://github.com/llvm/llvm-project/pull/130493

None

>From cf55439ce8af415138e618f2d8b4af1180319586 Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0907 at 163.com>
Date: Sun, 9 Mar 2025 16:05:52 +0000
Subject: [PATCH] [clang-tidy][NFC]clean ConstCorrectnessCheck

---
 .../clang-tidy/misc/ConstCorrectnessCheck.cpp      | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

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.



More information about the cfe-commits mailing list