-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Conversation
lib/astutils.cpp
Outdated
if (macro) { | ||
if (tok1->isExpandedMacro() != tok2->isExpandedMacro()) | ||
return false; | ||
if (tok1->isExpandedMacro() && tok1->originalName() != tok2->originalName()) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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).
Caused inconsistent results in #6889
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Caused inconsistent results in danmar#6889
No description provided.