File: n3030.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 (109 lines) | stat: -rw-r--r-- 5,292 bytes parent folder | download | duplicates (3)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// RUN: %clang_cc1 -verify -triple x86_64-unknown-linux-gnu -fsyntax-only -std=c23 %s -pedantic -Wall

#include <limits.h>

enum us : unsigned short {
  us_max = USHRT_MAX,
  us_violation,  // expected-error {{enumerator value 65536 is not representable in the underlying type 'unsigned short'}}
  us_violation_2 = us_max + 1, // expected-error {{enumerator value is not representable in the underlying type 'unsigned short'}}
  us_wrap_around_to_zero = (unsigned short)(USHRT_MAX + 1) /* Okay: conversion
                            done in constant expression before conversion to
                            underlying type: unsigned semantics okay. */
};

enum ui : unsigned int {
  ui_max = UINT_MAX,
  ui_violation,  // expected-error {{enumerator value 4294967296 is not representable in the underlying type 'unsigned int'}}
  ui_no_violation = ui_max + 1,
  ui_wrap_around_to_zero = (unsigned int)(UINT_MAX + 1)
};

enum E1 : short;
enum E2 : short; // expected-note {{previous}}
enum E3; // expected-warning {{ISO C forbids forward references to 'enum' types}}
enum E4 : unsigned long long;

enum E1 : short { m11, m12 };
enum E1 x = m11;

enum E2 : long { // expected-error {{enumeration redeclared with different underlying type 'long' (was 'short')}}
  m21,
  m22
};

enum E3 { // expected-note {{definition of 'enum E3' is not complete until the closing '}'}}
          // expected-note@-1 {{previous}}
  m31,
  m32,
  m33 = sizeof(enum E3) // expected-error {{invalid application of 'sizeof' to an incomplete type 'enum E3'}}
};
enum E3 : int; // expected-error {{enumeration previously declared with nonfixed underlying type}}

enum E4 : unsigned long long {
  m40 = sizeof(enum E4),
  m41 = ULLONG_MAX,
  m42 // expected-error {{enumerator value 18446744073709551616 is not representable in the underlying type 'unsigned long long'}}
};

enum E5 y; // expected-error {{tentative definition has type 'enum E5' that is never completed}}
           // expected-warning@-1 {{ISO C forbids forward references to 'enum' types}}
           // expected-note@-2 {{forward declaration of 'enum E5'}}
enum E6 : long int z;   // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration; missing list of enumerators?}}
enum E7 : long int = 0;  // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration; missing list of enumerators?}}
                         // expected-error@-1 {{expected identifier or '('}}

enum underlying : unsigned char { b0 };

constexpr int a = _Generic(b0, int: 2, unsigned char: 1, default: 0);
constexpr int b = _Generic((enum underlying)b0, int: 2, unsigned char: 1, default: 0);
static_assert(a == 1);
static_assert(b == 1);

void f1(enum a : long b); // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration; missing list of enumerators?}}
                          // expected-warning@-1 {{declaration of 'enum a' will not be visible outside of this function}}
void f2(enum c : long{x} d);
enum e : int f3(); // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration; missing list of enumerators?}}

typedef enum t u; // expected-warning {{ISO C forbids forward references to 'enum' types}}
typedef enum v : short W; // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration; missing list of enumerators?}}
typedef enum q : short { s } R;

struct s1 {
  int x;
  enum e:int : 1; // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration; missing list of enumerators?}}
  int y;
};

enum forward; // expected-warning {{ISO C forbids forward references to 'enum' types}}
extern enum forward fwd_val0;  /* Constraint violation: incomplete type */
extern enum forward *fwd_ptr0; // expected-note {{previous}}
extern int
    *fwd_ptr0; // expected-error {{redeclaration of 'fwd_ptr0' with a different type: 'int *' vs 'enum forward *'}}

enum forward1 : int;
extern enum forward1 fwd_val1;
extern int fwd_val1;
extern enum forward1 *fwd_ptr1;
extern int *fwd_ptr1;

enum ee1 : short;
enum e : short f = 0; // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration; missing list of enumerators?}}
enum g : short { yyy } h = yyy;

enum ee2 : typeof ((enum ee3 : short { A })0, (short)0);

enum not_actually_atomic : _Atomic(short) { // expected-error {{'_Atomic' qualifier ignored; operations involving the enumeration type will be non-atomic}}
  Surprise
};

enum not_actually_const : const int { // expected-warning {{'const' qualifier in enumeration underlying type ignored}}
  SurpriseAgain
};

enum not_actually_volatile : volatile int { // expected-warning {{'volatile' qualifier in enumeration underlying type ignored}}
  SurpriseOnceMore
};

enum not_acually_const_or_volatile : const volatile int { // expected-warning {{'const' and 'volatile' qualifiers in enumeration underlying type ignored}}
  WhyTheSurprise
};