From 7b2b844b8eb58bd13a6bda368a9d71989ca3ce18 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Fri, 20 Aug 2010 19:47:41 +0200 Subject: [PATCH] Fixed #1964 (False positive: function can be const (get this)) --- lib/checkclass.cpp | 5 +++++ test/testclass.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+) 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() {