Skip to content

Commit

Permalink
Fix valueFlowBailoutIncompleteVar with new (refs #10045) (#5487)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Sep 26, 2023
1 parent 3774d46 commit e928f2b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Token *>(tok)->isIncompleteVar(true); // TODO: avoid const_cast
}
}
Expand Down
17 changes: 17 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit e928f2b

Please sign in to comment.