From 53e926c8cd54a9f1b5817c8e4b50c87aacce432b Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Thu, 14 Jun 2018 21:27:04 +0100 Subject: [PATCH] LWG 3075 basic_string needs deduction guides from basic_string_view * testsuite/21_strings/basic_string/cons/char/deduction.cc: Test deduction from string views. * testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc: Likewise. From-SVN: r261612 --- libstdc++-v3/ChangeLog | 6 ++++++ libstdc++-v3/include/bits/basic_string.h | 17 ++++++++++++++++ .../basic_string/cons/char/deduction.cc | 20 +++++++++++++++++++ .../basic_string/cons/wchar_t/deduction.cc | 20 +++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6db36225c1f..e368044232f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,11 @@ 2018-06-14 Jonathan Wakely + LWG 3075 basic_string needs deduction guides from basic_string_view + * testsuite/21_strings/basic_string/cons/char/deduction.cc: Test + deduction from string views. + * testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc: + Likewise. + LWG 3074 make scalar types non-deduced in valarray non-member functions * include/bits/valarray_after.h (_DEFINE_EXPR_BINARY_FUNCTION): Change scalar parameters to be a non-deduced context. diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 5bffa1c72a1..fbac38ae973 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -5873,6 +5873,23 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 typename = _RequireAllocator<_Allocator>> basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator()) -> basic_string<_CharT, char_traits<_CharT>, _Allocator>; + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3075. basic_string needs deduction guides from basic_string_view + template, + typename = _RequireAllocator<_Allocator>> + basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator()) + -> basic_string<_CharT, _Traits, _Allocator>; + + template, + typename = _RequireAllocator<_Allocator>> + basic_string(basic_string_view<_CharT, _Traits>, + typename basic_string<_CharT, _Traits, _Allocator>::size_type, + typename basic_string<_CharT, _Traits, _Allocator>::size_type, + const _Allocator& = _Allocator()) + -> basic_string<_CharT, _Traits, _Allocator>; _GLIBCXX_END_NAMESPACE_CXX11 #endif diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/deduction.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/deduction.cc index f7dee1e6141..cf6857c6678 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/deduction.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/deduction.cc @@ -118,3 +118,23 @@ test04() std::basic_string s4((char32_t)1, U'a', std::allocator()); check_type(s4); } + +void +test05() +{ + // LWG 3075 basic_string needs deduction guides from basic_string_view + std::string_view sv{"A View to a Kill"}; + const std::allocator a; + + std::basic_string s1(sv); + check_type(s1); + + std::basic_string s2(sv, a); + check_type(s2); + + std::basic_string s3(sv, 2u, 6u); + check_type(s3); + + std::basic_string s4(sv, 2u, 6u, a); + check_type(s4); +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc index 7fe367b56dd..ea312ff653e 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc @@ -77,3 +77,23 @@ test02() std::basic_string s4((wchar_t)1, L'a', std::allocator()); check_type(s4); } + +void +test05() +{ + // LWG 3075 basic_string needs deduction guides from basic_string_view + std::wstring_view sv{L"A View to a Kill"}; + const std::allocator a; + + std::basic_string s1(sv); + check_type(s1); + + std::basic_string s2(sv, a); + check_type(s2); + + std::basic_string s3(sv, 2u, 6u); + check_type(s3); + + std::basic_string s4(sv, 2u, 6u, a); + check_type(s4); +} -- 2.30.2