Fixed #1312 (false positive: missing const message on functions returning references)

This commit is contained in:
Daniel Marjamäki 2010-01-25 21:40:57 +01:00
parent 8be8c266ac
commit e12d115e9a
2 changed files with 14 additions and 2 deletions

View File

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

View File

@ -83,6 +83,7 @@ private:
TEST_CASE(const1);
TEST_CASE(constoperator); // operator< can often be const
TEST_CASE(constincdec); // increment/decrement => non-const
TEST_CASE(constReturnReference);
}
// Check the operator Equal
@ -1586,6 +1587,17 @@ private:
"};\n");
ASSERT_EQUALS("", errout.str());
}
// return pointer/reference => not const
void constReturnReference()
{
checkConst("class Fred {\n"
" int a;\n"
" int &getR() { return a; }\n"
" int *getP() { return &a; }"
"};\n");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestClass)