From cdbc7026710751e15379282f6b3ba0d116b414a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 25 Nov 2026 15:46:47 +0100 Subject: [PATCH] Fix #15272 (Tokenizer: isSplittedVarDeclEq is set on '=' instead of ';' for function pointer declaration with initializer) --- lib/tokenize.cpp | 2 +- lib/valueflow.cpp | 3 ++- test/testtokenize.cpp | 12 ++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 60fbe92968c..9eee81a02e6 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7761,7 +7761,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co varName = varName->link()->previous(); endDecl->insertToken(";"); endDecl = endDecl->next(); - endDecl->next()->isSplittedVarDeclEq(true); + endDecl->isSplittedVarDeclEq(true); endDecl->insertToken(varName->str()); if (!varName->getMacroName().empty()) endDecl->next()->setMacroName(varName->getMacroName()); diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index b2a5798795d..686cb6f6a5e 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -4243,7 +4243,8 @@ static void valueFlowAfterAssign(const TokenList &tokenlist, }); if (values.empty()) continue; - const bool init = vars.size() == 1 && (vars.front()->nameToken() == tok->astOperand1() || tok->isSplittedVarDeclEq()); + const bool init = vars.size() == 1 && (vars.front()->nameToken() == tok->astOperand1() || + (Token::Match(tok->tokAt(-2), "; %var% =") && tok->tokAt(-2)->isSplittedVarDeclEq())); valueFlowForwardAssign( rhs, tok->astOperand1(), std::move(vars), values, init, tokenlist, errorLogger, settings); // Back propagate symbolic values diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 8822a66fc27..d527b98f62c 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -252,6 +252,7 @@ class TestTokenizer : public TestFixture { TEST_CASE(vardecl_par2); // #3912 - set correct links TEST_CASE(vardecl_par3); // #6556 - Fred x1(a), x2(b); TEST_CASE(vardecl_class_ref); + TEST_CASE(vardecl_funcptr_splitted); TEST_CASE(volatile_variables); // unsigned i; => unsigned int i; @@ -2559,6 +2560,17 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("class A { B & b1 ; B & b2 ; } ;", tokenizeAndStringify(code)); } + void vardecl_funcptr_splitted() { + const char code[] = "int g(int);\n" + "void f() { int (*fp)(int) = g; }\n"; + SimpleTokenizer tokenizer(settings1, *this); + ASSERT(tokenizer.tokenize(code)); + const Token* semi = Token::findsimplematch(tokenizer.tokens(), "; fp = g ;"); + ASSERT(semi); + ASSERT(semi->isSplittedVarDeclEq()); + ASSERT(!semi->tokAt(2)->isSplittedVarDeclEq()); + } + void vardec_static() { { // don't simplify declarations of static variables