-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix #14660 Handle reverse conditions in isOppositeCond function #8408
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2674,6 +2674,12 @@ class TestCondition : public TestFixture { | |
| check("void f1(const std::string &s) { if(s.size() >= 0) if(s.empty()) {}} "); // CheckOther says: Unsigned expression 's.size()' can't be negative so it is unnecessary to test it. [unsignedPositive] | ||
| ASSERT_EQUALS("", errout_str()); | ||
|
|
||
| check("void f1(const std::string &s) { if(42 < s.size()) if(s.empty()) {}}"); | ||
| ASSERT_EQUALS("[test.cpp:1:39] -> [test.cpp:1:61]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm I feel it's out of scope for this PR but I feel the warning message is a bit obfuscated. The "leads to a dead code block" is true but it's an indirect consequence. I think it would be better to try to describe the direct consequence that inner condition |
||
|
|
||
| check("void f1(const std::string &s) { if(s.empty()) if(42 < s.size()) {}}"); | ||
| ASSERT_EQUALS("[test.cpp:1:43] -> [test.cpp:1:53]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); | ||
|
|
||
| // TODO: These are identical condition since size cannot be negative | ||
| check("void f1(const std::string &s) { if(s.size() <= 0) if(s.empty()) {}}"); | ||
| ASSERT_EQUALS("", errout_str()); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.