1 // RUN: %clang_cc1 -fsyntax-only -verify -Wassign-enum -Wswitch-enum -Wcovered-switch-default %s 2 3 enum Enum { 4 A0 = 1, A1 = 10 5 }; 6 7 enum __attribute__((enum_extensibility(closed))) EnumClosed { 8 B0 = 1, B1 = 10 9 }; 10 11 enum __attribute__((enum_extensibility(open))) EnumOpen { 12 C0 = 1, C1 = 10 13 }; 14 15 enum __attribute__((flag_enum)) EnumFlag { 16 D0 = 1, D1 = 8 17 }; 18 19 enum __attribute__((flag_enum,enum_extensibility(closed))) EnumFlagClosed { 20 E0 = 1, E1 = 8 21 }; 22 23 enum __attribute__((flag_enum,enum_extensibility(open))) EnumFlagOpen { 24 F0 = 1, F1 = 8 25 }; 26 27 enum __attribute__((enum_extensibility(arg1))) EnumInvalidArg { // expected-warning{{'enum_extensibility' attribute argument not supported: 'arg1'}} 28 X0 29 }; 30 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'}} 33 X1 34 }; 35 36 enum __attribute__((enum_extensibility())) EnumTooFewArgs { // expected-error{{'enum_extensibility' attribute takes one argument}} 37 X2 38 }; 39 40 struct __attribute__((enum_extensibility(open))) S { // expected-warning{{'enum_extensibility' attribute only applies to enums}}{ 41 }; 42 test()43void test() { 44 enum Enum t0 = 100; // expected-warning{{integer constant not in range of enumerated type}} 45 t0 = 1; 46 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}} 50 } 51 52 switch (t0) { 53 case A0: break; 54 case A1: break; 55 default: break; // expected-warning{{default label in switch which covers all enumeration}} 56 } 57 58 enum EnumClosed t1 = 100; // expected-warning{{integer constant not in range of enumerated type}} 59 t1 = 1; 60 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}} 64 } 65 66 switch (t1) { 67 case B0: break; 68 case B1: break; 69 default: break; // expected-warning{{default label in switch which covers all enumeration}} 70 } 71 72 enum EnumOpen t2 = 100; 73 t2 = 1; 74 75 switch (t2) { // expected-warning{{enumeration value 'C1' not handled in switch}} 76 case C0: break; 77 case 16: break; 78 } 79 80 switch (t2) { 81 case C0: break; 82 case C1: break; 83 default: break; 84 } 85 86 enum EnumFlag t3 = 5; // expected-warning{{integer constant not in range of enumerated type}} 87 t3 = 9; 88 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}} 93 } 94 95 switch (t3) { 96 case D0: break; 97 case D1: break; 98 default: break; 99 } 100 101 enum EnumFlagClosed t4 = 5; // expected-warning{{integer constant not in range of enumerated type}} 102 t4 = 9; 103 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}} 108 } 109 110 switch (t4) { 111 case E0: break; 112 case E1: break; 113 default: break; 114 } 115 116 enum EnumFlagOpen t5 = 5; 117 t5 = 9; 118 119 switch (t5) { // expected-warning{{enumeration value 'F1' not handled in switch}} 120 case F0: break; 121 case 9: break; 122 case 16: break; 123 } 124 125 switch (t5) { 126 case F0: break; 127 case F1: break; 128 default: break; 129 } 130 } 131