]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/81256.cc
1 // Copyright (C) 2018-2022 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-do run { target c++11 } }
22 #include <testsuite_hooks.h>
24 struct E
: std::runtime_error
26 E() : runtime_error("") { }
29 struct Cvt
: std::codecvt
<wchar_t, char, std::mbstate_t>
31 explicit Cvt(size_t refs
) : codecvt(refs
) { }
33 mutable int exceptions_thrown
= 0;
37 do_encoding() const noexcept override
41 do_always_noconv() const noexcept override
45 do_unshift(state_type
&, char*, char*, char*&) const override
52 struct filebuf
: std::basic_filebuf
<wchar_t>
54 explicit filebuf(Cvt
* c
)
56 std::locale
loc(std::locale::classic(), c
);
64 // This facet needs to still be valid when ~basic_filebuf runs:
68 fb
.open("output.txt", std::wios::out
);
74 /* [filebuf.members] p7: If one of these calls throws an exception,
75 * the exception is caught and rethrown after closing the file. */
82 VERIFY( conv
.exceptions_thrown
== 1 );
85 VERIFY( conv
.exceptions_thrown
== 1 );
91 // This facet needs to still be valid when ~basic_filebuf runs:
95 fb
.open("output.txt", std::wios::out
);
97 /* [filebuf.cons] p5: If an exception occurs during the destruction
98 * of the object, including the call to close(), the exception is
99 * caught but not rethrown. */
101 VERIFY( conv
.exceptions_thrown
== 1 );