blob: a25f2a0ce7b876dceeabe261d216760554beaa58 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
// 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) {
(void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{?: 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}}
(void)(x - b ? 1 : 2); // expected-warning {{?: 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}}
(void)(x * (x == y) ? 1 : 2); // expected-warning {{?: 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}}
}
class Stream {
public:
operator int();
Stream &operator<<(int);
Stream &operator<<(const char*);
};
void f(Stream& s, bool b) {
(void)(s << b ? "foo" : "bar"); // expected-warning {{?: 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}}
}
|