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