aboutsummaryrefslogtreecommitdiff
path: root/clang/test/Sema/implicit-int-conversion-on-int.c
blob: 3b1d81cd6a9ab3b42d06346c0c0d21b040a7faf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// RUN: %clang_cc1 %s -verify=expected -Wimplicit-int-conversion
// RUN: %clang_cc1 %s -verify=none -Wimplicit-int-conversion -Wno-implicit-int-conversion-on-negation

// none-no-diagnostics

char test_char(char x) {
  return -x; // expected-warning {{implicit conversion loses integer precision: 'int' to 'char' on negation}}
}

unsigned char test_unsigned_char(unsigned char x) {
  return -x; // expected-warning {{implicit conversion loses integer precision: 'int' to 'unsigned char' on negation}}
}

short test_short(short x) {
  return -x; // expected-warning {{implicit conversion loses integer precision: 'int' to 'short' on negation}}
}

unsigned short test_unsigned_short(unsigned short x) {
  return -x; // expected-warning {{implicit conversion loses integer precision: 'int' to 'unsigned short' on negation}}
}

// --- int-width and wider (should NOT warn) ---

int test_i(int x) {
  return -x;
}

unsigned int test_ui(unsigned int x) {
  return -x;
}

long test_l(long x) {
  return -x;
}

unsigned long test_ul(unsigned long x) {
  return -x;
}

long long test_ll(long long x) {
  return -x;
}

unsigned long long test_ull(unsigned long long x) {
  return -x;
}

unsigned _BitInt(16) test_unsigned_bit_int(unsigned _BitInt(16) x) {
  return -x;
}

unsigned test_shift_minus(int i) {
  return -(1 << i);
}

unsigned test_shift_not(int i) {
  return ~(1 << i);
}