blob: 880819e407e9b16e430b00a3a793085c2eb357e7 [file] [log] [blame]
Ted Kremenek28eace62013-11-23 01:01:34 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -verify %s -Wno-objc-root-class
2
3@protocol Protocol
4- (void) theBestOfTimes; // expected-note {{method 'theBestOfTimes' declared here}}
5@property (readonly) id theWorstOfTimes; // expected-note {{property declared here}}
6@end
7
8// In this example, the root class provides all the methods for
9// a protocol, and the immediate subclass adopts the attribute.
10//
11// The further subclasses should not have access to the root class's
12// methods for checking protocol conformance.
13//
14// ClassC states protocol conformance, but does not redeclare the method.
15// For this case we get a warning.
16//
17// ClassD states protocol conformance, but does redeclare the method.
18// For this case we do not get a warning.
19//
20
21@interface ClassA <Protocol>
22- (void) theBestOfTimes;
23//@property (readonly) id theWorstOfTimes;
24@end
25
26__attribute__((objc_suppress_protocol_methods(Protocol))) @interface ClassB : ClassA @end
27
28@interface ClassC : ClassB <Protocol> @end // expected-note {{required for direct or indirect protocol 'Protocol'}}
29
30@interface ClassD : ClassB <Protocol>
31- (void) theBestOfTimes;
32@property (readonly) id theWorstOfTimes;
33@end
34
35@implementation ClassA // expected-warning {{auto property synthesis will not synthesize property declared in a protocol}}
36- (void) theBestOfTimes {}
37@end
38
39@implementation ClassC @end // expected-warning {{method 'theBestOfTimes' in protocol not implemented}}
40
41@implementation ClassD // no-warning
42- (void) theBestOfTimes {}
43@end
44
45// In this example, the class both conforms to the protocl and adopts
46// the attribute. This illustrates that the attribute does not
47// interfere with the protocol conformance checking for the class
48// itself.
49__attribute__((objc_suppress_protocol_methods(Protocol)))
50@interface AdoptsAndConforms <Protocol>
51- (void) theBestOfTimes;
52@property (readonly) id theWorstOfTimes;
53@end
54
55@implementation AdoptsAndConforms // no-warning
56- (void) theBestOfTimes {}
57@end
58
59// This attribute cannot be added to a class extension or category.
60@interface ClassE
61-(void) theBestOfTimes;
62@end
63
64__attribute__((objc_supress_protocol(Protocol)))
65@interface ClassE () @end // expected-error {{attributes may not be specified on a category}}
66
67__attribute__((objc_supress_protocol(Protocol)))
68@interface ClassE (MyCat) @end // expected-error {{attributes may not be specified on a category}}
69
70// The attribute requires one or more identifiers.
Ted Kremenek7559b472013-11-23 22:29:11 +000071__attribute__((objc_suppress_protocol_methods())) // expected-error {{'objc_suppress_protocol_methods' attribute takes one argument}}
72@interface ClassF @end
Ted Kremenek28eace62013-11-23 01:01:34 +000073
74// The attribute requires one or more identifiers.
75__attribute__((objc_suppress_protocol_methods(ProtoA, ProtoB))) // expected-error {{use of undeclared identifier 'ProtoB'}}
76@interface ClassG @end
77__attribute__((objc_suppress_protocol_methods(1+2)))
78@interface ClassH @end // expected-error {{parameter of 'objc_suppress_protocol_methods' attribute must be a single name of an Objective-C protocol}}
79