Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s |
Steve Naroff | 6b9dfd4 | 2009-03-04 15:11:40 +0000 | [diff] [blame] | 2 | |
| 3 | #include <stddef.h> |
| 4 | |
Steve Naroff | a0c3e9c | 2009-04-08 23:52:26 +0000 | [diff] [blame] | 5 | typedef struct objc_object *id; |
Steve Naroff | 6b9dfd4 | 2009-03-04 15:11:40 +0000 | [diff] [blame] | 6 | id objc_getClass(const char *s); |
| 7 | |
| 8 | @interface Object |
John McCall | a52ef08 | 2009-11-11 02:41:58 +0000 | [diff] [blame] | 9 | - (id) initWithInt: (int) i; |
Steve Naroff | 6b9dfd4 | 2009-03-04 15:11:40 +0000 | [diff] [blame] | 10 | @end |
| 11 | |
| 12 | @protocol Func |
| 13 | + (int) class_func0; |
| 14 | - (int) instance_func0; |
| 15 | @end |
| 16 | |
| 17 | @interface Derived: Object |
| 18 | + (int) class_func1; |
| 19 | + (int) class_func2; |
| 20 | + (int) class_func3; |
| 21 | + (int) class_func4; |
| 22 | + (int) class_func5; |
| 23 | + (int) class_func6; |
| 24 | + (int) class_func7; |
| 25 | - (int) instance_func1; |
| 26 | - (int) instance_func2; |
| 27 | - (int) instance_func3; |
| 28 | - (int) instance_func4; |
| 29 | - (int) instance_func5; |
| 30 | - (int) instance_func6; |
| 31 | - (int) instance_func7; |
John McCall | a52ef08 | 2009-11-11 02:41:58 +0000 | [diff] [blame] | 32 | - (id) initWithInt: (int) i; |
Steve Naroff | 6b9dfd4 | 2009-03-04 15:11:40 +0000 | [diff] [blame] | 33 | @end |
| 34 | |
| 35 | @implementation Derived |
| 36 | + (int) class_func1 |
| 37 | { |
| 38 | int i = (size_t)[self class_func0]; // expected-warning {{method '-class_func0' not found (return type defaults to 'id')}} |
| 39 | return i + (size_t)[super class_func0]; // expected-warning {{method '+class_func0' not found (return type defaults to 'id')}} |
| 40 | } |
| 41 | + (int) class_func2 |
| 42 | { |
Steve Naroff | ebaa768 | 2009-04-07 15:07:57 +0000 | [diff] [blame] | 43 | int i = [(id <Func>)self class_func0]; |
Steve Naroff | a0c3e9c | 2009-04-08 23:52:26 +0000 | [diff] [blame] | 44 | i += [(id <Func>)super class_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}} |
Steve Naroff | 470301b | 2009-07-22 16:07:01 +0000 | [diff] [blame] | 45 | i += [(Class <Func>)self class_func0]; // |
| 46 | return i + [(Class <Func>)super class_func0]; // // expected-error {{cannot cast 'super' (it isn't an expression)}} |
Steve Naroff | 6b9dfd4 | 2009-03-04 15:11:40 +0000 | [diff] [blame] | 47 | } |
| 48 | + (int) class_func3 |
| 49 | { |
Steve Naroff | a0c3e9c | 2009-04-08 23:52:26 +0000 | [diff] [blame] | 50 | return [(Object <Func> *)super class_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}} |
Steve Naroff | 6b9dfd4 | 2009-03-04 15:11:40 +0000 | [diff] [blame] | 51 | } |
| 52 | + (int) class_func4 |
| 53 | { |
Steve Naroff | a0c3e9c | 2009-04-08 23:52:26 +0000 | [diff] [blame] | 54 | return [(Derived <Func> *)super class_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}} |
Steve Naroff | 6b9dfd4 | 2009-03-04 15:11:40 +0000 | [diff] [blame] | 55 | } |
| 56 | + (int) class_func5 |
| 57 | { |
| 58 | int i = (size_t)[Derived class_func0]; // expected-warning {{method '+class_func0' not found (return type defaults to 'id')}} |
| 59 | return i + (size_t)[Object class_func0]; // expected-warning {{method '+class_func0' not found (return type defaults to 'id')}} |
| 60 | } |
| 61 | + (int) class_func6 |
| 62 | { |
| 63 | return (size_t)[objc_getClass("Object") class_func1]; // GCC warns about this |
| 64 | } |
| 65 | + (int) class_func7 |
| 66 | { |
| 67 | return [objc_getClass("Derived") class_func1]; |
| 68 | } |
| 69 | - (int) instance_func1 |
| 70 | { |
| 71 | int i = (size_t)[self instance_func0]; // expected-warning {{method '-instance_func0' not found (return type defaults to 'id'))}} |
| 72 | return i + (size_t)[super instance_func0]; // expected-warning {{method '-instance_func0' not found (return type defaults to 'id')}} |
| 73 | } |
| 74 | - (int) instance_func2 |
| 75 | { |
Steve Naroff | a0c3e9c | 2009-04-08 23:52:26 +0000 | [diff] [blame] | 76 | return [(id <Func>)super instance_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}} |
Steve Naroff | 6b9dfd4 | 2009-03-04 15:11:40 +0000 | [diff] [blame] | 77 | } |
| 78 | - (int) instance_func3 |
| 79 | { |
Steve Naroff | a0c3e9c | 2009-04-08 23:52:26 +0000 | [diff] [blame] | 80 | return [(Object <Func> *)super instance_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}} |
Steve Naroff | 6b9dfd4 | 2009-03-04 15:11:40 +0000 | [diff] [blame] | 81 | } |
| 82 | - (int) instance_func4 |
| 83 | { |
Steve Naroff | a0c3e9c | 2009-04-08 23:52:26 +0000 | [diff] [blame] | 84 | return [(Derived <Func> *)super instance_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}} |
Steve Naroff | 6b9dfd4 | 2009-03-04 15:11:40 +0000 | [diff] [blame] | 85 | } |
| 86 | - (int) instance_func5 |
| 87 | { |
Fariborz Jahanian | b1006c7 | 2009-03-04 17:50:39 +0000 | [diff] [blame] | 88 | int i = (size_t)[Derived instance_func1]; // expected-warning {{method '+instance_func1' not found (return type defaults to 'id')}} |
Steve Naroff | 6b9dfd4 | 2009-03-04 15:11:40 +0000 | [diff] [blame] | 89 | return i + (size_t)[Object instance_func1]; // expected-warning {{method '+instance_func1' not found (return type defaults to 'id')}} |
| 90 | } |
| 91 | - (int) instance_func6 |
| 92 | { |
| 93 | return (size_t)[objc_getClass("Object") class_func1]; |
| 94 | } |
| 95 | - (int) instance_func7 |
| 96 | { |
| 97 | return [objc_getClass("Derived") class_func1]; |
| 98 | } |
John McCall | a52ef08 | 2009-11-11 02:41:58 +0000 | [diff] [blame] | 99 | - (id) initWithInt: (int) i |
| 100 | { |
| 101 | // Don't warn about parentheses here. |
| 102 | if (self = [super initWithInt: i]) { |
| 103 | [self instance_func1]; |
| 104 | } |
| 105 | return self; |
| 106 | } |
Steve Naroff | 6b9dfd4 | 2009-03-04 15:11:40 +0000 | [diff] [blame] | 107 | @end |
| 108 | |