Fixed #1308 (False positive: The function 'x' can be const for a static member function)

This commit is contained in:
Daniel Marjamäki 2010-01-24 18:26:39 +01:00
parent 019f775aa5
commit 7ce4825f95
2 changed files with 16 additions and 1 deletions

View File

@ -1433,8 +1433,14 @@ void CheckClass::checkConst()
if (tok2->isName() && tok2->str().find(":") != std::string::npos)
tok2 = tok2->next();
// static functions can't be const
// virtual functions may be non-const for a reason
if (Token::Match(tok2, "static|virtual"))
continue;
// member function?
if (Token::Match(tok2, "%type% %var% (") ||
if (Token::Match(tok2, "%type% *|&| %var% (") ||
Token::Match(tok2, "%type% %type% *|&| %var% (") ||
Token::Match(tok2, "%type% operator %any% ("))
{
// goto function name..

View File

@ -1556,6 +1556,15 @@ private:
" void b() { a(); }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
// static functions can't be const..
checkConst("class foo\n"
"{\n"
"public:\n"
" static unsigned get()\n"
" { return 0; }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
// operator< can often be const