Fixed #1312 (false positive: missing const message on functions returning references)
This commit is contained in:
parent
8be8c266ac
commit
e12d115e9a
|
@ -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..
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue