Fixed wrongly detected unconditional scope with C++11-style initialization in SymbolDatabase (#6581)

This commit is contained in:
PKEuS 2015-11-06 10:16:44 +01:00
parent eefea507b9
commit eb2b0fa0d0
2 changed files with 20 additions and 2 deletions

View File

@ -823,8 +823,10 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
else if (scope->type == Scope::eCatch)
scope->checkVariable(tok->tokAt(2), Throw, &settings->library); // check for variable declaration and add it to new scope if found
tok = scopeStartTok;
} else if (tok->str() == "{" && !tok->previous()->varId()) {
if (tok->strAt(-1) == ")" && tok->linkAt(-1)->strAt(-1) == "]") {
} else if (tok->str() == "{") {
if (tok->previous()->varId())
tok = tok->link();
else if (tok->strAt(-1) == ")" && tok->linkAt(-1)->strAt(-1) == "]") {
scopeList.push_back(Scope(this, tok->linkAt(-1)->linkAt(-1), scope, Scope::eLambda, tok));
scope->nestedList.push_back(&scopeList.back());
scope = &scopeList.back();

View File

@ -233,6 +233,7 @@ private:
TEST_CASE(symboldatabase49); // #6424
TEST_CASE(symboldatabase50); // #6432
TEST_CASE(symboldatabase51); // #6538
TEST_CASE(symboldatabase52); // #6581
TEST_CASE(isImplicitlyVirtual);
@ -2174,6 +2175,21 @@ private:
}
}
void symboldatabase52() { // #6581
GET_SYMBOL_DB("void foo() {\n"
" int i = 0;\n"
" S s{ { i }, 0 };\n"
"}");
ASSERT(db != nullptr);
if (db) {
ASSERT_EQUALS(2, db->scopeList.size());
ASSERT_EQUALS(2, db->getVariableListSize()-1);
ASSERT(db->getVariableFromVarId(1));
ASSERT(db->getVariableFromVarId(2));
}
}
void isImplicitlyVirtual() {
{
GET_SYMBOL_DB("class Base {\n"