Fixed #1403 (false positive: The function can be const)

This commit is contained in:
Daniel Marjamäki 2010-02-20 09:55:51 +01:00
parent 6a03fa604c
commit d0348fa57a
2 changed files with 19 additions and 0 deletions

View File

@ -1449,6 +1449,7 @@ const Token * findParameter(const Token *var, const Token *start, const Token *
return 0;
}
// Can a function be const?
void CheckClass::checkConst()
{
if (!_settings->_checkCodingStyle)
@ -1570,6 +1571,13 @@ void CheckClass::checkConst()
isconst = false;
break;
}
// delete..
else if (tok3->str() == "delete")
{
isconst = false;
break;
}
}
// nothing non-const was found. write error..

View File

@ -89,6 +89,7 @@ private:
TEST_CASE(constoperator); // operator< can often be const
TEST_CASE(constincdec); // increment/decrement => non-const
TEST_CASE(constReturnReference);
TEST_CASE(constDelete); // delete member variable => not const
}
// Check the operator Equal
@ -1786,6 +1787,16 @@ private:
"};\n");
ASSERT_EQUALS("", errout.str());
}
// delete member variable => not const (but technically it can, it compiles without errors)
void constDelete()
{
checkConst("class Fred {\n"
" int *a;\n"
" void clean() { delete a; }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestClass)