Fixed false positive 'unusedVar' with C++11 initialization (#6160)

This commit is contained in:
PKEuS 2014-09-30 12:39:27 +02:00
parent 926a3694a0
commit 936043d47d
2 changed files with 13 additions and 2 deletions

View File

@ -1025,8 +1025,8 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
variables.read(tok->varId(), tok); variables.read(tok->varId(), tok);
} }
else if (Token::Match(tok, "[{,] %var% [,}]")) { else if (Token::Match(tok->previous(), "[{,] %var% [,}]")) {
variables.read(tok->next()->varId(), tok); variables.read(tok->varId(), tok);
} }
else if (tok->varId() && Token::Match(tok, "%var% .")) { else if (tok->varId() && Token::Match(tok, "%var% .")) {

View File

@ -156,6 +156,8 @@ private:
TEST_CASE(localvarNULL); // #4203 - Setting NULL value is not redundant - it is safe TEST_CASE(localvarNULL); // #4203 - Setting NULL value is not redundant - it is safe
TEST_CASE(localvarUnusedGoto); // #4447, #4558 goto TEST_CASE(localvarUnusedGoto); // #4447, #4558 goto
TEST_CASE(localvarCpp11Initialization);
TEST_CASE(chainedAssignment); // #5466 TEST_CASE(chainedAssignment); // #5466
TEST_CASE(crash1); TEST_CASE(crash1);
@ -3775,6 +3777,15 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void localvarCpp11Initialization() {
// #6160
functionVariableUsage("void foo() {\n"
" int myNewValue{ 3u };\n"
" myManager.theDummyTable.addRow(UnsignedIndexValue{ myNewValue }, DummyRowData{ false });\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void chainedAssignment() { void chainedAssignment() {
// #5466 // #5466
functionVariableUsage("void NotUsed(double* pdD, int n) {\n" functionVariableUsage("void NotUsed(double* pdD, int n) {\n"