diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index b6dce8e02..8dab3b4b1 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1430,6 +1430,8 @@ void CheckClass::checkConst() { // get function name const std::string functionName(tok2->strAt(2)); + if (functionName == classname) + continue; // goto the ')' tok2 = tok2->tokAt(3)->link(); diff --git a/test/testclass.cpp b/test/testclass.cpp index a9b853108..00d18b5f8 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -1530,6 +1530,15 @@ private: " int getA() { return a; }\n" "};\n"); ASSERT_EQUALS("[test.cpp:3]: (style) The function 'Fred::getA' can be const\n", errout.str()); + + // constructors can't be const.. + checkConst("class Fred {\n" + " int a;\n" + "public:\n" + " Fred() { }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } };