Fix #10077 FP functionConst when overloaded operator ++ is used (#4309)

This commit is contained in:
chrchr-github 2022-07-26 08:30:59 +02:00 committed by GitHub
parent 0005be1dbf
commit 58d7185d64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -2266,6 +2266,8 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
return false;
if (Token::Match(tok1->previous(), "( this . * %var% )")) // call using ptr to member function TODO: check constness
return false;
if (Token::simpleMatch(tok1->astParent(), "*") && tok1->astParent()->astParent() && tok1->astParent()->astParent()->isIncDecOp())
return false;
}
// non const pointer cast

View File

@ -6245,6 +6245,14 @@ private:
" void nextA() { return a--; }\n"
"};");
ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout.str());
checkConst("struct S {\n" // #10077
" int i{};\n"
" S& operator ++() { ++i; return *this; }\n"
" S operator ++(int) { S s = *this; ++(*this); return s; }\n"
" void f() { (*this)--; }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void constassign1() {