Skip to content

Commit 0f8ce70

Browse files
Update checkunusedvar.cpp
1 parent 5b70f39 commit 0f8ce70

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

lib/checkunusedvar.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,15 @@ class Variables {
148148
void clear() {
149149
mVarUsage.clear();
150150
}
151+
void clearConst() {
152+
std::set<int> keys;
153+
for (const std::pair<const nonneg int, Variables::VariableUsage>& var : mVarUsage) {
154+
if (var.second._var && var.second._var->isConst())
155+
keys.emplace(var.first);
156+
}
157+
for (const int key : keys)
158+
mvarUsage.erase(key);
159+
}
151160
const std::map<nonneg int, VariableUsage> &varUsage() const {
152161
return mVarUsage;
153162
}
@@ -796,9 +805,8 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
796805
// templates
797806
if (tok->isName() && endsWith(tok->str(), '>')) {
798807
// TODO: This is a quick fix to handle when constants are used
799-
// as template parameters. Try to handle this better, perhaps
800-
// only remove constants.
801-
variables.clear();
808+
// as template parameters.
809+
variables.clearConst();
802810
}
803811

804812
else if (Token::Match(tok->previous(), "[;{}]")) {

0 commit comments

Comments
 (0)