From f462b62279c4ef37489e80f1d261f19532971809 Mon Sep 17 00:00:00 2001 From: Ivan Razumov Date: Thu, 19 Dec 2024 14:45:47 +0100 Subject: [PATCH] Add missing check for access modifier in UnnecessaryMutableChecker; fix reported location --- .../StaticAnalyzers/src/UnnecessaryMutableChecker.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Utilities/StaticAnalyzers/src/UnnecessaryMutableChecker.cpp b/Utilities/StaticAnalyzers/src/UnnecessaryMutableChecker.cpp index d2c1c50caaf77..c92770b5ea92d 100644 --- a/Utilities/StaticAnalyzers/src/UnnecessaryMutableChecker.cpp +++ b/Utilities/StaticAnalyzers/src/UnnecessaryMutableChecker.cpp @@ -46,6 +46,12 @@ namespace clangcms { if (!Field->isMutable()) { continue; } + + // == Skip non-public mutables, we deal with them elsewhere + if (Field->getAccess() != clang::AS_public) { + return; + } + // == Skip atmoic mutables, these are thread-safe by design == if (support::isStdAtomic(Field)) { return; // Skip if it's a mutable std::atomic @@ -64,6 +70,7 @@ namespace clangcms { if (!isMutableMemberModified(Field, RD)) { clang::SourceLocation Loc = Field->getLocation(); if (Loc.isValid()) { + clang::ento::PathDiagnosticLocation FieldLoc(Loc, SM); if (!BT) { BT = std::make_unique(this, "Unnecessarily Mutable Member", "Coding Practices"); } @@ -72,8 +79,8 @@ namespace clangcms { this, "Useless mutable field", "ConstThreadSafety", - "The mutable field '" + Field->getQualifiedNameAsString() + "' is not modified in any const methods", - PathLoc); + "The mutable field '" + Field->getQualifiedNameAsString() + "' is not modified in any public const methods", + FieldLoc); } } }