2013-11-23 09:01:34 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -verify %s -Wno-objc-root-class
|
|
|
|
|
2013-12-11 03:43:48 +08:00
|
|
|
// Mark this protocol as requiring all of its methods and properties
|
|
|
|
// to be explicitly implemented in the adopting class.
|
|
|
|
__attribute__((objc_protocol_requires_explicit_implementation))
|
2013-11-23 09:01:34 +08:00
|
|
|
@protocol Protocol
|
|
|
|
- (void) theBestOfTimes; // expected-note {{method 'theBestOfTimes' declared here}}
|
|
|
|
@property (readonly) id theWorstOfTimes;
|
|
|
|
@end
|
|
|
|
|
2013-12-11 03:43:48 +08:00
|
|
|
// In this example, ClassA adopts the protocol. We won't
|
|
|
|
// provide the implementation here, but this protocol will
|
|
|
|
// be adopted later by a subclass.
|
|
|
|
@interface ClassA <Protocol>
|
2013-11-23 09:01:34 +08:00
|
|
|
- (void) theBestOfTimes;
|
|
|
|
@property (readonly) id theWorstOfTimes;
|
|
|
|
@end
|
|
|
|
|
2013-12-11 03:43:48 +08:00
|
|
|
// This class subclasses ClassA (which adopts 'Protocol'),
|
|
|
|
// but does not provide the needed implementation.
|
|
|
|
@interface ClassB : ClassA <Protocol> // expected-note {{required for direct or indirect protocol 'Protocol'}}
|
2013-11-23 09:01:34 +08:00
|
|
|
@end
|
|
|
|
|
2013-12-11 03:43:48 +08:00
|
|
|
@implementation ClassB // expected-warning {{method 'theBestOfTimes' in protocol not implemented}}
|
2013-11-23 09:01:34 +08:00
|
|
|
@end
|
|
|
|
|
2013-12-11 03:43:48 +08:00
|
|
|
// Test that the attribute is used correctly.
|
|
|
|
__attribute__((objc_protocol_requires_explicit_implementation(1+2))) // expected-error {{attribute takes no arguments}}
|
|
|
|
@protocol AnotherProtocol @end
|
2013-11-23 09:01:34 +08:00
|
|
|
|
2013-12-11 03:43:48 +08:00
|
|
|
// Cannot put the attribute on classes or other non-protocol declarations.
|
|
|
|
__attribute__((objc_protocol_requires_explicit_implementation)) // expected-error {{attribute only applies to Objective-C protocols}}
|
|
|
|
@interface AnotherClass @end
|
2013-11-23 09:01:34 +08:00
|
|
|
|
2013-12-11 03:43:48 +08:00
|
|
|
__attribute__((objc_protocol_requires_explicit_implementation)) // expected-error {{attribute only applies to Objective-C protocols}}
|
|
|
|
int x;
|
2013-11-23 09:01:34 +08:00
|
|
|
|