2011-06-04 02:00:36 +08:00
|
|
|
// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
|
|
|
|
// RUN: %clang_cc1 -Wparentheses -fixit %s -o - | %clang_cc1 -Wparentheses -Werror -
|
|
|
|
|
|
|
|
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 '+'}} \
|
|
|
|
// expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
|
|
|
|
// expected-note {{place parentheses around the '+' expression to silence this warning}}
|
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 '-'}} \
|
|
|
|
// expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
|
|
|
|
// expected-note {{place parentheses around the '-' expression to silence this warning}}
|
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 '*'}} \
|
|
|
|
// expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
|
|
|
|
// expected-note {{place parentheses around the '*' expression to silence this warning}}
|
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*);
|
|
|
|
};
|
|
|
|
|
|
|
|
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 '<<'}} \
|
|
|
|
// expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
|
|
|
|
// expected-note {{place parentheses around the '<<' expression to silence this warning}}
|
2011-06-10 01:06:51 +08:00
|
|
|
}
|