Fixed false positive with range-based for-loop (#7075)

This commit is contained in:
PKEuS 2015-10-27 14:46:58 +01:00
parent bfd8a69e74
commit 7866990d04
2 changed files with 11 additions and 1 deletions

View File

@ -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() == ")") {

View File

@ -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"