From eb2b0fa0d05731c0e1fdcdf20232b048121028ec Mon Sep 17 00:00:00 2001 From: PKEuS Date: Fri, 6 Nov 2015 10:16:44 +0100 Subject: [PATCH] Fixed wrongly detected unconditional scope with C++11-style initialization in SymbolDatabase (#6581) --- lib/symboldatabase.cpp | 6 ++++-- test/testsymboldatabase.cpp | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 313ebaa94..5e8f2995b 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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(); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 5aab459aa..434259a4d 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -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"