Fix valueFlowBailoutIncompleteVar for init list (refs #10045) (#5433)

This commit is contained in:
chrchr-github 2023-09-11 16:49:39 +02:00 committed by GitHub
parent aa281501c9
commit cbbf500cd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -1482,7 +1482,7 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars()
continue;
if (tok->type())
continue;
if (Token::Match(tok->next(), "::|.|(|:|%var%"))
if (Token::Match(tok->next(), "::|.|(|{|:|%var%"))
continue;
if (Token::Match(tok->next(), "&|&&|* )|,|%var%"))
continue;

View File

@ -373,6 +373,8 @@ private:
TEST_CASE(createSymbolDatabaseFindAllScopes5);
TEST_CASE(createSymbolDatabaseFindAllScopes6);
TEST_CASE(createSymbolDatabaseIncompleteVars);
TEST_CASE(enum1);
TEST_CASE(enum2);
TEST_CASE(enum3);
@ -5426,6 +5428,19 @@ private:
ASSERT_EQUALS(classNC.derivedFrom[1].type, &classNB);
}
void createSymbolDatabaseIncompleteVars()
{
GET_SYMBOL_DB("void f() {\n"
" auto s1 = std::string{ \"abc\" };\n"
" auto s2 = std::string(\"def\");\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, "string (");
ASSERT(s2 && !s2->isIncompleteVar());
}
void enum1() {
GET_SYMBOL_DB("enum BOOL { FALSE, TRUE }; enum BOOL b;");