diff options
Diffstat (limited to 'test/SemaObjC')
213 files changed, 2196 insertions, 394 deletions
diff --git a/test/SemaObjC/ClassPropertyNotObject.m b/test/SemaObjC/ClassPropertyNotObject.m new file mode 100644 index 000000000000..02ed40ae338b --- /dev/null +++ b/test/SemaObjC/ClassPropertyNotObject.m @@ -0,0 +1,15 @@ +// 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 +// rdar://10565506 + +@protocol P @end + +@interface I +@property Class<P> MyClass; +@property Class MyClass1; +@property void * VOIDSTAR; +@end + +@implementation I +@synthesize MyClass, MyClass1, VOIDSTAR; +@end diff --git a/test/SemaObjC/ContClassPropertyLookup.m b/test/SemaObjC/ContClassPropertyLookup.m index b3459c13e413..06a0ffae588c 100644 --- a/test/SemaObjC/ContClassPropertyLookup.m +++ b/test/SemaObjC/ContClassPropertyLookup.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface MyObject { int _foo; @@ -16,3 +16,23 @@ @implementation MyObject @synthesize foo = _foo; @end + +// rdar://10666594 +@interface MPMediaItem +@end + +@class MPMediaItem; + +@interface MPMediaItem () +@property (nonatomic, readonly) id title; +@end + +@interface PodcastEpisodesViewController +@end + +@implementation PodcastEpisodesViewController +- (id) Meth { + MPMediaItem *episode; + return episode.title; +} +@end diff --git a/test/SemaObjC/DoubleMethod.m b/test/SemaObjC/DoubleMethod.m index 98aa699a0fce..4eca4c701af7 100644 --- a/test/SemaObjC/DoubleMethod.m +++ b/test/SemaObjC/DoubleMethod.m @@ -1,12 +1,12 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -Wduplicate-method-match -fsyntax-only -verify -Wno-objc-root-class %s @interface Subclass { int ivar; } -- (void) method; -- (void) method; +- (void) method; // expected-note {{previous declaration is here}} +- (void) method; // expected-warning {{multiple declarations of method 'method' found and ignored}} @end @implementation Subclass diff --git a/test/SemaObjC/NSString-type.m b/test/SemaObjC/NSString-type.m new file mode 100644 index 000000000000..3b4857ae0e9e --- /dev/null +++ b/test/SemaObjC/NSString-type.m @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fblocks -fsyntax-only -verify %s +// rdar://10907410 + +void test(id pid, Class pclass) { + void (^block)(void) = @"help"; // expected-error {{initializing 'void (^)(void)' with an expression of incompatible type 'NSString *'}} + void (^block1)(void) = pid; + void (^block2)(void) = @"help"; // expected-error {{initializing 'void (^)(void)' with an expression of incompatible type 'NSString *'}} + void (^block3)(void) = @"help"; // expected-error {{initializing 'void (^)(void)' with an expression of incompatible type 'NSString *'}} +} + diff --git a/test/SemaObjC/alias-test-2.m b/test/SemaObjC/alias-test-2.m index 1f12b76055e8..6688db62e538 100644 --- a/test/SemaObjC/alias-test-2.m +++ b/test/SemaObjC/alias-test-2.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // Note: GCC doesn't produce any of the following errors. @interface Super @end // expected-note {{previous definition is here}} @@ -9,9 +9,9 @@ @compatibility_alias AliasForSuper Super; -@interface MyAlias : AliasForSuper // expected-error {{duplicate interface definition for class 'MyWpModule'}} +@implementation MyAlias : AliasForSuper // expected-error {{conflicting super class name 'Super'}} @end -@implementation MyAlias : AliasForSuper // expected-error {{conflicting super class name 'Super'}} +@interface MyAlias : AliasForSuper // expected-error {{duplicate interface definition for class 'MyWpModule'}} @end diff --git a/test/SemaObjC/arc-bridged-cast.m b/test/SemaObjC/arc-bridged-cast.m index 47476c83064d..56efe81d608b 100644 --- a/test/SemaObjC/arc-bridged-cast.m +++ b/test/SemaObjC/arc-bridged-cast.m @@ -1,7 +1,8 @@ // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -verify %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fblocks %s typedef const void *CFTypeRef; +CFTypeRef CFBridgingRetain(id X); +id CFBridgingRelease(CFTypeRef); typedef const struct __CFString *CFStringRef; @interface NSString @@ -36,8 +37,8 @@ void to_cf(id obj) { void fixits() { id obj1 = (id)CFCreateSomething(); // expected-error{{cast of C pointer type 'CFTypeRef' (aka 'const void *') 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 'CFTypeRef' (aka 'const void *') into ARC}} + // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'CFTypeRef' (aka 'const void *') into ARC}} CFTypeRef cf1 = (CFTypeRef)CreateSomething(); // expected-error{{cast of Objective-C pointer type 'id' to C pointer type 'CFTypeRef' (aka 'const void *') requires a bridged cast}} \ // expected-note{{use __bridge to convert directly (no change in ownership)}} \ - // expected-note{{use __bridge_retained to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}} + // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}} } diff --git a/test/SemaObjC/arc-cf.m b/test/SemaObjC/arc-cf.m index c1df3e0489f1..69662ea61078 100644 --- a/test/SemaObjC/arc-cf.m +++ b/test/SemaObjC/arc-cf.m @@ -1,14 +1,20 @@ // RUN: %clang_cc1 -fsyntax-only -fobjc-arc -verify %s +#if __has_feature(arc_cf_code_audited) +char _global[-1]; // expected-error {{declared as an array with a negative size}} +#endif + typedef const void *CFTypeRef; +CFTypeRef CFBridgingRetain(id X); +id CFBridgingRelease(CFTypeRef); typedef const struct __CFString *CFStringRef; extern CFStringRef CFMakeString0(void); extern CFStringRef CFCreateString0(void); void test0() { id x; - x = (id) CFMakeString0(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{__bridge_transfer to transfer}} - x = (id) CFCreateString0(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{__bridge_transfer to transfer}} + x = (id) CFMakeString0(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{CFBridgingRelease call to transfer}} + x = (id) CFCreateString0(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{CFBridgingRelease call to transfer}} } extern CFStringRef CFMakeString1(void) __attribute__((cf_returns_not_retained)); @@ -16,5 +22,24 @@ extern CFStringRef CFCreateString1(void) __attribute__((cf_returns_retained)); void test1() { id x; x = (id) CFMakeString1(); - x = (id) CFCreateString1(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{__bridge_transfer to transfer}} + x = (id) CFCreateString1(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{CFBridgingRelease call to transfer}} +} + +#define CF_AUDIT_BEGIN _Pragma("clang arc_cf_code_audited begin") +#define CF_AUDIT_END _Pragma("clang arc_cf_code_audited end") +#define CF_RETURNS_RETAINED __attribute__((cf_returns_retained)) +#define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained)) + +CF_AUDIT_BEGIN +extern CFStringRef CFMakeString2(void); +extern CFStringRef CFCreateString2(void) CF_RETURNS_NOT_RETAINED; +extern CFStringRef CFMakeString3(void) CF_RETURNS_RETAINED; +extern CFStringRef CFCreateString3(void); +CF_AUDIT_END +void test2() { + id x; + x = (id) CFMakeString2(); + x = (id) CFCreateString2(); + x = (id) CFMakeString3(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{CFBridgingRelease call to transfer}} + x = (id) CFCreateString3(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{CFBridgingRelease call to transfer}} } diff --git a/test/SemaObjC/arc-decls.m b/test/SemaObjC/arc-decls.m index 1084db86268f..8d5cca26a74c 100644 --- a/test/SemaObjC/arc-decls.m +++ b/test/SemaObjC/arc-decls.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -verify %s +// RUN: %clang_cc1 -fsyntax-only -fblocks -fobjc-arc -verify -Wno-objc-root-class %s // rdar://8843524 @@ -21,6 +21,11 @@ union u { }; @end +// rdar://10260525 +struct r10260525 { + id (^block) (); // expected-error {{ARC forbids blocks in structs or unions}} +}; + struct S { id __attribute__((objc_ownership(none))) i; void * vp; @@ -81,3 +86,14 @@ void func() - (id)not_ret:(id) b __attribute((ns_returns_retained)); // expected-error {{overriding method has mismatched ns_returns_retained attributes}} - (id)both__returns_not_retained:(id) b __attribute((ns_returns_not_retained)); @end + +// Test that we give a good diagnostic here that mentions the missing +// ownership qualifier. We don't want this to get suppressed because +// of an invalid conversion. +void test7(void) { + id x; + id *px = &x; // expected-error {{pointer to non-const type 'id' with no explicit ownership}} + + I *y; + J **py = &y; // expected-error {{pointer to non-const type 'J *' with no explicit ownership}} expected-warning {{incompatible pointer types initializing}} +} diff --git a/test/SemaObjC/arc-invalid.m b/test/SemaObjC/arc-invalid.m new file mode 100644 index 000000000000..c736ed4a167c --- /dev/null +++ b/test/SemaObjC/arc-invalid.m @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fblocks -verify %s + +// rdar://problem/10982793 +// [p foo] in ARC creates a cleanup. +// The plus is invalid and causes the cleanup to go unbound. +// Don't crash. +@interface A +- (id) foo; +@end +void takeBlock(void (^)(void)); +void test0(id p) { + takeBlock(^{ [p foo] + p; }); // expected-error {{invalid operands to binary expression}} +} + +void test1(void) { + __autoreleasing id p; // expected-note {{'p' declared here}} + takeBlock(^{ (void) p; }); // expected-error {{cannot capture __autoreleasing variable in a block}} +} diff --git a/test/SemaObjC/arc-jump-block.m b/test/SemaObjC/arc-jump-block.m index 9b44606c59d3..26a1fc839d73 100644 --- a/test/SemaObjC/arc-jump-block.m +++ b/test/SemaObjC/arc-jump-block.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -verify -Wno-objc-root-class %s // rdar://9535237 typedef struct dispatch_queue_s *dispatch_queue_t; @@ -82,3 +82,16 @@ extern __attribute__((visibility("default"))) struct dispatch_queue_s _dispatch_ - (void)pageLeft {} - (void)pageRight {} @end + +// Test 2. rdar://problem/11150919 +int test2(id obj, int state) { // expected-note {{jump enters lifetime of block}} FIXME: wierd location + switch (state) { + case 0: + (void) ^{ (void) obj; }; + return 0; + + default: // expected-error {{switch case is in protected scope}} + return 1; + } +} + diff --git a/test/SemaObjC/arc-no-runtime.m b/test/SemaObjC/arc-no-runtime.m index 49c439b16760..b75064f77651 100644 --- a/test/SemaObjC/arc-no-runtime.m +++ b/test/SemaObjC/arc-no-runtime.m @@ -1,8 +1,9 @@ -// RUN: %clang_cc1 -fobjc-arc -verify %s +// RUN: %clang_cc1 -fobjc-arc -verify -Wno-objc-root-class %s // rdar://problem/9150784 void test(void) { __weak id x; // expected-error {{the current deployment target does not support automated __weak references}} + __weak void *v; // expected-warning {{'__weak' only applies to objective-c object or block pointer types}} } @interface A diff --git a/test/SemaObjC/arc-objc-lifetime.m b/test/SemaObjC/arc-objc-lifetime.m new file mode 100644 index 000000000000..03260e8cdd4a --- /dev/null +++ b/test/SemaObjC/arc-objc-lifetime.m @@ -0,0 +1,42 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s +// rdar://10244607 + +typedef const struct __CFString * CFStringRef; +@class NSString; + +NSString *CFBridgingRelease(); + +typedef NSString * PNSString; + +typedef __autoreleasing NSString * AUTORELEASEPNSString; + +@interface I @end + +@implementation I +- (CFStringRef)myString +{ + CFStringRef myString = + (__bridge CFStringRef) (__strong NSString *)CFBridgingRelease(); // expected-error {{explicit ownership qualifier on cast result has no effect}} + + myString = + (__bridge CFStringRef) (__autoreleasing PNSString) CFBridgingRelease(); // expected-error {{explicit ownership qualifier on cast result has no effect}} + myString = + (__bridge CFStringRef) (AUTORELEASEPNSString) CFBridgingRelease(); // OK + myString = + (__bridge CFStringRef) (typeof(__strong NSString *)) CFBridgingRelease(); // expected-error {{explicit ownership qualifier on cast result has no effect}} + return myString; +} + +- (void)decodeValueOfObjCType:(const char *)type at:(void *)addr { + __autoreleasing id *stuff = (__autoreleasing id *)addr; +} +@end + +// rdar://problem/10711456 +__strong I *__strong test1; // expected-error {{the type 'I *__strong' is already explicitly ownership-qualified}} +__strong I *(__strong test2); // expected-error {{the type 'I *__strong' is already explicitly ownership-qualified}} +__strong I *(__strong (test3)); // expected-error {{the type 'I *__strong' is already explicitly ownership-qualified}} +__unsafe_unretained __typeof__(test3) test4; +typedef __strong I *strong_I; +__unsafe_unretained strong_I test5; diff --git a/test/SemaObjC/arc-peformselector.m b/test/SemaObjC/arc-peformselector.m index c015eb871150..dec09e33ed68 100644 --- a/test/SemaObjC/arc-peformselector.m +++ b/test/SemaObjC/arc-peformselector.m @@ -2,12 +2,12 @@ // rdar://9659270 @interface NSObject -- (id)copy; // expected-note {{method declared here}} -- (id) test __attribute__((ns_returns_retained)); // expected-note {{method declared here}} -+ (id) new ; // expected-note {{method declared here}} +- (id)copy; // expected-note {{method 'copy' declared here}} +- (id) test __attribute__((ns_returns_retained)); // expected-note {{method 'test' declared here}} ++ (id) new ; // expected-note {{method 'new' declared here}} - (id) init __attribute__((ns_returns_not_retained)); - (id)PlusZero; -- (id)PlusOne __attribute__((ns_returns_retained)); // expected-note {{method declared here}} +- (id)PlusOne __attribute__((ns_returns_retained)); // expected-note {{method 'PlusOne' declared here}} @end @interface I : NSObject diff --git a/test/SemaObjC/arc-property-lifetime.m b/test/SemaObjC/arc-property-lifetime.m index 9cc3ada15fad..fad37ccbf463 100644 --- a/test/SemaObjC/arc-property-lifetime.m +++ b/test/SemaObjC/arc-property-lifetime.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s // rdar://9340606 @interface Foo { @@ -125,3 +125,46 @@ @synthesize controllerClass = _controllerClass; @synthesize controllerId = _controllerId; @end + +// rdar://10630891 +@interface UIView @end +@class UIColor; + +@interface UIView(UIViewRendering) +@property(nonatomic,copy) UIColor *backgroundColor; +@end + +@interface UILabel : UIView +@end + +@interface MyView +@property (strong) UILabel *label; +@end + +@interface MyView2 : MyView @end + +@implementation MyView2 +- (void)foo { + super.label.backgroundColor = 0; +} +@end + +// rdar://10694932 +@interface Baz +@property id prop; +@property __strong id strong_prop; +@property (strong) id strong_attr_prop; +@property (strong) __strong id realy_strong_attr_prop; ++ (id) alloc; +- (id) init; +- (id) implicit; +- (void) setImplicit : (id) arg; +@end + +void foo(Baz *f) { + f.prop = [[Baz alloc] init]; + f.strong_prop = [[Baz alloc] init]; + f.strong_attr_prop = [[Baz alloc] init]; + f.realy_strong_attr_prop = [[Baz alloc] init]; + f.implicit = [[Baz alloc] init]; +} diff --git a/test/SemaObjC/arc-property.m b/test/SemaObjC/arc-property.m index 299311859203..2599fb9848f2 100644 --- a/test/SemaObjC/arc-property.m +++ b/test/SemaObjC/arc-property.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -verify -Wno-objc-root-class %s // rdar://9309489 @interface MyClass { @@ -46,3 +46,12 @@ @synthesize z; // suppressed @end +// rdar://problem/10904479 +// Don't crash. +@interface Test2 +// Minor FIXME: kill the redundant error +@property (strong) UndeclaredClass *test2; // expected-error {{unknown type name 'UndeclaredClass'}} expected-error {{must be of object type}} +@end +@implementation Test2 +@synthesize test2; +@end diff --git a/test/SemaObjC/arc-readonly-property-ivar-1.m b/test/SemaObjC/arc-readonly-property-ivar-1.m new file mode 100644 index 000000000000..c773f26cc113 --- /dev/null +++ b/test/SemaObjC/arc-readonly-property-ivar-1.m @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -fobjc-default-synthesize-properties -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fobjc-arc -fsyntax-only -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -x objective-c++ -fobjc-default-synthesize-properties -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fobjc-arc -fsyntax-only -verify -Wno-objc-root-class %s +// rdar:// 10558871 + +@interface PP +@property (readonly) id ReadOnlyPropertyNoBackingIvar; +@property (readonly) id ReadOnlyProperty; +@property (readonly) id ReadOnlyPropertyX; +@end + +@implementation PP { +__weak id _ReadOnlyProperty; +} +@synthesize ReadOnlyPropertyNoBackingIvar; +@synthesize ReadOnlyProperty = _ReadOnlyProperty; +@synthesize ReadOnlyPropertyX = _ReadOnlyPropertyX; +@end + +@interface DD +@property (readonly) id ReadOnlyProperty; +@property (readonly) id ReadOnlyPropertyStrong; +@property (readonly) id ReadOnlyPropertyNoBackingIvar; +@end + +@implementation DD { +__weak id _ReadOnlyProperty; +__strong id _ReadOnlyPropertyStrong; +} +@end diff --git a/test/SemaObjC/arc-readonly-property-ivar.m b/test/SemaObjC/arc-readonly-property-ivar.m new file mode 100644 index 000000000000..635b9fec71d1 --- /dev/null +++ b/test/SemaObjC/arc-readonly-property-ivar.m @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fobjc-arc -fsyntax-only -verify -Wno-objc-root-class %s +// rdar:// 10558871 + +@interface PP +@property (readonly) id ReadOnlyPropertyNoBackingIvar; +@property (readonly) id ReadOnlyProperty; +@property (readonly) id ReadOnlyPropertyX; +@end + +@implementation PP { +__weak id _ReadOnlyProperty; +} +@synthesize ReadOnlyPropertyNoBackingIvar; +@synthesize ReadOnlyProperty = _ReadOnlyProperty; +@synthesize ReadOnlyPropertyX = _ReadOnlyPropertyX; +@end diff --git a/test/SemaObjC/arc-retain-block-property.m b/test/SemaObjC/arc-retain-block-property.m index c7d043004948..3b66d149302c 100644 --- a/test/SemaObjC/arc-retain-block-property.m +++ b/test/SemaObjC/arc-retain-block-property.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -fblocks -fobjc-arc -verify %s +// RUN: %clang_cc1 -fsyntax-only -fblocks -fobjc-arc -verify -Wno-objc-root-class %s // rdar://9829425 extern void doSomething(); diff --git a/test/SemaObjC/arc-setter-property-match.m b/test/SemaObjC/arc-setter-property-match.m index 0de0a11f1bbe..9158b09a47e7 100644 --- a/test/SemaObjC/arc-setter-property-match.m +++ b/test/SemaObjC/arc-setter-property-match.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -verify -Wno-objc-root-class %s // rdar://10156674 @class NSArray; diff --git a/test/SemaObjC/arc-type-conversion.m b/test/SemaObjC/arc-type-conversion.m index 01f61bd4b674..5cf2cf4b745e 100644 --- a/test/SemaObjC/arc-type-conversion.m +++ b/test/SemaObjC/arc-type-conversion.m @@ -1,5 +1,9 @@ // RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -verify -fblocks %s +typedef const void * CFTypeRef; +CFTypeRef CFBridgingRetain(id X); +id CFBridgingRelease(CFTypeRef); + void * cvt(id arg) { void* voidp_val; @@ -12,12 +16,15 @@ void * cvt(id arg) (void)(void*)voidp_val; (void)(void**)arg; // expected-error {{cast of an Objective-C pointer to 'void **' is disallowed with ARC}} cvt((void*)arg); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} \ - // expected-error {{implicit conversion of a non-Objective-C pointer type 'void *' to 'id' is disallowed with ARC}} \ - // expected-note{{use __bridge to convert directly (no change in ownership)}} \ - // expected-note{{use __bridge_retained to make an ARC object available as a +1 'void *'}} + // expected-error {{implicit conversion of C pointer type 'void *' to Objective-C pointer type 'id' requires a bridged cast}} \ + // expected-note 2 {{use __bridge to convert directly (no change in ownership)}} \ + // expected-note {{use CFBridgingRetain call to make an ARC object available as a +1 'void *'}} \ + // expected-note {{use CFBridgingRelease call to transfer ownership of a +1 'void *' into ARC}} cvt(0); (void)(__strong id**)(0); - return arg; // expected-error {{implicit conversion of an Objective-C pointer to 'void *' is disallowed with ARC}} + return arg; // expected-error {{implicit conversion of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} \ + // expected-note {{use __bridge to convert directly (no change in ownership)}} \ + // expected-note {{use CFBridgingRetain call to make an ARC object available as a +1 'void *'}} } void to_void(__strong id *sip, __weak id *wip, @@ -74,4 +81,18 @@ void ownership_transfer_in_cast(void *vp, Block *pblk) { Block_strong blk_strong1; Block_strong blk_strong2 = (Block)blk_strong1; Block_autoreleasing *blk_auto = (Block*)pblk; + + id lv; + (void)(id)&lv; // expected-error {{cast of an indirect pointer to an Objective-C pointer to 'id'}} + (void)(id*)lv; // expected-error {{cast of an Objective-C pointer to '__strong id *'}} + (void)(NSString*)&lv; // expected-error {{cast of an indirect pointer to an Objective-C pointer to 'NSString *'}} + (void)(NSString**)lv; // expected-error {{cast of an Objective-C pointer to 'NSString *__strong *'}} + (void)(Block)&lv; // expected-error {{cast of an indirect pointer to an Objective-C pointer to 'Block'}} + (void)(Block*)lv; // expected-error {{cast of an Objective-C pointer to '__strong Block *'}} +} + +// <rdar://problem/10486347> +void conversion_in_conditional(id a, void* b) { + id c = 1 ? a : b; // expected-error {{operands to conditional of types 'id' and 'void *' are incompatible in ARC mode}} + id d = 1 ? b : a; // expected-error {{operands to conditional of types 'void *' and 'id' are incompatible in ARC mode}} } diff --git a/test/SemaObjC/arc-unavailable-for-weakref.m b/test/SemaObjC/arc-unavailable-for-weakref.m index 6db2155f8c64..8498de6d9a11 100644 --- a/test/SemaObjC/arc-unavailable-for-weakref.m +++ b/test/SemaObjC/arc-unavailable-for-weakref.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s // rdar://9693477 __attribute__((objc_arc_weak_reference_unavailable)) @@ -15,7 +15,8 @@ int main() { id obj; ns1 = (__weak sub *)obj; // expected-error {{assignment of a weak-unavailable object to a __weak object}} \ - // expected-error {{class is incompatible with __weak references}} + // expected-error {{class is incompatible with __weak references}} \ + // expected-error {{explicit ownership qualifier on cast result has no effect}} } // rdar://9732636 @@ -30,7 +31,8 @@ NOWEAK * Test1() { weak1 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} __weak id weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} - return (__weak id)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK *' to a __weak object of type '__weak id'}} + return (__weak id)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK *' to a __weak object of type '__weak id'}} \ + // expected-error {{explicit ownership qualifier on cast result has no effect}} } @protocol P @end @@ -42,6 +44,21 @@ NOWEAK<P, P1> * Test2() { weak1 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} __weak id<P> weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} - return (__weak id<P>)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK<P,P1> *' to a __weak object of type '__weak id<P>'}} + return (__weak id<P>)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK<P,P1> *' to a __weak object of type '__weak id<P>'}} \ + // expected-error {{explicit ownership qualifier on cast result has no effect}} } +// rdar://10535245 +__attribute__((objc_arc_weak_reference_unavailable)) +@interface NSFont +@end + +@interface I +{ +} +@property (weak) NSFont *font; // expected-note {{property declared here}} +@end + +@implementation I +@synthesize font = _font; // expected-error {{synthesis of a weak-unavailable property is disallowed because it requires synthesis of an ivar of the __weak object}} +@end diff --git a/test/SemaObjC/arc-unbridged-cast.m b/test/SemaObjC/arc-unbridged-cast.m index 8b835a14986d..7d5a6b007b38 100644 --- a/test/SemaObjC/arc-unbridged-cast.m +++ b/test/SemaObjC/arc-unbridged-cast.m @@ -1,6 +1,10 @@ // // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -verify %s typedef const struct __CFString * CFStringRef; +typedef const void * CFTypeRef; +CFTypeRef CFBridgingRetain(id X); +id CFBridgingRelease(CFTypeRef); + @interface Object @property CFStringRef property; @@ -35,15 +39,15 @@ void test1(int cond) { x = (id) (cond ? (void*) 0 : auditedString()); x = (id) (cond ? (CFStringRef) @"help" : auditedString()); - x = (id) unauditedString(); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use __bridge_transfer to}} - x = (id) (cond ? unauditedString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use __bridge_transfer to}} - x = (id) (cond ? (void*) 0 : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use __bridge_transfer to}} - x = (id) (cond ? (CFStringRef) @"help" : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use __bridge_transfer to}} + x = (id) unauditedString(); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}} + x = (id) (cond ? unauditedString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}} + x = (id) (cond ? (void*) 0 : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}} + x = (id) (cond ? (CFStringRef) @"help" : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}} - x = (id) auditedCreateString(); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use __bridge_transfer to}} - x = (id) (cond ? auditedCreateString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use __bridge_transfer to}} - x = (id) (cond ? (void*) 0 : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use __bridge_transfer to}} - x = (id) (cond ? (CFStringRef) @"help" : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use __bridge_transfer to}} + x = (id) auditedCreateString(); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}} + x = (id) (cond ? auditedCreateString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}} + x = (id) (cond ? (void*) 0 : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}} + x = (id) (cond ? (CFStringRef) @"help" : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}} x = (id) [object property]; x = (id) (cond ? [object property] : (void*) 0); @@ -70,3 +74,50 @@ void test1(int cond) { x = (id) (cond ? (void*) 0 : [object newString]); x = (id) (cond ? (CFStringRef) @"help" : [object newString]); // a bit questionable } + +// rdar://problem/10246264 +@interface CFTaker +- (void) takeOrdinary: (CFStringRef) arg; +- (void) takeVariadic: (int) n, ...; +- (void) takeConsumed: (CFStringRef __attribute__((cf_consumed))) arg; +@end +void testCFTaker(CFTaker *taker, id string) { + [taker takeOrdinary: (CFStringRef) string]; + [taker takeVariadic: 1, (CFStringRef) string]; + [taker takeConsumed: (CFStringRef) string]; // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}} +} + +void takeCFOrdinaryUnaudited(CFStringRef arg); +void takeCFVariadicUnaudited(int n, ...); +void takeCFConsumedUnaudited(CFStringRef __attribute__((cf_consumed)) arg); +#pragma clang arc_cf_code_audited begin +void takeCFOrdinaryAudited(CFStringRef arg); +void takeCFVariadicAudited(int n, ...); +void takeCFConsumedAudited(CFStringRef __attribute__((cf_consumed)) arg); +#pragma clang arc_cf_code_audited end + +void testTakerFunctions(id string) { + takeCFOrdinaryUnaudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}} + takeCFVariadicUnaudited(1, (CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}} + takeCFConsumedUnaudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}} + + void (*taker)(CFStringRef) = 0; + taker((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}} + + takeCFOrdinaryAudited((CFStringRef) string); + takeCFVariadicAudited(1, (CFStringRef) string); + takeCFConsumedAudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}} +} + +void testTakerFunctions_parens(id string) { + takeCFOrdinaryUnaudited(((CFStringRef) string)); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}} + takeCFVariadicUnaudited(1, ((CFStringRef) string)); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}} + takeCFConsumedUnaudited(((CFStringRef) string)); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}} + + void (*taker)(CFStringRef) = 0; + taker(((CFStringRef) string)); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}} + + takeCFOrdinaryAudited(((CFStringRef) string)); + takeCFVariadicAudited(1, ((CFStringRef) string)); + takeCFConsumedAudited(((CFStringRef) string)); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}} +} diff --git a/test/SemaObjC/arc-unsafe-assigns.m b/test/SemaObjC/arc-unsafe-assigns.m index 6dba18ba073b..1805b852fb18 100644 --- a/test/SemaObjC/arc-unsafe-assigns.m +++ b/test/SemaObjC/arc-unsafe-assigns.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s // rdar://9495837 @interface Foo { diff --git a/test/SemaObjC/arc.m b/test/SemaObjC/arc.m index ed6e60d8dc2f..9c3b298cb561 100644 --- a/test/SemaObjC/arc.m +++ b/test/SemaObjC/arc.m @@ -1,6 +1,9 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -verify -Wno-objc-root-class %s typedef unsigned long NSUInteger; +typedef const void * CFTypeRef; +CFTypeRef CFBridgingRetain(id X); +id CFBridgingRelease(CFTypeRef); void test0(void (*fn)(int), int val) { fn(val); @@ -36,15 +39,13 @@ void test1(A *a) { } @end -__weak __strong id x; // expected-error {{the type '__strong id' already has retainment attributes}} - // rdar://8843638 @interface I -- (id)retain; // expected-note {{method declared here}} -- (id)autorelease; // expected-note {{method declared here}} -- (oneway void)release; // expected-note {{method declared here}} -- (NSUInteger)retainCount; // expected-note {{method declared here}} +- (id)retain; // expected-note {{method 'retain' declared here}} +- (id)autorelease; // expected-note {{method 'autorelease' declared here}} +- (oneway void)release; // expected-note {{method 'release' declared here}} +- (NSUInteger)retainCount; // expected-note {{method 'retainCount' declared here}} @end @implementation I @@ -189,13 +190,13 @@ void test7_unsafe(void) { - (id) init50 { return 0; } - (void) init01 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} \ - // expected-warning{{ method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}} + // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}} - (void) init11 {} - (void) init21 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} - (void) init31 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} \ - // expected-warning{{ method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}} + // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}} - (void) init41 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} \ - // expected-warning{{ method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}} + // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}} - (void) init51 {} - (Test8_incomplete*) init02 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \ @@ -263,8 +264,8 @@ void test11(id op, void *vp) { b = (vp == nil); b = (nil == vp); - b = (vp == op); // expected-error {{implicit conversion of an Objective-C pointer to 'void *'}} - b = (op == vp); // expected-error {{implicit conversion of a non-Objective-C pointer type 'void *' to 'id'}} + b = (vp == op); // expected-error {{implicit conversion of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} expected-note {{use __bridge}} expected-note {{use CFBridgingRetain call}} + b = (op == vp); // expected-error {{implicit conversion of C pointer type 'void *' to Objective-C pointer type 'id' requires a bridged cast}} expected-note {{use __bridge}} expected-note {{use CFBridgingRelease call}} } void test12(id collection) { @@ -294,6 +295,16 @@ void test12(id collection) { } @end +// <rdar://problem/10274056> +@interface Test13_B +- (id) consumesSelf __attribute__((ns_consumes_self)); +@end +@implementation Test13_B +- (id) consumesSelf { + self = 0; // no-warning +} +@end + // rdar://problem/9172151 @class Test14A, Test14B; void test14() { @@ -368,7 +379,7 @@ void test16(void) { [v test16_6: 0]; } -@class Test17; +@class Test17; // expected-note 2{{forward declaration of class here}} @protocol Test17p - (void) test17; + (void) test17; @@ -393,11 +404,11 @@ struct Test19 *const test19b = 0; void test19(void) { id x; x = (id) test19a; // expected-error {{bridged cast}} \ - // expected-note{{use __bridge to convert directly (no change in ownership))}} \ - // expected-note{{use __bridge_transfer to transfer ownership of a +1 'struct Test19 *' into ARC}} + // expected-note{{use __bridge to convert directly (no change in ownership)}} \ + // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'struct Test19 *' into ARC}} x = (id) test19b; // expected-error {{bridged cast}} \ // expected-note{{use __bridge to convert directly (no change in ownership)}} \ - // expected-note{{use __bridge_transfer to transfer ownership of a +1 'struct Test19 *' into ARC}} + // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'struct Test19 *' into ARC}} } // rdar://problem/8951453 @@ -492,18 +503,18 @@ void test26(id y) { id myProp2; } @property id x; -@property (readonly) id ro; // expected-note {{declared here}} +@property (readonly) id ro; @property (readonly) id custom_ro; @property int y; -@property (readonly) id myProp1; +@property (readonly) __weak id myProp1; @property (readonly) id myProp2; @property (readonly) __strong id myProp3; @end @implementation Test27 @synthesize x; -@synthesize ro; // expected-error {{ARC forbids synthesizing a property of an Objective-C object with unspecified ownership or storage attribute}} +@synthesize ro; @synthesize y; @synthesize myProp1 = _myProp1; @@ -641,7 +652,7 @@ void test36(int first, ...) { __builtin_va_end(arglist); } -@class Test37; +@class Test37; // expected-note{{forward declaration of class here}} void test37(Test37 *c) { for (id y in c) { // expected-error {{collection expression type 'Test37' is a forward declaration}} (void) y; diff --git a/test/SemaObjC/assign-rvalue-message.m b/test/SemaObjC/assign-rvalue-message.m index 8cbce8e2ee54..1105d5e743a9 100644 --- a/test/SemaObjC/assign-rvalue-message.m +++ b/test/SemaObjC/assign-rvalue-message.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s -// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin10 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin10 -fsyntax-only -verify -Wno-objc-root-class %s // rdar://9005189 @interface Foo diff --git a/test/SemaObjC/atomoic-property-synnthesis-rules.m b/test/SemaObjC/atomoic-property-synnthesis-rules.m index 2061a779dc57..b681558220da 100644 --- a/test/SemaObjC/atomoic-property-synnthesis-rules.m +++ b/test/SemaObjC/atomoic-property-synnthesis-rules.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s /* Conditions for warning: @@ -107,8 +107,10 @@ // read-write - might warn @property int GetSet; -@property int Get; // expected-note {{property declared here}} -@property int Set; // expected-note {{property declared here}} +@property int Get; // expected-note {{property declared here}} \ + // expected-note {{setter and getter must both be synthesized}} +@property int Set; // expected-note {{property declared here}} \ + // expected-note {{setter and getter must both be synthesized}} @property int None; @property(nonatomic) int GetSet_Nonatomic; @property(nonatomic) int Get_Nonatomic; @@ -127,8 +129,10 @@ // read-only in class, read-write in class extension - might warn @property(readonly) int GetSet_ReadWriteInExt; -@property(readonly) int Get_ReadWriteInExt; // expected-note {{property declared here}} -@property(readonly) int Set_ReadWriteInExt; // expected-note {{property declared here}} +@property(readonly) int Get_ReadWriteInExt; // expected-note {{property declared here}} \ + // expected-note {{setter and getter must both be synthesized}} +@property(readonly) int Set_ReadWriteInExt; // expected-note {{property declared here}} \ + // expected-note {{setter and getter must both be synthesized}} @property(readonly) int None_ReadWriteInExt; @property(nonatomic,readonly) int GetSet_Nonatomic_ReadWriteInExt; @property(nonatomic,readonly) int Get_Nonatomic_ReadWriteInExt; @@ -138,8 +142,10 @@ // same as above, but @synthesize follows the hand-written methods - might warn @property int GetSet_LateSynthesize; -@property int Get_LateSynthesize; // expected-note {{property declared here}} -@property int Set_LateSynthesize; // expected-note {{property declared here}} +@property int Get_LateSynthesize; // expected-note {{property declared here}} \ + // expected-note {{setter and getter must both be synthesized}} +@property int Set_LateSynthesize; // expected-note {{property declared here}} \ + // expected-note {{setter and getter must both be synthesized}} @property int None_LateSynthesize; @property(nonatomic) int GetSet_Nonatomic_LateSynthesize; @property(nonatomic) int Get_Nonatomic_LateSynthesize; @@ -156,8 +162,10 @@ @property(nonatomic,readonly) int None_Nonatomic_ReadOnly_LateSynthesize; @property(readonly) int GetSet_ReadWriteInExt_LateSynthesize; -@property(readonly) int Get_ReadWriteInExt_LateSynthesize; // expected-note {{property declared here}} -@property(readonly) int Set_ReadWriteInExt_LateSynthesize; // expected-note {{property declared here}} +@property(readonly) int Get_ReadWriteInExt_LateSynthesize; // expected-note {{property declared here}} \ + // expected-note {{setter and getter must both be synthesized}} +@property(readonly) int Set_ReadWriteInExt_LateSynthesize; // expected-note {{property declared here}} \ + // expected-note {{setter and getter must both be synthesized}} @property(readonly) int None_ReadWriteInExt_LateSynthesize; @property(nonatomic,readonly) int GetSet_Nonatomic_ReadWriteInExt_LateSynthesize; @property(nonatomic,readonly) int Get_Nonatomic_ReadWriteInExt_LateSynthesize; @@ -240,10 +248,8 @@ GET(GetSet) SET(GetSet) -GET(Get) // expected-warning {{writable atomic property 'Get' cannot pair a synthesized setter with a user defined getter}} \ - // expected-note {{setter and getter must both be synthesized}} -SET(Set) // expected-warning {{writable atomic property 'Set' cannot pair a synthesized getter with a user defined setter}} \ - // expected-note {{setter and getter must both be synthesized}} +GET(Get) // expected-warning {{writable atomic property 'Get' cannot pair a synthesized setter with a user defined getter}} +SET(Set) // expected-warning {{writable atomic property 'Set' cannot pair a synthesized getter with a user defined setter}} GET(GetSet_Nonatomic) SET(GetSet_Nonatomic) GET(Get_Nonatomic) @@ -260,10 +266,8 @@ SET(Set_Nonatomic_ReadOnly) GET(GetSet_ReadWriteInExt) SET(GetSet_ReadWriteInExt) -GET(Get_ReadWriteInExt) // expected-warning {{writable atomic property 'Get_ReadWriteInExt' cannot pair a synthesized setter with a user defined getter}} \ - // expected-note {{setter and getter must both be synthesized}} -SET(Set_ReadWriteInExt) // expected-warning {{writable atomic property 'Set_ReadWriteInExt' cannot pair a synthesized getter with a user defined setter}} \ - // expected-note {{setter and getter must both be synthesized}} +GET(Get_ReadWriteInExt) // expected-warning {{writable atomic property 'Get_ReadWriteInExt' cannot pair a synthesized setter with a user defined getter}} +SET(Set_ReadWriteInExt) // expected-warning {{writable atomic property 'Set_ReadWriteInExt' cannot pair a synthesized getter with a user defined setter}} GET(GetSet_Nonatomic_ReadWriteInExt) SET(GetSet_Nonatomic_ReadWriteInExt) GET(Get_Nonatomic_ReadWriteInExt) @@ -272,10 +276,8 @@ SET(Set_Nonatomic_ReadWriteInExt) GET(GetSet_LateSynthesize) SET(GetSet_LateSynthesize) -GET(Get_LateSynthesize) // expected-warning {{writable atomic property 'Get_LateSynthesize' cannot pair a synthesized setter with a user defined getter}} \ - // expected-note {{setter and getter must both be synthesized}} -SET(Set_LateSynthesize) // expected-warning {{writable atomic property 'Set_LateSynthesize' cannot pair a synthesized getter with a user defined setter}} \ - // expected-note {{setter and getter must both be synthesized}} +GET(Get_LateSynthesize) // expected-warning {{writable atomic property 'Get_LateSynthesize' cannot pair a synthesized setter with a user defined getter}} +SET(Set_LateSynthesize) // expected-warning {{writable atomic property 'Set_LateSynthesize' cannot pair a synthesized getter with a user defined setter}} GET(GetSet_Nonatomic_LateSynthesize) SET(GetSet_Nonatomic_LateSynthesize) GET(Get_Nonatomic_LateSynthesize) @@ -292,10 +294,8 @@ SET(Set_Nonatomic_ReadOnly_LateSynthesize) GET(GetSet_ReadWriteInExt_LateSynthesize) SET(GetSet_ReadWriteInExt_LateSynthesize) -GET(Get_ReadWriteInExt_LateSynthesize) // expected-warning {{writable atomic property 'Get_ReadWriteInExt_LateSynthesize' cannot pair a synthesized setter with a user defined getter}} \ - // expected-note {{setter and getter must both be synthesized}} -SET(Set_ReadWriteInExt_LateSynthesize) // expected-warning {{writable atomic property 'Set_ReadWriteInExt_LateSynthesize' cannot pair a synthesized getter with a user defined setter}} \ - // expected-note {{setter and getter must both be synthesized}} +GET(Get_ReadWriteInExt_LateSynthesize) // expected-warning {{writable atomic property 'Get_ReadWriteInExt_LateSynthesize' cannot pair a synthesized setter with a user defined getter}} +SET(Set_ReadWriteInExt_LateSynthesize) // expected-warning {{writable atomic property 'Set_ReadWriteInExt_LateSynthesize' cannot pair a synthesized getter with a user defined setter}} GET(GetSet_Nonatomic_ReadWriteInExt_LateSynthesize) SET(GetSet_Nonatomic_ReadWriteInExt_LateSynthesize) GET(Get_Nonatomic_ReadWriteInExt_LateSynthesize) diff --git a/test/SemaObjC/attr-deprecated.m b/test/SemaObjC/attr-deprecated.m index ca267599288e..db0b958f8dd4 100644 --- a/test/SemaObjC/attr-deprecated.m +++ b/test/SemaObjC/attr-deprecated.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -fsyntax-only -verify +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface A { int X __attribute__((deprecated)); @@ -9,7 +9,7 @@ @implementation A + (void)F __attribute__((deprecated)) -{ // expected-warning {{method attribute can only be specified on method declarations}} +{ [self F]; // no warning, since the caller is also deprecated. } @@ -77,8 +77,8 @@ void t4(Class c) int t5() { Bar *f; - f.FooBar = 1; // expected-warning {{warning: 'FooBar' is deprecated}} - return f.FooBar; // expected-warning {{warning: 'FooBar' is deprecated}} + f.FooBar = 1; // expected-warning {{'FooBar' is deprecated}} + return f.FooBar; // expected-warning {{'FooBar' is deprecated}} } @@ -99,10 +99,10 @@ __attribute ((deprecated)) @interface DEPRECATED (Category2) // no warning. @end -@implementation DEPRECATED (Category2) // expected-warning {{warning: 'DEPRECATED' is deprecated}} +@implementation DEPRECATED (Category2) // expected-warning {{'DEPRECATED' is deprecated}} @end -@interface NS : DEPRECATED // expected-warning {{warning: 'DEPRECATED' is deprecated}} +@interface NS : DEPRECATED // expected-warning {{'DEPRECATED' is deprecated}} @end diff --git a/test/SemaObjC/attr-root-class.m b/test/SemaObjC/attr-root-class.m new file mode 100644 index 000000000000..195cd663acda --- /dev/null +++ b/test/SemaObjC/attr-root-class.m @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wattributes -Wobjc-root-class %s +@interface RootClass {} // expected-warning {{class 'RootClass' defined without specifying a base class}} \ + // expected-note {{add a super class to fix this problem}} +@end +@implementation RootClass +@end + +__attribute__((objc_root_class)) +@interface NonRootClass : RootClass // expected-error {{objc_root_class attribute may only be specified on a root class declaration}} +@end +@implementation NonRootClass +@end + +__attribute__((objc_root_class)) static void nonClassDeclaration() // expected-error {{attribute may only be applied to an Objective-C interface}} +{ +} diff --git a/test/SemaObjC/autoreleasepool.m b/test/SemaObjC/autoreleasepool.m index 41e17681afdf..45c749e570c1 100644 --- a/test/SemaObjC/autoreleasepool.m +++ b/test/SemaObjC/autoreleasepool.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s void *objc_autoreleasepool_push(); void autoreleasepool_pop(void*); diff --git a/test/SemaObjC/bad-property-synthesis-crash.m b/test/SemaObjC/bad-property-synthesis-crash.m index 577faea9dadc..ea4e0045dc4b 100644 --- a/test/SemaObjC/bad-property-synthesis-crash.m +++ b/test/SemaObjC/bad-property-synthesis-crash.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // rdar://10177744 @interface Foo diff --git a/test/SemaObjC/block-id-as-block-argtype.m b/test/SemaObjC/block-id-as-block-argtype.m new file mode 100644 index 000000000000..20bb6adec327 --- /dev/null +++ b/test/SemaObjC/block-id-as-block-argtype.m @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks +// rdar://10734265 + +@class NSObject; +typedef void (^block1_t)(int arg); +typedef void (^block2_t)(block1_t arg); +typedef void (^block3_t)(NSObject *arg); +typedef void (^block4_t)(id arg); + +void fn(block4_t arg); // expected-note {{passing argument to parameter 'arg' here}} + +void another_fn(block2_t arg); + +int main() { + block1_t b1; + block2_t b2; + block3_t b3; + block3_t b4; + block4_t b5; + + fn(b1); // expected-error {{incompatible block pointer types passing 'block1_t' (aka 'void (^)(int)') to parameter of type 'block4_t' (aka 'void (^)(id)')}} + fn(b2); // must succeed: block1_t *is* compatible with id + fn(b3); // succeeds: NSObject* compatible with id + fn(b4); // succeeds: id compatible with id + + another_fn(b5); +} diff --git a/test/SemaObjC/block-on-method-param.m b/test/SemaObjC/block-on-method-param.m new file mode 100644 index 000000000000..d5cbc8a822d4 --- /dev/null +++ b/test/SemaObjC/block-on-method-param.m @@ -0,0 +1,12 @@ +// 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 + +// rdar://10681443 +@interface I +- (void) compileSandboxProfileAndReturnError:(__attribute__((__blocks__(byref))) id)errorp; // expected-error {{__block attribute not allowed, only allowed on local variables}} +@end + +@implementation I +- (void) compileSandboxProfileAndReturnError:(__attribute__((__blocks__(byref))) id)errorp {} // expected-error {{__block attribute not allowed, only allowed on local variables}} +@end + diff --git a/test/SemaObjC/block-type-safety.m b/test/SemaObjC/block-type-safety.m index ebc6777f7fbb..56342baae528 100644 --- a/test/SemaObjC/block-type-safety.m +++ b/test/SemaObjC/block-type-safety.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks +// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class %s // test for block type safety. @interface Super @end @@ -138,3 +138,20 @@ int test5() { return 0; } +// rdar://10798770 +typedef int NSInteger; + +typedef enum : NSInteger {NSOrderedAscending = -1L, NSOrderedSame, NSOrderedDescending} NSComparisonResult; + +typedef NSComparisonResult (^NSComparator)(id obj1, id obj2); + +@interface radar10798770 +- (void)sortUsingComparator:(NSComparator)c; +@end + +void f() { + radar10798770 *f; + [f sortUsingComparator:^(id a, id b) { + return NSOrderedSame; + }]; +} diff --git a/test/SemaObjC/blocks.m b/test/SemaObjC/blocks.m index 2d77a20fce03..7beec19ea789 100644 --- a/test/SemaObjC/blocks.m +++ b/test/SemaObjC/blocks.m @@ -45,10 +45,10 @@ void foo7(id (^x)(int)) { @end void foo8() { - void *P = ^(itf x) {}; // expected-error {{Objective-C interface type 'itf' cannot be passed by value; did you forget * in 'itf'}} - P = ^itf(int x) {}; // expected-error {{Objective-C interface type 'itf' cannot be returned by value; did you forget * in 'itf'}} - P = ^itf() {}; // expected-error {{Objective-C interface type 'itf' cannot be returned by value; did you forget * in 'itf'}} - P = ^itf{}; // expected-error {{Objective-C interface type 'itf' cannot be returned by value; did you forget * in 'itf'}} + void *P = ^(itf x) {}; // expected-error {{interface type 'itf' cannot be passed by value; did you forget * in 'itf'}} + P = ^itf(int x) {}; // expected-error {{interface type 'itf' cannot be returned by value; did you forget * in 'itf'}} + P = ^itf() {}; // expected-error {{interface type 'itf' cannot be returned by value; did you forget * in 'itf'}} + P = ^itf{}; // expected-error {{interface type 'itf' cannot be returned by value; did you forget * in 'itf'}} } diff --git a/test/SemaObjC/builtin_objc_lib_functions.m b/test/SemaObjC/builtin_objc_lib_functions.m index 02b05b95b862..956ee12573ff 100644 --- a/test/SemaObjC/builtin_objc_lib_functions.m +++ b/test/SemaObjC/builtin_objc_lib_functions.m @@ -1,29 +1,29 @@ // RUN: %clang_cc1 -x objective-c %s -fsyntax-only -verify // rdar://8592641 -Class f0() { return objc_getClass("a"); } // expected-warning {{implicitly declaring C library function 'objc_getClass' with type 'id (const char *)'}} \ +Class f0() { return objc_getClass("a"); } // expected-warning {{implicitly declaring library function 'objc_getClass' with type 'id (const char *)'}} \ // expected-note {{please include the header <objc/runtime.h> or explicitly provide a declaration for 'objc_getClass'}} // rdar://8735023 -Class f1() { return objc_getMetaClass("a"); } // expected-warning {{implicitly declaring C library function 'objc_getMetaClass' with type 'id (const char *)'}} \ +Class f1() { return objc_getMetaClass("a"); } // expected-warning {{implicitly declaring library function 'objc_getMetaClass' with type 'id (const char *)'}} \ // expected-note {{please include the header <objc/runtime.h> or explicitly provide a declaration for 'objc_getMetaClass'}} -void f2(id val) { objc_enumerationMutation(val); } // expected-warning {{implicitly declaring C library function 'objc_enumerationMutation' with type 'void (id)'}} \ +void f2(id val) { objc_enumerationMutation(val); } // expected-warning {{implicitly declaring library function 'objc_enumerationMutation' with type 'void (id)'}} \ // expected-note {{please include the header <objc/runtime.h> or explicitly provide a declaration for 'objc_enumerationMutation'}} -long double f3(id self, SEL op) { return objc_msgSend_fpret(self, op); } // expected-warning {{implicitly declaring C library function 'objc_msgSend_fpret' with type 'long double (id, SEL, ...)'}} \ +long double f3(id self, SEL op) { return objc_msgSend_fpret(self, op); } // expected-warning {{implicitly declaring library function 'objc_msgSend_fpret' with type 'long double (id, SEL, ...)'}} \ // 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 C 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 (void *, SEL, ...)'}} \ // expected-note {{please include the header <objc/message.h> or explicitly provide a declaration for 'objc_msgSendSuper'}} } id f5(id val, id *dest) { - return objc_assign_strongCast(val, dest); // expected-warning {{implicitly declaring C library function 'objc_assign_strongCast' with type 'id (id, id *)'}} \ - // expected-note {{please include the header </objc/objc-auto.h> or explicitly provide a declaration for 'objc_assign_strongCast'}} + return objc_assign_strongCast(val, dest); // expected-warning {{implicitly declaring library function 'objc_assign_strongCast' with type 'id (id, id *)'}} \ + // expected-note {{please include the header <objc/objc-auto.h> or explicitly provide a declaration for 'objc_assign_strongCast'}} } int f6(Class exceptionClass, id exception) { - return objc_exception_match(exceptionClass, exception); // expected-warning {{implicitly declaring C library function 'objc_exception_match' with type 'int (id, id)'}} \ - // expected-note {{please include the header </objc/objc-exception.h> or explicitly provide a declaration for 'objc_exception_match'}} + return objc_exception_match(exceptionClass, exception); // expected-warning {{implicitly declaring library function 'objc_exception_match' with type 'int (id, id)'}} \ + // expected-note {{please include the header <objc/objc-exception.h> or explicitly provide a declaration for 'objc_exception_match'}} } diff --git a/test/SemaObjC/builtin_objc_nslog.m b/test/SemaObjC/builtin_objc_nslog.m new file mode 100644 index 000000000000..c940b16cdc3a --- /dev/null +++ b/test/SemaObjC/builtin_objc_nslog.m @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -x objective-c %s -fsyntax-only -verify + +#include <stdarg.h> + +void f1(id arg) { + NSLog(@"%@", arg); // expected-warning {{implicitly declaring library function 'NSLog' with type 'void (id, ...)'}} \ + // expected-note {{please include the header <Foundation/NSObjCRuntime.h> or explicitly provide a declaration for 'NSLog'}} +} + +void f2(id str, va_list args) { + NSLogv(@"%@", args); // expected-warning {{implicitly declaring library function 'NSLogv' with type }} \ + // expected-note {{please include the header <Foundation/NSObjCRuntime.h> or explicitly provide a declaration for 'NSLogv'}} +} diff --git a/test/SemaObjC/call-super-2.m b/test/SemaObjC/call-super-2.m index d77b759ffa73..3c45a2c73238 100644 --- a/test/SemaObjC/call-super-2.m +++ b/test/SemaObjC/call-super-2.m @@ -68,8 +68,8 @@ id objc_getClass(const char *s); } - (int) instance_func1 { - int i = (size_t)[self instance_func0]; // expected-warning {{instance method '-instance_func0' not found (return type defaults to 'id'))}} - return i + (size_t)[super instance_func0]; // expected-warning {{'Object' may not respond to 'instance_func0')}} + int i = (size_t)[self instance_func0]; // expected-warning {{instance method '-instance_func0' not found (return type defaults to 'id')}} + return i + (size_t)[super instance_func0]; // expected-warning {{'Object' may not respond to 'instance_func0'}} } - (int) instance_func2 { diff --git a/test/SemaObjC/category-1.m b/test/SemaObjC/category-1.m index 4cc5dafaa91b..f8422782d78b 100644 --- a/test/SemaObjC/category-1.m +++ b/test/SemaObjC/category-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface MyClass1 @end @@ -31,9 +31,9 @@ @interface UnknownClass (Category) @end // expected-error {{cannot find interface declaration for 'UnknownClass'}} -@class MyClass2; +@class MyClass2; // expected-note{{forward declaration of class here}} -@interface MyClass2 (Category) @end // expected-error {{cannot find interface declaration for 'MyClass2'}} +@interface MyClass2 (Category) @end // expected-error {{cannot define category for undefined class 'MyClass2'}} @interface XCRemoteComputerManager @end @@ -62,7 +62,7 @@ // <rdar://problem/7249233> @protocol MultipleCat_P --(void) im0; // expected-note {{method declared here}} +-(void) im0; // expected-note {{method 'im0' declared here}} @end @interface MultipleCat_I @end // expected-note {{required for direct or indirect protocol 'MultipleCat_P'}} @@ -72,7 +72,7 @@ @interface MultipleCat_I() <MultipleCat_P> @end @implementation MultipleCat_I // expected-warning {{incomplete implementation}} \ - // expected-warning {{method in protocol not implemented [-Wprotocol]}} + // expected-warning {{method 'im0' in protocol not implemented}} @end // <rdar://problem/7680391> - Handle nameless categories with no name that refer @@ -95,3 +95,7 @@ @synthesize name = _name; @end +// rdar://10968158 +@class I; // expected-note {{forward declaration}} +@implementation I(cat) // expected-error{{cannot find interface declaration}} +@end diff --git a/test/SemaObjC/category-method-lookup.m b/test/SemaObjC/category-method-lookup.m index 27a10e556c28..4223a747947c 100644 --- a/test/SemaObjC/category-method-lookup.m +++ b/test/SemaObjC/category-method-lookup.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface Foo @end diff --git a/test/SemaObjC/check-dup-decl-methods-1.m b/test/SemaObjC/check-dup-decl-methods-1.m index 1dd6446e84ca..389566781d87 100644 --- a/test/SemaObjC/check-dup-decl-methods-1.m +++ b/test/SemaObjC/check-dup-decl-methods-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -Wduplicate-method-match -fsyntax-only -verify %s @interface SUPER - (int) meth; @@ -10,8 +10,8 @@ @interface class1 : SUPER - (int) meth; // expected-note {{previous declaration is here}} - (int*) meth; // expected-error {{duplicate declaration of method 'meth'}} -- (T*) meth1; -- (T*) meth1; +- (T*) meth1; // expected-note {{previous declaration is here}} +- (T*) meth1; // expected-warning {{multiple declarations of method 'meth1' found and ignored}} + (T*) meth1; @end diff --git a/test/SemaObjC/check-dup-objc-decls-1.m b/test/SemaObjC/check-dup-objc-decls-1.m index 8dde777f7437..d6fa53a2f0b2 100644 --- a/test/SemaObjC/check-dup-objc-decls-1.m +++ b/test/SemaObjC/check-dup-objc-decls-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface Foo // expected-note {{previous definition is here}} @end diff --git a/test/SemaObjC/class-conforming-protocol-1.m b/test/SemaObjC/class-conforming-protocol-1.m index 43ea6d34d1bb..115ddd231ead 100644 --- a/test/SemaObjC/class-conforming-protocol-1.m +++ b/test/SemaObjC/class-conforming-protocol-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -Wduplicate-method-match -fsyntax-only -verify %s @protocol P1 @end @protocol P2 @end @@ -8,12 +8,11 @@ - (INTF*) METH1; // expected-note {{previous declaration is here}} - (INTF<P1>*) METH1; // expected-error {{duplicate declaration of method 'METH1'}} -- (INTF<P1,P2>*) METH2; - (INTF<P2,P1>*) METH2; // expected-note {{previous declaration is here}} - (INTF<P2,P1,P3>*) METH2; // expected-error {{duplicate declaration of method 'METH2'}} -- (INTF<P2,P1,P3>*) METH3; -- (INTF<P3,P1,P2, P3>*) METH3; +- (INTF<P2,P1,P3>*) METH3; // expected-note {{previous declaration is here}} +- (INTF<P3,P1,P2, P3>*) METH3; // expected-warning {{multiple declarations of method 'METH3' found and ignored}} @end diff --git a/test/SemaObjC/class-def-test-1.m b/test/SemaObjC/class-def-test-1.m index 95a259bd527b..0d114b99fb6d 100644 --- a/test/SemaObjC/class-def-test-1.m +++ b/test/SemaObjC/class-def-test-1.m @@ -30,4 +30,6 @@ typedef NSObject TD_NSObject; @interface XCElementUnit : TD_NSObject {} @end - +// Make sure we don't typo-correct to ourselves. +@interface SomeClassSub : SomeClassSup // expected-error{{cannot find interface declaration for 'SomeClassSup', superclass of 'SomeClassSub'}} +@end diff --git a/test/SemaObjC/class-extension-after-implementation.m b/test/SemaObjC/class-extension-after-implementation.m index 2d8a5b1d4d80..ccfd3ef0e39f 100644 --- a/test/SemaObjC/class-extension-after-implementation.m +++ b/test/SemaObjC/class-extension-after-implementation.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // rdar://7822210 @interface A @end diff --git a/test/SemaObjC/class-extension-dup-methods.m b/test/SemaObjC/class-extension-dup-methods.m index 452d242888af..692ff8c68a0a 100644 --- a/test/SemaObjC/class-extension-dup-methods.m +++ b/test/SemaObjC/class-extension-dup-methods.m @@ -1,9 +1,9 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s @interface Foo -- (int) garf; // expected-note {{ previous declaration is here}} +- (int) garf; // expected-note {{previous declaration is here}} - (int) OK; -+ (int) cgarf; // expected-note {{ previous declaration is here}} ++ (int) cgarf; // expected-note {{previous declaration is here}} - (int) InstMeth; @end diff --git a/test/SemaObjC/class-getter-using-dotsyntax.m b/test/SemaObjC/class-getter-using-dotsyntax.m index 6454bc013c1a..4ff9428e9637 100644 --- a/test/SemaObjC/class-getter-using-dotsyntax.m +++ b/test/SemaObjC/class-getter-using-dotsyntax.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s typedef struct objc_class *Class; diff --git a/test/SemaObjC/class-impl-1.m b/test/SemaObjC/class-impl-1.m index 90a4112c7122..68becaf0ac87 100644 --- a/test/SemaObjC/class-impl-1.m +++ b/test/SemaObjC/class-impl-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s typedef int INTF3; // expected-note {{previous definition is here}} @@ -31,7 +31,7 @@ typedef int INTF3; // expected-note {{previous definition is here}} @implementation INTF4 @end // expected-warning {{cannot find interface declaration for 'INTF4'}} -@class INTF5; +@class INTF5; // expected-note{{forward declaration of class here}} @implementation INTF5 { // expected-warning {{cannot find interface declaration for 'INTF5'}} int x; diff --git a/test/SemaObjC/class-message-protocol-lookup.m b/test/SemaObjC/class-message-protocol-lookup.m index ae64ea86804b..37df7a641673 100644 --- a/test/SemaObjC/class-message-protocol-lookup.m +++ b/test/SemaObjC/class-message-protocol-lookup.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // rdar://9224670 @interface RandomObject { @@ -13,7 +13,7 @@ @protocol Test2Protocol + (id)alloc; -- (id)alloc2; // expected-note 2 {{method declared here}} +- (id)alloc2; // expected-note 2 {{method 'alloc2' declared here}} @end @implementation RandomObject diff --git a/test/SemaObjC/class-method-self.m b/test/SemaObjC/class-method-self.m index ba70644ebae8..b1e37bfe58f2 100644 --- a/test/SemaObjC/class-method-self.m +++ b/test/SemaObjC/class-method-self.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify %s +// RUN: %clang_cc1 -verify -Wno-objc-root-class %s typedef struct objc_class *Class; @interface XX diff --git a/test/SemaObjC/class-proto-1.m b/test/SemaObjC/class-proto-1.m index 80309764335b..02c40aab6599 100644 --- a/test/SemaObjC/class-proto-1.m +++ b/test/SemaObjC/class-proto-1.m @@ -23,7 +23,7 @@ @interface E2 <p1,p2,p3> @end // expected-warning {{cannot find protocol definition for 'p3'}} -@class U1, U2; // expected-note {{forward class is declared here}} +@class U1, U2; // expected-note {{forward declaration of class here}} @interface E3 : U1 @end // expected-error {{attempting to use the forward class 'U1' as superclass of 'E3'}} diff --git a/test/SemaObjC/class-protocol-method-match.m b/test/SemaObjC/class-protocol-method-match.m index 04243e967757..7c936e653fba 100644 --- a/test/SemaObjC/class-protocol-method-match.m +++ b/test/SemaObjC/class-protocol-method-match.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -Woverriding-method-mismatch -fsyntax-only -verify %s +// RUN: %clang_cc1 -Woverriding-method-mismatch -fsyntax-only -verify -Wno-objc-root-class %s // rdar://9352731 @protocol Bar diff --git a/test/SemaObjC/cocoa-api-usage.m b/test/SemaObjC/cocoa-api-usage.m new file mode 100644 index 000000000000..85e21154a9e3 --- /dev/null +++ b/test/SemaObjC/cocoa-api-usage.m @@ -0,0 +1,88 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -fsyntax-only -Wobjc-cocoa-api -verify +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc %s -fsyntax-only -Wobjc-cocoa-api -verify +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -x objective-c %s.fixed -fsyntax-only +// RUN: cp %s %t.m +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %t.m -fixit -Wobjc-cocoa-api +// RUN: diff %s.fixed %t.m +// RUN: cp %s %t.m +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc %t.m -fixit -Wobjc-cocoa-api +// RUN: diff %s.fixed %t.m + +typedef signed char BOOL; +#define nil ((void*) 0) + +@interface NSObject ++ (id)alloc; +@end + +@interface NSString : NSObject ++ (id)stringWithString:(NSString *)string; +- (id)initWithString:(NSString *)aString; +@end + +@interface NSArray : NSObject +- (id)objectAtIndex:(unsigned long)index; +- (id)objectAtIndexedSubscript:(int)index; +@end + +@interface NSArray (NSArrayCreation) ++ (id)array; ++ (id)arrayWithObject:(id)anObject; ++ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt; ++ (id)arrayWithObjects:(id)firstObj, ...; ++ (id)arrayWithArray:(NSArray *)array; + +- (id)initWithObjects:(const id [])objects count:(unsigned long)cnt; +- (id)initWithObjects:(id)firstObj, ...; +- (id)initWithArray:(NSArray *)array; + +- (id)objectAtIndex:(unsigned long)index; +@end + +@interface NSMutableArray : NSArray +- (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject; +- (void)setObject:(id)object atIndexedSubscript:(int)index; +@end + +@interface NSDictionary : NSObject +- (id)objectForKeyedSubscript:(id)key; +@end + +@interface NSDictionary (NSDictionaryCreation) ++ (id)dictionary; ++ (id)dictionaryWithObject:(id)object forKey:(id)key; ++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt; ++ (id)dictionaryWithObjectsAndKeys:(id)firstObject, ...; ++ (id)dictionaryWithDictionary:(NSDictionary *)dict; ++ (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys; + +- (id)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt; +- (id)initWithObjectsAndKeys:(id)firstObject, ...; +- (id)initWithDictionary:(NSDictionary *)otherDictionary; +- (id)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys; + +- (id)objectForKey:(id)aKey; +@end + +@interface NSMutableDictionary : NSDictionary +- (void)setObject:(id)anObject forKey:(id)aKey; +- (void)setObject:(id)object forKeyedSubscript:(id)key; +@end + +@interface NSNumber : NSObject +@end + +@interface NSNumber (NSNumberCreation) ++ (NSNumber *)numberWithInt:(int)value; +@end + +#define M(x) (x) +#define PAIR(x) @#x, [NSNumber numberWithInt:(x)] +#define TWO(x) ((x), (x)) + +void foo() { + NSString *str = M([NSString stringWithString:@"foo"]); // expected-warning {{redundant}} + str = [[NSString alloc] initWithString:@"foo"]; + NSArray *arr = [NSArray arrayWithArray:@[str]]; // expected-warning {{redundant}} + NSDictionary *dict = [NSDictionary dictionaryWithDictionary:@{str: arr}]; // expected-warning {{redundant}} +} diff --git a/test/SemaObjC/cocoa-api-usage.m.fixed b/test/SemaObjC/cocoa-api-usage.m.fixed new file mode 100644 index 000000000000..55e060a068b1 --- /dev/null +++ b/test/SemaObjC/cocoa-api-usage.m.fixed @@ -0,0 +1,88 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -fsyntax-only -Wobjc-cocoa-api -verify +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc %s -fsyntax-only -Wobjc-cocoa-api -verify +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -x objective-c %s.fixed -fsyntax-only +// RUN: cp %s %t.m +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %t.m -fixit -Wobjc-cocoa-api +// RUN: diff %s.fixed %t.m +// RUN: cp %s %t.m +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc %t.m -fixit -Wobjc-cocoa-api +// RUN: diff %s.fixed %t.m + +typedef signed char BOOL; +#define nil ((void*) 0) + +@interface NSObject ++ (id)alloc; +@end + +@interface NSString : NSObject ++ (id)stringWithString:(NSString *)string; +- (id)initWithString:(NSString *)aString; +@end + +@interface NSArray : NSObject +- (id)objectAtIndex:(unsigned long)index; +- (id)objectAtIndexedSubscript:(int)index; +@end + +@interface NSArray (NSArrayCreation) ++ (id)array; ++ (id)arrayWithObject:(id)anObject; ++ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt; ++ (id)arrayWithObjects:(id)firstObj, ...; ++ (id)arrayWithArray:(NSArray *)array; + +- (id)initWithObjects:(const id [])objects count:(unsigned long)cnt; +- (id)initWithObjects:(id)firstObj, ...; +- (id)initWithArray:(NSArray *)array; + +- (id)objectAtIndex:(unsigned long)index; +@end + +@interface NSMutableArray : NSArray +- (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject; +- (void)setObject:(id)object atIndexedSubscript:(int)index; +@end + +@interface NSDictionary : NSObject +- (id)objectForKeyedSubscript:(id)key; +@end + +@interface NSDictionary (NSDictionaryCreation) ++ (id)dictionary; ++ (id)dictionaryWithObject:(id)object forKey:(id)key; ++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt; ++ (id)dictionaryWithObjectsAndKeys:(id)firstObject, ...; ++ (id)dictionaryWithDictionary:(NSDictionary *)dict; ++ (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys; + +- (id)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt; +- (id)initWithObjectsAndKeys:(id)firstObject, ...; +- (id)initWithDictionary:(NSDictionary *)otherDictionary; +- (id)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys; + +- (id)objectForKey:(id)aKey; +@end + +@interface NSMutableDictionary : NSDictionary +- (void)setObject:(id)anObject forKey:(id)aKey; +- (void)setObject:(id)object forKeyedSubscript:(id)key; +@end + +@interface NSNumber : NSObject +@end + +@interface NSNumber (NSNumberCreation) ++ (NSNumber *)numberWithInt:(int)value; +@end + +#define M(x) (x) +#define PAIR(x) @#x, [NSNumber numberWithInt:(x)] +#define TWO(x) ((x), (x)) + +void foo() { + NSString *str = M(@"foo"); // expected-warning {{redundant}} + str = [[NSString alloc] initWithString:@"foo"]; + NSArray *arr = @[str]; // expected-warning {{redundant}} + NSDictionary *dict = @{str: arr}; // expected-warning {{redundant}} +} diff --git a/test/SemaObjC/compare-qualified-id.m b/test/SemaObjC/compare-qualified-id.m index ce0db191ea9a..d31dfae86e89 100644 --- a/test/SemaObjC/compare-qualified-id.m +++ b/test/SemaObjC/compare-qualified-id.m @@ -5,7 +5,7 @@ typedef unsigned int NSUInteger; typedef struct _NSZone NSZone; @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; @protocol NSObject - (BOOL)isEqual:(id)object; @end -@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end // expected-note {{method declared here}} +@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end // expected-note {{method 'copyWithZone:' declared here}} @protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end @interface NSObject <NSObject> {} @end @@ -24,7 +24,7 @@ extern NSString * const NSTaskDidTerminateNotification; @end @implementation XCPropertyExpansionContext // expected-warning {{incomplete implementation}} \ - // expected-warning {{method in protocol not implemented [-Wprotocol]}} + // 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/compatible-protocol-qualified-types.m b/test/SemaObjC/compatible-protocol-qualified-types.m index 0342622a11e1..c0b929de446f 100644 --- a/test/SemaObjC/compatible-protocol-qualified-types.m +++ b/test/SemaObjC/compatible-protocol-qualified-types.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -pedantic -fsyntax-only -verify %s +// RUN: %clang_cc1 -pedantic -fsyntax-only -verify -Wno-objc-root-class %s typedef signed char BOOL; @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; diff --git a/test/SemaObjC/comptypes-1.m b/test/SemaObjC/comptypes-1.m index 98107eef2157..997ef19c1b4e 100644 --- a/test/SemaObjC/comptypes-1.m +++ b/test/SemaObjC/comptypes-1.m @@ -42,7 +42,7 @@ int main() MyProtocol), but not from an 'id' or from a 'MyOtherClass *' (which implements MyProtocol). */ obj_p = obj; /* Ok */ - obj_p = obj_c; // expected-warning {{ assigning to 'id<MyProtocol>' from incompatible type 'MyClass *'}} + obj_p = obj_c; // expected-warning {{assigning to 'id<MyProtocol>' from incompatible type 'MyClass *'}} obj_p = obj_cp; /* Ok */ obj_p = obj_C; // expected-warning {{incompatible pointer types assigning to 'id<MyProtocol>' from 'Class'}} diff --git a/test/SemaObjC/comptypes-10.m b/test/SemaObjC/comptypes-10.m index 1a6533a600ea..5f16a6e654f1 100644 --- a/test/SemaObjC/comptypes-10.m +++ b/test/SemaObjC/comptypes-10.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s //rdar: //8591619 // pr8453 diff --git a/test/SemaObjC/comptypes-7.m b/test/SemaObjC/comptypes-7.m index ef0f158c49ee..dde504b8606b 100644 --- a/test/SemaObjC/comptypes-7.m +++ b/test/SemaObjC/comptypes-7.m @@ -28,7 +28,7 @@ int main() obj = j; // expected-warning {{incompatible pointer types assigning to 'id' from 'int *'}} obj_p = i; // expected-warning {{incompatible integer to pointer conversion assigning to 'id<MyProtocol>' from 'int'}} - obj_p = j; // expected-warning {{ incompatible pointer types assigning to 'id<MyProtocol>' from 'int *'}} + obj_p = j; // expected-warning {{incompatible pointer types assigning to 'id<MyProtocol>' from 'int *'}} obj_c = i; // expected-warning {{incompatible integer to pointer conversion assigning to 'MyClass *' from 'int'}} obj_c = j; // expected-warning {{incompatible pointer types assigning to 'MyClass *' from 'int *'}} @@ -42,7 +42,7 @@ int main() i = obj_C; // expected-warning {{incompatible pointer to integer conversion assigning to 'int' from 'Class'}} j = obj; // expected-warning {{incompatible pointer types assigning to 'int *' from 'id'}} - j = obj_p; // expected-warning {{ incompatible pointer types assigning to 'int *' from 'id<MyProtocol>'}} + j = obj_p; // expected-warning {{incompatible pointer types assigning to 'int *' from 'id<MyProtocol>'}} j = obj_c; // expected-warning {{incompatible pointer types assigning to 'int *' from 'MyClass *'}} j = obj_C; // expected-warning {{incompatible pointer types assigning to 'int *' from 'Class'}} diff --git a/test/SemaObjC/comptypes-a.m b/test/SemaObjC/comptypes-a.m index 8480f524dc72..18d546b02f60 100644 --- a/test/SemaObjC/comptypes-a.m +++ b/test/SemaObjC/comptypes-a.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Wmethod-signatures -verify -pedantic %s +// RUN: %clang_cc1 -fsyntax-only -Wmethod-signatures -verify -pedantic -Wno-objc-root-class %s typedef signed char BOOL; typedef int NSInteger; diff --git a/test/SemaObjC/conditional-expr-3.m b/test/SemaObjC/conditional-expr-3.m index 3b5f609e4213..166e02be9e4b 100644 --- a/test/SemaObjC/conditional-expr-3.m +++ b/test/SemaObjC/conditional-expr-3.m @@ -31,7 +31,7 @@ void f2(id<P1> x) { } void f3(A *a) { - id<P1> l = a; // expected-warning {{ initializing 'id<P1>' with an expression of incompatible type 'A *'}} + id<P1> l = a; // expected-warning {{initializing 'id<P1>' with an expression of incompatible type 'A *'}} } void f4(int cond, id x, A *a) { diff --git a/test/SemaObjC/conditional-expr-5.m b/test/SemaObjC/conditional-expr-5.m index 63afca18fdd6..47aed3e6a579 100644 --- a/test/SemaObjC/conditional-expr-5.m +++ b/test/SemaObjC/conditional-expr-5.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface PBXBuildSettingsDictionary { diff --git a/test/SemaObjC/conditional-expr.m b/test/SemaObjC/conditional-expr.m index 74ab59bdb9ed..e0a3210debd3 100644 --- a/test/SemaObjC/conditional-expr.m +++ b/test/SemaObjC/conditional-expr.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s +// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wno-objc-root-class %s @protocol NSObject @end @@ -21,7 +21,7 @@ @end @interface DTFilterOutputStream2 -- nextOutputStream; // expected-note {{{{method definition for 'nextOutputStream' not found}} +- nextOutputStream; // expected-note {{method definition for 'nextOutputStream' not found}} @end @implementation DTFilterOutputStream2 // expected-warning {{incomplete implementation}} @@ -100,7 +100,7 @@ void 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> *')'}} + 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> *')}} diff --git a/test/SemaObjC/conflict-nonfragile-abi2.m b/test/SemaObjC/conflict-nonfragile-abi2.m index 7c95d5d57b5e..819732758d27 100644 --- a/test/SemaObjC/conflict-nonfragile-abi2.m +++ b/test/SemaObjC/conflict-nonfragile-abi2.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify -fsyntax-only %s +// RUN: %clang_cc1 -verify -fsyntax-only -Wno-objc-root-class %s // rdar://8225011 int glob; diff --git a/test/SemaObjC/conflicting-ivar-test-1.m b/test/SemaObjC/conflicting-ivar-test-1.m index 01b35314aa98..a7c1d353a608 100644 --- a/test/SemaObjC/conflicting-ivar-test-1.m +++ b/test/SemaObjC/conflicting-ivar-test-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fobjc-fragile-abi -fsyntax-only -verify %s +// RUN: %clang_cc1 -fobjc-fragile-abi -fsyntax-only -verify -Wno-objc-root-class %s @interface INTF { diff --git a/test/SemaObjC/continuation-class-err.m b/test/SemaObjC/continuation-class-err.m index 700cf61eedb5..d691f124e8a5 100644 --- a/test/SemaObjC/continuation-class-err.m +++ b/test/SemaObjC/continuation-class-err.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface ReadOnly { @@ -40,3 +40,12 @@ @synthesize fee = _fee; @end +// rdar://10752081 +@interface MyOtherClass() // expected-error {{cannot find interface declaration for 'MyOtherClass'}} +{ + id array; +} +@end + +@implementation MyOtherClass // expected-warning {{cannot find interface declaration for 'MyOtherClass'}} +@end diff --git a/test/SemaObjC/continuation-class-property.m b/test/SemaObjC/continuation-class-property.m index a579184060b7..7d95424a06c8 100644 --- a/test/SemaObjC/continuation-class-property.m +++ b/test/SemaObjC/continuation-class-property.m @@ -38,6 +38,26 @@ typedef struct { @end @interface MyClass () -@property (readwrite) NSString *foo; // expected-warning {{type of property 'NSString *' in continuation class does not match property type in primary class}} -@property (readwrite, strong) NSRect bar; // expected-warning {{type of property 'NSRect' in continuation class does not match property type in primary class}} +@property (readwrite) NSString *foo; // expected-error {{type of property 'NSString *' in continuation class does not match property type in primary class}} +@property (readwrite, strong) NSRect bar; // expected-error {{type of property 'NSRect' in continuation class does not match property type in primary class}} +@end + +// rdar://10655530 +struct S; +struct S1; +@interface STAdKitContext +@property (nonatomic, readonly, assign) struct evhttp_request *httpRequest; +@property (nonatomic, readonly, assign) struct S *httpRequest2; +@property (nonatomic, readonly, assign) struct S1 *httpRequest3; +@property (nonatomic, readonly, assign) struct S2 *httpRequest4; +@end + +struct evhttp_request; +struct S1; + +@interface STAdKitContext() +@property (nonatomic, readwrite, assign) struct evhttp_request *httpRequest; +@property (nonatomic, readwrite, assign) struct S *httpRequest2; +@property (nonatomic, readwrite, assign) struct S1 *httpRequest3; +@property (nonatomic, readwrite, assign) struct S2 *httpRequest4; @end diff --git a/test/SemaObjC/custom-atomic-property.m b/test/SemaObjC/custom-atomic-property.m index f80119e14903..53eaeb022ca9 100644 --- a/test/SemaObjC/custom-atomic-property.m +++ b/test/SemaObjC/custom-atomic-property.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Wcustom-atomic-properties -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wcustom-atomic-properties -verify -Wno-objc-root-class %s @interface Foo @property (assign) Foo *myProp; // expected-note {{property declared here}} expected-note {{property declared here}} diff --git a/test/SemaObjC/debugger-cast-result-to-id.m b/test/SemaObjC/debugger-cast-result-to-id.m new file mode 100644 index 000000000000..00a02be2c308 --- /dev/null +++ b/test/SemaObjC/debugger-cast-result-to-id.m @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -funknown-anytype -fsyntax-only -fdebugger-support -fdebugger-cast-result-to-id -verify %s + +extern __unknown_anytype test0; +extern __unknown_anytype test1(); + +void test_unknown_anytype_receiver() { + (void)(int)[[test0 unknownMethod] otherUnknownMethod];; + (void)(id)[[test1() unknownMethod] otherUnknownMethod]; +} + +// rdar://10988847 +@class NSString; // expected-note {{forward declaration of class here}} + +void rdar10988847() { + id s = [NSString stringWithUTF8String:"foo"]; // expected-warning {{receiver 'NSString' is a forward class and corresponding @interface may not exist}} +} diff --git a/test/SemaObjC/default-synthesize-1.m b/test/SemaObjC/default-synthesize-1.m index 1e763af62c0a..c201e747090b 100644 --- a/test/SemaObjC/default-synthesize-1.m +++ b/test/SemaObjC/default-synthesize-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -verify %s +// RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -verify -Wno-objc-root-class %s @interface NSObject - (void) release; diff --git a/test/SemaObjC/default-synthesize-2.m b/test/SemaObjC/default-synthesize-2.m index 1ea492ef5795..b95f263c32d2 100644 --- a/test/SemaObjC/default-synthesize-2.m +++ b/test/SemaObjC/default-synthesize-2.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -x objective-c -fsyntax-only -fobjc-default-synthesize-properties -verify %s -// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -fobjc-default-synthesize-properties -verify %s +// RUN: %clang_cc1 -x objective-c -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://8843851 @interface StopAccessingIvarsDirectlyExample diff --git a/test/SemaObjC/default-synthesize-3.m b/test/SemaObjC/default-synthesize-3.m new file mode 100644 index 000000000000..606ece33af8d --- /dev/null +++ b/test/SemaObjC/default-synthesize-3.m @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 -x objective-c -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 + +#if __has_attribute(objc_requires_property_definitions) +__attribute ((objc_requires_property_definitions)) +#endif +@interface NoAuto // expected-note 2 {{class with specified objc_requires_property_definitions attribute is declared here}} +@property int NoAutoProp; // expected-note 2 {{property declared here}} +@end + +@implementation NoAuto // expected-warning {{property 'NoAutoProp' requires method 'NoAutoProp' to be defined}} \ + // expected-warning {{property 'NoAutoProp' requires method 'setNoAutoProp:'}} +@end + +__attribute ((objc_requires_property_definitions)) // redundant, just for testing +@interface Sub : NoAuto // expected-note 3 {{class with specified objc_requires_property_definitions attribute is declared here}} +@property (copy) id SubProperty; // expected-note 2 {{property declared here}} +@end + +@implementation Sub // expected-warning {{property 'SubProperty' requires method 'SubProperty' to be defined}} \ + // expected-warning {{property 'SubProperty' requires method 'setSubProperty:' to be defined}} +@end + +@interface Deep : Sub +@property (copy) id DeepProperty; +@property (copy) id DeepSynthProperty; +@property (copy) id DeepMustSynthProperty; // expected-note {{property declared here}} +@end + +@implementation Deep // expected-warning {{property 'DeepMustSynthProperty' requires method 'setDeepMustSynthProperty:' to be defined}} +@dynamic DeepProperty; +@synthesize DeepSynthProperty; +- (id) DeepMustSynthProperty { return 0; } +@end + +__attribute ((objc_requires_property_definitions)) +@interface Deep(CAT) // expected-error {{attributes may not be specified on a category}} +@end + +__attribute ((objc_requires_property_definitions)) // expected-error {{objc_requires_property_definitions attribute may only be specified on a class}} +@protocol P @end diff --git a/test/SemaObjC/default-synthesize.m b/test/SemaObjC/default-synthesize.m index 0d2f47339900..e6ea0a5eafb3 100644 --- a/test/SemaObjC/default-synthesize.m +++ b/test/SemaObjC/default-synthesize.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -verify %s +// RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -verify -Wno-objc-root-class %s @interface NSString @end @@ -10,7 +10,9 @@ @end @implementation SynthItAll -//@synthesize howMany, what; +#if !__has_feature(objc_default_synthesize_properties) +@synthesize howMany, what; +#endif @end @@ -20,7 +22,9 @@ @end @implementation SynthSetter -//@synthesize howMany, what; +#if !__has_feature(objc_default_synthesize_properties) +@synthesize howMany, what; +#endif - (int) howMany { return self.howMany; @@ -40,7 +44,9 @@ @end @implementation SynthGetter -//@synthesize howMany, what; +#if !__has_feature(objc_default_synthesize_properties) +@synthesize howMany, what; +#endif // - (int) howMany - (void) setHowMany: (int) value { @@ -61,7 +67,9 @@ @end @implementation SynthNone -//@synthesize howMany, what; // REM: Redundant anyway +#if !__has_feature(objc_default_synthesize_properties) +@synthesize howMany, what; // REM: Redundant anyway +#endif - (int) howMany { return self.howMany; @@ -112,6 +120,21 @@ @implementation D - (int) Meth { return self.PROP; } +#if __has_feature(objc_default_synthesize_properties) @synthesize PROP=IVAR; +#endif @end +// rdar://10567333 +@protocol MyProtocol +@property (nonatomic, strong) NSString *requiredString; // expected-note {{property declared here}} + +@optional +@property (nonatomic, strong) NSString *optionalString; +@end + +@interface MyClass <MyProtocol> +@end + +@implementation MyClass // expected-warning {{auto property synthesis will not synthesize property declared in a protocol}} +@end diff --git a/test/SemaObjC/deref-interface.m b/test/SemaObjC/deref-interface.m index 490e3a565d2e..3201412cbc27 100644 --- a/test/SemaObjC/deref-interface.m +++ b/test/SemaObjC/deref-interface.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify -fsyntax-only %s +// RUN: %clang_cc1 -verify -fsyntax-only -Wno-objc-root-class %s @interface NSView - (id)initWithView:(id)realView; @@ -6,7 +6,7 @@ @implementation NSView - (id)initWithView:(id)realView { - *(NSView *)self = *(NSView *)realView; // expected-error {{cannot assign to class object in non-fragile ABI}} + *(NSView *)self = *(NSView *)realView; // expected-error {{cannot assign to class object}} } @end diff --git a/test/SemaObjC/direct-synthesized-ivar-access.m b/test/SemaObjC/direct-synthesized-ivar-access.m index 7e57a29b18ac..54b71109c335 100644 --- a/test/SemaObjC/direct-synthesized-ivar-access.m +++ b/test/SemaObjC/direct-synthesized-ivar-access.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -Wnonfragile-abi2 -fsyntax-only -fobjc-default-synthesize-properties -verify %s +// RUN: %clang_cc1 -Wnonfragile-abi2 -fsyntax-only -fobjc-default-synthesize-properties -verify -Wno-objc-root-class %s // rdar://8673791 // rdar://9943851 diff --git a/test/SemaObjC/dist-object-modifiers.m b/test/SemaObjC/dist-object-modifiers.m index 98a9ce6cdc52..aa7e3405c57b 100644 --- a/test/SemaObjC/dist-object-modifiers.m +++ b/test/SemaObjC/dist-object-modifiers.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // rdar://7076235 @protocol P diff --git a/test/SemaObjC/enhanced-proto-2.m b/test/SemaObjC/enhanced-proto-2.m index da7875cfa7c7..28b03d93e2d2 100644 --- a/test/SemaObjC/enhanced-proto-2.m +++ b/test/SemaObjC/enhanced-proto-2.m @@ -1,10 +1,10 @@ -// RUN: %clang_cc1 -verify %s +// RUN: %clang_cc1 -verify -Wno-objc-root-class %s @protocol MyProto1 @optional - (void) FOO; @optional -- (void) FOO; +- (void) FOO1; @optional - (void) REQ; @optional diff --git a/test/SemaObjC/enum-fixed-type.m b/test/SemaObjC/enum-fixed-type.m index 530ee0fe9995..95153bedb3db 100644 --- a/test/SemaObjC/enum-fixed-type.m +++ b/test/SemaObjC/enum-fixed-type.m @@ -25,3 +25,13 @@ void test() { long value = 2; Enumeration e = value; } + +// <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]; + +// <rdar://problem/10760113> +typedef enum : long long { Bar = -1 } LongLongEnum; +int arr3[(long long)Bar == (long long)-1 ? 1 : -1]; diff --git a/test/SemaObjC/err-ivar-access-in-class-method.m b/test/SemaObjC/err-ivar-access-in-class-method.m new file mode 100644 index 000000000000..2a5e0dca7704 --- /dev/null +++ b/test/SemaObjC/err-ivar-access-in-class-method.m @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -x objective-c -fsyntax-only -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wno-objc-root-class %s +// rdar://10593227 + +@class UIWindow; + +@interface CNAppDelegate + +@property (strong, nonatomic) UIWindow *window; + +@end + + +@interface CNAppDelegate () +@property (nonatomic,retain) id foo; +@end + +@implementation CNAppDelegate +@synthesize foo; +@synthesize window = _window; + ++(void)myClassMethod; +{ + foo = 0; // expected-error {{instance variable 'foo' accessed in class method}} +} +@end diff --git a/test/SemaObjC/error-property-gc-attr.m b/test/SemaObjC/error-property-gc-attr.m index 25fee051174b..56802960c6b2 100644 --- a/test/SemaObjC/error-property-gc-attr.m +++ b/test/SemaObjC/error-property-gc-attr.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin9 -fobjc-gc -fsyntax-only -verify %s -// RUN: %clang_cc1 -x objective-c++ -triple i386-apple-darwin9 -fobjc-gc -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i386-apple-darwin9 -fobjc-gc -fsyntax-only -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -x objective-c++ -triple i386-apple-darwin9 -fobjc-gc -fsyntax-only -verify -Wno-objc-root-class %s @interface INTF { diff --git a/test/SemaObjC/exprs.m b/test/SemaObjC/exprs.m index 2b505e0eae33..b198cba4a9b1 100644 --- a/test/SemaObjC/exprs.m +++ b/test/SemaObjC/exprs.m @@ -33,7 +33,7 @@ void test3(Object *o) { __sync_bool_compare_and_swap(&g, 0, o); } -@class Incomplete_ObjC_class; +@class Incomplete_ObjC_class; // expected-note{{forward declaration of class here}} struct Incomplete_struct; // expected-note {{forward declaration}} void test_encode() { diff --git a/test/SemaObjC/foreach.m b/test/SemaObjC/foreach.m index c865374e61af..d0e0f7b9e214 100644 --- a/test/SemaObjC/foreach.m +++ b/test/SemaObjC/foreach.m @@ -46,3 +46,12 @@ int main () return 0; } +/* rdar://problem/11068137 */ +@interface Test2 +@property (assign) id prop; +@end +void test2(NSObject<NSFastEnumeration> *collection) { + Test2 *obj; + for (obj.prop in collection) { /* expected-error {{selector element is not a valid lvalue}} */ + } +} diff --git a/test/SemaObjC/format-strings-objc.m b/test/SemaObjC/format-strings-objc.m index d89f50afa968..987889bc232f 100644 --- a/test/SemaObjC/format-strings-objc.m +++ b/test/SemaObjC/format-strings-objc.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin -Wformat-nonliteral -fsyntax-only -fblocks -verify -Wno-objc-root-class %s //===----------------------------------------------------------------------===// // The following code is reduced using delta-debugging from @@ -9,10 +9,13 @@ // portable to non-Mac platforms. //===----------------------------------------------------------------------===// +#include <stdarg.h> + typedef signed char BOOL; typedef unsigned int NSUInteger; @class NSString, Protocol; -extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2))); +extern void NSLog(NSString *format, ...); +extern void NSLogv(NSString *format, va_list args); typedef struct _NSZone NSZone; @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; @protocol NSObject - (BOOL)isEqual:(id)object; @end @@ -47,8 +50,8 @@ extern void CFStringCreateWithFormat2(int *format, ...) __attribute__((format(CF // <rdar://problem/7068334> - Catch use of long long with int arguments. void rdar_7068334() { long long test = 500; - printf("%i ",test); // expected-warning{{conversion specifies type 'int' but the argument has type 'long long'}} - NSLog(@"%i ",test); // expected-warning{{conversion specifies type 'int' but the argument has type 'long long'}} + printf("%i ",test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}} + NSLog(@"%i ",test); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}} } // <rdar://problem/7697748> @@ -63,3 +66,123 @@ void test_p_conversion_with_objc_pointer(id x, id<Foo> y) { printf("%p", y); // no-warning } +// <rdar://problem/10696348>, PR 10274 - CFString and NSString formats are ignored +extern void MyNSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2))); +extern void MyCFStringCreateWithFormat(CFStringRef format, ...) __attribute__((format(__CFString__, 1, 2))); + +void check_mylog() { + MyNSLog(@"%@"); // expected-warning {{more '%' conversions than data arguments}} + // FIXME: find a way to test CFString too, but I don't know how to create constant CFString. +} + +// PR 10275 - format function attribute isn't checked in Objective-C methods +@interface Foo ++ (id)fooWithFormat:(NSString *)fmt, ... __attribute__((format(__NSString__, 1, 2))); ++ (id)fooWithCStringFormat:(const char *)format, ... __attribute__((format(__printf__, 1, 2))); +@end + +void check_method() { + [Foo fooWithFormat:@"%@"]; // expected-warning {{more '%' conversions than data arguments}} + [Foo fooWithCStringFormat:"%@"]; // expected-warning {{invalid conversion specifier '@'}} +} + +// Warn about using BOOL with %@ +void rdar10743758(id x) { + NSLog(@"%@ %@", x, (BOOL) 1); // expected-warning {{format specifies type 'id' but the argument has type 'BOOL' (aka 'signed char')}} +} + +NSString *test_literal_propagation(void) { + const char * const s1 = "constant string %s"; // expected-note {{format string is defined here}} + printf(s1); // expected-warning {{more '%' conversions than data arguments}} + const char * const s5 = "constant string %s"; // expected-note {{format string is defined here}} + const char * const s2 = s5; + printf(s2); // expected-warning {{more '%' conversions than data arguments}} + + const char * const s3 = (const char *)0; + printf(s3); // no-warning (NULL is a valid format string) + + NSString * const ns1 = @"constant string %s"; // expected-note {{format string is defined here}} + NSLog(ns1); // expected-warning {{more '%' conversions than data arguments}} + NSString * const ns5 = @"constant string %s"; // expected-note {{format string is defined here}} + NSString * const ns2 = ns5; + NSLog(ns2); // expected-warning {{more '%' conversions than data arguments}} + NSString * ns3 = ns1; + NSLog(ns3); // expected-warning {{format string is not a string literal}}} +} + +// Do not emit warnings when using NSLocalizedString +extern NSString *GetLocalizedString(NSString *str); +#define NSLocalizedString(key) GetLocalizedString(key) + +void check_NSLocalizedString() { + [Foo fooWithFormat:NSLocalizedString(@"format"), @"arg"]; // no-warning +} + +typedef __WCHAR_TYPE__ wchar_t; + +// Test that %S, %C, %ls check for 16 bit types in ObjC strings, as described at +// http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265 + +void test_percent_S() { + const unsigned short data[] = { 'a', 'b', 0 }; + const unsigned short* ptr = data; + 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 *'}} +} + +void test_percent_ls() { + const unsigned short data[] = { 'a', 'b', 0 }; + const unsigned short* ptr = data; + 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 *'}} +} + +void test_percent_C() { + const unsigned short data = 'a'; + 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'}} +} + +// Test that %@ works with toll-free bridging (<rdar://problem/10814120>). +void test_toll_free_bridging(CFStringRef x) { + NSLog(@"%@", x); // no-warning +} + +@interface Bar ++ (void)log:(NSString *)fmt, ...; ++ (void)log2:(NSString *)fmt, ... __attribute__((format(NSString, 1, 2))); +@end + +@implementation Bar + ++ (void)log:(NSString *)fmt, ... { + va_list ap; + va_start(ap,fmt); + NSLogv(fmt, ap); // expected-warning{{format string is not a string literal}} + va_end(ap); +} + ++ (void)log2:(NSString *)fmt, ... { + va_list ap; + va_start(ap,fmt); + NSLogv(fmt, ap); // no-warning + va_end(ap); +} + +@end + + +// Test that it is okay to use %p with the address of a block. +void rdar11049844_aux(); +int rdar11049844() { + typedef void (^MyBlock)(void); + MyBlock x = ^void() { rdar11049844_aux(); }; + printf("%p", x); // no-warning +} + diff --git a/test/SemaObjC/forward-class-1.m b/test/SemaObjC/forward-class-1.m index de94e884aee2..85c6c875014b 100644 --- a/test/SemaObjC/forward-class-1.m +++ b/test/SemaObjC/forward-class-1.m @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s -@class FOO, BAR; // expected-note {{forward class is declared here}} -@class FOO, BAR; +@class FOO, BAR; // expected-note {{forward declaration of class here}} +@class FOO, BAR; @interface INTF : FOO // expected-error {{attempting to use the forward class 'FOO' as superclass of 'INTF'}} @end @@ -31,14 +31,14 @@ @protocol XCElementP @end -typedef NSObject <XCElementP> XCElement; +typedef NSObject <XCElementP> XCElement; // expected-note {{previous definition is here}} @interface XCElementMainImp { XCElement * _editingElement; } @end -@class XCElement; +@class XCElement; // expected-warning {{redefinition of forward class 'XCElement' of a typedef name of an object type is ignored}} @implementation XCElementMainImp - (XCElement *)editingElement { return _editingElement; } @@ -46,7 +46,7 @@ typedef NSObject <XCElementP> XCElement; // rdar://9653341 -@class B; // expected-note {{forward class is declared here}} +@class B; // expected-note {{forward declaration of class here}} @interface A : B {} // expected-error {{attempting to use the forward class 'B' as superclass of 'A'}} @end diff --git a/test/SemaObjC/forward-class-receiver.m b/test/SemaObjC/forward-class-receiver.m index 55b29c15c5c3..9bcb03961dc0 100644 --- a/test/SemaObjC/forward-class-receiver.m +++ b/test/SemaObjC/forward-class-receiver.m @@ -5,7 +5,7 @@ @end Class isa; -@class NotKnown; +@class NotKnown; // expected-note{{forward declaration of class here}} void foo(NotKnown *n) { [isa new]; diff --git a/test/SemaObjC/forward-class-redeclare.m b/test/SemaObjC/forward-class-redeclare.m new file mode 100644 index 000000000000..80dc33536280 --- /dev/null +++ b/test/SemaObjC/forward-class-redeclare.m @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// rdar://10733000 + +@interface NSObject @end + +@protocol PLAssetContainer +@property (readonly, nonatomic, retain) id assets; +@end + + +typedef NSObject <PLAssetContainer> PLAlbum; // expected-note {{previous definition is here}} + +@class PLAlbum; // expected-warning {{redefinition of forward class 'PLAlbum' of a typedef name of an object type is ignore}} + +@interface PLPhotoBrowserController +{ + PLAlbum *_album; +} +@end + +@interface WPhotoViewController:PLPhotoBrowserController +@end + +@implementation WPhotoViewController +- (void)_prepareForContracting +{ + (void)_album.assets; +} +@end diff --git a/test/SemaObjC/gcc-cast-ext.m b/test/SemaObjC/gcc-cast-ext.m index 599e37d77839..30e0dce4bdab 100644 --- a/test/SemaObjC/gcc-cast-ext.m +++ b/test/SemaObjC/gcc-cast-ext.m @@ -1,12 +1,12 @@ -// RUN: %clang_cc1 %s -verify -fms-extensions +// RUN: %clang_cc1 -verify -fms-extensions -Wno-objc-root-class %s @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; 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 definition for 'alloc' not found}} +- autorelease; // expected-note {{method definition for 'autorelease' not found}} @end // GCC allows pointer expressions in integer constant expressions. diff --git a/test/SemaObjC/ibaction.m b/test/SemaObjC/ibaction.m index bcedf8334047..9c59d7aaec5b 100644 --- a/test/SemaObjC/ibaction.m +++ b/test/SemaObjC/ibaction.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -verify +// RUN: %clang_cc1 -verify -Wno-objc-root-class %s @interface Foo { diff --git a/test/SemaObjC/iboutletcollection-attr.m b/test/SemaObjC/iboutletcollection-attr.m index 6bfe31389546..22c21a764bdc 100644 --- a/test/SemaObjC/iboutletcollection-attr.m +++ b/test/SemaObjC/iboutletcollection-attr.m @@ -2,6 +2,8 @@ // RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify %s // rdar://8308053 +@class NSObject; + @interface I { __attribute__((iboutletcollection(I))) id ivar1; __attribute__((iboutletcollection(id))) id ivar2; @@ -19,13 +21,23 @@ typedef void *PV; __attribute__((iboutletcollection(I, 1))) id ivar1; // expected-error {{attribute takes one argument}} __attribute__((iboutletcollection(B))) id ivar2; // expected-error {{invalid type 'B' as argument of iboutletcollection attribute}} __attribute__((iboutletcollection(PV))) id ivar3; // expected-error {{invalid type 'PV' as argument of iboutletcollection attribute}} - __attribute__((iboutletcollection(PV))) void *ivar4; // expected-error {{ivar with 'iboutletcollection' attribute must be an object type (invalid 'void *')}} + __attribute__((iboutletcollection(PV))) void *ivar4; // expected-warning {{ivar with 'iboutletcollection' attribute must be an object type (invalid 'void *')}} __attribute__((iboutletcollection(int))) id ivar5; // expected-error {{type argument of iboutletcollection attribute cannot be a builtin type}} - __attribute__((iboutlet)) int ivar6; // expected-error {{ivar with 'iboutlet' attribute must be an object type}} + __attribute__((iboutlet)) int ivar6; // expected-warning {{ivar with 'iboutlet' attribute must be an object type}} } @property (nonatomic, retain) __attribute__((iboutletcollection(I,2,3))) id prop1; // expected-error {{attribute takes one argument}} @property (nonatomic, retain) __attribute__((iboutletcollection(B))) id prop2; // expected-error {{invalid type 'B' as argument of iboutletcollection attribute}} -@property __attribute__((iboutletcollection(BAD))) int prop3; // expected-error {{property with 'iboutletcollection' attribute must be an object type (invalid 'int')}} +@property __attribute__((iboutletcollection(BAD))) int prop3; // expected-warning {{property with 'iboutletcollection' attribute must be an object type (invalid 'int')}} @end +// rdar://10296078 +@interface ParentRDar10296078 @end +@class NSArray; +@protocol RDar10296078_Protocol; +@class RDar10296078_OtherClass; + +@interface RDar10296078 : ParentRDar10296078 +@property (nonatomic, strong) + __attribute__((iboutletcollection(RDar10296078_OtherClass<RDar10296078_Protocol>))) NSArray *stuff; +@end diff --git a/test/SemaObjC/id-isa-ref.m b/test/SemaObjC/id-isa-ref.m index dfc0a5b9fdac..c2debb0bc3c3 100644 --- a/test/SemaObjC/id-isa-ref.m +++ b/test/SemaObjC/id-isa-ref.m @@ -16,8 +16,9 @@ static void func() { id x; - [(*x).isa self]; - [x->isa self]; + // 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()}} Whatever *y; diff --git a/test/SemaObjC/idiomatic-parentheses.m b/test/SemaObjC/idiomatic-parentheses.m index 39e97e2df60a..417b948b8fab 100644 --- a/test/SemaObjC/idiomatic-parentheses.m +++ b/test/SemaObjC/idiomatic-parentheses.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -Wparentheses %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wparentheses -Wno-objc-root-class %s // Don't warn about some common ObjC idioms unless we have -Widiomatic-parentheses on. // <rdar://problem/7382435> diff --git a/test/SemaObjC/ignore-qualifier-on-qualified-id.m b/test/SemaObjC/ignore-qualifier-on-qualified-id.m new file mode 100644 index 000000000000..36a2c1ad873d --- /dev/null +++ b/test/SemaObjC/ignore-qualifier-on-qualified-id.m @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify %s +// rdar://10667659 + +@protocol NSCopying @end + +@interface NSString <NSCopying> +@end + +void takeId(id test) {} + +void takeCopyableId(id<NSCopying> test) {} + +id<NSCopying> Test () { + NSString const *constantString = @"Test"; + takeId(constantString); + takeCopyableId(constantString); + id ID = constantString; + id<NSCopying> IDQNSCopying = constantString; + return constantString; +} diff --git a/test/SemaObjC/illegal-nonarc-bridged-cast.m b/test/SemaObjC/illegal-nonarc-bridged-cast.m new file mode 100644 index 000000000000..a5bb01ffe0a8 --- /dev/null +++ b/test/SemaObjC/illegal-nonarc-bridged-cast.m @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fblocks -verify %s +// rdar://10597832 + +typedef const void *CFTypeRef; +typedef const struct __CFString *CFStringRef; + +@interface NSString +@end + +CFTypeRef CFCreateSomething(); +CFStringRef CFCreateString(); +CFTypeRef CFGetSomething(); +CFStringRef CFGetString(); + +id CreateSomething(); +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}} +} + +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}} +} + +void fixits() { + id obj1 = (id)CFCreateSomething(); + CFTypeRef cf1 = (CFTypeRef)CreateSomething(); +} + +#pragma clang diagnostic ignored "-Warc-bridge-casts-disallowed-in-nonarc" + +void to_cf_ignored(id obj) { + CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething(); // no-warning + CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething(); // no-warning +} diff --git a/test/SemaObjC/incomplete-implementation.m b/test/SemaObjC/incomplete-implementation.m index f5c5a7cc1813..54f66efcb22d 100644 --- a/test/SemaObjC/incomplete-implementation.m +++ b/test/SemaObjC/incomplete-implementation.m @@ -1,8 +1,8 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface I - Meth; // expected-note{{method definition for 'Meth' not found}} \ - // expected-note{{method declared here}} + // expected-note{{method 'Meth' declared here}} @end @implementation I // expected-warning{{incomplete implementation}} @@ -14,7 +14,7 @@ #pragma GCC diagnostic ignored "-Wincomplete-implementation" @interface I2 -- Meth; // expected-note{{method declared here}} +- Meth; // expected-note{{method 'Meth' declared here}} @end @implementation I2 @@ -24,4 +24,17 @@ - Meth {return 0;} // expected-warning {{category is implementing a method which will also be implemented by its primary class}} @end +@interface Q +@end + +// rdar://10336158 +@implementation Q + +__attribute__((visibility("default"))) +@interface QN // expected-error {{Objective-C declarations may only appear in global scope}} +{ +} +@end + +@end diff --git a/test/SemaObjC/instancetype.m b/test/SemaObjC/instancetype.m index 13d6e0309f82..40f35d93b2bd 100644 --- a/test/SemaObjC/instancetype.m +++ b/test/SemaObjC/instancetype.m @@ -143,7 +143,7 @@ void test_instancetype_narrow_method_search() { @implementation Subclass4 + (id)alloc { - return self; // expected-warning{{incompatible pointer types returning 'Class' from a function with result type 'Subclass4 *'}} + return self; // expected-warning{{incompatible pointer types casting 'Class' to type 'Subclass4 *'}} } - (Subclass3 *)init { return 0; } // don't complain: we lost the related return type @@ -166,12 +166,12 @@ void test_instancetype_inherited() { @implementation Subclass2 - (instancetype)initSubclass2 { Subclass1 *sc1 = [[Subclass1 alloc] init]; - return sc1; // expected-warning{{incompatible pointer types returning 'Subclass1 *' from a function with result type 'Subclass2 *'}} + return sc1; // expected-warning{{incompatible pointer types casting 'Subclass1 *' to type 'Subclass2 *'}} } - (void)methodOnSubclass2 {} - (id)self { Subclass1 *sc1 = [[Subclass1 alloc] init]; - return sc1; // expected-warning{{incompatible pointer types returning 'Subclass1 *' from a function with result type 'Subclass2 *'}} + return sc1; // expected-warning{{incompatible pointer types casting 'Subclass1 *' to type 'Subclass2 *'}} } @end diff --git a/test/SemaObjC/interface-scope-2.m b/test/SemaObjC/interface-scope-2.m index d8046c9c2fa7..60fd900285d0 100644 --- a/test/SemaObjC/interface-scope-2.m +++ b/test/SemaObjC/interface-scope-2.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-apple-darwin9 %s +// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-apple-darwin9 -Wno-objc-root-class %s // FIXME: must also compile as Objective-C++ // <rdar://problem/6487662> diff --git a/test/SemaObjC/invalid-code.m b/test/SemaObjC/invalid-code.m index 9b7f2c8a975a..290f9d519223 100644 --- a/test/SemaObjC/invalid-code.m +++ b/test/SemaObjC/invalid-code.m @@ -1,8 +1,9 @@ -// RUN: %clang_cc1 %s -fsyntax-only -verify -fobjc-exceptions +// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions -Wno-objc-root-class %s // rdar://6124613 void test1() { - void *p = @1; // expected-error {{unexpected '@' in program}} + void *xyzzy = 0; + void *p = @xyzzy; // expected-error {{unexpected '@' in program}} } // <rdar://problem/7495713> @@ -19,3 +20,35 @@ void foo() { @throw (id)0 // expected-error{{expected ';' after @throw}} } +// <rdar://problem/10415026> +@class NSView; +@implementation IBFillView(IBFillViewIntegration) // expected-error {{cannot find interface declaration for 'IBFillView'}} +- (NSView *)ibDesignableContentView { + [Cake lie]; // expected-error {{undeclared}} + return self; +} +@end + +@interface I +@end +@interface I2 +@end + +@implementation I // expected-note {{started here}} +-(void) foo {} + +@implementation I2 // expected-error {{missing '@end'}} +-(void) foo2 {} +@end + +@end // expected-error {{'@end' must appear in an Objective-C context}} + +@class ForwardBase; +@implementation SomeI : ForwardBase // expected-error {{cannot find interface declaration for 'ForwardBase', superclass of 'SomeI'}} \ + // expected-warning {{cannot find interface declaration for 'SomeI'}} +-(void)meth {} +@end + +@interface I3 +__attribute__((unavailable)) @interface I4 @end // expected-error {{Objective-C declarations may only appear in global scope}} +@end diff --git a/test/SemaObjC/invalid-objc-decls-1.m b/test/SemaObjC/invalid-objc-decls-1.m index 91bd8a8c8698..46338bb4becf 100644 --- a/test/SemaObjC/invalid-objc-decls-1.m +++ b/test/SemaObjC/invalid-objc-decls-1.m @@ -27,8 +27,8 @@ struct whatever { } @end -Super foo( // expected-error{{interface interface type 'Super' cannot be returned by value; did you forget * in 'Super'}} - Super parm1) { // expected-error{{interface interface type 'Super' cannot be passed by value; did you forget * in 'Super'}} +Super foo( // expected-error{{interface type 'Super' cannot be returned by value; did you forget * in 'Super'}} + Super parm1) { // expected-error{{interface type 'Super' cannot be passed by value; did you forget * in 'Super'}} Super p1; // expected-error{{interface type cannot be statically allocated}} return p1; } diff --git a/test/SemaObjC/ivar-access-tests.m b/test/SemaObjC/ivar-access-tests.m index 85612209003f..cd7e09d406ad 100644 --- a/test/SemaObjC/ivar-access-tests.m +++ b/test/SemaObjC/ivar-access-tests.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface MySuperClass { diff --git a/test/SemaObjC/ivar-in-class-extension.m b/test/SemaObjC/ivar-in-class-extension.m index c9f138f40752..cf02d26e7219 100644 --- a/test/SemaObjC/ivar-in-class-extension.m +++ b/test/SemaObjC/ivar-in-class-extension.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface SomeClass @end diff --git a/test/SemaObjC/ivar-in-implementations.m b/test/SemaObjC/ivar-in-implementations.m index c4cfc10d5e40..7281f553e233 100644 --- a/test/SemaObjC/ivar-in-implementations.m +++ b/test/SemaObjC/ivar-in-implementations.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface Super @end diff --git a/test/SemaObjC/ivar-lookup-resolution-builtin.m b/test/SemaObjC/ivar-lookup-resolution-builtin.m index 2e90e8e04425..dd11b51459d7 100644 --- a/test/SemaObjC/ivar-lookup-resolution-builtin.m +++ b/test/SemaObjC/ivar-lookup-resolution-builtin.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // pr5986 @interface Test { @@ -28,7 +28,7 @@ @implementation Test1 - (int) InstMethod { - return index; // expected-warning {{implicitly declaring C library function 'index'}} \ + return index; // expected-warning {{implicitly declaring library function 'index'}} \ // expected-note {{please include the header <strings.h> or explicitly provide a declaration for 'index'}} \ // expected-warning {{incompatible pointer to integer conversion returning}} } diff --git a/test/SemaObjC/ivar-lookup.m b/test/SemaObjC/ivar-lookup.m index 2b14bff85d84..df9d8bac9077 100644 --- a/test/SemaObjC/ivar-lookup.m +++ b/test/SemaObjC/ivar-lookup.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -fsyntax-only -verify +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface Test { int x; @@ -29,7 +29,7 @@ extern struct foo x; @implementation A - (int*)method { - int *ip = [Ivar method]; // expected-warning{{warning: incompatible pointer types initializing 'int *' with an expression of type 'float *'}} + int *ip = [Ivar method]; // expected-warning{{incompatible pointer types initializing 'int *' with an expression of type 'float *'}} // Note that there is no warning in Objective-C++ return 0; } @@ -47,3 +47,36 @@ extern struct foo x; // expected-error{{instance variable 'b' accessed in class method}} } @end + +// rdar://10309454 +@interface Radar10309454 +{ + int IVAR; // expected-note 4 {{previous definition is here}} +} +@end + +@interface Radar10309454() +{ + int IVAR; // expected-error {{instance variable is already declared}} + int PIVAR; // expected-note {{previous definition is here}} +} +@end + +@interface Radar10309454() +{ + int IVAR; // expected-error {{instance variable is already declared}} +} +@end + +@interface Radar10309454() +{ + int IVAR; // expected-error {{instance variable is already declared}} + int PIVAR; // expected-error {{instance variable is already declared}} +} +@end + +@implementation Radar10309454 +{ + int IVAR; // expected-error {{instance variable is already declared}} +} +@end diff --git a/test/SemaObjC/ivar-ref-misuse.m b/test/SemaObjC/ivar-ref-misuse.m index f6d9c9408445..3115f5bd2332 100644 --- a/test/SemaObjC/ivar-ref-misuse.m +++ b/test/SemaObjC/ivar-ref-misuse.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface Sprite { // expected-note{{'Sprite' declared here}} int sprite, spree; diff --git a/test/SemaObjC/legacy-implementation-1.m b/test/SemaObjC/legacy-implementation-1.m index e9abb87f041e..2e4c5ae06106 100644 --- a/test/SemaObjC/legacy-implementation-1.m +++ b/test/SemaObjC/legacy-implementation-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @implementation INTF // expected-warning {{cannot find interface declaration for 'INTF'}} @end diff --git a/test/SemaObjC/message.m b/test/SemaObjC/message.m index fed3961ce111..621a18fc9bf0 100644 --- a/test/SemaObjC/message.m +++ b/test/SemaObjC/message.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s typedef struct objc_object { Class isa; diff --git a/test/SemaObjC/method-attributes.m b/test/SemaObjC/method-attributes.m index 9157fcfefe11..f7252af1f1b7 100644 --- a/test/SemaObjC/method-attributes.m +++ b/test/SemaObjC/method-attributes.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify -fsyntax-only %s +// RUN: %clang_cc1 -verify -fsyntax-only -Wno-objc-root-class %s @class NSString; @@ -13,20 +13,45 @@ @interface INTF - (int) foo1: (int)arg1 __attribute__((deprecated)); -- (int) foo: (int)arg1; +- (int) foo: (int)arg1; // expected-note {{method 'foo:' declared here}} -- (int) foo2: (int)arg1 __attribute__((deprecated)) __attribute__((unavailable)); +- (int) foo2: (int)arg1 __attribute__((deprecated)) __attribute__((unavailable)); // expected-note {{method 'foo2:' declared here}} +- (int) foo3: (int)arg1 __attribute__((deprecated)) __attribute__((unavailable)) __attribute__((ns_consumes_self)); @end @implementation INTF -- (int) foo: (int)arg1 __attribute__((deprecated)){ // expected-warning {{method attribute can only be specified}} +- (int) foo: (int)arg1 __attribute__((deprecated)){ // expected-warning {{attributes on method implementation and its declaration must match}} return 10; } - (int) foo1: (int)arg1 { return 10; } -- (int) foo2: (int)arg1 __attribute__((deprecated)) { // expected-warning {{method attribute can only be specified}} +- (int) foo2: (int)arg1 __attribute__((deprecated)) { // expected-warning {{attributes on method implementation and its declaration must match}} return 10; } +- (int) foo3: (int)arg1 __attribute__((deprecated)) __attribute__((unavailable)) __attribute__((ns_consumes_self)) {return 0; } +- (void) dep __attribute__((deprecated)) { } // OK private methodn @end + +// rdar://10529259 +#define IBAction void)__attribute__((ibaction) + +@interface Foo +- (void)doSomething1:(id)sender; +- (void)doSomething2:(id)sender; // expected-note {{method 'doSomething2:' declared here}} +@end + +@implementation Foo +- (void)doSomething1:(id)sender{} +- (void)doSomething2:(id)sender{} +@end + +@interface Bar : Foo +- (IBAction)doSomething1:(id)sender; +@end +@implementation Bar +- (IBAction)doSomething1:(id)sender {} +- (IBAction)doSomething2:(id)sender {} // expected-warning {{attributes on method implementation and its declaration must match}} +- (IBAction)doSomething3:(id)sender {} +@end diff --git a/test/SemaObjC/method-bad-param.m b/test/SemaObjC/method-bad-param.m index 0a1b1cd06782..9505cb44a346 100644 --- a/test/SemaObjC/method-bad-param.m +++ b/test/SemaObjC/method-bad-param.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface foo @end @@ -7,21 +7,21 @@ @end @interface bar --(void) my_method:(foo) my_param; // expected-error {{Objective-C interface type 'foo' cannot be passed by value; did you forget * in 'foo'}} -- (foo)cccccc:(long)ddddd; // expected-error {{Objective-C interface type 'foo' cannot be returned by value; did you forget * in 'foo'}} +-(void) my_method:(foo) my_param; // expected-error {{interface type 'foo' cannot be passed by value; did you forget * in 'foo'}} +- (foo)cccccc:(long)ddddd; // expected-error {{interface type 'foo' cannot be returned by value; did you forget * in 'foo'}} @end @implementation bar --(void) my_method:(foo) my_param // expected-error {{Objective-C interface type 'foo' cannot be passed by value; did you forget * in 'foo'}} +-(void) my_method:(foo) my_param // expected-error {{interface type 'foo' cannot be passed by value; did you forget * in 'foo'}} { } -- (foo)cccccc:(long)ddddd // expected-error {{Objective-C interface type 'foo' cannot be returned by value; did you forget * in 'foo'}} +- (foo)cccccc:(long)ddddd // expected-error {{interface type 'foo' cannot be returned by value; did you forget * in 'foo'}} { } @end -void somefunc(foo x) {} // expected-error {{Objective-C interface type 'foo' cannot be passed by value; did you forget * in 'foo'}} -foo somefunc2() {} // expected-error {{Objective-C interface type 'foo' cannot be returned by value; did you forget * in 'foo'}} +void somefunc(foo x) {} // expected-error {{interface type 'foo' cannot be passed by value; did you forget * in 'foo'}} +foo somefunc2() {} // expected-error {{interface type 'foo' cannot be returned by value; did you forget * in 'foo'}} // rdar://6780761 void f0(foo *a0) { diff --git a/test/SemaObjC/method-conflict-1.m b/test/SemaObjC/method-conflict-1.m index 3cf2c6b5a908..ca91ebdef237 100644 --- a/test/SemaObjC/method-conflict-1.m +++ b/test/SemaObjC/method-conflict-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // This test case tests the default behavior. diff --git a/test/SemaObjC/method-conflict-2.m b/test/SemaObjC/method-conflict-2.m index 7b5a08ad9ee4..df59f242ce7a 100644 --- a/test/SemaObjC/method-conflict-2.m +++ b/test/SemaObjC/method-conflict-2.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -Wmethod-signatures -fsyntax-only -verify %s +// RUN: %clang_cc1 -Wmethod-signatures -fsyntax-only -verify -Wno-objc-root-class %s @interface A @end @interface B : A @end diff --git a/test/SemaObjC/method-conflict.m b/test/SemaObjC/method-conflict.m index 4eb729061251..2da629e566a8 100644 --- a/test/SemaObjC/method-conflict.m +++ b/test/SemaObjC/method-conflict.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -Wmethod-signatures -fsyntax-only -verify %s +// RUN: %clang_cc1 -Wmethod-signatures -fsyntax-only -verify -Wno-objc-root-class %s typedef signed char BOOL; typedef unsigned int NSUInteger; diff --git a/test/SemaObjC/method-def-1.m b/test/SemaObjC/method-def-1.m index bc7ea7bc449c..7b292fb36ae1 100644 --- a/test/SemaObjC/method-def-1.m +++ b/test/SemaObjC/method-def-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -Wmethod-signatures -fsyntax-only -verify %s +// RUN: %clang_cc1 -Wmethod-signatures -fsyntax-only -verify -Wno-objc-root-class %s @interface foo - (int)meth; diff --git a/test/SemaObjC/method-lookup.m b/test/SemaObjC/method-lookup.m index 3091124e66ab..13e2d7fe4c3e 100644 --- a/test/SemaObjC/method-lookup.m +++ b/test/SemaObjC/method-lookup.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s typedef signed char BOOL; typedef int NSInteger; diff --git a/test/SemaObjC/method-not-defined.m b/test/SemaObjC/method-not-defined.m index ed68b22945c4..22466f7dc342 100644 --- a/test/SemaObjC/method-not-defined.m +++ b/test/SemaObjC/method-not-defined.m @@ -9,5 +9,5 @@ void test() { [[Foo alloc] init]; // expected-warning {{class method '+alloc' not found (return type defaults to 'id')}} expected-warning {{instance method '-init' not found (return type defaults to 'id')}} [fooObj notdefined]; // expected-warning {{instance method '-notdefined' not found (return type defaults to 'id')}} - [obj whatever:1 :2 :3]; // expected-warning {{instance method '-whatever:::' not found (return type defaults to 'id'))}} + [obj whatever:1 :2 :3]; // expected-warning {{instance method '-whatever:::' not found (return type defaults to 'id')}} } diff --git a/test/SemaObjC/method-prototype-scope.m b/test/SemaObjC/method-prototype-scope.m index b08faa65b22a..0bebd9b029d7 100644 --- a/test/SemaObjC/method-prototype-scope.m +++ b/test/SemaObjC/method-prototype-scope.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Wduplicate-method-arg -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wduplicate-method-arg -verify -Wno-objc-root-class %s // rdar://8877730 diff --git a/test/SemaObjC/method-typecheck-1.m b/test/SemaObjC/method-typecheck-1.m index 6c382d8cd956..ee068d0bfccf 100644 --- a/test/SemaObjC/method-typecheck-1.m +++ b/test/SemaObjC/method-typecheck-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface A - (void) setMoo: (int) x; // expected-note {{previous definition is here}} diff --git a/test/SemaObjC/method-undef-category-warn-1.m b/test/SemaObjC/method-undef-category-warn-1.m index 532ecfca9e08..2548cbd241fb 100644 --- a/test/SemaObjC/method-undef-category-warn-1.m +++ b/test/SemaObjC/method-undef-category-warn-1.m @@ -4,8 +4,8 @@ @end @protocol P -- (void) Pmeth; // expected-note {{method declared here }} -- (void) Pmeth1; // expected-note {{method 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'}} @@ -13,7 +13,7 @@ @end @implementation MyClass1(CAT) // expected-warning {{incomplete implementation}} \ - // expected-warning {{method in protocol not implemented [-Wprotocol]}} + // expected-warning {{method 'Pmeth' in protocol not implemented}} - (void) Pmeth1{} @end @@ -22,9 +22,53 @@ @end @implementation MyClass1(DOG) // expected-warning {{incomplete implementation}} \ - // expected-warning {{method in protocol not implemented [-Wprotocol]}} + // expected-warning {{method 'Pmeth1' in protocol not implemented}} - (void) Pmeth {} @end @implementation MyClass1(CAT1) @end + +// rdar://10823023 +@class NSString; + +@protocol NSObject +- (NSString *)meth_inprotocol; +@end + +@interface NSObject <NSObject> +- (NSString *)description; ++ (NSString *) cls_description; +@end + +@protocol Foo +- (NSString *)description; ++ (NSString *) cls_description; +@end + +@interface NSObject (FooConformance) <Foo> +@end + +@implementation NSObject (FooConformance) +@end + +// rdar://11186449 +// Don't warn when a category does not implemented a method imported +// by its protocol because another category has its declaration and +// that category will implement it. +@interface NSOrderedSet @end + +@interface NSOrderedSet(CoolectionImplements) +- (unsigned char)containsObject:(id)object; +@end + +@protocol Collection +- (unsigned char)containsObject:(id)object; +@end + +@interface NSOrderedSet (CollectionConformance) <Collection> +@end + +@implementation NSOrderedSet (CollectionConformance) +@end + diff --git a/test/SemaObjC/method-undef-extension-warn-1.m b/test/SemaObjC/method-undef-extension-warn-1.m index ade861e52eec..c092f2482847 100644 --- a/test/SemaObjC/method-undef-extension-warn-1.m +++ b/test/SemaObjC/method-undef-extension-warn-1.m @@ -1,11 +1,11 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface MyClass // expected-note {{required for direct or indirect protocol 'P'}} @end @protocol P - (void)Pmeth; -- (void)Pmeth1; // expected-note {{method declared here}} +- (void)Pmeth1; // expected-note {{method 'Pmeth1' declared here}} @end // Class extension @@ -19,6 +19,6 @@ @end @implementation MyClass // expected-warning {{incomplete implementation}} \ - // expected-warning {{method in protocol not implemented [-Wprotocol]}} + // expected-warning {{method 'Pmeth1' in protocol not implemented}} - (void)Pmeth {} @end diff --git a/test/SemaObjC/method-undefined-warn-1.m b/test/SemaObjC/method-undefined-warn-1.m index 922a0347992b..27d645e73bc1 100644 --- a/test/SemaObjC/method-undefined-warn-1.m +++ b/test/SemaObjC/method-undefined-warn-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface INTF - (void) meth; diff --git a/test/SemaObjC/method-unused-attribute.m b/test/SemaObjC/method-unused-attribute.m index a4e53210c251..d604c3975c80 100644 --- a/test/SemaObjC/method-unused-attribute.m +++ b/test/SemaObjC/method-unused-attribute.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Wunused-parameter -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wunused-parameter -verify -Wno-objc-root-class %s @interface INTF - (void) correct_use_of_unused: (void *) notice : (id)another_arg; diff --git a/test/SemaObjC/missing-atend-metadata.m b/test/SemaObjC/missing-atend-metadata.m index 9b79c52d9629..f072981dc1bf 100644 --- a/test/SemaObjC/missing-atend-metadata.m +++ b/test/SemaObjC/missing-atend-metadata.m @@ -1,22 +1,22 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify -Wno-objc-root-class %s @interface I0 @end -@implementation I0 // expected-error {{'@end' is missing in implementation context}} +@implementation I0 // expected-note {{implementation started here}} - meth { return 0; } -@interface I1 : I0 +@interface I1 : I0 // expected-error {{missing '@end'}} @end -@implementation I1 // expected-error {{'@end' is missing in implementation context}} --(void) im0 { self = [super init]; } +@implementation I1 // expected-note {{implementation started here}} +-(void) im0 { self = [super init]; } // expected-warning {{not found}} -@interface I2 : I0 +@interface I2 : I0 // expected-error {{missing '@end'}} - I2meth; @end -@implementation I2 // expected-error {{'@end' is missing in implementation context}} +@implementation I2 // expected-note {{implementation started here}} - I2meth { return 0; } -@implementation I2(CAT) // expected-error {{'@end' is missing in implementation context}} +@implementation I2(CAT) // expected-error 2 {{missing '@end'}} expected-note {{implementation started here}} diff --git a/test/SemaObjC/missing-method-return-type.m b/test/SemaObjC/missing-method-return-type.m index b62a0466ad35..fc6ff7b1fe80 100644 --- a/test/SemaObjC/missing-method-return-type.m +++ b/test/SemaObjC/missing-method-return-type.m @@ -1,11 +1,11 @@ -// RUN: %clang_cc1 -Wmissing-method-return-type -fsyntax-only -verify %s +// RUN: %clang_cc1 -Wmissing-method-return-type -fsyntax-only -verify -Wno-objc-root-class %s // rdar://9615045 @interface I -- initWithFoo:(id)foo; // expected-warning {{method has no return type specified; defaults to 'id' [-Wmissing-method-return-type]}} +- initWithFoo:(id)foo; // expected-warning {{method has no return type specified; defaults to 'id'}} @end @implementation I -- initWithFoo:(id)foo { return 0; } // expected-warning {{method has no return type specified; defaults to 'id' [-Wmissing-method-return-type]}} +- initWithFoo:(id)foo { return 0; } // expected-warning {{method has no return type specified; defaults to 'id'}} @end diff --git a/test/SemaObjC/narrow-property-type-in-cont-class.m b/test/SemaObjC/narrow-property-type-in-cont-class.m new file mode 100644 index 000000000000..3ba848f03ad0 --- /dev/null +++ b/test/SemaObjC/narrow-property-type-in-cont-class.m @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -x objective-c -fsyntax-only -verify %s +// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify %s +// rdar://10790488 + +@interface NSArray @end + +@interface NSMutableArray : NSArray +@end + +@interface GKTurnBasedMatchMakerKVO +@property(nonatomic,readonly,retain) NSArray* outline; +@property(nonatomic,readonly,retain) NSMutableArray* err_outline; // expected-note {{property declared here}} +@end + +@interface GKTurnBasedMatchMakerKVO () +@property(nonatomic,readwrite,retain) NSMutableArray* outline; +@property(nonatomic,readwrite,retain) NSArray* err_outline; // expected-error {{type of property 'NSArray *' in continuation class does not match property type in primary class}} +@end + diff --git a/test/SemaObjC/nested-typedef-decl.m b/test/SemaObjC/nested-typedef-decl.m index 70ca3a12cc0f..bb01eadba94b 100644 --- a/test/SemaObjC/nested-typedef-decl.m +++ b/test/SemaObjC/nested-typedef-decl.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -x objective-c -fsyntax-only -verify %s -// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify %s +// RUN: %clang_cc1 -x objective-c -fsyntax-only -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wno-objc-root-class %s // rdar://10041908 @interface Bar { diff --git a/test/SemaObjC/newproperty-class-method-1.m b/test/SemaObjC/newproperty-class-method-1.m index d4ea5e54a553..0f32998ba53b 100644 --- a/test/SemaObjC/newproperty-class-method-1.m +++ b/test/SemaObjC/newproperty-class-method-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -verify -fsyntax-only +// RUN: %clang_cc1 -verify -fsyntax-only -Wno-objc-root-class %s void abort(void); diff --git a/test/SemaObjC/no-gc-weak-test.m b/test/SemaObjC/no-gc-weak-test.m index ca8318d00fc2..dd9b73cc0de3 100644 --- a/test/SemaObjC/no-gc-weak-test.m +++ b/test/SemaObjC/no-gc-weak-test.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify -Wno-objc-root-class %s @interface Subtask { diff --git a/test/SemaObjC/no-ivar-access-control.m b/test/SemaObjC/no-ivar-access-control.m new file mode 100644 index 000000000000..6f00b1a367c7 --- /dev/null +++ b/test/SemaObjC/no-ivar-access-control.m @@ -0,0 +1,70 @@ +// RUN: %clang_cc1 -fsyntax-only -fdebugger-support -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -x objective-c++ -fdebugger-support -fsyntax-only -verify -Wno-objc-root-class %s +// rdar://10997647 + +@interface I +{ +@private +int ivar; +} +@end + +@implementation I +- (int) meth { + return self->ivar; +} +int foo1(I* p) { + return p->ivar; +} +@end + +int foo(I* p) { + return p->ivar; +} + +@interface B +@end + +@implementation B +- (int) meth : (I*) arg { + return arg->ivar; +} +@end + + +@interface I1 { + int protected_ivar; +} +@property int PROP_INMAIN; +@end + +@interface I1() { + int private_ivar; +} +@property int PROP_INCLASSEXT; +@end + +@implementation I1 +@synthesize PROP_INMAIN, PROP_INCLASSEXT; + +- (int) Meth { + PROP_INMAIN = 1; + PROP_INCLASSEXT = 2; + protected_ivar = 1; // OK + return private_ivar; // OK +} +@end + + +@interface DER : I1 +@end + +@implementation DER +- (int) Meth { + protected_ivar = 1; // OK + PROP_INMAIN = 1; + PROP_INCLASSEXT = 2; + return private_ivar; +} +@end + diff --git a/test/SemaObjC/no-protocol-option-tests.m b/test/SemaObjC/no-protocol-option-tests.m index 5d2da0af48e0..dbd2a14e91d0 100644 --- a/test/SemaObjC/no-protocol-option-tests.m +++ b/test/SemaObjC/no-protocol-option-tests.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Wno-protocol -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wno-protocol -verify -Wno-objc-root-class %s // rdar: // 7056600 @protocol P @@ -17,7 +17,7 @@ // Test2 @interface super - PMeth; @end @interface J : super <P> -- PMeth; // expected-note {{ method definition for 'PMeth' not found}} +- PMeth; // expected-note {{method definition for 'PMeth' not found}} @end @implementation J @end // expected-warning {{incomplete implementation}} diff --git a/test/SemaObjC/no-warn-qual-mismatch.m b/test/SemaObjC/no-warn-qual-mismatch.m index 1b5f184ae063..1e3c18636674 100644 --- a/test/SemaObjC/no-warn-qual-mismatch.m +++ b/test/SemaObjC/no-warn-qual-mismatch.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // radar 7211563 @interface X diff --git a/test/SemaObjC/no-warn-synth-protocol-meth.m b/test/SemaObjC/no-warn-synth-protocol-meth.m index fed6b27652ea..103f6bbd02ed 100644 --- a/test/SemaObjC/no-warn-synth-protocol-meth.m +++ b/test/SemaObjC/no-warn-synth-protocol-meth.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @protocol CYCdef - (int)name; diff --git a/test/SemaObjC/no-warning-unavail-unimp.m b/test/SemaObjC/no-warning-unavail-unimp.m index 94093222e8c9..88d519d115c4 100644 --- a/test/SemaObjC/no-warning-unavail-unimp.m +++ b/test/SemaObjC/no-warning-unavail-unimp.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // rdar://9651605 @interface Foo diff --git a/test/SemaObjC/nonnull.m b/test/SemaObjC/nonnull.m index 76c6ffa229ea..a38c0acb84f1 100644 --- a/test/SemaObjC/nonnull.m +++ b/test/SemaObjC/nonnull.m @@ -1,6 +1,6 @@ #include "nonnull.h" -// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s +// RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wno-objc-root-class %s @class NSObject; diff --git a/test/SemaObjC/nsobject-attribute-1.m b/test/SemaObjC/nsobject-attribute-1.m index 991246c72fd4..72d8fa693a9b 100644 --- a/test/SemaObjC/nsobject-attribute-1.m +++ b/test/SemaObjC/nsobject-attribute-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s +// RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wno-objc-root-class %s @interface NSObject - (id)self; diff --git a/test/SemaObjC/nsobject-attribute.m b/test/SemaObjC/nsobject-attribute.m index 13a4929995bb..f41df8932887 100644 --- a/test/SemaObjC/nsobject-attribute.m +++ b/test/SemaObjC/nsobject-attribute.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s typedef struct CGColor * __attribute__ ((NSObject)) CGColorRef; static int count; @@ -15,8 +15,8 @@ typedef void * __attribute__ ((NSObject)) CGColorRef2; // expected-error {{__at @property(copy) CGColorRef x; // rdar: // 7809460 -typedef struct CGColor *CGColorRefNoNSObject; -@property (nonatomic, retain) __attribute__((NSObject)) CGColorRefNoNSObject color; +typedef struct CGColor * __attribute__((NSObject)) CGColorRefNoNSObject; +@property (nonatomic, retain) CGColorRefNoNSObject color; @end void setProperty(id self, id value) { @@ -40,3 +40,15 @@ int main(int argc, char *argv[]) { return 0; } +// rdar://10453342 +@interface I +{ + __attribute__((NSObject)) void * color; // expected-warning {{__attribute ((NSObject)) may be put on a typedef only, attribute is ignored}} +} + // <rdar://problem/10930507> +@property (nonatomic, retain) __attribute__((NSObject)) void * color; // // no-warning +@end +void test_10453342() { + char* __attribute__((NSObject)) string2 = 0; // expected-warning {{__attribute ((NSObject)) may be put on a typedef only, attribute is ignored}} +} + diff --git a/test/SemaObjC/objc-array-literal.m b/test/SemaObjC/objc-array-literal.m new file mode 100644 index 000000000000..9f59316219c7 --- /dev/null +++ b/test/SemaObjC/objc-array-literal.m @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// rdar://10111397 + +#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64 +typedef unsigned long NSUInteger; +#else +typedef unsigned int NSUInteger; +#endif + +@class NSString; + +extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2))); + +@class NSFastEnumerationState; + +@protocol NSFastEnumeration + +- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id [])buffer count:(NSUInteger)len; + +@end + +@interface NSNumber ++ (NSNumber *)numberWithInt:(int)value; +@end + +@interface NSArray <NSFastEnumeration> ++ (id)arrayWithObjects:(const id [])objects count:(NSUInteger)cnt; +@end + + +int main() { + NSArray *array = @[@"Hello", @"There", @"How Are You", [NSNumber numberWithInt:42]]; + + for (id string in array) + NSLog(@"%@\n", string); + + NSArray *array1 = @["Forgot"]; // expected-error {{string literal must be prefixed by '@' in a collection}} + + const char *blah; + NSArray *array2 = @[blah]; // expected-error{{collection element of type 'const char *' is not an Objective-C object}} +} diff --git a/test/SemaObjC/objc-buffered-methods.m b/test/SemaObjC/objc-buffered-methods.m index 78912aed8605..a4b83be0cd70 100644 --- a/test/SemaObjC/objc-buffered-methods.m +++ b/test/SemaObjC/objc-buffered-methods.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // rdar://8843851 int* global; diff --git a/test/SemaObjC/objc-container-subscripting-1.m b/test/SemaObjC/objc-container-subscripting-1.m new file mode 100644 index 000000000000..a58a7c3bda81 --- /dev/null +++ b/test/SemaObjC/objc-container-subscripting-1.m @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +typedef unsigned int size_t; +@protocol P @end + +@interface NSMutableArray +@end + +@interface XNSMutableArray +@end + +int main() { +id array; +id oldObject = array[10]; // expected-warning {{instance method '-objectAtIndexedSubscript:' not found (return type defaults to 'id')}} + +array[10] = 0; // expected-warning {{instance method '-setObject:atIndexedSubscript:' not found (return type defaults to 'id')}} + +id<P> p_array; +oldObject = p_array[10]; // expected-warning {{instance method '-objectAtIndexedSubscript:' not found (return type defaults to 'id')}} + +p_array[10] = 0; // expected-warning {{instance method '-setObject:atIndexedSubscript:' not found (return type defaults to 'id')}} +} + diff --git a/test/SemaObjC/objc-container-subscripting-2.m b/test/SemaObjC/objc-container-subscripting-2.m new file mode 100644 index 000000000000..3c0081b72a76 --- /dev/null +++ b/test/SemaObjC/objc-container-subscripting-2.m @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +typedef unsigned int size_t; +@protocol P @end + +@interface NSMutableArray +- (id)objectAtIndexedSubscript:(size_t)index; +- (void)setObject:(id)object atIndexedSubscript:(size_t)index; +@end + +@interface NSMutableDictionary +- (id)objectForKeyedSubscript:(id)key; +- (void)setObject:(id)object forKeyedSubscript:(size_t)key; +@end + +id func() { + NSMutableArray *array; + float f; + array[f] = array; // expected-error {{indexing expression is invalid because subscript type 'float' is not an integral or objective-C pointer type}} + return array[3.14]; // expected-error {{indexing expression is invalid because subscript type 'double' is not an integral or objective-C pointer type}} +} + +void test_unused() { + NSMutableArray *array; + array[10]; // expected-warning {{container access result unused - container access should not be used for side effects}} + + NSMutableDictionary *dict; + dict[array]; // expected-warning {{container access result unused - container access should not be used for side effects}} +} + diff --git a/test/SemaObjC/objc-container-subscripting-3.m b/test/SemaObjC/objc-container-subscripting-3.m new file mode 100644 index 000000000000..5fd1a10915f7 --- /dev/null +++ b/test/SemaObjC/objc-container-subscripting-3.m @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// rdar://10904488 + +@interface Test +- (int)objectAtIndexedSubscript:(int)index; // expected-note {{method 'objectAtIndexedSubscript:' declared here}} +- (void)setObject:(int)object atIndexedSubscript:(int)index; // expected-note {{parameter of type 'int' is declared here}} +@end + +@interface NSMutableDictionary +- (int)objectForKeyedSubscript:(id)key; // expected-note {{method 'objectForKeyedSubscript:' declared here}} +- (void)setObject:(int)object forKeyedSubscript:(id)key; // expected-note {{parameter of type 'int' is declared here}} +@end + +int main() { + Test *array; + int i = array[10]; // expected-error {{method for accessing array element must have Objective-C object return type instead of 'int'}} + array[2] = i; // expected-error {{cannot assign to this array because assigning method's 2nd parameter of type 'int' is not an objective-C pointer type}} + + NSMutableDictionary *dict; + id key, val; + val = dict[key]; // expected-error {{method for accessing dictionary element must have Objective-C object return type instead of 'int'}} \ + // expected-warning {{incompatible integer to pointer conversion assigning to 'id' from 'int'}} + dict[key] = val; // expected-error {{method object parameter type 'int' is not object type}} +} + diff --git a/test/SemaObjC/objc-container-subscripting.m b/test/SemaObjC/objc-container-subscripting.m new file mode 100644 index 000000000000..4125bc634a7f --- /dev/null +++ b/test/SemaObjC/objc-container-subscripting.m @@ -0,0 +1,42 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +typedef unsigned int size_t; +@protocol P @end + +@interface NSMutableArray +- (id)objectAtIndexedSubscript:(double)index; // expected-note {{parameter of type 'double' is declared here}} +- (void)setObject:(id *)object atIndexedSubscript:(void *)index; // expected-note {{parameter of type 'void *' is declared here}} \ + // expected-note {{parameter of type 'id *' is declared here}} +@end +@interface I @end + +int main() { + NSMutableArray<P> * array; + id oldObject = array[10]; // expected-error {{method index parameter type 'double' is not integral type}} + array[3] = 0; // expected-error {{method index parameter type 'void *' is not integral type}} \ + // expected-error {{cannot assign to this array because assigning method's 2nd parameter of type 'id *' is not an objective-C pointer type}} + + I* iarray; + iarray[3] = 0; // expected-error {{expected method to write array element not found on object of type 'I *'}} + I* p = iarray[4]; // expected-error {{expected method to read array element not found on object of type 'I *'}} + + oldObject = array[10]++; // expected-error {{illegal operation on objective-c container subscripting}} + oldObject = array[10]--; // expected-error {{illegal operation on objective-c container subscripting}} + oldObject = --array[10]; // expected-error {{illegal operation on objective-c container subscripting}} +} + +@interface NSMutableDictionary +- (id)objectForKeyedSubscript:(id*)key; // expected-note {{parameter of type 'id *' is declared here}} +- (void)setObject:(void*)object forKeyedSubscript:(id*)key; // expected-note {{parameter of type 'void *' is declared here}} \ + // expected-note {{parameter of type 'id *' is declared here}} +@end +@class NSString; + +void testDict() { + NSMutableDictionary *dictionary; + NSString *key; + id newObject, oldObject; + oldObject = dictionary[key]; // expected-error {{method key parameter type 'id *' is not object type}} + dictionary[key] = newObject; // expected-error {{method object parameter type 'void *' is not object type}} \ + // expected-error {{method key parameter type 'id *' is not object type}} +} diff --git a/test/SemaObjC/objc-cstyle-args-in-methods.m b/test/SemaObjC/objc-cstyle-args-in-methods.m index 9f752959e95b..d37b5897b114 100644 --- a/test/SemaObjC/objc-cstyle-args-in-methods.m +++ b/test/SemaObjC/objc-cstyle-args-in-methods.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface Foo - (id)test:(id)one, id two; diff --git a/test/SemaObjC/objc-dictionary-literal.m b/test/SemaObjC/objc-dictionary-literal.m new file mode 100644 index 000000000000..2acbc39e3885 --- /dev/null +++ b/test/SemaObjC/objc-dictionary-literal.m @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// rdar://11062080 + +@interface NSNumber ++ (NSNumber *)numberWithChar:(char)value; ++ (NSNumber *)numberWithInt:(int)value; +@end + +@protocol NSCopying @end +typedef unsigned long NSUInteger; +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; +@end + +@interface NSString<NSCopying> +@end + +@interface NSArray +- (id)objectAtIndexedSubscript:(NSInteger)index; +- (void)setObject:(id)object atIndexedSubscript:(NSInteger)index; +@end + +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}} + + return 0; +} + diff --git a/test/SemaObjC/objc-literal-nsnumber.m b/test/SemaObjC/objc-literal-nsnumber.m new file mode 100644 index 000000000000..449bfff4d964 --- /dev/null +++ b/test/SemaObjC/objc-literal-nsnumber.m @@ -0,0 +1,85 @@ +// RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s +// rdar://10111397 + +#if __LP64__ +typedef unsigned long NSUInteger; +#else +typedef unsigned int NSUInteger; +#endif + +@interface NSObject ++ (NSObject*)nsobject; +@end + +@interface NSNumber : NSObject ++ (NSNumber *)numberWithChar:(char)value; ++ (NSNumber *)numberWithInt:(int)value; ++ (NSNumber *)numberWithFloat:(float)value; +@end + +int main() { + NSNumber * N = @3.1415926535; // expected-error {{declaration of 'numberWithDouble:' is missing in NSNumber class}} + NSNumber *noNumber = @__objc_yes; // expected-error {{declaration of 'numberWithBool:' is missing in NSNumber class}} + NSNumber * NInt = @1000; + NSNumber * NLongDouble = @1000.0l; // expected-error{{'long double' is not a valid literal type for NSNumber}} + id character = @ 'a'; + + NSNumber *NNegativeInt = @-1000; + NSNumber *NPositiveInt = @+1000; + NSNumber *NNegativeFloat = @-1000.1f; + NSNumber *NPositiveFloat = @+1000.1f; + + int five = 5; + @-five; // expected-error{{@- must be followed by a number to form an NSNumber object}} + @+five; // expected-error{{@+ must be followed by a number to form an NSNumber object}} +} + +// Dictionary test +@class NSDictionary; + +NSDictionary *err() { + return @{@"name" : @"value"}; // expected-error {{declaration of 'dictionaryWithObjects:forKeys:count:' is missing in NSDictionary class}} +} + +@interface NSDate : NSObject ++ (NSDate *) date; +@end + +@protocol NSCopying +- copy; +@end + +@interface NSDictionary : NSObject ++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id<NSCopying> [])keys count:(NSUInteger)cnt; +@end + +@interface NSString<NSCopying> +@end + +id NSUserName(); + +int Int(); + +NSDictionary * blocks() { + return @{ @"task" : ^ { return 17; } }; +} + +NSDictionary * warn() { + NSDictionary *dictionary = @{@"name" : NSUserName(), + @"date" : [NSDate date], + @"name2" : @"other", + NSObject.nsobject : @"nsobject" }; // expected-warning{{passing 'NSObject *' to parameter of incompatible type 'const id<NSCopying>'}} + NSDictionary *dictionary2 = @{@"name" : Int()}; // expected-error {{collection element of type 'int' is not an Objective-C object}} + + NSObject *o; + NSDictionary *dictionary3 = @{o : o, // expected-warning{{passing 'NSObject *' to parameter of incompatible type 'const id<NSCopying>'}} + @"date" : [NSDate date] }; + return dictionary3; +} + +// rdar:// 11231426 +typedef float BOOL; // expected-note {{previous declaration is here}} + +BOOL radar11231426() { + return __objc_yes; // expected-warning {{BOOL of type 'float' is non-intergal and unsuitable for a boolean literal - ignored}} +} diff --git a/test/SemaObjC/objc-literal-sig.m b/test/SemaObjC/objc-literal-sig.m new file mode 100644 index 000000000000..fb5c79fd8437 --- /dev/null +++ b/test/SemaObjC/objc-literal-sig.m @@ -0,0 +1,40 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +typedef _Bool BOOL; + +@interface NSNumber @end + +@interface NSNumber (NSNumberCreation) ++ (NSNumber *)numberWithChar:(char)value; ++ (NSNumber *)numberWithUnsignedChar:(unsigned char)value; ++ (NSNumber *)numberWithShort:(short)value; ++ (NSNumber *)numberWithUnsignedShort:(unsigned short)value; ++ (NSNumber *)numberWithInt:(int)value; ++ (NSNumber *)numberWithUnsignedInt:(unsigned int)value; ++ (NSNumber *)numberWithLong:(long)value; ++ (NSNumber *)numberWithUnsignedLong:(unsigned long)value; ++ (NSNumber *)numberWithLongLong:(long long)value; ++ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value; ++ (NSNumber *)numberWithFloat:(float)value; ++ (NSNumber *)numberWithDouble:(double)value; ++ (int)numberWithBool:(BOOL)value; // expected-note{{method returns unexpected type 'int' (should be an object type)}} +@end + +@interface NSArray +@end + +@interface NSArray (NSArrayCreation) ++ (id)arrayWithObjects:(const int [])objects // expected-note{{first parameter has unexpected type 'const int *' (should be 'const id *')}} + count:(unsigned long)cnt; +@end + +@interface NSDictionary ++ (id)dictionaryWithObjects:(const id [])objects + forKeys:(const int [])keys // expected-note{{second parameter has unexpected type 'const int *' (should be 'const id *')}} + count:(unsigned long)cnt; +@end + +void test_sig() { + (void)@__objc_yes; // expected-error{{literal construction method 'numberWithBool:' has incompatible signature}} + id array = @[ @17 ]; // expected-error{{literal construction method 'arrayWithObjects:count:' has incompatible signature}} + id dict = @{ @"hello" : @17 }; // expected-error{{literal construction method 'dictionaryWithObjects:forKeys:count:' has incompatible signature}} +} diff --git a/test/SemaObjC/objc-qualified-property-lookup.m b/test/SemaObjC/objc-qualified-property-lookup.m index daf583de334b..48b28cb05ca5 100644 --- a/test/SemaObjC/objc-qualified-property-lookup.m +++ b/test/SemaObjC/objc-qualified-property-lookup.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // rdar://9078584 @interface NSObject @end diff --git a/test/SemaObjC/pedantic-dynamic-test.m b/test/SemaObjC/pedantic-dynamic-test.m index 9b14c1d75f39..61f36b333826 100644 --- a/test/SemaObjC/pedantic-dynamic-test.m +++ b/test/SemaObjC/pedantic-dynamic-test.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s +// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wno-objc-root-class %s // rdar: // 7860960 @interface I diff --git a/test/SemaObjC/pragma-pack.m b/test/SemaObjC/pragma-pack.m new file mode 100644 index 000000000000..ba39257fcd50 --- /dev/null +++ b/test/SemaObjC/pragma-pack.m @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -verify -Wno-objc-root-class %s + +// Make sure pragma pack works inside ObjC methods. <rdar://problem/10893316> +@interface X +@end +@implementation X +- (void)Y { +#pragma pack(push, 1) + struct x { + char a; + int b; + }; +#pragma pack(pop) + typedef char check_[sizeof (struct x) == 5 ? 1 : -1]; +} +@end diff --git a/test/SemaObjC/property-10.m b/test/SemaObjC/property-10.m index e89d68e9d051..51eb39c9e7cd 100644 --- a/test/SemaObjC/property-10.m +++ b/test/SemaObjC/property-10.m @@ -37,3 +37,12 @@ @property(nonatomic,copy) int (*PROP1)(); // expected-error {{property with 'copy' attribute must be of object type}} @property(nonatomic,weak) int (*PROP2)(); // expected-error {{property with 'weak' attribute must be of object type}} @end + +// rdar://10357768 +@interface rdar10357768 +{ + int n1; +} +@property (readonly, setter=crushN1:) int n1; // expected-warning {{setter cannot be specified for a readonly property}} +@end + diff --git a/test/SemaObjC/property-2.m b/test/SemaObjC/property-2.m index 069b0cbc7132..f95af5990275 100644 --- a/test/SemaObjC/property-2.m +++ b/test/SemaObjC/property-2.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface Tester @property char PropertyAtomic_char; diff --git a/test/SemaObjC/property-9.m b/test/SemaObjC/property-9.m index 2b6564d29593..4bed8751b6a8 100644 --- a/test/SemaObjC/property-9.m +++ b/test/SemaObjC/property-9.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s typedef signed char BOOL; @protocol NSObject - (BOOL)isEqual:(id)object; @end @@ -44,21 +44,20 @@ typedef signed char BOOL; } @property (readonly) int; // expected-warning {{declaration does not declare anything}} -@property (readonly) ; // expected-error {{type name requires a specifier or qualifier}} \ - expected-warning {{declaration does not declare anything}} +@property (readonly) ; // expected-error {{type name requires a specifier or qualifier}} @property (readonly) int : 4; // expected-error {{property requires fields to be named}} // test parser recovery: rdar://6254579 @property ( // expected-note {{to match this '('}} - readonly getter=isAwesome) // expected-error {{error: expected ')'}} + readonly getter=isAwesome) // expected-error {{expected ')'}} int _awesome; @property (readonlyx) // expected-error {{unknown property attribute 'readonlyx'}} int _awesome2; @property ( // expected-note {{to match this '('}} - +) // expected-error {{error: expected ')'}} + +) // expected-error {{expected ')'}} int _awesome3; @@ -97,13 +96,13 @@ typedef signed char BOOL; @end // rdar://8774513 -@class MDAInstance; // expected-note {{forward class is declared here}} +@class MDAInstance; // expected-note {{forward declaration of class here}} @interface MDATestDocument @property(retain) MDAInstance *instance; @end id f0(MDATestDocument *d) { - return d.instance.path; // expected-error {{property 'path' cannot be found in forward class object 'MDAInstance *'}} + return d.instance.path; // expected-error {{property 'path' cannot be found in forward class object 'MDAInstance'}} } diff --git a/test/SemaObjC/property-and-ivar-use.m b/test/SemaObjC/property-and-ivar-use.m index 12874e7d201e..5b40d854898e 100644 --- a/test/SemaObjC/property-and-ivar-use.m +++ b/test/SemaObjC/property-and-ivar-use.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // Do not issue error if 'ivar' used previously belongs to the inherited class // and has same name as @dynalic property in current class. diff --git a/test/SemaObjC/property-category-1.m b/test/SemaObjC/property-category-1.m index 6382826080fb..3788bc90ddf0 100644 --- a/test/SemaObjC/property-category-1.m +++ b/test/SemaObjC/property-category-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface Object + (id)new; @@ -48,6 +48,6 @@ int main(int argc, char **argv) { @implementation I0 // expected-warning {{property 'p0' requires method 'p0' to be define}} - (void) foo { - self.p0 = 0; // expected-error {{assigning to property with 'readonly' attribute not allowed}} + self.p0 = 0; // expected-error {{assignment to readonly property}} } @end diff --git a/test/SemaObjC/property-category-3.m b/test/SemaObjC/property-category-3.m index 2a61d9272477..47e93a33d242 100644 --- a/test/SemaObjC/property-category-3.m +++ b/test/SemaObjC/property-category-3.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @protocol P @property(readonly) int X; // expected-note {{property declared here}} diff --git a/test/SemaObjC/property-category-4.m b/test/SemaObjC/property-category-4.m index aa49a3f0b5ed..e7939b32c114 100644 --- a/test/SemaObjC/property-category-4.m +++ b/test/SemaObjC/property-category-4.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface IDELogNavigator { diff --git a/test/SemaObjC/property-category-impl.m b/test/SemaObjC/property-category-impl.m index 21fdf1b6d4be..9524c22799da 100644 --- a/test/SemaObjC/property-category-impl.m +++ b/test/SemaObjC/property-category-impl.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s /* This test is for categories which don't implement the accessors but some accessors are implemented in their base class implementation. In this case,no warning must be issued. diff --git a/test/SemaObjC/property-dot-receiver.m b/test/SemaObjC/property-dot-receiver.m index 733ad4288a83..c5a928b4e892 100644 --- a/test/SemaObjC/property-dot-receiver.m +++ b/test/SemaObjC/property-dot-receiver.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify %s +// 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 // rdar://8962253 @interface Singleton { diff --git a/test/SemaObjC/property-error-readonly-assign.m b/test/SemaObjC/property-error-readonly-assign.m index fc8c48c4f6cf..3484172844b7 100644 --- a/test/SemaObjC/property-error-readonly-assign.m +++ b/test/SemaObjC/property-error-readonly-assign.m @@ -13,9 +13,9 @@ @end void f0(A *a, B* b) { - a.x = 10; // expected-error {{assigning to property with 'readonly' attribute not allowed}} + a.x = 10; // expected-error {{assignment to readonly property}} a.ok = 20; - b.x = 10; // expected-error {{setter method is needed to assign to object using property assignment syntax}} + b.x = 10; // expected-error {{no setter method 'setX:' for assignment to property}} b.ok = 20; } @@ -39,6 +39,6 @@ NSRect NSMakeRect(); @implementation NSWindow (Category) -(void)methodToMakeClangCrash { - self.frame = NSMakeRect(); // expected-error {{setter method is needed to assign to object using property assignment syntax}} + self.frame = NSMakeRect(); // expected-error {{no setter method 'setFrame:' for assignment to property}} } @end diff --git a/test/SemaObjC/property-expression-error.m b/test/SemaObjC/property-expression-error.m index 6b5cf047dc17..e306722e6c51 100644 --- a/test/SemaObjC/property-expression-error.m +++ b/test/SemaObjC/property-expression-error.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface AddressMyProperties { diff --git a/test/SemaObjC/property-impl-misuse.m b/test/SemaObjC/property-impl-misuse.m index 122afc1d4b5b..c3cedb05ed61 100644 --- a/test/SemaObjC/property-impl-misuse.m +++ b/test/SemaObjC/property-impl-misuse.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface I { int Y; diff --git a/test/SemaObjC/property-in-class-extension.m b/test/SemaObjC/property-in-class-extension.m index 6ae0b8148a3d..a7b513075263 100644 --- a/test/SemaObjC/property-in-class-extension.m +++ b/test/SemaObjC/property-in-class-extension.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // rdar://7766184 @interface Foo @end @@ -9,7 +9,7 @@ void FUNC () { Foo *foo; - foo.bar = 0; // expected-error {{assigning to property with 'readonly' attribute not allowed}} + foo.bar = 0; // expected-error {{assignment to readonly property}} } // rdar://8747333 diff --git a/test/SemaObjC/property-ivar-mismatch.m b/test/SemaObjC/property-ivar-mismatch.m index 16ff33855061..6abd6e662d72 100644 --- a/test/SemaObjC/property-ivar-mismatch.m +++ b/test/SemaObjC/property-ivar-mismatch.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // Test that arithmatic types on property and its ivar have exact match. @interface Test4 diff --git a/test/SemaObjC/property-lookup-in-id.m b/test/SemaObjC/property-lookup-in-id.m index 86da48e85105..38aa32c50607 100644 --- a/test/SemaObjC/property-lookup-in-id.m +++ b/test/SemaObjC/property-lookup-in-id.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // rdar://9106929 typedef struct objc_class *Class; @@ -25,7 +25,7 @@ extern id NSApp; - (void)startFSEventGathering:(id)sender { - fsEventStream = [NSApp delegate].fsEventStream; // expected-warning {{warning: instance method '-delegate' not found (return type defaults to 'id')}} \ + fsEventStream = [NSApp delegate].fsEventStream; // expected-warning {{instance method '-delegate' not found (return type defaults to 'id')}} \ // expected-error {{property 'fsEventStream' not found on object of type 'id'}} } diff --git a/test/SemaObjC/property-method-lookup-impl.m b/test/SemaObjC/property-method-lookup-impl.m index 0a018b0dffd8..19d4e684944a 100644 --- a/test/SemaObjC/property-method-lookup-impl.m +++ b/test/SemaObjC/property-method-lookup-impl.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface SSyncCEList { diff --git a/test/SemaObjC/property-missing.m b/test/SemaObjC/property-missing.m index bf75601b79bc..3ebf0a81159c 100644 --- a/test/SemaObjC/property-missing.m +++ b/test/SemaObjC/property-missing.m @@ -21,7 +21,7 @@ void f3(id o) } // rdar://8851803 -@class SomeOtherClass; // expected-note {{forward class is declared here}} +@class SomeOtherClass; // expected-note {{forward declaration of class here}} @interface MyClass { SomeOtherClass *someOtherObject; diff --git a/test/SemaObjC/property-not-lvalue.m b/test/SemaObjC/property-not-lvalue.m index 3d95d2607f8e..12d2cc62ff47 100644 --- a/test/SemaObjC/property-not-lvalue.m +++ b/test/SemaObjC/property-not-lvalue.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s typedef struct NSSize { int width; diff --git a/test/SemaObjC/property-ns-returns-not-retained-attr.m b/test/SemaObjC/property-ns-returns-not-retained-attr.m index a209da884ed7..96ef3eddecb1 100644 --- a/test/SemaObjC/property-ns-returns-not-retained-attr.m +++ b/test/SemaObjC/property-ns-returns-not-retained-attr.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -verify -Wno-objc-root-class %s // rdar://9636091 @interface I diff --git a/test/SemaObjC/property-redundant-decl-accessor.m b/test/SemaObjC/property-redundant-decl-accessor.m index 2a24e7e82446..3b0e825b9d8c 100644 --- a/test/SemaObjC/property-redundant-decl-accessor.m +++ b/test/SemaObjC/property-redundant-decl-accessor.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Werror -verify %s +// RUN: %clang_cc1 -fsyntax-only -Werror -verify -Wno-objc-root-class %s @interface MyClass { const char *_myName; diff --git a/test/SemaObjC/property-typecheck-1.m b/test/SemaObjC/property-typecheck-1.m index f86e04779991..f71e4a0f1c7f 100644 --- a/test/SemaObjC/property-typecheck-1.m +++ b/test/SemaObjC/property-typecheck-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface A -(float) x; // expected-note {{declared here}} diff --git a/test/SemaObjC/property-user-setter.m b/test/SemaObjC/property-user-setter.m index 2f1e19727a88..7d4e544f0332 100644 --- a/test/SemaObjC/property-user-setter.m +++ b/test/SemaObjC/property-user-setter.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface I0 @property(readonly) int x; @@ -20,7 +20,7 @@ -(void) im0 { self.x = 0; self.y = 2; - self.z = 2; // expected-error {{assigning to property with 'readonly' attribute not allowed}} + self.z = 2; // expected-error {{assignment to readonly property}} } @end @@ -85,7 +85,7 @@ static int g_val; - (void)setFoo:(int)value; @end -void g(int); +void g(int); // expected-note {{passing argument to parameter here}} void f(C *c) { c.Foo = 17; // OK diff --git a/test/SemaObjC/property.m b/test/SemaObjC/property.m index 7d1cb7a36160..a9487412c19d 100644 --- a/test/SemaObjC/property.m +++ b/test/SemaObjC/property.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin9 -fobjc-fragile-abi -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i386-apple-darwin9 -fobjc-fragile-abi -fsyntax-only -verify -Wno-objc-root-class %s @interface I { @@ -65,3 +65,19 @@ typedef id BYObjectIdentifier; // rdar://10127639 @synthesize window; // expected-error {{missing context for property implementation declaration}} + +// rdar://10408414 +Class test6_getClass(); +@interface Test6 +@end +@implementation Test6 ++ (float) globalValue { return 5.0f; } ++ (float) gv { return test6_getClass().globalValue; } +@end + +@interface Test7 +@property unsigned length; +@end +void test7(Test7 *t) { + char data[t.length] = {}; // expected-error {{variable-sized object may not be initialized}} +} diff --git a/test/SemaObjC/protocol-archane.m b/test/SemaObjC/protocol-archane.m index 992d3e4798c1..49c9851122ec 100644 --- a/test/SemaObjC/protocol-archane.m +++ b/test/SemaObjC/protocol-archane.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // rdar://5986251 @protocol SomeProtocol diff --git a/test/SemaObjC/protocol-id-test-1.m b/test/SemaObjC/protocol-id-test-1.m index 6b2b682a135d..19a4432de619 100644 --- a/test/SemaObjC/protocol-id-test-1.m +++ b/test/SemaObjC/protocol-id-test-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify %s +// RUN: %clang_cc1 -verify -Wno-objc-root-class %s @interface FF - (void) Meth; diff --git a/test/SemaObjC/protocol-id-test-2.m b/test/SemaObjC/protocol-id-test-2.m index a9365e9cb932..6bd2feeeaf1f 100644 --- a/test/SemaObjC/protocol-id-test-2.m +++ b/test/SemaObjC/protocol-id-test-2.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify %s +// RUN: %clang_cc1 -verify -Wno-objc-root-class %s @protocol P @end diff --git a/test/SemaObjC/protocol-implementing-class-methods.m b/test/SemaObjC/protocol-implementing-class-methods.m index f08a5a97d8b7..503eef11ca68 100644 --- a/test/SemaObjC/protocol-implementing-class-methods.m +++ b/test/SemaObjC/protocol-implementing-class-methods.m @@ -5,11 +5,11 @@ @optional - (int) PMeth; @required -- (void) : (double) arg; // expected-note {{method declared here}} +- (void) : (double) arg; // expected-note {{method ':' declared here}} @end @interface NSImage <P1> -- (void) initialize; // expected-note {{method declared here}} +- (void) initialize; // expected-note {{method 'initialize' declared here}} @end @interface NSImage (AirPortUI) @@ -17,7 +17,7 @@ @end @interface NSImage() -- (void) CEMeth; // expected-note {{method declared here}} +- (void) CEMeth; // expected-note {{method 'CEMeth' declared here}} @end @implementation NSImage (AirPortUI) diff --git a/test/SemaObjC/provisional-ivar-lookup.m b/test/SemaObjC/provisional-ivar-lookup.m index 007c21b726a5..2ec23a55c37c 100644 --- a/test/SemaObjC/provisional-ivar-lookup.m +++ b/test/SemaObjC/provisional-ivar-lookup.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -verify %s +// RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -verify -Wno-objc-root-class %s // rdar:// 8565343 @interface Foo { diff --git a/test/SemaObjC/qualified-protocol-method-conflicts.m b/test/SemaObjC/qualified-protocol-method-conflicts.m index 0cff3ff46841..d1d5612ef0ed 100644 --- a/test/SemaObjC/qualified-protocol-method-conflicts.m +++ b/test/SemaObjC/qualified-protocol-method-conflicts.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -Woverriding-method-mismatch -fsyntax-only -verify %s +// RUN: %clang_cc1 -Woverriding-method-mismatch -fsyntax-only -verify -Wno-objc-root-class %s // rdar://6191214 @protocol Xint diff --git a/test/SemaObjC/receiver-forward-class.m b/test/SemaObjC/receiver-forward-class.m new file mode 100644 index 000000000000..cefb5d782f99 --- /dev/null +++ b/test/SemaObjC/receiver-forward-class.m @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -fsyntax-only -Wreceiver-forward-class -verify %s +// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -Wreceiver-forward-class -verify %s +// rdar://10686120 + +@class A; // expected-note {{forward declaration of class here}} + +@interface B +-(int) width; // expected-note {{using}} +@end +@interface C +-(float) width; // expected-note {{also found}} +@end + +int f0(A *x) { + return [x width]; // expected-warning {{receiver type 'A' for instance message is a forward declaration}} \ + // expected-warning {{multiple methods named 'width' found}} \ + // expected-note {{receiver is treated with 'id' type for purpose of method lookup}} +} + diff --git a/test/SemaObjC/related-result-type-inference.m b/test/SemaObjC/related-result-type-inference.m index 11b4b9602e14..124767cd6654 100644 --- a/test/SemaObjC/related-result-type-inference.m +++ b/test/SemaObjC/related-result-type-inference.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify %s +// RUN: %clang_cc1 -verify -Wno-objc-root-class %s @interface Unrelated @end @@ -150,7 +150,7 @@ void test_inference() { // <rdar://problem/9340699> @interface G -- (id)_ABC_init __attribute__((objc_method_family(init))); // expected-note {{method declared here}} +- (id)_ABC_init __attribute__((objc_method_family(init))); // expected-note {{method '_ABC_init' declared here}} @end @interface G (Additions) @@ -169,3 +169,12 @@ void test_inference() { } @end +// PR12384 +@interface Fail @end +@protocol X @end +@implementation Fail +- (id<X>) initWithX +{ + return (id)self; // expected-warning {{returning 'Fail *' from a function with incompatible result type 'id<X>'}} +} +@end diff --git a/test/SemaObjC/return.m b/test/SemaObjC/return.m index 4e70bde1edc1..f69d41eaade9 100644 --- a/test/SemaObjC/return.m +++ b/test/SemaObjC/return.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -fsyntax-only -verify -Wmissing-noreturn -fobjc-exceptions +// RUN: %clang_cc1 -fsyntax-only -verify -Wmissing-noreturn -fobjc-exceptions -Wno-objc-root-class %s int test1() { id a; diff --git a/test/SemaObjC/scope-check.m b/test/SemaObjC/scope-check.m index 3f474be6e8df..e19ba47ad272 100644 --- a/test/SemaObjC/scope-check.m +++ b/test/SemaObjC/scope-check.m @@ -1,11 +1,11 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions %s +// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions -Wno-objc-root-class %s @class A, B, C; void test1() { - goto L; // expected-error{{illegal goto into protected scope}} - goto L2; // expected-error{{illegal goto into protected scope}} - goto L3; // expected-error{{illegal goto into protected scope}} + goto L; // expected-error{{goto into protected scope}} + goto L2; // expected-error{{goto into protected scope}} + goto L3; // expected-error{{goto into protected scope}} @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{{illegal goto into protected scope}} - goto L5; // expected-error{{illegal goto into protected scope}} + goto L4; // expected-error{{goto into protected scope}} + goto L5; // expected-error{{goto into protected scope}} } @catch (C *c) { // expected-note {{jump bypasses initialization of @catch block}} L5: ; - goto L6; // expected-error{{illegal goto into protected scope}} + goto L6; // expected-error{{goto into protected scope}} } @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{{illegal goto into protected scope}} + goto L7; // expected-error{{goto into protected scope}} } @finally { - goto L7; // expected-error{{illegal goto into protected scope}} + goto L7; // expected-error{{goto into protected scope}} } - goto L8; // expected-error{{illegal goto into protected scope}} + goto L8; // expected-error{{goto into protected scope}} @try { } @catch (A *c) { } @catch (B *c) { @@ -47,7 +47,7 @@ L3: ; // rdar://6810106 id X; - goto L9; // expected-error{{illegal goto into protected scope}} + goto L9; // expected-error{{goto into protected scope}} 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 {{illegal goto into protected scope}} + goto blargh; // expected-error {{goto into protected scope}} } @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 {{illegal goto into protected scope}} + goto L0; // expected-error {{goto into protected scope}} typedef int A[n]; // expected-note {{jump bypasses initialization of VLA typedef}} L0: - goto L1; // expected-error {{illegal goto into protected scope}} + goto L1; // expected-error {{goto into protected scope}} A b, c[10]; // expected-note 2 {{jump bypasses initialization of variable length array}} L1: - goto L2; // expected-error {{illegal goto into protected scope}} + goto L2; // expected-error {{goto into protected scope}} A d[n]; // expected-note {{jump bypasses initialization of variable length array}} L2: return; diff --git a/test/SemaObjC/selector-3.m b/test/SemaObjC/selector-3.m index b248a5d036ab..4c12a9392dc1 100644 --- a/test/SemaObjC/selector-3.m +++ b/test/SemaObjC/selector-3.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Wselector -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wselector -verify -Wno-objc-root-class %s // rdar://8851684 @interface Foo diff --git a/test/SemaObjC/selector-error.m b/test/SemaObjC/selector-error.m index dfd6bd053d19..f59dec812b70 100644 --- a/test/SemaObjC/selector-error.m +++ b/test/SemaObjC/selector-error.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface Foo - (char*) foo; diff --git a/test/SemaObjC/self-assign.m b/test/SemaObjC/self-assign.m index f05b028d6718..e0f5f43f3319 100644 --- a/test/SemaObjC/self-assign.m +++ b/test/SemaObjC/self-assign.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface A @end diff --git a/test/SemaObjC/self-declared-in-block.m b/test/SemaObjC/self-declared-in-block.m index 25ce8ba59933..40a03313b693 100644 --- a/test/SemaObjC/self-declared-in-block.m +++ b/test/SemaObjC/self-declared-in-block.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin10 -fblocks -verify %s -// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -triple x86_64-apple-darwin10 -fblocks -verify %s +// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin10 -fblocks -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -triple x86_64-apple-darwin10 -fblocks -verify -Wno-objc-root-class %s // rdar://9154582 @interface Blocky @end diff --git a/test/SemaObjC/severe-syntax-error.m b/test/SemaObjC/severe-syntax-error.m new file mode 100644 index 000000000000..8c59151c2bdd --- /dev/null +++ b/test/SemaObjC/severe-syntax-error.m @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s +// rdar://10633434 + +@interface testClass +@end + +@class NSArray; + +@implementation testClass + +static NSArray* prefixArray[] = @"BEGIN:", @"END:", @"VERSION:", @"N:", @"FN:", @"TEL;", @"TEL:", nil; // expected-error {{array initializer must be an initializer list}} \ + // expected-error {{expected identifier or '('}} \ + // expected-error {{expected ';' after top level declarator}} + +static NSString* prefixArray1[] = @"BEGIN:", @"END:", @"VERSION:", @"N:", @"FN:", @"TEL;", @"TEL:", nil; // expected-error {{unknown type name 'NSString'}} \ + // expected-error {{expected identifier or '('}} \ + // expected-error {{expected ';' after top level declarator}} + +static char* cArray[] = "BEGIN:", "END"; // expected-error {{array initializer must be an initializer list}} \ + // expected-error {{expected identifier or '('}} \ + // expected-error {{expected ';' after top level declarator}} + +@end diff --git a/test/SemaObjC/sizeof-interface.m b/test/SemaObjC/sizeof-interface.m index 43870a17a30f..7304b6c2c8a6 100644 --- a/test/SemaObjC/sizeof-interface.m +++ b/test/SemaObjC/sizeof-interface.m @@ -1,6 +1,6 @@ -// RUN: %clang_cc1 -verify -fsyntax-only %s +// RUN: %clang_cc1 -verify -fsyntax-only -Wno-objc-root-class %s -@class I0; +@class I0; // expected-note 2{{forward declaration of class here}} // rdar://6811884 int g0 = sizeof(I0); // expected-error{{invalid application of 'sizeof' to an incomplete type 'I0'}} @@ -9,7 +9,7 @@ int g0 = sizeof(I0); // expected-error{{invalid application of 'sizeof' to an in void *g3(I0 *P) { P = P+5; // expected-error {{arithmetic on a pointer to an incomplete type 'I0'}} - return &P[4]; // expected-error{{subscript of pointer to incomplete type 'I0'}} + return &P[4]; // expected-error{{expected method to read array element not found on object of type 'I0 *'}} } @@ -55,7 +55,7 @@ int bar(I0 *P) { P = 5+P; // expected-error {{arithmetic on pointer to interface 'I0', which is not a constant size in non-fragile ABI}} P = P-5; // expected-error {{arithmetic on pointer to interface 'I0', which is not a constant size in non-fragile ABI}} - return P[4].x[2]; // expected-error {{subscript requires size of interface 'I0', which is not constant in non-fragile ABI}} + return P[4].x[2]; // expected-error {{expected method to read array element not found on object of type 'I0 *'}} } diff --git a/test/SemaObjC/special-dep-unavail-warning.m b/test/SemaObjC/special-dep-unavail-warning.m index 57a2fa346569..754bf5f4cb63 100644 --- a/test/SemaObjC/special-dep-unavail-warning.m +++ b/test/SemaObjC/special-dep-unavail-warning.m @@ -27,7 +27,7 @@ @end -@class C; // expected-note 5 {{forward class is declared here}} +@class C; // expected-note 5 {{forward declaration of class here}} void test(C *c) { [c depInA]; // expected-warning {{'depInA' maybe deprecated because receiver type is unknown}} @@ -43,3 +43,13 @@ void test(C *c) { } +// rdar://10268422 +__attribute ((deprecated)) +@interface DEPRECATED ++(id)new; +@end + +void foo() { + [DEPRECATED new]; // expected-warning {{'DEPRECATED' is deprecated}} +} + diff --git a/test/SemaObjC/stand-alone-implementation.m b/test/SemaObjC/stand-alone-implementation.m index c33b66a37bc3..6fa9b4bec5a2 100644 --- a/test/SemaObjC/stand-alone-implementation.m +++ b/test/SemaObjC/stand-alone-implementation.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // radar 7547942 // Allow injection of ivars into implementation's implicit class. diff --git a/test/SemaObjC/super.m b/test/SemaObjC/super.m index 0c42e99d715d..cf48c196db2d 100644 --- a/test/SemaObjC/super.m +++ b/test/SemaObjC/super.m @@ -21,7 +21,7 @@ void takevoidptr(void*); @implementation B - (void)instanceMethod { - [super iMethod]; // expected-warning{{'A' may not respond to 'iMethod')}} + [super iMethod]; // expected-warning{{'A' may not respond to 'iMethod'}} // Use of super in a block is ok and does codegen to the right thing. // rdar://7852959 diff --git a/test/SemaObjC/synchronized.m b/test/SemaObjC/synchronized.m index dac620a81829..c158815acbf8 100644 --- a/test/SemaObjC/synchronized.m +++ b/test/SemaObjC/synchronized.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface PBXTrackableTaskManager @end diff --git a/test/SemaObjC/synth-provisional-ivars-1.m b/test/SemaObjC/synth-provisional-ivars-1.m index 8bf687811fd2..0e155f4840f0 100644 --- a/test/SemaObjC/synth-provisional-ivars-1.m +++ b/test/SemaObjC/synth-provisional-ivars-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -verify %s +// RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -verify -Wno-objc-root-class %s // rdar://8913053 typedef unsigned char BOOL; diff --git a/test/SemaObjC/synth-provisional-ivars.m b/test/SemaObjC/synth-provisional-ivars.m index 696eb9b38558..9d7abd566d7a 100644 --- a/test/SemaObjC/synth-provisional-ivars.m +++ b/test/SemaObjC/synth-provisional-ivars.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -verify %s +// RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -verify -Wno-objc-root-class %s int bar; diff --git a/test/SemaObjC/synthesize-setter-contclass.m b/test/SemaObjC/synthesize-setter-contclass.m index 36967d458e36..d75441518725 100644 --- a/test/SemaObjC/synthesize-setter-contclass.m +++ b/test/SemaObjC/synthesize-setter-contclass.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface TestClass { diff --git a/test/SemaObjC/synthesized-ivar.m b/test/SemaObjC/synthesized-ivar.m index 745fe77449ac..8c9d90587f4d 100644 --- a/test/SemaObjC/synthesized-ivar.m +++ b/test/SemaObjC/synthesized-ivar.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -verify %s +// RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -verify -Wno-objc-root-class %s @interface I { } diff --git a/test/SemaObjC/transparent-union.m b/test/SemaObjC/transparent-union.m index cb03dfec3563..6f2dbf915ac0 100644 --- a/test/SemaObjC/transparent-union.m +++ b/test/SemaObjC/transparent-union.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s typedef union { struct xx_object_s *_do; diff --git a/test/SemaObjC/try-catch.m b/test/SemaObjC/try-catch.m index da06eca47026..5afbbb6c32e8 100644 --- a/test/SemaObjC/try-catch.m +++ b/test/SemaObjC/try-catch.m @@ -40,7 +40,7 @@ typedef struct _NSZone NSZone; int foo() { struct s { int a, b; } agg, *pagg; - @throw 42; // expected-error {{@throw requires an Objective-C object type ('int' invalid))}} + @throw 42; // expected-error {{@throw requires an Objective-C object type ('int' invalid)}} @throw agg; // expected-error {{@throw requires an Objective-C object type ('struct s' invalid)}} @throw pagg; // expected-error {{@throw requires an Objective-C object type ('struct s *' invalid)}} @throw; // expected-error {{@throw (rethrow) used outside of a @catch block}} diff --git a/test/SemaObjC/typedef-class.m b/test/SemaObjC/typedef-class.m index c983195b243e..bd68397fd969 100644 --- a/test/SemaObjC/typedef-class.m +++ b/test/SemaObjC/typedef-class.m @@ -48,13 +48,13 @@ typedef NSObject < XCElementSpacerP > XCElementSpacer; @protocol XCElementTogglerP < XCElementP > -(void) setDisplayed:(BOOL) displayed; @end -typedef NSObject < XCElementTogglerP > XCElementToggler; +typedef NSObject < XCElementTogglerP > XCElementToggler; // expected-note {{previous definition is here}} @interface XCElementRootFace:NSObject {} @end @interface XCElementFace:XCElementRootFace {} @end -@class XCElementToggler; +@class XCElementToggler; // expected-warning {{redefinition of forward class 'XCElementToggler' of a typedef name of an object type is ignored}} @interface XCRASlice:XCElementFace {} @end diff --git a/test/SemaObjC/undeclared-selector.m b/test/SemaObjC/undeclared-selector.m index af52fde8806e..091451003f55 100644 --- a/test/SemaObjC/undeclared-selector.m +++ b/test/SemaObjC/undeclared-selector.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Wundeclared-selector -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wundeclared-selector -verify -Wno-objc-root-class %s typedef struct objc_selector *SEL; diff --git a/test/SemaObjC/undef-protocol-methods-1.m b/test/SemaObjC/undef-protocol-methods-1.m index 44d384c63940..15ba1a1eb2f8 100644 --- a/test/SemaObjC/undef-protocol-methods-1.m +++ b/test/SemaObjC/undef-protocol-methods-1.m @@ -1,25 +1,25 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @protocol P1 -- (void) P1proto; // expected-note {{method declared here}} -+ (void) ClsP1Proto; // expected-note {{method declared here}} +- (void) P1proto; // expected-note {{method 'P1proto' declared here}} ++ (void) ClsP1Proto; // expected-note {{method 'ClsP1Proto' declared here}} - (void) DefP1proto; @end @protocol P2 -- (void) P2proto; // expected-note {{method declared here}} -+ (void) ClsP2Proto; // expected-note {{method declared here}} +- (void) P2proto; // expected-note {{method 'P2proto' declared here}} ++ (void) ClsP2Proto; // expected-note {{method 'ClsP2Proto' declared here}} @end @protocol P3<P2> -- (void) P3proto; // expected-note {{method declared here}} -+ (void) ClsP3Proto; // expected-note {{method declared here}} +- (void) P3proto; // expected-note {{method 'P3proto' declared here}} ++ (void) ClsP3Proto; // expected-note {{method 'ClsP3Proto' declared here}} + (void) DefClsP3Proto; @end @protocol PROTO<P1, P3> -- (void) meth; // expected-note {{method declared here}} -- (void) meth : (int) arg1; // expected-note {{method declared here}} -+ (void) cls_meth : (int) arg1; // expected-note {{method declared here}} +- (void) meth; // expected-note {{method 'meth' declared here}} +- (void) meth : (int) arg1; // expected-note {{method 'meth:' declared here}} ++ (void) cls_meth : (int) arg1; // expected-note {{method 'cls_meth:' declared here}} @end @interface INTF <PROTO> // expected-note 3 {{required for direct or indirect protocol 'PROTO'}} \ @@ -29,7 +29,7 @@ @end @implementation INTF // expected-warning {{incomplete implementation}} \ - // expected-warning 9 {{method in protocol not implemented [-Wprotocol}} + // expected-warning 9 {{in protocol not implemented}} - (void) DefP1proto{} + (void) DefClsP3Proto{} diff --git a/test/SemaObjC/undef-superclass-1.m b/test/SemaObjC/undef-superclass-1.m index 41cf1439bd9c..e8e03c5938f2 100644 --- a/test/SemaObjC/undef-superclass-1.m +++ b/test/SemaObjC/undef-superclass-1.m @@ -1,6 +1,6 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s -@class SUPER, Y; // expected-note 2 {{forward class is declared here}} +@class SUPER, Y; // expected-note 2 {{forward declaration of class here}} @interface INTF :SUPER // expected-error {{attempting to use the forward class 'SUPER' as superclass of 'INTF'}} @end diff --git a/test/SemaObjC/undefined-protocol-type-1.m b/test/SemaObjC/undefined-protocol-type-1.m index 3be4425cdcec..f1a08024b251 100644 --- a/test/SemaObjC/undefined-protocol-type-1.m +++ b/test/SemaObjC/undefined-protocol-type-1.m @@ -5,5 +5,5 @@ @interface T - (T<p2, p3, p1, p4>*) meth; // expected-error {{cannot find protocol declaration for 'p3'}} -- (T<p2, p3, p1, p4>*) meth; // expected-error {{cannot find protocol declaration for 'p3'}} +- (T<p2, p3, p1, p4>*) meth1; // expected-error {{cannot find protocol declaration for 'p3'}} @end diff --git a/test/SemaObjC/unimplemented-protocol-prop.m b/test/SemaObjC/unimplemented-protocol-prop.m index fa3ed8ef121c..1438cf595d1f 100644 --- a/test/SemaObjC/unimplemented-protocol-prop.m +++ b/test/SemaObjC/unimplemented-protocol-prop.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @protocol PROTOCOL0 @required diff --git a/test/SemaObjC/unknown-anytype.m b/test/SemaObjC/unknown-anytype.m new file mode 100644 index 000000000000..38e058c513f6 --- /dev/null +++ b/test/SemaObjC/unknown-anytype.m @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -funknown-anytype -fsyntax-only -fdebugger-support -verify %s + +extern __unknown_anytype test0; +extern __unknown_anytype test1(); + +@interface A +- (int*)getIntPtr; +- (double*)getSomePtr; +@end + +@interface B +- (float*)getFloatPtr; +- (short*)getSomePtr; +@end + +void test_unknown_anytype_receiver() { + int *ip = [test0 getIntPtr]; + float *fp = [test1() getFloatPtr]; + double *dp = [test1() getSomePtr]; // okay: picks first method found + [[test0 unknownMethod] otherUnknownMethod]; // expected-error{{no known method '-otherUnknownMethod'; cast the message send to the method's return type}} + (void)(int)[[test0 unknownMethod] otherUnknownMethod];; + [[test1() unknownMethod] otherUnknownMethod]; // expected-error{{no known method '-otherUnknownMethod'; cast the message send to the method's return type}} + (void)(id)[[test1() unknownMethod] otherUnknownMethod]; + + if ([[test0 unknownMethod] otherUnknownMethod]) { // expected-error{{no known method '-otherUnknownMethod'; cast the message send to the method's return type}} + } + if ([[test1() unknownMethod] otherUnknownMethod]) { // expected-error{{no known method '-otherUnknownMethod'; cast the message send to the method's return type}} + } +} diff --git a/test/SemaObjC/unused.m b/test/SemaObjC/unused.m index 1ecf32295eae..975b9a96a773 100644 --- a/test/SemaObjC/unused.m +++ b/test/SemaObjC/unused.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -verify -Wunused -Wunused-parameter -fsyntax-only +// RUN: %clang_cc1 -verify -Wunused -Wunused-parameter -fsyntax-only -Wno-objc-root-class %s int printf(const char *, ...); diff --git a/test/SemaObjC/warn-deprecated-implementations.m b/test/SemaObjC/warn-deprecated-implementations.m index 60da7b0c41dc..919b2211ddc4 100644 --- a/test/SemaObjC/warn-deprecated-implementations.m +++ b/test/SemaObjC/warn-deprecated-implementations.m @@ -1,16 +1,16 @@ -// RUN: %clang_cc1 -fsyntax-only -Wdeprecated-implementations -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wdeprecated-implementations -verify -Wno-objc-root-class %s // rdar://8973810 @protocol P -- (void) D __attribute__((deprecated)); // expected-note {{method declared here}} +- (void) D __attribute__((deprecated)); // expected-note {{method 'D' declared here}} @end @interface A <P> -+ (void)F __attribute__((deprecated)); // expected-note {{method declared here}} ++ (void)F __attribute__((deprecated)); // expected-note {{method 'F' declared here}} @end @interface A() -- (void) E __attribute__((deprecated)); // expected-note {{method declared here}} +- (void) E __attribute__((deprecated)); // expected-note {{method 'E' declared here}} @end @implementation A @@ -34,7 +34,7 @@ __attribute__((deprecated)) @end @interface BASE -- (void) B __attribute__((deprecated)); // expected-note {{method declared here}} +- (void) B __attribute__((deprecated)); // expected-note {{method 'B' declared here}} @end @interface SUB : BASE diff --git a/test/SemaObjC/warn-forward-class-attr-deprecated.m b/test/SemaObjC/warn-forward-class-attr-deprecated.m new file mode 100644 index 000000000000..854ff699eed4 --- /dev/null +++ b/test/SemaObjC/warn-forward-class-attr-deprecated.m @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s +// rdar://10290322 + +@class ABGroupImportFilesScope; // expected-note {{forward declaration of class here}} + +@interface I1 +- (id) filenames __attribute__((deprecated)); +@end + +@interface I2 +- (id) Meth : (ABGroupImportFilesScope*) scope; +- (id) filenames __attribute__((deprecated)); +- (id)initWithAccount: (id)account filenames:(id)filenames; +@end + +@implementation I2 +- (id) Meth : (ABGroupImportFilesScope*) scope +{ + id p = [self initWithAccount : 0 filenames :[scope filenames]]; // expected-warning {{'filenames' maybe deprecated because receiver type is unknown}} + return 0; +} +- (id) filenames { return 0; } +- (id)initWithAccount: (id)account filenames:(id)filenames { return 0; } +@end diff --git a/test/SemaObjC/warn-implicit-atomic-property.m b/test/SemaObjC/warn-implicit-atomic-property.m index ec8e84e20f0c..887a2862250a 100644 --- a/test/SemaObjC/warn-implicit-atomic-property.m +++ b/test/SemaObjC/warn-implicit-atomic-property.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Wimplicit-atomic-properties -fobjc-default-synthesize-properties -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wimplicit-atomic-properties -fobjc-default-synthesize-properties -verify -Wno-objc-root-class %s // rdar://8774580 @interface Super @@ -8,6 +8,6 @@ @property int P3; // expected-note {{property declared here}} @end -@implementation Super // expected-warning {{property is assumed atomic when auto-synthesizing the property [-Wimplicit-atomic-properties]}} -@synthesize P,P1,P2; // expected-warning {{property is assumed atomic by default [-Wimplicit-atomic-properties]}} +@implementation Super // expected-warning {{property is assumed atomic when auto-synthesizing the property}} +@synthesize P,P1,P2; // expected-warning {{property is assumed atomic by default}} @end diff --git a/test/SemaObjC/warn-missing-super.m b/test/SemaObjC/warn-missing-super.m index 0169a6157258..02b81651d7a2 100644 --- a/test/SemaObjC/warn-missing-super.m +++ b/test/SemaObjC/warn-missing-super.m @@ -1,5 +1,6 @@ @protocol NSCopying @end +__attribute__((objc_root_class)) @interface NSObject <NSCopying> - (void)dealloc; @end @@ -40,18 +41,18 @@ @end // RUN: %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck %s -// CHECK: warn-missing-super.m:23:1: warning: method possibly missing a [super dealloc] call +// CHECK: warn-missing-super.m:24:1: warning: method possibly missing a [super dealloc] call // CHECK: 1 warning generated. // RUN: %clang_cc1 -fsyntax-only -fobjc-gc %s 2>&1 | FileCheck --check-prefix=CHECK-GC %s -// CHECK-GC: warn-missing-super.m:23:1: warning: method possibly missing a [super dealloc] call -// CHECK-GC: warn-missing-super.m:25:1: warning: method possibly missing a [super finalize] call +// CHECK-GC: warn-missing-super.m:24:1: warning: method possibly missing a [super dealloc] call +// CHECK-GC: warn-missing-super.m:26:1: warning: method possibly missing a [super finalize] call // CHECK-GC: 2 warnings generated. // RUN: %clang_cc1 -fsyntax-only -fobjc-gc-only %s 2>&1 | FileCheck --check-prefix=CHECK-GC-ONLY %s -// CHECK-GC-ONLY: warn-missing-super.m:25:1: warning: method possibly missing a [super finalize] call +// CHECK-GC-ONLY: warn-missing-super.m:26:1: warning: method possibly missing a [super finalize] call // CHECK-GC-ONLY: 1 warning generated. // RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin10 -fobjc-arc %s 2>&1 | FileCheck --check-prefix=CHECK-ARC %s -// CHECK-ARC: warn-missing-super.m:35:4: error: ARC forbids explicit message send of 'dealloc' +// CHECK-ARC: warn-missing-super.m:36:4: error: ARC forbids explicit message send of 'dealloc' // CHECK-ARC: 1 error generated. diff --git a/test/SemaObjC/warn-retain-cycle.m b/test/SemaObjC/warn-retain-cycle.m index 596858f83a3e..00fd234a0c09 100644 --- a/test/SemaObjC/warn-retain-cycle.m +++ b/test/SemaObjC/warn-retain-cycle.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -fblocks -verify %s +// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -fblocks -verify -Wno-objc-root-class %s @interface Test0 - (void) setBlock: (void(^)(void)) block; @@ -89,3 +89,37 @@ void test2_helper(id); }; } @end + + +@interface NSOperationQueue {} +- (void)addOperationWithBlock:(void (^)(void))block; +- (void)addSomethingElse:(void (^)(void))block; + +@end + +@interface Test3 { + NSOperationQueue *myOperationQueue; + unsigned count; +} +@end +void doSomething(unsigned v); +@implementation Test3 +- (void) test { + // 'addOperationWithBlock:' is specifically whitelisted. + [myOperationQueue addOperationWithBlock:^() { // no-warning + if (count > 20) { + doSomething(count); + } + }]; +} +- (void) test_positive { + // Sanity check that we are really whitelisting 'addOperationWithBlock:' and not doing + // something funny. + [myOperationQueue addSomethingElse:^() { // expected-note {{block will be retained by an object strongly retained by the captured object}} + if (count > 20) { // expected-warning {{capturing 'self' strongly in this block is likely to lead to a retain cycle}} + doSomething(count); + } + }]; +} +@end + diff --git a/test/SemaObjC/warn-strict-selector-match.m b/test/SemaObjC/warn-strict-selector-match.m index 8ac0ca46ac43..34f1712f8b58 100644 --- a/test/SemaObjC/warn-strict-selector-match.m +++ b/test/SemaObjC/warn-strict-selector-match.m @@ -8,7 +8,7 @@ -(float) method; // expected-note {{also found}} @end -int main() { [(id)0 method]; } // expected-warning {{multiple methods named 'method' found [-Wstrict-selector-match]}} +int main() { [(id)0 method]; } // expected-warning {{multiple methods named 'method' found}} @interface Object @end @@ -24,7 +24,7 @@ id foo(void) { Object *obj = 0; id obj2 = obj; [obj setWindow:0]; // expected-warning {{Object' may not respond to 'setWindow:'}} - [obj2 setWindow:0]; // expected-warning {{multiple methods named 'setWindow:' found [-Wstrict-selector-match]}} + [obj2 setWindow:0]; // expected-warning {{multiple methods named 'setWindow:' found}} return obj; } @@ -54,7 +54,7 @@ id foo(void) { } + (NTGridDataObject*)dataObject:(id<MyObject, MyCoding>)data { - NTGridDataObject *result = [(id)0 initWithData:data]; // expected-warning {{multiple methods named 'initWithData:' found [-Wstrict-selector-match]}} \ + 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 *'}} return result; } diff --git a/test/SemaObjC/warn-unreachable.m b/test/SemaObjC/warn-unreachable.m new file mode 100644 index 000000000000..832cbd23d27e --- /dev/null +++ b/test/SemaObjC/warn-unreachable.m @@ -0,0 +1,17 @@ +// RUN: %clang %s -fsyntax-only -Xclang -verify -fblocks -Wunreachable-code -Wno-unused-value -Wno-covered-switch-default + +// This previously triggered a warning from -Wunreachable-code because of +// a busted CFG. +typedef signed char BOOL; +BOOL radar10989084() { + @autoreleasepool { // no-warning + return __objc_yes; + } +} + +// Test the warning works. +void test_unreachable() { + return; + return; // expected-warning {{will never be executed}} +} + diff --git a/test/SemaObjC/warn-weak-field.m b/test/SemaObjC/warn-weak-field.m index ead454a04a37..e7b0fe2694d6 100644 --- a/test/SemaObjC/warn-weak-field.m +++ b/test/SemaObjC/warn-weak-field.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -fobjc-gc -verify %s -// RUN: %clang_cc1 -x objective-c++ -triple i386-apple-darwin9 -fsyntax-only -fobjc-gc -verify %s +// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -fobjc-gc -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -x objective-c++ -triple i386-apple-darwin9 -fsyntax-only -fobjc-gc -verify -Wno-objc-root-class %s struct S { __weak id w; // expected-warning {{__weak attribute cannot be specified on a field declaration}} diff --git a/test/SemaObjC/weak-property.m b/test/SemaObjC/weak-property.m index bea66281ea7b..8a2adf99b7e4 100644 --- a/test/SemaObjC/weak-property.m +++ b/test/SemaObjC/weak-property.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -verify %s +// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -verify -Wno-objc-root-class %s // rdar://8899430 @interface WeakPropertyTest { diff --git a/test/SemaObjC/weak-receiver-warn.m b/test/SemaObjC/weak-receiver-warn.m new file mode 100644 index 000000000000..f3955da3bc28 --- /dev/null +++ b/test/SemaObjC/weak-receiver-warn.m @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -fblocks -Wreceiver-is-weak -verify %s +// rdar://10225276 + +@interface Test0 +- (void) setBlock: (void(^)(void)) block; +- (void) addBlock: (void(^)(void)) block; +- (void) actNow; +@end + +void test0(Test0 *x) { + __weak Test0 *weakx = x; + [x addBlock: ^{ [weakx actNow]; }]; // expected-warning {{weak receiver may be unpredictably null in ARC mode}} + [x setBlock: ^{ [weakx actNow]; }]; // expected-warning {{weak receiver may be unpredictably null in ARC mode}} + x.block = ^{ [weakx actNow]; }; // expected-warning {{weak receiver may be unpredictably null in ARC mode}} + + [weakx addBlock: ^{ [x actNow]; }]; // expected-warning {{weak receiver may be unpredictably null in ARC mode}} + [weakx setBlock: ^{ [x actNow]; }]; // expected-warning {{weak receiver may be unpredictably null in ARC mode}} + weakx.block = ^{ [x actNow]; }; +} |