Skip to content

Commit

Permalink
Add missing check for access modifier in UnnecessaryMutableChecker; f…
Browse files Browse the repository at this point in the history
…ix reported location
  • Loading branch information
iarspider committed Dec 19, 2024
1 parent 63d4310 commit f462b62
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Utilities/StaticAnalyzers/src/UnnecessaryMutableChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<clang::ento::BugType>(this, "Unnecessarily Mutable Member", "Coding Practices");
}
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit f462b62

Please sign in to comment.