Fixed #1784 (false positive: Variable is not assigned a value)
This commit is contained in:
parent
6b65b77acf
commit
3d2c28a524
|
@ -946,7 +946,7 @@ void CheckOther::functionVariableUsage()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (Token::Match(tok, "struct|union|class {") ||
|
else if (Token::Match(tok, "struct|union|class {") ||
|
||||||
Token::Match(tok, "struct|union|class %type% {"))
|
Token::Match(tok, "struct|union|class %type% {|:"))
|
||||||
{
|
{
|
||||||
while (tok->str() != "{")
|
while (tok->str() != "{")
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
|
@ -104,6 +104,7 @@ private:
|
||||||
TEST_CASE(localvarFor); // for ( ; var; )
|
TEST_CASE(localvarFor); // for ( ; var; )
|
||||||
TEST_CASE(localvarShift); // 1 >> var
|
TEST_CASE(localvarShift); // 1 >> var
|
||||||
TEST_CASE(localvarCast);
|
TEST_CASE(localvarCast);
|
||||||
|
TEST_CASE(localvarClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
void structmember1()
|
void structmember1()
|
||||||
|
@ -1881,6 +1882,17 @@ private:
|
||||||
ASSERT_EQUALS(std::string(""), errout.str());
|
ASSERT_EQUALS(std::string(""), errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void localvarClass()
|
||||||
|
{
|
||||||
|
functionVariableUsage("int foo()\n"
|
||||||
|
"{\n"
|
||||||
|
" class B : public A {\n"
|
||||||
|
" int a;\n"
|
||||||
|
" int f() { return a; }\n"
|
||||||
|
" } b;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS(std::string(""), errout.str());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestUnusedVar)
|
REGISTER_TEST(TestUnusedVar)
|
||||||
|
|
Loading…
Reference in New Issue