]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/ctype.cc
collate.cc: Compile-only.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / ctype.cc
1 // 1999-08-24 bkoz
2
3 // Copyright (C) 2000, 1999 Free Software Foundation
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
20
21 // 22.2.1 The ctype category
22
23 // { dg-do compile }
24
25 // 1: Test that the locale headers are picking up the correct declaration
26 // of the internal type `ctype_base::mask'.
27 int mask ();
28
29 #include <locale>
30
31 // 2: Should be able to instantiate this for other types besides char, wchar_t
32 typedef std::ctype<char> cctype;
33
34 class gnu_ctype: public std::ctype<unsigned char>
35 {
36 private:
37 const cctype& _M_cctype;
38
39 public:
40 explicit
41 gnu_ctype(size_t __refs = 0)
42 : std::ctype<unsigned char>(__refs),
43 _M_cctype(std::use_facet<cctype>(std::locale::classic()))
44 { }
45
46 ~gnu_ctype();
47
48 protected:
49 virtual bool
50 do_is(mask __m, char_type __c) const
51 { return _M_cctype.is(__m, __c); }
52
53 virtual const char_type*
54 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const
55 {
56 const char* __c = _M_cctype.is(reinterpret_cast<const char*>(__lo),
57 reinterpret_cast<const char*>(__hi), __vec);
58 return reinterpret_cast<const char_type*>(__c);
59 }
60
61 virtual const char_type*
62 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const
63 {
64 const char* __c = _M_cctype.scan_is(__m,
65 reinterpret_cast<const char*>(__lo),
66 reinterpret_cast<const char*>(__hi));
67 return reinterpret_cast<const char_type*>(__c);
68 }
69
70 virtual const char_type*
71 do_scan_not(mask __m, const char_type* __lo, const char_type* __hi) const
72 {
73 const char* __c = _M_cctype.scan_is(__m,
74 reinterpret_cast<const char*>(__lo),
75 reinterpret_cast<const char*>(__hi));
76 return reinterpret_cast<const char_type*>(__c);
77 }
78
79 virtual char_type
80 do_toupper(char_type __c) const
81 { return _M_cctype.toupper(__c); }
82
83 virtual const char_type*
84 do_toupper(char_type* __lo, const char_type* __hi) const
85 {
86 const char* __c = _M_cctype.toupper(reinterpret_cast<char*>(__lo),
87 reinterpret_cast<const char*>(__hi));
88 return reinterpret_cast<const char_type*>(__c);
89 }
90
91 virtual char_type
92 do_tolower(char_type __c) const
93 { return _M_cctype.tolower(__c); }
94
95 virtual const char_type*
96 do_tolower(char_type* __lo, const char_type* __hi) const
97 {
98 const char* __c = _M_cctype.toupper(reinterpret_cast<char*>(__lo),
99 reinterpret_cast<const char*>(__hi));
100 return reinterpret_cast<const char_type*>(__c);
101 }
102
103 virtual char_type
104 do_widen(char __c) const
105 { return _M_cctype.widen(__c); }
106
107 virtual const char*
108 do_widen(const char* __lo, const char* __hi, char_type* __dest) const
109 {
110 const char* __c = _M_cctype.widen(reinterpret_cast<const char*>(__lo),
111 reinterpret_cast<const char*>(__hi),
112 reinterpret_cast<char*>(__dest));
113 return __c;
114 }
115
116 virtual char
117 do_narrow(char_type __c, char __dfault) const
118 { return _M_cctype.narrow(__c, __dfault); }
119
120 virtual const char_type*
121 do_narrow(const char_type* __lo, const char_type* __hi, char __dfault,
122 char* __dest) const
123 {
124 const char* __c = _M_cctype.narrow(reinterpret_cast<const char*>(__lo),
125 reinterpret_cast<const char*>(__hi),
126 __dfault,
127 reinterpret_cast<char*>(__dest));
128 return reinterpret_cast<const char_type*>(__c);
129 }
130
131 };
132
133 gnu_ctype::~gnu_ctype() { }
134
135 gnu_ctype facet01;
136
137 // 3: Sanity check ctype_base::mask bitmask requirements
138 void
139 test01()
140 {
141 using namespace std;
142
143 ctype_base::mask m01;
144 ctype_base::mask m02;
145
146 m01 = ctype_base::space;
147 m02 = ctype_base::xdigit;
148
149 m01 & m02;
150 m01 | m02;
151 m01 ^ m02;
152 ~m01;
153 m01 &= m02;
154 m01 |= m02;
155 m01 ^= m02;
156 }
157
158 class gnu_obj
159 { };
160
161 class gnu_ctype2: public std::ctype<gnu_obj>
162 { };
163
164 // libstdc++/3017
165 void test02()
166 {
167 gnu_ctype2 obj;
168 }
169
170 int main()
171 {
172 test01();
173 test02();
174 return 0;
175 }