aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.law/except5.C
blob: 623d0d8587f42cb7eb4be3a42bd768fb639c1733 (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
// Build don't link: 
// Special g++ Options: -fexceptions
// GROUPS passed exceptions
// except file
// Message-Id: <199311101607.AA11803@hsi86.hsi.com>
// From: Grigory Tsipenyuk <grigory@hsi.com>
// Subject: exception's bug?
// Date: Wed, 10 Nov 1993 11:07:12 -0500

#include <stream.h>
class X {
        int     *a;
        int     sz;
public:
        class range { }; // exception class
        X(int s)        { a=new int[sz=s]; }
        int& operator[](int i);
};

int& X::operator[](int i)
{
        if (i < 0 || i >= sz) {
                throw range();
        }
        return a[i];
}

int
main()
{
        X       c(10);
        try {
                for (int i = 0; i < 12; i++)
                        c[i] = 1;
        } catch (X::range) {
                cerr << "invalid range\n";
        }
        return 0;
}