Skip to content

Conversation

@danmar
Copy link
Owner

@danmar danmar commented Nov 1, 2025

There was a regression introduced by #468 . This PR just reverts the #468 changes and introduces a test.

@danmar danmar requested a review from firewave November 1, 2025 08:45
@danmar
Copy link
Owner Author

danmar commented Nov 1, 2025

@firewave This is a critical bug for me and I can't release Cppcheck with this bug.

So when this fix is merged I want to make a new simplecpp tag and merge it to cppcheck.. you made many refactorings since 1.6.1 do you think we should tag HEAD or make a release branch that only contains this change..

@firewave
Copy link
Collaborator

firewave commented Nov 3, 2025

CC @glankk

@glankk
Copy link
Contributor

glankk commented Nov 3, 2025

Caused by nextcond not being set in if tokens with a false condition when followed by an elif. A fix:

diff --git a/simplecpp.cpp b/simplecpp.cpp
index 7d306fd..ef891eb 100644
--- a/simplecpp.cpp
+++ b/simplecpp.cpp
@@ -3701,12 +3701,11 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
                     else
                         ifstates.push(conditionIsTrue ? True : ElseIsTrue);
                     iftokens.push(rawtok);
-                } else if (ifstates.top() == True) {
-                    ifstates.top() = AlwaysFalse;
-                    iftokens.top()->nextcond = rawtok;
-                    iftokens.top() = rawtok;
-                } else if (ifstates.top() == ElseIsTrue && conditionIsTrue) {
-                    ifstates.top() = True;
+                } else {
+                    if (ifstates.top() == True)
+                        ifstates.top() = AlwaysFalse;
+                    else if (ifstates.top() == ElseIsTrue && conditionIsTrue)
+                        ifstates.top() = True;
                     iftokens.top()->nextcond = rawtok;
                     iftokens.top() = rawtok;
                 }

@danmar danmar merged commit 7a81c1a into master Nov 5, 2025
31 checks passed
@danmar danmar deleted the fix-581 branch November 5, 2025 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants