diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 2029d4955..8fbd0c007 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2210,6 +2210,8 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool& return false; tok1 = jumpBackToken?jumpBackToken:end; // Jump back to first [ to check inside, or jump to end of expression + if (tok1 == end && Token::Match(end->previous(), ". %name% ( !!)")) + tok1 = tok1->previous(); // check function call } // streaming: << diff --git a/test/testclass.cpp b/test/testclass.cpp index 81e6d037a..a219c7cac 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -173,6 +173,7 @@ private: TEST_CASE(const68); // ticket #6471 TEST_CASE(const69); // ticket #9806 TEST_CASE(const70); // variadic template can receive more arguments than in its definition + TEST_CASE(const71); // ticket #10146 TEST_CASE(const_handleDefaultParameters); TEST_CASE(const_passThisToMemberOfOtherClass); TEST_CASE(assigningPointerToPointerIsNotAConstOperation); @@ -5772,6 +5773,19 @@ private: ASSERT_EQUALS("", errout.str()); } + void const71() { // #10146 + checkConst("struct Bar {\n" + " int j = 5;\n" + " void f(int& i) const { i += j; }\n" + "};\n" + "struct Foo {\n" + " Bar bar;\n" + " int k{};\n" + " void g() { bar.f(k); }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } + void const_handleDefaultParameters() { checkConst("struct Foo {\n" " void foo1(int i, int j = 0) {\n"