Skip to content

Fix rescanning when a macro expansion result forms a new function-like macro call - #682

Merged
danmar merged 4 commits into
cppcheck-opensource:masterfrom
pfultz2:macro-expansion
Aug 4, 2026
Merged

Fix rescanning when a macro expansion result forms a new function-like macro call#682
danmar merged 4 commits into
cppcheck-opensource:masterfrom
pfultz2:macro-expansion

Conversation

@pfultz2

Copy link
Copy Markdown
Contributor

When the result of a macro expansion ends with the name of a function-like
macro and the tokens that follow supply its arguments, simplecpp performed
that rescan only once instead of repeatedly. Given:

#define a(b, c) c
#define d() a
#define g(e) h(e, ) h(e, )
#define h(e, b) d()(, e)()
#define i()
g(i)

g(i) expanded to i ( ) i ( ) instead of nothing: inside h's body
d()(, e)(), d() was correctly rescanned as a(, i) yielding i, but the
resulting i was never rescanned against the trailing ().

The rescan logic was also missing logic to prevent re-expanding the same macro name: so #define f() f + f()() gave f instead of f().

@pfultz2

Copy link
Copy Markdown
ContributorAuthor

@danmar@firewave Any feedback?

@pfultz2

Copy link
Copy Markdown
ContributorAuthor

@danmar Are you able to review?

@danmar

Copy link
Copy Markdown
Collaborator

I hope this might fix some existing issue i.e. #549

@pfultz2

Copy link
Copy Markdown
ContributorAuthor

@danmar Can this be merged now?

@danmar
danmar merged commit 74a5a63 into cppcheck-opensource:masterAug 4, 2026
26 checks passed
@danmar

Copy link
Copy Markdown
Collaborator

This did not solve #549 unfortunately :-(

@pfultz2
pfultz2 deleted the macro-expansion branch August 4, 2026 20:07
@pfultz2

Copy link
Copy Markdown
ContributorAuthor

This did not solve #549 unfortunately :-(

I opened #695 which fixes that issue.

Sign up for freeto 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.

2 participants

@pfultz2@danmar