1// RUN: %clang_cc1 -verify %s -x objective-c 2// RUN: %clang_cc1 -verify %s -x objective-c++ 3 4 5#define CF_ENUM(_type, _name) enum _name : _type _name; enum _name : _type 6#define NS_ENUM(_type, _name) CF_ENUM(_type, _name) 7 8#define NS_ERROR_ENUM(_type, _name, _domain) \ 9 enum _name : _type _name; enum __attribute__((ns_error_domain(_domain))) _name : _type 10 11typedef NS_ENUM(unsigned, MyEnum) { 12 MyFirst, 13 MySecond, 14}; 15 16typedef NS_ENUM(invalidType, MyInvalidEnum) { 17// expected-error@-1{{unknown type name 'invalidType'}} 18// expected-error@-2{{unknown type name 'invalidType'}} 19 MyFirstInvalid, 20 MySecondInvalid, 21}; 22 23@interface NSString 24@end 25 26extern NSString *const MyErrorDomain; 27typedef NS_ERROR_ENUM(unsigned char, MyErrorEnum, MyErrorDomain) { 28 MyErrFirst, 29 MyErrSecond, 30}; 31 32typedef NSString *const NsErrorDomain; 33extern NsErrorDomain MyTypedefErrorDomain; 34typedef NS_ERROR_ENUM(unsigned char, MyTypedefErrorEnum, MyTypedefErrorDomain) { 35 MyTypedefErrFirst, 36 MyTypedefErrSecond, 37}; 38 39typedef const struct __CFString * CFStringRef; 40 41extern CFStringRef const MyCFErrorDomain; 42typedef NS_ERROR_ENUM(unsigned char, MyCFErrorEnum, MyCFErrorDomain) { 43 MyCFErrFirst, 44 MyCFErrSecond, 45}; 46 47typedef CFStringRef CFErrorDomain; 48extern CFErrorDomain const MyCFTypedefErrorDomain; 49typedef NS_ERROR_ENUM(unsigned char, MyCFTypedefErrorEnum, MyCFTypedefErrorDomain) { 50 MyCFTypedefErrFirst, 51 MyCFTypedefErrSecond, 52}; 53 54extern char *const WrongErrorDomainType; 55enum __attribute__((ns_error_domain(WrongErrorDomainType))) MyWrongErrorDomainType { MyWrongErrorDomain }; 56// expected-error@-1{{domain argument 'WrongErrorDomainType' does not point to an NSString or CFString constant}} 57 58struct __attribute__((ns_error_domain(MyErrorDomain))) MyStructWithErrorDomain {}; 59// expected-error@-1{{'ns_error_domain' attribute only applies to enums}} 60 61int __attribute__((ns_error_domain(MyErrorDomain))) NotTagDecl; 62 // expected-error@-1{{'ns_error_domain' attribute only applies to enums}} 63 64enum __attribute__((ns_error_domain())) NoArg { NoArgError }; 65// expected-error@-1{{'ns_error_domain' attribute takes one argument}} 66 67enum __attribute__((ns_error_domain(MyErrorDomain, MyErrorDomain))) TwoArgs { TwoArgsError }; 68// expected-error@-1{{'ns_error_domain' attribute takes one argument}} 69 70typedef NS_ERROR_ENUM(unsigned char, MyErrorEnumInvalid, InvalidDomain) { 71 // expected-error@-1{{use of undeclared identifier 'InvalidDomain'}} 72 MyErrFirstInvalid, 73 MyErrSecondInvalid, 74}; 75 76typedef NS_ERROR_ENUM(unsigned char, MyErrorEnumInvalid, "domain-string"); 77 // expected-error@-1{{domain argument does not refer to global constant}} 78 79void foo() {} 80typedef NS_ERROR_ENUM(unsigned char, MyErrorEnumInvalidFunction, foo); 81 // expected-error@-1{{domain argument 'foo' does not refer to global constant}} 82