From 76133e02346e528fe09d97934b66c7614199e356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 29 Jun 2010 12:51:18 +0200 Subject: [PATCH] Class checking: Fixed FP for static arrays (not initialized in constructor) --- lib/checkclass.cpp | 18 +++++++++++------- test/testclass.cpp | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index c53178a8d..151baa8cd 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -104,19 +104,23 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo if (next->str() == "__property") continue; - // Is it a static variable? - bool isStatic = false; - if (next->str() == "static") + // Is it const..? + if (next->str() == "const") + { + next = next->next(); + } + + // Is it a static variable? + const bool isStatic(Token::simpleMatch(next, "static")); + if (isStatic) { - isStatic = true; next = next->next(); } // Is it a mutable variable? - bool isMutable = false; - if (next->str() == "mutable") + const bool isMutable(Token::simpleMatch(next, "mutable")); + if (isMutable) { - isMutable = true; next = next->next(); } diff --git a/test/testclass.cpp b/test/testclass.cpp index 8e25a372f..fbfb54db5 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -61,6 +61,7 @@ private: TEST_CASE(uninitVarArray3); TEST_CASE(uninitVarArray4); TEST_CASE(uninitVarArray5); + TEST_CASE(uninitVarArray6); TEST_CASE(uninitVarArray2D); TEST_CASE(uninitMissingFuncDef);// can't expand function in constructor TEST_CASE(privateCtor1); // If constructor is private.. @@ -1702,6 +1703,19 @@ private: ASSERT_EQUALS("", errout.str()); } + void uninitVarArray6() + { + checkUninitVar("class Foo\n" + "{\n" + "public:\n" + " Foo();\n" + " static const char STR[];\n" + "};\n" + "const char Foo::STR[] = \"abc\";\n" + "Foo::Foo() { }"); + ASSERT_EQUALS("", errout.str()); + } + void uninitVarArray2D() { checkUninitVar("class John\n"