xref: /llvm-project/clang/test/SemaObjC/super.m (revision 0f1c1be1968076d6f96f8a7bcc4a15cf195ecd97)
1// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s
2
3void takevoidptr(void*);
4
5
6@interface Foo
7- iMethod;
8+ cMethod;
9@end
10
11@interface A
12+ superClassMethod;
13- (void)instanceMethod;
14@end
15
16@interface B : A
17- (void)instanceMethod;
18+ classMethod;
19@end
20
21@implementation B
22
23- (void)instanceMethod {
24  [super iMethod]; // expected-warning{{'A' may not respond to 'iMethod'}}
25
26  // Use of super in a block is ok and does codegen to the right thing.
27  takevoidptr(^{
28    [super instanceMethod];
29  });
30}
31
32+ classMethod {
33  [super cMethod]; // expected-warning{{method '+cMethod' not found (return type defaults to 'id')}}
34
35  id X[] = { [ super superClassMethod] };
36  id Y[] = {
37    [ super.superClassMethod iMethod],
38    super.superClassMethod,
39    (id)super.superClassMethod  // not a cast of super
40  };
41  return 0;
42}
43@end
44
45@interface XX
46- m;
47@end
48
49void f(id super) {
50  [super m];
51}
52void f0(int super) {
53  [super m]; // expected-warning{{receiver type 'int' is not 'id'}}
54}
55void f1(id puper) {  // expected-note {{'puper' declared here}}
56  [super m]; // expected-error{{use of undeclared identifier 'super'}}
57}
58
59typedef Foo super;
60
61typedef Foo FooTD;
62
63void test(void) {
64  [FooTD cMethod];
65  [super cMethod];
66}
67
68struct SomeStruct {
69  int X;
70};
71
72int test2(void) {
73  struct SomeStruct super = { 0 };
74  return super.X;
75}
76
77int test3(void) {
78  id super = 0;
79  [(B*)super instanceMethod];
80  int *s1 = (int*)super;
81
82  id X[] = { [ super superClassMethod] };
83  return 0;
84}
85