summaryrefslogtreecommitdiff
path: root/gcc/testsuite/objc/execute/exceptions/foward-1.m
blob: 6b31d7cc86c002ec8a20bb6db5e6e197f79375f5 (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* Check that throwing an exception from a -forward:: works.  */
/* Developed by Marcin Koziej <creep@desk.pl>.  */

#include <stdlib.h>
#include <objc/Object.h>
#ifndef __NEXT_RUNTIME__
#import <objc/objc-api.h>
#endif

#ifdef __OBJC2__
@interface Object (TEST_SUITE_ADDITIONS)
+ initialize;
+ alloc;
+ new;
- init;
- free;
@end

@implementation Object (TEST_SUITE_ADDITIONS)
+ initialize { return self; }
+ alloc { return class_createInstance (self, 0); }
+ new { return [[self alloc] init]; }
- init { return self; }
- free { return object_dispose(self); }
@end
#endif

static int i;

__attribute__((objc_exception)) 
@interface Thrower : Object 
- forward: (SEL) s : (void*) a;
@end

@implementation Thrower
- forward: (SEL) s : (void*) a
{
  i++;
  @throw [Object new];
  return nil;
}
@end

int
main()
{
  id t = [Thrower new];
  @try
  {
    [t doesnotexist];
  }
  @catch (id error)
  {
    i++;
    [error free];
  }
  
  if (i != 2)
    abort ();
  
  return 0;
}