-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Warn on identical subexpressions to the left and right of ||, &&, possibly >= etc #10324
Comments
chandler: At one point, this would've discovered a minor-ish bug in chrome. Maybe you know someone who might want to work on this? |
http://www.viva64.com/en/d/0090/ has more information about that warning and points out some cases where it doesn't warn. |
Nico asked me to add some samples that represent real bugs that would have been caught with such a check. Each of these bugs are in various open-source libraries Mesa3D, filed as https://bugs.freedesktop.org/show_bug.cgi?id=37648 Fixed: libjingle, filed as http://crbug.com/84129 Fixed: Webkit, filed as http://crbug.com/84141 Fixed: Also http://crbug.com/84140 , http://crbug.com/84139 Original: Fixed: skia, filed as http://crbug.com/84138 Fixed: |
possible testcases |
clang's r153568 suggests that warning on identical subexpressions next to >= (and <=, <, >) is probably useful, too. |
A related idea would be to warn about identical condition expressions in if-else statements: if (cond) |
*** Bug #9565 has been marked as a duplicate of this bug. *** |
work-in-progress patch idea |
Extended Description
http://www.viva64.com/ru/pvs-studio/ seems to warn on this code:
void f() {
int a0 = 0, a1 = 1;
if (a0 == 0 || a0 == 0)
a1 = 2;
}
It says something along the lines of "There are identical sub-expressions to the left and to the right of the '||' operator."
Can / should clang do this, too?
The text was updated successfully, but these errors were encountered: