Fixed #3435 (False positive: (warning) Member variable 'A::m_Vec' is not initialized in the constructor.)

This commit is contained in:
Daniel Marjamäki 2011-12-25 11:05:06 +01:00
parent 347982a347
commit a4dcf8feea
2 changed files with 15 additions and 2 deletions

View File

@ -1547,7 +1547,7 @@ const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess)
std::vector<Dimension> dimensions; std::vector<Dimension> dimensions;
if (tok && isVariableDeclaration(tok, vartok, typetok, isArray, isPointer)) { 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() != "&"); isClass = (!typetok->isStandardType() && !isPointer && vartok->previous()->str() != "&");
if (isArray) { if (isArray) {
isArray = check->arrayDimensions(dimensions, vartok->next()); isArray = check->arrayDimensions(dimensions, vartok->next());
@ -1646,7 +1646,7 @@ bool Scope::isVariableDeclaration(const Token* tok, const Token*& vartok, const
typetok = localTypeTok; typetok = localTypeTok;
isArray = false; isArray = false;
} }
isPointer = vartok && (vartok->strAt(-1) == "*" || vartok->strAt(-2) == "*"); isPointer = vartok && (vartok->strAt(-1) == "*" || Token::simpleMatch(vartok->tokAt(-2), "* const"));
return NULL != vartok; return NULL != vartok;
} }

View File

@ -132,6 +132,7 @@ private:
TEST_CASE(symboldatabase20); // ticket #3013 (segmentation fault) TEST_CASE(symboldatabase20); // ticket #3013 (segmentation fault)
TEST_CASE(symboldatabase21); TEST_CASE(symboldatabase21);
TEST_CASE(symboldatabase22); // ticket #3437 (segmentation fault) TEST_CASE(symboldatabase22); // ticket #3437 (segmentation fault)
TEST_CASE(symboldatabase23); // ticket #3435
} }
void test_isVariableDeclarationCanHandleNull() { void test_isVariableDeclarationCanHandleNull() {
@ -893,6 +894,18 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
// #ticket 3435 (std::vector)
void symboldatabase23() {
GET_SYMBOL_DB("class A { std::vector<int*> 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) REGISTER_TEST(TestSymbolDatabase)