| 1 |
// RUN: %clang_cc1 %s -verify=expected -Wimplicit-int-conversion |
| 2 |
// RUN: %clang_cc1 %s -verify=none -Wimplicit-int-conversion -Wno-implicit-int-conversion-on-negation |
| 3 |
|
| 4 |
// none-no-diagnostics |
| 5 |
|
| 6 |
char test_char(char x) { |
| 7 |
return -x; // expected-warning {{implicit conversion loses integer precision: 'int' to 'char' on negation}} |
| 8 |
} |
| 9 |
|
| 10 |
unsigned char test_unsigned_char(unsigned char x) { |
| 11 |
return -x; // expected-warning {{implicit conversion loses integer precision: 'int' to 'unsigned char' on negation}} |
| 12 |
} |
| 13 |
|
| 14 |
short test_short(short x) { |
| 15 |
return -x; // expected-warning {{implicit conversion loses integer precision: 'int' to 'short' on negation}} |
| 16 |
} |
| 17 |
|
| 18 |
unsigned short test_unsigned_short(unsigned short x) { |
| 19 |
return -x; // expected-warning {{implicit conversion loses integer precision: 'int' to 'unsigned short' on negation}} |
| 20 |
} |
| 21 |
|
| 22 |
// --- int-width and wider (should NOT warn) --- |
| 23 |
|
| 24 |
int test_i(int x) { |
| 25 |
return -x; |
| 26 |
} |
| 27 |
|
| 28 |
unsigned int test_ui(unsigned int x) { |
| 29 |
return -x; |
| 30 |
} |
| 31 |
|
| 32 |
long test_l(long x) { |
| 33 |
return -x; |
| 34 |
} |
| 35 |
|
| 36 |
unsigned long test_ul(unsigned long x) { |
| 37 |
return -x; |
| 38 |
} |
| 39 |
|
| 40 |
long long test_ll(long long x) { |
| 41 |
return -x; |
| 42 |
} |
| 43 |
|
| 44 |
unsigned long long test_ull(unsigned long long x) { |
| 45 |
return -x; |
| 46 |
} |
| 47 |
|
| 48 |
unsigned _BitInt(16) test_unsigned_bit_int(unsigned _BitInt(16) x) { |
| 49 |
return -x; |
| 50 |
} |
| 51 |
|
| 52 |
unsigned test_shift_minus(int i) { |
| 53 |
return -(1 << i); |
| 54 |
} |
| 55 |
|
| 56 |
unsigned test_shift_not(int i) { |
| 57 |
return ~(1 << i); |
| 58 |
} |