summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/12206.cc
blob: 4c6bebf1f046eef3ce8a7b8e9c5b60c6e16e269a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright (C) 2003, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

// 27.8.1.4 Overridden virtual functions

#include <fstream>

typedef unsigned char Char;

namespace std
{
  template <>
  class codecvt<Char, char, mbstate_t> :
    public locale::facet, public codecvt_base
  {
  public:
    typedef Char intern_type;
    typedef char extern_type;
    typedef mbstate_t state_type;
    
    explicit codecvt(size_t refs = 0)
      : locale::facet(refs) { }
    result out(mbstate_t& state, const Char* from,
	       const Char* from_end, const Char*& from_next,
	       char* to, char* to_limit, char*& to_next) const
    {
      return do_out(state, from, from_end, from_next,
		    to, to_limit, to_next);
    }
    result in(mbstate_t& state, const char* from,
	      const char* from_end, const char*& from_next,
	      Char* to, Char* to_limit, Char*& to_next) const
    {
      return do_in(state, from, from_end, from_next,
		   to, to_limit, to_next);
    }
    result unshift(mbstate_t& state, char* to, char* to_end,
		   char*& to_next) const
    { return do_unshift(state, to, to_end, to_next); }
    int length(mbstate_t& state, const char* from,
	       const char* from_end, size_t max) const
    { return do_length(state, from, from_end, max); }
    int encoding() const throw()
    { return do_encoding(); }
    bool always_noconv() const throw()
    { return do_always_noconv(); }
    int max_length() const throw()
    { return do_max_length(); }
    
    static locale::id id;
    
  protected:
    virtual result do_out(mbstate_t&, const Char*,
			  const Char*,
			  const Char*&, char*,
			  char*, char*&) const
    { return ok; }
    virtual result do_in(mbstate_t&, const char*,
			 const char*,
			 const char*&, Char*,
			 Char*, Char*&) const
    { return ok; }
    virtual result do_unshift(mbstate_t&, char*, char*,
			      char*&) const
    { return noconv; }
    virtual int do_length(mbstate_t&, const char*,
			  const char*, size_t) const
    { return 1; }
    virtual int do_encoding() const throw()
    { return 1; }
    virtual bool do_always_noconv() const throw()
    { return false; }
    virtual int do_max_length() const throw()
    { return 1; }
  };
  
  locale::id codecvt<Char, char, mbstate_t>::id;
}

// libstdc++/12206
void test01()
{
  using namespace std;
  bool test __attribute__((unused)) = true;
  
  locale loc(locale::classic(),
	     new codecvt<Char, char, std::mbstate_t>);
  locale::global(loc);
  
  basic_filebuf<Char, char_traits<Char> > fb;

  loc = locale::classic();
  locale::global(loc);
  fb.pubimbue(loc);

  fb.open("tmp_12206", ios_base::out);
  try
    {
      fb.pubseekoff(0, ios_base::cur);
    }
  catch (std::exception&)
    {
    }
  fb.close();
}

int main()
{
  test01();
  return 0;
}