| Ted Kremenek | 28eace6 | 2013-11-23 01:01:34 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -verify %s -Wno-objc-root-class |
| 2 | |
| Ted Kremenek | f41cf7f1 | 2013-12-10 19:43:48 +0000 | [diff] [blame^] | 3 | // Mark this protocol as requiring all of its methods and properties |
| 4 | // to be explicitly implemented in the adopting class. |
| 5 | __attribute__((objc_protocol_requires_explicit_implementation)) |
| Ted Kremenek | 28eace6 | 2013-11-23 01:01:34 +0000 | [diff] [blame] | 6 | @protocol Protocol |
| 7 | - (void) theBestOfTimes; // expected-note {{method 'theBestOfTimes' declared here}} |
| Ted Kremenek | f41cf7f1 | 2013-12-10 19:43:48 +0000 | [diff] [blame^] | 8 | @property (readonly) id theWorstOfTimes; |
| Ted Kremenek | 28eace6 | 2013-11-23 01:01:34 +0000 | [diff] [blame] | 9 | @end |
| 10 | |
| Ted Kremenek | f41cf7f1 | 2013-12-10 19:43:48 +0000 | [diff] [blame^] | 11 | // In this example, ClassA adopts the protocol. We won't |
| 12 | // provide the implementation here, but this protocol will |
| 13 | // be adopted later by a subclass. |
| Ted Kremenek | 28eace6 | 2013-11-23 01:01:34 +0000 | [diff] [blame] | 14 | @interface ClassA <Protocol> |
| 15 | - (void) theBestOfTimes; |
| Ted Kremenek | 28eace6 | 2013-11-23 01:01:34 +0000 | [diff] [blame] | 16 | @property (readonly) id theWorstOfTimes; |
| 17 | @end |
| 18 | |
| Ted Kremenek | f41cf7f1 | 2013-12-10 19:43:48 +0000 | [diff] [blame^] | 19 | // This class subclasses ClassA (which adopts 'Protocol'), |
| 20 | // but does not provide the needed implementation. |
| 21 | @interface ClassB : ClassA <Protocol> // expected-note {{required for direct or indirect protocol 'Protocol'}} |
| Ted Kremenek | 28eace6 | 2013-11-23 01:01:34 +0000 | [diff] [blame] | 22 | @end |
| 23 | |
| Ted Kremenek | f41cf7f1 | 2013-12-10 19:43:48 +0000 | [diff] [blame^] | 24 | @implementation ClassB // expected-warning {{method 'theBestOfTimes' in protocol not implemented}} |
| Ted Kremenek | 28eace6 | 2013-11-23 01:01:34 +0000 | [diff] [blame] | 25 | @end |
| 26 | |
| Ted Kremenek | f41cf7f1 | 2013-12-10 19:43:48 +0000 | [diff] [blame^] | 27 | // Test that the attribute is used correctly. |
| 28 | __attribute__((objc_protocol_requires_explicit_implementation(1+2))) // expected-error {{attribute takes no arguments}} |
| 29 | @protocol AnotherProtocol @end |
| Ted Kremenek | 28eace6 | 2013-11-23 01:01:34 +0000 | [diff] [blame] | 30 | |
| Ted Kremenek | f41cf7f1 | 2013-12-10 19:43:48 +0000 | [diff] [blame^] | 31 | // Cannot put the attribute on classes or other non-protocol declarations. |
| 32 | __attribute__((objc_protocol_requires_explicit_implementation)) // expected-error {{attribute only applies to Objective-C protocols}} |
| 33 | @interface AnotherClass @end |
| Ted Kremenek | 28eace6 | 2013-11-23 01:01:34 +0000 | [diff] [blame] | 34 | |
| Ted Kremenek | f41cf7f1 | 2013-12-10 19:43:48 +0000 | [diff] [blame^] | 35 | __attribute__((objc_protocol_requires_explicit_implementation)) // expected-error {{attribute only applies to Objective-C protocols}} |
| 36 | int x; |
| Ted Kremenek | 28eace6 | 2013-11-23 01:01:34 +0000 | [diff] [blame] | 37 | |