brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 26d6dfd Raw
66 lines · c
1// RUN: %clang_cc1 -verify=expected,all -triple x86_64-unknown-linux-gnu -fsyntax-only -std=c23 %s -Wpre-c23-compat2// RUN: %clang_cc1 -verify=pedantic,all -triple x86_64-unknown-linux-gnu -fsyntax-only -std=c17 %s -pedantic3 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 21enum x {22a = INT_MAX,23b = 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}}25a_type = GET_TYPE_INT(a),26b_type = GET_TYPE_INT(b)27};28 29_Static_assert(GET_TYPE_INT(a) == GET_TYPE_INT(b), "ok"); 30 31extern enum x e_a;32extern __typeof(b) e_a;33extern __typeof(a) e_a;34 35enum 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 44int f (void) {45  return a0; // all-warning {{implicit conversion from 'unsigned long' to 'int' changes value from 18446744073709551615 to -1}}46}47 48unsigned long g (void) {49  return a0;50}51 52unsigned long long h (void) {53  return a0;54}55 56enum big_enum {57  big_enum_a = LONG_MAX, // expected-warning {{enumerator value which exceeds the range of 'int' is incompatible with C standards before C23}}58                         // pedantic-warning@-1 {{enumerator value which exceeds the range of 'int' is a C23 extension}}59  big_enum_b = a + 1, // expected-warning {{enumerator value which exceeds the range of 'int' is incompatible with C standards before C23}}60                      // pedantic-warning@-1 {{enumerator value which exceeds the range of 'int' is a C23 extension}}61  big_enum_c = ULLONG_MAX // expected-warning {{enumerator value which exceeds the range of 'int' is incompatible with C standards before C23}}62                          // pedantic-warning@-1 {{enumerator value which exceeds the range of 'int' is a C23 extension}}63};64 65_Static_assert(GET_TYPE_INT(big_enum_a) == GET_TYPE_INT(big_enum_b), "ok");66