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