Fixed #1522 (false positive: function can be const (assignment in return))

This commit is contained in:
Robert Reif 2010-03-26 16:30:30 +01:00 committed by Daniel Marjamäki
parent 80edb4d8f4
commit a1528d3154
2 changed files with 19 additions and 2 deletions

View File

@ -1743,7 +1743,7 @@ bool CheckClass::sameFunc(int nest, const Token *firstEnd, const Token *secondEn
bool CheckClass::isMemberVar(const Var *varlist, const Token *tok)
{
while (tok->previous() && !Token::Match(tok->previous(), "}|{|;|public:|protected:|private:|return"))
while (tok->previous() && !Token::Match(tok->previous(), "}|{|;|public:|protected:|private:|return|:|?"))
{
if (Token::Match(tok->previous(), "* this"))
return true;

View File

@ -94,7 +94,7 @@ private:
TEST_CASE(const7);
TEST_CASE(const8); // ticket #1517
TEST_CASE(const9); // ticket #1515
TEST_CASE(const10);
TEST_CASE(const10); // ticket #1522
TEST_CASE(constoperator); // operator< can often be const
TEST_CASE(constincdec); // increment/decrement => non-const
TEST_CASE(constReturnReference);
@ -2158,6 +2158,7 @@ private:
void const10()
{
// ticket #1522
checkConst("class A {\n"
"public:\n"
" int foo() { return x = 0; }\n"
@ -2165,6 +2166,22 @@ private:
" int x;\n"
"}");
ASSERT_EQUALS("", errout.str());
checkConst("class A {\n"
"public:\n"
" int foo() { return (x ? x : x = 0); }\n"
"private:\n"
" int x;\n"
"}");
ASSERT_EQUALS("", errout.str());
checkConst("class A {\n"
"public:\n"
" int foo() { return (x ? x = 0 : x); }\n"
"private:\n"
" int x;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
// increment/decrement => not const