]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_ostream/exceptions/wchar_t/9561.cc
99cd6ee4b468d59f6abc21dfdcc0a5840f80dc43
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_ostream / exceptions / wchar_t / 9561.cc
1 // Copyright (C) 2005-2020 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 #include <ostream>
19 #include <streambuf>
20 #include <testsuite_hooks.h>
21
22 // libstdc++/9561
23 struct foobar: std::exception { };
24
25 struct buf: std::wstreambuf
26 {
27 virtual int_type
28 overflow(int_type)
29 {
30 throw foobar();
31 return int_type();
32 }
33 };
34
35 void test01()
36 {
37 using namespace std;
38
39 buf b;
40 std::wostream strm(&b);
41 strm.exceptions(std::wios::badbit);
42
43 try
44 {
45 strm << std::endl;
46 }
47 catch(foobar)
48 {
49 // strm should throw foobar and not do anything else
50 VERIFY(strm.bad());
51 return;
52 }
53 catch(...)
54 {
55 VERIFY( false );
56 return;
57 }
58 VERIFY( false );
59 }
60
61 int main()
62 {
63 test01();
64 return 0;
65 }