Fixed #1784 (false positive: Variable is not assigned a value)

This commit is contained in:
Robert Reif 2010-06-10 07:21:47 +02:00 committed by Daniel Marjamäki
parent 6b65b77acf
commit 3d2c28a524
2 changed files with 13 additions and 1 deletions

View File

@ -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();

View File

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