Debian Codegraph @

gcc/testsuite/g++.old-deja/g++.law/except5.C

raw
1 // { dg-do assemble }
2 // { dg-options "-fexceptions" }
3 // { dg-skip-if "requires hosted libstdc++ for iostream" { ! hostedlib } }
4 // GROUPS passed exceptions
5 // except file
6 // Message-Id: <[email protected]>
7 // From: Grigory Tsipenyuk <[email protected]>
8 // Subject: exception's bug?
9 // Date: Wed, 10 Nov 1993 11:07:12 -0500
10
11 #include <iostream>
12
13 class X {
14 int *a;
15 int sz;
16 public:
17 class range { }; // exception class
18 X(int s) { a=new int[sz=s]; }
19 int& operator[](int i);
20 };
21
22 int& X::operator[](int i)
23 {
24 if (i < 0 || i >= sz) {
25 throw range();
26 }
27 return a[i];
28 }
29
30 int
31 main()
32 {
33 X c(10);
34 try {
35 for (int i = 0; i < 12; i++)
36 c[i] = 1;
37 } catch (X::range) {
38 std::cerr << "invalid range\n";
39 }
40 return 0;
41 }