diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 4bd9b46ad..40ea68a7d 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1554,8 +1554,9 @@ void CheckClass::checkConst() // member function? if (Token::Match(tok2, "%type% %var% (") || Token::Match(tok2, "%type% %type% %var% (") || + Token::Match(tok2, "%type% :: %type% %var% (") || Token::Match(tok2, "const %type% &|* %var% (") || - Token::Match(tok2, "const std :: %type% &|*| %var% (") || + Token::Match(tok2, "const %type% :: %type% &|*| %var% (") || Token::Match(tok2, "%type% operator %any% (")) { // goto function name.. diff --git a/test/testclass.cpp b/test/testclass.cpp index 3cfa1aa2f..86969f53f 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -92,6 +92,7 @@ private: TEST_CASE(const5); // ticket #1482 TEST_CASE(const6); // ticket #1491 TEST_CASE(const7); + TEST_CASE(const8); // ticket #1517 TEST_CASE(constoperator); // operator< can often be const TEST_CASE(constincdec); // increment/decrement => non-const TEST_CASE(constReturnReference); @@ -2128,6 +2129,19 @@ private: ASSERT_EQUALS("", errout.str()); } + void const8() + { + // ticket #1517 + checkConst("class A {\n" + "public:\n" + " A():m_strValue(""){}\n" + " std::string strGetString() { return m_strValue; }\n" + "private:\n" + " std::string m_strValue;\n" + "}"); + ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::strGetString' can be const\n", errout.str()); + } + // increment/decrement => not const void constincdec() {