This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/77965] New: -Wduplicated-cond should find duplicated condition / identical expressions of form "a || a" or "a && a"


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;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]