From e96f8b52d92ee7d1d13a7a0e1f22a15c2bc52f5b Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 9 Mar 2016 17:51:43 +0000 Subject: [PATCH] Implement LWG#2583: There is no way to supply an allocator for basic_string(str, pos) llvm-svn: 263036 --- libcxx/include/string | 22 ++++++++++++++++-- .../basic.string/string.cons/substr.pass.cpp | 27 ++++++++++++++++++++-- libcxx/www/cxx1z_status.html | 2 +- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/libcxx/include/string b/libcxx/include/string index a453779..6f5089c 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -98,8 +98,10 @@ public: basic_string(const basic_string& str); basic_string(basic_string&& str) noexcept(is_nothrow_move_constructible::value); - basic_string(const basic_string& str, size_type pos, size_type n = npos, + basic_string(const basic_string& str, size_type pos, // LWG#2583 const allocator_type& a = allocator_type()); + basic_string(const basic_string& str, size_type pos, size_type n, // LWG#2583 + const Allocator& a = Allocator()); basic_string(const value_type* s, const allocator_type& a = allocator_type()); basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type()); basic_string(size_type n, value_type c, const allocator_type& a = allocator_type()); @@ -1397,7 +1399,9 @@ public: basic_string(size_type __n, value_type __c); _LIBCPP_INLINE_VISIBILITY basic_string(size_type __n, value_type __c, const allocator_type& __a); - basic_string(const basic_string& __str, size_type __pos, size_type __n = npos, + basic_string(const basic_string& __str, size_type __pos, size_type __n, + const allocator_type& __a = allocator_type()); + basic_string(const basic_string& __str, size_type __pos, const allocator_type& __a = allocator_type()); template _LIBCPP_INLINE_VISIBILITY @@ -2223,6 +2227,20 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st } template +basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, + const allocator_type& __a) + : __r_(__a) +{ + size_type __str_sz = __str.size(); + if (__pos > __str_sz) + this->__throw_out_of_range(); + __init(__str.data() + __pos, __str_sz - __pos); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template template typename enable_if < diff --git a/libcxx/test/std/strings/basic.string/string.cons/substr.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/substr.pass.cpp index 2e42be1..3eaf009 100644 --- a/libcxx/test/std/strings/basic.string/string.cons/substr.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.cons/substr.pass.cpp @@ -11,14 +11,21 @@ // // basic_string(const basic_string& str, -// size_type pos, size_type n = npos, +// size_type pos, size_type n, +// const Allocator& a = Allocator()); +// +// basic_string(const basic_string& str, +// size_type pos, // const Allocator& a = Allocator()); #include #include #include +#include +#include #include +#include "test_macros.h" #include "test_allocator.h" #include "min_allocator.h" @@ -91,6 +98,20 @@ test(S str, unsigned pos, unsigned n, const typename S::allocator_type& a) } } +#if TEST_STD_VER >= 11 +void test2583() +{ // LWG #2583 + typedef std::basic_string, test_allocator > StringA; + std::vector>> vs; + StringA s{"1234"}; + vs.emplace_back(s, 2); + + try { vs.emplace_back(s, 5); } + catch (const std::out_of_range&) { return; } + assert(false); +} +#endif + int main() { { @@ -131,7 +152,7 @@ int main() test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 10, A(8)); test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 100, A(8)); } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { typedef min_allocator A; typedef std::basic_string, A> S; @@ -170,5 +191,7 @@ int main() test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 10, A()); test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 100, A()); } + + test2583(); #endif } diff --git a/libcxx/www/cxx1z_status.html b/libcxx/www/cxx1z_status.html index c30166e..477946f 100644 --- a/libcxx/www/cxx1z_status.html +++ b/libcxx/www/cxx1z_status.html @@ -227,7 +227,7 @@ 2579Inconsistency wrt Allocators in basic_string assignment vs. basic_string::assignJacksonville 2581Specialization of <type_traits> variable templates should be prohibitedJacksonvilleComplete 2582§[res.on.functions]/2's prohibition against incomplete types shouldn't apply to type traitsJacksonville - 2583There is no way to supply an allocator for basic_string(str, pos)Jacksonville + 2583There is no way to supply an allocator for basic_string(str, pos)JacksonvilleComplete 2585forward_list::resize(size_type, const value_type&) effects incorrectJacksonville 2586Wrong value category used in scoped_allocator_adaptor::construct()Jacksonville 2590Aggregate initialization for std::arrayJacksonvilleComplete -- 2.7.4