From e61ca252e84b9610e9702413616088b9b3dc47bf Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 4 Apr 2024 12:05:49 +0200 Subject: [PATCH] Fix #12571 debug: valueFlowBailoutIncompleteVar with trailing return type (#6229) --- lib/symboldatabase.cpp | 3 +++ test/testsymboldatabase.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index d391f053496..b51d10b517e 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1554,6 +1554,9 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars() parent = parent->astParent(); if (Token::simpleMatch(parent, "new")) continue; + // trailing return type + if (Token::simpleMatch(ftok, ".") && ftok->originalName() == "->" && Token::Match(ftok->tokAt(-1), "[])]")) + continue; } tok->isIncompleteVar(true); } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index fc684d9314b..43330c0541f 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -5845,6 +5845,16 @@ class TestSymbolDatabase : public TestFixture { const Token* r = Token::findsimplematch(q, "r"); ASSERT(r && !r->isIncompleteVar()); } + { + GET_SYMBOL_DB("void f() {\n" // #12571 + " auto g = []() -> std::string* {\n" + " return nullptr;\n" + " };\n" + "}\n"); + ASSERT(db && errout_str().empty()); + const Token* s = Token::findsimplematch(tokenizer.tokens(), "string"); + ASSERT(s && !s->isIncompleteVar()); + } } void enum1() {