]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/21_strings/basic_string/modifiers/append/wchar_t/4.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / modifiers / append / wchar_t / 4.cc
CommitLineData
6458742a 1// { dg-do run { target c++17 } }
ca8f2cb1 2
a945c346 3// Copyright (C) 2016-2024 Free Software Foundation, Inc.
ca8f2cb1
VV
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// [string.modifiers]
21
22#include <string>
23#include <testsuite_hooks.h>
24
25void
26test03()
27{
ca8f2cb1
VV
28 std::wstring_view str1(L"foo");
29 std::wstring str2;
30 str2 += str1;
31 VERIFY (str2 == str1);
32 std::wstring str3;
33 str3.append(str1);
34 VERIFY (str3 == str1);
35 std::wstring str4;
36 str4.append(str1, 1, 2);
37 VERIFY (str4 == L"oo");
38}
39
657213f7
JW
40// PR libstdc++/77264
41void
42test04()
43{
657213f7
JW
44 std::wstring str(L"a");
45
46 wchar_t c = L'b';
47 str.append(&c, 1);
48 VERIFY (str[1] == c);
49
50 wchar_t arr[] = L"c";
51 str.append(arr, 1);
52 VERIFY (str[2] == arr[0]);
53
54 const wchar_t carr[] = L"d";
55 str.append(carr, 1);
56 VERIFY (str[3] == carr[0]);
57
58 struct S {
59 operator wchar_t*() { return &c; }
60 operator std::wstring_view() { return L"!"; }
61 wchar_t c = L'e';
62 };
63
64 str.append(S{}, 1);
65 VERIFY (str[4] == S{}.c);
66}
67
ca8f2cb1
VV
68int main()
69{
70 test03();
657213f7 71 test04();
ca8f2cb1
VV
72 return 0;
73}