diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index f9d6521b9..ee20203f0 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5491,6 +5491,7 @@ void Tokenizer::simplifyIfAssign() for (tok2 = tok2->next(); tok2 && tok2 != tok; tok2 = tok2->previous()) { tok3->insertToken(tok2->str()); + tok3->next()->varId(tok2->varId()); Token *newTok = tok3->next(); newTok->fileIndex(tok2->fileIndex()); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index c6bcd068a..b564b0080 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -144,6 +144,7 @@ private: TEST_CASE(ifAssignWithCast); TEST_CASE(whileAssign1); TEST_CASE(whileAssign2); + TEST_CASE(whileAssign3); // varid // "if(0==x)" => "if(!x)" TEST_CASE(ifnot); @@ -2507,6 +2508,19 @@ private: ASSERT_EQUALS("", errout.str()); } + void whileAssign3() { + // #4254 - Variable id + const char code[] = "void f() {\n" + " int a;\n" + " while (a = x());\n" + "}"; + ASSERT_EQUALS("\n\n##file 0\n" + "1: void f ( ) {\n" + "2: int a@1 ;\n" + "3: a@1 = x ( ) ; while ( a@1 ) { ; a@1 = x ( ) ; }\n" + "4: }\n", tokenizeDebugListing(code, true, "test.c")); + } + void ifnot() { ASSERT_EQUALS("if ( ! x ) { ; }", tok("if(0==x);", false));