llvm-project/clang/test/Sema/bitwise-op-parentheses.c
Fangrui Song e93341f7c8 [Sema] Disable -Wbitwise-op-parentheses and -Wlogical-op-parentheses by default
Summary:
The -Wparentheses warnings are enabled by default in clang but they are under
-Wall in gcc (gcc/c-family/c.opt). Some of the operator precedence warnings are
oftentimes criticized as noise (clang: default; gcc: -Wall). If a warning is
very controversial, it is probably not a good idea to enable it by default.
This patch disables the rather annoying ones:

-Wbitwise-op-parentheses, e.g. i & i | i
-Wlogical-op-parentheses, e.g. i && i || i

After this change:

```
* = enabled by default

-Wall
  -Wparentheses
    -Wlogical-op-parentheses
    -Wlogical-not-parentheses*
    -Wbitwise-op-parentheses
    -Wshift-op-parentheses*
    -Woverloaded-shift-op-parentheses*
    -Wparentheses-equality*
    -Wdangling-else*
```

-Woverloaded-shift-op-parentheses is typically followed by overload
resolution failure. We can instead improve the error message, and
probably delete -Woverloaded-shift-op-parentheses in the future. Keep it
for now because it gives some diagnostics.

Reviewers: akyrtzi, jyknight, rtrieu, rsmith, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: dexonsmith, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65192

llvm-svn: 367690
2019-08-02 16:31:38 +00:00

59 lines
2.2 KiB
C

// RUN: %clang_cc1 -fsyntax-only -verify %s -DSILENCE
// RUN: %clang_cc1 -fsyntax-only -verify %s -Wbitwise-op-parentheses
// RUN: %clang_cc1 -fsyntax-only -verify %s -Wparentheses
// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s -Wbitwise-op-parentheses 2>&1 | FileCheck %s
#ifdef SILENCE
// expected-no-diagnostics
#endif
void bitwise_op_parentheses(unsigned i) {
(void)(i & i | i);
#ifndef SILENCE
// expected-warning@-2 {{'&' within '|'}}
// expected-note@-3 {{place parentheses around the '&' expression to silence this warning}}
#endif
// CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:10-[[@LINE-5]]:10}:"("
// CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:15-[[@LINE-6]]:15}:")"
(void)(i | i & i);
#ifndef SILENCE
// expected-warning@-2 {{'&' within '|'}}
// expected-note@-3 {{place parentheses around the '&' expression to silence this warning}}
#endif
// CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:14-[[@LINE-5]]:14}:"("
// CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:19-[[@LINE-6]]:19}:")"
(void)(i ^ i | i);
#ifndef SILENCE
// expected-warning@-2 {{'^' within '|'}}
// expected-note@-3 {{place parentheses around the '^' expression to silence this warning}}
#endif
// CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:10-[[@LINE-5]]:10}:"("
// CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:15-[[@LINE-6]]:15}:")"
(void)(i | i ^ i);
#ifndef SILENCE
// expected-warning@-2 {{'^' within '|'}}
// expected-note@-3 {{place parentheses around the '^' expression to silence this warning}}
#endif
// CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:14-[[@LINE-5]]:14}:"("
// CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:19-[[@LINE-6]]:19}:")"
(void)(i & i ^ i);
#ifndef SILENCE
// expected-warning@-2 {{'&' within '^'}}
// expected-note@-3 {{place parentheses around the '&' expression to silence this warning}}
#endif
// CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:10-[[@LINE-5]]:10}:"("
// CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:15-[[@LINE-6]]:15}:")"
(void)(i ^ i & i);
#ifndef SILENCE
// expected-warning@-2 {{'&' within '^'}}
// expected-note@-3 {{place parentheses around the '&' expression to silence this warning}}
#endif
// CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:14-[[@LINE-5]]:14}:"("
// CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:19-[[@LINE-6]]:19}:")"
}