Debian Codegraph @

libstdc++-v3/testsuite/21_strings/basic_string/modifiers/assign/wchar_t/4.cc

raw
1 // { dg-do run { target c++17 } }
2
3 // Copyright (C) 2016-2025 Free Software Foundation, Inc.
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
25 void
26 test03()
27 {
28 std::wstring_view str1(L"foo");
29 std::wstring str2;
30 str2.assign(str1);
31 VERIFY (str2 == str1);
32 std::wstring str4;
33 str4.assign(str1, 1, 2);
34 VERIFY (str4 == L"oo");
35 }
36
37 // PR libstdc++/77264
38 void
39 test04()
40 {
41 std::wstring str(L"a");
42
43 wchar_t c = L'b';
44 str.assign(&c, 1);
45 VERIFY (str[0] == c);
46
47 wchar_t arr[] = L"c";
48 str.assign(arr, 1);
49 VERIFY (str[0] == arr[0]);
50
51 const wchar_t carr[] = L"d";
52 str.assign(carr, 1);
53 VERIFY (str[0] == carr[0]);
54
55 struct S {
56 operator wchar_t*() { return &c; }
57 operator std::wstring_view() { return L"!"; }
58 wchar_t c = L'e';
59 };
60
61 str.assign(S{}, 1);
62 VERIFY (str[0] == S{}.c);
63 }
64
65 int main()
66 {
67 test03();
68 test04();
69 return 0;
70 }