diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 2cfb188c3..455ed4008 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1743,7 +1743,7 @@ bool CheckClass::sameFunc(int nest, const Token *firstEnd, const Token *secondEn bool CheckClass::isMemberVar(const Var *varlist, const Token *tok) { - while (tok->previous() && !Token::Match(tok->previous(), "}|{|;|public:|protected:|private:")) + while (tok->previous() && !Token::Match(tok->previous(), "}|{|;|public:|protected:|private:|return")) { if (Token::Match(tok->previous(), "* this")) return true; diff --git a/test/testclass.cpp b/test/testclass.cpp index 65be780e4..8c1e3c8fc 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -94,6 +94,7 @@ private: TEST_CASE(const7); TEST_CASE(const8); // ticket #1517 TEST_CASE(const9); // ticket #1515 + TEST_CASE(const10); TEST_CASE(constoperator); // operator< can often be const TEST_CASE(constincdec); // increment/decrement => non-const TEST_CASE(constReturnReference); @@ -2155,6 +2156,17 @@ private: ASSERT_EQUALS("", errout.str()); } + void const10() + { + checkConst("class A {\n" + "public:\n" + " int foo() { return x = 0; }\n" + "private:\n" + " int x;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + // increment/decrement => not const void constincdec() {