From 3faff5e9fcaf349aea295fe7a4359a9a66f1a939 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 22 Mar 2022 07:24:40 +0100 Subject: [PATCH] Fix #10248 FP knownConditionTrueFalse static variable with direct initialization (#3922) --- lib/tokenize.cpp | 1 + lib/valueflow.cpp | 2 +- test/testcondition.cpp | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 1aea3d0ef..232e57c6e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7497,6 +7497,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->insertToken(varName->str()); continue; } diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 8329d0116..42b284277 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -5292,7 +5292,7 @@ static void valueFlowAfterAssign(TokenList *tokenlist, SymbolDatabase* symboldat }); if (values.empty()) continue; - const bool init = vars.size() == 1 && vars.front()->nameToken() == tok->astOperand1(); + const bool init = vars.size() == 1 && (vars.front()->nameToken() == tok->astOperand1() || tok->isSplittedVarDeclEq()); valueFlowForwardAssign( tok->astOperand2(), tok->astOperand1(), vars, values, init, tokenlist, errorLogger, settings); // Back propagate symbolic values diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 53fb51701..c29e4695d 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -3935,7 +3935,7 @@ private: " if (logger == nullptr)\n" " logger = Fun;\n" "}\n"); - TODO_ASSERT_EQUALS("", "[test.cpp:5]: (style) Condition 'logger==nullptr' is always true\n", errout.str()); + ASSERT_EQUALS("", errout.str()); check("void Fun();\n" "typedef void (*Fn)();\n"