Skip to content

Fix #581 (Failure when header is included twice with different macros defined)#582

Merged
danmar merged 1 commit into
masterfrom
fix-581
Nov 5, 2025
Merged

Fix #581 (Failure when header is included twice with different macros defined)#582
danmar merged 1 commit into
masterfrom
fix-581

Conversation

@danmar

@danmar danmar commented Nov 1, 2025

Copy link
Copy Markdown
Collaborator

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

danmar commented Nov 1, 2025

Copy link
Copy Markdown
Collaborator Author

@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

firewave commented Nov 3, 2025

Copy link
Copy Markdown
Collaborator

CC @glankk

@glankk

glankk commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

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.

4 participants