xref: /llvm-project/clang/test/SemaObjC/method-attributes.m (revision acfbe9e1f22886d82c503cd0c20dc0ef3bf9f12a)
1// RUN: %clang_cc1 -verify -fsyntax-only -Wno-objc-root-class %s
2
3@class NSString;
4
5@interface A
6-t1 __attribute__((noreturn));
7- (NSString *)stringByAppendingFormat:(NSString *)format, ... __attribute__((format(__NSString__, 1, 2)));
8-(void) m0 __attribute__((noreturn));
9-(void) m1 __attribute__((unused));
10@end
11
12
13@interface INTF
14- (int) foo1: (int)arg1 __attribute__((deprecated));
15
16- (int) foo: (int)arg1;  // expected-note {{method 'foo:' declared here}}
17
18- (int) foo2: (int)arg1 __attribute__((deprecated)) __attribute__((unavailable)); // expected-note {{method 'foo2:' declared here}}
19- (int) foo3: (int)arg1 __attribute__((deprecated)) __attribute__((unavailable)) __attribute__((ns_consumes_self));
20@end
21
22@implementation INTF
23- (int) foo: (int)arg1  __attribute__((deprecated)){ // expected-warning {{attributes on method implementation and its declaration must match}}
24        return 10;
25}
26- (int) foo1: (int)arg1 {
27        return 10;
28}
29- (int) foo2: (int)arg1 __attribute__((deprecated)) {  // expected-warning {{attributes on method implementation and its declaration must match}}
30        return 10;
31}
32- (int) foo3: (int)arg1 __attribute__((deprecated)) __attribute__((unavailable)) __attribute__((ns_consumes_self)) {return 0; }
33- (void) dep __attribute__((deprecated)) { } // OK private methodn
34@end
35
36
37// rdar://10529259
38#define IBAction void)__attribute__((ibaction)
39
40@interface Foo
41- (void)doSomething1:(id)sender;
42- (void)doSomething2:(id)sender; // expected-note {{method 'doSomething2:' declared here}}
43@end
44
45@implementation Foo
46- (void)doSomething1:(id)sender{}
47- (void)doSomething2:(id)sender{}
48@end
49
50@interface Bar : Foo
51- (IBAction)doSomething1:(id)sender;
52@end
53@implementation Bar
54- (IBAction)doSomething1:(id)sender {}
55- (IBAction)doSomething2:(id)sender {} // expected-warning {{attributes on method implementation and its declaration must match}}
56- (IBAction)doSomething3:(id)sender {}
57@end
58