diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2015-01-18 16:23:48 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2015-01-18 16:23:48 +0000 |
| commit | 06d4ba388873e6d1cfa9cd715a8935ecc8cd2097 (patch) | |
| tree | 3eb853da77d46cc77c4b017525a422f9ddb1385b /test/SemaObjC | |
| parent | 30d791273d07fac9c0c1641a0731191bca6e8606 (diff) | |
Diffstat (limited to 'test/SemaObjC')
35 files changed, 724 insertions, 86 deletions
diff --git a/test/SemaObjC/access-property-getter.m b/test/SemaObjC/access-property-getter.m index afaf82e73106..41827bb3c8a4 100644 --- a/test/SemaObjC/access-property-getter.m +++ b/test/SemaObjC/access-property-getter.m @@ -34,3 +34,20 @@ return 0; } @end + +// rdar://19137815 +#pragma clang diagnostic ignored "-Wunused-getter-return-value" + +@interface NSObject @end + +@interface I : NSObject +@property (copy) id window; +@end + +@implementation I +- (void) Meth { + [self window]; + self.window; +} +@end + diff --git a/test/SemaObjC/arc-jump-block.m b/test/SemaObjC/arc-jump-block.m index 9b06c5a780cc..418d296452b4 100644 --- a/test/SemaObjC/arc-jump-block.m +++ b/test/SemaObjC/arc-jump-block.m @@ -21,15 +21,15 @@ extern __attribute__((visibility("default"))) struct dispatch_queue_s _dispatch_ case 0: dispatch_async((&_dispatch_main_q), ^{ [self pageLeft]; }); // expected-note 3 {{jump enters lifetime of block which strongly captures a variable}} break; - case 2: // expected-error {{switch case is in protected scope}} + case 2: // expected-error {{cannot jump}} dispatch_async((&_dispatch_main_q), ^{ [self pageRight]; }); // expected-note 2 {{jump enters lifetime of block which strongly captures a variable}} break; - case 3: // expected-error {{switch case is in protected scope}} + case 3: // expected-error {{cannot jump}} { dispatch_async((&_dispatch_main_q), ^{ [self pageRight]; }); break; } - case 4: // expected-error {{switch case is in protected scope}} + case 4: // expected-error {{cannot jump}} break; } @@ -90,7 +90,7 @@ int test2(id obj, int state) { // expected-note {{jump enters lifetime of block} (void) ^{ (void) obj; }; return 0; - default: // expected-error {{switch case is in protected scope}} + default: // expected-error {{cannot jump}} return 1; } } diff --git a/test/SemaObjC/arc-repeated-weak.mm b/test/SemaObjC/arc-repeated-weak.mm index 64df92a9afa9..264c598942ae 100644 --- a/test/SemaObjC/arc-repeated-weak.mm +++ b/test/SemaObjC/arc-repeated-weak.mm @@ -425,3 +425,17 @@ void doubleLevelAccessIvar(Test *a, Test *b) { } @end +// rdar://19053620 +@interface NSNull ++ (NSNull *)null; +@end + +@interface INTF @end + +@implementation INTF +- (void) Meth : (id) data +{ + data = data ?: NSNull.null; +} +@end + diff --git a/test/SemaObjC/arc.m b/test/SemaObjC/arc.m index ba7c09f4f9d7..54a7db7b11b1 100644 --- a/test/SemaObjC/arc.m +++ b/test/SemaObjC/arc.m @@ -129,7 +129,7 @@ void test6(unsigned cond) { ; id x; // expected-note {{jump bypasses initialization of retaining variable}} - case 1: // expected-error {{switch case is in protected scope}} + case 1: // expected-error {{cannot jump}} break; } } diff --git a/test/SemaObjC/attr-availability-1.m b/test/SemaObjC/attr-availability-1.m new file mode 100644 index 000000000000..063407adaeee --- /dev/null +++ b/test/SemaObjC/attr-availability-1.m @@ -0,0 +1,116 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin9.0.0 -fsyntax-only -verify %s +// RUN: %clang_cc1 -x objective-c++ -std=c++11 -triple x86_64-apple-darwin9.0.0 -fsyntax-only -verify %s +// RUN: %clang_cc1 -x objective-c++ -std=c++03 -triple x86_64-apple-darwin9.0.0 -fsyntax-only -verify %s +// rdar://18490958 + +@protocol P +- (void)proto_method __attribute__((availability(macosx,introduced=10_1,deprecated=10_2))); // expected-note 2 {{'proto_method' has been explicitly marked deprecated here}} +@end + +@interface A <P> +- (void)method __attribute__((availability(macosx,introduced=10_1,deprecated=10_2))); // expected-note {{'method' has been explicitly marked deprecated here}} + +- (void)overridden __attribute__((availability(macosx,introduced=10_3))); // expected-note{{overridden method is here}} +- (void)overridden2 __attribute__((availability(macosx,introduced=10_3))); +- (void)overridden3 __attribute__((availability(macosx,deprecated=10_3))); +- (void)overridden4 __attribute__((availability(macosx,deprecated=10_3))); // expected-note{{overridden method is here}} +- (void)overridden5 __attribute__((availability(macosx,unavailable))); +- (void)overridden6 __attribute__((availability(macosx,introduced=10_3))); // expected-note{{overridden method is here}} +@end + +// rdar://11475360 +@interface B : A +- (void)method; // NOTE: we expect 'method' to *not* inherit availability. +- (void)overridden __attribute__((availability(macosx,introduced=10_4))); // expected-warning{{overriding method introduced after overridden method on OS X (10_4 vs. 10_3)}} +- (void)overridden2 __attribute__((availability(macosx,introduced=10_2))); +- (void)overridden3 __attribute__((availability(macosx,deprecated=10_4))); +- (void)overridden4 __attribute__((availability(macosx,deprecated=10_2))); // expected-warning{{overriding method deprecated before overridden method on OS X (10_3 vs. 10_2)}} +- (void)overridden5 __attribute__((availability(macosx,introduced=10_3))); +- (void)overridden6 __attribute__((availability(macosx,unavailable))); // expected-warning{{overriding method cannot be unavailable on OS X when its overridden method is available}} +@end + +void f(A *a, B *b) { + [a method]; // expected-warning{{'method' is deprecated: first deprecated in OS X 10.2}} + [b method]; // no-warning + [a proto_method]; // expected-warning{{'proto_method' is deprecated: first deprecated in OS X 10.2}} + [b proto_method]; // expected-warning{{'proto_method' is deprecated: first deprecated in OS X 10.2}} +} + +// Test case for <rdar://problem/11627873>. Warn about +// using a deprecated method when that method is re-implemented in a +// subclass where the redeclared method is not deprecated. +@interface C +- (void) method __attribute__((availability(macosx,introduced=10_1,deprecated=10_2))); // expected-note {{'method' has been explicitly marked deprecated here}} +@end + +@interface D : C +- (void) method; +@end + +@interface E : D +- (void) method; +@end + +@implementation D +- (void) method { + [super method]; // expected-warning {{'method' is deprecated: first deprecated in OS X 10.2}} +} +@end + +@implementation E +- (void) method { + [super method]; // no-warning +} +@end + +// rdar://18059669 +@class NSMutableArray; + +@interface NSDictionary ++ (instancetype)dictionaryWithObjectsAndKeys:(id)firstObject, ... __attribute__((sentinel(0,1))); +@end + +@class NSString; + +extern NSString *NSNibTopLevelObjects __attribute__((availability(macosx,introduced=10_0 ,deprecated=10_8,message="" ))); +id NSNibOwner, topNibObjects; + +@interface AppDelegate (SIEImport) // expected-error {{cannot find interface declaration for 'AppDelegate'}} + +-(void)__attribute__((ibaction))importFromSIE:(id)sender; + +@end + +@implementation AppDelegate (SIEImport) // expected-error {{cannot find interface declaration for 'AppDelegate'}} + +-(void)__attribute__((ibaction))importFromSIE:(id)sender { + + NSMutableArray *topNibObjects; + NSDictionary *nibLoadDict = [NSDictionary dictionaryWithObjectsAndKeys:self, NSNibOwner, topNibObjects, NSNibTopLevelObjects, ((void *)0)]; +} + +@end + +@interface Mixed +- (void)Meth1 __attribute__((availability(macosx,introduced=10.3_0))); // expected-warning {{use same version number separators '_' or '.'}} +- (void)Meth2 __attribute__((availability(macosx,introduced=10_3.1))); // expected-warning {{use same version number separators '_' or '.'}} +@end + +// rdar://18804883 +@protocol P18804883 +- (void)proto_method __attribute__((availability(macosx,introduced=10_1,deprecated=NA))); // means nothing (not deprecated) +@end + +@interface A18804883 <P18804883> +- (void)interface_method __attribute__((availability(macosx,introduced=NA))); // expected-note {{'interface_method' has been explicitly marked unavailable here}} +- (void)strange_method __attribute__((availability(macosx,introduced=NA,deprecated=NA))); // expected-note {{'strange_method' has been explicitly marked unavailable here}} +- (void) always_available __attribute__((availability(macosx,deprecated=NA))); +@end + +void foo (A18804883* pa) { + [pa interface_method]; // expected-error {{'interface_method' is unavailable: not available on OS X}} + [pa proto_method]; + [pa strange_method]; // expected-error {{'strange_method' is unavailable: not available on OS X}} + [pa always_available]; +} + diff --git a/test/SemaObjC/attr-availability.m b/test/SemaObjC/attr-availability.m index 7990b1202e8f..c455bc7acce6 100644 --- a/test/SemaObjC/attr-availability.m +++ b/test/SemaObjC/attr-availability.m @@ -60,3 +60,30 @@ void f(A *a, B *b) { } @end +// rdar://18059669 +@class NSMutableArray; + +@interface NSDictionary ++ (instancetype)dictionaryWithObjectsAndKeys:(id)firstObject, ... __attribute__((sentinel(0,1))); +@end + +@class NSString; + +extern NSString *NSNibTopLevelObjects __attribute__((availability(macosx,introduced=10.0 ,deprecated=10.8,message="" ))); +id NSNibOwner, topNibObjects; + +@interface AppDelegate (SIEImport) // expected-error {{cannot find interface declaration for 'AppDelegate'}} + +-(void)__attribute__((ibaction))importFromSIE:(id)sender; + +@end + +@implementation AppDelegate (SIEImport) // expected-error {{cannot find interface declaration for 'AppDelegate'}} + +-(void)__attribute__((ibaction))importFromSIE:(id)sender { + + NSMutableArray *topNibObjects; + NSDictionary *nibLoadDict = [NSDictionary dictionaryWithObjectsAndKeys:self, NSNibOwner, topNibObjects, NSNibTopLevelObjects, ((void *)0)]; +} + +@end diff --git a/test/SemaObjC/attr-deprecated-pch.m b/test/SemaObjC/attr-deprecated-pch.m new file mode 100644 index 000000000000..2b48aea379a0 --- /dev/null +++ b/test/SemaObjC/attr-deprecated-pch.m @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -fsyntax-only -DBOTH -verify %s +// If the decls come from a pch, the behavior shouldn't change: +// RUN: %clang_cc1 -x objective-c-header %s -emit-pch -o %t +// RUN: %clang_cc1 -DUSES -include-pch %t -fsyntax-only -verify %s +// expected-no-diagnostics + +// The slightly strange ifdefs are so that the command that builds the gch file +// doesn't need any -D switches, for these would get embedded in the gch. + +#ifndef USES +@interface Interface1 +- (void)partiallyUnavailableMethod; +@end +@interface Interface2 +- (void)partiallyUnavailableMethod __attribute__((unavailable)); +@end +#endif + +#if defined(USES) || defined(BOTH) +void f(id a) { + [a partiallyUnavailableMethod]; // no warning, `a` could be an Interface1. +} +#endif diff --git a/test/SemaObjC/attr-deprecated.m b/test/SemaObjC/attr-deprecated.m index ca30d0a27d88..13ba68db58e6 100644 --- a/test/SemaObjC/attr-deprecated.m +++ b/test/SemaObjC/attr-deprecated.m @@ -1,11 +1,11 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s -// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin10.4 -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -triple x86_64-apple-darwin10.4 -verify -Wno-objc-root-class %s @interface A { int X __attribute__((deprecated)); // expected-note 2 {{'X' has been explicitly marked deprecated here}} } + (void)F __attribute__((deprecated)); // expected-note 2 {{'F' has been explicitly marked deprecated here}} -- (void)f __attribute__((deprecated)); // expected-note 4 {{'f' has been explicitly marked deprecated here}} +- (void)f __attribute__((deprecated)); // expected-note 5 {{'f' has been explicitly marked deprecated here}} @end @implementation A @@ -54,7 +54,7 @@ void t1(A *a) void t2(id a) { - [a f]; + [a f]; // expected-warning {{'f' is deprecated}} } void t3(A<P>* a) @@ -197,18 +197,19 @@ __attribute__((deprecated)) @interface TestBase @property (nonatomic, strong) id object __attribute__((deprecated("deprecated"))); // expected-note {{'object' has been explicitly marked deprecated here}} \ expected-note {{property 'object' is declared deprecated here}} \ -expected-note {{'setObject:' has been explicitly marked deprecated here}} +expected-note {{'setObject:' has been explicitly marked deprecated here}} \ +expected-note {{property declared here}} @end @interface TestDerived : TestBase -@property (nonatomic, strong) id object; +@property (nonatomic, strong) id object; //expected-warning {{auto property synthesis will not synthesize property 'object'; it will be implemented by its superclass}} @end @interface TestUse @end @implementation TestBase @end -@implementation TestDerived @end +@implementation TestDerived @end // expected-note {{detected while default synthesizing properties in class implementation}} @implementation TestUse @@ -227,3 +228,59 @@ expected-note {{'setObject:' has been explicitly marked deprecated here}} @end +// rdar://18848183 +@interface NSString +- (const char *)cString __attribute__((availability(macosx,introduced=10.0 ,deprecated=10.4,message="" ))); // expected-note {{'cString' has been explicitly marked deprecated here}} +@end + +id PID = 0; +const char * func() { + return [PID cString]; // expected-warning {{'cString' is deprecated: first deprecated in OS X 10.4}} +} + +// rdar://18960378 +@interface NSObject ++ (instancetype)alloc; +- (instancetype)init; +@end + +@interface NSLocale +- (instancetype)init __attribute__((unavailable)); +@end + +@interface PLBatteryProperties : NSObject ++ (id)properties; +@end + +@implementation PLBatteryProperties ++ (id)properties { + return [[self alloc] init]; +} +@end + +@implementation UndeclaredImpl // expected-warning{{cannot find interface declaration}} +- (void)partiallyUnavailableMethod {} +@end + +@interface InterfaceWithSameMethodAsUndeclaredImpl +- (void)partiallyUnavailableMethod __attribute__((unavailable)); +@end + +void f(id a) { + [a partiallyUnavailableMethod]; // no warning, `a` could be an UndeclaredImpl. +} + +@interface InterfaceWithImplementation +- (void)anotherPartiallyUnavailableMethod; +@end +@implementation InterfaceWithImplementation +- (void)anotherPartiallyUnavailableMethod {} +@end + +@interface InterfaceWithSameMethodAsInterfaceWithImplementation +- (void)anotherPartiallyUnavailableMethod __attribute__((unavailable)); +@end + +void g(id a) { + [a anotherPartiallyUnavailableMethod]; // no warning, `a` could be an InterfaceWithImplementation. +} diff --git a/test/SemaObjC/autoreleasepool.m b/test/SemaObjC/autoreleasepool.m index 45c749e570c1..c88f1bacca63 100644 --- a/test/SemaObjC/autoreleasepool.m +++ b/test/SemaObjC/autoreleasepool.m @@ -7,7 +7,7 @@ void autoreleasepool_pop(void*); @implementation AUTORP - (void) unregisterTask:(id) task { - goto L; // expected-error {{goto into protected scope}} + goto L; // expected-error {{cannot jump}} @autoreleasepool { // expected-note {{jump bypasses auto release push of @autoreleasepool block}} void *tmp = objc_autoreleasepool_push(); diff --git a/test/SemaObjC/compare-qualified-class.m b/test/SemaObjC/compare-qualified-class.m index 60ef851e1f3f..a52561521444 100644 --- a/test/SemaObjC/compare-qualified-class.m +++ b/test/SemaObjC/compare-qualified-class.m @@ -28,3 +28,38 @@ int main () { classA == classD; // expected-warning {{comparison of distinct pointer types ('Class<SomeProtocol>' and 'Class<SomeProtocol1>')}} } +// rdar://18491222 +@protocol NSObject @end + +@interface NSObject @end +@protocol ProtocolX <NSObject> +@end + +@protocol ProtocolY <NSObject> +@end + +@interface ClassA : NSObject +@end + +@interface ClassB : ClassA <ProtocolY, ProtocolX> +@end + +@interface OtherClass : NSObject +@property (nonatomic, copy) ClassB<ProtocolX> *aProperty; +- (ClassA<ProtocolY> *)aMethod; +- (ClassA<ProtocolY> *)anotherMethod; +@end + +@implementation OtherClass +- (ClassA<ProtocolY> *)aMethod { + // This does not work, even though ClassB subclasses from A and conforms to Y + // because the property type explicity adds ProtocolX conformance + // even though ClassB already conforms to ProtocolX + return self.aProperty; +} +- (ClassA<ProtocolY> *)anotherMethod { + // This works, even though all it is doing is removing an explicit + // protocol conformance that ClassB already conforms to + return (ClassB *)self.aProperty; +} +@end diff --git a/test/SemaObjC/conditional-expr.m b/test/SemaObjC/conditional-expr.m index d8862c584a0d..71e108cce673 100644 --- a/test/SemaObjC/conditional-expr.m +++ b/test/SemaObjC/conditional-expr.m @@ -101,10 +101,10 @@ int f8(int a, A<P0> *x, A *y) { } void f9(int a, A<P0> *x, A<P1> *y) { - id l0 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}} - A<P0> *l1 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}} - A<P1> *l2 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}} - [ (a ? x : y ) intProp ]; // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}} + id l0 = (a ? x : y ); // Ok. y is of A<P1> object type and A is qualified by P0. + A<P0> *l1 = (a ? x : y ); // Ok. y is of A<P1> object type and A is qualified by P0. + A<P1> *l2 = (a ? x : y ); // expected-warning {{incompatible pointer types initializing 'A<P1> *' with an expression of type 'A<P0> *'}} + (void)[ (a ? x : y ) intProp ]; // Ok. Common type is A<P0> * and P0's property intProp is accessed. } void f10(int a, id<P0> x, id y) { @@ -116,5 +116,5 @@ void f11(int a, id<P0> x, id<P1> y) { } void f12(int a, A<P0> *x, A<P1> *y) { - A<P1>* l0 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}} + A<P1>* l0 = (a ? x : y ); // expected-warning {{incompatible pointer types initializing 'A<P1> *' with an expression of type 'A<P0> *'}} } diff --git a/test/SemaObjC/debugger-support.m b/test/SemaObjC/debugger-support.m index 21c096edad43..5dbc3eebfa2c 100644 --- a/test/SemaObjC/debugger-support.m +++ b/test/SemaObjC/debugger-support.m @@ -9,6 +9,6 @@ void test0(id x) { // CHECK-NEXT: [[RESULT:%.*]] = alloca [[A:%.*]], align 4 // CHECK-NEXT: store i8* {{%.*}}, i8** [[X]], // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]], - // CHECK-NEXT: [[T1:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_" + // CHECK-NEXT: [[T1:%.*]] = load i8** @OBJC_SELECTOR_REFERENCES_ // CHECK-NEXT: [[T2:%.*]] = call { i64, i64 } bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to { i64, i64 } (i8*, i8*)*)(i8* [[T0]], i8* [[T1]]) } diff --git a/test/SemaObjC/default-synthesize-1.m b/test/SemaObjC/default-synthesize-1.m index f9f2e72eaf94..731aa863e103 100644 --- a/test/SemaObjC/default-synthesize-1.m +++ b/test/SemaObjC/default-synthesize-1.m @@ -124,3 +124,20 @@ // expected-note {{detected while default synthesizing properties in class implementation}} @synthesize x; // expected-error {{cannot synthesize property 'x' with incomplete type 'enum A'}} @end + +// rdar://17774815 +@interface ZXParsedResult +@property (nonatomic, copy, readonly) NSString *description; // expected-note {{property declared here}} +@end + +@interface ZXCalendarParsedResult : ZXParsedResult + +@property (nonatomic, copy, readonly) NSString *description; // expected-warning {{auto property synthesis will not synthesize property 'description'; it will be implemented by its superclass}} + +@end + +@implementation ZXCalendarParsedResult // expected-note {{detected while default synthesizing properties in class implementation}} +- (NSString *) Meth { + return _description; // expected-error {{use of undeclared identifier '_description'}} +} +@end diff --git a/test/SemaObjC/default-synthesize-3.m b/test/SemaObjC/default-synthesize-3.m index c91597462d91..dce9edabb90d 100644 --- a/test/SemaObjC/default-synthesize-3.m +++ b/test/SemaObjC/default-synthesize-3.m @@ -44,7 +44,7 @@ __attribute ((objc_requires_property_definitions)) // expected-error {{'objc_req @interface NSObject @end @protocol Foo @property (readonly) char isFoo; // expected-note {{property declared here}} -@property (readonly) char isNotFree; +@property (readonly) char isNotFree; // expected-note {{property declared here}} @end @interface Bar : NSObject <Foo> @@ -66,10 +66,10 @@ __attribute ((objc_requires_property_definitions)) // expected-error {{'objc_req @property (readwrite) char isFoo; // expected-warning {{auto property synthesis will not synthesize property 'isFoo' because it is 'readwrite' but it will be synthesized 'readonly' via another property}} @property char Property1; // expected-warning {{auto property synthesis will not synthesize property 'Property1' because it cannot share an ivar with another synthesized property}} @property char Property2; -@property (readwrite) char isNotFree; +@property (readwrite) char isNotFree; // expected-warning {{auto property synthesis will not synthesize property 'isNotFree'}} @end -@implementation Baz { +@implementation Baz { // expected-note {{detected while default synthesizing properties in class implementation}} char _isFoo; char _isNotFree; } @@ -90,9 +90,9 @@ __attribute ((objc_requires_property_definitions)) // expected-error {{'objc_req @end @interface B -@property (readonly) id prop; -@property (readonly) id prop1; -@property (readonly) id prop2; +@property (readonly) id prop; // expected-note {{property declared here}} +@property (readonly) id prop1; // expected-note {{property declared here}} +@property (readonly) id prop2; // expected-note {{property declared here}} @end @interface B() @@ -104,12 +104,12 @@ __attribute ((objc_requires_property_definitions)) // expected-error {{'objc_req @end @interface S : B<P1> -@property (assign,readwrite) id prop; -@property (assign,readwrite) id prop1; -@property (assign,readwrite) id prop2; +@property (assign,readwrite) id prop; // expected-warning {{auto property synthesis will not synthesize property 'prop'}} +@property (assign,readwrite) id prop1; // expected-warning {{auto property synthesis will not synthesize property 'prop1'}} +@property (assign,readwrite) id prop2; // expected-warning {{auto property synthesis will not synthesize property 'prop2'}} @end -@implementation S +@implementation S // expected-note 3 {{detected while default synthesizing properties in class implementation}} @end // rdar://14085456 diff --git a/test/SemaObjC/default-synthesize.m b/test/SemaObjC/default-synthesize.m index 9356b9f5b3a3..3f0ae0261daf 100644 --- a/test/SemaObjC/default-synthesize.m +++ b/test/SemaObjC/default-synthesize.m @@ -97,10 +97,10 @@ } @end -@interface SubClass : TopClass <TopProtocol> +@interface SubClass : TopClass <TopProtocol> @end -@implementation SubClass @end +@implementation SubClass @end // rdar://7920807 @interface C @end @@ -138,3 +138,39 @@ @implementation MyClass // expected-warning {{auto property synthesis will not synthesize property 'requiredString' declared in protocol 'MyProtocol'}} @end + +// rdar://18152478 +@protocol NSObject @end +@protocol TMSourceManagerDelegate<NSObject> +@end + +@protocol TMSourceManager <NSObject> +@property (nonatomic, assign) id <TMSourceManagerDelegate> delegate; +@end + +@interface TMSourceManager +@property (nonatomic, assign) id <TMSourceManagerDelegate> delegate; +@end + +@protocol TMTimeZoneManager <TMSourceManager> +@end + +@interface TimeZoneManager : TMSourceManager <TMTimeZoneManager> +@end + +@implementation TimeZoneManager +@end + +// rdar://18179833 +@protocol BaseProt +@property (assign) id prot; +@end + +@interface Base<BaseProt> +@end + +@interface I : Base<BaseProt> +@end + +@implementation I +@end diff --git a/test/SemaObjC/encode-typeof-test.m b/test/SemaObjC/encode-typeof-test.m index 2cda9739681b..fe8f29c3b972 100644 --- a/test/SemaObjC/encode-typeof-test.m +++ b/test/SemaObjC/encode-typeof-test.m @@ -24,3 +24,22 @@ int main() int i; typeof(@encode(typeof(i))) e = @encode(typeof(Intf)); // expected-warning {{initializer-string for char array is too long}} } + +// rdar://9255564 +typedef short short8 __attribute__((ext_vector_type(8))); + +struct foo { + char a; + int b; + long c; + short8 d; + int array[4]; + short int bitfield1:5; + unsigned short bitfield2:11; + char *string; +}; + +const char *RetEncode () { + return @encode(struct foo); // expected-warning {{encoding of 'struct foo' type is incomplete because 'short8' (vector of 8 'short' values) component has unknown encoding}} +} + diff --git a/test/SemaObjC/format-cstrings-warning.m b/test/SemaObjC/format-cstrings-warning.m new file mode 100644 index 000000000000..28fa7ce0dcd8 --- /dev/null +++ b/test/SemaObjC/format-cstrings-warning.m @@ -0,0 +1,79 @@ +// RUN: %clang_cc1 -Wcstring-format-directive -verify -fsyntax-only %s +// rdar://18182443 + +typedef __builtin_va_list __darwin_va_list; +typedef __builtin_va_list va_list; + +@interface NSString +@end + +va_list argList; + +@interface NSString (NSStringExtensionMethods) +- (NSString *)stringByAppendingFormat:(NSString *)format, ... __attribute__((format(__NSString__, 1, 2))); +- (instancetype)initWithFormat:(NSString *)format, ... __attribute__((format(__NSString__, 1, 2))); // expected-note 2 {{method 'initWithFormat:' declared here}} +- (instancetype)initWithFormat:(NSString *)format arguments:(va_list)argList __attribute__((format(__NSString__, 1, 0))); +- (instancetype)initWithFormat:(NSString *)format locale:(id)locale, ... __attribute__((format(__NSString__, 1, 3))); +- (instancetype)initWithFormat:(NSString *)format locale:(id)locale arguments:(va_list)argList __attribute__((format(__NSString__, 1, 0))); ++ (instancetype)stringWithFormat:(NSString *)format, ... __attribute__((format(__NSString__, 1, 2))); // expected-note {{method 'stringWithFormat:' declared here}} ++ (instancetype)localizedStringWithFormat:(NSString *)format, ... __attribute__((format(__NSString__, 1, 2))); // expected-note {{method 'localizedStringWithFormat:' declared here}} +- (void)MyRandomMethod:(NSString *)format locale:(id)locale arguments:(va_list)argList __attribute__((format(__NSString__, 1, 0))); // expected-note {{method 'MyRandomMethod:locale:arguments:' declared here}} +@end + +@interface NSMutableString : NSString +@end + +@interface NSMutableString (NSMutableStringExtensionMethods) + +- (void)appendFormat:(NSString *)format, ... __attribute__((format(__NSString__, 1, 2))); + +@end + +NSString *ns(NSString *pns) { + [pns initWithFormat: @"Number %d length %c name %s", 1, 'a', "something"]; // expected-warning {{using %s directive in NSString which is being passed as a formatting argument to the formatting method}} + [NSString localizedStringWithFormat : @"Hello%s", " There"]; // expected-warning {{using %s directive in NSString which is being passed as a formatting argument to the formatting method}} + [pns initWithFormat : @"Hello%s %d %d", "Hello", 1, 2]; // expected-warning {{using %s directive in NSString which is being passed as a formatting argument to the formatting method}} + [pns MyRandomMethod : @"Hello%s %d %d" locale:0 arguments: argList]; // expected-warning {{using %s directive in NSString which is being passed as a formatting argument to the formatting method}} + return [NSString stringWithFormat : @"Hello%s", " There"]; // expected-warning {{using %s directive in NSString which is being passed as a formatting argument to the formatting method}} +} + + +typedef const struct __CFString * CFStringRef; +typedef struct __CFString * CFMutableStringRef; +typedef const struct __CFAllocator * CFAllocatorRef; + + +typedef const struct __CFDictionary * CFDictionaryRef; + + +extern +CFStringRef CFStringCreateWithFormat(CFAllocatorRef alloc, CFDictionaryRef formatOptions, CFStringRef format, ...) __attribute__((format(CFString, 3, 4))); + +extern +CFStringRef CFStringCreateWithFormatAndArguments(CFAllocatorRef alloc, CFDictionaryRef formatOptions, CFStringRef format, va_list arguments) __attribute__((format(CFString, 3, 0))); // expected-note {{'CFStringCreateWithFormatAndArguments' declared here}} + +extern +void CFStringAppendFormat(CFMutableStringRef theString, CFDictionaryRef formatOptions, CFStringRef format, ...) __attribute__((format(CFString, 3, 4))); + +extern +void CFStringAppendFormatAndArguments(CFMutableStringRef theString, CFDictionaryRef formatOptions, CFStringRef format, va_list arguments) __attribute__((format(CFString, 3, 0))); // expected-note {{'CFStringAppendFormatAndArguments' declared here}} + +void Test1(va_list argList) { + CFAllocatorRef alloc; + CFStringCreateWithFormatAndArguments (alloc, 0, (CFStringRef)@"%s\n", argList); // expected-warning {{using %s directive in CFString which is being passed as a formatting argument to the formatting CFfunction}} + CFStringAppendFormatAndArguments ((CFMutableStringRef)@"AAAA", 0, (CFStringRef)"Hello %s there %d\n", argList); // expected-warning {{using %s directive in CFString which is being passed as a formatting argument to the formatting CFfunction}} + CFStringCreateWithFormatAndArguments (alloc, 0, (CFStringRef)@"%c\n", argList); + CFStringAppendFormatAndArguments ((CFMutableStringRef)@"AAAA", 0, (CFStringRef)"%d\n", argList); +} + +extern void MyNSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2))); // expected-note {{'MyNSLog' declared here}} +extern void MyCFStringCreateWithFormat(CFStringRef format, ...) __attribute__((format(__CFString__, 1, 2))); // expected-note {{'MyCFStringCreateWithFormat' declared here}} +extern void XMyNSLog(int, NSString *format, ...) __attribute__((format(__NSString__, 2, 3))); // expected-note {{'XMyNSLog' declared here}} + +void Test2() { + MyNSLog(@"%s\n", "Hello"); // expected-warning {{using %s directive in CFString which is being passed as a formatting argument to the formatting CFfunction}} + + MyCFStringCreateWithFormat((CFStringRef)@"%s", "Hello"); // expected-warning {{using %s directive in CFString which is being passed as a formatting argument to the formatting CFfunction}} + XMyNSLog(4, @"%s\n", "Hello"); // expected-warning {{using %s directive in CFString which is being passed as a formatting argument to the formatting CFfunction}} +} + diff --git a/test/SemaObjC/format-strings-objc.m b/test/SemaObjC/format-strings-objc.m index 49567a710c3a..f4c528cc7ac0 100644 --- a/test/SemaObjC/format-strings-objc.m +++ b/test/SemaObjC/format-strings-objc.m @@ -243,7 +243,7 @@ void testByValueObjectInFormat(Foo *obj) { // <rdar://problem/13557053> void testTypeOf(NSInteger dW, NSInteger dH) { - NSLog(@"dW %d dH %d",({ __typeof__(dW) __a = (dW); __a < 0 ? -__a : __a; }),({ __typeof__(dH) __a = (dH); __a < 0 ? -__a : __a; })); // expected-warning 2 {{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}} + NSLog(@"dW %d dH %d",({ __typeof__(dW) __a = (dW); __a < 0 ? -__a : __a; }),({ __typeof__(dH) __a = (dH); __a < 0 ? -__a : __a; })); // expected-warning 2 {{format specifies type 'int' but the argument has type 'long'}} } void testUnicode() { diff --git a/test/SemaObjC/iboutlet.m b/test/SemaObjC/iboutlet.m index 63eac9af8a52..7d656a51684a 100644 --- a/test/SemaObjC/iboutlet.m +++ b/test/SemaObjC/iboutlet.m @@ -6,12 +6,10 @@ @class NSView; -#define IBOutlet __attribute__((iboutlet)) - -@interface I +IB_DESIGNABLE @interface I @property (getter = MyGetter, readonly, assign) IBOutlet NSView *myView; // expected-warning {{readonly IBOutlet property 'myView' when auto-synthesized may not work correctly with 'nib' loader}} expected-note {{property should be changed to be readwrite}} -@property (readonly) IBOutlet NSView *myView1; // expected-warning {{readonly IBOutlet property 'myView1' when auto-synthesized may not work correctly with 'nib' loader}} expected-note {{property should be changed to be readwrite}} +IBInspectable @property (readonly) IBOutlet NSView *myView1; // expected-warning {{readonly IBOutlet property 'myView1' when auto-synthesized may not work correctly with 'nib' loader}} expected-note {{property should be changed to be readwrite}} @property (getter = MyGetter, READONLY) IBOutlet NSView *myView2; // expected-warning {{readonly IBOutlet property 'myView2' when auto-synthesized may not work correctly with 'nib' loader}} diff --git a/test/SemaObjC/ivar-lookup.m b/test/SemaObjC/ivar-lookup.m index 938c8eb189a5..57f432c717a1 100644 --- a/test/SemaObjC/ivar-lookup.m +++ b/test/SemaObjC/ivar-lookup.m @@ -99,9 +99,9 @@ extern struct foo x; }; struct S { __typeof(myStatus) __in; // fails. - struct S1 { + struct S1 { // expected-warning {{declaration does not declare anything}} __typeof(myStatus) __in; // fails. - struct S { + struct S { // expected-warning {{declaration does not declare anything}} __typeof(myStatus) __in; // fails. }; }; diff --git a/test/SemaObjC/method-lookup-3.m b/test/SemaObjC/method-lookup-3.m index b3d9c46484c3..ff2c4898a411 100644 --- a/test/SemaObjC/method-lookup-3.m +++ b/test/SemaObjC/method-lookup-3.m @@ -71,3 +71,29 @@ struct test4b { float x, y; }; void test4(id x) { (void) [x test4]; //expected-warning {{multiple methods named 'test4' found}} } + +// rdar://19265296 +#pragma clang diagnostic ignored "-Wobjc-multiple-method-names" +@interface NSObject ++ (id)alloc; ++ (id)class; +- (id) init; +@end + +@class NSString; +@interface A : NSObject +- (instancetype)initWithType:(NSString *)whatever; +@end + +@interface Test : NSObject @end + +@implementation Test ++ (instancetype)foo +{ + return [[[self class] alloc] initWithType:3]; +} +- (instancetype)initWithType:(int)whatever +{ + return [super init]; +} +@end diff --git a/test/SemaObjC/nonnull.m b/test/SemaObjC/nonnull.m index a345eddbf1e4..cacca07240f6 100644 --- a/test/SemaObjC/nonnull.m +++ b/test/SemaObjC/nonnull.m @@ -31,16 +31,16 @@ foo (int i1, int i2, int i3, void (^cp1)(), void (^cp2)(), void (^cp3)()) { func1(cp1, cp2, i1); - func1(0, cp2, i1); // expected-warning {{null passed to a callee which requires a non-null argument}} - func1(cp1, 0, i1); // expected-warning {{null passed to a callee which requires a non-null argument}} + func1(0, cp2, i1); // expected-warning {{null passed to a callee that requires a non-null argument}} + func1(cp1, 0, i1); // expected-warning {{null passed to a callee that requires a non-null argument}} func1(cp1, cp2, 0); - func3(0, i2, cp3, i3); // expected-warning {{null passed to a callee which requires a non-null argument}} - func3(cp3, i2, 0, i3); // expected-warning {{null passed to a callee which requires a non-null argument}} + func3(0, i2, cp3, i3); // expected-warning {{null passed to a callee that requires a non-null argument}} + func3(cp3, i2, 0, i3); // expected-warning {{null passed to a callee that requires a non-null argument}} - func4(0, cp1); // expected-warning {{null passed to a callee which requires a non-null argument}} - func4(cp1, 0); // expected-warning {{null passed to a callee which requires a non-null argument}} + func4(0, cp1); // expected-warning {{null passed to a callee that requires a non-null argument}} + func4(cp1, 0); // expected-warning {{null passed to a callee that requires a non-null argument}} // Shouldn't these emit warnings? Clang doesn't, and neither does GCC. It // seems that the checking should handle Objective-C pointers. @@ -64,7 +64,7 @@ __attribute__((nonnull)) void _dispatch_queue_push_list(dispatch_object_t _head); // no warning void func6(dispatch_object_t _head) { - _dispatch_queue_push_list(0); // expected-warning {{null passed to a callee which requires a non-null argument}} + _dispatch_queue_push_list(0); // expected-warning {{null passed to a callee that requires a non-null argument}} _dispatch_queue_push_list(_head._do); // no warning } @@ -91,10 +91,10 @@ extern void DoSomethingNotNull(void *db) __attribute__((nonnull(1))); @implementation IMP - (void) Meth { NSObject *object; - [object doSomethingWithNonNullPointer:NULL:1:NULL]; // expected-warning 2 {{null passed to a callee which requires a non-null argument}} - [object doSomethingWithNonNullPointer:vp:1:NULL]; // expected-warning {{null passed to a callee which requires a non-null argument}} - [NSObject doSomethingClassyWithNonNullPointer:NULL]; // expected-warning {{null passed to a callee which requires a non-null argument}} - DoSomethingNotNull(NULL); // expected-warning {{null passed to a callee which requires a non-null argument}} + [object doSomethingWithNonNullPointer:NULL:1:NULL]; // expected-warning 2 {{null passed to a callee that requires a non-null argument}} + [object doSomethingWithNonNullPointer:vp:1:NULL]; // expected-warning {{null passed to a callee that requires a non-null argument}} + [NSObject doSomethingClassyWithNonNullPointer:NULL]; // expected-warning {{null passed to a callee that requires a non-null argument}} + DoSomethingNotNull(NULL); // expected-warning {{null passed to a callee that requires a non-null argument}} [object doSomethingWithNonNullPointer:vp:1:vp]; } - (void*) testRetNull { @@ -111,15 +111,15 @@ __attribute__((objc_root_class)) @end void test(TestNonNullParameters *f) { - [f doNotPassNullParameter:0]; // expected-warning {{null passed to a callee which requires a non-null argument}} + [f doNotPassNullParameter:0]; // expected-warning {{null passed to a callee that requires a non-null argument}} [f doNotPassNullParameterArgIndex:0]; // no-warning - [f doNotPassNullOnMethod:0]; // expected-warning {{null passed to a callee which requires a non-null argument}} + [f doNotPassNullOnMethod:0]; // expected-warning {{null passed to a callee that requires a non-null argument}} } void PR18795(int (^g)(const char *h, ...) __attribute__((nonnull(1))) __attribute__((nonnull))) { - g(0); // expected-warning{{null passed to a callee which requires a non-null argument}} + g(0); // expected-warning{{null passed to a callee that requires a non-null argument}} } void PR18795_helper() { - PR18795(0); // expected-warning{{null passed to a callee which requires a non-null argument}} + PR18795(0); // expected-warning{{null passed to a callee that requires a non-null argument}} } diff --git a/test/SemaObjC/objc-cf-audited-warning.m b/test/SemaObjC/objc-cf-audited-warning.m new file mode 100644 index 000000000000..db782299b8ab --- /dev/null +++ b/test/SemaObjC/objc-cf-audited-warning.m @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -fobjc-arc -verify %s +// rdar://18222007 + +#if __has_feature(arc_cf_code_audited) +#define CF_IMPLICIT_BRIDGING_ENABLED _Pragma("clang arc_cf_code_audited begin") +#define CF_IMPLICIT_BRIDGING_DISABLED _Pragma("clang arc_cf_code_audited end") +#endif +#define CF_BRIDGED_TYPE(T) __attribute__((objc_bridge(T))) + +typedef const struct CF_BRIDGED_TYPE(NSURL) __CFURL * CFURLRef; +typedef signed long long CFIndex; +typedef unsigned char Boolean; +typedef unsigned char UInt8; +typedef const struct __CFAllocator * CFAllocatorRef; +const CFAllocatorRef kCFAllocatorDefault; + +CF_IMPLICIT_BRIDGING_ENABLED +CFURLRef CFURLCreateFromFileSystemRepresentation(CFAllocatorRef allocator, const UInt8 *buffer, CFIndex bufLen, Boolean isDirectory); // expected-note {{passing argument to parameter 'buffer' here}} +CF_IMPLICIT_BRIDGING_DISABLED + +void saveImageToJPG(const char *filename) +{ + CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, filename, 10, 0); // expected-warning {{passing 'const char *' to parameter of type 'const UInt8 *' (aka 'const unsigned char *') converts between pointers to integer types with different sign}} +} diff --git a/test/SemaObjC/objc-dictionary-literal.m b/test/SemaObjC/objc-dictionary-literal.m index 9d86d88bcbec..f9fd57f2dae2 100644 --- a/test/SemaObjC/objc-dictionary-literal.m +++ b/test/SemaObjC/objc-dictionary-literal.m @@ -3,6 +3,8 @@ // RUN: %clang_cc1 -fsyntax-only -triple i386-apple-macosx10.9.0 -fobjc-runtime=macosx-fragile-10.9.0 -fobjc-subscripting-legacy-runtime -verify %s // rdar://15363492 +#define nil ((void *)0) + @interface NSNumber + (NSNumber *)numberWithChar:(char)value; + (NSNumber *)numberWithInt:(int)value; @@ -15,6 +17,7 @@ typedef long NSInteger; @interface NSDictionary + (id)dictionaryWithObjects:(const id [])objects forKeys:(const id <NSCopying> [])keys count:(NSUInteger)cnt; - (void)setObject:(id)object forKeyedSubscript:(id)key; +- (id)objectForKeyedSubscript:(id)key; @end @interface NSString<NSCopying> @@ -25,12 +28,24 @@ typedef long NSInteger; - (void)setObject:(id)object atIndexedSubscript:(NSInteger)index; @end +void *pvoid; int main() { NSDictionary *dict = @{ @"name":@666 }; dict[@"name"] = @666; dict["name"] = @666; // expected-error {{indexing expression is invalid because subscript type 'char *' is not an Objective-C pointer}} + // rdar://18254621 + [@{@"foo" : @"bar"} objectForKeyedSubscript:nil]; + (void)@{@"foo" : @"bar"}[nil]; + [@{@"foo" : @"bar"} objectForKeyedSubscript:pvoid]; + (void)@{@"foo" : @"bar"}[pvoid]; + + [@{@"foo" : @"bar"} setObject:nil forKeyedSubscript:@"gorf"]; + @{@"foo" : @"bar"}[nil] = @"gorf"; + [@{@"foo" : @"bar"} setObject:pvoid forKeyedSubscript:@"gorf"]; + @{@"foo" : @"bar"}[pvoid] = @"gorf"; + return 0; } diff --git a/test/SemaObjC/objcbridge-attribute-arc.m b/test/SemaObjC/objcbridge-attribute-arc.m index ee2bf07ed47e..ab8cab8d1919 100644 --- a/test/SemaObjC/objcbridge-attribute-arc.m +++ b/test/SemaObjC/objcbridge-attribute-arc.m @@ -221,3 +221,19 @@ void Test9(CFErrorRef2 cf, NSError *ns, NSString *str, Class c, CFUColor2Ref cf2 (void)(__bridge Class)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'Class'}} (void)(__bridge CFErrorRef)c; // expected-warning {{'__unsafe_unretained Class' cannot bridge to 'CFErrorRef' (aka 'struct __CFErrorRef *')}} } + +// rdar://19157264 +#if __has_feature(objc_bridge_id) +typedef struct __attribute__((objc_bridge(id))) __CFFoo *CFFooRef; +#endif + +id convert(CFFooRef obj) { + (void)(NSError *)obj; // expected-error {{cast of C pointer type 'CFFooRef' (aka 'struct __CFFoo *') to Objective-C pointer type 'NSError *' requires a bridged cast}} \ + // expected-note {{use __bridge to convert directly (no change in ownership)}} \ + // expected-note {{use __bridge_transfer to transfer ownership of a +1 'CFFooRef' (aka 'struct __CFFoo *') into ARC}} + (void) (__bridge NSError *)obj; + (void) (id)obj; // expected-error {{cast of C pointer type 'CFFooRef' (aka 'struct __CFFoo *') to Objective-C pointer type 'id' requires a bridged cast}} \ + // expected-note {{use __bridge to convert directly (no change in ownership)}} \ + // expected-note {{use __bridge_transfer to transfer ownership of a +1 'CFFooRef' (aka 'struct __CFFoo *') into ARC}} + return (__bridge id)obj; +} diff --git a/test/SemaObjC/property-user-setter.m b/test/SemaObjC/property-user-setter.m index e84fad2394ab..7674c2b3a2cd 100644 --- a/test/SemaObjC/property-user-setter.m +++ b/test/SemaObjC/property-user-setter.m @@ -124,15 +124,16 @@ int main (void) { @synthesize t, T; @synthesize Pxyz, pxyz; - (id) Meth { - self.P = 0; - self.q = 0; + self.P = 0; // expected-warning {{property 'P' not found on object of type 'rdar11363363 *'; did you mean to access property p?}} + self.q = 0; // expected-warning {{property 'q' not found on object of type 'rdar11363363 *'; did you mean to access property Q?}} // rdar://11528439 self.t = 0; // expected-error {{synthesized properties 't' and 'T' both claim setter 'setT:'}} self.T = 0; // expected-error {{synthesized properties 'T' and 't' both claim setter 'setT:'}} self.Pxyz = 0; // expected-error {{synthesized properties 'Pxyz' and 'pxyz' both claim setter 'setPxyz:'}} self.pxyz = 0; // expected-error {{synthesized properties 'pxyz' and 'Pxyz' both claim setter 'setPxyz:'}} - self.R = 0; - return self.R; // expected-error {{no getter method for read from property}} + self.r = 0; + return self.R; // expected-error {{no getter method for read from property}} \ + // expected-warning {{property 'R' not found on object of type 'rdar11363363 *'; did you mean to access property r?}} } @end diff --git a/test/SemaObjC/protocol-expr-1.m b/test/SemaObjC/protocol-expr-1.m index 94a0d9e3e8b5..5ff3db474c75 100644 --- a/test/SemaObjC/protocol-expr-1.m +++ b/test/SemaObjC/protocol-expr-1.m @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics -@protocol fproto; +@protocol fproto @end @protocol p1 @end diff --git a/test/SemaObjC/protocol-expr-neg-1.m b/test/SemaObjC/protocol-expr-neg-1.m index 58ac8c0ca322..aed56c016b08 100644 --- a/test/SemaObjC/protocol-expr-neg-1.m +++ b/test/SemaObjC/protocol-expr-neg-1.m @@ -2,7 +2,7 @@ @class Protocol; -@protocol fproto; +@protocol fproto; // expected-note {{'fproto' declared here}} @protocol p1 @end @@ -12,8 +12,23 @@ int main() { Protocol *proto = @protocol(p1); - Protocol *fproto = @protocol(fproto); + Protocol *fproto = @protocol(fproto); // expected-warning {{@protocol is using a forward protocol declaration of fproto}} Protocol *pp = @protocol(i); // expected-error {{cannot find protocol declaration for 'i'}} Protocol *p1p = @protocol(cl); // expected-error {{cannot find protocol declaration for 'cl'}} } +// rdar://17768630 +@protocol SuperProtocol; // expected-note {{'SuperProtocol' declared here}} +@protocol TestProtocol; // expected-note {{'TestProtocol' declared here}} + +@interface I +- (int) conformsToProtocol : (Protocol *)protocl; +@end + +int doesConform(id foo) { + return [foo conformsToProtocol:@protocol(TestProtocol)]; // expected-warning {{@protocol is using a forward protocol declaration of TestProtocol}} +} + +int doesConformSuper(id foo) { + return [foo conformsToProtocol:@protocol(SuperProtocol)]; // expected-warning {{@protocol is using a forward protocol declaration of SuperProtocol}} +} diff --git a/test/SemaObjC/protocols-suppress-conformance.m b/test/SemaObjC/protocols-suppress-conformance.m index 299e44e8074e..a6604b7ff958 100644 --- a/test/SemaObjC/protocols-suppress-conformance.m +++ b/test/SemaObjC/protocols-suppress-conformance.m @@ -5,7 +5,7 @@ __attribute__((objc_protocol_requires_explicit_implementation)) @protocol Protocol - (void) theBestOfTimes; // expected-note {{method 'theBestOfTimes' declared here}} -@property (readonly) id theWorstOfTimes; // expected-note {{property declared here}} +@property (readonly) id theWorstOfTimes; // expected-note {{property declared here}} @end // In this example, ClassA adopts the protocol. We won't @@ -13,14 +13,14 @@ __attribute__((objc_protocol_requires_explicit_implementation)) // be adopted later by a subclass. @interface ClassA <Protocol> - (void) theBestOfTimes; -@property (readonly) id theWorstOfTimes; +@property (readonly) id theWorstOfTimes; // expected-note {{property declared here}} @end // This class subclasses ClassA (which also adopts 'Protocol'). @interface ClassB : ClassA <Protocol> @end -@implementation ClassB // expected-warning {{property 'theWorstOfTimes' requires method 'theWorstOfTimes' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation}} +@implementation ClassB // expected-warning {{property 'theWorstOfTimes' requires method 'theWorstOfTimes' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation}} @end @interface ClassB_Good : ClassA <Protocol> @@ -32,7 +32,7 @@ __attribute__((objc_protocol_requires_explicit_implementation)) @end @interface ClassB_AlsoGood : ClassA <Protocol> -@property (readonly) id theWorstOfTimes; +@property (readonly) id theWorstOfTimes; // expected-warning {{auto property synthesis will not synthesize property 'theWorstOfTimes'; it will be implemented by its superclass}} @end // Default synthesis acts as if @dynamic @@ -40,7 +40,7 @@ __attribute__((objc_protocol_requires_explicit_implementation)) // it is declared in ClassA. This is okay, since // the author of ClassB_AlsoGood needs explicitly // write @property in the @interface. -@implementation ClassB_AlsoGood // no-warning +@implementation ClassB_AlsoGood // expected-note {{detected while default synthesizing properties in class implementation}} - (void) theBestOfTimes {} @end diff --git a/test/SemaObjC/resolve-method-in-global-pool.m b/test/SemaObjC/resolve-method-in-global-pool.m new file mode 100644 index 000000000000..523856d663f6 --- /dev/null +++ b/test/SemaObjC/resolve-method-in-global-pool.m @@ -0,0 +1,63 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -fblocks -Wno-objc-root-class %s +// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin10 -fsyntax-only -verify -fblocks -Wno-objc-root-class %s +// expected-no-diagnostics + +// rdar://16808765 + +@interface NSObject ++ (void)clsMethod:(int*)arg; +@end + +@class NSDictionary; +@class NSError; + +@interface Foo : NSObject +- (void)getDonuts:(void (^)(NSDictionary *, NSError *))replyBlock; +- (void)getCake:(int*)arg, ...; +@end + +@protocol Protocol +@required +- (void)getDonuts:(void (^)(NSDictionary *))replyBlock; +- (void)getCake:(float*)arg, ...; ++ (void)clsMethod:(float*)arg; +@end + +@implementation Foo +{ + float g; +} + +- (void)getDonuts:(void (^)(NSDictionary *, NSError *))replyBlock { + [(id) 0 getDonuts:^(NSDictionary *replyDict) { }]; +} + +- (void) getCake:(int*)arg, ... { + [(id)0 getCake: &g, 1,3.14]; +} +@end + +void func( Class c, float g ) { + [c clsMethod: &g]; +} + +// rdar://18095772 +@protocol NSKeyedArchiverDelegate @end + +@interface NSKeyedArchiver +@property (assign) id <NSKeyedArchiverDelegate> delegate; +@end + +@interface NSConnection +@property (assign) id delegate; +@end + +extern id NSApp; + +@interface AppDelegate +@end + +AppDelegate* GetDelegate() +{ + return [NSApp delegate]; +} diff --git a/test/SemaObjC/scope-check.m b/test/SemaObjC/scope-check.m index e19ba47ad272..b52e7a06ffc2 100644 --- a/test/SemaObjC/scope-check.m +++ b/test/SemaObjC/scope-check.m @@ -3,9 +3,9 @@ @class A, B, C; void test1() { - goto L; // expected-error{{goto into protected scope}} - goto L2; // expected-error{{goto into protected scope}} - goto L3; // expected-error{{goto into protected scope}} + goto L; // expected-error{{cannot jump}} + goto L2; // expected-error{{cannot jump}} + goto L3; // expected-error{{cannot jump}} @try { // expected-note {{jump bypasses initialization of @try block}} L: ; } @catch (A *x) { // expected-note {{jump bypasses initialization of @catch block}} @@ -17,11 +17,11 @@ L3: ; } @try { - goto L4; // expected-error{{goto into protected scope}} - goto L5; // expected-error{{goto into protected scope}} + goto L4; // expected-error{{cannot jump}} + goto L5; // expected-error{{cannot jump}} } @catch (C *c) { // expected-note {{jump bypasses initialization of @catch block}} L5: ; - goto L6; // expected-error{{goto into protected scope}} + goto L6; // expected-error{{cannot jump}} } @catch (B *c) { // expected-note {{jump bypasses initialization of @catch block}} L6: ; } @finally { // expected-note {{jump bypasses initialization of @finally block}} @@ -32,12 +32,12 @@ L3: ; @try { // expected-note 2 {{jump bypasses initialization of @try block}} L7: ; } @catch (C *c) { - goto L7; // expected-error{{goto into protected scope}} + goto L7; // expected-error{{cannot jump}} } @finally { - goto L7; // expected-error{{goto into protected scope}} + goto L7; // expected-error{{cannot jump}} } - goto L8; // expected-error{{goto into protected scope}} + goto L8; // expected-error{{cannot jump}} @try { } @catch (A *c) { } @catch (B *c) { @@ -47,7 +47,7 @@ L3: ; // rdar://6810106 id X; - goto L9; // expected-error{{goto into protected scope}} + goto L9; // expected-error{{cannot jump}} goto L10; // ok @synchronized // expected-note {{jump bypasses initialization of @synchronized block}} ( ({ L10: ; X; })) { @@ -79,7 +79,7 @@ void test3() { + (void) hello { @try { - goto blargh; // expected-error {{goto into protected scope}} + goto blargh; // expected-error {{cannot jump}} } @catch (...) { // expected-note {{jump bypasses initialization of @catch block}} blargh: ; } @@ -87,14 +87,14 @@ void test3() { + (void)meth2 { int n; void *P; - goto L0; // expected-error {{goto into protected scope}} + goto L0; // expected-error {{cannot jump}} typedef int A[n]; // expected-note {{jump bypasses initialization of VLA typedef}} L0: - goto L1; // expected-error {{goto into protected scope}} + goto L1; // expected-error {{cannot jump}} A b, c[10]; // expected-note 2 {{jump bypasses initialization of variable length array}} L1: - goto L2; // expected-error {{goto into protected scope}} + goto L2; // expected-error {{cannot jump}} A d[n]; // expected-note {{jump bypasses initialization of variable length array}} L2: return; diff --git a/test/SemaObjC/super-property-notation.m b/test/SemaObjC/super-property-notation.m index aa67f0af39dc..2b13a5c0f87c 100644 --- a/test/SemaObjC/super-property-notation.m +++ b/test/SemaObjC/super-property-notation.m @@ -30,7 +30,7 @@ void f0() { // rdar://13349296 __attribute__((objc_root_class)) @interface ClassBase -@property (nonatomic, retain) ClassBase * foo; +@property (nonatomic, retain) ClassBase * foo; // expected-note {{property declared here}} @end @implementation ClassBase @@ -41,10 +41,10 @@ __attribute__((objc_root_class)) @interface ClassBase @end @interface ClassDerived : ClassBase -@property (nonatomic, retain) ClassDerived * foo; +@property (nonatomic, retain) ClassDerived * foo; // expected-warning {{auto property synthesis will not synthesize property 'foo'; it will be implemented by its superclass}} @end -@implementation ClassDerived +@implementation ClassDerived // expected-note {{detected while default synthesizing properties in class implementation}} - (void) Meth:(ClassBase*)foo { super.foo = foo; // must work with no warning [super setFoo:foo]; // works with no warning diff --git a/test/SemaObjC/warn-category-method-deprecated.m b/test/SemaObjC/warn-category-method-deprecated.m new file mode 100644 index 000000000000..349a27a795c2 --- /dev/null +++ b/test/SemaObjC/warn-category-method-deprecated.m @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fsyntax-only -Wno-objc-root-class -verify %s +// rdar://18013929 + +@protocol P +- (void)meth; +@end + +@interface I <P> +@end + +@interface I(cat) +- (void)meth __attribute__((deprecated)); // expected-note {{'meth' has been explicitly marked deprecated here}} +@end + +void foo(I *i) { + [i meth]; // expected-warning {{'meth' is deprecated}} +} diff --git a/test/SemaObjC/warn-explicit-call-initialize.m b/test/SemaObjC/warn-explicit-call-initialize.m new file mode 100644 index 000000000000..99fdf530afd8 --- /dev/null +++ b/test/SemaObjC/warn-explicit-call-initialize.m @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin10 -verify %s +// rdar://16628028 + +@interface NSObject ++ (void)initialize; // expected-note 2 {{method 'initialize' declared here}} +@end + +@interface I : NSObject ++ (void)initialize; // expected-note {{method 'initialize' declared here}} ++ (void)SomeRandomMethod; +@end + +@implementation I +- (void) Meth { + [I initialize]; // expected-warning {{explicit call to +initialize results in duplicate call to +initialize}} + [NSObject initialize]; // expected-warning {{explicit call to +initialize results in duplicate call to +initialize}} +} ++ (void)initialize { + [super initialize]; +} ++ (void)SomeRandomMethod { // expected-note {{method 'SomeRandomMethod' declared here}} + [super initialize]; // expected-warning {{explicit call to [super initialize] should only be in implementation of +initialize}} +} +@end + diff --git a/test/SemaObjC/warn-strict-selector-match.m b/test/SemaObjC/warn-strict-selector-match.m index 34f1712f8b58..9f22e73edc69 100644 --- a/test/SemaObjC/warn-strict-selector-match.m +++ b/test/SemaObjC/warn-strict-selector-match.m @@ -29,8 +29,7 @@ id foo(void) { } @protocol MyObject -- (id)initWithData:(Object *)data; // expected-note {{using}} \ - // expected-note {{passing argument to parameter 'data' here}} +- (id)initWithData:(Object *)data; // expected-note {{using}} @end @protocol SomeOther @@ -54,8 +53,7 @@ id foo(void) { } + (NTGridDataObject*)dataObject:(id<MyObject, MyCoding>)data { - NTGridDataObject *result = [(id)0 initWithData:data]; // expected-warning {{multiple methods named 'initWithData:' found}} \ - expected-warning {{sending 'id<MyObject,MyCoding>' to parameter of incompatible type 'Object *'}} + NTGridDataObject *result = [(id)0 initWithData:data]; // expected-warning {{multiple methods named 'initWithData:' found}} return result; } @end |
