Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #13202 FP oppositeInnerCondition for string defines #6889

Merged
merged 10 commits into from
Oct 11, 2024

Conversation

chrchr-github
Copy link
Collaborator

No description provided.

lib/astutils.cpp Outdated
if (macro) {
if (tok1->isExpandedMacro() != tok2->isExpandedMacro())
return false;
if (tok1->isExpandedMacro() && tok1->originalName() != tok2->originalName())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if (MACRO == MACRO) should still result in a warning

Copy link
Owner

Choose a reason for hiding this comment

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

hmm I am not sure but I don't think originalName checks the macro name? If we check that the macro names in LHS and RHS are the same then I would agree with you.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should probably use getMacroName() instead, and add a test. originalName() seems to be for typedefs only.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should say "typdefs and other simplifications which aren't macro replacements". We should probably spell that out in a comment for originalName().

@@ -7066,6 +7066,14 @@ class TestOther : public TestFixture {
" if ($a == $a) { }\n"
"}");
ASSERT_EQUALS("", errout_str());

checkP("#define X 1\n"
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure what macroName there will be if there are nested macros. Can you try this:

#define X 1
#define Y X
void f() {
     if (X == Y) {}
}

I think that ideally we don't warn about that because Y could possibly have different definitions..

Copy link
Owner

Choose a reason for hiding this comment

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

it strikes me that it might be within reach to identify if a macro can have different possible values in different configurations.. if the code is something like:

#ifdef __GNUC__
#define X 1
#else
#define X 2
#endif

I think it would not be impossible to mark "X" as a macro that has different values using the info from simplecpp that I think is available. But the info must be propagated to the checkers somehow..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We also don't know if a macro was a simple define or a functional-style macro, which should be handled differently (see the failing test in windows.cpp).

chrchr-github added a commit that referenced this pull request Oct 11, 2024
@chrchr-github chrchr-github reopened this Oct 11, 2024
Copy link
Owner

@danmar danmar left a comment

Choose a reason for hiding this comment

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

lgtm

@chrchr-github chrchr-github merged commit c3e3387 into danmar:main Oct 11, 2024
103 of 129 checks passed
@chrchr-github chrchr-github deleted the chr_13202 branch October 11, 2024 15:29
ludviggunne pushed a commit to ludviggunne/cppcheck that referenced this pull request Oct 19, 2024
ludviggunne pushed a commit to ludviggunne/cppcheck that referenced this pull request Oct 19, 2024
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