Fixed #1883 (false positive: (style) The function 'A::SetPos' can be const)

This commit is contained in:
Robert Reif 2010-07-20 09:43:27 +02:00 committed by Daniel Marjamäki
parent 9debcb84cd
commit f2f5b3ebf0
2 changed files with 27 additions and 1 deletions

View File

@ -2368,7 +2368,12 @@ bool CheckClass::checkConstFunc(const std::string &classname, const std::vector<
(tok1->str().find("=") == 1 &&
tok1->str().find_first_of("<!>") == std::string::npos))
{
if (isMemberVar(classname, derivedFrom, varlist, tok1->previous()))
if (tok1->previous()->varId() == 0 && !derivedFrom.empty())
{
isconst = false;
break;
}
else if (isMemberVar(classname, derivedFrom, varlist, tok1->previous()))
{
isconst = false;
break;

View File

@ -3630,6 +3630,27 @@ private:
"};\n"
);
ASSERT_EQUALS("", errout.str());
checkConst("class AA : public P {\n"
"public:\n"
" AA():P(){}\n"
" inline void vSetXPos(int x_)\n"
" {\n"
" UnknownScope::x = x_;\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
checkConst("class AA {\n"
"public:\n"
" AA():P(){}\n"
" inline void vSetXPos(int x_)\n"
" {\n"
" UnknownScope::x = x_;\n"
" }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'AA::vSetXPos' can be const\n", errout.str());
}
void const27() // ticket #1882