diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index b335ea747..b33fe2867 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1893,9 +1893,6 @@ void CheckClass::checkConst() // does the function have a body? if (func.type == Func::Function && func.hasBody && !func.isFriend && !func.isStatic && !func.isConst && !func.isVirtual) { - // get function name - const std::string functionName((func.tokenDef->isName() ? "" : "operator") + func.tokenDef->str()); - // get last token of return type const Token *previous = func.tokenDef->isName() ? func.token->previous() : func.token->tokAt(-2); while (previous->str() == "::") @@ -1969,6 +1966,14 @@ void CheckClass::checkConst() nest = nest->nestedIn; } + // get function name + std::string functionName((func.tokenDef->isName() ? "" : "operator") + func.tokenDef->str()); + + if (func.tokenDef->str() == "(") + functionName += ")"; + else if (func.tokenDef->str() == "[") + functionName += "]"; + if (func.isInline) checkConstError(func.token, classname, functionName); else // not inline diff --git a/test/testclass.cpp b/test/testclass.cpp index 934ab28f6..483d61690 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -2878,7 +2878,7 @@ private: " int array[10];\n" " int const & operator [] (unsigned int index) { return array[index]; }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) The function 'Fred::operator[' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (style) The function 'Fred::operator[]' can be const\n", errout.str()); } void const5()