| 1 |
// Copyright (C) 2017-2025 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 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 |
// { dg-additional-options "-Wno-deprecated-declarations" { target c++17 } } |
| 20 |
|
| 21 |
#include <locale> |
| 22 |
#include <codecvt> |
| 23 |
#include <testsuite_hooks.h> |
| 24 |
|
| 25 |
// PR libstdc++/79511 |
| 26 |
|
| 27 |
template<typename ElemT> |
| 28 |
std::basic_string<ElemT> conv(const char* src) |
| 29 |
{ |
| 30 |
std::wstring_convert<std::codecvt_utf8_utf16<ElemT>, ElemT> conv; |
| 31 |
return conv.from_bytes(src); |
| 32 |
} |
| 33 |
|
| 34 |
void |
| 35 |
test01() |
| 36 |
{ |
| 37 |
static char const src[] = "\xEF\xBF\xBF"; |
| 38 |
VERIFY( conv<char16_t>(src) == u"\xffff" ); |
| 39 |
VERIFY( conv<char32_t>(src) == U"\xffff" ); |
| 40 |
#ifdef _GLIBCXX_USE_WCHAR_T |
| 41 |
VERIFY( conv<wchar_t>(src) == L"\xffff" ); |
| 42 |
#endif |
| 43 |
} |
| 44 |
|
| 45 |
void |
| 46 |
test02() |
| 47 |
{ |
| 48 |
static char const src[] = "\xE2\x82\xAC"; |
| 49 |
VERIFY( conv<char16_t>(src) == u"\x20ac" ); |
| 50 |
VERIFY( conv<char32_t>(src) == U"\x20ac" ); |
| 51 |
#ifdef _GLIBCXX_USE_WCHAR_T |
| 52 |
VERIFY( conv<wchar_t>(src) == L"\x20ac" ); |
| 53 |
#endif |
| 54 |
} |
| 55 |
|
| 56 |
int |
| 57 |
main() |
| 58 |
{ |
| 59 |
test01(); |
| 60 |
test02(); |
| 61 |
} |