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