diff options
Diffstat (limited to 'test/SemaObjC')
57 files changed, 780 insertions, 160 deletions
diff --git a/test/SemaObjC/arc-decls.m b/test/SemaObjC/arc-decls.m index a53b52a..cdf6cc6 100644 --- a/test/SemaObjC/arc-decls.m +++ b/test/SemaObjC/arc-decls.m @@ -3,17 +3,17 @@ // rdar://8843524 struct A { - id x; // expected-error {{ARC forbids Objective-C objects in structs or unions}} + id x; // expected-error {{ARC forbids Objective-C objects in struct}} }; union u { - id u; // expected-error {{ARC forbids Objective-C objects in structs or unions}} + id u; // expected-error {{ARC forbids Objective-C objects in union}} }; @interface I { struct A a; struct B { - id y[10][20]; // expected-error {{ARC forbids Objective-C objects in structs or unions}} + id y[10][20]; // expected-error {{ARC forbids Objective-C objects in struct}} id z; } b; @@ -23,7 +23,7 @@ union u { // rdar://10260525 struct r10260525 { - id (^block) (); // expected-error {{ARC forbids blocks in structs or unions}} + id (^block) (); // expected-error {{ARC forbids blocks in struct}} }; struct S { diff --git a/test/SemaObjC/arc-objc-lifetime.m b/test/SemaObjC/arc-objc-lifetime.m index 08d2dbe..5e25253 100644 --- a/test/SemaObjC/arc-objc-lifetime.m +++ b/test/SemaObjC/arc-objc-lifetime.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -Wexplicit-ownership-type -verify -Wno-objc-root-class %s -// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -Wexplicit-ownership-type -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -fobjc-runtime-has-weak -Wexplicit-ownership-type -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -fobjc-runtime-has-weak -Wexplicit-ownership-type -verify -Wno-objc-root-class %s // rdar://10244607 typedef const struct __CFString * CFStringRef; @@ -67,3 +67,61 @@ typedef void (^T) (); - (void)createInferiorTransportAndSetEnvironment:(NSMutableDictionary*)environment error:(__autoreleasing NSError**)error {} @end +// <rdar://problem/12367446> +typedef __strong id strong_id; +typedef NSObject *NSObject_ptr; +typedef __strong NSObject *strong_NSObject_ptr; + +// Warn +__strong id f1(); // expected-warning{{ARC __strong lifetime qualifier on return type is ignored}} +NSObject __unsafe_unretained *f2(int); // expected-warning{{ARC __unsafe_unretained lifetime qualifier on return type is ignored}} +__autoreleasing NSObject *f3(void); // expected-warning{{ARC __autoreleasing lifetime qualifier on return type is ignored}} +NSObject * __strong f4(void); // expected-warning{{ARC __strong lifetime qualifier on return type is ignored}} +NSObject_ptr __strong f5(); // expected-warning{{ARC __strong lifetime qualifier on return type is ignored}} + +typedef __strong id (*fptr)(int); // expected-warning{{ARC __strong lifetime qualifier on return type is ignored}} + +// Don't warn +strong_id f6(); +strong_NSObject_ptr f7(); +typedef __strong id (^block_ptr)(int); + +// rdar://10127067 +void test8_a() { + __weak id *(^myBlock)(void); + __weak id *var = myBlock(); + (void) (__strong id *) &myBlock; + (void) (__weak id *) &myBlock; // expected-error {{cast}} +} +void test8_b() { + __weak id (^myBlock)(void); + (void) (__weak id *) &myBlock; + (void) (__strong id *) &myBlock; // expected-error {{cast}} +} +void test8_c() { + __weak id (^*(^myBlock)(void))(void); + (void) (__weak id*) myBlock(); + (void) (__strong id*) myBlock(); // expected-error {{cast}} + (void) (__weak id*) &myBlock; // expected-error {{cast}} + (void) (__strong id*) &myBlock; +} + +@class Test9; +void test9_a() { + __weak Test9 **(^myBlock)(void); + __weak Test9 **var = myBlock(); + (void) (__strong Test9 **) &myBlock; + (void) (__weak Test9 **) &myBlock; // expected-error {{cast}} +} +void test9_b() { + __weak Test9 *(^myBlock)(void); + (void) (__weak Test9**) &myBlock; + (void) (__strong Test9**) &myBlock; // expected-error {{cast}} +} +void test9_c() { + __weak Test9 *(^*(^myBlock)(void))(void); + (void) (__weak Test9 **) myBlock(); + (void) (__strong Test9 **) myBlock(); // expected-error {{cast}} + (void) (__weak Test9 **) &myBlock; // expected-error {{cast}} + (void) (__strong Test9 **) &myBlock; +} diff --git a/test/SemaObjC/arc-property-lifetime.m b/test/SemaObjC/arc-property-lifetime.m index 1957081..b824b2a 100644 --- a/test/SemaObjC/arc-property-lifetime.m +++ b/test/SemaObjC/arc-property-lifetime.m @@ -1,10 +1,10 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-default-synthesize-properties -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s // rdar://9340606 @interface Foo { @public - id __unsafe_unretained x; - id __weak y; + id __unsafe_unretained x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}} + id __weak y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}} id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}} } @property(strong) id x; // expected-note {{property declared here}} @@ -13,15 +13,15 @@ @end @implementation Foo -@synthesize x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}} -@synthesize y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}} +@synthesize x; // expected-note {{property synthesized here}} +@synthesize y; // expected-note {{property synthesized here}} @synthesize z; // suppressed @end @interface Bar { @public - id __unsafe_unretained x; - id __weak y; + id __unsafe_unretained x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}} + id __weak y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}} id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}} } @property(retain) id x; // expected-note {{property declared here}} @@ -30,15 +30,15 @@ @end @implementation Bar -@synthesize x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}} -@synthesize y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}} +@synthesize x; // expected-note {{property synthesized here}} +@synthesize y; // expected-note {{property synthesized here}} @synthesize z; // suppressed @end @interface Bas { @public - id __unsafe_unretained x; - id __weak y; + id __unsafe_unretained x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}} + id __weak y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}} id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}} } @property(copy) id x; // expected-note {{property declared here}} @@ -47,8 +47,8 @@ @end @implementation Bas -@synthesize x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}} -@synthesize y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}} +@synthesize x; // expected-note {{property synthesized here}} +@synthesize y; // expected-note {{property synthesized here}} @synthesize z; // suppressed @end @@ -70,7 +70,7 @@ // rdar://9341593 @interface Gorf { id __unsafe_unretained x; - id y; + id y; // expected-error {{existing instance variable 'y' for property 'y' with assign attribute must be __unsafe_unretained}} } @property(assign) id __unsafe_unretained x; @property(assign) id y; // expected-note {{property declared here}} @@ -79,13 +79,13 @@ @implementation Gorf @synthesize x; -@synthesize y; // expected-error {{existing instance variable 'y' for property 'y' with assign attribute must be __unsafe_unretained}} +@synthesize y; // expected-note {{property synthesized here}} @synthesize z; @end @interface Gorf2 { id __unsafe_unretained x; - id y; + id y; // expected-error {{existing instance variable 'y' for property 'y' with unsafe_unretained attribute must be __unsafe_unretained}} } @property(unsafe_unretained) id __unsafe_unretained x; @property(unsafe_unretained) id y; // expected-note {{property declared here}} @@ -94,7 +94,7 @@ @implementation Gorf2 @synthesize x; -@synthesize y; // expected-error {{existing instance variable 'y' for property 'y' with unsafe_unretained attribute must be __unsafe_unretained}} +@synthesize y; // expected-note {{property synthesized here}} @synthesize z; @end @@ -173,3 +173,12 @@ void foo(Baz *f) { @interface Boom @property (readonly) const void * innerPointer __attribute__((objc_returns_inner_pointer)); // expected-error {{'objc_returns_inner_pointer' attribute only applies to methods}} @end + +@interface Foo2 { + id _prop; // expected-error {{existing instance variable '_prop' for property 'prop' with assign attribute must be __unsafe_unretained}} +} +@property (nonatomic, assign) id prop; // expected-note {{property declared here}} +@end + +@implementation Foo2 +@end diff --git a/test/SemaObjC/arc-property.m b/test/SemaObjC/arc-property.m index 2925459..cf823ae 100644 --- a/test/SemaObjC/arc-property.m +++ b/test/SemaObjC/arc-property.m @@ -2,11 +2,11 @@ // rdar://9309489 @interface MyClass { - id __weak myString; + id __weak myString; // expected-error {{existing instance variable 'myString' for strong property 'myString' may not be __weak}} id StrongIvar; - id __weak myString2; + id __weak myString2; // expected-error {{existing instance variable 'myString2' for strong property 'myString2' may not be __weak}} id __weak myString3; - id StrongIvar5; + id StrongIvar5; // expected-error {{existing instance variable 'StrongIvar5' for __weak property 'myString5' must be __weak}} } @property (strong) id myString; // expected-note {{property declared here}} @property (strong) id myString1; @@ -18,21 +18,21 @@ @end @implementation MyClass -@synthesize myString; // expected-error {{existing instance variable 'myString' for strong property 'myString' may not be __weak}} +@synthesize myString; // expected-note {{property synthesized here}} @synthesize myString1 = StrongIvar; // OK -@synthesize myString2 = myString2; // expected-error {{existing instance variable 'myString2' for strong property 'myString2' may not be __weak}} +@synthesize myString2 = myString2; // expected-note {{property synthesized here}} // @synthesize myString3; // OK @synthesize myString4; // OK -@synthesize myString5 = StrongIvar5; // expected-error {{existing instance variable 'StrongIvar5' for __weak property 'myString5' must be __weak}} +@synthesize myString5 = StrongIvar5; // expected-note {{property synthesized here}} @end // rdar://9340692 @interface Foo { @public - id __unsafe_unretained x; // should be __weak - id __strong y; + id __unsafe_unretained x; // expected-error {{existing instance variable 'x' for __weak property 'x' must be __weak}} + id __strong y; // expected-error {{existing instance variable 'y' for __weak property 'y' must be __weak}} id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}} } @property(weak) id x; // expected-note {{property declared here}} @@ -41,8 +41,8 @@ @end @implementation Foo -@synthesize x; // expected-error {{existing instance variable 'x' for __weak property 'x' must be __weak}} -@synthesize y; // expected-error {{existing instance variable 'y' for __weak property 'y' must be __weak}} +@synthesize x; // expected-note {{property synthesized here}} +@synthesize y; // expected-note {{property synthesized here}} @synthesize z; // suppressed @end diff --git a/test/SemaObjC/arc.m b/test/SemaObjC/arc.m index bd30715..d89d035 100644 --- a/test/SemaObjC/arc.m +++ b/test/SemaObjC/arc.m @@ -4,6 +4,21 @@ typedef unsigned long NSUInteger; typedef const void * CFTypeRef; CFTypeRef CFBridgingRetain(id X); id CFBridgingRelease(CFTypeRef); +@protocol NSCopying @end +@interface NSDictionary ++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id <NSCopying> [])keys count:(NSUInteger)cnt; +- (void)setObject:(id)object forKeyedSubscript:(id)key; +@end +@class NSFastEnumerationState; +@protocol NSFastEnumeration +- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained [])buffer count:(NSUInteger)len; +@end +@interface NSNumber ++ (NSNumber *)numberWithInt:(int)value; +@end +@interface NSArray <NSFastEnumeration> ++ (id)arrayWithObjects:(const id [])objects count:(NSUInteger)cnt; +@end void test0(void (*fn)(int), int val) { fn(val); @@ -717,3 +732,27 @@ void _NSCalcBeze(NSColor* color, NSColor* bezelColors[]); // expected-error {{mu - init { return 0; } @end +// <rdar://problem/12569201>. Warn on cases of initializing a weak variable +// with an Objective-C object literal. +void rdar12569201(id key, id value) { + // Declarations. + __weak id x = @"foo"; // no-warning + __weak id y = @{ key : value }; // expected-warning {{assigning dictionary literal to a weak variable; object will be released after assignment}} + __weak id z = @[ value ]; // expected-warning {{assigning array literal to a weak variable; object will be released after assignment}} + __weak id b = ^() {}; // expected-warning {{assigning block literal to a weak variable; object will be released after assignment}} + __weak id n = @42; // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}} + __weak id e = @(42); // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}} + __weak id m = @(41 + 1); // expected-warning {{assigning boxed expression to a weak variable; object will be released after assignment}} + + // Assignments. + y = @{ key : value }; // expected-warning {{assigning dictionary literal to a weak variable; object will be released after assignment}} + z = @[ value ]; // expected-warning {{assigning array literal to a weak variable; object will be released after assignment}} + b = ^() {}; // expected-warning {{assigning block literal to a weak variable; object will be released after assignment}} + n = @42; // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}} + e = @(42); // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}} + m = @(41 + 1); // expected-warning {{assigning boxed expression to a weak variable; object will be released after assignment}} +} + +@interface C +- (void)method:(id[])objects; // expected-error{{must explicitly describe intended ownership of an object array parameter}} +@end diff --git a/test/SemaObjC/attr-availability.m b/test/SemaObjC/attr-availability.m index ed6b760..bf7ef19 100644 --- a/test/SemaObjC/attr-availability.m +++ b/test/SemaObjC/attr-availability.m @@ -6,11 +6,24 @@ @interface A <P> - (void)method __attribute__((availability(macosx,introduced=10.1,deprecated=10.2))); // expected-note {{method 'method' declared 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; // expected-note {{method 'method' declared here}} +- (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) { diff --git a/test/SemaObjC/attr-deprecated.m b/test/SemaObjC/attr-deprecated.m index c0aa9fc..aa4b479 100644 --- a/test/SemaObjC/attr-deprecated.m +++ b/test/SemaObjC/attr-deprecated.m @@ -1,4 +1,5 @@ // 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 @interface A { int X __attribute__((deprecated)); // expected-note 2 {{declared here}} @@ -135,3 +136,21 @@ typedef struct { @property footype c; // expected-warning {{'footype' is deprecated}} @property footype d __attribute((deprecated)); @end + +// rdar://13569424 +@interface NewI ++(void)cmeth; +@end + +typedef NewI DeprI __attribute__((deprecated("blah"))); // expected-note 4 {{'DeprI' declared here}} + +@interface SI : DeprI // expected-warning {{'DeprI' is deprecated: blah}} +-(DeprI*)meth; // expected-warning {{'DeprI' is deprecated: blah}} +@end + +@implementation SI +-(DeprI*)meth { // expected-warning {{'DeprI' is deprecated: blah}} + [DeprI cmeth]; // expected-warning {{'DeprI' is deprecated: blah}} + return 0; +} +@end diff --git a/test/SemaObjC/bad-receiver-1.m b/test/SemaObjC/bad-receiver-1.m index fe3eecf..fe7f7f5 100644 --- a/test/SemaObjC/bad-receiver-1.m +++ b/test/SemaObjC/bad-receiver-1.m @@ -7,8 +7,7 @@ int objc_lookUpClass(const char*); void __raiseExc1() { - [objc_lookUpClass("NSString") retain]; // expected-warning {{receiver type 'int' is not 'id'}} \ - expected-warning {{method '-retain' not found}} + [objc_lookUpClass("NSString") retain]; // expected-warning {{receiver type 'int' is not 'id'}} } typedef const struct __CFString * CFStringRef; diff --git a/test/SemaObjC/blocks.m b/test/SemaObjC/blocks.m index 9926b08..b523e4c 100644 --- a/test/SemaObjC/blocks.m +++ b/test/SemaObjC/blocks.m @@ -75,10 +75,11 @@ void foo10() { // In C, enum constants have the type of the underlying integer type, not the -// enumeration they are part of. We pretend the constants have enum type when -// they are mixed with other expressions of enum type. +// enumeration they are part of. We pretend the constants have enum type if +// all the returns seem to be playing along. enum CStyleEnum { - CSE_Value = 1 + CSE_Value = 1, + CSE_Value2 = 2 }; enum CStyleEnum getCSE(); typedef enum CStyleEnum (^cse_block_t)(); @@ -92,7 +93,9 @@ void testCStyleEnumInference(bool arg) { a = ^{ // expected-error {{incompatible block pointer types assigning to 'cse_block_t' (aka 'enum CStyleEnum (^)()') from 'int (^)(void)'}} return 1; }; - a = ^{ // expected-error {{incompatible block pointer types assigning to 'cse_block_t' (aka 'enum CStyleEnum (^)()') from 'int (^)(void)'}} + + // No warning here. + a = ^{ return CSE_Value; }; @@ -114,6 +117,15 @@ void testCStyleEnumInference(bool arg) { else return 1; }; + + // rdar://13200889 + extern void check_enum(void); + a = ^{ + return (arg ? (CSE_Value) : (check_enum(), (!arg ? CSE_Value2 : getCSE()))); + }; + a = ^{ + return (arg ? (CSE_Value) : ({check_enum(); CSE_Value2; })); + }; } @@ -184,8 +196,8 @@ typedef short (^short_block_t)(); void testAnonymousEnumTypes(int arg) { int_block_t IB; IB = ^{ return AnonymousValue; }; - IB = ^{ if (arg) return TDE_Value; else return getTDE(); }; // expected-error {{incompatible block pointer}} - IB = ^{ if (arg) return getTDE(); else return TDE_Value; }; // expected-error {{incompatible block pointer}} + IB = ^{ if (arg) return TDE_Value; else return getTDE(); }; + IB = ^{ if (arg) return getTDE(); else return TDE_Value; }; // Since we fixed the underlying type of the enum, these are considered // compatible block types anyway. diff --git a/test/SemaObjC/boxing-illegal-types.m b/test/SemaObjC/boxing-illegal.m index ad45b11..59b5c8b 100644 --- a/test/SemaObjC/boxing-illegal-types.m +++ b/test/SemaObjC/boxing-illegal.m @@ -56,3 +56,20 @@ void testEnum(void *p) { box = @(ME_foo); box = @(*(enum ForwE*)p); // expected-error {{incomplete type 'enum ForwE' used in a boxed expression}} } + +// rdar://13333205 +@class NSMutableDictionary; + +@interface NSMutableArray ++ (NSMutableArray*) array; +@end + +NSMutableDictionary* mBars; + +__attribute((objc_root_class)) @interface rdar13333205 @end + +@implementation rdar13333205 +- (void) insertBar:(id)preset ofKind:(id) kind atIndex:(int)index { + NSMutableArray* presetArray = mBars[kind] ?: [NSMutableArray array]; // expected-error {{expected method to read dictionary element not found on object of type 'NSMutableDictionary *'}} +} +@end diff --git a/test/SemaObjC/builtin_objc_lib_functions.m b/test/SemaObjC/builtin_objc_lib_functions.m index 956ee12..d8713dd 100644 --- a/test/SemaObjC/builtin_objc_lib_functions.m +++ b/test/SemaObjC/builtin_objc_lib_functions.m @@ -14,7 +14,7 @@ long double f3(id self, SEL op) { return objc_msgSend_fpret(self, op); } // expe // expected-note {{please include the header <objc/message.h> or explicitly provide a declaration for 'objc_msgSend_fpret'}} id f4(struct objc_super *super, SEL op) { // expected-warning {{declaration of 'struct objc_super' will not be visible outside of this function}} - return objc_msgSendSuper(super, op); // expected-warning {{implicitly declaring library function 'objc_msgSendSuper' with type 'id (void *, SEL, ...)'}} \ + return objc_msgSendSuper(super, op); // expected-warning {{implicitly declaring library function 'objc_msgSendSuper' with type 'id (struct objc_super *, SEL, ...)'}} \ // expected-note {{please include the header <objc/message.h> or explicitly provide a declaration for 'objc_msgSendSuper'}} } diff --git a/test/SemaObjC/builtin_objc_msgSend.m b/test/SemaObjC/builtin_objc_msgSend.m index bfa09d9..ffa16e7 100644 --- a/test/SemaObjC/builtin_objc_msgSend.m +++ b/test/SemaObjC/builtin_objc_msgSend.m @@ -2,3 +2,19 @@ // expected-no-diagnostics // rdar://8632525 extern id objc_msgSend(id self, SEL op, ...); + +// rdar://12489098 +struct objc_super { + id receiver; + Class super_class; +}; + +extern __attribute__((visibility("default"))) id objc_msgSendSuper(struct objc_super *super, SEL op, ...) + __attribute__((availability(macosx,introduced=10.0))); + +extern __attribute__((visibility("default"))) void objc_msgSendSuper_stret(struct objc_super *super, SEL op, ...) + __attribute__((availability(macosx,introduced=10.0))); + +extern __attribute__((visibility("default"))) void objc_msgSend_stret(id self, SEL op, ...) + __attribute__((availability(macosx,introduced=10.0))); + diff --git a/test/SemaObjC/category-1.m b/test/SemaObjC/category-1.m index a7e6965..18b872a 100644 --- a/test/SemaObjC/category-1.m +++ b/test/SemaObjC/category-1.m @@ -71,8 +71,7 @@ @interface MultipleCat_I() <MultipleCat_P> @end -@implementation MultipleCat_I // expected-warning {{incomplete implementation}} \ - // expected-warning {{method 'im0' in protocol not implemented}} +@implementation MultipleCat_I // expected-warning {{method 'im0' in protocol not implemented}} @end // <rdar://problem/7680391> - Handle nameless categories with no name that refer diff --git a/test/SemaObjC/compare-qualified-id.m b/test/SemaObjC/compare-qualified-id.m index d31dfae..82868f8a 100644 --- a/test/SemaObjC/compare-qualified-id.m +++ b/test/SemaObjC/compare-qualified-id.m @@ -23,8 +23,7 @@ extern NSString * const NSTaskDidTerminateNotification; - (NSString *)evaluateAsStringInContext:(XCPropertyExpansionContext *)context withNestingState:(const void *)state; @end -@implementation XCPropertyExpansionContext // expected-warning {{incomplete implementation}} \ - // expected-warning {{method 'copyWithZone:' in protocol not implemented}} +@implementation XCPropertyExpansionContext // expected-warning {{method 'copyWithZone:' in protocol not implemented}} - (NSString *)expandedValueForProperty:(NSString *)property { id <XCPropertyValues> cachedValueNode = [_propNamesToPropValuesCache objectForKey:property]; // expected-warning {{method '-objectForKey:' not found (return type defaults to 'id')}} if (cachedValueNode == ((void *)0)) { } diff --git a/test/SemaObjC/conditional-expr.m b/test/SemaObjC/conditional-expr.m index e0a3210..ec1305d 100644 --- a/test/SemaObjC/conditional-expr.m +++ b/test/SemaObjC/conditional-expr.m @@ -21,10 +21,10 @@ @end @interface DTFilterOutputStream2 -- nextOutputStream; // expected-note {{method definition for 'nextOutputStream' not found}} +- nextOutputStream; // expected-note {{method 'nextOutputStream' declared here}} @end -@implementation DTFilterOutputStream2 // expected-warning {{incomplete implementation}} +@implementation DTFilterOutputStream2 // expected-warning {{method definition for 'nextOutputStream' not found}} - (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream { id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; self = nextOutputStream; // expected-warning {{assigning to 'DTFilterOutputStream2 *' from incompatible type 'id<DTOutputStreams>'}} diff --git a/test/SemaObjC/crash-on-objc-bool-literal.m b/test/SemaObjC/crash-on-objc-bool-literal.m index 2c003a5..47e1ce2 100644 --- a/test/SemaObjC/crash-on-objc-bool-literal.m +++ b/test/SemaObjC/crash-on-objc-bool-literal.m @@ -2,11 +2,10 @@ // RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify %s // rdar://12456743 -typedef signed char BOOL; // expected-note 2 {{candidate found by name lookup is 'BOOL'}} +typedef signed char BOOL; -EXPORT BOOL FUNC(BOOL enabled); // expected-error {{unknown type name 'EXPORT'}} // expected-error {{expected ';' after top level declarator}} \ - // expected-note 2 {{candidate found by name lookup is 'BOOL'}} +EXPORT BOOL FUNC(BOOL enabled); // expected-error {{unknown type name 'EXPORT'}} // expected-error {{expected ';' after top level declarator}} -static inline BOOL MFIsPrivateVersion(void) { // expected-error {{reference to 'BOOL' is ambiguous}} - return __objc_yes; // expected-error {{reference to 'BOOL' is ambiguous}} +static inline BOOL MFIsPrivateVersion(void) { + return __objc_yes; } diff --git a/test/SemaObjC/debugger-cast-result-to-id.m b/test/SemaObjC/debugger-cast-result-to-id.m index 00a02be..ecf3e74 100644 --- a/test/SemaObjC/debugger-cast-result-to-id.m +++ b/test/SemaObjC/debugger-cast-result-to-id.m @@ -6,6 +6,8 @@ extern __unknown_anytype test1(); void test_unknown_anytype_receiver() { (void)(int)[[test0 unknownMethod] otherUnknownMethod];; (void)(id)[[test1() unknownMethod] otherUnknownMethod]; + id x = test0; + id y = test1(); } // rdar://10988847 diff --git a/test/SemaObjC/default-synthesize-3.m b/test/SemaObjC/default-synthesize-3.m index 606ece3..82f968d 100644 --- a/test/SemaObjC/default-synthesize-3.m +++ b/test/SemaObjC/default-synthesize-3.m @@ -39,3 +39,75 @@ __attribute ((objc_requires_property_definitions)) __attribute ((objc_requires_property_definitions)) // expected-error {{objc_requires_property_definitions attribute may only be specified on a class}} @protocol P @end + +// rdar://13388503 +@interface NSObject @end +@protocol Foo +@property (readonly) char isFoo; // expected-note {{property declared here}} +@property (readonly) char isNotFree; +@end + +@interface Bar : NSObject <Foo> +@end + +@implementation Bar +- (char)isFoo { + return 0; +} +- (char)isNotFree { + return 0; +} +@end + +@interface Baz : Bar +@end + +@interface Baz () +@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; +@end + +@implementation Baz { + char _isFoo; + char _isNotFree; +} +@synthesize Property2 = Property1; // expected-note {{property synthesized here}} + +- (void) setIsNotFree : (char)Arg { + _isNotFree = Arg; +} + +@end + +// More test where such warnings should not be issued. +@protocol MyProtocol +-(void)setProp1:(id)x; +@end + +@protocol P1 <MyProtocol> +@end + +@interface B +@property (readonly) id prop; +@property (readonly) id prop1; +@property (readonly) id prop2; +@end + +@interface B() +-(void)setProp:(id)x; +@end + +@interface B(cat) +@property (readwrite) id prop2; +@end + +@interface S : B<P1> +@property (assign,readwrite) id prop; +@property (assign,readwrite) id prop1; +@property (assign,readwrite) id prop2; +@end + +@implementation S +@end diff --git a/test/SemaObjC/enum-fixed-type.m b/test/SemaObjC/enum-fixed-type.m index 4fe643f..c00e45a 100644 --- a/test/SemaObjC/enum-fixed-type.m +++ b/test/SemaObjC/enum-fixed-type.m @@ -1,5 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -// expected-no-diagnostics +// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s #if !__has_feature(objc_fixed_enum) # error Enumerations with a fixed underlying type are not supported @@ -29,10 +28,13 @@ void test() { // <rdar://10381507> typedef enum : long { Foo } IntegerEnum; -int arr[(sizeof(typeof(Foo)) == sizeof(typeof(IntegerEnum))) - 1]; -int arr1[(sizeof(typeof(Foo)) == sizeof(typeof(long))) - 1]; -int arr2[(sizeof(typeof(IntegerEnum)) == sizeof(typeof(long))) - 1]; +int arr[(sizeof(__typeof__(Foo)) == sizeof(__typeof__(IntegerEnum)))? 1 : -1]; +int arr1[(sizeof(__typeof__(Foo)) == sizeof(__typeof__(long)))? 1 : -1]; +int arr2[(sizeof(__typeof__(IntegerEnum)) == sizeof(__typeof__(long)))? 1 : -1]; // <rdar://problem/10760113> typedef enum : long long { Bar = -1 } LongLongEnum; int arr3[(long long)Bar == (long long)-1 ? 1 : -1]; + +typedef enum : Integer { BaseElem } BaseEnum; +typedef enum : BaseEnum { DerivedElem } DerivedEnum; // expected-error {{non-integral type 'BaseEnum' is an invalid underlying type}} diff --git a/test/SemaObjC/error-missing-getter.m b/test/SemaObjC/error-missing-getter.m index 3c91ab2..3dce858 100644 --- a/test/SemaObjC/error-missing-getter.m +++ b/test/SemaObjC/error-missing-getter.m @@ -9,11 +9,34 @@ @end int func (int arg, Subclass *x) { - if (x.setterOnly) { // expected-error {{expected getter method not found on object of type 'Subclass *'}} + if (x.setterOnly) { // expected-error {{no getter method for read from property}} x.setterOnly = 1; } - func(x.setterOnly + 1, x); // expected-error {{expected getter method not found on object of type 'Subclass *'}} - int i = x.setterOnly + 1; // expected-error {{expected getter method not found on object of type 'Subclass *'}} - return x.setterOnly + 1; // expected-error {{expected getter method not found on object of type 'Subclass *'}} + func(x.setterOnly + 1, x); // expected-error {{no getter method for read from property}} + int i = x.setterOnly + 1; // expected-error {{no getter method for read from property}} + return x.setterOnly + 1; // expected-error {{no getter method for read from property}} } +// <rdar://problem/12765391> + +@interface TestClass ++ (void) setSetterOnly : (int) arg; +@end + +int func2 (int arg) { + if (TestClass.setterOnly) { // expected-error {{no getter method for read from property}} + TestClass.setterOnly = 1; + } + func(TestClass.setterOnly + 1, x); // expected-error {{no getter method for read from property}} + int i = TestClass.setterOnly + 1; // expected-error {{no getter method for read from property}} + return TestClass.setterOnly + 1; // expected-error {{no getter method for read from property}} +} + +@interface Sub : Subclass +- (int) func3; +@end +@implementation Sub +- (int) func3 { + return super.setterOnly; // expected-error {{no getter method for read from property}} +} +@end diff --git a/test/SemaObjC/error-outof-scope-property-use.m b/test/SemaObjC/error-outof-scope-property-use.m new file mode 100644 index 0000000..c69a405 --- /dev/null +++ b/test/SemaObjC/error-outof-scope-property-use.m @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -fobjc-default-synthesize-properties -verify -Wno-objc-root-class %s +// rdar://13178483 + +@class NSMutableDictionary; + +@interface LaunchdJobs + +@property (nonatomic,retain) NSMutableDictionary *uuids_jobs; // expected-note 2 {{'_uuids_jobs' declared here}} + +@end + +@implementation LaunchdJobs + +-(void)job +{ + + [uuids_jobs objectForKey]; // expected-error {{use of undeclared identifier 'uuids_jobs'}} \ + // expected-warning {{instance method '-objectForKey' not found}} +} + + +@end + +void +doLaunchdJobCPU() +{ + [uuids_jobs enumerateKeysAndObjectsUsingBlock]; // expected-error {{use of undeclared identifier 'uuids_jobs'}} +} diff --git a/test/SemaObjC/format-strings-objc.m b/test/SemaObjC/format-strings-objc.m index 7faa995..bd33ad4 100644 --- a/test/SemaObjC/format-strings-objc.m +++ b/test/SemaObjC/format-strings-objc.m @@ -145,7 +145,7 @@ void test_percent_S() { NSLog(@"%S", ptr); // no-warning const wchar_t* wchar_ptr = L"ab"; - NSLog(@"%S", wchar_ptr); // expected-warning{{format specifies type 'const unsigned short *' but the argument has type 'const wchar_t *'}} + NSLog(@"%S", wchar_ptr); // expected-warning{{format specifies type 'const unichar *' (aka 'const unsigned short *') but the argument has type 'const wchar_t *'}} } void test_percent_ls() { @@ -154,7 +154,7 @@ void test_percent_ls() { NSLog(@"%ls", ptr); // no-warning const wchar_t* wchar_ptr = L"ab"; - NSLog(@"%ls", wchar_ptr); // expected-warning{{format specifies type 'const unsigned short *' but the argument has type 'const wchar_t *'}} + NSLog(@"%ls", wchar_ptr); // expected-warning{{format specifies type 'const unichar *' (aka 'const unsigned short *') but the argument has type 'const wchar_t *'}} } void test_percent_C() { @@ -162,7 +162,7 @@ void test_percent_C() { NSLog(@"%C", data); // no-warning const wchar_t wchar_data = L'a'; - NSLog(@"%C", wchar_data); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'wchar_t'}} + NSLog(@"%C", wchar_data); // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'wchar_t'}} } // Test that %@ works with toll-free bridging (<rdar://problem/10814120>). diff --git a/test/SemaObjC/forward-protocol-incomplete-impl-warn.m b/test/SemaObjC/forward-protocol-incomplete-impl-warn.m new file mode 100644 index 0000000..01fedec --- /dev/null +++ b/test/SemaObjC/forward-protocol-incomplete-impl-warn.m @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-default-synthesize-properties %s +// rdar://12958878 + +@interface NSObject @end + +@protocol DVTInvalidation +- (void)invalidate; // expected-note {{method 'invalidate' declared here}} +@property int Prop; // expected-note {{property declared here}} +@end + + + +@protocol DVTInvalidation; + +@interface IBImageCatalogDocument : NSObject <DVTInvalidation> // expected-note {{required for direct or indirect protocol 'DVTInvalidation'}} +@end + +@implementation IBImageCatalogDocument // expected-warning {{auto property synthesis will not synthesize property declared in a protocol}} \ + // expected-warning {{method 'invalidate' in protocol not implemented}} +@end diff --git a/test/SemaObjC/gcc-cast-ext.m b/test/SemaObjC/gcc-cast-ext.m index 30e0dce..5858393 100644 --- a/test/SemaObjC/gcc-cast-ext.m +++ b/test/SemaObjC/gcc-cast-ext.m @@ -5,8 +5,8 @@ typedef struct _NSRange { } NSRange; @class PBXFileReference; @interface PBXDocBookmark -+ alloc; // expected-note {{method definition for 'alloc' not found}} -- autorelease; // expected-note {{method definition for 'autorelease' not found}} ++ alloc; // expected-note {{method 'alloc' declared here}} +- autorelease; // expected-note {{method 'autorelease' declared here}} @end // GCC allows pointer expressions in integer constant expressions. @@ -14,7 +14,8 @@ struct { char control[((int)(char *)2)]; } xx; -@implementation PBXDocBookmark // expected-warning {{incomplete implementation}} +@implementation PBXDocBookmark // expected-warning {{method definition for 'autorelease' not found}}\ + // expected-warning {{method definition for 'alloc' not found}} + (id)bookmarkWithFileReference:(PBXFileReference *)fileRef gylphRange:(NSRange)range anchor:(NSString *)htmlAnchor { diff --git a/test/SemaObjC/generic-selection.m b/test/SemaObjC/generic-selection.m new file mode 100644 index 0000000..70c77dc --- /dev/null +++ b/test/SemaObjC/generic-selection.m @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics + +__attribute__((objc_root_class)) +@interface Root { + Class isa; +} +@end + +@interface A +@property (strong) id x; +@end + +// rdar://13193560 +void test0(A *a) { + int kind = _Generic(a.x, id : 0, int : 1, float : 2); +} diff --git a/test/SemaObjC/iboutlet.m b/test/SemaObjC/iboutlet.m index a29915c..01e1bfc 100644 --- a/test/SemaObjC/iboutlet.m +++ b/test/SemaObjC/iboutlet.m @@ -9,15 +9,34 @@ #define IBOutlet __attribute__((iboutlet)) @interface I -@property (getter = MyGetter, readonly, assign) IBOutlet NSView *myView; // expected-note {{property declared here}} \ - // expected-note {{readonly IBOutlet property should be changed to be readwrite}} +@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-note {{readonly IBOutlet property should be changed to be readwrite}} \ - // expected-note {{property declared here}} +@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-note {{property declared here}} +@property (getter = MyGetter, READONLY) IBOutlet NSView *myView2; // expected-warning {{readonly IBOutlet property 'myView2' when auto-synthesized may not work correctly with 'nib' loader}} @end -@implementation I // expected-warning 3 {{readonly IBOutlet property when auto-synthesized may not work correctly with 'nib' loader}} +@implementation I +@end + + +// rdar://13123861 +@class UILabel; + +@interface NSObject @end + +@interface RKTFHView : NSObject +@property( readonly ) __attribute__((iboutlet)) UILabel *autoReadOnlyReadOnly; // expected-warning {{readonly IBOutlet property 'autoReadOnlyReadOnly' when auto-synthesized may not work correctly with 'nib' loader}} expected-note {{property should be changed to be readwrite}} +@property( readonly ) __attribute__((iboutlet)) UILabel *autoReadOnlyReadWrite; +@property( readonly ) __attribute__((iboutlet)) UILabel *synthReadOnlyReadWrite; +@end + +@interface RKTFHView() +@property( readwrite ) __attribute__((iboutlet)) UILabel *autoReadOnlyReadWrite; +@property( readwrite ) __attribute__((iboutlet)) UILabel *synthReadOnlyReadWrite; +@end + +@implementation RKTFHView +@synthesize synthReadOnlyReadWrite=_synthReadOnlyReadWrite; @end diff --git a/test/SemaObjC/illegal-nonarc-bridged-cast.m b/test/SemaObjC/illegal-nonarc-bridged-cast.m index a5bb01f..f3406ef 100644 --- a/test/SemaObjC/illegal-nonarc-bridged-cast.m +++ b/test/SemaObjC/illegal-nonarc-bridged-cast.m @@ -18,17 +18,16 @@ NSString *CreateNSString(); void from_cf() { id obj1 = (__bridge_transfer id)CFCreateSomething(); // expected-warning {{'__bridge_transfer' casts have no effect when not using ARC}} id obj2 = (__bridge_transfer NSString*)CFCreateString(); // expected-warning {{'__bridge_transfer' casts have no effect when not using ARC}} - (__bridge int*)CFCreateSomething(); // expected-warning {{'__bridge' casts have no effect when not using ARC}} \ - // expected-warning {{expression result unused}} - id obj3 = (__bridge id)CFGetSomething(); // expected-warning {{'__bridge' casts have no effect when not using ARC}} - id obj4 = (__bridge NSString*)CFGetString(); // expected-warning {{'__bridge' casts have no effect when not using ARC}} + (__bridge int*)CFCreateSomething(); // expected-warning {{expression result unused}} + id obj3 = (__bridge id)CFGetSomething(); + id obj4 = (__bridge NSString*)CFGetString(); } void to_cf(id obj) { CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething(); // expected-warning {{'__bridge_retained' casts have no effect when not using ARC}} CFStringRef cf2 = (__bridge_retained CFStringRef)CreateNSString(); // expected-warning {{'__bridge_retained' casts have no effect when not using ARC}} - CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething(); // expected-warning {{'__bridge' casts have no effect when not using ARC}} - CFStringRef cf4 = (__bridge CFStringRef)CreateNSString(); // expected-warning {{'__bridge' casts have no effect when not using ARC}} + CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething(); + CFStringRef cf4 = (__bridge CFStringRef)CreateNSString(); } void fixits() { diff --git a/test/SemaObjC/incomplete-implementation.m b/test/SemaObjC/incomplete-implementation.m index 54f66ef..4b8d600 100644 --- a/test/SemaObjC/incomplete-implementation.m +++ b/test/SemaObjC/incomplete-implementation.m @@ -1,11 +1,12 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -verify -Wno-objc-root-class %s @interface I -- Meth; // expected-note{{method definition for 'Meth' not found}} \ - // expected-note{{method 'Meth' declared here}} +- Meth; // expected-note 2 {{method 'Meth' declared here}} +- unavailableMeth __attribute__((availability(macosx,unavailable))); +- unavailableMeth2 __attribute__((unavailable)); @end -@implementation I // expected-warning{{incomplete implementation}} +@implementation I // expected-warning {{method definition for 'Meth' not found}} @end @implementation I(CAT) diff --git a/test/SemaObjC/instancetype.m b/test/SemaObjC/instancetype.m index 40f35d9..8137964 100644 --- a/test/SemaObjC/instancetype.m +++ b/test/SemaObjC/instancetype.m @@ -5,9 +5,9 @@ #endif @interface Root -+ (instancetype)alloc; ++ (instancetype)alloc; // expected-note {{explicitly declared 'instancetype'}} - (instancetype)init; // expected-note{{overridden method is part of the 'init' method family}} -- (instancetype)self; +- (instancetype)self; // expected-note {{explicitly declared 'instancetype'}} - (Class)class; @property (assign) Root *selfProp; @@ -143,7 +143,7 @@ void test_instancetype_narrow_method_search() { @implementation Subclass4 + (id)alloc { - return self; // expected-warning{{incompatible pointer types casting 'Class' to type 'Subclass4 *'}} + return self; // expected-warning{{incompatible pointer types returning 'Class' from a function with result type 'Subclass4 *'}} } - (Subclass3 *)init { return 0; } // don't complain: we lost the related return type @@ -164,14 +164,14 @@ void test_instancetype_inherited() { // Check that related return types tighten up the semantics of // Objective-C method implementations. @implementation Subclass2 -- (instancetype)initSubclass2 { +- (instancetype)initSubclass2 { // expected-note {{explicitly declared 'instancetype'}} Subclass1 *sc1 = [[Subclass1 alloc] init]; - return sc1; // expected-warning{{incompatible pointer types casting 'Subclass1 *' to type 'Subclass2 *'}} + return sc1; // expected-warning{{incompatible pointer types returning 'Subclass1 *' from a function with result type 'Subclass2 *'}} } - (void)methodOnSubclass2 {} - (id)self { Subclass1 *sc1 = [[Subclass1 alloc] init]; - return sc1; // expected-warning{{incompatible pointer types casting 'Subclass1 *' to type 'Subclass2 *'}} + return sc1; // expected-warning{{incompatible pointer types returning 'Subclass1 *' from a function with result type 'Subclass2 *'}} } @end @@ -188,3 +188,29 @@ void test_instancetype_inherited() { @end +// rdar://12493140 +@protocol P4 +- (instancetype) foo; // expected-note {{current method is explicitly declared 'instancetype' and is expected to return an instance of its class type}} +@end +@interface A4 : Root <P4> +- (instancetype) bar; // expected-note {{current method is explicitly declared 'instancetype' and is expected to return an instance of its class type}} +- (instancetype) baz; // expected-note {{overridden method returns an instance of its class type}} expected-note {{previous definition is here}} +@end +@interface B4 : Root @end + +@implementation A4 { + B4 *_b; +} +- (id) foo { + return _b; // expected-warning {{incompatible pointer types returning 'B4 *' from a function with result type 'A4 *'}} +} +- (id) bar { + return _b; // expected-warning {{incompatible pointer types returning 'B4 *' from a function with result type 'A4 *'}} +} + +// This is really just to ensure that we don't crash. +// FIXME: only one diagnostic, please +- (float) baz { // expected-warning {{method is expected to return an instance of its class type 'A4', but is declared to return 'float'}} expected-warning {{conflicting return type in implementation}} + return 0; +} +@end diff --git a/test/SemaObjC/message.m b/test/SemaObjC/message.m index 621a18f..f43bdf9 100644 --- a/test/SemaObjC/message.m +++ b/test/SemaObjC/message.m @@ -95,6 +95,14 @@ int test5(int X) { void foo4() { struct objc_object X[10]; - [X rect]; // expected-warning {{receiver type 'struct objc_object *' is not 'id' or interface pointer, consider casting it to 'id'}} expected-warning {{method '-rect' not found (return type defaults to 'id')}} + [X rect]; // expected-warning {{receiver type 'struct objc_object *' is not 'id' or interface pointer, consider casting it to 'id'}} } +// rdar://13207886 +void foo5(id p) { + p + [(id)(p) bar]; // expected-error {{missing '['}} \ + // expected-error {{expected ']'}} \ + // expected-note {{to match this '['}} \ + // expected-warning {{instance method '-bar' not found}} +} diff --git a/test/SemaObjC/method-undef-category-warn-1.m b/test/SemaObjC/method-undef-category-warn-1.m index 2548cbd..98d732b 100644 --- a/test/SemaObjC/method-undef-category-warn-1.m +++ b/test/SemaObjC/method-undef-category-warn-1.m @@ -4,25 +4,25 @@ @end @protocol P -- (void) Pmeth; // expected-note {{method 'Pmeth' declared here}} -- (void) Pmeth1; // expected-note {{method 'Pmeth1' declared here}} +- (void) Pmeth; // expected-note {{method 'Pmeth' declared here}} +- (void) Pmeth1; // expected-note {{method 'Pmeth1' declared here}} @end @interface MyClass1(CAT) <P> // expected-note {{required for direct or indirect protocol 'P'}} -- (void) meth2; // expected-note {{method definition for 'meth2' not found}} +- (void) meth2; // expected-note {{method 'meth2' declared here}} @end -@implementation MyClass1(CAT) // expected-warning {{incomplete implementation}} \ - // expected-warning {{method 'Pmeth' in protocol not implemented}} +@implementation MyClass1(CAT) // expected-warning {{method 'Pmeth' in protocol not implemented}} \ + // expected-warning {{method definition for 'meth2' not found}} - (void) Pmeth1{} @end @interface MyClass1(DOG) <P> // expected-note {{required for direct or indirect protocol 'P'}} -- (void)ppp; // expected-note {{method definition for 'ppp' not found}} +- (void)ppp; // expected-note {{method 'ppp' declared here}} @end -@implementation MyClass1(DOG) // expected-warning {{incomplete implementation}} \ - // expected-warning {{method 'Pmeth1' in protocol not implemented}} +@implementation MyClass1(DOG) // expected-warning {{method 'Pmeth1' in protocol not implemented}} \ + // expected-warning {{method definition for 'ppp' not found}} - (void) Pmeth {} @end diff --git a/test/SemaObjC/method-undef-extension-warn-1.m b/test/SemaObjC/method-undef-extension-warn-1.m index c092f24..fbc21bd 100644 --- a/test/SemaObjC/method-undef-extension-warn-1.m +++ b/test/SemaObjC/method-undef-extension-warn-1.m @@ -10,7 +10,7 @@ // Class extension @interface MyClass () <P> -- (void)meth2; // expected-note {{method definition for 'meth2' not found}} +- (void)meth2; // expected-note {{method 'meth2' declared here}} @end // Add a category to test that clang does not emit warning for this method. @@ -18,7 +18,7 @@ - (void)categoryMethod; @end -@implementation MyClass // expected-warning {{incomplete implementation}} \ - // expected-warning {{method 'Pmeth1' in protocol not implemented}} +@implementation MyClass // expected-warning {{method 'Pmeth1' in protocol not implemented}} \ + // expected-warning {{method definition for 'meth2' not found}} - (void)Pmeth {} @end diff --git a/test/SemaObjC/method-undefined-warn-1.m b/test/SemaObjC/method-undefined-warn-1.m index 27d645e..e22140d 100644 --- a/test/SemaObjC/method-undefined-warn-1.m +++ b/test/SemaObjC/method-undefined-warn-1.m @@ -3,12 +3,14 @@ @interface INTF - (void) meth; - (void) meth : (int) arg1; -- (int) int_meth; // expected-note {{method definition for 'int_meth' not found}} -+ (int) cls_meth; // expected-note {{method definition for 'cls_meth' not found}} -+ (void) cls_meth1 : (int) arg1; // expected-note {{method definition for 'cls_meth1:' not found}} +- (int) int_meth; // expected-note {{method 'int_meth' declared here}} ++ (int) cls_meth; // expected-note {{method 'cls_meth' declared here}} ++ (void) cls_meth1 : (int) arg1; // expected-note {{method 'cls_meth1:' declared here}} @end -@implementation INTF // expected-warning {{incomplete implementation}} +@implementation INTF // expected-warning {{method definition for 'int_meth' not found}} \ + // expected-warning {{method definition for 'cls_meth' not found}} \ + // expected-warning {{method definition for 'cls_meth1:' not found}} - (void) meth {} - (void) meth : (int) arg2{} - (void) cls_meth1 : (int) arg2{} @@ -17,12 +19,14 @@ @interface INTF1 - (void) meth; - (void) meth : (int) arg1; -- (int) int_meth; // expected-note {{method definition for 'int_meth' not found}} -+ (int) cls_meth; // expected-note {{method definition for 'cls_meth' not found}} -+ (void) cls_meth1 : (int) arg1; // expected-note {{method definition for 'cls_meth1:' not found}} +- (int) int_meth; // expected-note {{method 'int_meth' declared here}} ++ (int) cls_meth; // expected-note {{method 'cls_meth' declared here}} ++ (void) cls_meth1 : (int) arg1; // expected-note {{method 'cls_meth1:' declared here}} @end -@implementation INTF1 // expected-warning {{incomplete implementation}} +@implementation INTF1 // expected-warning {{method definition for 'int_meth' not found}} \ + // expected-warning {{method definition for 'cls_meth' not found}} \ + // expected-warning {{method definition for 'cls_meth1:' not found}} - (void) meth {} - (void) meth : (int) arg2{} - (void) cls_meth1 : (int) arg2{} diff --git a/test/SemaObjC/no-protocol-option-tests.m b/test/SemaObjC/no-protocol-option-tests.m index dbd2a14..605cf9f 100644 --- a/test/SemaObjC/no-protocol-option-tests.m +++ b/test/SemaObjC/no-protocol-option-tests.m @@ -17,9 +17,9 @@ // Test2 @interface super - PMeth; @end @interface J : super <P> -- PMeth; // expected-note {{method definition for 'PMeth' not found}} +- PMeth; // expected-note {{method 'PMeth' declared here}} @end -@implementation J @end // expected-warning {{incomplete implementation}} +@implementation J @end // expected-warning {{method definition for 'PMeth' not found}} // Test3 @interface K : super <P> diff --git a/test/SemaObjC/no-warning-unavail-unimp.m b/test/SemaObjC/no-warning-unavail-unimp.m index d5a4eac..037bf24 100644 --- a/test/SemaObjC/no-warning-unavail-unimp.m +++ b/test/SemaObjC/no-warning-unavail-unimp.m @@ -1,9 +1,11 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -verify -Wno-objc-root-class %s // expected-no-diagnostics // rdar://9651605 +// rdar://12958191 @interface Foo @property (getter=getVal) int val __attribute__((unavailable)); +@property (getter=getVal) int val2 __attribute__((availability(macosx,unavailable))); - Method __attribute__((unavailable)); + CMethod __attribute__((unavailable)); @end diff --git a/test/SemaObjC/objc-literal-comparison.m b/test/SemaObjC/objc-literal-comparison.m index 0a10582..95ebfb3 100644 --- a/test/SemaObjC/objc-literal-comparison.m +++ b/test/SemaObjC/objc-literal-comparison.m @@ -98,3 +98,6 @@ void testNilComparison() { RETURN_IF_NIL(@(1+1)); } +void PR15257(Class c) { + return c == @""; // expected-warning{{direct comparison of a string literal has undefined behavior}} +} diff --git a/test/SemaObjC/property-3.m b/test/SemaObjC/property-3.m index 439dc28..3f82bcc 100644 --- a/test/SemaObjC/property-3.m +++ b/test/SemaObjC/property-3.m @@ -9,6 +9,25 @@ @end @interface NOW : I -@property (readonly) id d1; // expected-warning {{attribute 'readonly' of property 'd1' restricts attribute 'readwrite' of property inherited from 'I'}} expected-warning {{property 'd1' 'copy' attribute does not match the property inherited from 'I'}} +@property (readonly) id d1; // expected-warning {{attribute 'readonly' of property 'd1' restricts attribute 'readwrite' of property inherited from 'I'}} expected-warning {{'copy' attribute on property 'd1' does not match the property inherited from 'I'}} @property (readwrite, copy) I* d2; @end + +// rdar://13156292 +typedef signed char BOOL; + +@protocol EKProtocolCalendar +@property (nonatomic, readonly) BOOL allowReminders; +@property (atomic, readonly) BOOL allowNonatomicProperty; // expected-note {{property declared here}} +@end + +@protocol EKProtocolMutableCalendar <EKProtocolCalendar> +@end + +@interface EKCalendar +@end + +@interface EKCalendar () <EKProtocolMutableCalendar> +@property (nonatomic, assign) BOOL allowReminders; +@property (nonatomic, assign) BOOL allowNonatomicProperty; // expected-warning {{'atomic' attribute on property 'allowNonatomicProperty' does not match the property inherited from 'EKProtocolCalendar'}} +@end diff --git a/test/SemaObjC/property-4.m b/test/SemaObjC/property-4.m index 2168048..49f0958 100644 --- a/test/SemaObjC/property-4.m +++ b/test/SemaObjC/property-4.m @@ -24,6 +24,6 @@ int newO; int oldO; } -@property (retain) id MayCauseError; // expected-warning {{property 'MayCauseError' 'copy' attribute does not match the property inherited from 'ProtocolObject'}} +@property (retain) id MayCauseError; // expected-warning {{'copy' attribute on property 'MayCauseError' does not match the property inherited from 'ProtocolObject'}} @end diff --git a/test/SemaObjC/property-category-3.m b/test/SemaObjC/property-category-3.m index 47e93a3..9be97ae 100644 --- a/test/SemaObjC/property-category-3.m +++ b/test/SemaObjC/property-category-3.m @@ -16,7 +16,7 @@ @end @interface I (Cat2) <P1> -@property (retain) id ID; // expected-warning {{property 'ID' 'copy' attribute does not match the property inherited from 'P1'}} +@property (retain) id ID; // expected-warning {{'copy' attribute on property 'ID' does not match the property inherited from 'P1'}} @end diff --git a/test/SemaObjC/property-category-impl.m b/test/SemaObjC/property-category-impl.m index 9524c22..be42dea 100644 --- a/test/SemaObjC/property-category-impl.m +++ b/test/SemaObjC/property-category-impl.m @@ -29,3 +29,32 @@ @implementation MyClass (public)// expected-warning {{property 'foo' requires method 'setFoo:' to be defined }} @end + +// rdar://12568064 +// No warn of unimplemented property of protocols in category, +// when those properties will be implemented in category's primary +// class or one of its super classes. +@interface HBSuperclass +@property (nonatomic) char myProperty; +@property (nonatomic) char myProperty2; +@end + +@interface HBClass : HBSuperclass +@end + +@protocol HBProtocol +@property (nonatomic) char myProperty; +@property (nonatomic) char myProperty2; +@end + +@interface HBSuperclass (HBSCategory)<HBProtocol> +@end + +@implementation HBSuperclass (HBSCategory) +@end + +@interface HBClass (HBCategory)<HBProtocol> +@end + +@implementation HBClass (HBCategory) +@end diff --git a/test/SemaObjC/property-in-class-extension.m b/test/SemaObjC/property-in-class-extension.m index a7b5130..022a487 100644 --- a/test/SemaObjC/property-in-class-extension.m +++ b/test/SemaObjC/property-in-class-extension.m @@ -37,11 +37,12 @@ void FUNC () { @interface rdar8747333 () - (NSObject *)bam; -- (NSObject *)warn; // expected-note {{method definition for 'warn' not found}} -- (void)setWarn : (NSObject *)val; // expected-note {{method definition for 'setWarn:' not found}} +- (NSObject *)warn; // expected-note {{method 'warn' declared here}} +- (void)setWarn : (NSObject *)val; // expected-note {{method 'setWarn:' declared here}} @end -@implementation rdar8747333 // expected-warning {{incomplete implementation}} +@implementation rdar8747333 // expected-warning {{method definition for 'warn' not found}} \ + // expected-warning {{method definition for 'setWarn:' not found}} @synthesize bar = _bar; @synthesize baz = _baz; @synthesize bam = _bam; diff --git a/test/SemaObjC/property-noninherited-availability-attr.m b/test/SemaObjC/property-noninherited-availability-attr.m new file mode 100644 index 0000000..79cdd3e --- /dev/null +++ b/test/SemaObjC/property-noninherited-availability-attr.m @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.8.0 -fsyntax-only -verify %s + +// This test case shows that 'availablity' and 'deprecated' does not inherit +// when a property is redeclared in a subclass. This is intentional. + +@interface NSObject @end +@protocol myProtocol +@property int myProtocolProperty __attribute__((availability(macosx,introduced=10.7,deprecated=10.8))); +@end + +@interface Foo : NSObject +@property int myProperty __attribute__((availability(macosx,introduced=10.7,deprecated=10.8))); // expected-note {{'myProperty' declared here}} \ + // expected-note {{method 'myProperty' declared here}} \ + // expected-note {{property 'myProperty' is declared deprecated here}} +@end + +@interface Bar : Foo <myProtocol> +@property int myProperty; // expected-note {{'myProperty' declared here}} +@property int myProtocolProperty; // expected-note {{'myProtocolProperty' declared here}} +@end + +void test(Foo *y, Bar *x) { + y.myProperty = 0; // expected-warning {{'myProperty' is deprecated: first deprecated in OS X 10.8}} + [y myProperty]; // expected-warning {{'myProperty' is deprecated: first deprecated in OS X 10.8}} + + x.myProperty = 1; // no-warning + [x myProperty]; // expected-warning {{'myProperty' is deprecated: first deprecated in OS X 10.8}} + + x.myProtocolProperty = 0; // no-warning + + [x myProtocolProperty]; // expected-warning {{'myProtocolProperty' is deprecated: first deprecated in OS X 10.8}} +} diff --git a/test/SemaObjC/property-user-setter.m b/test/SemaObjC/property-user-setter.m index 9ebad60..cda983c 100644 --- a/test/SemaObjC/property-user-setter.m +++ b/test/SemaObjC/property-user-setter.m @@ -89,7 +89,7 @@ void g(int); // expected-note {{passing argument to parameter here}} void f(C *c) { c.Foo = 17; // OK - g(c.Foo); // expected-error {{expected getter method not found on object of type 'C *'}} + g(c.Foo); // expected-error {{no getter method for read from property}} } @@ -132,7 +132,7 @@ int main (void) { 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 {{expected getter method not found on object of type 'rdar11363363 *'}} + return self.R; // expected-error {{no getter method for read from property}} } @end diff --git a/test/SemaObjC/protocol-archane.m b/test/SemaObjC/protocol-archane.m index 49c9851..788edf2 100644 --- a/test/SemaObjC/protocol-archane.m +++ b/test/SemaObjC/protocol-archane.m @@ -8,9 +8,9 @@ void bar(); void foo(id x) { bar((short<SomeProtocol>)x); // expected-error {{expected ')'}} expected-note {{to match this '('}} - bar((<SomeProtocol>)x); // expected-warning {{protocol qualifiers without 'id' is archaic}} + bar((<SomeProtocol>)x); // expected-warning {{protocol has no object type specified; defaults to qualified 'id'}} - [(<SomeProtocol>)x bar]; // expected-warning {{protocol qualifiers without 'id' is archaic}} + [(<SomeProtocol>)x bar]; // expected-warning {{protocol has no object type specified; defaults to qualified 'id'}} } @protocol MyProtocol @@ -37,6 +37,6 @@ Class <SomeProtocol> UnfortunateGCCExtension; @protocol Broken @end @interface Crash @end @implementation Crash -- (void)crashWith:(<Broken>)a { // expected-warning {{protocol qualifiers without 'id' is archaic}} +- (void)crashWith:(<Broken>)a { // expected-warning {{protocol has no object type specified; defaults to qualified 'id'}} } @end diff --git a/test/SemaObjC/related-result-type-inference.m b/test/SemaObjC/related-result-type-inference.m index b1d77dc..50aaf2d 100644 --- a/test/SemaObjC/related-result-type-inference.m +++ b/test/SemaObjC/related-result-type-inference.m @@ -175,7 +175,7 @@ void test_inference() { @implementation Fail - (id<X>) initWithX { - return (id)self; // expected-warning {{returning 'Fail *' from a function with incompatible result type 'id<X>'}} + return (id)self; // expected-warning {{casting 'Fail *' to incompatible type 'id<X>'}} } @end diff --git a/test/SemaObjC/selector-3.m b/test/SemaObjC/selector-3.m index 4c12a93..f968aeb 100644 --- a/test/SemaObjC/selector-3.m +++ b/test/SemaObjC/selector-3.m @@ -52,3 +52,32 @@ SEL func() } @end +// rdar://12938616 +@class NSXPCConnection; + +@interface NSObject +@end + +@interface INTF : NSObject +{ + NSXPCConnection *cnx; // Comes in as a parameter. +} +- (void) Meth; +@end + +extern SEL MySelector(SEL s); + +@implementation INTF +- (void) Meth { + if( [cnx respondsToSelector:MySelector(@selector( _setQueue: ))] ) // expected-warning {{unimplemented selector '_setQueue:'}} + { + } + + if( [cnx respondsToSelector:@selector( _setQueueXX: )] ) // No warning here. + { + } + if( [cnx respondsToSelector:(@selector( _setQueueXX: ))] ) // No warning here. + { + } +} +@end diff --git a/test/SemaObjC/super-property-notation.m b/test/SemaObjC/super-property-notation.m index 0c17bb9..4741d1b 100644 --- a/test/SemaObjC/super-property-notation.m +++ b/test/SemaObjC/super-property-notation.m @@ -1,5 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -// expected-no-diagnostics +// RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -verify %s @interface B +(int) classGetter; @@ -29,3 +28,25 @@ void f0() { int l2 = [A classGetter2]; } +// rdar://13349296 +__attribute__((objc_root_class)) @interface ClassBase +@property (nonatomic, retain) ClassBase * foo; +@end + +@implementation ClassBase +- (void) Meth:(ClassBase*)foo { + super.foo = foo; // expected-error {{'ClassBase' cannot use 'super' because it is a root class}} + [super setFoo:foo]; // expected-error {{'ClassBase' cannot use 'super' because it is a root class}} +} +@end + +@interface ClassDerived : ClassBase +@property (nonatomic, retain) ClassDerived * foo; +@end + +@implementation ClassDerived +- (void) Meth:(ClassBase*)foo { + super.foo = foo; // must work with no warning + [super setFoo:foo]; // works with no warning +} +@end diff --git a/test/SemaObjC/super.m b/test/SemaObjC/super.m index cf48c19..fd069af 100644 --- a/test/SemaObjC/super.m +++ b/test/SemaObjC/super.m @@ -51,8 +51,7 @@ void f(id super) { [super m]; } void f0(int super) { - [super m]; // expected-warning{{receiver type 'int' is not 'id'}} \ - expected-warning {{method '-m' not found (return type defaults to 'id')}} + [super m]; // expected-warning{{receiver type 'int' is not 'id'}} } void f1(id puper) { // expected-note {{'puper' declared here}} [super m]; // expected-error{{use of undeclared identifier 'super'}} diff --git a/test/SemaObjC/typo-correction.m b/test/SemaObjC/typo-correction.m new file mode 100644 index 0000000..3fd61e2 --- /dev/null +++ b/test/SemaObjC/typo-correction.m @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -fwarn-on-spellcheck + +@interface B +@property int x; +@end + +@interface S : B +@end + +// Spell-checking 'undefined' is ok. +undefined var; // expected-warning {{spell-checking initiated}} \ + // expected-error {{unknown type name}} + +typedef int super1; +@implementation S +-(void)foo { + // Spell-checking 'super' is not ok. + super.x = 0; + self.x = 0; +} +@end diff --git a/test/SemaObjC/undef-protocol-methods-1.m b/test/SemaObjC/undef-protocol-methods-1.m index 15ba1a1..25b1dad 100644 --- a/test/SemaObjC/undef-protocol-methods-1.m +++ b/test/SemaObjC/undef-protocol-methods-1.m @@ -28,10 +28,7 @@ // expected-note 2 {{required for direct or indirect protocol 'P2'}} @end -@implementation INTF // expected-warning {{incomplete implementation}} \ - // expected-warning 9 {{in protocol not implemented}} +@implementation INTF // expected-warning 9 {{in protocol not implemented}} - (void) DefP1proto{} - + (void) DefClsP3Proto{} - @end diff --git a/test/SemaObjC/warn-cast-of-sel-expr.m b/test/SemaObjC/warn-cast-of-sel-expr.m index 97915a0..1253db9 100644 --- a/test/SemaObjC/warn-cast-of-sel-expr.m +++ b/test/SemaObjC/warn-cast-of-sel-expr.m @@ -18,4 +18,7 @@ int main() { (void *const)s; // ok (const void *const)s; // ok + +// rdar://12859590 +(SEL)sel_registerName("foo"); // ok } diff --git a/test/SemaObjC/warn-deprecated-implementations.m b/test/SemaObjC/warn-deprecated-implementations.m index 5f7c2fd..f63962f 100644 --- a/test/SemaObjC/warn-deprecated-implementations.m +++ b/test/SemaObjC/warn-deprecated-implementations.m @@ -1,12 +1,13 @@ // RUN: %clang_cc1 -fsyntax-only -Wdeprecated-implementations -verify -Wno-objc-root-class %s // rdar://8973810 +// rdar://12717705 @protocol P - (void) D __attribute__((deprecated)); // expected-note {{method 'D' declared here}} @end @interface A <P> -+ (void)F __attribute__((deprecated)); // expected-note {{method 'F' declared here}} ++ (void)F __attribute__((deprecated)); @end @interface A() @@ -14,11 +15,19 @@ @end @implementation A -+ (void)F { } // expected-warning {{Implementing deprecated method}} ++ (void)F { } // No warning, implementing its own deprecated method - (void) D {} // expected-warning {{Implementing deprecated method}} - (void) E {} // expected-warning {{Implementing deprecated method}} @end +@interface A(CAT) +- (void) G __attribute__((deprecated)); +@end + +@implementation A(CAT) +- (void) G {} // No warning, implementing its own deprecated method +@end + __attribute__((deprecated)) @interface CL // expected-note 2 {{class declared here}} // expected-note 2 {{declared here}} @end diff --git a/test/SemaObjC/warn-direct-ivar-access.m b/test/SemaObjC/warn-direct-ivar-access.m index 088fe0f..283a00f 100644 --- a/test/SemaObjC/warn-direct-ivar-access.m +++ b/test/SemaObjC/warn-direct-ivar-access.m @@ -1,10 +1,10 @@ -// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -Wdirect-ivar-access -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -fobjc-default-synthesize-properties -Wdirect-ivar-access -verify -Wno-objc-root-class %s // rdar://6505197 __attribute__((objc_root_class)) @interface MyObject { @public id _myMaster; - id _isTickledPink; + id _isTickledPink; // expected-error {{existing instance variable '_isTickledPink' for property 'isTickledPink'}} int _myIntProp; } @property(retain) id myMaster; @@ -15,7 +15,7 @@ __attribute__((objc_root_class)) @interface MyObject { @implementation MyObject @synthesize myMaster = _myMaster; -@synthesize isTickledPink = _isTickledPink; // expected-error {{existing instance variable '_isTickledPink' for property 'isTickledPink'}} +@synthesize isTickledPink = _isTickledPink; // expected-note {{property synthesized here}} @synthesize myIntProp = _myIntProp; - (void) doSomething { @@ -54,3 +54,25 @@ id Test32(__weak ITest32 *x) { : (*x).ivar; // expected-error {{dereferencing a __weak pointer is not allowed}} } +// rdar://13142820 +@protocol PROTOCOL +@property (copy, nonatomic) id property_in_protocol; +@end + +__attribute__((objc_root_class)) @interface INTF <PROTOCOL> +@property (copy, nonatomic) id foo; +- (id) foo; +@end + +@interface INTF() +@property (copy, nonatomic) id foo1; +- (id) foo1; +@end + +@implementation INTF +- (id) foo { return _foo; } +- (id) property_in_protocol { return _property_in_protocol; } // expected-warning {{instance variable '_property_in_protocol' is being directly accessed}} +- (id) foo1 { return _foo1; } +@synthesize property_in_protocol = _property_in_protocol; +@end + diff --git a/test/SemaObjC/warn-isa-ref.m b/test/SemaObjC/warn-isa-ref.m index 9d7abd4..b1ffb4f 100644 --- a/test/SemaObjC/warn-isa-ref.m +++ b/test/SemaObjC/warn-isa-ref.m @@ -18,21 +18,19 @@ static void func() { id x; // rdar://8290002 - [(*x).isa self]; // expected-warning {{direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()}} - [x->isa self]; // expected-warning {{direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()}} + [(*x).isa self]; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}} + [x->isa self]; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}} Whatever *y; // GCC allows this, with the following warning: // instance variable 'isa' is @protected; this will be a hard error in the future // - // FIXME: see if we can avoid the 2 warnings that follow the error. + // FIXME: see if we can avoid the warning that follows the error. [(*y).isa self]; // expected-error {{instance variable 'isa' is protected}} \ - expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}} \ - expected-warning{{method '-self' not found (return type defaults to 'id')}} + expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}} [y->isa self]; // expected-error {{instance variable 'isa' is protected}} \ - expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}} \ - expected-warning{{method '-self' not found (return type defaults to 'id')}} + expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}} } // rdar://11702488 @@ -41,7 +39,7 @@ static void func() { @interface BaseClass { @public - Class isa; // expected-note 3 {{instance variable is declared here}} + Class isa; // expected-note 4 {{instance variable is declared here}} } @end @@ -72,12 +70,14 @@ static void func() { Subclass *x; SiblingClass *y; OtherClass *z; - (void)v->isa; // expected-warning {{direct access to objective-c's isa is deprecated}} - (void)w->isa; // expected-warning {{direct access to objective-c's isa is deprecated}} - (void)x->isa; // expected-warning {{direct access to objective-c's isa is deprecated}} - (void)y->isa; // expected-warning {{direct access to objective-c's isa is deprecated}} + (void)v->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}} + (void)w->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}} + (void)x->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}} + (void)y->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}} (void)z->isa; (void)u->isa; + + w->isa = 0; // expected-warning {{assignment to Objective-C's isa is deprecated in favor of object_setClass()}} } @end diff --git a/test/SemaObjC/warn-retain-block-property.m b/test/SemaObjC/warn-retain-block-property.m index 3a54baf..45823e3 100644 --- a/test/SemaObjC/warn-retain-block-property.m +++ b/test/SemaObjC/warn-retain-block-property.m @@ -1,6 +1,7 @@ -// RUN: %clang_cc1 -fsyntax-only -fblocks -fobjc-arc -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -fsyntax-only -fblocks -fobjc-arc -Wno-objc-root-class %s 2>&1 | FileCheck --check-prefix=CHECK-ARC %s // rdar://9829425 -// RUN: %clang_cc1 -fsyntax-only -fblocks -verify -Wno-objc-root-class %s + +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-objc-root-class %s 2>&1 | FileCheck %s // rdar://11761511 extern void doSomething(); @@ -10,12 +11,12 @@ extern void doSomething(); @public void (^aBlock)(void); } -@property (retain) void (^aBlock)(void); // expected-warning {{retain'ed block property does not copy the block - use copy attribute instead}} -@property (weak, retain) void (^aBlockW)(void); // expected-error {{property attributes 'retain' and 'weak' are mutually exclusive}} +@property (retain) void (^aBlock)(void); +@property (weak, retain) void (^aBlockW)(void); @property (strong, retain) void (^aBlockS)(void); // OK @property (readonly, retain) void (^aBlockR)(void); // OK -@property (copy, retain) void (^aBlockC)(void); // expected-error {{property attributes 'copy' and 'retain' are mutually exclusive}} -@property (assign, retain) void (^aBlockA)(void); // expected-error {{property attributes 'assign' and 'retain' are mutually exclusive}} +@property (copy, retain) void (^aBlockC)(void); +@property (assign, retain) void (^aBlockA)(void); @end @implementation Test @@ -30,3 +31,33 @@ int main() { t.aBlockS = ^{ doSomething(); }; } +// CHECK-ARC: 14:1: warning: retain'ed block property does not copy the block - use copy attribute instead +// CHECK-ARC: @property (retain) void (^aBlock)(void); +// CHECK-ARC: ^ +// CHECK-ARC: 15:1: error: property attributes 'retain' and 'weak' are mutually exclusive +// CHECK-ARC: @property (weak, retain) void (^aBlockW)(void); +// CHECK-ARC: ^ +// CHECK-ARC: 18:1: error: property attributes 'copy' and 'retain' are mutually exclusive +// CHECK-ARC: @property (copy, retain) void (^aBlockC)(void); +// CHECK-ARC: ^ +// CHECK-ARC: 19:1: error: property attributes 'assign' and 'retain' are mutually exclusive +// CHECK-ARC: @property (assign, retain) void (^aBlockA)(void); +// CHECK-ARC: ^ +// CHECK-ARC: 30:13: warning: assigning block literal to a weak property; object will be released after assignment +// CHECK-ARC: t.aBlockW = ^{ doSomething(); }; +// CHECK-ARC: ^ ~~~~~~~~~~~~~~~~~~~ +// CHECK-ARC: 2 warnings and 3 errors generated. + +// CHECK: 14:1: warning: retain'ed block property does not copy the block - use copy attribute instead +// CHECK: @property (retain) void (^aBlock)(void); +// CHECK: ^ +// CHECK: 15:1: error: property attributes 'retain' and 'weak' are mutually exclusive +// CHECK: @property (weak, retain) void (^aBlockW)(void); +// CHECK: ^ +// CHECK: 18:1: error: property attributes 'copy' and 'retain' are mutually exclusive +// CHECK: @property (copy, retain) void (^aBlockC)(void); +// CHECK: ^ +// CHECK: 19:1: error: property attributes 'assign' and 'retain' are mutually exclusive +// CHECK: @property (assign, retain) void (^aBlockA)(void); +// CHECK: ^ +// CHECK: 1 warning and 3 errors generated. diff --git a/test/SemaObjC/warning-missing-selector-name.m b/test/SemaObjC/warning-missing-selector-name.m index d43031e..a335e02 100644 --- a/test/SemaObjC/warning-missing-selector-name.m +++ b/test/SemaObjC/warning-missing-selector-name.m @@ -15,11 +15,11 @@ - method:(id) second:(id)second; // expected-warning {{'second' used as the name of the previous parameter rather than as part of the selector}} \ // expected-note {{introduce a parameter name to make 'second' part of the selector}} \ // expected-note {{or insert whitespace before ':' to use 'second' as parameter name and have an empty entry in the selector}} \ - // expected-note {{method definition for 'method::' not found}} + // expected-note {{method 'method::' declared here}} @end -@implementation INTF // expected-warning {{incomplete implementation}} +@implementation INTF // expected-warning {{method definition for 'method::' not found}} -(void) Name1:(id)Arg1 Name2:(id)Arg2{} -(void) Name1:(id) Name2:(id)Arg2 {} // expected-warning {{'Name2' used as the name of the previous parameter rather than as part of the selector}} \ // expected-note {{introduce a parameter name to make 'Name2' part of the selector}} \ diff --git a/test/SemaObjC/weak-property.m b/test/SemaObjC/weak-property.m index 141c35b..d306a92 100644 --- a/test/SemaObjC/weak-property.m +++ b/test/SemaObjC/weak-property.m @@ -4,7 +4,7 @@ @interface WeakPropertyTest { Class isa; __weak id value; - id x; + id x; // expected-error {{existing instance variable 'x' for __weak property 'x' must be __weak}} } @property (weak) id value1; @property __weak id value; @@ -19,6 +19,6 @@ @end @implementation WeakPropertyTest -@synthesize x; // expected-error {{existing instance variable 'x' for __weak property 'x' must be __weak}} +@synthesize x; // expected-note {{property synthesized here}} @dynamic value1, value, value2, v1,v2,v3,v4; @end |