summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.law/except5.C
blob: a99ad8a4833ed749bad5729ce20c09151d80432f (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
40
// { dg-do assemble  }
// { dg-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 <iostream>

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) {
                std::cerr << "invalid range\n";
        }
        return 0;
}