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