Skip to content

Do not record a usage for a function-like macro name without ( - #759

Open
JayToltTech wants to merge 1 commit into
cppcheck-opensource:masterfrom
JayToltTech:macro-usage-unexpanded
Open

JayToltTech wants to merge 1 commit into
cppcheck-opensource:masterfrom
JayToltTech:macro-usage-unexpanded

Conversation

@JayToltTech

@JayToltTech JayToltTech commented Nov 13, 2026 •

Copy link
Copy Markdown

Macro::expand() adds the use location to usageList before it checks whether a function-like macro is followed by (. So with #define F(x) x, the F in int F = 1; shows up in the macro usage list even though nothing is expanded there.

Came up in cppcheck-opensource/cppcheck#9018, where cppcheck uses the usage list to apply cppcheck-suppress-macro and that phantom usage suppressed a real zerodiv. That PR filters it on the cppcheck side for now.

This moves the usageList.emplace_back below the no-arguments check. __COUNTER__ still sees its usage before it reads the count, and builtins aren't function-like so they're unaffected.

tokenMacro16 covers it. testrunner and run-tests.py pass on macOS arm64. I also dropped the same change into cppcheck's externals/simplecpp locally and its testrunner passes. runformat with uncrustify 0.80.1 makes no changes.

expand() added the use location to the usage list before checking whether
a function-like macro is followed by (, so `int F = 1;` with F defined as
a function-like macro was reported as a usage of F although nothing is
expanded. Record the usage after that check.
Copilot AI balanced review requested due to automatic review settings November 13, 2026 04:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

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