Fixed #1565 (False positive: Uninitialized variable 'B::j'. There are 2 classes with the name 'B')

This commit is contained in:
Daniel Marjamäki 2010-04-02 19:29:54 +02:00
parent 9788333ee9
commit c6bbc9d739
2 changed files with 31 additions and 2 deletions

View File

@ -6180,7 +6180,7 @@ const Token * Tokenizer::findClassFunction(const Token *tok, const std::string &
*/
const std::string classPattern(std::string(isStruct ? "struct " : "class ") + classname + " :|{");
const std::string internalPattern(std::string("!!~ ") + funcname + " (");
const std::string externalPattern(std::string(classname) + " :: " + funcname + " (");
const std::string externalPattern(classname + " :: " + funcname + " (");
for (; tok; tok = tok->next())
{
@ -6234,6 +6234,7 @@ const Token * Tokenizer::findClassFunction(const Token *tok, const std::string &
else if (indentlevel == 0 && Token::Match(tok, externalPattern.c_str()))
{
if (!Token::simpleMatch(tok->previous(), "::"))
return tok;
}
}

View File

@ -69,6 +69,7 @@ private:
TEST_CASE(uninitOperator); // No FP about uninitialized 'operator[]'
TEST_CASE(uninitFunction1); // No FP when initialized in function
TEST_CASE(uninitFunction2); // No FP when initialized in function
TEST_CASE(uninitSameClassName); // No FP when two classes have the same name
TEST_CASE(noConstructor1);
TEST_CASE(noConstructor2);
@ -1574,6 +1575,33 @@ private:
ASSERT_EQUALS("", errout.str());
}
void uninitSameClassName()
{
checkUninitVar("class B\n"
"{\n"
"public:\n"
" B();\n"
" int j;\n"
"};\n"
"\n"
"class A\n"
"{\n"
" class B\n"
" {\n"
" public:\n"
" B();\n"
" int i;\n"
" };\n"
"};\n"
"\n"
"A::B::B()\n"
"{\n"
" i = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void checkNoConstructor(const char code[])
{
// Tokenize..