diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 69cf8e70533..9fc9bdc7863 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2567,7 +2567,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, Member 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()) + if (Token::simpleMatch(tok1->astParent(), "*")) return false; } diff --git a/test/testclass.cpp b/test/testclass.cpp index 62cf32cfba5..2cecdfe80f6 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -6974,13 +6974,28 @@ class TestClass : public TestFixture { } void const101() { - checkConst("struct error {\n" + checkConst("struct error {\n" // #14450 " error() = default;\n" "};\n" "struct S : U {\n" " int f() { return this->error(); }\n" "};\n"); ASSERT_EQUALS("", errout_str()); + + checkConst("struct S {\n" // #14702 + " int i;\n" + " void f() {\n" + " S& r = *this;\n" + " r.i = 0;\n" + " }\n" + "};\n" + "struct T : std::array {\n" + " void g() {\n" + " for (int& r : *this)\n" + " r = 0;\n" + " }\n" + "};\n"); + ASSERT_EQUALS("", errout_str()); } void const_handleDefaultParameters() {