Skip to content

Commit e6a1efa

Browse files
author
Daniel Marjamäki
committed
Fixed cppcheck-opensource#2302 (Duplicate id 'unusedVariable')
1 parent d341b42 commit e6a1efa

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,7 @@ void CheckOther::unusedVariableError(const Token *tok, const std::string &varnam
18751875

18761876
void CheckOther::allocatedButUnusedVariableError(const Token *tok, const std::string &varname)
18771877
{
1878-
reportError(tok, Severity::style, "unusedVariable", "Variable '" + varname + "' is allocated memory that is never used");
1878+
reportError(tok, Severity::style, "unusedAllocatedMemory", "Variable '" + varname + "' is allocated memory that is never used");
18791879
}
18801880

18811881
void CheckOther::unreadVariableError(const Token *tok, const std::string &varname)

test/testcppcheck.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ class TestCppcheck : public TestFixture
7777
ASSERT(!errorLogger.id.empty());
7878

7979
// TODO: check if there are duplicate error ids in errorLogger.id
80+
std::string duplicate;
81+
for (std::list<std::string>::iterator it = errorLogger.id.begin();
82+
it != errorLogger.id.end();
83+
++it)
84+
{
85+
if (std::find(errorLogger.id.begin(), it, *it) != it)
86+
{
87+
duplicate = "Duplicate ID: " + *it;
88+
break;
89+
}
90+
}
91+
ASSERT_EQUALS("", duplicate);
8092
}
8193
};
8294

0 commit comments

Comments
 (0)