Fix valueFlowBailoutIncompleteVar with new (refs #10045) (#5487)

This commit is contained in:
chrchr-github 2023-09-26 21:39:07 +02:00 committed by GitHub
parent 3774d46303
commit e928f2b5aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -1522,6 +1522,13 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars()
} }
if (mSettings.library.functions.find(fstr) != mSettings.library.functions.end()) if (mSettings.library.functions.find(fstr) != mSettings.library.functions.end())
continue; 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 const_cast<Token *>(tok)->isIncompleteVar(true); // TODO: avoid const_cast
} }
} }

View File

@ -5494,6 +5494,23 @@ private:
const Token* u = Token::findsimplematch(s, "uint64_t"); const Token* u = Token::findsimplematch(s, "uint64_t");
ASSERT(u && !u->isIncompleteVar()); 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() { void enum1() {