diff options
Diffstat (limited to 'clang/test/SemaObjC')
80 files changed, 2677 insertions, 0 deletions
diff --git a/clang/test/SemaObjC/DoubleMethod.m b/clang/test/SemaObjC/DoubleMethod.m new file mode 100644 index 00000000000..70c7ed55f1e --- /dev/null +++ b/clang/test/SemaObjC/DoubleMethod.m @@ -0,0 +1,19 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface Subclass +{ + int ivar; +} + +- (void) method; +- (void) method; +@end + +@implementation Subclass +- (void) method {;} // expected-error {{previous declaration is here}} +- (void) method {;} // expected-error {{duplicate declaration of method 'method'}} +@end + +int main (void) { + return 0; +} diff --git a/clang/test/SemaObjC/alias-test-1.m b/clang/test/SemaObjC/alias-test-1.m new file mode 100644 index 00000000000..fdaccf3f8bc --- /dev/null +++ b/clang/test/SemaObjC/alias-test-1.m @@ -0,0 +1,31 @@ +// RUN: clang -fsyntax-only -verify %s + +@compatibility_alias alias4 foo; // expected-warning {{cannot find interface declaration for 'foo'}} + +@class class2; // expected-error {{previous declaration is here}} +@class class3; + +typedef int I; // expected-warning {{previous declaration is here}} + +@compatibility_alias alias1 I; // expected-warning {{cannot find interface declaration for 'I'}} + +@compatibility_alias alias class2; +@compatibility_alias alias class3; // expected-error {{conflicting types for alias 'alias'}} + + +typedef int alias2; // expected-error {{previous declaration is here}} +@compatibility_alias alias2 class3; // expected-error {{conflicting types for alias 'alias2'}} + +alias *p; +class2 *p2; + +int foo () +{ + + if (p == p2) { + int alias = 1; + } + + alias *p3; + return p3 == p2; +} diff --git a/clang/test/SemaObjC/alias-test-2.m b/clang/test/SemaObjC/alias-test-2.m new file mode 100644 index 00000000000..0a17846685c --- /dev/null +++ b/clang/test/SemaObjC/alias-test-2.m @@ -0,0 +1,16 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface Super @end + +@interface MyWpModule @end + +@compatibility_alias MyAlias MyWpModule; + +@compatibility_alias AliasForSuper Super; + +@interface MyAlias : AliasForSuper // expected-error {{duplicate interface declaration for class 'MyWpModule'}} +@end + +@implementation MyAlias : AliasForSuper +@end + diff --git a/clang/test/SemaObjC/argument-checking.m b/clang/test/SemaObjC/argument-checking.m new file mode 100644 index 00000000000..820a2f09c79 --- /dev/null +++ b/clang/test/SemaObjC/argument-checking.m @@ -0,0 +1,25 @@ +// RUN: clang -fsyntax-only -verify -pedantic %s + +struct S { int a; }; + +extern int charStarFunc(char *); +extern int charFunc(char); + +@interface Test ++alloc; +-(int)charStarMeth:(char *)s; +-structMeth:(struct S)s; +-structMeth:(struct S)s :(struct S)s2; +@end + +void test() { + id obj = [Test alloc]; + struct S sInst; + + charStarFunc(1); // expected-warning {{incompatible integer to pointer conversion passing 'int', expected 'char *'}} + charFunc("abc"); // expected-warning {{incompatible pointer to integer conversion passing 'char [4]', expected 'char'}} + + [obj charStarMeth:1]; // expected-warning {{incompatible integer to pointer conversion sending 'int'}} + [obj structMeth:1]; // expected-error {{incompatible type sending 'int'}} + [obj structMeth:sInst :1]; // expected-error {{incompatible type sending 'int'}} +} diff --git a/clang/test/SemaObjC/category-1.m b/clang/test/SemaObjC/category-1.m new file mode 100644 index 00000000000..15f6b166c5b --- /dev/null +++ b/clang/test/SemaObjC/category-1.m @@ -0,0 +1,56 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface MyClass1 @end + +@protocol p1,p2,p3; + +@interface MyClass1 (Category1) <p1> // expected-warning {{cannot find protocol definition for 'p1', referenced by 'Category1'}} +@end + +@interface MyClass1 (Category1) // expected-warning {{duplicate interface declaration for category 'MyClass1(Category1)'}} +@end + +@interface MyClass1 (Category3) +@end + +@interface MyClass1 (Category4) @end +@interface MyClass1 (Category5) @end +@interface MyClass1 (Category6) @end +@interface MyClass1 (Category7) @end +@interface MyClass1 (Category8) @end + + +@interface MyClass1 (Category4) @end // expected-warning {{duplicate interface declaration for category 'MyClass1(Category4)'}} +@interface MyClass1 (Category7) @end // expected-warning {{duplicate interface declaration for category 'MyClass1(Category7)'}} +@interface MyClass1 (Category8) @end // expected-warning {{duplicate interface declaration for category 'MyClass1(Category8)'}} + + +@protocol p3 @end + +@interface MyClass1 (Category) <p2, p3> @end // expected-warning {{cannot find protocol definition for 'p2', referenced by 'Category'}} + +@interface MyClass (Category) @end // expected-error {{cannot find interface declaration for 'MyClass'}} + +@class MyClass2; + +@interface MyClass2 (Category) @end // expected-error {{cannot find interface declaration for 'MyClass2'}} + +@interface XCRemoteComputerManager +@end + +@interface XCRemoteComputerManager() +@end + +@interface XCRemoteComputerManager() +@end + +@interface XCRemoteComputerManager(x) +@end + +@interface XCRemoteComputerManager(x) // expected-warning {{duplicate interface declaration for category 'XCRemoteComputerManager(x)'}} +@end + +@implementation XCRemoteComputerManager +@end + + diff --git a/clang/test/SemaObjC/check-dup-decl-methods-1.m b/clang/test/SemaObjC/check-dup-decl-methods-1.m new file mode 100644 index 00000000000..36a98a24a46 --- /dev/null +++ b/clang/test/SemaObjC/check-dup-decl-methods-1.m @@ -0,0 +1,38 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface SUPER +- (int) meth; ++ (int) foobar; +@end + +@interface T @end + +@interface class1 : SUPER +- (int) meth; // expected-error {{previous declaration is here}} +- (int*) meth; // expected-error {{duplicate declaration of method 'meth'}} +- (T*) meth1; +- (T*) meth1; ++ (T*) meth1; +@end + +@interface class1(cat) +- (int) catm : (char)ch1; // expected-error {{previous declaration is here}} +- (int) catm1 : (char)ch : (int)i; +- (int) catm : (char*)ch1; // expected-error {{duplicate declaration of method 'catm:'}} ++ (int) catm1 : (char)ch : (int)i; ++ (T*) meth1; +@end + +@interface class1(cat1) ++ (int) catm1 : (char)ch : (int)i; // expected-error {{previous declaration is here}} ++ (T*) meth1; // expected-error {{previous declaration is here}} ++ (int) catm1 : (char)ch : (int*)i; // expected-error {{duplicate declaration of method 'catm1::'}} ++ (T**) meth1; // expected-error {{duplicate declaration of method 'meth1'}} ++ (int) foobar; +@end + +@protocol P +- (int) meth; // expected-error {{previous declaration is here}} +- (int*) meth; // expected-error {{duplicate declaration of method 'meth'}} +@end + diff --git a/clang/test/SemaObjC/check-dup-objc-decls-1.m b/clang/test/SemaObjC/check-dup-objc-decls-1.m new file mode 100644 index 00000000000..e3902bdcca3 --- /dev/null +++ b/clang/test/SemaObjC/check-dup-objc-decls-1.m @@ -0,0 +1,28 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface Foo // expected-error {{previous definition is here}} +@end + +float Foo; // expected-error {{redefinition of 'Foo' as different kind of symbol}} + +@class Bar; // expected-error {{previous definition is here}} + +typedef int Bar; // expected-error {{redefinition of 'Bar' as different kind of symbol}} + +@implementation FooBar // expected-warning {{cannot find interface declaration for 'FooBar'}} +@end + + +typedef int OBJECT; // expected-error {{previous definition is here}} + +@class OBJECT ; // expected-error {{redefinition of 'OBJECT' as different kind of symbol}} + + +typedef int Gorf; // expected-error {{previous definition is here}} + +@interface Gorf @end // expected-error {{redefinition of 'Gorf' as different kind of symbol}} + +void Gorf() // expected-error {{redefinition of 'Gorf' as different kind of symbol}} +{ + int Bar, Foo, FooBar; +} diff --git a/clang/test/SemaObjC/class-conforming-protocol-1.m b/clang/test/SemaObjC/class-conforming-protocol-1.m new file mode 100644 index 00000000000..6afee0d3d4d --- /dev/null +++ b/clang/test/SemaObjC/class-conforming-protocol-1.m @@ -0,0 +1,21 @@ +// RUN: clang -fsyntax-only -verify %s + +@protocol P1 @end +@protocol P2 @end +@protocol P3 @end + +@interface INTF +- (INTF*) METH1; // expected-error {{previous declaration is here}} +- (INTF<P1>*) METH1; // expected-error {{duplicate declaration of method 'METH1'}} + +- (INTF<P1,P2>*) METH2; +- (INTF<P2,P1>*) METH2; // expected-error {{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; + +@end + +INTF<P2,P1,P3>* p1; + diff --git a/clang/test/SemaObjC/class-def-test-1.m b/clang/test/SemaObjC/class-def-test-1.m new file mode 100644 index 00000000000..72702d9d18b --- /dev/null +++ b/clang/test/SemaObjC/class-def-test-1.m @@ -0,0 +1,26 @@ +// RUN: clang -fsyntax-only -verify %s + +@protocol SUPER; + +@interface SUPER <SUPER> @end // expected-warning {{cannot find protocol definition for 'SUPER', referenced by 'SUPER'}} + +typedef int INTF; // expected-error {{previous definition is here}} + +@interface INTF @end // expected-error {{redefinition of 'INTF' as different kind of symbol}} + +@interface OBJECT @end // expected-error {{previous definition is here}} + +@interface INTF1 : OBJECT @end + +@interface INTF1 : OBJECT @end // expected-error {{duplicate interface declaration for class 'INTF1'}} + +typedef int OBJECT; // expected-error {{previous definition is here}} \ + expected-error {{redefinition of 'OBJECT' as different kind of symbol}} + +@interface INTF2 : OBJECT @end // expected-error {{redefinition of 'OBJECT' as different kind of symbol}} + + +@protocol PROTO; + +@interface INTF3 : PROTO @end // expected-error {{cannot find interface declaration for 'PROTO', superclass of 'INTF3'}} + diff --git a/clang/test/SemaObjC/class-impl-1.m b/clang/test/SemaObjC/class-impl-1.m new file mode 100644 index 00000000000..dedce58d2c0 --- /dev/null +++ b/clang/test/SemaObjC/class-impl-1.m @@ -0,0 +1,33 @@ +// RUN: clang -fsyntax-only -verify %s + +typedef int INTF3; // expected-error {{previous definition is here}} + +@interface SUPER @end // expected-error {{previous definition is here}} + +@interface OBJECT @end + +@interface INTF : OBJECT +@end + +@implementation INTF @end + +@implementation INTF // expected-error {{reimplementation of class 'INTF'}} +@end + + +@interface INTF1 : OBJECT +@end + +@implementation INTF1 : SUPER // expected-error {{conflicting super class name 'SUPER'}} +@end + +@interface INTF2 +@end + +@implementation INTF2 : SUPR // expected-error {{cannot find interface declaration for 'SUPR', superclass of 'INTF2'}} +@end + +@implementation INTF3 @end // expected-error {{redefinition of 'INTF3' as different kind of symbol}} + +@implementation INTF4 @end // expected-warning {{cannot find interface declaration for 'INTF4'}} + diff --git a/clang/test/SemaObjC/class-proto-1.m b/clang/test/SemaObjC/class-proto-1.m new file mode 100644 index 00000000000..f38eaea4c19 --- /dev/null +++ b/clang/test/SemaObjC/class-proto-1.m @@ -0,0 +1,36 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface INTF1 @end + +@protocol p1,p2,p3; + +@protocol p1; + +@protocol PROTO1 +- (INTF1<p1>*) meth; +@end + +@protocol p1 @end + +@interface I1 <p1> @end + +@interface E1 <p2> @end // expected-warning {{cannot find protocol definition for 'p2', referenced by 'E1'}} + +@protocol p2 @end + + +@interface I2 <p1,p2> @end + +@interface E2 <p1,p2,p3> @end // expected-warning {{cannot find protocol definition for 'p3', referenced by 'E2'}} + +@class U1, U2; + +@interface E3 : U1 @end // expected-error {{cannot find interface declaration for 'U1', superclass of 'E3'}} + + +@interface I3 : E3 @end + +@interface U2 @end + +@interface I4 : U2 <p1,p2> +@end diff --git a/clang/test/SemaObjC/cocoa.m b/clang/test/SemaObjC/cocoa.m new file mode 100644 index 00000000000..7cb1b5295c5 --- /dev/null +++ b/clang/test/SemaObjC/cocoa.m @@ -0,0 +1,5 @@ +// RUN: clang %s -print-stats +#ifdef __APPLE__ +#include <Cocoa/Cocoa.h> +#endif + diff --git a/clang/test/SemaObjC/compatible-protocol-qualified-types.m b/clang/test/SemaObjC/compatible-protocol-qualified-types.m new file mode 100644 index 00000000000..2e7eb6c43b8 --- /dev/null +++ b/clang/test/SemaObjC/compatible-protocol-qualified-types.m @@ -0,0 +1,40 @@ +// RUN: clang -pedantic -fsyntax-only -verify %s +typedef signed char BOOL; + +@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; + +@protocol NSObject +- (BOOL)isEqual:(id)object; +@end + +@protocol NSCoding +- (void)encodeWithCoder:(NSCoder *)aCoder; +@end + +@interface NSObject <NSObject> {} +@end + +typedef float CGFloat; + +@interface NSResponder : NSObject <NSCoding> {} +@end + +@protocol XCSelectionSource; + +@interface XCSelection : NSResponder {} +- (NSObject <XCSelectionSource> *) source; +@end + +extern NSString * const XCActiveSelectionLevel; + +@interface XCActionManager : NSResponder {} ++defaultActionManager; +-selectionAtLevel:(NSString *const)s; +@end + +@implementation XDMenuItemsManager // expected-warning {{cannot find interface declaration for 'XDMenuItemsManager'}} ++ (void)initialize { + id<XCSelectionSource, NSObject> source = + [[[XCActionManager defaultActionManager] selectionAtLevel:XCActiveSelectionLevel] source]; +} +@end diff --git a/clang/test/SemaObjC/conditional-expr.m b/clang/test/SemaObjC/conditional-expr.m new file mode 100644 index 00000000000..e3cd041d3a5 --- /dev/null +++ b/clang/test/SemaObjC/conditional-expr.m @@ -0,0 +1,44 @@ +// RUN: clang -fsyntax-only -verify -pedantic %s +@protocol NSObject +@end + +@protocol DTOutputStreams <NSObject> +@end + +@interface DTFilterOutputStream <DTOutputStreams> +- nextOutputStream; +@end + +@implementation DTFilterOutputStream +- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream { + id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; + self = nextOutputStream; + return nextOutputStream ? nextOutputStream : self; +} +- nextOutputStream { + return self; +} +@end + +@interface DTFilterOutputStream2 +- nextOutputStream; +@end + +@implementation DTFilterOutputStream2 // expected-warning {{incomplete implementation}} expected-warning {{method definition for 'nextOutputStream' not found}} +- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream { + id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; + // GCC warns about both of these. + self = nextOutputStream; // expected-error {{incompatible type assigning 'id<DTOutputStreams>', expected 'DTFilterOutputStream2 *'}} + return nextOutputStream ? nextOutputStream : self; // expected-error {{incompatible operand types ('id<DTOutputStreams>' and 'DTFilterOutputStream2 *')}} +} +@end + +// No @interface declaration for DTFilterOutputStream3 +@implementation DTFilterOutputStream3 // expected-warning {{cannot find interface declaration for 'DTFilterOutputStream3'}} +- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream { + id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; + // GCC warns about both of these as well (no errors). + self = nextOutputStream; // expected-error {{incompatible type assigning 'id<DTOutputStreams>', expected 'DTFilterOutputStream3 *'}} + return nextOutputStream ? nextOutputStream : self; // expected-error {{incompatible operand types ('id<DTOutputStreams>' and 'DTFilterOutputStream3 *')}} +} +@end diff --git a/clang/test/SemaObjC/conflicting-ivar-test-1.m b/clang/test/SemaObjC/conflicting-ivar-test-1.m new file mode 100644 index 00000000000..6f24e8cb3aa --- /dev/null +++ b/clang/test/SemaObjC/conflicting-ivar-test-1.m @@ -0,0 +1,86 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface INTF +{ +@public + int IVAR; // expected-error {{previous definition is here}} +} +@end + +@implementation INTF +{ +@private + + int XIVAR; // expected-error {{conflicting instance variable name 'XIVAR'}} +} +@end + + + +@interface INTF1 +{ +@public + int IVAR; + int IVAR1; // expected-error {{inconsistent number of instance variables specified}} +} +@end + +@implementation INTF1 +{ +@private + + int IVAR; +} +@end + + +@interface INTF2 +{ +@public + int IVAR; +} +@end + +@implementation INTF2 +{ +@private + + int IVAR; + int IVAR1; // expected-error {{inconsistent number of instance variables specified}} +} +@end + + +@interface INTF3 +{ +@public + int IVAR; // expected-error {{previous definition is here}} +} +@end + +@implementation INTF3 +{ +@private + + short IVAR; // expected-error {{conflicting instance variable type}} +} +@end + +@implementation INTF4 // expected-warning {{cannot find interface declaration for 'INTF4'}} +{ +@private + + short IVAR; +} +@end + +@interface INTF5 +{ + char * ch; +} +@end + +@implementation INTF5 +{ +} +@end diff --git a/clang/test/SemaObjC/const-id.m b/clang/test/SemaObjC/const-id.m new file mode 100644 index 00000000000..9087e4ce7df --- /dev/null +++ b/clang/test/SemaObjC/const-id.m @@ -0,0 +1,8 @@ +// RUN: clang %s -verify -fsyntax-only + +int main() { + const id foo; + [foo bar]; // expected-warning {{method '-bar' not found (return type defaults to 'id')}} + return 0; +} + diff --git a/clang/test/SemaObjC/enhanced-proto-2.m b/clang/test/SemaObjC/enhanced-proto-2.m new file mode 100644 index 00000000000..82e23c4b63f --- /dev/null +++ b/clang/test/SemaObjC/enhanced-proto-2.m @@ -0,0 +1,21 @@ +// RUN: clang -verify %s + +@protocol MyProto1 +@optional +- (void) FOO; +@optional +- (void) FOO; +@optional +- (void) REQ; +@optional +@end + +@interface MyProto2 <MyProto1> +- (void) FOO2; +- (void) FOO3; +@end + +@implementation MyProto2 +- (void) FOO2{} +- (void) FOO3{} +@end diff --git a/clang/test/SemaObjC/format-strings-objc.m b/clang/test/SemaObjC/format-strings-objc.m new file mode 100644 index 00000000000..bdf12082a70 --- /dev/null +++ b/clang/test/SemaObjC/format-strings-objc.m @@ -0,0 +1,36 @@ +// RUN: clang -fsyntax-only -verify %s + +//===----------------------------------------------------------------------===// +// The following code is reduced using delta-debugging from +// Foundation.h (Mac OS X). +// +// It includes the basic definitions for the test cases below. +// Not including Foundation.h directly makes this test case both svelt and +// portable to non-Mac platforms. +//===----------------------------------------------------------------------===// + +typedef signed char BOOL; +typedef unsigned int NSUInteger; +@class NSString, Protocol; +extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2))); +typedef struct _NSZone NSZone; +@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; +@protocol NSObject - (BOOL)isEqual:(id)object; @end +@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end +@protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end +@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end +@interface NSObject <NSObject> {} @end +typedef float CGFloat; +@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding> - (NSUInteger)length; @end +@interface NSSimpleCString : NSString {} @end +@interface NSConstantString : NSSimpleCString @end +extern void *_NSConstantStringClassReference; + +//===----------------------------------------------------------------------===// +// Test cases. +//===----------------------------------------------------------------------===// + +void check_nslog(unsigned k) { + NSLog(@"%d%%", k); // no-warning + NSLog(@"%s%lb%d", "unix", 10,20); // expected-warning {{lid conversion '%lb'}} +} diff --git a/clang/test/SemaObjC/forward-class-1.m b/clang/test/SemaObjC/forward-class-1.m new file mode 100644 index 00000000000..2b9369ba5f8 --- /dev/null +++ b/clang/test/SemaObjC/forward-class-1.m @@ -0,0 +1,24 @@ +// RUN: clang -fsyntax-only -verify %s + +@class FOO, BAR; +@class FOO, BAR; + +@interface INTF : FOO // expected-error {{cannot find interface declaration for 'FOO', superclass of 'INTF'}} +@end + +@interface FOO +- (BAR*) Meth1; +- (FOO*) Meth2; +@end + +@interface INTF1 : FOO +@end + +@interface INTF2 : INTF1 +@end + + +@class INTF1, INTF2; + +@interface INTF2 : INTF1 // expected-error {{duplicate interface declaration for class 'INTF2'}} +@end diff --git a/clang/test/SemaObjC/gcc-cast-ext.m b/clang/test/SemaObjC/gcc-cast-ext.m new file mode 100644 index 00000000000..866aee9069e --- /dev/null +++ b/clang/test/SemaObjC/gcc-cast-ext.m @@ -0,0 +1,24 @@ +// RUN: clang %s -verify -fms-extensions +@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; +typedef struct _NSRange { } NSRange; + +@class PBXFileReference; + +@interface PBXDocBookmark ++ alloc; +- autorelease; +@end + +// GCC allows pointer expressions in integer constant expressions. +struct { + char control[((int)(char *)2)]; +} xx; + +@implementation PBXDocBookmark // expected-warning {{incomplete implementation}} expected-warning {{method definition for 'autorelease' not found}} expected-warning {{method definition for 'alloc' not found}} + ++ (id)bookmarkWithFileReference:(PBXFileReference *)fileRef gylphRange:(NSRange)range anchor:(NSString *)htmlAnchor +{ + NSRange r = (NSRange)range; + return [[[self alloc] initWithFileReference:fileRef gylphRange:(NSRange)range anchor:(NSString *)htmlAnchor] autorelease]; // expected-warning {{method '-initWithFileReference:gylphRange:anchor:' not found (return type defaults to 'id')}} +} +@end diff --git a/clang/test/SemaObjC/id_builtin.m b/clang/test/SemaObjC/id_builtin.m new file mode 100644 index 00000000000..d7c916146fd --- /dev/null +++ b/clang/test/SemaObjC/id_builtin.m @@ -0,0 +1,10 @@ +// RUN: clang %s -fsyntax-only -verify + +// id is now builtin. There should be no errors. +id obj; + +@interface Foo + +- defaultToId; + +@end diff --git a/clang/test/SemaObjC/incompatible-protocol-qualified-types.m b/clang/test/SemaObjC/incompatible-protocol-qualified-types.m new file mode 100644 index 00000000000..ad8c45e5e0a --- /dev/null +++ b/clang/test/SemaObjC/incompatible-protocol-qualified-types.m @@ -0,0 +1,40 @@ +// RUN: clang -pedantic -fsyntax-only -verify %s + +@protocol MyProto1 +@end + +@protocol MyProto2 +@end + +@interface INTF @end + +INTF <MyProto1> * Func(INTF <MyProto1, MyProto2> *p2) +{ + return p2; +} + + +INTF <MyProto1> * Func1(INTF <MyProto1, MyProto2> *p2) +{ + return p2; +} + +INTF <MyProto1, MyProto2> * Func2(INTF <MyProto1> *p2) +{ + Func(p2); // expected-warning {{incompatible pointer types passing 'INTF<MyProto1> *', expected 'INTF<MyProto1,MyProto2> *}} + return p2; // expected-warning {{incompatible pointer types returning 'INTF<MyProto1> *', expected 'INTF<MyProto1,MyProto2> *}} +} + + + +INTF <MyProto1> * Func3(INTF <MyProto2> *p2) +{ + return p2; // expected-warning {{incompatible pointer types returning 'INTF<MyProto2> *', expected 'INTF<MyProto1> *}} +} + + +INTF <MyProto1, MyProto2> * Func4(INTF <MyProto2, MyProto1> *p2) +{ + return p2; +} + diff --git a/clang/test/SemaObjC/invalid-objc-decls-1.m b/clang/test/SemaObjC/invalid-objc-decls-1.m new file mode 100644 index 00000000000..fa18079d075 --- /dev/null +++ b/clang/test/SemaObjC/invalid-objc-decls-1.m @@ -0,0 +1,29 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface Super @end +Super s1; // expected-error{{statically allocated Objective-C object 's1'}} + +extern Super e1; // expected-error{{statically allocated Objective-C object 'e1'}} + +struct S { + Super s1; // expected-error{{statically allocated Objective-C object 's1'}} +}; + +@protocol P1 @end + +@interface INTF +{ + Super ivar1; // expected-error{{statically allocated Objective-C object 'ivar1'}} +} +@end + +@interface MyIntf +{ + Super<P1> ivar1; // expected-error{{statically allocated Objective-C object 'ivar1'}} +} +@end + +Super foo(Super parm1) { + Super p1; // expected-error{{statically allocated Objective-C object 'p1'}} + return p1; +} diff --git a/clang/test/SemaObjC/ivar-sem-check-1.m b/clang/test/SemaObjC/ivar-sem-check-1.m new file mode 100644 index 00000000000..4e810a29a81 --- /dev/null +++ b/clang/test/SemaObjC/ivar-sem-check-1.m @@ -0,0 +1,19 @@ +// RUN: clang -fsyntax-only -verify %s + +struct S; +typedef int FOO(); + +@interface INTF +{ + struct F {} JJ; + int arr[]; // expected-error {{field 'arr' has incomplete type}} + struct S IC; // expected-error {{field 'IC' has incomplete type}} + struct T { // expected-error {{previous definition is here}} + struct T {} X; // expected-error {{nested redefinition of 'struct'}} + }YYY; + FOO BADFUNC; // expected-error {{field 'BADFUNC' declared as a function}} + int kaka; // expected-error {{previous definition is here}} + int kaka; // expected-error {{duplicate member 'kaka'}} + char ch[]; // expected-error {{field 'ch' has incomplete type}} +} +@end diff --git a/clang/test/SemaObjC/message.m b/clang/test/SemaObjC/message.m new file mode 100644 index 00000000000..9c9289b6b85 --- /dev/null +++ b/clang/test/SemaObjC/message.m @@ -0,0 +1,63 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface foo +- (void)meth; +@end + +@implementation foo +- (void) contents {} // No declaration in @interface! +- (void) meth { [self contents]; } +@end + +typedef struct _NSPoint { + float x; + float y; +} NSPoint; + +typedef struct _NSSize { + float width; + float height; +} NSSize; + +typedef struct _NSRect { + NSPoint origin; + NSSize size; +} NSRect; + +@interface AnyClass +- (NSRect)rect; +@end + +@class Helicopter; + +static void func(Helicopter *obj) { + // Note that the proto for "rect" is found in the global pool even when + // a statically typed object's class interface isn't in scope! This + // behavior isn't very desirable, however wee need it for GCC compatibility. + NSRect r = [obj rect]; +} + +@interface NSObject @end + +extern Class NSClassFromObject(id object); + +@interface XX : NSObject +@end + +@implementation XX + ++ _privateMethod { + return self; +} + +- (void) xx { + [NSClassFromObject(self) _privateMethod]; +} +@end + +@implementation XX (Private) +- (void) yy { + [NSClassFromObject(self) _privateMethod]; +} +@end + diff --git a/clang/test/SemaObjC/method-def-1.m b/clang/test/SemaObjC/method-def-1.m new file mode 100644 index 00000000000..2d5f92fcbc1 --- /dev/null +++ b/clang/test/SemaObjC/method-def-1.m @@ -0,0 +1,10 @@ +// RUN: clang -fsyntax-only %s + +@interface foo +- (int)meth; +@end + +@implementation foo +- (int) meth { return [self meth]; } +@end + diff --git a/clang/test/SemaObjC/method-def-2.m b/clang/test/SemaObjC/method-def-2.m new file mode 100644 index 00000000000..d31a2b58b9d --- /dev/null +++ b/clang/test/SemaObjC/method-def-2.m @@ -0,0 +1,19 @@ +// RUN: clang -ast-print %s +extern void abort(void); +#define CHECK_IF(expr) if(!(expr)) abort() + +static double d = 4.5920234e2; + +@interface Foo +-(void) brokenType: (int)x floatingPoint: (double)y; +@end + + +@implementation Foo +-(void) brokenType: (int)x floatingPoint: (double)y +{ + CHECK_IF(x == 459); + CHECK_IF(y == d); +} +@end + diff --git a/clang/test/SemaObjC/method-encoding-2.m b/clang/test/SemaObjC/method-encoding-2.m new file mode 100644 index 00000000000..08a579b0a87 --- /dev/null +++ b/clang/test/SemaObjC/method-encoding-2.m @@ -0,0 +1,12 @@ +// RUN: clang %s +// TODO: We don't support rewrite of method definitions + +@interface Intf +- (in out bycopy id) address:(byref inout void *)location with:(out oneway unsigned **)arg2; +- (id) another:(void *)location with:(unsigned **)arg2; +@end + +@implementation Intf +- (in out bycopy id) address:(byref inout void *)location with:(out oneway unsigned **)arg2{} +- (id) another:(void *)location with:(unsigned **)arg2 {} +@end diff --git a/clang/test/SemaObjC/method-lookup.m b/clang/test/SemaObjC/method-lookup.m new file mode 100644 index 00000000000..4dfbc746627 --- /dev/null +++ b/clang/test/SemaObjC/method-lookup.m @@ -0,0 +1,34 @@ +// RUN: clang -fsyntax-only -verify %s +typedef signed char BOOL; +typedef int NSInteger; + +@protocol NSObject +- (BOOL)isEqual:(id)object; +- (BOOL)respondsToSelector:(SEL)s; +@end + +@interface NSObject <NSObject> {} +@end + +@class NSString, NSData, NSMutableData, NSMutableDictionary, NSMutableArray; + +@protocol PBXCompletionItem +- (NSString *) name; +- (NSInteger)priority; +- setPriority:(NSInteger)p; +@end + +@implementation PBXCodeAssistant // expected-warning{{cannot find interface declaration for 'PBXCodeAssistant'}} +static NSMutableArray * recentCompletions = ((void *)0); ++ (float) factorForRecentCompletion:(NSString *) completion +{ + for (NSObject<PBXCompletionItem> * item in [self completionItems]) // expected-warning{{method '-completionItems' not found (return type defaults to 'id')}} + { + if ([item respondsToSelector:@selector(setPriority:)]) + { + [(id)item setPriority:[item priority] / [PBXCodeAssistant factorForRecentCompletion:[item name]]]; + } + } +} +@end + diff --git a/clang/test/SemaObjC/method-not-defined.m b/clang/test/SemaObjC/method-not-defined.m new file mode 100644 index 00000000000..62a8be72e7d --- /dev/null +++ b/clang/test/SemaObjC/method-not-defined.m @@ -0,0 +1,13 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface Foo +@end + +void test() { + Foo *fooObj; + id obj; + + [[Foo alloc] init]; // expected-warning {{method '+alloc' not found (return type defaults to 'id')}} expected-warning {{method '-init' not found (return type defaults to 'id')}} + [fooObj notdefined]; // expected-warning {{method '-notdefined' not found (return type defaults to 'id')}} + [obj whatever:1 :2 :3]; // expected-warning {{method '-whatever:::' not found (return type defaults to 'id'))}} +} diff --git a/clang/test/SemaObjC/method-undef-category-warn-1.m b/clang/test/SemaObjC/method-undef-category-warn-1.m new file mode 100644 index 00000000000..792c24d748f --- /dev/null +++ b/clang/test/SemaObjC/method-undef-category-warn-1.m @@ -0,0 +1,32 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface MyClass1 +@end + +@protocol P +- (void) Pmeth; +- (void) Pmeth1; +@end + +@interface MyClass1(CAT) <P> +- (void) meth2; +@end + +@implementation MyClass1(CAT) // expected-warning {{incomplete implementation}} \ + expected-warning {{method definition for 'meth2' not found}} \ + expected-warning {{method definition for 'Pmeth' not found}} +- (void) Pmeth1{} +@end + +@interface MyClass1(DOG) <P> +- (void)ppp; +@end + +@implementation MyClass1(DOG) // expected-warning {{incomplete implementation}} \ + expected-warning {{method definition for 'ppp' not found}} \ + expected-warning {{method definition for 'Pmeth1' not found}} +- (void) Pmeth {} +@end + +@implementation MyClass1(CAT1) +@end diff --git a/clang/test/SemaObjC/method-undefined-warn-1.m b/clang/test/SemaObjC/method-undefined-warn-1.m new file mode 100644 index 00000000000..9e646f82f73 --- /dev/null +++ b/clang/test/SemaObjC/method-undefined-warn-1.m @@ -0,0 +1,42 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface INTF +- (void) meth; +- (void) meth : (int) arg1; +- (int) int_meth; ++ (int) cls_meth; ++ (void) cls_meth1 : (int) arg1; +@end + +@implementation INTF // expected-warning {{incomplete implementation}} expected-warning {{method definition for 'int_meth' not found}} expected-warning {{method definition for 'cls_meth' not found}} expected-warning {{method definition for 'cls_meth1:' not found}} +- (void) meth {} +- (void) meth : (int) arg2{} +- (void) cls_meth1 : (int) arg2{} +@end + +@interface INTF1 +- (void) meth; +- (void) meth : (int) arg1; +- (int) int_meth; ++ (int) cls_meth; ++ (void) cls_meth1 : (int) arg1; +@end + +@implementation INTF1 // expected-warning {{incomplete implementation}} expected-warning {{method definition for 'int_meth' not found}} expected-warning {{method definition for 'cls_meth' not found}} expected-warning {{method definition for 'cls_meth1:' not found}} +- (void) meth {} +- (void) meth : (int) arg2{} +- (void) cls_meth1 : (int) arg2{} +@end + +@interface INTF2 +- (void) meth; +- (void) meth : (int) arg1; +- (void) cls_meth1 : (int) arg1; +@end + +@implementation INTF2 +- (void) meth {} +- (void) meth : (int) arg2{} +- (void) cls_meth1 : (int) arg2{} +@end + diff --git a/clang/test/SemaObjC/missing-method-context.m b/clang/test/SemaObjC/missing-method-context.m new file mode 100644 index 00000000000..20437b70ec1 --- /dev/null +++ b/clang/test/SemaObjC/missing-method-context.m @@ -0,0 +1,4 @@ +// RUN: clang %s -verify -fsyntax-only +- (void)compilerTestAgainst; // expected-error {{missing context for method declaration}} + +void xx(); // expected-error {{expected method body}} diff --git a/clang/test/SemaObjC/objc-at-defs.m b/clang/test/SemaObjC/objc-at-defs.m new file mode 100644 index 00000000000..5bbdd6a715e --- /dev/null +++ b/clang/test/SemaObjC/objc-at-defs.m @@ -0,0 +1,29 @@ +// RUN: clang %s -fsyntax-only + +@interface Test { + double a; +} +@end +@implementation Test +@end +@interface TestObject : Test { +@public + float bar; + int foo; +} +@end +@implementation TestObject +@end +struct wibble { + @defs(TestObject) +}; + + +int main(void) +{ + TestObject * a = (id)malloc(100); + a->foo = 12; + printf("12: %d\n", ((struct wibble*)a)->foo); + printf("%d: %d\n", ((char*)&(((struct wibble*)a)->foo)) - (char*)a, ((char*)&(a->foo)) - (char*)a); + return 0; +} diff --git a/clang/test/SemaObjC/objc-bad-receiver-1.m b/clang/test/SemaObjC/objc-bad-receiver-1.m new file mode 100644 index 00000000000..8376a5ced7a --- /dev/null +++ b/clang/test/SemaObjC/objc-bad-receiver-1.m @@ -0,0 +1,9 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface I +- (id) retain; +@end + +void __raiseExc1() { + [objc_lookUpClass("NSString") retain]; // expected-error {{ "bad receiver type 'int'" }} +} diff --git a/clang/test/SemaObjC/objc-comptypes-1.m b/clang/test/SemaObjC/objc-comptypes-1.m new file mode 100644 index 00000000000..e47bc63565f --- /dev/null +++ b/clang/test/SemaObjC/objc-comptypes-1.m @@ -0,0 +1,89 @@ +// RUN: clang -fsyntax-only -verify -pedantic %s + +#define nil (void *)0; +#define Nil (void *)0; + +extern void foo(); + +@protocol MyProtocol +- (void) foo; +@end + +@interface MyClass +@end + +@interface MyOtherClass <MyProtocol> +- (void) foo; +@end + +int main() +{ + id obj = nil; + id<MyProtocol> obj_p = nil; + MyClass *obj_c = nil; + MyOtherClass *obj_cp = nil; + Class obj_C = Nil; + + /* Assigning to an 'id' variable should never + generate a warning. */ + obj = obj_p; /* Ok */ + obj = obj_c; /* Ok */ + obj = obj_cp; /* Ok */ + obj = obj_C; /* Ok */ + + /* Assigning to a 'MyClass *' variable should always generate a + warning, unless done from an 'id'. */ + obj_c = obj; /* Ok */ + obj_c = obj_cp; // // expected-warning {{incompatible pointer types assigning 'MyOtherClass *', expected 'MyClass *'}} + obj_c = obj_C; // expected-warning {{incompatible pointer types assigning 'Class', expected 'MyClass *'}} + + /* Assigning to an 'id<MyProtocol>' variable should generate a + warning if done from a 'MyClass *' (which doesn't implement + MyProtocol), but not from an 'id' or from a 'MyOtherClass *' + (which implements MyProtocol). */ + obj_p = obj; /* Ok */ + obj_p = obj_c; // expected-error {{incompatible type assigning 'MyClass *', expected 'id<MyProtocol>'}} + obj_p = obj_cp; /* Ok */ + obj_p = obj_C; // expected-error {{incompatible type assigning 'Class', expected 'id<MyProtocol>'}} + + /* Assigning to a 'MyOtherClass *' variable should always generate + a warning, unless done from an 'id' or an 'id<MyProtocol>' (since + MyOtherClass implements MyProtocol). */ + obj_cp = obj; /* Ok */ + obj_cp = obj_c; // expected-warning {{incompatible pointer types assigning 'MyClass *', expected 'MyOtherClass *'}} + obj_cp = obj_p; /* Ok */ + obj_cp = obj_C; // expected-warning {{incompatible pointer types assigning 'Class', expected 'MyOtherClass *'}} + + /* Any comparison involving an 'id' must be without warnings. */ + if (obj == obj_p) foo() ; /* Ok */ /*Bogus warning here in 2.95.4*/ + if (obj_p == obj) foo() ; /* Ok */ + if (obj == obj_c) foo() ; /* Ok */ + if (obj_c == obj) foo() ; /* Ok */ + if (obj == obj_cp) foo() ; /* Ok */ + if (obj_cp == obj) foo() ; /* Ok */ + if (obj == obj_C) foo() ; /* Ok */ + if (obj_C == obj) foo() ; /* Ok */ + + /* Any comparison between 'MyClass *' and anything which is not an 'id' + must generate a warning. */ + if (obj_p == obj_c) foo() ; // expected-error {{invalid operands to binary expression ('id<MyProtocol>' and 'MyClass *')}} + + if (obj_c == obj_cp) foo() ; // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'MyOtherClass *')}} + if (obj_cp == obj_c) foo() ; // expected-warning {{comparison of distinct pointer types ('MyOtherClass *' and 'MyClass *')}} + + if (obj_c == obj_C) foo() ; // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'Class')}} + if (obj_C == obj_c) foo() ; // expected-warning {{comparison of distinct pointer types ('Class' and 'MyClass *')}} + + /* Any comparison between 'MyOtherClass *' (which implements + MyProtocol) and an 'id' implementing MyProtocol are Ok. */ + if (obj_cp == obj_p) foo() ; /* Ok */ + if (obj_p == obj_cp) foo() ; /* Ok */ + + + if (obj_p == obj_C) foo() ; // expected-error {{invalid operands to binary expression ('id<MyProtocol>' and 'Class')}} + if (obj_C == obj_p) foo() ; // expected-error {{invalid operands to binary expression ('Class' and 'id<MyProtocol>')}} + if (obj_cp == obj_C) foo() ; // expected-warning {{comparison of distinct pointer types ('MyOtherClass *' and 'Class')}} + if (obj_C == obj_cp) foo() ; // expected-warning {{comparison of distinct pointer types ('Class' and 'MyOtherClass *')}} + + return 0; +} diff --git a/clang/test/SemaObjC/objc-comptypes-2.m b/clang/test/SemaObjC/objc-comptypes-2.m new file mode 100644 index 00000000000..d063d95cc24 --- /dev/null +++ b/clang/test/SemaObjC/objc-comptypes-2.m @@ -0,0 +1,37 @@ +// RUN: clang -fsyntax-only -verify %s + +#define nil (void *)0; +#define Nil (void *)0; + +@protocol MyProtocol +- (void) foo; +@end + +@interface MyClass +@end + +int main() +{ + id obj = nil; + id<MyProtocol> obj_p = nil; + MyClass *obj_c = nil; + Class obj_C = Nil; + + /* All these casts should generate no warnings. */ + + obj = (id)obj_p; + obj = (id)obj_c; + obj = (id)obj_C; + obj_c = (MyClass *)obj; + obj_c = (MyClass *)obj_p; + obj_c = (MyClass *)obj_C; + obj_p = (id<MyProtocol>)obj; + obj_p = (id<MyProtocol>)obj_c; + obj_p = (id<MyProtocol>)obj_C; + obj_C = (Class)obj; + obj_C = (Class)obj_p; + obj_C = (Class)obj_c; + + + return 0; +} diff --git a/clang/test/SemaObjC/objc-comptypes-3.m b/clang/test/SemaObjC/objc-comptypes-3.m new file mode 100644 index 00000000000..1e271c8340e --- /dev/null +++ b/clang/test/SemaObjC/objc-comptypes-3.m @@ -0,0 +1,64 @@ +// RUN: clang -fsyntax-only -verify %s + +#define nil (void *)0; + +extern void foo(); + +@protocol MyProtocolA +- (void) methodA; +@end + +@protocol MyProtocolB +- (void) methodB; +@end + +@protocol MyProtocolAB <MyProtocolA, MyProtocolB> +@end + +@protocol MyProtocolAC <MyProtocolA> +- (void) methodC; +@end + +int main() +{ + id<MyProtocolA> obj_a = nil; + id<MyProtocolB> obj_b = nil; + id<MyProtocolAB> obj_ab = nil; + id<MyProtocolAC> obj_ac = nil; + + obj_a = obj_b; // expected-error {{incompatible type assigning 'id<MyProtocolB>', expected 'id<MyProtocolA>'}} + obj_a = obj_ab; /* Ok */ + obj_a = obj_ac; /* Ok */ + + obj_b = obj_a; // expected-error {{incompatible type assigning 'id<MyProtocolA>', expected 'id<MyProtocolB>'}} + obj_b = obj_ab; /* Ok */ + obj_b = obj_ac; // expected-error {{incompatible type assigning 'id<MyProtocolAC>', expected 'id<MyProtocolB>'}} + + obj_ab = obj_a; // expected-error {{incompatible type assigning 'id<MyProtocolA>', expected 'id<MyProtocolAB>'}} + obj_ab = obj_b; // expected-error {{incompatible type assigning 'id<MyProtocolB>', expected 'id<MyProtocolAB>'}} + obj_ab = obj_ac; // expected-error {{incompatible type assigning 'id<MyProtocolAC>', expected 'id<MyProtocolAB>'}} + + obj_ac = obj_a; // expected-error {{incompatible type assigning 'id<MyProtocolA>', expected 'id<MyProtocolAC>'}} + obj_ac = obj_b; // expected-error {{incompatible type assigning 'id<MyProtocolB>', expected 'id<MyProtocolAC>'}} + obj_ac = obj_ab; // expected-error {{incompatible type assigning 'id<MyProtocolAB>', expected 'id<MyProtocolAC>'}} + + if (obj_a == obj_b) foo (); // expected-error {{invalid operands to binary expression ('id<MyProtocolA>' and 'id<MyProtocolB>')}} + if (obj_b == obj_a) foo (); // expected-error {{invalid operands to binary expression ('id<MyProtocolB>' and 'id<MyProtocolA>')}} + + if (obj_a == obj_ab) foo (); /* Ok */ + if (obj_ab == obj_a) foo (); /* Ok */ + + if (obj_a == obj_ac) foo (); /* Ok */ + if (obj_ac == obj_a) foo (); /* Ok */ + + if (obj_b == obj_ab) foo (); /* Ok */ + if (obj_ab == obj_b) foo (); /* Ok */ + + if (obj_b == obj_ac) foo (); // expected-error {{invalid operands to binary expression ('id<MyProtocolB>' and 'id<MyProtocolAC>')}} + if (obj_ac == obj_b) foo (); // expected-error {{invalid operands to binary expression ('id<MyProtocolAC>' and 'id<MyProtocolB>')}} + + if (obj_ab == obj_ac) foo (); // expected-error {{invalid operands to binary expression ('id<MyProtocolAB>' and 'id<MyProtocolAC>')}} + if (obj_ac == obj_ab) foo (); // expected-error {{invalid operands to binary expression ('id<MyProtocolAC>' and 'id<MyProtocolAB>')}} + + return 0; +} diff --git a/clang/test/SemaObjC/objc-comptypes-4.m b/clang/test/SemaObjC/objc-comptypes-4.m new file mode 100644 index 00000000000..bda9050164b --- /dev/null +++ b/clang/test/SemaObjC/objc-comptypes-4.m @@ -0,0 +1,25 @@ +// RUN: clang -fsyntax-only -verify %s + +extern void foo(); + +@protocol MyProtocol @end + +@interface MyClass @end + +int main() +{ + MyClass <MyProtocol> *obj_p; + MyClass *obj_cp; + + obj_cp = obj_p; + obj_p = obj_cp; + + if (obj_cp == obj_p) + foo(); + + if (obj_p == obj_cp) + foo(); + +} + + diff --git a/clang/test/SemaObjC/objc-comptypes-5.m b/clang/test/SemaObjC/objc-comptypes-5.m new file mode 100644 index 00000000000..f12fa9ab5d4 --- /dev/null +++ b/clang/test/SemaObjC/objc-comptypes-5.m @@ -0,0 +1,44 @@ +// RUN: clang -fsyntax-only -pedantic -verify %s + +#define nil (void *)0; + +extern void foo(); + +@protocol MyProtocol +- (void) method; +@end + +@interface MyClass +@end + +@interface MyClass (Addition) <MyProtocol> +- (void) method; +@end + +@interface MyOtherClass : MyClass +@end + +int main() +{ + id <MyProtocol> obj_id_p = nil; + MyClass *obj_c_cat_p = nil; + MyOtherClass *obj_c_super_p = nil; + MyOtherClass<MyProtocol> *obj_c_super_p_q = nil; + MyClass<MyProtocol> *obj_c_cat_p_q = nil; + + obj_c_cat_p = obj_id_p; // expected-error {{incompatible type assigning 'id<MyProtocol>', expected 'MyClass *'}} + obj_c_super_p = obj_id_p; // expected-error {{incompatible type assigning 'id<MyProtocol>', expected 'MyOtherClass *'}} + obj_id_p = obj_c_cat_p; /* Ok */ + obj_id_p = obj_c_super_p; /* Ok */ + + if (obj_c_cat_p == obj_id_p) foo(); /* Ok */ + if (obj_c_super_p == obj_id_p) foo() ; /* Ok */ + if (obj_id_p == obj_c_cat_p) foo(); /* Ok */ + if (obj_id_p == obj_c_super_p) foo(); /* Ok */ + + obj_c_cat_p = obj_c_super_p; // ok. + obj_c_cat_p = obj_c_super_p_q; // ok. + obj_c_super_p = obj_c_cat_p_q; // expected-warning {{incompatible pointer types}} + obj_c_cat_p_q = obj_c_super_p; + return 0; +} diff --git a/clang/test/SemaObjC/objc-comptypes-6.m b/clang/test/SemaObjC/objc-comptypes-6.m new file mode 100644 index 00000000000..2edb181e83b --- /dev/null +++ b/clang/test/SemaObjC/objc-comptypes-6.m @@ -0,0 +1,16 @@ +// RUN: clang -fsyntax-only -verify -pedantic %s + +@interface Derived +@end + +@interface Object @end + +extern Object* foo(void); + +static Derived *test(void) +{ + Derived *m = foo(); // expected-warning {{incompatible pointer types initializing 'Object *', expected 'Derived *'}} + + return m; +} + diff --git a/clang/test/SemaObjC/objc-comptypes-7.m b/clang/test/SemaObjC/objc-comptypes-7.m new file mode 100644 index 00000000000..ef3a7790a3d --- /dev/null +++ b/clang/test/SemaObjC/objc-comptypes-7.m @@ -0,0 +1,70 @@ +// RUN: clang -fsyntax-only -verify -pedantic %s + +#define nil (void *)0; +#define Nil (void *)0; + +extern void foo(); + +@protocol MyProtocol +- (void) method; +@end + +@interface MyClass +@end + +int main() +{ + id obj = nil; + id <MyProtocol> obj_p = nil; + MyClass *obj_c = nil; + Class obj_C = Nil; + + int i = 0; + int *j = nil; + + /* These should all generate warnings. */ + + obj = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'id'}} + obj = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'id'}} + + obj_p = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'id<MyProtocol>'}} + obj_p = j; // expected-error {{incompatible type assigning 'int *', expected 'id<MyProtocol>'}} + + obj_c = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'MyClass *'}} + obj_c = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'MyClass *'}} + + obj_C = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'Class'}} + obj_C = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'Class'}} + + i = obj; // expected-warning {{incompatible pointer to integer conversion assigning 'id', expected 'int'}} + i = obj_p; // expected-warning {{incompatible pointer to integer conversion assigning 'id<MyProtocol>', expected 'int'}} + i = obj_c; // expected-warning {{incompatible pointer to integer conversion assigning 'MyClass *', expected 'int'}} + i = obj_C; // expected-warning {{incompatible pointer to integer conversion assigning 'Class', expected 'int'}} + + j = obj; // expected-warning {{incompatible pointer types assigning 'id', expected 'int *'}} + j = obj_p; // expected-error {{incompatible type assigning 'id<MyProtocol>', expected 'int *'}} + j = obj_c; // expected-warning {{incompatible pointer types assigning 'MyClass *', expected 'int *'}} + j = obj_C; // expected-warning {{incompatible pointer types assigning 'Class', expected 'int *'}} + + if (obj == i) foo() ; // expected-warning {{comparison between pointer and integer ('id' and 'int')}} + if (i == obj) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'id')}} + if (obj == j) foo() ; // expected-warning {{comparison of distinct pointer types ('id' and 'int *')}} + if (j == obj) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'id')}} + + if (obj_c == i) foo() ; // expected-warning {{comparison between pointer and integer ('MyClass *' and 'int')}} + if (i == obj_c) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'MyClass *')}} + if (obj_c == j) foo() ; // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'int *')}} + if (j == obj_c) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'MyClass *')}} + + if (obj_p == i) foo() ; // expected-warning {{comparison between pointer and integer ('id<MyProtocol>' and 'int')}} + if (i == obj_p) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'id<MyProtocol>')}} + if (obj_p == j) foo() ; // expected-error {{invalid operands to binary expression ('id<MyProtocol>' and 'int *')}} + if (j == obj_p) foo() ; // expected-error {{invalid operands to binary expression ('int *' and 'id<MyProtocol>')}} + + if (obj_C == i) foo() ; // expected-warning {{comparison between pointer and integer ('Class' and 'int')}} + if (i == obj_C) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'Class')}} + if (obj_C == j) foo() ; // expected-warning {{comparison of distinct pointer types ('Class' and 'int *')}} + if (j == obj_C) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'Class')}} + + return 0; +} diff --git a/clang/test/SemaObjC/objc-comptypes-8.m b/clang/test/SemaObjC/objc-comptypes-8.m new file mode 100644 index 00000000000..c22e88c8805 --- /dev/null +++ b/clang/test/SemaObjC/objc-comptypes-8.m @@ -0,0 +1,12 @@ +// RUN: clang -fsyntax-only %s + +@protocol MyProtocol +@end + +id<MyProtocol> obj_p = 0; + +int main() +{ + obj_p = 0; +} + diff --git a/clang/test/SemaObjC/objc-comptypes-9.m b/clang/test/SemaObjC/objc-comptypes-9.m new file mode 100644 index 00000000000..4f0a277e74e --- /dev/null +++ b/clang/test/SemaObjC/objc-comptypes-9.m @@ -0,0 +1,86 @@ +// RUN: clang -fsyntax-only %s +// FIXME: This test case tests the patch applied in: http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20080602/006017.html +// Eventually that logic should be treated as an extension. + +typedef signed char BOOL; +typedef int NSInteger; +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 + +@protocol NSMutableCopying +- (id)mutableCopyWithZone:(NSZone *)zone; +@end + +@protocol NSCoding +- (void)encodeWithCoder:(NSCoder *)aCoder; +@end + +@interface NSObject <NSObject> {} +@end + +@class NSArray; + +typedef struct {} NSFastEnumerationState; + +@protocol NSFastEnumeration +- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len; +@end + +@class NSString; + +@interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration> +- (NSUInteger)count; +- (id)objectAtIndex:(NSUInteger)index; +@end + +typedef unsigned short unichar; + +@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding> +- (NSUInteger)length; +@end + +@interface NSSimpleCString : NSString +{} + +@end + +@interface NSConstantString : NSSimpleCString @end + +extern void *_NSConstantStringClassReference; + +@interface NSResponder : NSObject <NSCoding> {} +@end + +@class NSDate, NSDictionary, NSError, NSException, NSNotification; + +@interface NSWindowController : NSResponder <NSCoding> {} +@end + +@class PBXBuildLog, PBXBuildLogItem, PBXBuildLogContainerItem, XCWorkQueueCommand, XCBuildLogContainerItemMutationState; + +@protocol PBXBuildLogContainerItems <NSObject> +- (PBXBuildLog *)buildLog; +@end + +@interface PBXBuildLogItem : NSObject {} +- (id <PBXBuildLogContainerItems>)superitem; +@end +@interface PBXBuildResultsModule +@end + +@implementation PBXBuildResultsModule +- (void) revealItems +{ + PBXBuildLogItem *objItem; + PBXBuildLogItem *superitem = [objItem superitem]; +} +@end diff --git a/clang/test/SemaObjC/objc-interface-1.m b/clang/test/SemaObjC/objc-interface-1.m new file mode 100644 index 00000000000..0130a33f9b9 --- /dev/null +++ b/clang/test/SemaObjC/objc-interface-1.m @@ -0,0 +1,17 @@ +// RUN: clang %s -fsyntax-only -verify +// rdar://5957506 + +@interface NSWhatever : +NSObject // expected-error {{cannot find interface declaration for 'NSObject'}} +<NSCopying> // expected-error {{cannot find protocol definition for 'NSCopying'}} +@end + + +// rdar://6095245 +@interface A +{ + int x +} // expected-error {{expected ';' at end of declaration list}} +@end + + diff --git a/clang/test/SemaObjC/objc-interface-layout.m b/clang/test/SemaObjC/objc-interface-layout.m new file mode 100644 index 00000000000..637de8e3ac6 --- /dev/null +++ b/clang/test/SemaObjC/objc-interface-layout.m @@ -0,0 +1,27 @@ +// RUN: clang %s -fsyntax-only -verify +typedef struct objc_object {} *id; +typedef signed char BOOL; +typedef unsigned int NSUInteger; +typedef struct _NSZone NSZone; + +@protocol NSObject +- (BOOL) isEqual:(id) object; +@end + +@protocol NSCopying +- (id) copyWithZone:(NSZone *) zone; +@end + +@interface NSObject < NSObject > {} +@end + +extern id NSAllocateObject (Class aClass, NSUInteger extraBytes, NSZone * zone); + +@interface MyClassBase : NSObject < NSCopying > {} +@end + +@interface MyClassDirectNode : MyClassBase < NSCopying > +{ + @public NSUInteger attributeRuns[((1024 - 16 - sizeof (MyClassBase)) / (sizeof (NSUInteger) + sizeof (void *)))]; +} +@end diff --git a/clang/test/SemaObjC/objc-ivar-lookup.m b/clang/test/SemaObjC/objc-ivar-lookup.m new file mode 100644 index 00000000000..e599e9da016 --- /dev/null +++ b/clang/test/SemaObjC/objc-ivar-lookup.m @@ -0,0 +1,18 @@ +// RUN: clang %s -fsyntax-only -verify + +@interface Test { + int x; +} + +-(void) setX: (int) d; +@end + +extern struct foo x; + +@implementation Test + +-(void) setX: (int) n { + x = n; +} + +@end diff --git a/clang/test/SemaObjC/objc-legacy-implementation-1.m b/clang/test/SemaObjC/objc-legacy-implementation-1.m new file mode 100644 index 00000000000..76434471d14 --- /dev/null +++ b/clang/test/SemaObjC/objc-legacy-implementation-1.m @@ -0,0 +1,11 @@ +// RUN: clang -fsyntax-only -verify %s + +@implementation INTF // expected-warning {{cannot find interface declaration for 'INTF'}} +@end + +INTF* pi; + +INTF* FUNC() +{ + return pi; +} diff --git a/clang/test/SemaObjC/objc-method-lookup.m b/clang/test/SemaObjC/objc-method-lookup.m new file mode 100644 index 00000000000..4ebdb8e4524 --- /dev/null +++ b/clang/test/SemaObjC/objc-method-lookup.m @@ -0,0 +1,40 @@ +// RUN: clang -fsyntax-only -verify %s +typedef signed char BOOL; + +@protocol NSObject +- (BOOL) isEqual:(id) object; +@end + +@interface NSObject < NSObject > {} @end + +@class NSString, NSPort; + +@interface NSPortNameServer:NSObject ++ (NSPortNameServer *) systemDefaultPortNameServer; +@end + +@interface NSMachBootstrapServer:NSPortNameServer + (id) sharedInstance; @end + +enum { + NSWindowsNTOperatingSystem = 1, NSWindows95OperatingSystem, NSSolarisOperatingSystem, NSHPUXOperatingSystem, NSMACHOperatingSystem, NSSunOSOperatingSystem, NSOSF1OperatingSystem +}; + +@interface NSRunLoop:NSObject {} @end + +@interface NSRunLoop(NSRunLoopConveniences) +- (void) run; +@end + +extern NSString *const NSWillBecomeMultiThreadedNotification; + +@interface SenTestTool:NSObject {} +@end + +@implementation SenTestTool ++ (void) initialize {} ++(SenTestTool *) sharedInstance {} +-(int) run {} ++(int) run { + return[[self sharedInstance] run]; +} +@end diff --git a/clang/test/SemaObjC/objc-property-1.m b/clang/test/SemaObjC/objc-property-1.m new file mode 100644 index 00000000000..3bc2e3386b0 --- /dev/null +++ b/clang/test/SemaObjC/objc-property-1.m @@ -0,0 +1,39 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface I +{ + int IVAR; + int name; +} +@property int d1; +@property id prop_id; +@property int name; +@end + +@interface I(CAT) +@property int d1; +@end + +@implementation I +@synthesize d1; // expected-error {{synthesized property 'd1' must either be named the same as}} +@dynamic bad; // expected-error {{property implementation must have its declaration in interface 'I'}} +@synthesize prop_id; // expected-error {{synthesized property 'prop_id' must either be named the same}} +@synthesize prop_id = IVAR; // expected-error {{type of property 'prop_id' does not match type of ivar 'IVAR'}} +@synthesize name; // OK! property with same name as an accessible ivar of same name +@end + +@implementation I(CAT) +@synthesize d1; // expected-error {{@synthesize not allowed in a category's implementation}} +@dynamic bad; // expected-error {{property implementation must have its declaration in the category 'CAT'}} +@end + +@implementation E // expected-warning {{cannot find interface declaration for 'E'}} +@dynamic d; // expected-error {{property implementation must have its declaration in interface 'E'}} +@end + +@implementation Q(MYCAT) // expected-error {{cannot find interface declaration for 'Q'}} +@dynamic d; // expected-error {{property implementation in a category with no category declaration}} +@end + + + diff --git a/clang/test/SemaObjC/objc-property-2.m b/clang/test/SemaObjC/objc-property-2.m new file mode 100644 index 00000000000..4472a8f6955 --- /dev/null +++ b/clang/test/SemaObjC/objc-property-2.m @@ -0,0 +1,63 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface Tester +@property char PropertyAtomic_char; +@property short PropertyAtomic_short; +@property int PropertyAtomic_int; +@property long PropertyAtomic_long; +@property long long PropertyAtomic_longlong; +@property float PropertyAtomic_float; +@property double PropertyAtomic_double; +@property(assign) id PropertyAtomic_id; +@property(retain) id PropertyAtomicRetained_id; +@property(copy) id PropertyAtomicRetainedCopied_id; +@property(retain) id PropertyAtomicRetainedGCOnly_id; +@property(copy) id PropertyAtomicRetainedCopiedGCOnly_id; +@end + +@implementation Tester +@dynamic PropertyAtomic_char; +@dynamic PropertyAtomic_short; +@dynamic PropertyAtomic_int; +@dynamic PropertyAtomic_long; +@dynamic PropertyAtomic_longlong; +@dynamic PropertyAtomic_float; +@dynamic PropertyAtomic_double; +@dynamic PropertyAtomic_id; +@dynamic PropertyAtomicRetained_id; +@dynamic PropertyAtomicRetainedCopied_id; +@dynamic PropertyAtomicRetainedGCOnly_id; +@dynamic PropertyAtomicRetainedCopiedGCOnly_id; +@end + +@interface SubClass : Tester +{ + char PropertyAtomic_char; + short PropertyAtomic_short; + int PropertyAtomic_int; + long PropertyAtomic_long; + long long PropertyAtomic_longlong; + float PropertyAtomic_float; + double PropertyAtomic_double; + id PropertyAtomic_id; + id PropertyAtomicRetained_id; + id PropertyAtomicRetainedCopied_id; + id PropertyAtomicRetainedGCOnly_id; + id PropertyAtomicRetainedCopiedGCOnly_id; +} +@end + +@implementation SubClass +@synthesize PropertyAtomic_char; +@synthesize PropertyAtomic_short; +@synthesize PropertyAtomic_int; +@synthesize PropertyAtomic_long; +@synthesize PropertyAtomic_longlong; +@synthesize PropertyAtomic_float; +@synthesize PropertyAtomic_double; +@synthesize PropertyAtomic_id; +@synthesize PropertyAtomicRetained_id; +@synthesize PropertyAtomicRetainedCopied_id; +@synthesize PropertyAtomicRetainedGCOnly_id; +@synthesize PropertyAtomicRetainedCopiedGCOnly_id; +@end diff --git a/clang/test/SemaObjC/objc-property-3.m b/clang/test/SemaObjC/objc-property-3.m new file mode 100644 index 00000000000..b22059c2382 --- /dev/null +++ b/clang/test/SemaObjC/objc-property-3.m @@ -0,0 +1,14 @@ +// RUN: clang -verify %s + +@interface I +{ + id d1; +} +@property (readwrite, copy) id d1; +@property (readwrite, copy) id d2; +@end + +@interface NOW : I +@property (readonly, retain) id d1; // expected-warning {{attribute 'readonly' of property 'd1' restricts attribute 'readwrite' of property inherited from 'I'}} expected-warning {{property 'd1' 'copy' attribute does not match the property inherited from'I'}} +@property (readwrite, copy) I* d2; // expected-warning {{property type 'I *' does not match property type inherited from 'I'}} +@end diff --git a/clang/test/SemaObjC/objc-property-4.m b/clang/test/SemaObjC/objc-property-4.m new file mode 100644 index 00000000000..b5a8f8b1ccb --- /dev/null +++ b/clang/test/SemaObjC/objc-property-4.m @@ -0,0 +1,30 @@ +// RUN: clang -verify %s + +@interface Object +@end + +@protocol ProtocolObject +@property int class; +@property (copy) id MayCauseError; +@end + +@protocol ProtocolDerivedGCObject <ProtocolObject> +@property int Dclass; +@end + +@interface GCObject : Object <ProtocolDerivedGCObject> { + int ifield; + int iOwnClass; + int iDclass; +} +@property int OwnClass; +@end + +@interface ReleaseObject : GCObject <ProtocolObject> { + int newO; + int oldO; +} +@property (retain) id MayCauseError; // expected-warning {{property 'MayCauseError' 'copy' attribute does not match the property inherited from'GCObject'}} \ + expected-warning {{property 'MayCauseError' 'copy' attribute does not match the property inherited from'ProtocolObject'}} +@end + diff --git a/clang/test/SemaObjC/objc-property-5.m b/clang/test/SemaObjC/objc-property-5.m new file mode 100644 index 00000000000..c467e634dcc --- /dev/null +++ b/clang/test/SemaObjC/objc-property-5.m @@ -0,0 +1,31 @@ +// RUN: clang -verify %s + +@protocol P1 @end +@protocol P2 @end +@protocol P3 @end + +@interface NSData @end + +@interface MutableNSData : NSData @end + +@interface Base : NSData <P1> +@property(readonly) id ref; +@property(readonly) Base *p_base; +@property(readonly) NSData *nsdata; +@property(readonly) NSData * m_nsdata; +@end + +@interface Data : Base <P1, P2> +@property(readonly) NSData *ref; // expected-warning {{property type 'NSData *' does not match property type inherited from 'Base'}} +@property(readonly) Data *p_base; // expected-warning {{property type 'Data *' does not match property type inherited from 'Base'}} +@property(readonly) MutableNSData * m_nsdata; // expected-warning {{property type 'MutableNSData *' does not match property type inherited from 'Base'}} +@end + +@interface MutedData: Data +@property(readonly) id p_base; // expected-warning {{property type 'id' does not match property type inherited from 'Data'}} +@end + +@interface ConstData : Data <P1, P2, P3> +@property(readonly) ConstData *p_base; // expected-warning {{property type 'ConstData *' does not match property type inherited from 'Data'}} +@end + diff --git a/clang/test/SemaObjC/objc-property-6.m b/clang/test/SemaObjC/objc-property-6.m new file mode 100644 index 00000000000..a51994d3d49 --- /dev/null +++ b/clang/test/SemaObjC/objc-property-6.m @@ -0,0 +1,69 @@ +// RUN: clang -fsyntax-only -verify %s +# 1 "<command line>" +# 1 "/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h" 1 3 +typedef signed char BOOL; +typedef unsigned int NSUInteger; +typedef struct _NSZone NSZone; + +@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; + +@protocol NSObject +- (BOOL)isEqual:(id)object; ++ class; +@end + +@protocol NSCopying +- (id)copyWithZone:(NSZone *)zone; +@end + +@protocol NSMutableCopying +- (id)mutableCopyWithZone:(NSZone *)zone; +@end + +@protocol NSCoding +- (void)encodeWithCoder:(NSCoder *)aCoder; +@end + +@interface NSObject <NSObject> {} +@end + +typedef struct {} NSFastEnumerationState; + +@protocol NSFastEnumeration +- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len; +@end + +@interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration> +- (NSUInteger)count; +@end + +@interface NSMutableArray : NSArray +- (void)addObject:(id)anObject; ++ (id)arrayWithCapacity:(int)numItems; +@end + +@interface NSBundle : NSObject {} ++ (NSBundle *)bundleForClass:(Class)aClass; +- (NSString *)bundlePath; +- (void)setBundlePath:(NSString *)x; +@end + +@interface NSException : NSObject <NSCopying, NSCoding> {} +@end + +@class NSArray, NSDictionary, NSError, NSString, NSURL; + +@interface DTPlugInManager : NSObject +@end + +@implementation DTPlugInManager ++ (DTPlugInManager *)defaultPlugInManager { + @try { + NSMutableArray *plugInPaths = [NSMutableArray arrayWithCapacity:100]; + NSBundle *frameworkBundle = [NSBundle bundleForClass:[DTPlugInManager class]]; + frameworkBundle.bundlePath = 0; + [plugInPaths addObject:frameworkBundle.bundlePath]; + } + @catch (NSException *exception) {} +} +@end diff --git a/clang/test/SemaObjC/objc-property-7.m b/clang/test/SemaObjC/objc-property-7.m new file mode 100644 index 00000000000..ef7a98ad89c --- /dev/null +++ b/clang/test/SemaObjC/objc-property-7.m @@ -0,0 +1,34 @@ +// RUN: clang -fsyntax-only -verify %s +typedef signed char BOOL; +typedef struct _NSZone NSZone; + +@protocol NSObject +- (BOOL)isEqual:(id)object; +@end + +@protocol NSCopying +- (id)copyWithZone:(NSZone *)zone; +@end + +@interface NSObject <NSObject> {} +@end + +@class NSString, NSData, NSMutableData, NSMutableDictionary, NSMutableArray; + +@interface SCMObject : NSObject <NSCopying> {} + @property(assign) SCMObject *__attribute__((objc_gc(weak))) parent; +@end + +@interface SCMNode : SCMObject +{ + NSString *_name; +} +@property(copy) NSString *name; +@end + +@implementation SCMNode + @synthesize name = _name; + - (void) setParent:(SCMNode*) inParent { + super.parent = inParent; + } +@end diff --git a/clang/test/SemaObjC/objc-property-8.m b/clang/test/SemaObjC/objc-property-8.m new file mode 100644 index 00000000000..8ca0afc1ed4 --- /dev/null +++ b/clang/test/SemaObjC/objc-property-8.m @@ -0,0 +1,74 @@ +// RUN: clang -fsyntax-only -verify %s +typedef signed char BOOL; +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 +@protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end +@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end + +@interface NSObject <NSObject> {} @end + +typedef float CGFloat; + +typedef enum { NSMinXEdge = 0, NSMinYEdge = 1, NSMaxXEdge = 2, NSMaxYEdge = 3 } NSFastEnumerationState; + +@protocol NSFastEnumeration +- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len; +@end + +@class NSString; + +@interface NSDictionary : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration> +- (NSUInteger)count; +@end + +extern NSString * const NSBundleDidLoadNotification; + +@interface NSObject(NSKeyValueObserving) +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context; +- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath; +@end + +enum { NSCaseInsensitivePredicateOption = 0x01, NSDiacriticInsensitivePredicateOption = 0x02 }; + +@interface NSResponder : NSObject <NSCoding> {} +@end + +extern NSString * const NSFullScreenModeAllScreens; +@interface NSWindowController : NSResponder <NSCoding> {} +@end + +extern NSString *NSAlignmentBinding ; + +@interface _XCOQQuery : NSObject {} +@end + +extern NSString *PBXWindowDidChangeFirstResponderNotification; + +@interface PBXModule : NSWindowController {} +@end + +@class _XCOQHelpTextBackgroundView; +@interface PBXOpenQuicklyModule : PBXModule +{ +@private + _XCOQQuery *_query; +} +@end + +@interface PBXOpenQuicklyModule () +@property(readwrite, retain) _XCOQQuery *query; +@end + +@implementation PBXOpenQuicklyModule +@synthesize query = _query; +- (void) _clearQuery +{ + [self.query removeObserver: self forKeyPath: @"matches"]; +} +@end + diff --git a/clang/test/SemaObjC/objc-property-9-impl-method.m b/clang/test/SemaObjC/objc-property-9-impl-method.m new file mode 100644 index 00000000000..bb13d01b74a --- /dev/null +++ b/clang/test/SemaObjC/objc-property-9-impl-method.m @@ -0,0 +1,63 @@ +// RUN: clang %s -fsyntax-only -verify +// rdar://5967199 + +typedef signed char BOOL; +@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; + +@protocol NSObject +- (BOOL) isEqual:(id) object; +@end + +@protocol NSCoding +- (void) encodeWithCoder:(NSCoder *) aCoder; +@end + +@interface NSObject < NSObject > {} +@end + +typedef float CGFloat; +typedef struct _NSPoint {} NSSize; +typedef struct _NSRect {} NSRect; +typedef enum { NSMinXEdge = 0, NSMinYEdge = 1, NSMaxXEdge = 2, NSMaxYEdge = 3} NSRectEdge; +extern void NSDivideRect(NSRect inRect, NSRect * slice, NSRect * rem, CGFloat amount, NSRectEdge edge); + +@interface NSResponder:NSObject < NSCoding > {} +@end + +@protocol NSAnimatablePropertyContainer +- (id) animator; +@end + +extern NSString *NSAnimationTriggerOrderIn; + +@interface NSView:NSResponder < NSAnimatablePropertyContainer > {} +-(NSRect) bounds; +@end + +enum { + NSBackgroundStyleLight = 0, NSBackgroundStyleDark, NSBackgroundStyleRaised, NSBackgroundStyleLowered +}; + +@interface NSTabView:NSView {} +@end + +@ class OrganizerTabHeader; + +@interface OrganizerTabView:NSTabView {} +@property(assign) +NSSize minimumSize; +@end + +@interface OrganizerTabView() +@property(readonly) OrganizerTabHeader *tabHeaderView; +@property(readonly) NSRect headerRect; +@end + +@implementation OrganizerTabView +@dynamic tabHeaderView, headerRect, minimumSize; +-(CGFloat) tabAreaThickness {} +-(NSRectEdge) rectEdgeForTabs { + NSRect dummy, result = {}; + NSDivideRect(self.bounds, &result, &dummy, self.tabAreaThickness, self.rectEdgeForTabs); +} + diff --git a/clang/test/SemaObjC/objc-props-on-prots.m b/clang/test/SemaObjC/objc-props-on-prots.m new file mode 100644 index 00000000000..aa5be257954 --- /dev/null +++ b/clang/test/SemaObjC/objc-props-on-prots.m @@ -0,0 +1,65 @@ +// RUN: clang -fsyntax-only -verify %s +typedef signed char BOOL; +@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; + +@protocol NSObject +- (BOOL) isEqual:(id) object; +@end + +@protocol NSCoding +- (void) encodeWithCoder:(NSCoder *) aCoder; +@end + +@interface NSObject < NSObject > {} @end + +typedef float CGFloat; + +@interface NSResponder:NSObject < NSCoding > {} @end + +@class XCElementView; + +typedef struct _XCElementInset {} XCElementInset; + +@protocol XCElementP < NSObject > +-(BOOL) vertical; +@end + +@protocol XCElementDisplayDelegateP; +@protocol XCElementTabMarkerP; + +typedef NSObject < XCElementTabMarkerP > XCElementTabMarker; + +@protocol XCElementTabberP < XCElementP > +-(void) setMarker:(XCElementTabMarker *) marker; +@end + +typedef NSObject < XCElementTabberP > XCElementTabber; + +@protocol XCElementTabMarkerP < NSObject > +@property(nonatomic) +BOOL variableSized; +@end + +@protocol XCElementJustifierP < XCElementP > +-(void) setHJustification:(CGFloat) hJust; +@end + +typedef NSObject < XCElementJustifierP > XCElementJustifier; +@interface XCElementImp:NSObject < XCElementP > {} +@end + +@class XCElementImp; + +@interface XCElementTabberImp:XCElementImp < XCElementTabberP > { + XCElementTabMarker *_marker; +} +@end + +@implementation XCElementTabberImp +- (void) setMarker:(XCElementTabMarker *) marker { + if (_marker && _marker.variableSized) { + } +} +- vertical { return self; } +- (BOOL)isEqual:x { return 1; } +@end diff --git a/clang/test/SemaObjC/objc-protocol-1.m b/clang/test/SemaObjC/objc-protocol-1.m new file mode 100644 index 00000000000..3ace0ac3de0 --- /dev/null +++ b/clang/test/SemaObjC/objc-protocol-1.m @@ -0,0 +1,14 @@ +// RUN: clang -fsyntax-only -verify %s +// rdar://5986251 + +@protocol SomeProtocol +- (void) bar; +@end + +void foo(id x) { + bar((short<SomeProtocol>)x); // expected-error {{expected ')'}} expected-error {{to match this '('}} + bar((<SomeProtocol>)x); // expected-warning {{protocol qualifiers without 'id' is archaic}} + + [(<SomeProtocol>)x bar]; // expected-warning {{protocol qualifiers without 'id' is archaic}} +} + diff --git a/clang/test/SemaObjC/objc-string.m b/clang/test/SemaObjC/objc-string.m new file mode 100644 index 00000000000..e3974ad8f66 --- /dev/null +++ b/clang/test/SemaObjC/objc-string.m @@ -0,0 +1,15 @@ +// RUN: clang %s -verify -fsyntax-only && +// RUN: clang %s -verify -fsyntax-only -DDECLAREIT + +// a declaration of NSConstantString is not required. +#ifdef DECLAREIT +@interface NSConstantString; +@end +#endif + + + +id s = @"123"; // simple +id t = @"123" @"456"; // concat +id u = @"123" @ blah; // expected-error: {{unexpected token}} + diff --git a/clang/test/SemaObjC/objc-synchronized.m b/clang/test/SemaObjC/objc-synchronized.m new file mode 100644 index 00000000000..365da92dd4b --- /dev/null +++ b/clang/test/SemaObjC/objc-synchronized.m @@ -0,0 +1,75 @@ +// RUN: clang -fsyntax-only -verify %s +typedef signed char BOOL; +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 + +@protocol NSMutableCopying +- (id)mutableCopyWithZone:(NSZone *)zone; +@end + +@protocol NSCoding +- (void)encodeWithCoder:(NSCoder *)aCoder; +@end + +@interface NSObject <NSObject> {} @end + +typedef float CGFloat; +typedef struct { int a; } NSFastEnumerationState; + +@protocol NSFastEnumeration +- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len; +@end + +typedef unsigned short unichar; + +@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding> +- (NSUInteger)length; +@end + +@interface NSSimpleCString : NSString {} @end + +@interface NSConstantString : NSSimpleCString @end + +extern void *_NSConstantStringClassReference; + +@interface NSDictionary : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration> +- (NSUInteger)count; +@end + +@interface NSMutableDictionary : NSDictionary +- (void)removeObjectForKey:(id)aKey; +@end + +@class NSArray, NSSet, NSHashTable; + +@protocol PBXTrackableTask <NSObject> +- (float) taskPercentComplete; +- taskIdentifier; +@end + +@interface PBXTrackableTaskManager : NSObject { + NSMutableDictionary *_trackableTasks; +} +@end + +NSString *XCExecutableDebugTaskIdentifier = @"XCExecutableDebugTaskIdentifier"; + +@implementation PBXTrackableTaskManager +- (id) init {} +- (void) unregisterTask:(id <PBXTrackableTask>) task { + @synchronized (self) { + id taskID = [task taskIdentifier]; + id task = [_trackableTasks objectForKey:taskID]; // expected-warning{{method '-objectForKey:' not found (return type defaults to 'id')}} + } +} +@end + diff --git a/clang/test/SemaObjC/objc-try-catch.m b/clang/test/SemaObjC/objc-try-catch.m new file mode 100644 index 00000000000..e4c20b73438 --- /dev/null +++ b/clang/test/SemaObjC/objc-try-catch.m @@ -0,0 +1,37 @@ +// RUN: clang -fsyntax-only -verify %s +typedef signed char BOOL; +typedef struct _NSZone NSZone; + +@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; + +@protocol NSObject +- (BOOL)isEqual:(id)object; +@end + +@protocol NSCopying +- (id)copyWithZone:(NSZone *)zone; +@end + +@protocol NSCoding +- (void)encodeWithCoder:(NSCoder *)aCoder; +@end + +@interface NSObject <NSObject> {} +@end + +@class NSData, NSArray, NSDictionary, NSCharacterSet, NSData, NSURL, NSError, NSLocale; + +@interface NSException : NSObject <NSCopying, NSCoding> {} +@end + +@class ASTNode, XCRefactoringParser, Transform, TransformInstance, XCRefactoringSelectionInfo; + +@interface XCRefactoringTransformation : NSObject {} +@end + +@implementation XCRefactoringTransformation +- (NSDictionary *)setUpInfoForTransformKey:(NSString *)transformKey outError:(NSError **)outError; { + @try {} + // the exception name is optional (weird) + @catch (NSException *) {} +} diff --git a/clang/test/SemaObjC/objc-typedef-class.m b/clang/test/SemaObjC/objc-typedef-class.m new file mode 100644 index 00000000000..1bb3f87aa5a --- /dev/null +++ b/clang/test/SemaObjC/objc-typedef-class.m @@ -0,0 +1,78 @@ +// RUN: clang -fsyntax-only -verify %s +typedef signed char BOOL; +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 +@protocol NSCoding - (void) encodeWithCoder:(NSCoder *) aCoder; @end + +@interface NSObject < NSObject > {} ++(id) alloc; +@end + +typedef float CGFloat; + +@interface NSTask:NSObject +- (id) init; +@end + +typedef NSUInteger NSControlSize; +typedef struct __CFlags {} _CFlags; + +@interface NSCell:NSObject < NSCopying, NSCoding > {} +@end + +@interface NSActionCell:NSCell {} @end + +@class NSAttributedString, NSFont, NSImage, NSSound; + +typedef struct _XCElementInset {} XCElementInset; + +@protocol XCElementP < NSObject > +-(BOOL) vertical; +@end + +@protocol XCElementDisplayDelegateP; +@protocol XCElementDisplayDelegateP < NSObject > +-(void) configureForControlSize:(NSControlSize)size font:(NSFont *)font addDefaultSpace:(XCElementInset) additionalSpace; +@end + +@protocol XCElementSpacerP < XCElementP > +@end + +typedef NSObject < XCElementSpacerP > XCElementSpacer; + +@protocol XCElementTogglerP < XCElementP > -(void) setDisplayed:(BOOL) displayed; +@end + +typedef NSObject < XCElementTogglerP > XCElementToggler; + +@interface XCElementRootFace:NSObject {} @end + +@interface XCElementFace:XCElementRootFace {} @end + +@class XCElementToggler; + +@interface XCRASlice:XCElementFace {} @end + +@class XCElementSpacings; + +@interface XCElementDisplay:NSObject < XCElementDisplayDelegateP > {} @end +@interface XCElementDisplayRect:XCElementDisplay {} @end + +typedef XCElementDisplayRect XCElementGraphicsRect; + +@interface XCElementDisplayFillerImage:XCElementDisplay {} @end + +@implementation XCRASlice +- (void) addSliceWithLabel:(NSString *)label statusKey:(NSString *)statusKey disclosed:(BOOL)disclosed +{ + static XCElementGraphicsRect *_sGraphicsDelegate = ((void *) 0); + if (!_sGraphicsDelegate) { + _sGraphicsDelegate =[[XCElementGraphicsRect alloc] init]; + } +} +@end diff --git a/clang/test/SemaObjC/objc-types-compatible.m b/clang/test/SemaObjC/objc-types-compatible.m new file mode 100644 index 00000000000..bd8a7490c41 --- /dev/null +++ b/clang/test/SemaObjC/objc-types-compatible.m @@ -0,0 +1,40 @@ +// RUN: clang -fsyntax-only -verify -pedantic %s +typedef signed char BOOL; +typedef int NSInteger; + +@class NSString; + +@protocol PBXCompletionItem +- (NSString *) name; +- (NSInteger)priority; +@end + +extern NSInteger codeAssistantCaseCompareItems(id a, id b, void *context); + +NSInteger codeAssistantCaseCompareItems(id<PBXCompletionItem> a, id<PBXCompletionItem> b, void *context) +{ +} + +#if 0 +FIXME: clang needs to compare each method prototype with its definition (see below). + +GCC produces the following correct warnning: +[snaroff:llvm/tools/clang] snarofflocal% cc -c test/Sema/objc-types-compatible.m +test/Sema/objc-types-compatible.m: In function ‘-[TedWantsToVerifyObjCDoesTheRightThing compareThis:withThat:]’: +test/Sema/objc-types-compatible.m:26: warning: conflicting types for ‘-(id)compareThis:(id <PBXCompletionItem>)a withThat:(id <PBXCompletionItem>)b’ +test/Sema/objc-types-compatible.m:20: warning: previous declaration of ‘-(id)compareThis:(int)a withThat:(id)b’ +#endif + +@interface TedWantsToVerifyObjCDoesTheRightThing + +- compareThis:(int)a withThat:(id)b; + +@end + +@implementation TedWantsToVerifyObjCDoesTheRightThing + +- compareThis:(id<PBXCompletionItem>)a withThat:(id<PBXCompletionItem>)b { + return self; +} + +@end diff --git a/clang/test/SemaObjC/objc-unused.m b/clang/test/SemaObjC/objc-unused.m new file mode 100644 index 00000000000..cbe15a1abb5 --- /dev/null +++ b/clang/test/SemaObjC/objc-unused.m @@ -0,0 +1,18 @@ +// RUN: clang %s -verify -fsyntax-only +#include <stdio.h> + +@interface Greeter ++ (void) hello; +@end + +@implementation Greeter ++ (void) hello { + fprintf(stdout, "Hello, World!\n"); +} +@end + +int main (void) { + [Greeter hello]; + return 0; +} + diff --git a/clang/test/SemaObjC/protocol-expr-1.m b/clang/test/SemaObjC/protocol-expr-1.m new file mode 100644 index 00000000000..dff2866020d --- /dev/null +++ b/clang/test/SemaObjC/protocol-expr-1.m @@ -0,0 +1,15 @@ +// RUN: clang -fsyntax-only -verify %s + +@protocol fproto; + +@protocol p1 +@end + +@class cl; + +int main() +{ + Protocol *proto = @protocol(p1); + Protocol *fproto = @protocol(fproto); +} + diff --git a/clang/test/SemaObjC/protocol-expr-neg-1.m b/clang/test/SemaObjC/protocol-expr-neg-1.m new file mode 100644 index 00000000000..427e74417ab --- /dev/null +++ b/clang/test/SemaObjC/protocol-expr-neg-1.m @@ -0,0 +1,19 @@ +// RUN: clang -fsyntax-only -verify %s + +@class Protocol; + +@protocol fproto; + +@protocol p1 +@end + +@class cl; + +int main() +{ + Protocol *proto = @protocol(p1); + Protocol *fproto = @protocol(fproto); + Protocol *pp = @protocol(i); // expected-error {{cannot find protocol declaration for 'i'}} + Protocol *p1p = @protocol(cl); // expected-error {{cannot find protocol declaration for 'cl'}} +} + diff --git a/clang/test/SemaObjC/protocol-id-test-1.m b/clang/test/SemaObjC/protocol-id-test-1.m new file mode 100644 index 00000000000..765500e10d8 --- /dev/null +++ b/clang/test/SemaObjC/protocol-id-test-1.m @@ -0,0 +1,16 @@ +// RUN: clang -verify %s + +@interface FF +- (void) Meth; +@end + +@protocol P +@end + +@interface INTF<P> +- (void)IMeth; +@end + +@implementation INTF +- (void)IMeth {INTF<P> *pi; [pi Meth]; } // expected-warning {{method '-Meth' not found in protocol (return type defaults to 'id')}} +@end diff --git a/clang/test/SemaObjC/protocol-id-test-2.m b/clang/test/SemaObjC/protocol-id-test-2.m new file mode 100644 index 00000000000..525d2cca9e9 --- /dev/null +++ b/clang/test/SemaObjC/protocol-id-test-2.m @@ -0,0 +1,14 @@ +// RUN: clang -verify %s + +@protocol P +@end + +@interface INTF<P> +- (void)IMeth; + - (void) Meth; +@end + +@implementation INTF +- (void)IMeth { [(id<P>)self Meth]; } // expected-warning {{method '-Meth' not found in protocol (return type defaults to 'id')}} +- (void) Meth {} +@end diff --git a/clang/test/SemaObjC/protocol-id-test-3.m b/clang/test/SemaObjC/protocol-id-test-3.m new file mode 100644 index 00000000000..8c2beee989c --- /dev/null +++ b/clang/test/SemaObjC/protocol-id-test-3.m @@ -0,0 +1,94 @@ +// RUN: clang -pedantic -fsyntax-only -verify %s + +@protocol MyProto1 +@end + +@protocol MyProto2 +@end + +@interface INTF @end + +id<MyProto1> Func(INTF <MyProto1, MyProto2> *p2) +{ + return p2; +} + + + + + id<MyProto1> Gunc(id <MyProto1, MyProto2>p2) +{ + return p2; +} + + + id<MyProto1> Gunc1(id <MyProto1, MyProto2>p2) +{ + return p2; +} + +id<MyProto1, MyProto2> Gunc2(id <MyProto1>p2) +{ + Func(p2); // expected-error {{incompatible type passing 'id<MyProto1>', expected 'INTF<MyProto1,MyProto2> *'}} + return p2; // expected-error {{incompatible type returning 'id<MyProto1>', expected 'id<MyProto1,MyProto2>'}} +} + + + +id<MyProto1> Gunc3(id <MyProto2>p2) +{ + return p2; // expected-error {{incompatible type returning 'id<MyProto2>', expected 'id<MyProto1>'}} +} + + +id<MyProto1, MyProto2> Gunc4(id <MyProto2, MyProto1>p2) +{ + return p2; +} + + + +INTF<MyProto1> * Hunc(id <MyProto1, MyProto2>p2) +{ + return p2; +} + + +INTF<MyProto1> * Hunc1(id <MyProto1, MyProto2>p2) +{ + return p2; +} + +INTF<MyProto1, MyProto2> * Hunc2(id <MyProto1>p2) +{ + Func(p2); // expected-error {{incompatible type passing 'id<MyProto1>', expected 'INTF<MyProto1,MyProto2> *'}} + return p2; // expected-error {{incompatible type returning 'id<MyProto1>', expected 'INTF<MyProto1,MyProto2> *'}} +} + +INTF<MyProto1> * Hunc3(id <MyProto2>p2) +{ + return p2; // expected-error {{incompatible type returning 'id<MyProto2>', expected 'INTF<MyProto1> *'}} +} + + +INTF<MyProto1, MyProto2> * Hunc4(id <MyProto2, MyProto1>p2) +{ + return p2; +} + +id Iunc(id <MyProto1, MyProto2>p2) +{ + return p2; +} + + +id<MyProto1> Iunc1(id p2) +{ + return p2; +} + +id<MyProto1, MyProto2> Iunc2(id p2) +{ + Iunc(p2); + return p2; +} diff --git a/clang/test/SemaObjC/protocol-test-1.m b/clang/test/SemaObjC/protocol-test-1.m new file mode 100644 index 00000000000..6fb28b533cf --- /dev/null +++ b/clang/test/SemaObjC/protocol-test-1.m @@ -0,0 +1,20 @@ +// RUN: clang -fsyntax-only -verify %s + +@protocol PROTO1 +@required +- (int) FooBar; +@optional +- (void) MyMethod1; ++ (int) S; +@end + +@interface INTF1 +@required // expected-error {{@required may be specified in protocols only}} +- (int) FooBar; +- (int) FooBar1; +- (int) FooBar2; +@optional // expected-error {{@optional may be specified in protocols only}} ++ (int) C; + +- (int)I; +@end diff --git a/clang/test/SemaObjC/protocol-test-2.m b/clang/test/SemaObjC/protocol-test-2.m new file mode 100644 index 00000000000..f323745c5df --- /dev/null +++ b/clang/test/SemaObjC/protocol-test-2.m @@ -0,0 +1,31 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface INTF1 @end + +@protocol p1,p2,p3; + +@protocol p1; + +@protocol PROTO1 +- (INTF1<p1>*) meth; +@end + +@protocol PROTO2<p1> // expected-warning {{cannot find protocol definition for 'p1', referenced by 'PROTO2'}} +@end + +@protocol p1 @end + +@protocol PROTO<p1> +@end + +@protocol PROTO<p1> // expected-error {{duplicate protocol declaration of 'PROTO'}} +@end + +@protocol PROTO3<p1, p1> +@end + +@protocol p2 <p1> +@end + +@protocol PROTO4 <p1, p2, PROTO, PROTO3, p3> // expected-warning {{cannot find protocol definition for 'p3', referenced by 'PROTO4'}} +@end diff --git a/clang/test/SemaObjC/selector-1.m b/clang/test/SemaObjC/selector-1.m new file mode 100644 index 00000000000..476568f6caa --- /dev/null +++ b/clang/test/SemaObjC/selector-1.m @@ -0,0 +1,14 @@ +// RUN: clang -verify %s + +int main() { + SEL s = @selector(retain); + SEL s1 = @selector(meth1:); + SEL s2 = @selector(retainArgument::); + SEL s3 = @selector(retainArgument:::::); + SEL s4 = @selector(retainArgument:with:); + SEL s5 = @selector(meth1:with:with:); + SEL s6 = @selector(getEnum:enum:bool:); + SEL s7 = @selector(char:float:double:unsigned:short:long:); + + SEL s9 = @selector(:enum:bool:); +} diff --git a/clang/test/SemaObjC/selector-overload.m b/clang/test/SemaObjC/selector-overload.m new file mode 100644 index 00000000000..7bd25444c7e --- /dev/null +++ b/clang/test/SemaObjC/selector-overload.m @@ -0,0 +1,47 @@ +// RUN: clang %s -fsyntax-only + +@interface NSObject ++ alloc; +- init; +@end + +struct D { + double d; +}; + +@interface Foo : NSObject + +- method:(int)a; +- method:(int)a; + +@end + +@interface Bar : NSObject + +- method:(void *)a; + +@end + +@interface Car : NSObject + +- method:(struct D)a; + +@end + +@interface Zar : NSObject + +- method:(float)a; + +@end + +@interface Rar : NSObject + +- method:(float)a; + +@end + +int main() { + id xx = [[Car alloc] init]; // expected-warning {{incompatible types assigning 'int' to 'id'}} + + [xx method:4]; +} diff --git a/clang/test/SemaObjC/static-ivar-ref-1.m b/clang/test/SemaObjC/static-ivar-ref-1.m new file mode 100644 index 00000000000..d01a7fb6da0 --- /dev/null +++ b/clang/test/SemaObjC/static-ivar-ref-1.m @@ -0,0 +1,16 @@ +// RUN: clang -ast-print %s + +@interface current +{ + int ivar; + int ivar1; + int ivar2; +} +@end + +current *pc; + +int foo() +{ + return pc->ivar2 + (*pc).ivar + pc->ivar1; +} diff --git a/clang/test/SemaObjC/undef-protocol-methods-1.m b/clang/test/SemaObjC/undef-protocol-methods-1.m new file mode 100644 index 00000000000..9ad3593c6c4 --- /dev/null +++ b/clang/test/SemaObjC/undef-protocol-methods-1.m @@ -0,0 +1,42 @@ +// RUN: clang -fsyntax-only -verify %s + +@protocol P1 +- (void) P1proto; ++ (void) ClsP1Proto; +- (void) DefP1proto; +@end +@protocol P2 +- (void) P2proto; ++ (void) ClsP2Proto; +@end + +@protocol P3<P2> +- (void) P3proto; ++ (void) ClsP3Proto; ++ (void) DefClsP3Proto; +@end + +@protocol PROTO<P1, P3> +- (void) meth; +- (void) meth : (int) arg1; ++ (void) cls_meth : (int) arg1; +@end + +@interface INTF <PROTO> +@end + +@implementation INTF // expected-warning {{incomplete implementation}} \ + expected-warning {{method definition for 'meth' not found}} \ + expected-warning {{method definition for 'meth:' not found}} \ + expected-warning {{method definition for 'cls_meth:' not found}} \ + expected-warning {{method definition for 'P3proto' not found}} \ + expected-warning {{method definition for 'ClsP3Proto' not found}} \ + expected-warning {{method definition for 'P2proto' not found}} \ + expected-warning {{method definition for 'ClsP2Proto' not found}} \ + expected-warning {{method definition for 'ClsP1Proto' not found}} \ + expected-warning {{method definition for 'P1proto' not found}} +- (void) DefP1proto{} + ++ (void) DefClsP3Proto{} + +@end diff --git a/clang/test/SemaObjC/undef-superclass-1.m b/clang/test/SemaObjC/undef-superclass-1.m new file mode 100644 index 00000000000..7e12463654f --- /dev/null +++ b/clang/test/SemaObjC/undef-superclass-1.m @@ -0,0 +1,26 @@ +// RUN: clang -fsyntax-only -verify %s + +@class SUPER, Y; + +@interface INTF :SUPER // expected-error {{cannot find interface declaration for 'SUPER', superclass of 'INTF'}} +@end + +@interface SUPER @end + +@interface INTF1 : SUPER +@end + +@interface INTF2 : INTF1 +@end + +@interface INTF3 : Y // expected-error {{cannot find interface declaration for 'Y', superclass of 'INTF3'}} +@end + +@interface INTF1 // expected-error {{duplicate interface declaration for class 'INTF1'}} +@end + +@implementation SUPER +- (void)dealloc { + [super dealloc]; // expected-error {{no super class declared in @interface for 'SUPER'}} +} +@end diff --git a/clang/test/SemaObjC/undefined-protocol-type-1.m b/clang/test/SemaObjC/undefined-protocol-type-1.m new file mode 100644 index 00000000000..117f418ab1c --- /dev/null +++ b/clang/test/SemaObjC/undefined-protocol-type-1.m @@ -0,0 +1,9 @@ +// RUN: clang -fsyntax-only -verify %s + +@protocol p1, p4; +@protocol p2 @end + +@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'}} +@end diff --git a/clang/test/SemaObjC/va-method-1.m b/clang/test/SemaObjC/va-method-1.m new file mode 100644 index 00000000000..077982abbf5 --- /dev/null +++ b/clang/test/SemaObjC/va-method-1.m @@ -0,0 +1,17 @@ +// RUN: clang -fsyntax-only -verify %s + +#include <stdarg.h> + +@interface NSObject @end +@interface XX : NSObject @end + +@implementation XX +- (void)encodeValuesOfObjCTypes:(const char *)types, ... { + va_list ap; + va_start(ap, types); + while (*types) ; + va_end(ap); +} + +@end + |