Merge branch 'master' of git@github.com:danmar/cppcheck

This commit is contained in:
Martin Ettl 2010-04-02 20:24:04 +02:00
commit 5a21fe7ae8
4 changed files with 32 additions and 13 deletions

View File

@ -390,17 +390,8 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
patternIdentified = true; patternIdentified = true;
} }
// Any symbolname..
if (firstWordEquals(p, "%name%") == 0)
{
if (!tok->isName())
return false;
patternIdentified = true;
}
// Type.. // Type..
if (firstWordEquals(p, "%type%") == 0) else if (firstWordEquals(p, "%type%") == 0)
{ {
if (!tok->isName()) if (!tok->isName())
return false; return false;

View File

@ -98,7 +98,6 @@ public:
* Possible patterns * Possible patterns
* - "%any%" any token * - "%any%" any token
* - "%var%" any token which is a name or type e.g. "hello" or "int" * - "%var%" any token which is a name or type e.g. "hello" or "int"
* - "%name%" any token which is a name or type e.g. "hello" or "int"
* - "%type%" Anything that can be a variable type, e.g. "int", but not "delete". * - "%type%" Anything that can be a variable type, e.g. "int", but not "delete".
* - "%num%" Any numeric token, e.g. "23" * - "%num%" Any numeric token, e.g. "23"
* - "%bool%" true or false * - "%bool%" true or false

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 classPattern(std::string(isStruct ? "struct " : "class ") + classname + " :|{");
const std::string internalPattern(std::string("!!~ ") + funcname + " ("); 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()) 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())) else if (indentlevel == 0 && Token::Match(tok, externalPattern.c_str()))
{ {
if (!Token::simpleMatch(tok->previous(), "::"))
return tok; return tok;
} }
} }

View File

@ -69,6 +69,7 @@ private:
TEST_CASE(uninitOperator); // No FP about uninitialized 'operator[]' TEST_CASE(uninitOperator); // No FP about uninitialized 'operator[]'
TEST_CASE(uninitFunction1); // No FP when initialized in function TEST_CASE(uninitFunction1); // No FP when initialized in function
TEST_CASE(uninitFunction2); // 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(noConstructor1);
TEST_CASE(noConstructor2); TEST_CASE(noConstructor2);
@ -1574,6 +1575,33 @@ private:
ASSERT_EQUALS("", errout.str()); 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[]) void checkNoConstructor(const char code[])
{ {
// Tokenize.. // Tokenize..