diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index eb4d8dc93..8fbbd3d15 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1978,6 +1978,11 @@ bool CheckClass::checkConstFunc(const SpaceInfo *info, const Token *tok) isconst = false; break; } + else if (tok1->next()->str() == "this") + { + isconst = false; + break; + } } // streaming: << diff --git a/test/testclass.cpp b/test/testclass.cpp index 83b6717d9..f1216a90d 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -138,6 +138,7 @@ private: TEST_CASE(const31); TEST_CASE(const32); // ticket #1905 - member array is assigned TEST_CASE(const33); + TEST_CASE(const34); // ticket #1964 TEST_CASE(constoperator1); // operator< can often be const TEST_CASE(constoperator2); // operator<< TEST_CASE(constincdec); // increment/decrement => non-const @@ -3888,6 +3889,16 @@ private: ASSERT_EQUALS("", errout.str()); } + void const34() // ticket #1964 + { + checkConst("class Bar {\n" + " void init(Foo * foo) {\n" + " foo.bar = this;\n" + " }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } + // increment/decrement => not const void constincdec() {