diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index d374c798c..d026ea2f6 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -186,8 +186,24 @@ void CheckClass::addFunction(SpaceInfo **info, const Token **tok) { if (argsMatch(func->tokenDef->next(), (*tok)->next(), path, path_length)) { - func->hasBody = true; - func->token = (*tok); + // normal function? + if (!func->retFuncPtr && (*tok)->next()->link()) + { + if ((func->isConst && (*tok)->next()->link()->next()->str() == "const") || + (!func->isConst && (*tok)->next()->link()->next()->str() != "const")) + { + func->hasBody = true; + func->token = (*tok); + } + } + + // function returning function pointer? + else if (func->retFuncPtr) + { + // todo check for const + func->hasBody = true; + func->token = (*tok); + } } } diff --git a/test/testclass.cpp b/test/testclass.cpp index 42b1a2718..eb6c66e63 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -149,6 +149,7 @@ private: TEST_CASE(const36); // ticket #2003 TEST_CASE(const37); // ticket #2081 and #2085 TEST_CASE(const38); // ticket #2135 + TEST_CASE(const39); TEST_CASE(constoperator1); // operator< can often be const TEST_CASE(constoperator2); // operator<< TEST_CASE(constoperator3); @@ -4368,6 +4369,28 @@ private: ASSERT_EQUALS("", errout.str()); } + void const39() + { + checkConst("class Foo\n" + "{\n" + " int * p;\n" + "public:\n" + " Foo () : p(0) { }\n" + " int * f();\n" + " const int * f() const;\n" + "};\n" + "const int * Foo::f() const\n" + "{\n" + " return p;\n" + "}\n" + "int * Foo::f()\n" + "{\n" + " return p;\n" + "}\n"); + + ASSERT_EQUALS("", errout.str()); + } + // increment/decrement => not const void constincdec() {