OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [obj-c++.dg/] [try-catch-2.mm] - Blame information for rev 823

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 149 jeremybenn
/* Test out '@catch(id foo) {...}', which should catch
2
   all uncaught exceptions.  */
3
/* Developed by Ziemowit Laski .  */
4
 
5
/* { dg-options "-fobjc-exceptions" } */
6
/* { dg-do run } */
7
 
8
#include 
9
#include 
10
#include 
11
 
12
/* The following is not required in actual user code; we include it
13
   here to check that the compiler generates an internal definition of
14
   _setjmp that is consistent with what  provides.  */
15
#include 
16
 
17
#define CHECK_IF(expr) if(!(expr)) abort()
18
 
19
@interface Frob: Object
20
@end
21
 
22
@implementation Frob: Object
23
@end
24
 
25
static Frob* _connection = nil;
26
 
27
//--------------------------------------------------------------------
28
 
29
 
30
void test (Object* sendPort)
31
{
32
  int cleanupPorts = 1;
33
  Frob* receivePort = nil;
34
 
35
  @try {
36
    printf ("receivePort = %p\n", receivePort);
37
    printf ("sendPort = %p\n", sendPort);
38
    printf ("cleanupPorts = %d\n", cleanupPorts);
39
    printf ("---\n");
40
 
41
    receivePort = (Frob *) -1;
42
    _connection = (Frob *) -1;
43
    printf ("receivePort = %p\n", receivePort);
44
    printf ("sendPort = %p\n", sendPort);
45
    printf ("cleanupPorts = %d\n", cleanupPorts);
46
    printf ("---\n");
47
 
48
    receivePort = nil;
49
    sendPort = nil;
50
    cleanupPorts = 0;
51
 
52
    printf ("receivePort = %p\n", receivePort);
53
    printf ("sendPort = %p\n", sendPort);
54
    printf ("cleanupPorts = %d\n", cleanupPorts);
55
    printf ("---\n");
56
 
57
    @throw [Object new];
58
  }
59
  @catch(Frob *obj) {
60
    printf ("Exception caught by incorrect handler!\n");
61
    CHECK_IF(0);
62
  }
63
  @catch(id exc) {
64
    printf ("Exception caught by correct handler.\n");
65
    printf ("receivePort = %p (expected 0x0)\n", receivePort);
66
    printf ("sendPort = %p (expected 0x0)\n", sendPort);
67
    printf ("cleanupPorts = %d (expected 0)\n", cleanupPorts);
68
    printf ("---");
69
    CHECK_IF(!receivePort);
70
    CHECK_IF(!sendPort);
71
    CHECK_IF(!cleanupPorts);
72
  }
73
}
74
 
75
int main (void) {
76
  test((Object *)-1);
77
  return 0;
78
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.