| 1 |
/* The precise output depends of sizeof(int) and sizeof(long long), so |
| 2 |
filter by target. */ |
| 3 |
/* { dg-do compile { target i?86-*-* x86_64-*-* } } */ |
| 4 |
|
| 5 |
/* Apparent uses of ^ for powers of 2. */ |
| 6 |
|
| 7 |
short t2_16 = 2^16; /* { dg-warning "result of '2\\^16' is 18; did you mean '1 << 16' \\(65536\\)\\? \\\[-Wxor-used-as-pow\\\]" } */ |
| 8 |
int t2_17 = 2^17; /* { dg-warning "result of '2\\^17' is 19; did you mean '1 << 17' \\(131072\\)\\?" } */ |
| 9 |
int t2_30 = 2^30; /* { dg-warning "result of '2\\^30' is 28; did you mean '1 << 30' \\(1073741824\\)\\?" } */ |
| 10 |
|
| 11 |
/* Should be 1LL at 31 and above, due to overflow. */ |
| 12 |
int t2_31 = 2^31; /* { dg-warning "result of '2\\^31' is 29; did you mean '1LL << 31'\\?" } */ |
| 13 |
int t2_32 = 2^32; /* { dg-warning "result of '2\\^32' is 34; did you mean '1LL << 32'\\?" } */ |
| 14 |
|
| 15 |
long t2_63 = 2^63; /* { dg-warning "result of '2\\^63' is 61; did you mean exponentiation\\?" } */ |
| 16 |
long t2_64 = 2^64; /* { dg-warning "result of '2\\^64' is 66; did you mean exponentiation\\?" } */ |
| 17 |
|
| 18 |
/* ...but don't warn when RHS is large enough. */ |
| 19 |
long t2_65 = 2^65; |
| 20 |
long t2_127 = 2^127; |
| 21 |
long t2_128 = 2^128; |
| 22 |
long t2_129 = 2^129; |
| 23 |
|
| 24 |
/* Verify that -Wxor-used-as-pow happens before folding. */ |
| 25 |
long t2_32_m1 = ((2^32)-1); /* { dg-warning "result of '2\\^32' is 34; did you mean '1LL << 32'\\?" } */ |
| 26 |
|
| 27 |
|
| 28 |
/* Apparent uses of ^ for powers of 10. */ |
| 29 |
|
| 30 |
long t10_2 = 10^2; /* { dg-warning "result of '10\\^2' is 8; did you mean '1e2'\\?" } */ |
| 31 |
long t10_9 = 10^9; /* { dg-warning "result of '10\\^9' is 3; did you mean '1e9'\\?" } */ |
| 32 |
long t10_10 = 10^10; /* { dg-warning "result of '10\\^10' is 0; did you mean '1e10'\\?" } */ |
| 33 |
long t10_100 = 10^100; /* { dg-warning "result of '10\\^100' is 110; did you mean '1e100'\\?" } */ |
| 34 |
|
| 35 |
/* Don't warn on negatives. */ |
| 36 |
long tm2_2 = -2^2; |
| 37 |
long t2_m2 = 2^-2; |
| 38 |
long tm10_10 = -10^10; |
| 39 |
long t10_m10 = 10^-10; |
| 40 |
|
| 41 |
/* If LHS is not 2 or 10, we shouldn't complain. */ |
| 42 |
int t0_0 = 0 ^ 0; |
| 43 |
int t6_7 = 6 ^ 7; |
| 44 |
|
| 45 |
/* Floating point is already covered by type-checking. */ |
| 46 |
float f10_10 = 10.f^10; /* { dg-error "invalid operands to binary \\^ \\(have 'float' and 'int'\\)" "" { target c } } */ |
| 47 |
/* { dg-error "invalid operands of types 'float' and 'int' to binary 'operator\\^'" "" { target c++ } .-1 } */ |
| 48 |
|
| 49 |
/* Don't complain if the LHS isn't literal decimal 2 or 10. */ |
| 50 |
int t1p1_16 = (1 + 1) ^ 16; |
| 51 |
int t5p5_6 = (5 + 5) ^ 6; |
| 52 |
int h2_8 = 0x2 ^ 8; |
| 53 |
int h10_3 = 0xa ^ 3; |
| 54 |
|
| 55 |
/* Don't complain if the RHS isn't literal decimal. */ |
| 56 |
int t2_x16 = 2^0x10; |
| 57 |
int h10_x3 = 10 ^ 0x3; |
| 58 |
|
| 59 |
/* Don't complain about uses in macros. */ |
| 60 |
#define AMT (10^2) |
| 61 |
int amt = AMT; |