From 2825773918b0b2508c3004a596e952d95625b167 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 1 Apr 2010 17:01:52 +0200 Subject: [PATCH] Fixed #1552 (false positive: function can be const (array of struct)) --- lib/checkclass.cpp | 7 +++++-- test/testclass.cpp | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) 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() {