OSDN Git Service

2003-09-23 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 27_io / basic_istream / exceptions / char / 9561.cc
1 // 2003-03-08  Jerry Quinn  <jlquinn@optonline.net>
2
3 // Copyright (C) 2003 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING.  If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
20
21 #include <istream>
22 #include <streambuf>
23 #include <testsuite_hooks.h>
24
25 // libstdc++/9561
26 struct foobar: std::exception { };
27
28 struct buf: std::streambuf
29 {
30     virtual int_type underflow () {
31         throw foobar ();
32         return -1;
33     }
34     virtual int_type uflow () {
35         throw foobar ();
36         return -1;
37     }
38 };
39
40 void test01()
41 {
42   using namespace std;
43   bool test __attribute__((unused)) = true;
44
45   buf b;
46   std::istream strm (&b);
47   strm.exceptions (std::ios::badbit);
48   int i = 0;
49
50   try {
51     i = strm.get();
52   }
53   catch (foobar) {
54     // strm should throw foobar and not do anything else
55     VERIFY(strm.bad());
56   }
57   catch (...) {
58     VERIFY(false);
59   }
60
61   VERIFY(i == 0);
62 }
63
64
65 int main()
66 {
67   test01();
68   return 0;
69 }