summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td4
-rw-r--r--clang/test/Sema/bitwise-op-parentheses.c58
-rw-r--r--clang/test/Sema/logical-op-parentheses.c41
-rw-r--r--clang/test/Sema/parentheses.c53
-rw-r--r--clang/test/SemaCXX/parentheses.cpp2
5 files changed, 103 insertions, 55 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 2704a56e430..cf036b57608 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5642,10 +5642,10 @@ def note_logical_instead_of_bitwise_remove_constant : Note<
"remove constant to silence this warning">;
def warn_bitwise_op_in_bitwise_op : Warning<
- "'%0' within '%1'">, InGroup<BitwiseOpParentheses>;
+ "'%0' within '%1'">, InGroup<BitwiseOpParentheses>, DefaultIgnore;
def warn_logical_and_in_logical_or : Warning<
- "'&&' within '||'">, InGroup<LogicalOpParentheses>;
+ "'&&' within '||'">, InGroup<LogicalOpParentheses>, DefaultIgnore;
def warn_overloaded_shift_in_comparison :Warning<
"overloaded operator %select{>>|<<}0 has higher precedence than "
diff --git a/clang/test/Sema/bitwise-op-parentheses.c b/clang/test/Sema/bitwise-op-parentheses.c
new file mode 100644
index 00000000000..ed270de8424
--- /dev/null
+++ b/clang/test/Sema/bitwise-op-parentheses.c
@@ -0,0 +1,58 @@
+// 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}:")"
+}
diff --git a/clang/test/Sema/logical-op-parentheses.c b/clang/test/Sema/logical-op-parentheses.c
new file mode 100644
index 00000000000..84464b40095
--- /dev/null
+++ b/clang/test/Sema/logical-op-parentheses.c
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -DSILENCE
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wlogical-op-parentheses
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wparentheses
+// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s -Wlogical-op-parentheses 2>&1 | FileCheck %s
+
+#ifdef SILENCE
+// expected-no-diagnostics
+#endif
+
+void logical_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]]:14-[[@LINE-5]]:14}:"("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:20-[[@LINE-6]]:20}:")"
+
+ (void)(i || i && "w00t");
+ (void)("w00t" && i || i);
+
+ (void)(i || i && "w00t" || 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]]:15-[[@LINE-5]]:15}:"("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:26-[[@LINE-6]]:26}:")"
+
+ (void)(i || "w00t" && 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]]:15-[[@LINE-5]]:15}:"("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:26-[[@LINE-6]]:26}:")"
+
+ (void)(i && i || 0);
+ (void)(0 || i && i);
+}
diff --git a/clang/test/Sema/parentheses.c b/clang/test/Sema/parentheses.c
index 8c6c4999f73..0dabc11d391 100644
--- a/clang/test/Sema/parentheses.c
+++ b/clang/test/Sema/parentheses.c
@@ -1,3 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
// RUN: %clang_cc1 -Wparentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
@@ -44,58 +45,6 @@ void bitwise_rel(unsigned i) {
// Eager logical op
(void)(i == 1 | i == 2 | i == 3);
(void)(i != 1 & i != 2 & i != 3);
-
- (void)(i & i | i); // expected-warning {{'&' within '|'}} \
- // expected-note {{place parentheses around the '&' expression to silence this warning}}
- // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:10-[[@LINE-2]]:10}:"("
- // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:15-[[@LINE-3]]:15}:")"
-
- (void)(i | i & i); // expected-warning {{'&' within '|'}} \
- // expected-note {{place parentheses around the '&' expression to silence this warning}}
- // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:14-[[@LINE-2]]:14}:"("
- // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:19-[[@LINE-3]]:19}:")"
-
- (void)(i ^ i | i); // expected-warning {{'^' within '|'}} \
- // expected-note {{place parentheses around the '^' expression to silence this warning}}
- // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:10-[[@LINE-2]]:10}:"("
- // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:15-[[@LINE-3]]:15}:")"
-
- (void)(i | i ^ i); // expected-warning {{'^' within '|'}} \
- // expected-note {{place parentheses around the '^' expression to silence this warning}}
- // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:14-[[@LINE-2]]:14}:"("
- // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:19-[[@LINE-3]]:19}:")"
-
- (void)(i & i ^ i); // expected-warning {{'&' within '^'}} \
- // expected-note {{place parentheses around the '&' expression to silence this warning}}
- // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:10-[[@LINE-2]]:10}:"("
- // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:15-[[@LINE-3]]:15}:")"
-
- (void)(i ^ i & i); // expected-warning {{'&' within '^'}} \
- // expected-note {{place parentheses around the '&' expression to silence this warning}}
- // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:14-[[@LINE-2]]:14}:"("
- // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:19-[[@LINE-3]]:19}:")"
-
- (void)(i ||
- i && i); // expected-warning {{'&&' within '||'}} \
- // expected-note {{place parentheses around the '&&' expression to silence this warning}}
- // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:14-[[@LINE-2]]:14}:"("
- // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:20-[[@LINE-3]]:20}:")"
-
- (void)(i || i && "w00t"); // no warning.
- (void)("w00t" && i || i); // no warning.
-
- (void)(i || i && "w00t" || i); // expected-warning {{'&&' within '||'}} \
- // expected-note {{place parentheses around the '&&' expression to silence this warning}}
- // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:15-[[@LINE-2]]:15}:"("
- // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:26-[[@LINE-3]]:26}:")"
-
- (void)(i || "w00t" && i || i); // expected-warning {{'&&' within '||'}} \
- // expected-note {{place parentheses around the '&&' expression to silence this warning}}
- // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:15-[[@LINE-2]]:15}:"("
- // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:26-[[@LINE-3]]:26}:")"
-
- (void)(i && i || 0); // no warning.
- (void)(0 || i && i); // no warning.
}
_Bool someConditionFunc();
diff --git a/clang/test/SemaCXX/parentheses.cpp b/clang/test/SemaCXX/parentheses.cpp
index b430b25e5d6..d466bd01389 100644
--- a/clang/test/SemaCXX/parentheses.cpp
+++ b/clang/test/SemaCXX/parentheses.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -verify -Wlogical-op-parentheses %s
// PR16930, PR16727:
template<class Foo>
OpenPOWER on IntegriCloud