This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/77965] New: -Wduplicated-cond should find duplicated condition / identical expressions of form "a || a" or "a && a"
- From: "burnus at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 13 Oct 2016 12:23:40 +0000
- Subject: [Bug c/77965] New: -Wduplicated-cond should find duplicated condition / identical expressions of form "a || a" or "a && a"
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77965
Bug ID: 77965
Summary: -Wduplicated-cond should find duplicated condition /
identical expressions of form "a || a" or "a && a"
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: burnus at gcc dot gnu.org
Target Milestone: ---
First, I wonder whether "-Wduplicated-cond" should be enabled by -Wextra (or
even -Wall).
Secondly, it only warns for "if (a) ... else if (a) ...". However, it would be
also useful to warn for "(a || a)" and "(a && a)" as such code is easily
written by copy'n'paste.
[Possibly, instead of -Wduplicated-cond it should be used with
-Wtautological-compare?]
By comparison, cppcheck finds this issue and outputs:
(style) Same expression on both sides of '||'.
Example:
#include <assert.h>
int foo(int x) {
assert (x == 5 || x == 5);
return (x == 5 || x == 5) ? 1 : 0;
}