brintos

brintos / llvm-project-archived public Read only

0
0
Text · 10.6 KiB · 1d856f2 Raw
207 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s2 3 4void f(int x, int y, int z) {5 6  bool a,b;7 8  if(b > true)    {} // expected-warning {{comparison of true with expression of type 'bool' is always false}}9  if(b < true)    {} // no warning10  if(b >= true)   {} // no warning11  if(b <= true)   {} // expected-warning {{comparison of true with expression of type 'bool' is always true}}12  if(b == true)   {} // no warning13  if(b != true)   {} // no warning14 15  if(b > false)   {} // no warning16  if(b < false)   {} // expected-warning {{comparison of false with expression of type 'bool' is always false}}17  if(b >= false)  {} // expected-warning {{comparison of false with expression of type 'bool' is always true}}18  if(b <= false)  {} // no warning19  if(b == false)  {} // no warning20  if(b != false)  {} // no warning21 22  if(b > 1U){} // expected-warning {{comparison of constant 1 with expression of type 'bool' is always false}}23 24  if (a > b)      {} // no warning25  if (a < b)      {} // no warning26  if (a >= b)     {} // no warning27  if (a <= b)     {} // no warning28  if (a == b)     {} // no warning29  if (a != b)     {} // no warning30 31  if (a > 0) {} // no warning32  if (a > 1) {} // expected-warning {{comparison of constant 1 with expression of type 'bool' is always false}}33  if (a > 2) {} // expected-warning {{comparison of constant 2 with expression of type 'bool' is always false}}34 35  if (a >= 0) {} // expected-warning {{comparison of constant 0 with expression of type 'bool' is always true}}36  if (a >= 1) {} // no warning37  if (a >= 2) {} // expected-warning {{comparison of constant 2 with expression of type 'bool' is always false}}38  if (a >= -1) {} // expected-warning {{comparison of constant -1 with expression of type 'bool' is always true}}39 40  if (a <= 0) {} // no warning41  if (a <= 1) {} // expected-warning {{comparison of constant 1 with expression of type 'bool' is always true}}42  if (a <= 2) {} // expected-warning {{comparison of constant 2 with expression of type 'bool' is always true}}43  if (a <= -1) {} // expected-warning {{comparison of constant -1 with expression of type 'bool' is always false}}44 45  if (!a > 0)     {} // no warning46  if (!a > 1)     {} // expected-warning {{comparison of constant 1 with expression of type 'bool' is always false}}47  if (!a > 2)     {} // expected-warning {{comparison of constant 2 with expression of type 'bool' is always false}}48  if (!a > y)     {} // no warning49  if (!a > b)     {} // no warning50  if (!a > -1)    {} // expected-warning {{comparison of constant -1 with expression of type 'bool' is always true}}51 52  if (!a < 0)     {} // expected-warning {{comparison of constant 0 with expression of type 'bool' is always false}}53  if (!a < 1)     {} // no warning54  if (!a < 2)     {} // expected-warning {{comparison of constant 2 with expression of type 'bool' is always true}}55  if (!a < y)     {} // no warning56  if (!a < b)     {} // no warning57  if (!a < -1)    {} // expected-warning {{comparison of constant -1 with expression of type 'bool' is always false}}58 59  if (!a >= 0)    {} // expected-warning {{comparison of constant 0 with expression of type 'bool' is always true}}60  if (!a >= 1)    {} // no warning61  if (!a >= 2)    {} // expected-warning {{comparison of constant 2 with expression of type 'bool' is always false}}62  if (!a >= y)    {} // no warning63  if (!a >= b)    {} // no warning64  if (!a >= -1)   {} // expected-warning {{comparison of constant -1 with expression of type 'bool' is always true}}65 66  if (!a <= 0)    {} // no warning67  if (!a <= 1)    {} // expected-warning {{comparison of constant 1 with expression of type 'bool' is always true}}68  if (!a <= 2)    {} // expected-warning {{comparison of constant 2 with expression of type 'bool' is always true}}69  if (!a <= y)    {} // no warning70  if (!a <= b)    {} // no warning71  if (!a <= -1)   {} // expected-warning {{comparison of constant -1 with expression of type 'bool' is always false}}72 73  if ((a||b) > 0) {} // no warning74  if ((a||b) > 1) {} // expected-warning {{comparison of constant 1 with expression of type 'bool' is always false}}75  if ((a||b) > 4) {} // expected-warning {{comparison of constant 4 with expression of type 'bool' is always false}}76  if ((a||b) > -1) {}// expected-warning {{comparison of constant -1 with expression of type 'bool' is always true}}77 78  if ((a&&b) > 0) {} // no warning79  if ((a&&b) > 1) {} // expected-warning {{comparison of constant 1 with expression of type 'bool' is always false}}80  if ((a&&b) > 4) {} // expected-warning {{comparison of constant 4 with expression of type 'bool' is always false}}81 82  if ((a<y) > 0)  {} // no warning83  if ((a<y) > 1)  {} // expected-warning {{comparison of constant 1 with expression of type 'bool' is always false}}84  if ((a<y) > 4)  {} // expected-warning {{comparison of constant 4 with expression of type 'bool' is always false}}85  if ((a<y) > z)  {} // no warning86  if ((a<y) > -1) {} // expected-warning {{comparison of constant -1 with expression of type 'bool' is always true}}87 88  if ((a<y) == 0) {} // no warning89  if ((a<y) == 1) {} // no warning90  if ((a<y) == 2) {} // expected-warning {{comparison of constant 2 with expression of type 'bool' is always false}}91  if ((a<y) == z) {} // no warning92  if ((a<y) == -1) {}// expected-warning {{comparison of constant -1 with expression of type 'bool' is always false}}93 94  if ((a<y) != 0) {} // no warning95  if ((a<y) != 1) {} // no warning96  if ((a<y) != 2) {} // expected-warning {{comparison of constant 2 with expression of type 'bool' is always true}}97  if ((a<y) != z) {} // no warning98  if ((a<y) != -1) {}// expected-warning {{comparison of constant -1 with expression of type 'bool' is always true}}99 100  if ((a<y) == z) {} // no warning101  if (a>y<z)      {} // expected-error {{chained comparison 'X > Y < Z' does not behave the same as a mathematical expression}}102  if ((a<y) > z)  {} // no warning103  if((a<y)>(z<y)) {} // no warning104  if((a<y)==(z<y)){} // no warning105  if((a<y)!=(z<y)){} // no warning106  if((z==x)<(y==z)){}  // no warning107  if((a<y)!=((z==x)<(y==z))){} // no warning108 109 110  if (0 > !a)     {} // expected-warning {{comparison of constant 0 with expression of type 'bool' is always false}}111  if (1 > !a)     {} // no warning112  if (2 > !a)     {} // expected-warning {{comparison of constant 2 with expression of type 'bool' is always true}}113  if (y > !a)     {} // no warning114  if (-1 > !a)    {} // expected-warning {{comparison of constant -1 with expression of type 'bool' is always false}}115 116  if (0 < !a)     {} // no warning117  if (1 < !a)     {} // expected-warning {{comparison of constant 1 with expression of type 'bool' is always false}}118  if (2 < !a)     {} // expected-warning {{comparison of constant 2 with expression of type 'bool' is always false}}119  if (y < !a)     {} // no warning120  if (-1 < !a)    {} // expected-warning {{comparison of constant -1 with expression of type 'bool' is always true}}121 122 123  if (0 >= !a)    {} // no warning124  if (1 >= !a)    {} // expected-warning {{comparison of constant 1 with expression of type 'bool' is always true}}125  if (2 >= !a)    {} // expected-warning {{comparison of constant 2 with expression of type 'bool' is always true}}126  if (y >= !a)    {} // no warning127  if (-1 >= !a)   {} // expected-warning {{comparison of constant -1 with expression of type 'bool' is always false}}128 129  if (0 <= !a)    {} // expected-warning {{comparison of constant 0 with expression of type 'bool' is always true}}130  if (1 <= !a)    {} // no warning131  if (2 <= !a)    {} // expected-warning {{comparison of constant 2 with expression of type 'bool' is always false}}132  if (y <= !a)    {} //133  if (-1 <= !a)   {} // expected-warning {{comparison of constant -1 with expression of type 'bool' is always true}}134 135  if (0 > (a||b)) {} // expected-warning {{comparison of constant 0 with expression of type 'bool' is always false}}136  if (1 > (a||b)) {} // no warning137  if (4 > (a||b)) {} // expected-warning {{comparison of constant 4 with expression of type 'bool' is always true}}138 139  if (0 > (a&&b)) {} // expected-warning {{comparison of constant 0 with expression of type 'bool' is always false}}140  if (1 > (a&&b)) {} // no warning141  if (4 > (a&&b)) {} // expected-warning {{comparison of constant 4 with expression of type 'bool' is always true}}142 143  if (0 > (a<y))  {} // expected-warning {{comparison of constant 0 with expression of type 'bool' is always false}}144  if (1 > (a<y))  {} // no warning145  if (4 > (a<y))  {} // expected-warning {{comparison of constant 4 with expression of type 'bool' is always true}}146  if (z > (a<y))  {} //147  if (-1 > (a<y)) {} // expected-warning {{comparison of constant -1 with expression of type 'bool' is always false}}148 149  if (0 == (a<y)) {} // no warning150  if (1 == (a<y)) {} // no warning151  if (2 == (a<y)) {} // expected-warning {{comparison of constant 2 with expression of type 'bool' is always false}}152  if (z == (a<y)) {} // no warning153  if (-1 == (a<y)){} // expected-warning {{comparison of constant -1 with expression of type 'bool' is always false}}154 155  if (0 !=(a<y))  {} // no warning156  if (1 !=(a<y))  {} // no warning157  if (2 !=(a<y))  {} // expected-warning {{comparison of constant 2 with expression of type 'bool' is always true}}158  if (z !=(a<y))  {} // no warning159  if (-1 !=(a<y)) {} // expected-warning {{comparison of constant -1 with expression of type 'bool' is always true}}160 161  if (z ==(a<y))  {} // no warning162  if (z<a>y)      {} // expected-error {{chained comparison 'X < Y > Z' does not behave the same as a mathematical expression}}163  if (z > (a<y))  {} // no warning164  if((z<y)>(a<y)) {} // no warning165  if((z<y)==(a<y)){} // no warning166  if((z<y)!=(a<y)){} // no warning167  if((y==z)<(z==x)){} // no warning168  if(((z==x)<(y==z))!=(a<y)){}  // no warning169 170  if(((z==x)<(-1==z))!=(a<y)){} // no warning171  if(((z==x)<(z==-1))!=(a<y)){} // no warning172  if(((z==x)<-1)!=(a<y)){} // expected-warning {{comparison of constant -1 with expression of type 'bool' is always false}}173  if(((z==x)< 2)!=(a<y)){} // expected-warning {{comparison of constant 2 with expression of type 'bool' is always true}}174  if(((z==x)<(z>2))!=(a<y)){} // no warning175 176}177 178 179template<typename T, typename U, typename V> struct X6 {180  U f(T t, U u, V v) {181    // IfStmt182    if (t > 0)183      return u;184    else {185      if (t < 0)186        return v; // expected-error{{cannot initialize return object of type}}187    }188    bool r;189    if(r<0){} // expected-warning {{result of comparison of constant 0 with expression of type 'bool' is always false}}190 191    if (T x = t) {192      t = x;193    }194    return v; // expected-error{{cannot initialize return object of type}}195  }196};197 198struct ConvertibleToInt {199  operator int() const;200};201 202template struct X6<ConvertibleToInt, float, char>;203template struct X6<bool, int, int*>; // expected-note{{instantiation}}204 205 206 207