Merge from mainline
[official-gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_filebuf / imbue / 12206.cc
blob721e0333840c18d108dadccfe139b5b8639cb08b
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.
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 COPYING. If not, write to the Free
16 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17 // USA.
19 // 27.8.1.4 Overridden virtual functions
21 #include <fstream>
23 typedef unsigned char Char;
25 namespace std
27 template <>
28 class codecvt<Char, char, mbstate_t> :
29 public locale::facet, public codecvt_base
31 public:
32 typedef Char intern_type;
33 typedef char extern_type;
34 typedef mbstate_t state_type;
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
42 return do_out(state, from, from_end, from_next,
43 to, to_limit, to_next);
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
49 return do_in(state, from, from_end, from_next,
50 to, to_limit, to_next);
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(); }
65 static locale::id id;
67 protected:
68 virtual result do_out(mbstate_t&, const Char*,
69 const Char*,
70 const Char*&, char*,
71 char*, char*&) const
72 { return ok; }
73 virtual result do_in(mbstate_t&, const char*,
74 const char*,
75 const char*&, Char*,
76 Char*, Char*&) const
77 { return ok; }
78 virtual result do_unshift(mbstate_t&, char*, char*,
79 char*&) const
80 { return noconv; }
81 virtual int do_length(mbstate_t&, const char*,
82 const char*, size_t) 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; }
92 locale::id codecvt<Char, char, mbstate_t>::id;
95 // libstdc++/12206
96 void test01()
98 using namespace std;
99 bool test __attribute__((unused)) = true;
101 locale loc(locale::classic(),
102 new codecvt<Char, char, std::mbstate_t>);
103 locale::global(loc);
105 basic_filebuf<Char, char_traits<Char> > fb;
107 loc = locale::classic();
108 locale::global(loc);
109 fb.pubimbue(loc);
111 fb.open("tmp_12206", ios_base::out);
114 fb.pubseekoff(0, ios_base::cur);
116 catch (std::exception&)
119 fb.close();
122 int main()
124 test01();
125 return 0;