[PATCH] D119949: [Clang-tidy] Check the existence of ElaboratedType's qualifiers
Jun Zhang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 17 00:36:15 PST 2022
junaire updated this revision to Diff 409510.
junaire added a comment.
- Only suppress canonical types when it's a TypedefNameType.
- Add more tests.
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,11 @@
PrintingPolicy PrintingPolicyWithSupressedTag(AstContext->getLangOpts());
PrintingPolicyWithSupressedTag.SuppressTagKeyword = true;
PrintingPolicyWithSupressedTag.SuppressUnwrittenScope = true;
+
+ bool ShouldPrintCanonicalTy =
+ BaseExpr->getType()->isTypedefNameType() ? false : true;
+ PrintingPolicyWithSupressedTag.PrintCanonicalTypes = ShouldPrintCanonicalTy;
+
std::string BaseTypeName =
BaseType.getAsString(PrintingPolicyWithSupressedTag);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119949.409510.patch
Type: text/x-patch
Size: 2630 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220217/ab590a5d/attachment.bin>
More information about the cfe-commits
mailing list