blob: 043314d4e1821f694387061c47ddb84ae4627b12 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Steve Naroff6b9dfd42009-03-04 15:11:40 +00002
3#include <stddef.h>
4
Steve Naroffa0c3e9c2009-04-08 23:52:26 +00005typedef struct objc_object *id;
Steve Naroff6b9dfd42009-03-04 15:11:40 +00006id objc_getClass(const char *s);
7
8@interface Object
John McCalla52ef082009-11-11 02:41:58 +00009- (id) initWithInt: (int) i;
Steve Naroff6b9dfd42009-03-04 15:11:40 +000010@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 McCalla52ef082009-11-11 02:41:58 +000032- (id) initWithInt: (int) i;
Steve Naroff6b9dfd42009-03-04 15:11:40 +000033@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 Naroffebaa7682009-04-07 15:07:57 +000043 int i = [(id <Func>)self class_func0];
Steve Naroffa0c3e9c2009-04-08 23:52:26 +000044 i += [(id <Func>)super class_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}}
Steve Naroff470301b2009-07-22 16:07:01 +000045 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 Naroff6b9dfd42009-03-04 15:11:40 +000047}
48+ (int) class_func3
49{
Steve Naroffa0c3e9c2009-04-08 23:52:26 +000050 return [(Object <Func> *)super class_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}}
Steve Naroff6b9dfd42009-03-04 15:11:40 +000051}
52+ (int) class_func4
53{
Steve Naroffa0c3e9c2009-04-08 23:52:26 +000054 return [(Derived <Func> *)super class_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}}
Steve Naroff6b9dfd42009-03-04 15:11:40 +000055}
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'))}}
Chris Lattnereb483eb2010-04-11 08:28:14 +000072 return i + (size_t)[super instance_func0]; // expected-warning {{'Object' may not respond to 'instance_func0')}}
Steve Naroff6b9dfd42009-03-04 15:11:40 +000073}
74- (int) instance_func2
75{
Steve Naroffa0c3e9c2009-04-08 23:52:26 +000076 return [(id <Func>)super instance_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}}
Steve Naroff6b9dfd42009-03-04 15:11:40 +000077}
78- (int) instance_func3
79{
Steve Naroffa0c3e9c2009-04-08 23:52:26 +000080 return [(Object <Func> *)super instance_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}}
Steve Naroff6b9dfd42009-03-04 15:11:40 +000081}
82- (int) instance_func4
83{
Steve Naroffa0c3e9c2009-04-08 23:52:26 +000084 return [(Derived <Func> *)super instance_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}}
Steve Naroff6b9dfd42009-03-04 15:11:40 +000085}
86- (int) instance_func5
87{
Fariborz Jahanianb1006c72009-03-04 17:50:39 +000088 int i = (size_t)[Derived instance_func1]; // expected-warning {{method '+instance_func1' not found (return type defaults to 'id')}}
Steve Naroff6b9dfd42009-03-04 15:11:40 +000089 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 McCalla52ef082009-11-11 02:41:58 +000099- (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 Naroff6b9dfd42009-03-04 15:11:40 +0000107@end
108