Index: include/string =================================================================== --- include/string +++ include/string @@ -775,30 +775,30 @@ _LIBCPP_INLINE_VISIBILITY basic_string(basic_string&& __str, const allocator_type& __a); #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s); + _LIBCPP_INLINE_VISIBILITY basic_string(const _CharT* __s); _LIBCPP_INLINE_VISIBILITY - basic_string(const value_type* __s, const allocator_type& __a); + basic_string(const _CharT* __s, const _Allocator& __a); _LIBCPP_INLINE_VISIBILITY - basic_string(const value_type* __s, size_type __n); + basic_string(const _CharT* __s, size_type __n); _LIBCPP_INLINE_VISIBILITY - basic_string(const value_type* __s, size_type __n, const allocator_type& __a); + basic_string(const _CharT* __s, size_type __n, const _Allocator& __a); _LIBCPP_INLINE_VISIBILITY - basic_string(size_type __n, value_type __c); + basic_string(size_type __n, _CharT __c); _LIBCPP_INLINE_VISIBILITY - basic_string(size_type __n, value_type __c, const allocator_type& __a); + basic_string(size_type __n, _CharT __c, const _Allocator& __a); basic_string(const basic_string& __str, size_type __pos, size_type __n, - const allocator_type& __a = allocator_type()); + const _Allocator& __a = _Allocator()); _LIBCPP_INLINE_VISIBILITY basic_string(const basic_string& __str, size_type __pos, - const allocator_type& __a = allocator_type()); + const _Allocator& __a = _Allocator()); template - basic_string(const _Tp& __t, size_type __pos, size_type __n, + basic_string(const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a = allocator_type(), typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type* = 0); _LIBCPP_INLINE_VISIBILITY explicit basic_string(__self_view __sv); _LIBCPP_INLINE_VISIBILITY - basic_string(__self_view __sv, const allocator_type& __a); + basic_string(__self_view __sv, const _Allocator& __a); template _LIBCPP_INLINE_VISIBILITY basic_string(_InputIterator __first, _InputIterator __last); @@ -807,9 +807,9 @@ basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a); #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS _LIBCPP_INLINE_VISIBILITY - basic_string(initializer_list __il); + basic_string(initializer_list<_CharT> __il); _LIBCPP_INLINE_VISIBILITY - basic_string(initializer_list __il, const allocator_type& __a); + basic_string(initializer_list<_CharT> __il, const _Allocator& __a); #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS inline ~basic_string(); @@ -1557,7 +1557,7 @@ template inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s) +basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s) { _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr"); __init(__s, traits_type::length(__s)); @@ -1568,7 +1568,7 @@ template inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a) +basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a) : __r_(__a) { _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); @@ -1580,7 +1580,7 @@ template inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n) +basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n) { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); __init(__s, __n); @@ -1591,7 +1591,7 @@ template inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a) +basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a) : __r_(__a) { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr"); @@ -1615,7 +1615,8 @@ } template -basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a) +basic_string<_CharT, _Traits, _Allocator>::basic_string( + const basic_string& __str, const allocator_type& __a) : __r_(__a) { if (!__str.__is_long()) @@ -1694,7 +1695,7 @@ template inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c) +basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c) { __init(__n, __c); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1704,7 +1705,7 @@ template inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a) +basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a) : __r_(__a) { __init(__n, __c); @@ -1714,8 +1715,9 @@ } template -basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n, - const allocator_type& __a) +basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, + size_type __pos, size_type __n, + const _Allocator& __a) : __r_(__a) { size_type __str_sz = __str.size(); @@ -1730,7 +1732,7 @@ template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, - const allocator_type& __a) + const _Allocator& __a) : __r_(__a) { size_type __str_sz = __str.size(); @@ -1753,7 +1755,7 @@ __init(__sv.data(), __sv.size()); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); -#endif +#endif } template @@ -1768,7 +1770,7 @@ template inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv, const allocator_type& __a) +basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv, const _Allocator& __a) : __r_(__a) { __init(__sv.data(), __sv.size()); @@ -1863,7 +1865,8 @@ template inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list __il) +basic_string<_CharT, _Traits, _Allocator>::basic_string( + initializer_list<_CharT> __il) { __init(__il.begin(), __il.end()); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1873,7 +1876,9 @@ template inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list __il, const allocator_type& __a) +basic_string<_CharT, _Traits, _Allocator>::basic_string( + initializer_list<_CharT> __il, const _Allocator& __a) + : __r_(__a) { __init(__il.begin(), __il.end()); Index: test/std/strings/basic.string/string.cons/implicit_deduction_guides.pass.cpp =================================================================== --- /dev/null +++ test/std/strings/basic.string/string.cons/implicit_deduction_guides.pass.cpp @@ -0,0 +1,300 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// UNSUPPORTED: libcpp-no-deduction-guides + +// + +// Test that the constructors offered by std::basic_string are formulated +// so they're compatible with implicit deduction guides. + +#include +#include +#include + +#include "test_macros.h" +#include "test_allocator.h" +#include "test_iterators.h" +#include "constexpr_char_traits.hpp" + +template > +using BStr = std::basic_string, Alloc>; + +// Overloads +// using A = Allocator; +// using BS = basic_string +// using BSV = basic_string_view +// --------------- +// (1) basic_string() - NOT TESTED +// (2) basic_string(A const&) - BROKEN +// (3) basic_string(size_type, CharT, const A& = A()) +// (4) basic_string(BS const&, size_type, A const& = A()) +// (5) basic_string(BS const&, size_type, size_type, A const& = A()) - PARTIALLY BROKEN +// (6) basic_string(const CharT*, size_type, A const& = A()) +// (7) basic_string(const CharT*, A const& = A()) +// (8) basic_string(InputIt, InputIt, A const& = A()) - BROKEN +// (9) basic_string(BS const&) +// (10) basic_string(BS const&, A const&) +// (11) basic_string(BS&&) +// (12) basic_string(BS&&, A const&) +// (13) basic_string(initializer_list, A const& = A()) +// (14) basic_string(BSV, A const& = A()) +// (15) basic_string(const T&, size_type, size_type, A const& = A()) - BROKEN +int main() +{ + using TestSizeT = test_allocator::size_type; + { // Testing (1) + // Nothing TODO. Cannot deduce without any arguments. + } + { // Testing (2) + // This overload isn't compatible with implicit deduction guides as + // specified in the standard. + // const test_allocator alloc{}; + // std::basic_string s(alloc); + } + { // Testing (3) w/o allocator + std::basic_string s(6ull, 'a'); + ASSERT_SAME_TYPE(decltype(s), std::string); + assert(s == "aaaaaa"); + + std::basic_string w(2ull, L'b'); + ASSERT_SAME_TYPE(decltype(w), std::wstring); + assert(w == L"bb"); + } + { // Testing (3) w/ allocator + std::basic_string s(6ull, 'a', test_allocator{}); + ASSERT_SAME_TYPE(decltype(s), BStr>); + assert(s == "aaaaaa"); + + std::basic_string w(2ull, L'b', test_allocator{}); + ASSERT_SAME_TYPE(decltype(w), BStr>); + assert(w == L"bb"); + } + { // Testing (4) w/o allocator + const std::string sin("abc"); + std::basic_string s(sin, (size_t)1); + ASSERT_SAME_TYPE(decltype(s), std::string); + assert(s == "bc"); + + using WStr = std::basic_string, + test_allocator>; + const WStr win(L"abcdef"); + std::basic_string w(win, (TestSizeT)3); + ASSERT_SAME_TYPE(decltype(w), WStr); + assert(w == L"def"); + } + { // Testing (4) w/ allocator + const std::string sin("abc"); + std::basic_string s(sin, (size_t)1, std::allocator{}); + ASSERT_SAME_TYPE(decltype(s), std::string); + assert(s == "bc"); + + using WStr = std::basic_string, + test_allocator>; + const WStr win(L"abcdef"); + std::basic_string w(win, (TestSizeT)3, test_allocator{}); + ASSERT_SAME_TYPE(decltype(w), WStr); + assert(w == L"def"); + } + { // Testing (5) w/o allocator +#if 0 // FIXME: This doesn't work + const std::string sin("abc"); + std::basic_string s(sin, (size_t)1, (size_t)3); + ASSERT_SAME_TYPE(decltype(s), std::string); + assert(s == "bc"); + + using WStr = std::basic_string, + test_allocator>; + const WStr win(L"abcdef"); + std::basic_string w(win, (TestSizeT)2, (TestSizeT)3); + ASSERT_SAME_TYPE(decltype(w), WStr); + assert(w == L"cde"); +#endif + } + { // Testing (5) w/ allocator + const std::string sin("abc"); + std::basic_string s(sin, (size_t)1, (size_t)3, std::allocator{}); + ASSERT_SAME_TYPE(decltype(s), std::string); + assert(s == "bc"); + + using WStr = std::basic_string, + test_allocator>; + const WStr win(L"abcdef"); + std::basic_string w(win, (TestSizeT)2, (TestSizeT)3, test_allocator{}); + ASSERT_SAME_TYPE(decltype(w), WStr); + assert(w == L"cde"); + } + { // Testing (6) w/o allocator + std::basic_string s("abc", (size_t)2); + ASSERT_SAME_TYPE(decltype(s), std::string); + assert(s == "ab"); + + std::basic_string w(L"abcdef", (size_t)3); + ASSERT_SAME_TYPE(decltype(w), std::wstring); + assert(w == L"abc"); + } + { // Testing (6) w/ allocator + std::basic_string s("abc", (size_t)2, std::allocator{}); + ASSERT_SAME_TYPE(decltype(s), std::string); + assert(s == "ab"); + + using WStr = std::basic_string, + test_allocator>; + std::basic_string w(L"abcdef", (TestSizeT)3, test_allocator{}); + ASSERT_SAME_TYPE(decltype(w), WStr); + assert(w == L"abc"); + } + { // Testing (7) w/o allocator + std::basic_string s("abc"); + ASSERT_SAME_TYPE(decltype(s), std::string); + assert(s == "abc"); + + std::basic_string w(L"abcdef"); + ASSERT_SAME_TYPE(decltype(w), std::wstring); + assert(w == L"abcdef"); + } + { // Testing (7) w/ allocator + std::basic_string s("abc", std::allocator{}); + ASSERT_SAME_TYPE(decltype(s), std::string); + assert(s == "abc"); + + using WStr = std::basic_string, + test_allocator>; + std::basic_string w(L"abcdef", test_allocator{}); + ASSERT_SAME_TYPE(decltype(w), WStr); + assert(w == L"abcdef"); + } + { // (8) w/o allocator + // This overload isn't compatible with implicit deduction guides as + // specified in the standard. + // FIXME: Propose adding an explicit guide to the standard? + } + { // (8) w/ allocator + // This overload isn't compatible with implicit deduction guides as + // specified in the standard. + // FIXME: Propose adding an explicit guide to the standard? +#if 0 + using It = input_iterator; + const char* input = "abcdef"; + std::basic_string s(It(input), It(input + 3), std::allocator{}); + ASSERT_SAME_TYPE(decltype(s), std::string); +#endif + } + { // Testing (9) + const std::string sin("abc"); + std::basic_string s(sin); + ASSERT_SAME_TYPE(decltype(s), std::string); + assert(s == "abc"); + + using WStr = std::basic_string, + test_allocator>; + const WStr win(L"abcdef"); + std::basic_string w(win); + ASSERT_SAME_TYPE(decltype(w), WStr); + assert(w == L"abcdef"); + } + { // Testing (10) + const std::string sin("abc"); + std::basic_string s(sin, std::allocator{}); + ASSERT_SAME_TYPE(decltype(s), std::string); + assert(s == "abc"); + + using WStr = std::basic_string, + test_allocator>; + const WStr win(L"abcdef"); + std::basic_string w(win, test_allocator{}); + ASSERT_SAME_TYPE(decltype(w), WStr); + assert(w == L"abcdef"); + } + { // Testing (11) + std::string sin("abc"); + std::basic_string s(std::move(sin)); + ASSERT_SAME_TYPE(decltype(s), std::string); + assert(s == "abc"); + + using WStr = std::basic_string, + test_allocator>; + WStr win(L"abcdef"); + std::basic_string w(std::move(win)); + ASSERT_SAME_TYPE(decltype(w), WStr); + assert(w == L"abcdef"); + } + { // Testing (12) + std::string sin("abc"); + std::basic_string s(std::move(sin), std::allocator{}); + ASSERT_SAME_TYPE(decltype(s), std::string); + assert(s == "abc"); + + using WStr = std::basic_string, + test_allocator>; + WStr win(L"abcdef"); + std::basic_string w(std::move(win), test_allocator{}); + ASSERT_SAME_TYPE(decltype(w), WStr); + assert(w == L"abcdef"); + } + { // Testing (13) w/o allocator + std::basic_string s({'a', 'b', 'c'}); + ASSERT_SAME_TYPE(decltype(s), std::string); + assert(s == "abc"); + + std::basic_string w({L'a', L'b', L'c'}); + ASSERT_SAME_TYPE(decltype(w), std::wstring); + assert(w == L"abc"); + } + { // Testing (13) w/ allocator + std::basic_string s({'a', 'b', 'c'}, test_allocator{}); + ASSERT_SAME_TYPE(decltype(s), BStr>); + assert(s == "abc"); + + std::basic_string w({L'a', L'b', L'c'}, test_allocator{}); + ASSERT_SAME_TYPE(decltype(w), BStr>); + assert(w == L"abc"); + } + { // Testing (14) w/o allocator + std::string_view sv("abc"); + std::basic_string s(sv); + ASSERT_SAME_TYPE(decltype(s), std::string); + assert(s == "abc"); + + using Expect = std::basic_string>; + std::basic_string_view> BSV(L"abcdef"); + std::basic_string w(BSV); + ASSERT_SAME_TYPE(decltype(w), Expect); + assert(w == L"abcdef"); + } + { // Testing (14) w/ allocator + using ExpectS = std::basic_string, test_allocator>; + std::string_view sv("abc"); + std::basic_string s(sv, test_allocator{}); + ASSERT_SAME_TYPE(decltype(s), ExpectS); + assert(s == "abc"); + + using ExpectW = std::basic_string, + test_allocator>; + std::basic_string_view> BSV(L"abcdef"); + std::basic_string w(BSV, test_allocator{}); + ASSERT_SAME_TYPE(decltype(w), ExpectW); + assert(w == L"abcdef"); + } + { // Testing (15) + // This overload isn't compatible with implicit deduction guides as + // specified in the standard. + } +} Index: test/support/constexpr_char_traits.hpp =================================================================== --- test/support/constexpr_char_traits.hpp +++ test/support/constexpr_char_traits.hpp @@ -12,6 +12,7 @@ #define _CONSTEXPR_CHAR_TRAITS #include +#include #include "test_macros.h" @@ -118,7 +119,7 @@ TEST_CONSTEXPR_CXX14 _CharT* constexpr_char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n) { - _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); + assert(__s2 < __s1 || __s2 >= __s1+__n); char_type* __r = __s1; for (; __n; --__n, ++__s1, ++__s2) assign(*__s1, *__s2); Index: utils/libcxx/test/config.py =================================================================== --- utils/libcxx/test/config.py +++ utils/libcxx/test/config.py @@ -397,6 +397,9 @@ if '__cpp_structured_bindings' not in macros: self.config.available_features.add('libcpp-no-structured-bindings') + if '__cpp_deduction_guides' not in macros: + self.config.available_features.add('libcpp-no-deduction-guides') + if self.is_windows: self.config.available_features.add('windows')