From cbbf500cd48472f48c0c4dd1cebd2c805248678a Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 11 Sep 2023 16:49:39 +0200 Subject: [PATCH] Fix valueFlowBailoutIncompleteVar for init list (refs #10045) (#5433) --- lib/symboldatabase.cpp | 2 +- test/testsymboldatabase.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index d1c0d3d33..28a505362 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index b7ff49913..64e89d8f8 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -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;");