[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / SemaCXX / warn-bitwise-compare.cpp
blob28b926ec1f0c622f97446ff7b4b195d7c09bc637
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wtautological-bitwise-compare %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -Wall -Wno-unused %s
4 void test(int x) {
5 bool b1 = (8 & x) == 3;
6 // expected-warning@-1 {{bitwise comparison always evaluates to false}}
7 bool b2 = x | 5;
8 // expected-warning@-1 {{bitwise or with non-zero value always evaluates to true}}
9 bool b3 = (x | 5);
10 // expected-warning@-1 {{bitwise or with non-zero value always evaluates to true}}
11 bool b4 = !!(x | 5);
12 // expected-warning@-1 {{bitwise or with non-zero value always evaluates to true}}
15 template <int I, class T> // silence
16 void foo(int x) {
17 bool b1 = (x & sizeof(T)) == 8;
18 bool b2 = (x & I) == 8;
19 bool b3 = (x & 4) == 8; // expected-warning {{bitwise comparison always evaluates to false}}
22 void run(int x) {
23 foo<4, int>(8); // expected-note {{in instantiation of function template specialization 'foo<4, int>' requested here}}