[Clang-tidy] Check the existence of ElaboratedType's qualifiers
The ElaboratedType can have no qualifiers, so we should check it before use. Fix #issue53874(https://github.com/llvm/llvm-project/issues/53874) Differential Revision: https://reviews.llvm.org/D119949
This commit is contained in:
parent
70ab0a9b62
commit
ac616fbb05
|
@ -19,7 +19,7 @@ namespace readability {
|
||||||
|
|
||||||
static unsigned getNameSpecifierNestingLevel(const QualType &QType) {
|
static unsigned getNameSpecifierNestingLevel(const QualType &QType) {
|
||||||
if (const ElaboratedType *ElType = QType->getAs<ElaboratedType>()) {
|
if (const ElaboratedType *ElType = QType->getAs<ElaboratedType>()) {
|
||||||
const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier();
|
if (const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier()) {
|
||||||
unsigned NameSpecifierNestingLevel = 1;
|
unsigned NameSpecifierNestingLevel = 1;
|
||||||
do {
|
do {
|
||||||
NameSpecifierNestingLevel++;
|
NameSpecifierNestingLevel++;
|
||||||
|
@ -28,6 +28,7 @@ static unsigned getNameSpecifierNestingLevel(const QualType &QType) {
|
||||||
|
|
||||||
return NameSpecifierNestingLevel;
|
return NameSpecifierNestingLevel;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +69,10 @@ void StaticAccessedThroughInstanceCheck::check(
|
||||||
PrintingPolicy PrintingPolicyWithSupressedTag(AstContext->getLangOpts());
|
PrintingPolicy PrintingPolicyWithSupressedTag(AstContext->getLangOpts());
|
||||||
PrintingPolicyWithSupressedTag.SuppressTagKeyword = true;
|
PrintingPolicyWithSupressedTag.SuppressTagKeyword = true;
|
||||||
PrintingPolicyWithSupressedTag.SuppressUnwrittenScope = true;
|
PrintingPolicyWithSupressedTag.SuppressUnwrittenScope = true;
|
||||||
|
|
||||||
|
PrintingPolicyWithSupressedTag.PrintCanonicalTypes =
|
||||||
|
!BaseExpr->getType()->isTypedefNameType();
|
||||||
|
|
||||||
std::string BaseTypeName =
|
std::string BaseTypeName =
|
||||||
BaseType.getAsString(PrintingPolicyWithSupressedTag);
|
BaseType.getAsString(PrintingPolicyWithSupressedTag);
|
||||||
|
|
||||||
|
|
|
@ -198,6 +198,28 @@ void static_through_instance() {
|
||||||
h<4>();
|
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
|
// Overloaded member access operator
|
||||||
struct Q {
|
struct Q {
|
||||||
static int K;
|
static int K;
|
||||||
|
|
Loading…
Reference in New Issue