diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 91c065751..d6dc8bcb8 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -120,6 +120,12 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo next = next->next(); } + // Is it const..? + if (next->str() == "const") + { + next = next->next(); + } + // Is it a variable declaration? if (Token::Match(next, "%type% %var% ;|:")) { diff --git a/test/testclass.cpp b/test/testclass.cpp index fb947f758..9b0430192 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -116,6 +116,7 @@ private: TEST_CASE(const18); // ticket #1563 TEST_CASE(const19); // ticket #1612 TEST_CASE(const20); // ticket #1602 + TEST_CASE(const21); // ticket #1683 TEST_CASE(constoperator1); // operator< can often be const TEST_CASE(constoperator2); // operator<< TEST_CASE(constincdec); // increment/decrement => non-const @@ -3291,6 +3292,23 @@ private: ASSERT_EQUALS("[test.cpp:4]: (style) The function 'Fred::get' can be const\n", errout.str()); } + void const21() + { + // ticket #1683 + checkConst("class A\n" + "{\n" + "private:\n" + " const char * l1[10];\n" + "public:\n" + " A()\n" + " {\n" + " for (int i = 0 ; i < 10; l1[i] = NULL, i++);\n" + " }\n" + " void f1() { l1[0] = \"Hello\"; }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } + // increment/decrement => not const void constincdec() {