[PATCH] D119949: [Clang-tidy] Check the existence of ElaboratedType's qualifiers

Jun Zhang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 1 07:54:48 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGac616fbb05b8: [Clang-tidy] Check the existence of ElaboratedType's qualifiers (authored by junaire).

Changed prior to commit:
  https://reviews.llvm.org/D119949?vs=409511&id=412111#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119949/new/

https://reviews.llvm.org/D119949

Files:
  clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
@@ -198,6 +198,28 @@
   h<4>();
 }
 
+struct SP {
+  static int I;
+} P;
+
+void usep() {
+  P.I;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  SP::I;{{$}}
+}
+
+namespace NSP {
+struct SP {
+  static int I;
+} P;
+} // namespace NSP
+
+void usensp() {
+  NSP::P.I;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  NSP::SP::I;{{$}}
+}
+
 // Overloaded member access operator
 struct Q {
   static int K;
@@ -237,9 +259,9 @@
 
 namespace Outer {
   inline namespace Inline {
-    struct S {
-      static int I;
-    };
+  struct S {
+    static int I;
+  };
   }
 }
 
Index: clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -19,14 +19,15 @@
 
 static unsigned getNameSpecifierNestingLevel(const QualType &QType) {
   if (const ElaboratedType *ElType = QType->getAs<ElaboratedType>()) {
-    const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier();
-    unsigned NameSpecifierNestingLevel = 1;
-    do {
-      NameSpecifierNestingLevel++;
-      NestedSpecifiers = NestedSpecifiers->getPrefix();
-    } while (NestedSpecifiers);
-
-    return NameSpecifierNestingLevel;
+    if (const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier()) {
+      unsigned NameSpecifierNestingLevel = 1;
+      do {
+        NameSpecifierNestingLevel++;
+        NestedSpecifiers = NestedSpecifiers->getPrefix();
+      } while (NestedSpecifiers);
+
+      return NameSpecifierNestingLevel;
+    }
   }
   return 0;
 }
@@ -68,6 +69,10 @@
   PrintingPolicy PrintingPolicyWithSupressedTag(AstContext->getLangOpts());
   PrintingPolicyWithSupressedTag.SuppressTagKeyword = true;
   PrintingPolicyWithSupressedTag.SuppressUnwrittenScope = true;
+
+  PrintingPolicyWithSupressedTag.PrintCanonicalTypes =
+      !BaseExpr->getType()->isTypedefNameType();
+
   std::string BaseTypeName =
       BaseType.getAsString(PrintingPolicyWithSupressedTag);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119949.412111.patch
Type: text/x-patch
Size: 2559 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220301/f5a1a34a/attachment-0001.bin>


More information about the cfe-commits mailing list