]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/12206.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_filebuf / imbue / 12206.cc
1 // Copyright (C) 2003-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 // 27.8.1.4 Overridden virtual functions
19
20 #include <fstream>
21
22 typedef unsigned char Char;
23
24 namespace std
25 {
26 template <>
27 class codecvt<Char, char, mbstate_t> :
28 public locale::facet, public codecvt_base
29 {
30 public:
31 typedef Char intern_type;
32 typedef char extern_type;
33 typedef mbstate_t state_type;
34
35 explicit codecvt(size_t refs = 0)
36 : locale::facet(refs) { }
37 result out(mbstate_t& state, const Char* from,
38 const Char* from_end, const Char*& from_next,
39 char* to, char* to_limit, char*& to_next) const
40 {
41 return do_out(state, from, from_end, from_next,
42 to, to_limit, to_next);
43 }
44 result in(mbstate_t& state, const char* from,
45 const char* from_end, const char*& from_next,
46 Char* to, Char* to_limit, Char*& to_next) const
47 {
48 return do_in(state, from, from_end, from_next,
49 to, to_limit, to_next);
50 }
51 result unshift(mbstate_t& state, char* to, char* to_end,
52 char*& to_next) const
53 { return do_unshift(state, to, to_end, to_next); }
54 int length(mbstate_t& state, const char* from,
55 const char* from_end, size_t max) const
56 { return do_length(state, from, from_end, max); }
57 int encoding() const throw()
58 { return do_encoding(); }
59 bool always_noconv() const throw()
60 { return do_always_noconv(); }
61 int max_length() const throw()
62 { return do_max_length(); }
63
64 static locale::id id;
65
66 protected:
67 virtual result do_out(mbstate_t&, const Char*,
68 const Char*,
69 const Char*&, char*,
70 char*, char*&) const
71 { return ok; }
72 virtual result do_in(mbstate_t&, const char*,
73 const char*,
74 const char*&, Char*,
75 Char*, Char*&) const
76 { return ok; }
77 virtual result do_unshift(mbstate_t&, char*, char*,
78 char*&) const
79 { return noconv; }
80 virtual int do_length(mbstate_t&, const char*,
81 const char*, size_t) const
82 { return 1; }
83 virtual int do_encoding() const throw()
84 { return 1; }
85 virtual bool do_always_noconv() const throw()
86 { return false; }
87 virtual int do_max_length() const throw()
88 { return 1; }
89 };
90
91 locale::id codecvt<Char, char, mbstate_t>::id;
92 }
93
94 // libstdc++/12206
95 void test01()
96 {
97 using namespace std;
98
99 locale loc(locale::classic(),
100 new codecvt<Char, char, std::mbstate_t>);
101 locale::global(loc);
102
103 basic_filebuf<Char, char_traits<Char> > fb;
104
105 loc = locale::classic();
106 locale::global(loc);
107 fb.pubimbue(loc);
108
109 fb.open("tmp_12206", ios_base::out);
110 try
111 {
112 fb.pubseekoff(0, ios_base::cur);
113 }
114 catch (std::exception&)
115 {
116 }
117 fb.close();
118 }
119
120 int main()
121 {
122 test01();
123 return 0;
124 }