diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 81aa25d89..aa9c5d6e3 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1449,6 +1449,7 @@ const Token * findParameter(const Token *var, const Token *start, const Token * return 0; } +// Can a function be const? void CheckClass::checkConst() { if (!_settings->_checkCodingStyle) @@ -1570,6 +1571,13 @@ void CheckClass::checkConst() isconst = false; break; } + + // delete.. + else if (tok3->str() == "delete") + { + isconst = false; + break; + } } // nothing non-const was found. write error.. diff --git a/test/testclass.cpp b/test/testclass.cpp index 6c02b17a9..94e7b9af5 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -89,6 +89,7 @@ private: TEST_CASE(constoperator); // operator< can often be const TEST_CASE(constincdec); // increment/decrement => non-const TEST_CASE(constReturnReference); + TEST_CASE(constDelete); // delete member variable => not const } // Check the operator Equal @@ -1786,6 +1787,16 @@ private: "};\n"); ASSERT_EQUALS("", errout.str()); } + + // delete member variable => not const (but technically it can, it compiles without errors) + void constDelete() + { + checkConst("class Fred {\n" + " int *a;\n" + " void clean() { delete a; }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestClass)