]>
Commit | Line | Data |
---|---|---|
83ffe9cd | 1 | // Copyright (C) 2017-2023 Free Software Foundation, Inc. |
02e12bda JW |
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 3, 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 COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
18 | // { dg-do run { target c++11 } } | |
19 | ||
20 | #include <locale> | |
21 | #include <codecvt> | |
22 | #include <testsuite_hooks.h> | |
23 | ||
24 | // PR libstdc++/79511 | |
25 | ||
26 | template<typename ElemT> | |
27 | std::basic_string<ElemT> conv(const char* src) | |
28 | { | |
29 | std::wstring_convert<std::codecvt_utf8_utf16<ElemT>, ElemT> conv; | |
30 | return conv.from_bytes(src); | |
31 | } | |
32 | ||
33 | void | |
34 | test01() | |
35 | { | |
36 | static char const src[] = "\xEF\xBF\xBF"; | |
37 | VERIFY( conv<char16_t>(src) == u"\xffff" ); | |
38 | VERIFY( conv<char32_t>(src) == U"\xffff" ); | |
39 | #ifdef _GLIBCXX_USE_WCHAR_T | |
40 | VERIFY( conv<wchar_t>(src) == L"\xffff" ); | |
41 | #endif | |
42 | } | |
43 | ||
44 | void | |
45 | test02() | |
46 | { | |
47 | static char const src[] = "\xE2\x82\xAC"; | |
48 | VERIFY( conv<char16_t>(src) == u"\x20ac" ); | |
49 | VERIFY( conv<char32_t>(src) == U"\x20ac" ); | |
50 | #ifdef _GLIBCXX_USE_WCHAR_T | |
51 | VERIFY( conv<wchar_t>(src) == L"\x20ac" ); | |
52 | #endif | |
53 | } | |
54 | ||
55 | int | |
56 | main() | |
57 | { | |
58 | test01(); | |
59 | test02(); | |
60 | } |