Repository navigation
Report the usages of a macro that is undefined or redefined - #764
Open
JayToltTech wants to merge 1 commit into
Open
JayToltTech wants to merge 1 commit into
JayToltTech wants to merge 1 commit into
Conversation
preprocess() built the macro usage list from the macros still defined when preprocessing ended, so the usages of a macro were lost after #undef, and after a redefinition the usages of the first definition were lost. An #ifdef before the #undef was reported against the later definition. The usages are now reported when the definition goes away.
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
preprocess()builds the macro usage list from the macros that are still in its map when preprocessing ends. So after#undef Aevery usage ofAis gone from the list, and ifAis redefined the usages of the first definition are gone too.That gives an empty usage list, where I'd expect
A 1:9 use 2:1.There's a second effect with
#ifdef. Those usages are kept by name, so an#ifdef Athat came before#undef A/#define Agets reported against the second definition.Came up in cppcheck-opensource/cppcheck#9018, where cppcheck uses the usage list to apply
cppcheck-suppress-macro. A suppression on a macro that's#undef'd after its use doesn't match anything.This reports a macro's usages at the point its definition goes away, on
#undefand on redefinition, and at the end for whatever is left as before. The#ifdefusages for that name are handed over at the same time so they don't get counted again for a later definition.Tests are
macroUsageUndef,macroUsageRedefineandmacroUsageUndefIfdef, and all three fail without the change. testrunner and run-tests.py pass on macOS arm64. I also dropped the change into cppcheck'sexternals/simplecpplocally and the#undefcase in #9018 is suppressed with it.runformatmakes no changes.Separate from #759, they don't touch the same lines.