]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/22_locale/conversions/string/3.cc
Fix warnings occured during profiledboostrap on
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / conversions / string / 3.cc
CommitLineData
b6584a72
JW
1// { dg-options "-std=gnu++11" }
2
3// Copyright (C) 2012 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 3, 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 COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
19
20// 22.3.3.2.2 String conversions
21
22#include <locale>
23#include <string>
24#include <testsuite_hooks.h>
25
26template<typename Elem>
27struct cvt : std::codecvt<Elem, char, std::mbstate_t> { };
28
29template<typename Elem>
30using str_conv = std::wstring_convert<cvt<Elem>, Elem>;
31
32using std::string;
33using std::u32string;
34
35// test construction with state, for partial conversions
36
37void test01()
38{
39 typedef str_conv<char32_t> wsc;
40
41 wsc c;
42 string input = u8"\u00a3 shillings pence";
43 u32string woutput = c.from_bytes(input.substr(0, 1));
44 auto partial_state = c.state();
45 auto partial_count = c.converted();
46
47 auto woutput2 = c.from_bytes("state reset on next conversion");
48 VERIFY( woutput2 == U"state reset on next conversion" );
49
50 wsc c2(new cvt<char32_t>, partial_state);
51 woutput += c2.from_bytes(input.substr(partial_count));
52 VERIFY( U"\u00a3 shillings pence" == woutput );
53
54 string roundtrip = c2.to_bytes(woutput);
55 VERIFY( input == roundtrip );
56}
57
58int main()
59{
60 test01();
61}