really fix #3149 (false negative: Technically the member function 'A::f' can be const.)

This commit is contained in:
Robert Reif 2011-09-30 11:16:34 -04:00
parent 70b153cc1e
commit 1dcb8b2382
2 changed files with 44 additions and 1 deletions

View File

@ -1663,7 +1663,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Token *tok)
// function call..
else if (Token::Match(tok1, "%var% (") &&
!(Token::Match(tok1, "return|c_str|if|string|switch|while") || tok1->isStandardType()))
!(Token::Match(tok1, "return|c_str|if|string|switch|while|catch") || tok1->isStandardType()))
{
if (!isConstMemberFunc(scope, tok1))
{

View File

@ -5766,6 +5766,49 @@ private:
" }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:3]: (information) Technically the member function 'MyObject::foo' can be const.\n", errout.str());
checkConst("class A\n"
"{\n"
" protected:\n"
" unsigned short f (unsigned short X);\n"
" public:\n"
" A ();\n"
"};\n"
"\n"
"unsigned short A::f (unsigned short X)\n"
"{\n"
" enum ERetValues {RET_NOK = 0, RET_OK = 1};\n"
" enum ETypes {FLOAT_TYPE = 1, INT_TYPE = 2};\n"
"\n"
" try\n"
" {\n"
" switch (X)\n"
" {\n"
" case FLOAT_TYPE:\n"
" {\n"
" return RET_OK;\n"
" break;\n"
" }\n"
" case INT_TYPE:\n"
" {\n"
" return RET_OK;\n"
" break;\n"
" }\n"
" default:\n"
" {\n"
" return RET_NOK;\n"
" break;\n"
" }\n"
" }\n"
" }\n"
" catch (...)\n"
" {\n"
" return RET_NOK;\n"
" }\n"
"\n"
" return RET_NOK;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:4]: (information) Technically the member function 'A::f' can be const.\n", errout.str());
}
void assigningPointerToPointerIsNotAConstOperation()