Fixed #1699 (False positive: The function '...' can be const)

This commit is contained in:
Robert Reif 2010-05-20 17:45:10 +02:00 committed by Daniel Marjamäki
parent 1207531c21
commit 78614b8dc1
2 changed files with 28 additions and 3 deletions

View File

@ -177,9 +177,20 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo
else if (withClasses && (Token::Match(next, "%type% :: %type% <") ||
Token::Match(next, "%type% <")))
{
while (next && next->str() != ">")
next = next->next();
if (Token::Match(next, "> %var% ;"))
// find matching ">"
int level = 0;
for (; next; next = next->next())
{
if (next->str() == "<")
level++;
else if (next->str() == ">")
{
level--;
if (level == 0)
break;
}
}
if (next && Token::Match(next, "> %var% ;"))
varname = next->strAt(1);
}

View File

@ -118,6 +118,7 @@ private:
TEST_CASE(const20); // ticket #1602
TEST_CASE(const21); // ticket #1683
TEST_CASE(const22);
TEST_CASE(const23); // ticket #1699
TEST_CASE(constoperator1); // operator< can often be const
TEST_CASE(constoperator2); // operator<<
TEST_CASE(constincdec); // increment/decrement => non-const
@ -3331,6 +3332,19 @@ private:
ASSERT_EQUALS("", errout.str());
}
void const23()
{
checkConst("class Class {\n"
"public:\n"
" typedef Template<double> Type;\n"
" typedef Template2<Type> Type2;\n"
" void set_member(Type2 m) { _m = m; }\n"
"private:\n"
" Type2 _m;\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
// increment/decrement => not const
void constincdec()
{