Debian Codegraph @

gcc/testsuite/g++.old-deja/g++.brendan/eh1.C

raw
1 // { dg-do run }
2 // { dg-options "-O" }
3 // PRMS Id: 10776
4
5 extern "C" int printf (const char *, ...);
6
7 class Foo
8 {
9 public:
10 Foo(int n) : n_(n) { }
11 int f() { return n_; }
12
13 int badTest();
14 int goodTest();
15
16 private:
17
18 int n_;
19 };
20
21 int Foo::badTest()
22 {
23 try {
24 throw int(99);
25 }
26
27 catch (int &i) {
28 n_ = 16;
29 }
30
31 return n_;
32 // On the sparc, the return will use a ld [%l0],%i0 instruction.
33 // However %l0 was clobbered at the end of the catch block. It was
34 // used to do an indirect call.
35 }
36
37
38 int Foo::goodTest()
39 {
40 int n;
41
42 try {
43 throw int(99);
44 }
45
46 catch (int &i) {
47 n = 16;
48 }
49
50 return n_;
51 // The return will use a ld [%l2],%i0 instruction. Since %l2
52 // contains the "this" pointer this works.
53 }
54
55 int main()
56 {
57 Foo foo(5);
58 foo.goodTest();
59 foo.badTest();
60
61 // the badTest will have failed
62 printf ("PASS\n");
63 }