Fixed false positive 'unusedVar' with C++11 initialization (#6160)
This commit is contained in:
parent
926a3694a0
commit
936043d47d
|
@ -1025,8 +1025,8 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
|||
variables.read(tok->varId(), tok);
|
||||
}
|
||||
|
||||
else if (Token::Match(tok, "[{,] %var% [,}]")) {
|
||||
variables.read(tok->next()->varId(), tok);
|
||||
else if (Token::Match(tok->previous(), "[{,] %var% [,}]")) {
|
||||
variables.read(tok->varId(), tok);
|
||||
}
|
||||
|
||||
else if (tok->varId() && Token::Match(tok, "%var% .")) {
|
||||
|
|
|
@ -156,6 +156,8 @@ private:
|
|||
TEST_CASE(localvarNULL); // #4203 - Setting NULL value is not redundant - it is safe
|
||||
TEST_CASE(localvarUnusedGoto); // #4447, #4558 goto
|
||||
|
||||
TEST_CASE(localvarCpp11Initialization);
|
||||
|
||||
TEST_CASE(chainedAssignment); // #5466
|
||||
|
||||
TEST_CASE(crash1);
|
||||
|
@ -3775,6 +3777,15 @@ private:
|
|||
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() {
|
||||
// #5466
|
||||
functionVariableUsage("void NotUsed(double* pdD, int n) {\n"
|
||||
|
|
Loading…
Reference in New Issue