aboutsummaryrefslogtreecommitdiff
path: root/test/Sema/parentheses.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/Sema/parentheses.cpp')
-rw-r--r--test/Sema/parentheses.cpp63
1 files changed, 49 insertions, 14 deletions
diff --git a/test/Sema/parentheses.cpp b/test/Sema/parentheses.cpp
index 58edc0ba29..7288f8cb2f 100644
--- a/test/Sema/parentheses.cpp
+++ b/test/Sema/parentheses.cpp
@@ -1,19 +1,32 @@
// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wparentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
bool someConditionFunc();
void conditional_op(int x, int y, bool b) {
(void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} \
- // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
- // expected-note {{place parentheses around the '+' expression to silence this warning}}
+ // expected-note {{place parentheses around the '+' expression to silence this warning}} \
+ // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:10}:"("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:33-[[@LINE-4]]:33}:")"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:14-[[@LINE-5]]:14}:"("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:41-[[@LINE-6]]:41}:")"
(void)(x - b ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '-'}} \
- // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
- // expected-note {{place parentheses around the '-' expression to silence this warning}}
+ // expected-note {{place parentheses around the '-' expression to silence this warning}} \
+ // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:10}:"("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:15-[[@LINE-4]]:15}:")"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:14-[[@LINE-5]]:14}:"("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:23-[[@LINE-6]]:23}:")"
(void)(x * (x == y) ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '*'}} \
- // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
- // expected-note {{place parentheses around the '*' expression to silence this warning}}
+ // expected-note {{place parentheses around the '*' expression to silence this warning}} \
+ // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:10}:"("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:22-[[@LINE-4]]:22}:")"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:14-[[@LINE-5]]:14}:"("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:30-[[@LINE-6]]:30}:")"
}
class Stream {
@@ -27,14 +40,24 @@ public:
void f(Stream& s, bool b) {
(void)(s << b ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '<<'}} \
- // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
- // expected-note {{place parentheses around the '<<' expression to silence this warning}}
+ // expected-note {{place parentheses around the '<<' expression to silence this warning}} \
+ // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:10}:"("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:16-[[@LINE-4]]:16}:")"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:15-[[@LINE-5]]:15}:"("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:32-[[@LINE-6]]:32}:")"
+
(void)(s << 5 == 1); // expected-warning {{overloaded operator << has lower precedence than comparison operator}} \
- // expected-note {{place parentheses around the '<<' expression to silence this warning}} \
- // expected-note {{place parentheses around comparison expression to evaluate it first}}
+ // expected-note {{place parentheses around comparison expression to evaluate it first}} \
+ // expected-note {{place parentheses around the '<<' expression to silence this warning}}
+
(void)(s >> 5 == 1); // expected-warning {{overloaded operator >> has lower precedence than comparison operator}} \
- // expected-note {{place parentheses around the '>>' expression to silence this warning}} \
- // expected-note {{place parentheses around comparison expression to evaluate it first}}
+ // expected-note {{place parentheses around comparison expression to evaluate it first}} \
+ // expected-note {{place parentheses around the '>>' expression to silence this warning}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:15-[[@LINE-3]]:15}:"("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:21-[[@LINE-4]]:21}:")"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:10-[[@LINE-5]]:10}:"("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:16-[[@LINE-6]]:16}:")"
}
struct S {
@@ -44,8 +67,12 @@ struct S {
void test(S *s, bool (S::*m_ptr)()) {
(void)(*s + true ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '+'}} \
- // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
- // expected-note {{place parentheses around the '+' expression to silence this warning}}
+ // expected-note {{place parentheses around the '+' expression to silence this warning}} \
+ // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:10}:"("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:19-[[@LINE-4]]:19}:")"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:15-[[@LINE-5]]:15}:"("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:35-[[@LINE-6]]:35}:")"
(void)((*s + true) ? "foo" : "bar"); // No warning.
@@ -56,11 +83,19 @@ void test(S *s, bool (S::*m_ptr)()) {
void test(int a, int b, int c) {
(void)(a >> b + c); // expected-warning {{operator '>>' has lower precedence than '+'; '+' will be evaluated first}} \
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]]:20-[[@LINE-3]]:20}:")"
+
(void)(a - b << c); // expected-warning {{operator '<<' has lower precedence than '-'; '-' will be evaluated first}} \
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}:")"
+
Stream() << b + c;
Stream() >> b + c; // expected-warning {{operator '>>' has lower precedence than '+'; '+' will be evaluated first}} \
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]]:20-[[@LINE-3]]:20}:")"
}
namespace PR15628 {