summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Sema/parentheses.c12
-rw-r--r--clang/test/SemaCXX/warn-assignment-condition.cpp48
2 files changed, 40 insertions, 20 deletions
diff --git a/clang/test/Sema/parentheses.c b/clang/test/Sema/parentheses.c
index f7a7fbd37db..69c91cb15f4 100644
--- a/clang/test/Sema/parentheses.c
+++ b/clang/test/Sema/parentheses.c
@@ -4,14 +4,18 @@
// Test the various warnings under -Wparentheses
void if_assign(void) {
int i;
- if (i = 4) {} // expected-warning {{assignment as a condition}}
+ if (i = 4) {} // expected-warning {{assignment as a condition}} \
+ // expected-note{{use '==' to turn this assignment into an equality comparison}}
if ((i = 4)) {}
}
void bitwise_rel(unsigned i) {
- (void)(i & 0x2 == 0); // expected-warning {{& has lower precedence than ==}}
- (void)(0 == i & 0x2); // expected-warning {{& has lower precedence than ==}}
- (void)(i & 0xff < 30); // expected-warning {{& has lower precedence than <}}
+ (void)(i & 0x2 == 0); // expected-warning {{& has lower precedence than ==}} \
+ // expected-note{{place parentheses around the & expression to evaluate it first}}
+ (void)(0 == i & 0x2); // expected-warning {{& has lower precedence than ==}} \
+ // expected-note{{place parentheses around the & expression to evaluate it first}}
+ (void)(i & 0xff < 30); // expected-warning {{& has lower precedence than <}} \
+ // expected-note{{place parentheses around the & expression to evaluate it first}}
(void)((i & 0x2) == 0);
(void)(i & (0x2 == 0));
// Eager logical op
diff --git a/clang/test/SemaCXX/warn-assignment-condition.cpp b/clang/test/SemaCXX/warn-assignment-condition.cpp
index 1df906dd7ec..ce16a68a77e 100644
--- a/clang/test/SemaCXX/warn-assignment-condition.cpp
+++ b/clang/test/SemaCXX/warn-assignment-condition.cpp
@@ -11,26 +11,34 @@ void test() {
A a, b;
// With scalars.
- if (x = 7) {} // expected-warning {{using the result of an assignment as a condition without parentheses}}
+ if (x = 7) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \
+ // expected-note{{use '==' to turn this assignment into an equality comparison}}
if ((x = 7)) {}
do {
- } while (x = 7); // expected-warning {{using the result of an assignment as a condition without parentheses}}
+ } while (x = 7); // expected-warning {{using the result of an assignment as a condition without parentheses}} \
+ // expected-note{{use '==' to turn this assignment into an equality comparison}}
do {
} while ((x = 7));
- while (x = 7) {} // expected-warning {{using the result of an assignment as a condition without parentheses}}
+ while (x = 7) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \
+ // expected-note{{use '==' to turn this assignment into an equality comparison}}
while ((x = 7)) {}
- for (; x = 7; ) {} // expected-warning {{using the result of an assignment as a condition without parentheses}}
+ for (; x = 7; ) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \
+ // expected-note{{use '==' to turn this assignment into an equality comparison}}
for (; (x = 7); ) {}
- if (p = p) {} // expected-warning {{using the result of an assignment as a condition without parentheses}}
+ if (p = p) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \
+ // expected-note{{use '==' to turn this assignment into an equality comparison}}
if ((p = p)) {}
do {
- } while (p = p); // expected-warning {{using the result of an assignment as a condition without parentheses}}
+ } while (p = p); // expected-warning {{using the result of an assignment as a condition without parentheses}} \
+ // expected-note{{use '==' to turn this assignment into an equality comparison}}
do {
} while ((p = p));
- while (p = p) {} // expected-warning {{using the result of an assignment as a condition without parentheses}}
+ while (p = p) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \
+ // expected-note{{use '==' to turn this assignment into an equality comparison}}
while ((p = p)) {}
- for (; p = p; ) {} // expected-warning {{using the result of an assignment as a condition without parentheses}}
+ for (; p = p; ) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \
+ // expected-note{{use '==' to turn this assignment into an equality comparison}}
for (; (p = p); ) {}
// Initializing variables (shouldn't warn).
@@ -40,26 +48,34 @@ void test() {
while (A y = a) {}
// With temporaries.
- if (x = (b+b).foo()) {} // expected-warning {{using the result of an assignment as a condition without parentheses}}
+ if (x = (b+b).foo()) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \
+ // expected-note{{use '==' to turn this assignment into an equality comparison}}
if ((x = (b+b).foo())) {}
do {
- } while (x = (b+b).foo()); // expected-warning {{using the result of an assignment as a condition without parentheses}}
+ } while (x = (b+b).foo()); // expected-warning {{using the result of an assignment as a condition without parentheses}} \
+ // expected-note{{use '==' to turn this assignment into an equality comparison}}
do {
} while ((x = (b+b).foo()));
- while (x = (b+b).foo()) {} // expected-warning {{using the result of an assignment as a condition without parentheses}}
+ while (x = (b+b).foo()) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \
+ // expected-note{{use '==' to turn this assignment into an equality comparison}}
while ((x = (b+b).foo())) {}
- for (; x = (b+b).foo(); ) {} // expected-warning {{using the result of an assignment as a condition without parentheses}}
+ for (; x = (b+b).foo(); ) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \
+ // expected-note{{use '==' to turn this assignment into an equality comparison}}
for (; (x = (b+b).foo()); ) {}
// With a user-defined operator.
- if (a = b + b) {} // expected-warning {{using the result of an assignment as a condition without parentheses}}
+ if (a = b + b) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \
+ // expected-note{{use '==' to turn this assignment into an equality comparison}}
if ((a = b + b)) {}
do {
- } while (a = b + b); // expected-warning {{using the result of an assignment as a condition without parentheses}}
+ } while (a = b + b); // expected-warning {{using the result of an assignment as a condition without parentheses}} \
+ // expected-note{{use '==' to turn this assignment into an equality comparison}}
do {
} while ((a = b + b));
- while (a = b + b) {} // expected-warning {{using the result of an assignment as a condition without parentheses}}
+ while (a = b + b) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \
+ // expected-note{{use '==' to turn this assignment into an equality comparison}}
while ((a = b + b)) {}
- for (; a = b + b; ) {} // expected-warning {{using the result of an assignment as a condition without parentheses}}
+ for (; a = b + b; ) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \
+ // expected-note{{use '==' to turn this assignment into an equality comparison}}
for (; (a = b + b); ) {}
}
OpenPOWER on IntegriCloud