[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Sema / enum-attr.c
blob1cdd7028e03e0ebffc42a214a9bdfa268300e4e9
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wassign-enum -Wswitch-enum -Wcovered-switch-default %s
3 enum Enum {
4 A0 = 1, A1 = 10
5 };
7 enum __attribute__((enum_extensibility(closed))) EnumClosed {
8 B0 = 1, B1 = 10
9 };
11 enum __attribute__((enum_extensibility(open))) EnumOpen {
12 C0 = 1, C1 = 10
15 enum __attribute__((flag_enum)) EnumFlag {
16 D0 = 1, D1 = 8
19 enum __attribute__((flag_enum,enum_extensibility(closed))) EnumFlagClosed {
20 E0 = 1, E1 = 8
23 enum __attribute__((flag_enum,enum_extensibility(open))) EnumFlagOpen {
24 F0 = 1, F1 = 8
27 enum __attribute__((enum_extensibility(arg1))) EnumInvalidArg { // expected-warning{{'enum_extensibility' attribute argument not supported: 'arg1'}}
31 // FIXME: The warning should mention that enum_extensibility takes only one argument.
32 enum __attribute__((enum_extensibility(closed,open))) EnumTooManyArgs { // expected-error{{use of undeclared identifier 'open'}}
36 enum __attribute__((enum_extensibility())) EnumTooFewArgs { // expected-error{{'enum_extensibility' attribute takes one argument}}
40 struct __attribute__((enum_extensibility(open))) S { // expected-warning{{'enum_extensibility' attribute only applies to enums}}{
43 void test(void) {
44 enum Enum t0 = 100; // expected-warning{{integer constant not in range of enumerated type}}
45 t0 = 1;
47 switch (t0) { // expected-warning{{enumeration value 'A1' not handled in switch}}
48 case A0: break;
49 case 16: break; // expected-warning{{case value not in enumerated type}}
52 switch (t0) {
53 case A0: break;
54 case A1: break;
55 default: break; // expected-warning{{default label in switch which covers all enumeration}}
58 enum EnumClosed t1 = 100; // expected-warning{{integer constant not in range of enumerated type}}
59 t1 = 1;
61 switch (t1) { // expected-warning{{enumeration value 'B1' not handled in switch}}
62 case B0: break;
63 case 16: break; // expected-warning{{case value not in enumerated type}}
66 switch (t1) {
67 case B0: break;
68 case B1: break;
69 default: break; // expected-warning{{default label in switch which covers all enumeration}}
72 enum EnumOpen t2 = 100;
73 t2 = 1;
75 switch (t2) { // expected-warning{{enumeration value 'C1' not handled in switch}}
76 case C0: break;
77 case 16: break;
80 switch (t2) {
81 case C0: break;
82 case C1: break;
83 default: break;
86 enum EnumFlag t3 = 5; // expected-warning{{integer constant not in range of enumerated type}}
87 t3 = 9;
89 switch (t3) { // expected-warning{{enumeration value 'D1' not handled in switch}}
90 case D0: break;
91 case 9: break;
92 case 16: break; // expected-warning{{case value not in enumerated type}}
95 switch (t3) {
96 case D0: break;
97 case D1: break;
98 default: break;
101 enum EnumFlagClosed t4 = 5; // expected-warning{{integer constant not in range of enumerated type}}
102 t4 = 9;
104 switch (t4) { // expected-warning{{enumeration value 'E1' not handled in switch}}
105 case E0: break;
106 case 9: break;
107 case 16: break; // expected-warning{{case value not in enumerated type}}
110 switch (t4) {
111 case E0: break;
112 case E1: break;
113 default: break;
116 enum EnumFlagOpen t5 = 5;
117 t5 = 9;
119 switch (t5) { // expected-warning{{enumeration value 'F1' not handled in switch}}
120 case F0: break;
121 case 9: break;
122 case 16: break;
125 switch (t5) {
126 case F0: break;
127 case F1: break;
128 default: break;