brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.2 KiB · 94ea703 Raw
110 lines · c
1// RUN: %clang_cc1 -verify -triple x86_64-unknown-linux-gnu -fsyntax-only -std=c23 %s -pedantic -Wall2 3#include <limits.h>4 5enum us : unsigned short {6  us_max = USHRT_MAX,7  us_violation,  // expected-error {{enumerator value 65536 is not representable in the underlying type 'unsigned short'}}8  us_violation_2 = us_max + 1, // expected-error {{enumerator value is not representable in the underlying type 'unsigned short'}}9  us_wrap_around_to_zero = (unsigned short)(USHRT_MAX + 1) /* Okay: conversion10                            done in constant expression before conversion to11                            underlying type: unsigned semantics okay. */12};13 14enum ui : unsigned int {15  ui_max = UINT_MAX,16  ui_violation,  // expected-error {{enumerator value 4294967296 is not representable in the underlying type 'unsigned int'}}17  ui_no_violation = ui_max + 1,18  ui_wrap_around_to_zero = (unsigned int)(UINT_MAX + 1)19};20 21enum E1 : short;22enum E2 : short; // expected-note {{previous}}23enum E3; // expected-warning {{ISO C forbids forward references to 'enum' types}}24enum E4 : unsigned long long;25 26enum E1 : short { m11, m12 };27enum E1 x = m11;28 29enum E2 : long { // expected-error {{enumeration redeclared with different underlying type 'long' (was 'short')}}30  m21,31  m2232};33 34enum E3 { // expected-note {{definition of 'enum E3' is not complete until the closing '}'}}35          // expected-note@-1 {{previous}}36  m31,37  m32,38  m33 = sizeof(enum E3) // expected-error {{invalid application of 'sizeof' to an incomplete type 'enum E3'}}39};40enum E3 : int; // expected-error {{enumeration previously declared with nonfixed underlying type}}41 42enum E4 : unsigned long long {43  m40 = sizeof(enum E4),44  m41 = ULLONG_MAX,45  m42 // expected-error {{enumerator value 18446744073709551616 is not representable in the underlying type 'unsigned long long'}}46};47 48enum E5 y; // expected-error {{tentative definition has type 'enum E5' that is never completed}}49           // expected-warning@-1 {{ISO C forbids forward references to 'enum' types}}50           // expected-note@-2 {{forward declaration of 'enum E5'}}51enum 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?}}52enum 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?}}53                         // expected-error@-1 {{expected identifier or '('}}54 55enum underlying : unsigned char { b0 };56 57constexpr int a = _Generic(b0, int: 2, unsigned char: 1, default: 0);58constexpr int b = _Generic((enum underlying)b0, int: 2, unsigned char: 1, default: 0);59static_assert(a == 1);60static_assert(b == 1);61 62void 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?}}63                          // expected-warning@-1 {{declaration of 'enum a' will not be visible outside of this function}}64void f2(enum c : long{x} d);65enum 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?}}66 67typedef enum t u; // expected-warning {{ISO C forbids forward references to 'enum' types}}68typedef 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?}}69typedef enum q : short { s } R;70 71struct s1 {72  int x;73  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?}}74  int y;75};76 77enum forward; // expected-warning {{ISO C forbids forward references to 'enum' types}}78extern enum forward fwd_val0;  /* Constraint violation: incomplete type */79extern enum forward *fwd_ptr0; // expected-note {{previous}}80extern int81    *fwd_ptr0; // expected-error {{redeclaration of 'fwd_ptr0' with a different type: 'int *' vs 'enum forward *'}}82 83enum forward1 : int;84extern enum forward1 fwd_val1;85extern int fwd_val1;86extern enum forward1 *fwd_ptr1;87extern int *fwd_ptr1;88 89enum ee1 : short;90enum 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?}}91enum g : short { yyy } h = yyy;92 93enum ee2 : typeof ((enum ee3 : short { A })0, (short)0);94 95enum not_actually_atomic : _Atomic(short) { // expected-error {{'_Atomic' qualifier ignored; operations involving the enumeration type will be non-atomic}}96  Surprise97};98 99enum not_actually_const : const int { // expected-warning {{'const' qualifier in enumeration underlying type ignored}}100  SurpriseAgain101};102 103enum not_actually_volatile : volatile int { // expected-warning {{'volatile' qualifier in enumeration underlying type ignored}}104  SurpriseOnceMore105};106 107enum not_acually_const_or_volatile : const volatile int { // expected-warning {{'const' and 'volatile' qualifiers in enumeration underlying type ignored}}108  WhyTheSurprise109};110