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

@pfultz2 pfultz2 commented Jul 13, 2026

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

pfultz2 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

@danmar @firewave Any feedback?

@pfultz2

pfultz2 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@danmar Are you able to review?

@danmar

danmar commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

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

@pfultz2

pfultz2 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

@danmar Can this be merged now?

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

danmar commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

This did not solve #549 unfortunately :-(

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.

2 participants