File tree 2 files changed +30
-0
lines changed 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ // RUN: %clang_cc1 -fsyntax-only -Wshift-bool -verify %s
2
+
3
+ void t () {
4
+ int x = 10 ;
5
+ int y = 5 ;
6
+
7
+ int a = (x < y ) << 1 ;
8
+ int b = (x < y ) >> 1 ;
9
+
10
+ int c = (x > y ) << 1 ;
11
+ int d = (x > y ) >> 1 ;
12
+
13
+ int e = (x == y ) << 1 ;
14
+ int f = (x == y ) >> 1 ;
15
+
16
+ int g = (x != y ) << 1 ;
17
+ int h = (x != y ) >> 1 ;
18
+
19
+ int i = (x < y ) << 0 ;
20
+ int j = (x < y ) >> 0 ;
21
+
22
+ int k = (x < y ) << -1 ; // expected-warning {{shift count is negative}}
23
+ int l = (x < y ) >> -1 ; // expected-warning {{shift count is negative}}
24
+
25
+ if (((x < y ) << 1 ) != 0 ) { }
26
+ if (((x < y ) >> 1 ) != 0 ) { }
27
+ }
Original file line number Diff line number Diff line change 3
3
void t () {
4
4
int x = 10 ;
5
5
bool y = true ;
6
+ int z = 1 ;
6
7
7
8
bool a = y << x;
8
9
bool b = y >> x; // expected-warning {{right shifting a 'bool' implicitly converts it to 'int'}}
@@ -20,6 +21,8 @@ void t() {
20
21
bool i = y << 0 ;
21
22
bool j = y >> 0 ; // expected-warning {{right shifting a 'bool' implicitly converts it to 'int'}}
22
23
24
+ bool k = (x < z) >> 1 ; // expected-warning {{right shifting a 'bool' implicitly converts it to 'int'}}
25
+
23
26
if ((y << 1 ) != 0 ) { }
24
27
if ((y >> 1 ) != 0 ) { } // expected-warning {{right shifting a 'bool' implicitly converts it to 'int'}}
25
28
}
You can’t perform that action at this time.
0 commit comments