Fixed #1303 (False positive: The function 'x' can be const for a constructor)

This commit is contained in:
Daniel Marjamäki 2010-01-23 20:47:29 +01:00
parent f62466493b
commit 5b76be4935
2 changed files with 11 additions and 0 deletions

View File

@ -1430,6 +1430,8 @@ void CheckClass::checkConst()
{
// get function name
const std::string functionName(tok2->strAt(2));
if (functionName == classname)
continue;
// goto the ')'
tok2 = tok2->tokAt(3)->link();

View File

@ -1530,6 +1530,15 @@ private:
" int getA() { return a; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'Fred::getA' can be const\n", errout.str());
// constructors can't be const..
checkConst("class Fred {\n"
" int a;\n"
"public:\n"
" Fred() { }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
};