Skip to content

Commit 70105ea

Browse files
a-tarasyukfrederik-h
authored andcommitted
[Clang] add additional tests for -Wshift-bool (llvm#130339)
Fixes llvm#127336 (review)
1 parent 200214a commit 70105ea

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

clang/test/Sema/shift-bool.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}

clang/test/Sema/shift-bool.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
void t() {
44
int x = 10;
55
bool y = true;
6+
int z = 1;
67

78
bool a = y << x;
89
bool b = y >> x; // expected-warning {{right shifting a 'bool' implicitly converts it to 'int'}}
@@ -20,6 +21,8 @@ void t() {
2021
bool i = y << 0;
2122
bool j = y >> 0; // expected-warning {{right shifting a 'bool' implicitly converts it to 'int'}}
2223

24+
bool k = (x < z) >> 1; // expected-warning {{right shifting a 'bool' implicitly converts it to 'int'}}
25+
2326
if ((y << 1) != 0) { }
2427
if ((y >> 1) != 0) { } // expected-warning {{right shifting a 'bool' implicitly converts it to 'int'}}
2528
}

0 commit comments

Comments
 (0)