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