From 58d7185d642e227ca1543ff2ce365ec86ef031b6 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 26 Jul 2022 08:30:59 +0200 Subject: [PATCH] Fix #10077 FP functionConst when overloaded operator ++ is used (#4309) --- lib/checkclass.cpp | 2 ++ test/testclass.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index fd5de98d8..b20fd14a4 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -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 diff --git a/test/testclass.cpp b/test/testclass.cpp index 0db854351..6891f1b21 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -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() {