From 17d00748fea8b13b6aad90a3d2ca304fbbb83b4c 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 --- .../src/UnnecessaryMutableChecker.cpp | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Utilities/StaticAnalyzers/src/UnnecessaryMutableChecker.cpp b/Utilities/StaticAnalyzers/src/UnnecessaryMutableChecker.cpp index d2c1c50caaf77..0933f912e963c 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,16 +70,17 @@ 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"); } - BR.EmitBasicReport( - Field, - this, - "Useless mutable field", - "ConstThreadSafety", - "The mutable field '" + Field->getQualifiedNameAsString() + "' is not modified in any const methods", - PathLoc); + BR.EmitBasicReport(Field, + this, + "Useless mutable field", + "ConstThreadSafety", + "The mutable field '" + Field->getQualifiedNameAsString() + + "' is not modified in any public const methods", + FieldLoc); } } }