2011-06-04 02:00:36 +08:00
|
|
|
// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
|
2013-04-18 08:56:23 +08:00
|
|
|
// RUN: %clang_cc1 -Wparentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
|
2011-06-04 02:00:36 +08:00
|
|
|
|
|
|
|
bool someConditionFunc();
|
|
|
|
|
|
|
|
void conditional_op(int x, int y, bool b) {
|
2011-06-16 09:05:12 +08:00
|
|
|
(void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} \
|
2013-04-18 08:56:23 +08:00
|
|
|
// 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}:")"
|
2011-06-04 02:00:36 +08:00
|
|
|
|
2011-06-16 09:05:12 +08:00
|
|
|
(void)(x - b ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '-'}} \
|
2013-04-18 08:56:23 +08:00
|
|
|
// 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}:")"
|
2011-06-04 02:00:36 +08:00
|
|
|
|
2011-06-16 09:05:12 +08:00
|
|
|
(void)(x * (x == y) ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '*'}} \
|
2013-04-18 08:56:23 +08:00
|
|
|
// 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}:")"
|
2011-06-04 02:00:36 +08:00
|
|
|
}
|
2011-06-10 01:06:51 +08:00
|
|
|
|
|
|
|
class Stream {
|
|
|
|
public:
|
|
|
|
operator int();
|
|
|
|
Stream &operator<<(int);
|
|
|
|
Stream &operator<<(const char*);
|
2012-10-05 08:41:03 +08:00
|
|
|
Stream &operator>>(int);
|
|
|
|
Stream &operator>>(const char*);
|
2011-06-10 01:06:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void f(Stream& s, bool b) {
|
2011-06-16 09:05:12 +08:00
|
|
|
(void)(s << b ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '<<'}} \
|
2013-04-18 08:56:23 +08:00
|
|
|
// 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}:")"
|
|
|
|
|
2013-04-17 10:12:45 +08:00
|
|
|
(void)(s << 5 == 1); // expected-warning {{overloaded operator << has lower precedence than comparison operator}} \
|
2013-04-18 09:04:37 +08:00
|
|
|
// expected-note {{place parentheses around the '<<' expression to silence this warning}} \
|
|
|
|
// expected-note {{place parentheses around comparison 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]]:21-[[@LINE-6]]:21}:")"
|
2013-04-18 08:56:23 +08:00
|
|
|
|
2013-04-17 10:12:45 +08:00
|
|
|
(void)(s >> 5 == 1); // expected-warning {{overloaded operator >> has lower precedence than comparison operator}} \
|
2013-04-18 09:04:37 +08:00
|
|
|
// expected-note {{place parentheses around the '>>' expression to silence this warning}} \
|
|
|
|
// expected-note {{place parentheses around comparison 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]]:21-[[@LINE-6]]:21}:")"
|
2011-06-10 01:06:51 +08:00
|
|
|
}
|
2011-06-22 01:22:09 +08:00
|
|
|
|
|
|
|
struct S {
|
|
|
|
operator int() { return 42; }
|
|
|
|
friend S operator+(const S &lhs, bool) { return S(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
void test(S *s, bool (S::*m_ptr)()) {
|
|
|
|
(void)(*s + true ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '+'}} \
|
2013-04-18 08:56:23 +08:00
|
|
|
// 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}:")"
|
2011-06-22 01:22:09 +08:00
|
|
|
|
2011-09-12 20:07:30 +08:00
|
|
|
(void)((*s + true) ? "foo" : "bar"); // No warning.
|
|
|
|
|
2011-06-22 01:22:09 +08:00
|
|
|
// Don't crash on unusual member call expressions.
|
|
|
|
(void)((s->*m_ptr)() ? "foo" : "bar");
|
|
|
|
}
|
2012-10-05 08:41:03 +08:00
|
|
|
|
|
|
|
void test(int a, int b, int c) {
|
2012-10-20 02:26:06 +08:00
|
|
|
(void)(a >> b + c); // expected-warning {{operator '>>' has lower precedence than '+'; '+' will be evaluated first}} \
|
2012-10-05 08:41:03 +08:00
|
|
|
expected-note {{place parentheses around the '+' expression to silence this warning}}
|
2013-04-18 08:56:23 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:15-[[@LINE-2]]:15}:"("
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:20-[[@LINE-3]]:20}:")"
|
|
|
|
|
2012-10-20 02:26:06 +08:00
|
|
|
(void)(a - b << c); // expected-warning {{operator '<<' has lower precedence than '-'; '-' will be evaluated first}} \
|
2012-10-05 08:41:03 +08:00
|
|
|
expected-note {{place parentheses around the '-' expression to silence this warning}}
|
2013-04-18 08:56:23 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:10-[[@LINE-2]]:10}:"("
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:15-[[@LINE-3]]:15}:")"
|
|
|
|
|
2012-10-05 08:41:03 +08:00
|
|
|
Stream() << b + c;
|
2012-10-20 02:26:06 +08:00
|
|
|
Stream() >> b + c; // expected-warning {{operator '>>' has lower precedence than '+'; '+' will be evaluated first}} \
|
2012-10-05 08:41:03 +08:00
|
|
|
expected-note {{place parentheses around the '+' expression to silence this warning}}
|
2013-04-18 08:56:23 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:15-[[@LINE-2]]:15}:"("
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:20-[[@LINE-3]]:20}:")"
|
2012-10-05 08:41:03 +08:00
|
|
|
}
|
2013-03-30 19:56:00 +08:00
|
|
|
|
|
|
|
namespace PR15628 {
|
|
|
|
struct BlockInputIter {
|
|
|
|
void* operator++(int);
|
|
|
|
void* operator--(int);
|
|
|
|
};
|
|
|
|
|
|
|
|
void test(BlockInputIter i) {
|
|
|
|
(void)(i++ ? true : false); // no-warning
|
|
|
|
(void)(i-- ? true : false); // no-warning
|
|
|
|
}
|
|
|
|
}
|