diff --git a/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp b/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp --- a/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp @@ -19,14 +19,15 @@ static unsigned getNameSpecifierNestingLevel(const QualType &QType) { if (const ElaboratedType *ElType = QType->getAs()) { - 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; } diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp @@ -197,6 +197,15 @@ h<4>(); } +struct SP { + static int I; +} P; + +void usep() { + P.I; + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member + // CHECK-FIXES: {{^}} struct SP::I;{{$}} +} // Overloaded member access operator struct Q {