Fixed #1522 (false positive: function can be const (assignment in return))
This commit is contained in:
parent
bef1857221
commit
e95bc41e59
|
@ -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:"))
|
||||
while (tok->previous() && !Token::Match(tok->previous(), "}|{|;|public:|protected:|private:|return"))
|
||||
{
|
||||
if (Token::Match(tok->previous(), "* this"))
|
||||
return true;
|
||||
|
|
|
@ -94,6 +94,7 @@ private:
|
|||
TEST_CASE(const7);
|
||||
TEST_CASE(const8); // ticket #1517
|
||||
TEST_CASE(const9); // ticket #1515
|
||||
TEST_CASE(const10);
|
||||
TEST_CASE(constoperator); // operator< can often be const
|
||||
TEST_CASE(constincdec); // increment/decrement => non-const
|
||||
TEST_CASE(constReturnReference);
|
||||
|
@ -2155,6 +2156,17 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void const10()
|
||||
{
|
||||
checkConst("class A {\n"
|
||||
"public:\n"
|
||||
" int foo() { return x = 0; }\n"
|
||||
"private:\n"
|
||||
" int x;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// increment/decrement => not const
|
||||
void constincdec()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue