blob: c00e45a03ed0b7b22ed6c4d8b3fa5db38a69e304 [file] [log] [blame]
Douglas Gregorabde2c72013-03-25 22:22:35 +00001// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
Douglas Gregor5471bc82011-09-08 17:18:35 +00002
3#if !__has_feature(objc_fixed_enum)
4# error Enumerations with a fixed underlying type are not supported
5#endif
6
7typedef long Integer;
8
9typedef enum : Integer { Enumerator1, Enumerator2 } Enumeration;
10
11int array[sizeof(Enumeration) == sizeof(long)? 1 : -1];
12
13
14enum Color { Red, Green, Blue };
15
16struct 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 Gregor69ff26b2011-09-08 23:29:05 +000023
24void test() {
25 long value = 2;
26 Enumeration e = value;
27}
Eli Friedman04ca2522012-02-07 04:34:38 +000028
29// <rdar://10381507>
30typedef enum : long { Foo } IntegerEnum;
Douglas Gregorabde2c72013-03-25 22:22:35 +000031int arr[(sizeof(__typeof__(Foo)) == sizeof(__typeof__(IntegerEnum)))? 1 : -1];
32int arr1[(sizeof(__typeof__(Foo)) == sizeof(__typeof__(long)))? 1 : -1];
33int arr2[(sizeof(__typeof__(IntegerEnum)) == sizeof(__typeof__(long)))? 1 : -1];
Eli Friedman04ca2522012-02-07 04:34:38 +000034
35// <rdar://problem/10760113>
36typedef enum : long long { Bar = -1 } LongLongEnum;
37int arr3[(long long)Bar == (long long)-1 ? 1 : -1];
Eli Friedman2fcff832012-12-18 02:37:32 +000038
39typedef enum : Integer { BaseElem } BaseEnum;
40typedef enum : BaseEnum { DerivedElem } DerivedEnum; // expected-error {{non-integral type 'BaseEnum' is an invalid underlying type}}