diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 7498285ad24..2a470f1e4ed 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1522,6 +1522,13 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars() } if (mSettings.library.functions.find(fstr) != mSettings.library.functions.end()) continue; + if (mTokenizer.isCPP()) { + const Token* parent = tok->astParent(); + while (Token::Match(parent, "::|[|{")) + parent = parent->astParent(); + if (Token::simpleMatch(parent, "new")) + continue; + } const_cast(tok)->isIncompleteVar(true); // TODO: avoid const_cast } } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index b7e846784bf..f738c999864 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -5494,6 +5494,23 @@ class TestSymbolDatabase : public TestFixture { const Token* u = Token::findsimplematch(s, "uint64_t"); ASSERT(u && !u->isIncompleteVar()); } + { + GET_SYMBOL_DB("void f() {\n" + " std::string* p = new std::string;\n" + " std::string* q = new std::string(\"abc\");\n" + " std::string* r = new std::string{ \"def\" };\n" + " std::string* s = new std::string[3]{ \"ghi\" };\n" + "}\n"); + ASSERT(db && errout.str().empty()); + const Token* s1 = Token::findsimplematch(tokenizer.tokens(), "string ;"); + ASSERT(s1 && !s1->isIncompleteVar()); + const Token* s2 = Token::findsimplematch(s1->next(), "string ("); + ASSERT(s2 && !s2->isIncompleteVar()); + const Token* s3 = Token::findsimplematch(s2->next(), "string {"); + ASSERT(s3 && !s3->isIncompleteVar()); + const Token* s4 = Token::findsimplematch(s3->next(), "string ["); + ASSERT(s4 && !s4->isIncompleteVar()); + } } void enum1() {