David Blaikie | be0ee87 | 2012-05-15 16:56:36 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-constant-conversion %s |
Sebastian Redl | 95389dd | 2009-01-19 21:37:51 +0000 | [diff] [blame] | 2 | |
| 3 | void choice(int); |
| 4 | int choice(bool); |
| 5 | |
| 6 | void test() { |
| 7 | // Result of ! must be type bool. |
| 8 | int i = choice(!1); |
| 9 | } |
Fariborz Jahanian | 957355e | 2010-08-24 22:55:33 +0000 | [diff] [blame] | 10 | |
| 11 | // rdar://8018252 |
| 12 | void f0() { |
| 13 | extern void f0_1(int*); |
| 14 | register int x; |
| 15 | f0_1(&x); |
| 16 | } |
John McCall | 2bf6f49 | 2010-10-12 02:19:57 +0000 | [diff] [blame] | 17 | |
John McCall | f9c5afb | 2010-10-12 03:38:33 +0000 | [diff] [blame] | 18 | namespace test1 { |
| 19 | template <class T> void bar(T &x) { T::fail(); } |
| 20 | template <class T> void bar(volatile T &x) {} |
| 21 | |
| 22 | void test_ints() { |
| 23 | volatile int x; |
| 24 | bar(x = 5); |
| 25 | bar(x += 5); |
| 26 | } |
| 27 | |
| 28 | enum E { E_zero }; |
| 29 | void test_enums() { |
| 30 | volatile E x; |
| 31 | bar(x = E_zero); |
| 32 | bar(x += E_zero); // expected-error {{incompatible type}} |
| 33 | } |
John McCall | 2bf6f49 | 2010-10-12 02:19:57 +0000 | [diff] [blame] | 34 | } |
Chandler Carruth | 0683a14 | 2011-05-31 05:41:42 +0000 | [diff] [blame] | 35 | |
| 36 | int test2(int x) { |
Matt Beaumont-Gay | 9b127f3 | 2011-08-15 17:50:06 +0000 | [diff] [blame] | 37 | return x && 4; // expected-warning {{use of logical '&&' with constant operand}} \ |
| 38 | // expected-note {{use '&' for a bitwise operation}} \ |
| 39 | // expected-note {{remove constant to silence this warning}} |
Chandler Carruth | 0683a14 | 2011-05-31 05:41:42 +0000 | [diff] [blame] | 40 | |
| 41 | return x && sizeof(int) == 4; // no warning, RHS is logical op. |
| 42 | return x && true; |
| 43 | return x && false; |
| 44 | return x || true; |
| 45 | return x || false; |
| 46 | |
Matt Beaumont-Gay | 9b127f3 | 2011-08-15 17:50:06 +0000 | [diff] [blame] | 47 | return x && (unsigned)0; // expected-warning {{use of logical '&&' with constant operand}} \ |
| 48 | // expected-note {{use '&' for a bitwise operation}} \ |
| 49 | // expected-note {{remove constant to silence this warning}} |
Chandler Carruth | 0683a14 | 2011-05-31 05:41:42 +0000 | [diff] [blame] | 50 | |
Matt Beaumont-Gay | 9b127f3 | 2011-08-15 17:50:06 +0000 | [diff] [blame] | 51 | return x || (unsigned)1; // expected-warning {{use of logical '||' with constant operand}} \ |
| 52 | // expected-note {{use '|' for a bitwise operation}} |
Chandler Carruth | 0683a14 | 2011-05-31 05:41:42 +0000 | [diff] [blame] | 53 | |
Matt Beaumont-Gay | 9b127f3 | 2011-08-15 17:50:06 +0000 | [diff] [blame] | 54 | return x || 0; // expected-warning {{use of logical '||' with constant operand}} \ |
| 55 | // expected-note {{use '|' for a bitwise operation}} |
| 56 | return x || 1; // expected-warning {{use of logical '||' with constant operand}} \ |
| 57 | // expected-note {{use '|' for a bitwise operation}} |
| 58 | return x || -1; // expected-warning {{use of logical '||' with constant operand}} \ |
| 59 | // expected-note {{use '|' for a bitwise operation}} |
| 60 | return x || 5; // expected-warning {{use of logical '||' with constant operand}} \ |
| 61 | // expected-note {{use '|' for a bitwise operation}} |
| 62 | return x && 0; // expected-warning {{use of logical '&&' with constant operand}} \ |
| 63 | // expected-note {{use '&' for a bitwise operation}} \ |
| 64 | // expected-note {{remove constant to silence this warning}} |
| 65 | return x && 1; // expected-warning {{use of logical '&&' with constant operand}} \ |
| 66 | // expected-note {{use '&' for a bitwise operation}} \ |
| 67 | // expected-note {{remove constant to silence this warning}} |
| 68 | return x && -1; // expected-warning {{use of logical '&&' with constant operand}} \ |
| 69 | // expected-note {{use '&' for a bitwise operation}} \ |
| 70 | // expected-note {{remove constant to silence this warning}} |
| 71 | return x && 5; // expected-warning {{use of logical '&&' with constant operand}} \ |
| 72 | // expected-note {{use '&' for a bitwise operation}} \ |
| 73 | // expected-note {{remove constant to silence this warning}} |
| 74 | return x || (0); // expected-warning {{use of logical '||' with constant operand}} \ |
| 75 | // expected-note {{use '|' for a bitwise operation}} |
| 76 | return x || (1); // expected-warning {{use of logical '||' with constant operand}} \ |
| 77 | // expected-note {{use '|' for a bitwise operation}} |
| 78 | return x || (-1); // expected-warning {{use of logical '||' with constant operand}} \ |
| 79 | // expected-note {{use '|' for a bitwise operation}} |
| 80 | return x || (5); // expected-warning {{use of logical '||' with constant operand}} \ |
| 81 | // expected-note {{use '|' for a bitwise operation}} |
| 82 | return x && (0); // expected-warning {{use of logical '&&' with constant operand}} \ |
| 83 | // expected-note {{use '&' for a bitwise operation}} \ |
| 84 | // expected-note {{remove constant to silence this warning}} |
| 85 | return x && (1); // expected-warning {{use of logical '&&' with constant operand}} \ |
| 86 | // expected-note {{use '&' for a bitwise operation}} \ |
| 87 | // expected-note {{remove constant to silence this warning}} |
| 88 | return x && (-1); // expected-warning {{use of logical '&&' with constant operand}} \ |
| 89 | // expected-note {{use '&' for a bitwise operation}} \ |
| 90 | // expected-note {{remove constant to silence this warning}} |
| 91 | return x && (5); // expected-warning {{use of logical '&&' with constant operand}} \ |
| 92 | // expected-note {{use '&' for a bitwise operation}} \ |
| 93 | // expected-note {{remove constant to silence this warning}} |
Chandler Carruth | 0683a14 | 2011-05-31 05:41:42 +0000 | [diff] [blame] | 94 | } |
Richard Trieu | e5adf59 | 2011-07-15 00:00:51 +0000 | [diff] [blame] | 95 | |
| 96 | template<unsigned int A, unsigned int B> struct S |
| 97 | { |
| 98 | enum { |
| 99 | e1 = A && B, |
Matt Beaumont-Gay | 9b127f3 | 2011-08-15 17:50:06 +0000 | [diff] [blame] | 100 | e2 = A && 7 // expected-warning {{use of logical '&&' with constant operand}} \ |
| 101 | // expected-note {{use '&' for a bitwise operation}} \ |
| 102 | // expected-note {{remove constant to silence this warning}} |
Richard Trieu | e5adf59 | 2011-07-15 00:00:51 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | int foo() { |
| 106 | int x = A && B; |
Matt Beaumont-Gay | 9b127f3 | 2011-08-15 17:50:06 +0000 | [diff] [blame] | 107 | int y = B && 3; // expected-warning {{use of logical '&&' with constant operand}} \ |
| 108 | // expected-note {{use '&' for a bitwise operation}} \ |
| 109 | // expected-note {{remove constant to silence this warning}} |
Richard Trieu | e5adf59 | 2011-07-15 00:00:51 +0000 | [diff] [blame] | 110 | |
| 111 | return x + y; |
| 112 | } |
| 113 | }; |
| 114 | |
| 115 | void test3() { |
| 116 | S<5, 8> s1; |
| 117 | S<2, 7> s2; |
| 118 | (void)s1.foo(); |
| 119 | (void)s2.foo(); |
| 120 | } |