From 3f57b5a6ca8e15da06c7c83cdb2594e1bb953414 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 28 Mar 2013 06:36:49 +0100 Subject: [PATCH] Fixed #4682 (using 'struct' disables checking) --- lib/symboldatabase.cpp | 19 +++++++++++++++++-- test/testsymboldatabase.cpp | 11 +++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 6fcbe93c7..8ebdb0550 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -72,8 +72,23 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti tok2 = tok2->tokAt(2); // make sure we have valid code - if (!tok2 || !Token::Match(tok2, "{|:")) - break; + if (!tok2 || !Token::Match(tok2, "{|:")) { + // check for qualified variable + if (tok2 && tok2->next()) { + if (tok2->next()->str() == ";") + tok = tok2->next(); + else if (Token::Match(tok2->next(), "= {") && + tok2->linkAt(2)->next()->str() == ";") + tok = tok2->linkAt(2)->next(); + else if (Token::Match(tok2->next(), "(|{") && + tok2->next()->link()->next()->str() == ";") + tok = tok2->next()->link()->next(); + else + break; // bail + continue; + } + break; // bail + } Scope *new_scope = findScope(tok->next(), scope); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 939450349..07b5a32d8 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -188,6 +188,7 @@ private: TEST_CASE(symboldatabase29); // ticket #4442 (segmentation fault) TEST_CASE(symboldatabase30); TEST_CASE(symboldatabase31); + TEST_CASE(symboldatabase33); // ticket #4682 (false negatives) TEST_CASE(isImplicitlyVirtual); @@ -1445,6 +1446,16 @@ private: ASSERT(db && db->findScopeByName("Deri") && db->findScopeByName("Deri")->definedType->getFunction("foo")); } + void symboldatabase33() { // ticket #4682 + GET_SYMBOL_DB("static struct A::B s;\n" + "static struct A::B t = { 0 };\n" + "static struct A::B u(0);\n" + "static struct A::B v{0};\n" + "static struct A::B w({0});\n" + "void foo() { }"); + ASSERT(db && db->functionScopes.size() == 1); + } + void isImplicitlyVirtual() { { GET_SYMBOL_DB("class Base {\n"