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