File: n3029.c

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,245,028 kB
  • sloc: cpp: 7,619,726; ansic: 1,434,018; asm: 1,058,748; python: 252,740; f90: 94,671; objc: 70,685; lisp: 42,813; pascal: 18,401; sh: 8,601; ml: 5,111; perl: 4,720; makefile: 3,675; awk: 3,523; javascript: 2,409; xml: 892; fortran: 770
file content (65 lines) | stat: -rw-r--r-- 2,390 bytes parent folder | download | duplicates (5)
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
59
60
61
62
63
64
65
// RUN: %clang_cc1 -verify=expected,all -triple x86_64-unknown-linux-gnu -fsyntax-only -std=c23 %s -Wpre-c23-compat
// RUN: %clang_cc1 -verify=pedantic,all -triple x86_64-unknown-linux-gnu -fsyntax-only -std=c17 %s -pedantic

#include <limits.h>

#define GET_TYPE_INT(x) _Generic(x, \
  char: 1,\
  unsigned char: 2,\
  signed char: 3,\
  short: 4,\
  unsigned short: 5,\
  int: 6,\
  unsigned int: 7,\
  long: 8,\
  unsigned long: 9,\
  long long: 10,\
  unsigned long long: 11,\
  default: 0xFF\
  )\

enum x {
a = INT_MAX,
b = ULLONG_MAX, // expected-warning {{enumerator value which exceeds the range of 'int' is incompatible with C standards before C23}}
                // pedantic-warning@-1 {{enumerator value which exceeds the range of 'int' is a C23 extension}}
a_type = GET_TYPE_INT(a),
b_type = GET_TYPE_INT(b)
};

_Static_assert(GET_TYPE_INT(a) == GET_TYPE_INT(b), "ok"); 

extern enum x e_a;
extern __typeof(b) e_a;
extern __typeof(a) e_a;

enum a {
  a0 = 0xFFFFFFFFFFFFFFFFULL // expected-warning {{enumerator value which exceeds the range of 'int' is incompatible with C standards before C23}}
                             // pedantic-warning@-1 {{enumerator value which exceeds the range of 'int' is a C23 extension}}
};

_Bool e (void) {
  return a0;
}

int f (void) {
  return a0; // all-warning {{implicit conversion from 'unsigned long' to 'int' changes value from 18446744073709551615 to -1}}
}

unsigned long g (void) {
  return a0;
}

unsigned long long h (void) {
  return a0;
}

enum big_enum {
  big_enum_a = LONG_MAX, // expected-warning {{enumerator value which exceeds the range of 'int' is incompatible with C standards before C23}}
                         // pedantic-warning@-1 {{enumerator value which exceeds the range of 'int' is a C23 extension}}
  big_enum_b = a + 1, // expected-warning {{enumerator value which exceeds the range of 'int' is incompatible with C standards before C23}}
                      // pedantic-warning@-1 {{enumerator value which exceeds the range of 'int' is a C23 extension}}
  big_enum_c = ULLONG_MAX // expected-warning {{enumerator value which exceeds the range of 'int' is incompatible with C standards before C23}}
                          // pedantic-warning@-1 {{enumerator value which exceeds the range of 'int' is a C23 extension}}
};

_Static_assert(GET_TYPE_INT(big_enum_a) == GET_TYPE_INT(big_enum_b), "ok");