Fixed false positive with range-based for-loop (#7075)
This commit is contained in:
parent
bfd8a69e74
commit
7866990d04
|
@ -705,7 +705,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
||||||
for (; defValTok; defValTok = defValTok->next()) {
|
for (; defValTok; defValTok = defValTok->next()) {
|
||||||
if (defValTok->str() == "[")
|
if (defValTok->str() == "[")
|
||||||
defValTok = defValTok->link();
|
defValTok = defValTok->link();
|
||||||
else if (defValTok->str() == "(" || defValTok->str() == "{" || defValTok->str() == "=") {
|
else if (defValTok->str() == "(" || defValTok->str() == "{" || defValTok->str() == "=" || defValTok->str() == ":") {
|
||||||
variables.addVar(&*i, type, true);
|
variables.addVar(&*i, type, true);
|
||||||
break;
|
break;
|
||||||
} else if (defValTok->str() == ";" || defValTok->str() == "," || defValTok->str() == ")") {
|
} else if (defValTok->str() == ";" || defValTok->str() == "," || defValTok->str() == ")") {
|
||||||
|
|
|
@ -154,6 +154,7 @@ private:
|
||||||
TEST_CASE(localvarSwitch); // #3744 - false positive when localvar is used in switch
|
TEST_CASE(localvarSwitch); // #3744 - false positive when localvar is used in switch
|
||||||
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(localvarRangeBasedFor); // #7075
|
||||||
|
|
||||||
TEST_CASE(localvarCpp11Initialization);
|
TEST_CASE(localvarCpp11Initialization);
|
||||||
|
|
||||||
|
@ -3844,6 +3845,15 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void localvarRangeBasedFor() {
|
||||||
|
// #7075
|
||||||
|
functionVariableUsage("void reset() {\n"
|
||||||
|
" for (auto & e : array)\n"
|
||||||
|
" e = 0;\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"
|
||||||
|
|
Loading…
Reference in New Issue