loplugins ignoreLocation() is unreliable with PCH

Change-Id: Ic12cacb6e058a8725ea6d722399e3afe6ea458c6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132115
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2022-03-25 13:59:18 +02:00
parent 2029b2f6dd
commit ace70dae44
3 changed files with 11 additions and 18 deletions

View File

@ -180,8 +180,7 @@ bool SingleValFields::VisitFieldDecl( const FieldDecl* fieldDecl )
{ {
auto canonicalDecl = fieldDecl->getCanonicalDecl(); auto canonicalDecl = fieldDecl->getCanonicalDecl();
if( ignoreLocation( canonicalDecl ) if( isInUnoIncludeFile( compiler.getSourceManager().getSpellingLoc(canonicalDecl->getLocation())) )
|| isInUnoIncludeFile( compiler.getSourceManager().getSpellingLoc(canonicalDecl->getLocation())) )
return true; return true;
MyFieldInfo aInfo; MyFieldInfo aInfo;
@ -212,8 +211,7 @@ bool SingleValFields::VisitVarDecl( const VarDecl* varDecl )
if (!canonicalDecl->getLocation().isValid()) if (!canonicalDecl->getLocation().isValid())
return true; return true;
if( ignoreLocation( canonicalDecl ) if( isInUnoIncludeFile( compiler.getSourceManager().getSpellingLoc(canonicalDecl->getLocation())) )
|| isInUnoIncludeFile( compiler.getSourceManager().getSpellingLoc(canonicalDecl->getLocation())) )
return true; return true;
MyFieldInfo aInfo; MyFieldInfo aInfo;
@ -233,9 +231,6 @@ bool SingleValFields::VisitVarDecl( const VarDecl* varDecl )
bool SingleValFields::VisitCXXConstructorDecl( const CXXConstructorDecl* decl ) bool SingleValFields::VisitCXXConstructorDecl( const CXXConstructorDecl* decl )
{ {
if( ignoreLocation( decl ) )
return true;
// doesn't count as a write to fields because it's self->self // doesn't count as a write to fields because it's self->self
if (decl->isCopyOrMoveConstructor()) if (decl->isCopyOrMoveConstructor())
return true; return true;
@ -266,8 +261,6 @@ bool SingleValFields::VisitMemberExpr( const MemberExpr* memberExpr )
const FieldDecl* fieldDecl = dyn_cast<FieldDecl>(decl); const FieldDecl* fieldDecl = dyn_cast<FieldDecl>(decl);
if (!fieldDecl) if (!fieldDecl)
return true; return true;
if (ignoreLocation(memberExpr))
return true;
walkPotentialAssign(fieldDecl, memberExpr); walkPotentialAssign(fieldDecl, memberExpr);
return true; return true;
} }
@ -283,8 +276,6 @@ bool SingleValFields::VisitDeclRefExpr( const DeclRefExpr* declRefExpr )
return true; return true;
if (!(varDecl->isStaticLocal() || varDecl->isStaticDataMember() || varDecl->hasGlobalStorage())) if (!(varDecl->isStaticLocal() || varDecl->isStaticDataMember() || varDecl->hasGlobalStorage()))
return true; return true;
if (ignoreLocation(declRefExpr))
return true;
walkPotentialAssign(varDecl, declRefExpr); walkPotentialAssign(varDecl, declRefExpr);
return true; return true;
} }

View File

@ -108,9 +108,6 @@ std::string niceName(const CXXMethodDecl* cxxMethodDecl)
bool UnnecessaryVirtual::VisitCXXMethodDecl( const CXXMethodDecl* methodDecl ) bool UnnecessaryVirtual::VisitCXXMethodDecl( const CXXMethodDecl* methodDecl )
{ {
if (ignoreLocation(methodDecl)) {
return true;
}
if (!methodDecl->isVirtual() || methodDecl->isDeleted()) { if (!methodDecl->isVirtual() || methodDecl->isDeleted()) {
return true; return true;
} }
@ -132,6 +129,8 @@ bool UnnecessaryVirtual::VisitCXXMethodDecl( const CXXMethodDecl* methodDecl )
return true; return true;
methodDecl = methodDecl->getCanonicalDecl(); methodDecl = methodDecl->getCanonicalDecl();
if (!methodDecl)
return true;
std::string aNiceName = niceName(methodDecl); std::string aNiceName = niceName(methodDecl);
// for destructors, we need to check if any of the superclass' destructors are virtual // for destructors, we need to check if any of the superclass' destructors are virtual
@ -147,8 +146,11 @@ bool UnnecessaryVirtual::VisitCXXMethodDecl( const CXXMethodDecl* methodDecl )
if (baseSpecifier->getType()->isRecordType()) if (baseSpecifier->getType()->isRecordType())
{ {
const CXXRecordDecl* superclassCXXRecordDecl = baseSpecifier->getType()->getAsCXXRecordDecl(); const CXXRecordDecl* superclassCXXRecordDecl = baseSpecifier->getType()->getAsCXXRecordDecl();
std::string aOverriddenNiceName = niceName(superclassCXXRecordDecl->getDestructor()); if (superclassCXXRecordDecl->getDestructor())
overridingSet.insert(aOverriddenNiceName); {
std::string aOverriddenNiceName = niceName(superclassCXXRecordDecl->getDestructor());
overridingSet.insert(aOverriddenNiceName);
}
} }
} }
return true; return true;
@ -174,6 +176,8 @@ bool UnnecessaryVirtual::VisitCXXMethodDecl( const CXXMethodDecl* methodDecl )
void UnnecessaryVirtual::MarkRootOverridesNonEmpty( const CXXMethodDecl* methodDecl ) void UnnecessaryVirtual::MarkRootOverridesNonEmpty( const CXXMethodDecl* methodDecl )
{ {
if (!methodDecl)
return;
if (methodDecl->size_overridden_methods() == 0) { if (methodDecl->size_overridden_methods() == 0) {
nonEmptySet.insert(niceName(methodDecl)); nonEmptySet.insert(niceName(methodDecl));
return; return;

View File

@ -117,8 +117,6 @@ std::string niceName(const CXXMethodDecl* cxxMethodDecl)
bool VirtualDead::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl) bool VirtualDead::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl)
{ {
if (ignoreLocation(methodDecl))
return true;
if (!methodDecl->isVirtual() || methodDecl->isDeleted()) if (!methodDecl->isVirtual() || methodDecl->isDeleted())
return true; return true;
if (isa<CXXDestructorDecl>(methodDecl)) if (isa<CXXDestructorDecl>(methodDecl))