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