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 17d0074
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 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,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<clang::ento::BugType>(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);
}
}
}
Expand Down

0 comments on commit 17d0074

Please sign in to comment.