better fix for #2672 (False positive: function can be const, nested classes declared in one line)

This commit is contained in:
Robert Reif 2011-03-23 20:19:32 -04:00
parent 5f36ede4f5
commit 7e3e5d628d
3 changed files with 36 additions and 23 deletions

View File

@ -5673,6 +5673,16 @@ void Tokenizer::simplifyVarDecl()
if (Token::Match(tok2, "%type% *| %var% , %type% *| %var%"))
continue;
// check for qualification..
if (Token::Match(tok2, "%type% :: %type%"))
{
while (tok2 && Token::Match(tok2, "%type% ::"))
{
typelen += 2;
tok2 = tok2->tokAt(2);
}
}
if (Token::Match(tok2, "%type% *| %var% ,|="))
{
const bool isPointer = (tok2->next()->str() == "*");
@ -5715,17 +5725,6 @@ void Tokenizer::simplifyVarDecl()
}
}
else if (Token::Match(tok2, "%type% :: %type% %var% ,|="))
{
if (tok2->tokAt(3)->str() != "operator")
{
tok2 = tok2->tokAt(4); // The ',' token
typelen = 3;
}
else
tok2 = NULL;
}
else if (Token::Match(tok2, "%type% %var% [ %num% ] ,|=|[") ||
Token::Match(tok2, "%type% %var% [ %var% ] ,|=|["))
{
@ -5758,17 +5757,8 @@ void Tokenizer::simplifyVarDecl()
tok2 = tok2->tokAt(6); // The ',' token
}
else if (Token::Match(tok2, "std :: %type% <") || Token::Match(tok2, "%type% <"))
else if (Token::Match(tok2, "%type% <"))
{
//
// Deal with templates and standart types
//
if (Token::simpleMatch(tok2, "std ::"))
{
typelen += 2;
tok2 = tok2->tokAt(2);
}
typelen += 2;
tok2 = tok2->tokAt(2);
size_t indentlevel = 1;
@ -5827,7 +5817,6 @@ void Tokenizer::simplifyVarDecl()
typelen = 0;
}
if (tok2)
{
if (tok2->str() == ",")

View File

@ -168,6 +168,7 @@ private:
TEST_CASE(const45); // ticket #2664
TEST_CASE(const46); // ticket #2636
TEST_CASE(const47); // ticket #2670
TEST_CASE(const48); // ticket #2672
TEST_CASE(assigningPointerToPointerIsNotAConstOperation);
TEST_CASE(assigningArrayElementIsNotAConstOperation);
TEST_CASE(constoperator1); // operator< can often be const
@ -5283,6 +5284,29 @@ private:
ASSERT_EQUALS("[test.cpp:5]: (information) Technically the member function 'Altren::bar' can be const.\n", errout.str());
}
void const48() // ticket 2672
{
checkConst("class S0 {\n"
" class S1 {\n"
" class S2 {\n"
" class S3 {\n"
" class S4 { };\n"
" };\n"
" };\n"
" };\n"
"};\n"
"class TextIterator {\n"
" S0::S1::S2::S3::S4 mCurrent, mSave;\n"
"public:\n"
" bool setTagColour();\n"
"};\n"
"bool TextIterator::setTagColour() {\n"
" mSave = mCurrent;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void assigningPointerToPointerIsNotAConstOperation()
{
checkConst("struct s\n"

View File

@ -831,7 +831,7 @@ private:
" std::string * x = 0;\n"
" *x = \"test\";\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n", errout.str());
}
// Check if pointer is null and the dereference it