1 | // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s |
2 | // RUN: %clang_cc1 -fsyntax-only -verify -xc %s |
3 | |
4 | #ifdef __OBJC__ |
5 | #if !__has_feature(objc_fixed_enum) |
6 | # error Enumerations with a fixed underlying type are not supported |
7 | #endif |
8 | #endif |
9 | |
10 | #if !__has_extension(cxx_fixed_enum) |
11 | # error Enumerations with a fixed underlying type are not supported |
12 | #endif |
13 | |
14 | typedef long Integer; |
15 | |
16 | typedef enum : Integer { Enumerator1, Enumerator2 } Enumeration; |
17 | |
18 | int array[sizeof(Enumeration) == sizeof(long)? 1 : -1]; |
19 | |
20 | |
21 | enum Color { Red, Green, Blue }; |
22 | |
23 | struct X { |
24 | enum Color : 4; |
25 | enum Color field1: 4; |
26 | enum Other : Integer field2; |
27 | enum Other : Integer field3 : 4; |
28 | enum : Integer { Blah, Blarg } field4 : 4; |
29 | }; |
30 | |
31 | void test() { |
32 | long value = 2; |
33 | Enumeration e = value; |
34 | } |
35 | |
36 | // <rdar://10381507> |
37 | typedef enum : long { Foo } IntegerEnum; |
38 | int arr[(sizeof(__typeof__(Foo)) == sizeof(__typeof__(IntegerEnum)))? 1 : -1]; |
39 | int arr1[(sizeof(__typeof__(Foo)) == sizeof(__typeof__(long)))? 1 : -1]; |
40 | int arr2[(sizeof(__typeof__(IntegerEnum)) == sizeof(__typeof__(long)))? 1 : -1]; |
41 | |
42 | // <rdar://problem/10760113> |
43 | typedef enum : long long { Bar = -1 } LongLongEnum; |
44 | int arr3[(long long)Bar == (long long)-1 ? 1 : -1]; |
45 | |
46 | typedef enum : Integer { BaseElem } BaseEnum; |
47 | typedef enum : BaseEnum { DerivedElem } DerivedEnum; // expected-error {{non-integral type 'BaseEnum' is an invalid underlying type}} |
48 | |
49 | // <rdar://problem/24999533> |
50 | enum MyEnum : _Bool { |
51 | MyThing = 0 |
52 | }; |
53 | |