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