summaryrefslogtreecommitdiff
path: root/gcc/testsuite/objc.dg/instancetype-0.m
blob: 32cafdf314c328e58e6560c8d615b8714eabbb68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* Contributed by Iain Sandoe <iain@sandoe.co.uk>, May 2019.  */
/* { dg-do compile } */

/* Basic check of parsing instancetype.  */

extern id class_createInstance (id, int);
extern id class_getSuperclass (id);

@interface MyObject
{
  Class isa;
}
+ (instancetype)alloc;
- (instancetype)init;
+ (instancetype)initialize;
+ (instancetype)factoryMethodA;
+ (id)factoryMethodB;
+ (Class) class;
+ (Class) superclass;
@end

@implementation MyObject
+ (instancetype)alloc { return class_createInstance (self, 0); }
- (instancetype)init  { return self; }
+ (instancetype)initialize { return self; }
+ (instancetype)factoryMethodA { return [[[self class] alloc] init]; }
+ (id)factoryMethodB { return [[[self class] alloc] init]; }
+ (Class) class { return self; }
+ (Class) superclass { return class_getSuperclass (self); }
@end