From 307000b448842583bdee74934b234b609e0b1737 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Fri, 26 Mar 2010 18:16:33 +0100 Subject: [PATCH] Fixed #1529 (false positive: function can be const (struct member variable)) --- lib/checkclass.cpp | 6 ++++++ test/testclass.cpp | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 84a59d74b..c4654b107 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -123,6 +123,12 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo varname = next->strAt(1); } + // Structure? + else if (Token::Match(next, "struct|union %type% %var% ;")) + { + varname = next->strAt(2); + } + // Pointer? else if (Token::Match(next, "%type% * %var% ;")) { diff --git a/test/testclass.cpp b/test/testclass.cpp index f7dc0c9ae..a0deef392 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -97,6 +97,7 @@ private: TEST_CASE(const8); // ticket #1517 TEST_CASE(const9); // ticket #1515 TEST_CASE(const10); // ticket #1522 + TEST_CASE(const11); // ticket #1529 TEST_CASE(constoperator); // operator< can often be const TEST_CASE(constincdec); // increment/decrement => non-const TEST_CASE(constReturnReference); @@ -2216,6 +2217,18 @@ private: ASSERT_EQUALS("", errout.str()); } + void const11() + { + // ticket #1529 + checkConst("class A {\n" + "public:\n" + " void set(struct tm time) { m_time = time; }\n" + "private:\n" + " struct tm m_time;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + // increment/decrement => not const void constincdec() {