From a4dcf8feea71cadbb7af5abcf1c63579748c6e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 25 Dec 2011 11:05:06 +0100 Subject: [PATCH] Fixed #3435 (False positive: (warning) Member variable 'A::m_Vec' is not initialized in the constructor.) --- lib/symboldatabase.cpp | 4 ++-- test/testsymboldatabase.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index a6fdeda60..08baf05b1 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1547,7 +1547,7 @@ const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess) std::vector dimensions; if (tok && isVariableDeclaration(tok, vartok, typetok, isArray, isPointer)) { - isPointer = vartok->previous()->str() == "*" || vartok->strAt(-2) == "*"; + isPointer = vartok->previous()->str() == "*" || Token::simpleMatch(vartok->tokAt(-2), "* const"); isClass = (!typetok->isStandardType() && !isPointer && vartok->previous()->str() != "&"); if (isArray) { isArray = check->arrayDimensions(dimensions, vartok->next()); @@ -1646,7 +1646,7 @@ bool Scope::isVariableDeclaration(const Token* tok, const Token*& vartok, const typetok = localTypeTok; isArray = false; } - isPointer = vartok && (vartok->strAt(-1) == "*" || vartok->strAt(-2) == "*"); + isPointer = vartok && (vartok->strAt(-1) == "*" || Token::simpleMatch(vartok->tokAt(-2), "* const")); return NULL != vartok; } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 9643e4021..7f6185d9e 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -132,6 +132,7 @@ private: TEST_CASE(symboldatabase20); // ticket #3013 (segmentation fault) TEST_CASE(symboldatabase21); TEST_CASE(symboldatabase22); // ticket #3437 (segmentation fault) + TEST_CASE(symboldatabase23); // ticket #3435 } void test_isVariableDeclarationCanHandleNull() { @@ -893,6 +894,18 @@ private: ASSERT_EQUALS("", errout.str()); } + // #ticket 3435 (std::vector) + void symboldatabase23() { + GET_SYMBOL_DB("class A { std::vector ints; };\n"); + ASSERT_EQUALS(2U, db->scopeList.size()); + const Scope &scope = db->scopeList.back(); + ASSERT_EQUALS(1U, scope.varlist.size()); + const Variable &var = scope.varlist.front(); + ASSERT_EQUALS(std::string("ints"), var.name()); + ASSERT_EQUALS(true, var.isClass()); + } + + }; REGISTER_TEST(TestSymbolDatabase)