]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc
1 // Copyright (C) 2017-2020 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-options "-std=gnu++17" }
19 // { dg-do compile { target c++17 } }
20 // { dg-xfail-if "COW string missing deduction guides" { ! cxx11-abi } }
23 #include <testsuite_iterators.h>
25 template<typename T
, typename U
> struct require_same
;
26 template<typename T
> struct require_same
<T
, T
> { using type
= void; };
28 template<typename T
, typename U
>
29 typename require_same
<T
, U
>::type
36 std::allocator
<wchar_t> a
;
38 std::basic_string s1
= s0
;
39 check_type
<std::wstring
>(s1
);
41 std::basic_string s2
= std::move(s0
);
42 check_type
<std::wstring
>(s2
);
44 const std::basic_string s3
= s0
;
45 check_type
<const std::wstring
>(s3
);
47 const std::basic_string s4
= s2
;
48 check_type
<const std::wstring
>(s4
);
50 #if _GLIBCXX_USE_CXX11_ABI
51 std::basic_string
s5(s0
, a
);
52 check_type
<std::wstring
>(s5
);
54 std::basic_string
s6(std::move(s0
), a
);
55 check_type
<std::wstring
>(s6
);
58 std::basic_string
s7(s0
, 0, 0);
59 check_type
<std::wstring
>(s7
);
65 using namespace __gnu_test
;
67 test_container
<wchar_t, input_iterator_wrapper
> seq(a
);
69 std::basic_string
s1(seq
.begin(), seq
.end());
70 check_type
<std::wstring
>(s1
);
72 std::basic_string
s2(seq
.begin(), seq
.end(), std::allocator
<wchar_t>());
73 check_type
<std::wstring
>(s2
);
75 std::basic_string
s3((wchar_t)1, L
'a');
76 check_type
<std::wstring
>(s3
);
78 std::basic_string
s4((wchar_t)1, L
'a', std::allocator
<wchar_t>());
79 check_type
<std::wstring
>(s4
);
85 // LWG 3075 basic_string needs deduction guides from basic_string_view
86 std::wstring_view sv
{L
"A View to a Kill"};
87 const std::allocator
<wchar_t> a
;
89 std::basic_string
s1(sv
);
90 check_type
<std::wstring
>(s1
);
92 std::basic_string
s2(sv
, a
);
93 check_type
<std::wstring
>(s2
);
95 std::basic_string
s3(sv
, 2u, 6u);
96 check_type
<std::wstring
>(s3
);
98 std::basic_string
s4(sv
, 2u, 6u, a
);
99 check_type
<std::wstring
>(s4
);
105 // LWG 3076 basic_string CTAD ambiguity
109 basic_string
s1(s0
, 1, 1);
110 check_type
<std::wstring
>(s1
);
112 basic_string
s2(L
"cat"sv
, 1, 1);
113 check_type
<std::wstring
>(s2
);
115 basic_string
s3(L
"cat", 1);
116 check_type
<std::wstring
>(s3
);