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