blob: 95ece48e51feb2dd15115b649440a0417dd276f9 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Sebastian Redl95389dd2009-01-19 21:37:51 +00002
3void choice(int);
4int choice(bool);
5
6void test() {
7 // Result of ! must be type bool.
8 int i = choice(!1);
9}
Fariborz Jahanian957355e2010-08-24 22:55:33 +000010
11// rdar://8018252
12void f0() {
13 extern void f0_1(int*);
14 register int x;
15 f0_1(&x);
16}
John McCall2bf6f492010-10-12 02:19:57 +000017
John McCallf9c5afb2010-10-12 03:38:33 +000018namespace 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 McCall2bf6f492010-10-12 02:19:57 +000034}
Chandler Carruth0683a142011-05-31 05:41:42 +000035
36int test2(int x) {
37 return x && 4; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
38
39 return x && sizeof(int) == 4; // no warning, RHS is logical op.
40 return x && true;
41 return x && false;
42 return x || true;
43 return x || false;
44
45 return x && (unsigned)0; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
46
47 return x || (unsigned)1; // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
48
49 return x || 0; // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
50 return x || 1; // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
51 return x || -1; // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
52 return x || 5; // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
53 return x && 0; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
54 return x && 1; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
55 return x && -1; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
56 return x && 5; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
57 return x || (0); // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
58 return x || (1); // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
59 return x || (-1); // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
60 return x || (5); // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
61 return x && (0); // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
62 return x && (1); // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
63 return x && (-1); // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
64 return x && (5); // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
65}