| 1 |
// RUN: %clang_cc1 -verify=expected,all -triple x86_64-unknown-linux-gnu -fsyntax-only -std=c23 %s -Wpre-c23-compat |
| 2 |
// RUN: %clang_cc1 -verify=pedantic,all -triple x86_64-unknown-linux-gnu -fsyntax-only -std=c17 %s -pedantic |
| 3 |
|
| 4 |
#include <limits.h> |
| 5 |
|
| 6 |
#define GET_TYPE_INT(x) _Generic(x, \ |
| 7 |
char: 1,\ |
| 8 |
unsigned char: 2,\ |
| 9 |
signed char: 3,\ |
| 10 |
short: 4,\ |
| 11 |
unsigned short: 5,\ |
| 12 |
int: 6,\ |
| 13 |
unsigned int: 7,\ |
| 14 |
long: 8,\ |
| 15 |
unsigned long: 9,\ |
| 16 |
long long: 10,\ |
| 17 |
unsigned long long: 11,\ |
| 18 |
default: 0xFF\ |
| 19 |
)\ |
| 20 |
|
| 21 |
enum x { |
| 22 |
a = INT_MAX, |
| 23 |
b = ULLONG_MAX, // expected-warning {{enumerator value which exceeds the range of 'int' is incompatible with C standards before C23}} |
| 24 |
// pedantic-warning@-1 {{enumerator value which exceeds the range of 'int' is a C23 extension}} |
| 25 |
a_type = GET_TYPE_INT(a), |
| 26 |
b_type = GET_TYPE_INT(b) |
| 27 |
}; |
| 28 |
|
| 29 |
_Static_assert(GET_TYPE_INT(a) == GET_TYPE_INT(b), "ok"); |
| 30 |
|
| 31 |
extern enum x e_a; |
| 32 |
extern __typeof(b) e_a; |
| 33 |
extern __typeof(a) e_a; |
| 34 |
|
| 35 |
enum a { |
| 36 |
a0 = 0xFFFFFFFFFFFFFFFFULL // expected-warning {{enumerator value which exceeds the range of 'int' is incompatible with C standards before C23}} |
| 37 |
// pedantic-warning@-1 {{enumerator value which exceeds the range of 'int' is a C23 extension}} |
| 38 |
}; |
| 39 |
|
| 40 |
_Bool e (void) { |
| 41 |
return a0; |
| 42 |
} |
| 43 |
|
| 44 |
int f (void) { |
| 45 |
return a0; // expected-warning {{implicit conversion from 'enum a' to 'int' changes value from 18446744073709551615 to -1}} |
| 46 |
// pedantic-warning@-1 {{implicit conversion from 'unsigned long' to 'int' changes value from 18446744073709551615 to -1}} |
| 47 |
} |
| 48 |
|
| 49 |
unsigned long g (void) { |
| 50 |
return a0; |
| 51 |
} |
| 52 |
|
| 53 |
unsigned long long h (void) { |
| 54 |
return a0; |
| 55 |
} |
| 56 |
|
| 57 |
enum big_enum { |
| 58 |
big_enum_a = LONG_MAX, // expected-warning {{enumerator value which exceeds the range of 'int' is incompatible with C standards before C23}} |
| 59 |
// pedantic-warning@-1 {{enumerator value which exceeds the range of 'int' is a C23 extension}} |
| 60 |
big_enum_b = a + 1, // expected-warning {{enumerator value which exceeds the range of 'int' is incompatible with C standards before C23}} |
| 61 |
// pedantic-warning@-1 {{enumerator value which exceeds the range of 'int' is a C23 extension}} |
| 62 |
big_enum_c = ULLONG_MAX // expected-warning {{enumerator value which exceeds the range of 'int' is incompatible with C standards before C23}} |
| 63 |
// pedantic-warning@-1 {{enumerator value which exceeds the range of 'int' is a C23 extension}} |
| 64 |
}; |
| 65 |
|
| 66 |
_Static_assert(GET_TYPE_INT(big_enum_a) == GET_TYPE_INT(big_enum_b), "ok"); |