Douglas Gregor | abde2c7 | 2013-03-25 22:22:35 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s |
Douglas Gregor | 5471bc8 | 2011-09-08 17:18:35 +0000 | [diff] [blame] | 2 | |
| 3 | #if !__has_feature(objc_fixed_enum) |
| 4 | # error Enumerations with a fixed underlying type are not supported |
| 5 | #endif |
| 6 | |
| 7 | typedef long Integer; |
| 8 | |
| 9 | typedef enum : Integer { Enumerator1, Enumerator2 } Enumeration; |
| 10 | |
| 11 | int array[sizeof(Enumeration) == sizeof(long)? 1 : -1]; |
| 12 | |
| 13 | |
| 14 | enum Color { Red, Green, Blue }; |
| 15 | |
| 16 | struct X { |
| 17 | enum Color : 4; |
| 18 | enum Color field1: 4; |
| 19 | enum Other : Integer field2; |
| 20 | enum Other : Integer field3 : 4; |
| 21 | enum : Integer { Blah, Blarg } field4 : 4; |
| 22 | }; |
Douglas Gregor | 69ff26b | 2011-09-08 23:29:05 +0000 | [diff] [blame] | 23 | |
| 24 | void test() { |
| 25 | long value = 2; |
| 26 | Enumeration e = value; |
| 27 | } |
Eli Friedman | 04ca252 | 2012-02-07 04:34:38 +0000 | [diff] [blame] | 28 | |
| 29 | // <rdar://10381507> |
| 30 | typedef enum : long { Foo } IntegerEnum; |
Douglas Gregor | abde2c7 | 2013-03-25 22:22:35 +0000 | [diff] [blame] | 31 | int arr[(sizeof(__typeof__(Foo)) == sizeof(__typeof__(IntegerEnum)))? 1 : -1]; |
| 32 | int arr1[(sizeof(__typeof__(Foo)) == sizeof(__typeof__(long)))? 1 : -1]; |
| 33 | int arr2[(sizeof(__typeof__(IntegerEnum)) == sizeof(__typeof__(long)))? 1 : -1]; |
Eli Friedman | 04ca252 | 2012-02-07 04:34:38 +0000 | [diff] [blame] | 34 | |
| 35 | // <rdar://problem/10760113> |
| 36 | typedef enum : long long { Bar = -1 } LongLongEnum; |
| 37 | int arr3[(long long)Bar == (long long)-1 ? 1 : -1]; |
Eli Friedman | 2fcff83 | 2012-12-18 02:37:32 +0000 | [diff] [blame] | 38 | |
| 39 | typedef enum : Integer { BaseElem } BaseEnum; |
| 40 | typedef enum : BaseEnum { DerivedElem } DerivedEnum; // expected-error {{non-integral type 'BaseEnum' is an invalid underlying type}} |