diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 04d870ef6..3f80505ad 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1532,7 +1532,7 @@ void CheckClass::checkConst() // skip private: public: etc if (tok2->isName() && tok2->str().find(":") != std::string::npos) - tok2 = tok2->next(); + continue; // static functions can't be const // virtual functions may be non-const for a reason diff --git a/test/testclass.cpp b/test/testclass.cpp index 48addef36..668e3b709 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -89,6 +89,7 @@ private: TEST_CASE(const3); TEST_CASE(const4); TEST_CASE(const5); // ticket #1482 + TEST_CASE(const6); // ticket #1491 TEST_CASE(constoperator); // operator< can often be const TEST_CASE(constincdec); // increment/decrement => non-const TEST_CASE(constReturnReference); @@ -2064,6 +2065,16 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) The function 'A::foo' can be const\n", errout.str()); } + void const6() + { + // ticket # 1491 + checkConst("class foo {\n" + "public:\n" + "};\n" + "void bar() {}"); + ASSERT_EQUALS("", errout.str()); + } + // increment/decrement => not const void constincdec() {