Fixed #1319 (false negative: missing const not found)

This commit is contained in:
Daniel Marjamäki 2010-01-29 19:38:56 +01:00
parent 53f514fc5c
commit f561441d90
2 changed files with 13 additions and 0 deletions

View File

@ -1441,6 +1441,8 @@ void CheckClass::checkConst()
// member function?
if (Token::Match(tok2, "%type% %var% (") ||
Token::Match(tok2, "%type% %type% %var% (") ||
Token::Match(tok2, "const %type% &|* %var% (") ||
Token::Match(tok2, "const std :: %type% &|*| %var% (") ||
Token::Match(tok2, "%type% operator %any% ("))
{
// goto function name..

View File

@ -1546,6 +1546,17 @@ private:
"};\n");
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'Fred::getA' can be const\n", errout.str());
checkConst("class Fred {\n"
" const std::string foo() { return ""; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:2]: (style) The function 'Fred::foo' can be const\n", errout.str());
checkConst("class Fred {\n"
" std::string s;\n"
" const std::string & foo() { return ""; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'Fred::foo' can be const\n", errout.str());
// constructors can't be const..
checkConst("class Fred {\n"
" int a;\n"