diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 11a73e2e9..d2fb2e3e4 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -152,8 +152,11 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo // Array? else if (Token::Match(next, "%type% %var% [") && next->next()->str() != "operator") { - if (Token::findmatch(_tokenizer->tokens(), ("class|struct " + next->str()).c_str())) - continue; + if (!withClasses) + { + if (Token::findmatch(_tokenizer->tokens(), ("class|struct " + next->str()).c_str())) + continue; + } varname = next->strAt(1); } diff --git a/test/testclass.cpp b/test/testclass.cpp index 7feede591..14a48e8e3 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -108,6 +108,7 @@ private: TEST_CASE(const14); TEST_CASE(const15); TEST_CASE(const16); // ticket #1551 + TEST_CASE(const17); // ticket #1552 TEST_CASE(constoperator); // operator< can often be const TEST_CASE(constincdec); // increment/decrement => non-const TEST_CASE(constReturnReference); @@ -2788,6 +2789,18 @@ private: ASSERT_EQUALS("", errout.str()); } + void const17() + { + // ticket #1552 + checkConst("class Fred {\n" + "public:\n" + " void set(int i, int j) { a[i].k = i; }\n" + "private:\n" + " struct { int k; } a[4];\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } + // increment/decrement => not const void constincdec() {