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
          Reporter: burnus at gcc dot
  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

By comparison, cppcheck finds this issue and outputs:
  (style) Same expression on both sides of '||'.

#include <assert.h>

int foo(int x) {
  assert (x == 5 || x == 5);
  return (x == 5 || x == 5) ? 1 : 0;

Reply via email to