diff options
Diffstat (limited to 'test/std/strings/basic.string/string.cons')
32 files changed, 0 insertions, 2851 deletions
diff --git a/test/std/strings/basic.string/string.cons/T_size_size.pass.cpp b/test/std/strings/basic.string/string.cons/T_size_size.pass.cpp deleted file mode 100644 index 67ac43494a6ec..0000000000000 --- a/test/std/strings/basic.string/string.cons/T_size_size.pass.cpp +++ /dev/null @@ -1,187 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> - -// template<class _Tp> -// basic_string(const _Tp& __t, size_type __pos, size_type __n, -// const allocator_type& __a = allocator_type()); -// -// Mostly we're testing string_view here - -#include <string> -#include <string_view> -#include <stdexcept> -#include <algorithm> -#include <cassert> - -#include "test_macros.h" -#include "test_allocator.h" -#include "min_allocator.h" - -template <class S, class SV> -void -test(SV sv, std::size_t pos, std::size_t n) -{ - typedef typename S::traits_type T; - typedef typename S::allocator_type A; - typedef typename S::size_type Size; - if (pos <= sv.size()) - { - S s2(sv, static_cast<Size>(pos), static_cast<Size>(n)); - LIBCPP_ASSERT(s2.__invariants()); - assert(pos <= sv.size()); - std::size_t rlen = std::min(sv.size() - pos, n); - assert(s2.size() == rlen); - assert(T::compare(s2.data(), sv.data() + pos, rlen) == 0); - assert(s2.get_allocator() == A()); - assert(s2.capacity() >= s2.size()); - } -#ifndef TEST_HAS_NO_EXCEPTIONS - else - { - try - { - S s2(sv, static_cast<Size>(pos), static_cast<Size>(n)); - assert(false); - } - catch (std::out_of_range&) - { - assert(pos > sv.size()); - } - } -#endif -} - -template <class S, class SV> -void -test(SV sv, std::size_t pos, std::size_t n, const typename S::allocator_type& a) -{ - typedef typename S::traits_type T; - typedef typename S::size_type Size; - if (pos <= sv.size()) - { - S s2(sv, static_cast<Size>(pos), static_cast<Size>(n), a); - LIBCPP_ASSERT(s2.__invariants()); - assert(pos <= sv.size()); - std::size_t rlen = std::min(sv.size() - pos, n); - assert(s2.size() == rlen); - assert(T::compare(s2.data(), sv.data() + pos, rlen) == 0); - assert(s2.get_allocator() == a); - assert(s2.capacity() >= s2.size()); - } -#ifndef TEST_HAS_NO_EXCEPTIONS - else - { - try - { - S s2(sv, static_cast<Size>(pos), static_cast<Size>(n), a); - assert(false); - } - catch (std::out_of_range&) - { - assert(pos > sv.size()); - } - } -#endif -} - -int main() -{ - - { - typedef test_allocator<char> A; - typedef std::basic_string_view<char, std::char_traits<char> > SV; - typedef std::basic_string <char, std::char_traits<char>, A> S; - - test<S,SV>(SV(), 0, 0); - test<S,SV>(SV(), 0, 1); - test<S,SV>(SV(), 1, 0); - test<S,SV>(SV(), 1, 1); - test<S,SV>(SV(), 1, 2); - test<S,SV>(SV("1"), 0, 0); - test<S,SV>(SV("1"), 0, 1); - test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 0); - test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 1); - test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 10); - test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 100); - - test<S,SV>(SV(), 0, 0, A(4)); - test<S,SV>(SV(), 0, 1, A(4)); - test<S,SV>(SV(), 1, 0, A(4)); - test<S,SV>(SV(), 1, 1, A(4)); - test<S,SV>(SV(), 1, 2, A(4)); - test<S,SV>(SV("1"), 0, 0, A(6)); - test<S,SV>(SV("1"), 0, 1, A(6)); - test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 0, A(8)); - test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 1, A(8)); - test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 10, A(8)); - test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 100, A(8)); - } - -#if TEST_STD_VER >= 11 - { - typedef min_allocator<char> A; - typedef std::basic_string_view<char, std::char_traits<char> > SV; - typedef std::basic_string <char, std::char_traits<char>, A> S; - - test<S,SV>(SV(), 0, 0); - test<S,SV>(SV(), 0, 1); - test<S,SV>(SV(), 1, 0); - test<S,SV>(SV(), 1, 1); - test<S,SV>(SV(), 1, 2); - test<S,SV>(SV("1"), 0, 0); - test<S,SV>(SV("1"), 0, 1); - test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 0); - test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 1); - test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 10); - test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 100); - - test<S,SV>(SV(), 0, 0, A()); - test<S,SV>(SV(), 0, 1, A()); - test<S,SV>(SV(), 1, 0, A()); - test<S,SV>(SV(), 1, 1, A()); - test<S,SV>(SV(), 1, 2, A()); - test<S,SV>(SV("1"), 0, 0, A()); - test<S,SV>(SV("1"), 0, 1, A()); - test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 0, A()); - test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 1, A()); - test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 10, A()); - test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 100, A()); - } -#endif - { - typedef std::string S; - typedef std::string_view SV; - S s = "ABCD"; - SV sv = "EFGH"; - char arr[] = "IJKL"; - - S s1("CDEF", 4); // calls ctor(const char *, len) - assert(s1 == "CDEF"); - - S s2("QRST", 0, 3); // calls ctor(string("QRST", pos, len) - assert(s2 == "QRS"); - - S s3(sv, 0, std::string::npos); // calls ctor(T, pos, npos) - assert(s3 == sv); - - S s4(sv, 0, 3); // calls ctor(T, pos, len) - assert(s4 == "EFG"); - - S s5(arr, 0, 2); // calls ctor(const char *, len) - assert(s5 == "IJ"); - - S s6(arr, 0); // calls ctor(const char *, len) - assert(s6 == ""); - - S s7(s.data(), 2); // calls ctor(const char *, len) - assert(s7 == "AB"); - } -} diff --git a/test/std/strings/basic.string/string.cons/alloc.pass.cpp b/test/std/strings/basic.string/string.cons/alloc.pass.cpp deleted file mode 100644 index 9e3fb07226044..0000000000000 --- a/test/std/strings/basic.string/string.cons/alloc.pass.cpp +++ /dev/null @@ -1,96 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> - -// explicit basic_string(const Allocator& a = Allocator()); - -#include <string> -#include <cassert> - -#include "test_macros.h" -#include "test_allocator.h" -#include "min_allocator.h" - -template <class S> -void -test() -{ - { -#if TEST_STD_VER > 14 - static_assert((noexcept(S{})), "" ); -#elif TEST_STD_VER >= 11 - static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" ); -#endif - S s; - LIBCPP_ASSERT(s.__invariants()); - assert(s.data()); - assert(s.size() == 0); - assert(s.capacity() >= s.size()); - assert(s.get_allocator() == typename S::allocator_type()); - } - { -#if TEST_STD_VER > 14 - static_assert((noexcept(S{typename S::allocator_type{}})), "" ); -#elif TEST_STD_VER >= 11 - static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" ); -#endif - S s(typename S::allocator_type(5)); - LIBCPP_ASSERT(s.__invariants()); - assert(s.data()); - assert(s.size() == 0); - assert(s.capacity() >= s.size()); - assert(s.get_allocator() == typename S::allocator_type(5)); - } -} - -#if TEST_STD_VER >= 11 - -template <class S> -void -test2() -{ - { -#if TEST_STD_VER > 14 - static_assert((noexcept(S{})), "" ); -#elif TEST_STD_VER >= 11 - static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" ); -#endif - S s; - LIBCPP_ASSERT(s.__invariants()); - assert(s.data()); - assert(s.size() == 0); - assert(s.capacity() >= s.size()); - assert(s.get_allocator() == typename S::allocator_type()); - } - { -#if TEST_STD_VER > 14 - static_assert((noexcept(S{typename S::allocator_type{}})), "" ); -#elif TEST_STD_VER >= 11 - static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" ); -#endif - S s(typename S::allocator_type{}); - LIBCPP_ASSERT(s.__invariants()); - assert(s.data()); - assert(s.size() == 0); - assert(s.capacity() >= s.size()); - assert(s.get_allocator() == typename S::allocator_type()); - } -} - -#endif - -int main() -{ - test<std::basic_string<char, std::char_traits<char>, test_allocator<char> > >(); -#if TEST_STD_VER >= 11 - test2<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >(); - test2<std::basic_string<char, std::char_traits<char>, explicit_allocator<char> > >(); -#endif -} diff --git a/test/std/strings/basic.string/string.cons/brace_assignment.pass.cpp b/test/std/strings/basic.string/string.cons/brace_assignment.pass.cpp deleted file mode 100644 index 8b498f1787bdc..0000000000000 --- a/test/std/strings/basic.string/string.cons/brace_assignment.pass.cpp +++ /dev/null @@ -1,36 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 - -// <string> - -// basic_string<charT,traits,Allocator>& -// operator=(basic_string<charT,traits,Allocator>&& str); - -#include <string> -#include <cassert> - -#include "test_macros.h" - -int main() -{ - // Test that assignment from {} and {ptr, len} are allowed and are not - // ambiguous. - { - std::string s = "hello world"; - s = {}; - assert(s.empty()); - } - { - std::string s = "hello world"; - s = {"abc", 2}; - assert(s == "ab"); - } -} diff --git a/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp b/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp deleted file mode 100644 index f6bacb70e4ce5..0000000000000 --- a/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp +++ /dev/null @@ -1,50 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> - -// basic_string<charT,traits,Allocator>& operator=(charT c); - -#include <string> -#include <cassert> - -#include "test_macros.h" -#include "min_allocator.h" - -template <class S> -void -test(S s1, typename S::value_type s2) -{ - typedef typename S::traits_type T; - s1 = s2; - LIBCPP_ASSERT(s1.__invariants()); - assert(s1.size() == 1); - assert(T::eq(s1[0], s2)); - assert(s1.capacity() >= s1.size()); -} - -int main() -{ - { - typedef std::string S; - test(S(), 'a'); - test(S("1"), 'a'); - test(S("123456789"), 'a'); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 'a'); - } -#if TEST_STD_VER >= 11 - { - typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; - test(S(), 'a'); - test(S("1"), 'a'); - test(S("123456789"), 'a'); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 'a'); - } -#endif -} diff --git a/test/std/strings/basic.string/string.cons/copy.pass.cpp b/test/std/strings/basic.string/string.cons/copy.pass.cpp deleted file mode 100644 index cc4deb992a8b2..0000000000000 --- a/test/std/strings/basic.string/string.cons/copy.pass.cpp +++ /dev/null @@ -1,50 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> - -// basic_string(const basic_string<charT,traits,Allocator>& str); - -#include <string> -#include <cassert> - -#include "test_macros.h" -#include "test_allocator.h" -#include "min_allocator.h" - -template <class S> -void -test(S s1) -{ - S s2 = s1; - LIBCPP_ASSERT(s2.__invariants()); - assert(s2 == s1); - assert(s2.capacity() >= s2.size()); - assert(s2.get_allocator() == s1.get_allocator()); -} - -int main() -{ - { - typedef test_allocator<char> A; - typedef std::basic_string<char, std::char_traits<char>, A> S; - test(S(A(3))); - test(S("1", A(5))); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7))); - } -#if TEST_STD_VER >= 11 - { - typedef min_allocator<char> A; - typedef std::basic_string<char, std::char_traits<char>, A> S; - test(S(A{})); - test(S("1", A())); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A())); - } -#endif -} diff --git a/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp b/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp deleted file mode 100644 index edd5c6e32d568..0000000000000 --- a/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp +++ /dev/null @@ -1,131 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> - -// basic_string(const basic_string& str, const Allocator& alloc); - -#include <string> -#include <cassert> - -#include "test_macros.h" -#include "test_allocator.h" -#include "min_allocator.h" - -#ifndef TEST_HAS_NO_EXCEPTIONS -template <class T> -struct alloc_imp { - bool active; - - alloc_imp() : active(true) {} - - T* allocate(std::size_t n) - { - if (active) - return static_cast<T*>(std::malloc(n * sizeof(T))); - else - throw std::bad_alloc(); - } - - void deallocate(T* p, std::size_t) { std::free(p); } - void activate () { active = true; } - void deactivate() { active = false; } -}; - -template <class T> -struct poca_alloc { - typedef T value_type; - typedef std::true_type propagate_on_container_copy_assignment; - - alloc_imp<T> *imp; - - poca_alloc(alloc_imp<T> *imp_) : imp (imp_) {} - - template <class U> - poca_alloc(const poca_alloc<U>& other) : imp(other.imp) {} - - T* allocate (std::size_t n) { return imp->allocate(n);} - void deallocate(T* p, std::size_t n) { imp->deallocate(p, n); } -}; - -template <typename T, typename U> -bool operator==(const poca_alloc<T>& lhs, const poca_alloc<U>& rhs) -{ - return lhs.imp == rhs.imp; -} - -template <typename T, typename U> -bool operator!=(const poca_alloc<T>& lhs, const poca_alloc<U>& rhs) -{ - return lhs.imp != rhs.imp; -} - -template <class S> -void test_assign(S &s1, const S& s2) -{ - try { s1 = s2; } - catch ( std::bad_alloc &) { return; } - assert(false); -} -#endif - - - -template <class S> -void -test(S s1, const typename S::allocator_type& a) -{ - S s2(s1, a); - LIBCPP_ASSERT(s2.__invariants()); - assert(s2 == s1); - assert(s2.capacity() >= s2.size()); - assert(s2.get_allocator() == a); -} - -int main() -{ - { - typedef test_allocator<char> A; - typedef std::basic_string<char, std::char_traits<char>, A> S; - test(S(), A(3)); - test(S("1"), A(5)); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7)); - } -#if TEST_STD_VER >= 11 - { - typedef min_allocator<char> A; - typedef std::basic_string<char, std::char_traits<char>, A> S; - test(S(), A()); - test(S("1"), A()); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A()); - } - -#ifndef TEST_HAS_NO_EXCEPTIONS - { - typedef poca_alloc<char> A; - typedef std::basic_string<char, std::char_traits<char>, A> S; - const char * p1 = "This is my first string"; - const char * p2 = "This is my second string"; - - alloc_imp<char> imp1; - alloc_imp<char> imp2; - S s1(p1, A(&imp1)); - S s2(p2, A(&imp2)); - - assert(s1 == p1); - assert(s2 == p2); - - imp2.deactivate(); - test_assign(s1, s2); - assert(s1 == p1); - assert(s2 == p2); - } -#endif -#endif -} diff --git a/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp b/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp deleted file mode 100644 index 34d5f306a7394..0000000000000 --- a/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp +++ /dev/null @@ -1,80 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> - -// basic_string<charT,traits,Allocator>& -// operator=(const basic_string<charT,traits,Allocator>& str); - -#include <string> -#include <cassert> - -#include "test_macros.h" -#include "min_allocator.h" - -template <class S> -void -test(S s1, const S& s2) -{ - s1 = s2; - LIBCPP_ASSERT(s1.__invariants()); - assert(s1 == s2); - assert(s1.capacity() >= s1.size()); -} - -int main() -{ - { - typedef std::string S; - test(S(), S()); - test(S("1"), S()); - test(S(), S("1")); - test(S("1"), S("2")); - test(S("1"), S("2")); - - test(S(), - S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - test(S("123456789"), - S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), - S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890" - "1234567890123456789012345678901234567890123456789012345678901234567890"), - S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - } -#if TEST_STD_VER >= 11 - { - typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; - test(S(), S()); - test(S("1"), S()); - test(S(), S("1")); - test(S("1"), S("2")); - test(S("1"), S("2")); - - test(S(), - S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - test(S("123456789"), - S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), - S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890" - "1234567890123456789012345678901234567890123456789012345678901234567890"), - S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - } -#endif - -#if TEST_STD_VER > 3 - { // LWG 2946 - std::string s; - s = {"abc", 1}; - assert(s.size() == 1); - assert(s == "a"); - } -#endif -} diff --git a/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp b/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp deleted file mode 100644 index a995a51eed48b..0000000000000 --- a/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp +++ /dev/null @@ -1,39 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 - -// <string> - -// basic_string() -// noexcept(is_nothrow_default_constructible<allocator_type>::value); - -// This tests a conforming extension - -#include <string> -#include <cassert> - -#include "test_macros.h" -#include "test_allocator.h" - -int main() -{ - { - typedef std::string C; - static_assert(std::is_nothrow_default_constructible<C>::value, ""); - } - { - typedef std::basic_string<char, std::char_traits<char>, test_allocator<char>> C; - static_assert(std::is_nothrow_default_constructible<C>::value, ""); - } - { - typedef std::basic_string<char, std::char_traits<char>, limited_allocator<char, 10>> C; - static_assert(!std::is_nothrow_default_constructible<C>::value, ""); - } -} diff --git a/test/std/strings/basic.string/string.cons/dtor_noexcept.pass.cpp b/test/std/strings/basic.string/string.cons/dtor_noexcept.pass.cpp deleted file mode 100644 index a4de566a4dc0d..0000000000000 --- a/test/std/strings/basic.string/string.cons/dtor_noexcept.pass.cpp +++ /dev/null @@ -1,52 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 - -// <string> - -// ~basic_string() // implied noexcept; - -#include <string> -#include <cassert> - -#include "test_macros.h" -#include "test_allocator.h" - -template <class T> -struct throwing_alloc -{ - typedef T value_type; - throwing_alloc(const throwing_alloc&); - T *allocate(size_t); - ~throwing_alloc() noexcept(false); -}; - -// Test that it's possible to take the address of basic_string's destructors -// by creating globals which will register their destructors with cxa_atexit. -std::string s; -std::wstring ws; - -int main() -{ - { - typedef std::string C; - static_assert(std::is_nothrow_destructible<C>::value, ""); - } - { - typedef std::basic_string<char, std::char_traits<char>, test_allocator<char>> C; - static_assert(std::is_nothrow_destructible<C>::value, ""); - } -#if defined(_LIBCPP_VERSION) - { - typedef std::basic_string<char, std::char_traits<char>, throwing_alloc<char>> C; - static_assert(!std::is_nothrow_destructible<C>::value, ""); - } -#endif // _LIBCPP_VERSION -} diff --git a/test/std/strings/basic.string/string.cons/implicit_deduction_guides.pass.cpp b/test/std/strings/basic.string/string.cons/implicit_deduction_guides.pass.cpp deleted file mode 100644 index 3665e23a727bd..0000000000000 --- a/test/std/strings/basic.string/string.cons/implicit_deduction_guides.pass.cpp +++ /dev/null @@ -1,317 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 - -// <string> - -// Test that the constructors offered by std::basic_string are formulated -// so they're compatible with implicit deduction guides. - -#include <string> -#include <string_view> -#include <cassert> - -#include "test_macros.h" -#include "test_allocator.h" -#include "test_iterators.h" -#include "constexpr_char_traits.hpp" - -template <class T, class Alloc = std::allocator<T>> -using BStr = std::basic_string<T, std::char_traits<T>, 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()) -// (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<CharT>, A const& = A()) -// (14) basic_string(BSV, A const& = A()) -// (15) basic_string(const T&, size_type, size_type, A const& = A()) -int main() -{ - using TestSizeT = test_allocator<char>::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<char> 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<char>{}); - ASSERT_SAME_TYPE(decltype(s), BStr<char,test_allocator<char>>); - assert(s == "aaaaaa"); - - std::basic_string w(2ull, L'b', test_allocator<wchar_t>{}); - ASSERT_SAME_TYPE(decltype(w), BStr<wchar_t, test_allocator<wchar_t>>); - 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<wchar_t, - constexpr_char_traits<wchar_t>, - test_allocator<wchar_t>>; - 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<char>{}); - ASSERT_SAME_TYPE(decltype(s), std::string); - assert(s == "bc"); - - using WStr = std::basic_string<wchar_t, - constexpr_char_traits<wchar_t>, - test_allocator<wchar_t>>; - const WStr win(L"abcdef"); - std::basic_string w(win, (TestSizeT)3, test_allocator<wchar_t>{}); - ASSERT_SAME_TYPE(decltype(w), WStr); - assert(w == L"def"); - } - { // Testing (5) w/o allocator - 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<wchar_t, - constexpr_char_traits<wchar_t>, - test_allocator<wchar_t>>; - const WStr win(L"abcdef"); - std::basic_string w(win, (TestSizeT)2, (TestSizeT)3); - ASSERT_SAME_TYPE(decltype(w), WStr); - assert(w == L"cde"); - } - { // Testing (5) w/ allocator - const std::string sin("abc"); - std::basic_string s(sin, (size_t)1, (size_t)3, std::allocator<char>{}); - ASSERT_SAME_TYPE(decltype(s), std::string); - assert(s == "bc"); - - using WStr = std::basic_string<wchar_t, - constexpr_char_traits<wchar_t>, - test_allocator<wchar_t>>; - const WStr win(L"abcdef"); - std::basic_string w(win, (TestSizeT)2, (TestSizeT)3, test_allocator<wchar_t>{}); - 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<char>{}); - ASSERT_SAME_TYPE(decltype(s), std::string); - assert(s == "ab"); - - using WStr = std::basic_string<wchar_t, - std::char_traits<wchar_t>, - test_allocator<wchar_t>>; - std::basic_string w(L"abcdef", (TestSizeT)3, test_allocator<wchar_t>{}); - 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<char>{}); - ASSERT_SAME_TYPE(decltype(s), std::string); - assert(s == "abc"); - - using WStr = std::basic_string<wchar_t, - std::char_traits<wchar_t>, - test_allocator<wchar_t>>; - std::basic_string w(L"abcdef", test_allocator<wchar_t>{}); - ASSERT_SAME_TYPE(decltype(w), WStr); - assert(w == L"abcdef"); - } - { // (8) w/o allocator - using It = input_iterator<const char*>; - const char* input = "abcdef"; - std::basic_string s(It(input), It(input + 3), std::allocator<char>{}); - ASSERT_SAME_TYPE(decltype(s), std::string); - assert(s == "abc"); - } - { // (8) w/ allocator - using ExpectW = std::basic_string<wchar_t, std::char_traits<wchar_t>, test_allocator<wchar_t>>; - using It = input_iterator<const wchar_t*>; - const wchar_t* input = L"abcdef"; - std::basic_string s(It(input), It(input + 3), test_allocator<wchar_t>{}); - ASSERT_SAME_TYPE(decltype(s), ExpectW); - assert(s == L"abc"); - } - { // 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<wchar_t, - constexpr_char_traits<wchar_t>, - test_allocator<wchar_t>>; - 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<char>{}); - ASSERT_SAME_TYPE(decltype(s), std::string); - assert(s == "abc"); - - using WStr = std::basic_string<wchar_t, - constexpr_char_traits<wchar_t>, - test_allocator<wchar_t>>; - const WStr win(L"abcdef"); - std::basic_string w(win, test_allocator<wchar_t>{}); - 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<wchar_t, - constexpr_char_traits<wchar_t>, - test_allocator<wchar_t>>; - 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<char>{}); - ASSERT_SAME_TYPE(decltype(s), std::string); - assert(s == "abc"); - - using WStr = std::basic_string<wchar_t, - constexpr_char_traits<wchar_t>, - test_allocator<wchar_t>>; - WStr win(L"abcdef"); - std::basic_string w(std::move(win), test_allocator<wchar_t>{}); - 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<char>{}); - ASSERT_SAME_TYPE(decltype(s), BStr<char, test_allocator<char>>); - assert(s == "abc"); - - std::basic_string w({L'a', L'b', L'c'}, test_allocator<wchar_t>{}); - ASSERT_SAME_TYPE(decltype(w), BStr<wchar_t, test_allocator<wchar_t>>); - 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<wchar_t, constexpr_char_traits<wchar_t>>; - std::basic_string_view<wchar_t, constexpr_char_traits<wchar_t>> 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<char, std::char_traits<char>, test_allocator<char>>; - std::string_view sv("abc"); - std::basic_string s(sv, test_allocator<char>{}); - ASSERT_SAME_TYPE(decltype(s), ExpectS); - assert(s == "abc"); - - using ExpectW = std::basic_string<wchar_t, constexpr_char_traits<wchar_t>, - test_allocator<wchar_t>>; - std::basic_string_view<wchar_t, constexpr_char_traits<wchar_t>> BSV(L"abcdef"); - std::basic_string w(BSV, test_allocator<wchar_t>{}); - ASSERT_SAME_TYPE(decltype(w), ExpectW); - assert(w == L"abcdef"); - } - { // Testing (15) w/o allocator - std::string s0("abc"); - std::basic_string s(s0, 1, 1); - ASSERT_SAME_TYPE(decltype(s), std::string); - assert(s == "b"); - - std::wstring w0(L"abcdef"); - std::basic_string w(w0, 2, 2); - ASSERT_SAME_TYPE(decltype(w), std::wstring); - assert(w == L"cd"); - } - { // Testing (15) w/ allocator - using ExpectS = std::basic_string<char, std::char_traits<char>, test_allocator<char>>; - ExpectS s0("abc"); - std::basic_string s(s0, 1, 1, test_allocator<char>{4}); - ASSERT_SAME_TYPE(decltype(s), ExpectS); - assert(s == "b"); - - using ExpectW = std::basic_string<wchar_t, std::char_traits<wchar_t>, test_allocator<wchar_t>>; - ExpectW w0(L"abcdef"); - std::basic_string w(w0, 2, 2, test_allocator<wchar_t>{6}); - ASSERT_SAME_TYPE(decltype(w), ExpectW); - assert(w == L"cd"); - } -} diff --git a/test/std/strings/basic.string/string.cons/initializer_list.pass.cpp b/test/std/strings/basic.string/string.cons/initializer_list.pass.cpp deleted file mode 100644 index 3007b9e8f68ca..0000000000000 --- a/test/std/strings/basic.string/string.cons/initializer_list.pass.cpp +++ /dev/null @@ -1,44 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 - -// <string> - -// basic_string(initializer_list<charT> il, const Allocator& a = Allocator()); - -#include <string> -#include <cassert> - -#include "test_allocator.h" -#include "min_allocator.h" - -int main() -{ - { - std::string s = {'a', 'b', 'c'}; - assert(s == "abc"); - } - { - std::wstring s; - s = {L'a', L'b', L'c'}; - assert(s == L"abc"); - } - { - typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; - S s = {'a', 'b', 'c'}; - assert(s == "abc"); - } - { - typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, min_allocator<wchar_t>> S; - S s; - s = {L'a', L'b', L'c'}; - assert(s == L"abc"); - } -} diff --git a/test/std/strings/basic.string/string.cons/initializer_list_assignment.pass.cpp b/test/std/strings/basic.string/string.cons/initializer_list_assignment.pass.cpp deleted file mode 100644 index 20279c853eafa..0000000000000 --- a/test/std/strings/basic.string/string.cons/initializer_list_assignment.pass.cpp +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 - -// <string> - -// basic_string& operator=(initializer_list<charT> il); - -#include <string> -#include <cassert> - -#include "min_allocator.h" - -int main() -{ - { - std::string s; - s = {'a', 'b', 'c'}; - assert(s == "abc"); - } - { - typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; - S s; - s = {'a', 'b', 'c'}; - assert(s == "abc"); - } -} diff --git a/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp b/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp deleted file mode 100644 index e7fefacc068f1..0000000000000 --- a/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp +++ /dev/null @@ -1,120 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> - -// template<class InputIterator> -// basic_string(InputIterator begin, InputIterator end, -// const Allocator& a = Allocator()); - - -#include <string> -#include <iterator> -#include <cassert> -#include <cstddef> - -#include "test_macros.h" -#include "test_allocator.h" -#include "../input_iterator.h" -#include "min_allocator.h" - -template <class It> -void -test(It first, It last) -{ - typedef typename std::iterator_traits<It>::value_type charT; - typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S; - typedef typename S::allocator_type A; - S s2(first, last); - LIBCPP_ASSERT(s2.__invariants()); - assert(s2.size() == static_cast<std::size_t>(std::distance(first, last))); - unsigned i = 0; - for (It it = first; it != last; ++it, ++i) - assert(s2[i] == *it); - assert(s2.get_allocator() == A()); - assert(s2.capacity() >= s2.size()); -} - -template <class It, class A> -void -test(It first, It last, const A& a) -{ - typedef typename std::iterator_traits<It>::value_type charT; - typedef std::basic_string<charT, std::char_traits<charT>, A> S; - S s2(first, last, a); - LIBCPP_ASSERT(s2.__invariants()); - assert(s2.size() == static_cast<std::size_t>(std::distance(first, last))); - unsigned i = 0; - for (It it = first; it != last; ++it, ++i) - assert(s2[i] == *it); - assert(s2.get_allocator() == a); - assert(s2.capacity() >= s2.size()); -} - -int main() -{ - { - typedef test_allocator<char> A; - const char* s = "12345678901234567890123456789012345678901234567890"; - - test(s, s); - test(s, s, A(2)); - - test(s, s+1); - test(s, s+1, A(2)); - - test(s, s+10); - test(s, s+10, A(2)); - - test(s, s+50); - test(s, s+50, A(2)); - - test(input_iterator<const char*>(s), input_iterator<const char*>(s)); - test(input_iterator<const char*>(s), input_iterator<const char*>(s), A(2)); - - test(input_iterator<const char*>(s), input_iterator<const char*>(s+1)); - test(input_iterator<const char*>(s), input_iterator<const char*>(s+1), A(2)); - - test(input_iterator<const char*>(s), input_iterator<const char*>(s+10)); - test(input_iterator<const char*>(s), input_iterator<const char*>(s+10), A(2)); - - test(input_iterator<const char*>(s), input_iterator<const char*>(s+50)); - test(input_iterator<const char*>(s), input_iterator<const char*>(s+50), A(2)); - } -#if TEST_STD_VER >= 11 - { - typedef min_allocator<char> A; - const char* s = "12345678901234567890123456789012345678901234567890"; - - test(s, s); - test(s, s, A()); - - test(s, s+1); - test(s, s+1, A()); - - test(s, s+10); - test(s, s+10, A()); - - test(s, s+50); - test(s, s+50, A()); - - test(input_iterator<const char*>(s), input_iterator<const char*>(s)); - test(input_iterator<const char*>(s), input_iterator<const char*>(s), A()); - - test(input_iterator<const char*>(s), input_iterator<const char*>(s+1)); - test(input_iterator<const char*>(s), input_iterator<const char*>(s+1), A()); - - test(input_iterator<const char*>(s), input_iterator<const char*>(s+10)); - test(input_iterator<const char*>(s), input_iterator<const char*>(s+10), A()); - - test(input_iterator<const char*>(s), input_iterator<const char*>(s+50)); - test(input_iterator<const char*>(s), input_iterator<const char*>(s+50), A()); - } -#endif -} diff --git a/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp b/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp deleted file mode 100644 index 9c2a3201f8af2..0000000000000 --- a/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp +++ /dev/null @@ -1,56 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> -// UNSUPPORTED: c++98, c++03, c++11, c++14 -// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8, clang-3.9, clang-4.0 -// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8, apple-clang-9 - -// template<class InputIterator, -// class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> -// basic_string(InputIterator, InputIterator, Allocator = Allocator()) -// -> basic_string<typename iterator_traits<InputIterator>::value_type, -// char_traits<typename iterator_traits<InputIterator>::value_type>, -// Allocator>; -// -// The deduction guide shall not participate in overload resolution if InputIterator -// is a type that does not qualify as an input iterator, or if Allocator is a type -// that does not qualify as an allocator. - - -#include <string> -#include <iterator> -#include <cassert> -#include <cstddef> - -#include "test_macros.h" - -class NotAnItertor {}; - -template <typename T> -struct NotAnAllocator { typedef T value_type; }; - -int main() -{ - { // Not an iterator at all - std::basic_string s1{NotAnItertor{}, NotAnItertor{}, std::allocator<char>{}}; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'basic_string'}} - } - { // Not an input iterator - const char16_t* s = u"12345678901234"; - std::basic_string<char16_t> s0; - std::basic_string s1{std::back_insert_iterator(s0), // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'basic_string'}} - std::back_insert_iterator(s0), - std::allocator<char16_t>{}}; - } - { // Not an allocator - const wchar_t* s = L"12345678901234"; - std::basic_string s1{s, s+10, NotAnAllocator<wchar_t>{}}; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'basic_string'}} - } - -} diff --git a/test/std/strings/basic.string/string.cons/iter_alloc_deduction.pass.cpp b/test/std/strings/basic.string/string.cons/iter_alloc_deduction.pass.cpp deleted file mode 100644 index 815b5600dd472..0000000000000 --- a/test/std/strings/basic.string/string.cons/iter_alloc_deduction.pass.cpp +++ /dev/null @@ -1,93 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> -// UNSUPPORTED: c++98, c++03, c++11, c++14 -// XFAIL: libcpp-no-deduction-guides - -// template<class InputIterator> -// basic_string(InputIterator begin, InputIterator end, -// const Allocator& a = Allocator()); - -// template<class InputIterator, -// class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> -// basic_string(InputIterator, InputIterator, Allocator = Allocator()) -// -> basic_string<typename iterator_traits<InputIterator>::value_type, -// char_traits<typename iterator_traits<InputIterator>::value_type>, -// Allocator>; -// -// The deduction guide shall not participate in overload resolution if InputIterator -// is a type that does not qualify as an input iterator, or if Allocator is a type -// that does not qualify as an allocator. - - -#include <string> -#include <iterator> -#include <cassert> -#include <cstddef> - -#include "test_macros.h" -#include "test_allocator.h" -#include "../input_iterator.h" -#include "min_allocator.h" - -int main() -{ - { - const char* s = "12345678901234"; - std::basic_string s1(s, s+10); // Can't use {} here - using S = decltype(s1); // what type did we get? - static_assert(std::is_same_v<S::value_type, char>, ""); - static_assert(std::is_same_v<S::traits_type, std::char_traits<char>>, ""); - static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, ""); - assert(s1.size() == 10); - assert(s1.compare(0, s1.size(), s, s1.size()) == 0); - } - - { - const char* s = "12345678901234"; - std::basic_string s1{s, s+10, std::allocator<char>{}}; - using S = decltype(s1); // what type did we get? - static_assert(std::is_same_v<S::value_type, char>, ""); - static_assert(std::is_same_v<S::traits_type, std::char_traits<char>>, ""); - static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, ""); - assert(s1.size() == 10); - assert(s1.compare(0, s1.size(), s, s1.size()) == 0); - } - { - const wchar_t* s = L"12345678901234"; - std::basic_string s1{s, s+10, test_allocator<wchar_t>{}}; - using S = decltype(s1); // what type did we get? - static_assert(std::is_same_v<S::value_type, wchar_t>, ""); - static_assert(std::is_same_v<S::traits_type, std::char_traits<wchar_t>>, ""); - static_assert(std::is_same_v<S::allocator_type, test_allocator<wchar_t>>, ""); - assert(s1.size() == 10); - assert(s1.compare(0, s1.size(), s, s1.size()) == 0); - } - { - const char16_t* s = u"12345678901234"; - std::basic_string s1{s, s+10, min_allocator<char16_t>{}}; - using S = decltype(s1); // what type did we get? - static_assert(std::is_same_v<S::value_type, char16_t>, ""); - static_assert(std::is_same_v<S::traits_type, std::char_traits<char16_t>>, ""); - static_assert(std::is_same_v<S::allocator_type, min_allocator<char16_t>>, ""); - assert(s1.size() == 10); - assert(s1.compare(0, s1.size(), s, s1.size()) == 0); - } - { - const char32_t* s = U"12345678901234"; - std::basic_string s1{s, s+10, explicit_allocator<char32_t>{}}; - using S = decltype(s1); // what type did we get? - static_assert(std::is_same_v<S::value_type, char32_t>, ""); - static_assert(std::is_same_v<S::traits_type, std::char_traits<char32_t>>, ""); - static_assert(std::is_same_v<S::allocator_type, explicit_allocator<char32_t>>, ""); - assert(s1.size() == 10); - assert(s1.compare(0, s1.size(), s, s1.size()) == 0); - } -} diff --git a/test/std/strings/basic.string/string.cons/move.pass.cpp b/test/std/strings/basic.string/string.cons/move.pass.cpp deleted file mode 100644 index 9ed244406d018..0000000000000 --- a/test/std/strings/basic.string/string.cons/move.pass.cpp +++ /dev/null @@ -1,52 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 - -// <string> - -// basic_string(basic_string<charT,traits,Allocator>&& str); - -#include <string> -#include <cassert> - -#include "test_macros.h" -#include "test_allocator.h" -#include "min_allocator.h" - -template <class S> -void -test(S s0) -{ - S s1 = s0; - S s2 = std::move(s0); - LIBCPP_ASSERT(s2.__invariants()); - LIBCPP_ASSERT(s0.__invariants()); - assert(s2 == s1); - assert(s2.capacity() >= s2.size()); - assert(s2.get_allocator() == s1.get_allocator()); -} - -int main() -{ - { - typedef test_allocator<char> A; - typedef std::basic_string<char, std::char_traits<char>, A> S; - test(S(A(3))); - test(S("1", A(5))); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7))); - } - { - typedef min_allocator<char> A; - typedef std::basic_string<char, std::char_traits<char>, A> S; - test(S(A{})); - test(S("1", A())); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A())); - } -} diff --git a/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp b/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp deleted file mode 100644 index bb7bdcd1434f5..0000000000000 --- a/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp +++ /dev/null @@ -1,78 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 - -// <string> - -// basic_string(basic_string&& str, const Allocator& alloc); - -#include <string> -#include <cassert> - -#include "test_macros.h" -#include "test_allocator.h" -#include "min_allocator.h" - - -template <class S> -void -test(S s0, const typename S::allocator_type& a) -{ - S s1 = s0; - S s2(std::move(s0), a); - LIBCPP_ASSERT(s2.__invariants()); - LIBCPP_ASSERT(s0.__invariants()); - assert(s2 == s1); - assert(s2.capacity() >= s2.size()); - assert(s2.get_allocator() == a); -} - - -int main() -{ - { - typedef test_allocator<char> A; - typedef std::basic_string<char, std::char_traits<char>, A> S; -#if TEST_STD_VER > 14 - static_assert((noexcept(S{})), "" ); -#elif TEST_STD_VER >= 11 - static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" ); -#endif - test(S(), A(3)); - test(S("1"), A(5)); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7)); - } - - int alloc_count = test_alloc_base::alloc_count; - { - typedef test_allocator<char> A; - typedef std::basic_string<char, std::char_traits<char>, A> S; -#if TEST_STD_VER > 14 - static_assert((noexcept(S{})), "" ); -#elif TEST_STD_VER >= 11 - static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" ); -#endif - S s1 ( "Twas brillig, and the slivy toves did gyre and gymbal in the wabe" ); - S s2 (std::move(s1), A(1)); - } - assert ( test_alloc_base::alloc_count == alloc_count ); - { - typedef min_allocator<char> A; - typedef std::basic_string<char, std::char_traits<char>, A> S; -#if TEST_STD_VER > 14 - static_assert((noexcept(S{})), "" ); -#elif TEST_STD_VER >= 11 - static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" ); -#endif - test(S(), A()); - test(S("1"), A()); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A()); - } -} diff --git a/test/std/strings/basic.string/string.cons/move_assign_noexcept.pass.cpp b/test/std/strings/basic.string/string.cons/move_assign_noexcept.pass.cpp deleted file mode 100644 index ad9ed36d3f806..0000000000000 --- a/test/std/strings/basic.string/string.cons/move_assign_noexcept.pass.cpp +++ /dev/null @@ -1,97 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 - -// <string> - -// basic_string& operator=(basic_string&& c) -// noexcept( -// allocator_traits<allocator_type>::propagate_on_container_move_assignment::value || -// allocator_traits<allocator_type>::is_always_equal::value); // C++17 -// -// before C++17, we use the conforming extension -// noexcept( -// allocator_type::propagate_on_container_move_assignment::value && -// is_nothrow_move_assignable<allocator_type>::value); - -#include <string> -#include <cassert> - -#include "test_macros.h" -#include "test_allocator.h" - -template <class T> -struct some_alloc -{ - typedef T value_type; - some_alloc(const some_alloc&); - T *allocate(size_t); -}; - -template <class T> -struct some_alloc2 -{ - typedef T value_type; - - some_alloc2() {} - some_alloc2(const some_alloc2&); - T *allocate(size_t); - void deallocate(void*, unsigned) {} - - typedef std::false_type propagate_on_container_move_assignment; - typedef std::true_type is_always_equal; -}; - -template <class T> -struct some_alloc3 -{ - typedef T value_type; - - some_alloc3() {} - some_alloc3(const some_alloc3&); - T *allocate(size_t); - void deallocate(void*, unsigned) {} - - typedef std::false_type propagate_on_container_move_assignment; - typedef std::false_type is_always_equal; -}; - -int main() -{ - { - typedef std::string C; - static_assert(std::is_nothrow_move_assignable<C>::value, ""); - } - { - typedef std::basic_string<char, std::char_traits<char>, test_allocator<char>> C; - static_assert(!std::is_nothrow_move_assignable<C>::value, ""); - } - { - typedef std::basic_string<char, std::char_traits<char>, some_alloc<char>> C; -#if TEST_STD_VER > 14 - // if the allocators are always equal, then the move assignment can be noexcept - static_assert( std::is_nothrow_move_assignable<C>::value, ""); -#else - static_assert(!std::is_nothrow_move_assignable<C>::value, ""); -#endif - } -#if TEST_STD_VER > 14 - { - // POCMA is false, always equal - typedef std::basic_string<char, std::char_traits<char>, some_alloc2<char>> C; - static_assert( std::is_nothrow_move_assignable<C>::value, ""); - } - { - // POCMA is false, not always equal - typedef std::basic_string<char, std::char_traits<char>, some_alloc3<char>> C; - static_assert(!std::is_nothrow_move_assignable<C>::value, ""); - } -#endif -} diff --git a/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp b/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp deleted file mode 100644 index 006b5b9b4cb0a..0000000000000 --- a/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp +++ /dev/null @@ -1,74 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 - -// <string> - -// basic_string<charT,traits,Allocator>& -// operator=(basic_string<charT,traits,Allocator>&& str); - -#include <string> -#include <cassert> - -#include "test_macros.h" -#include "test_allocator.h" -#include "min_allocator.h" - -template <class S> -void -test(S s1, S s2) -{ - S s0 = s2; - s1 = std::move(s2); - LIBCPP_ASSERT(s1.__invariants()); - LIBCPP_ASSERT(s2.__invariants()); - assert(s1 == s0); - assert(s1.capacity() >= s1.size()); -} - -int main() -{ - { - typedef std::string S; - test(S(), S()); - test(S("1"), S()); - test(S(), S("1")); - test(S("1"), S("2")); - test(S("1"), S("2")); - - test(S(), - S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - test(S("123456789"), - S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), - S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890" - "1234567890123456789012345678901234567890123456789012345678901234567890"), - S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - } - { - typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; - test(S(), S()); - test(S("1"), S()); - test(S(), S("1")); - test(S("1"), S("2")); - test(S("1"), S("2")); - - test(S(), - S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - test(S("123456789"), - S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), - S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890" - "1234567890123456789012345678901234567890123456789012345678901234567890"), - S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - } -} diff --git a/test/std/strings/basic.string/string.cons/move_noexcept.pass.cpp b/test/std/strings/basic.string/string.cons/move_noexcept.pass.cpp deleted file mode 100644 index e0e4a4ff31bd8..0000000000000 --- a/test/std/strings/basic.string/string.cons/move_noexcept.pass.cpp +++ /dev/null @@ -1,43 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 - -// <string> - -// basic_string(basic_string&&) -// noexcept(is_nothrow_move_constructible<allocator_type>::value); - -// This tests a conforming extension - -#include <string> -#include <cassert> - -#include "test_macros.h" -#include "test_allocator.h" - -int main() -{ - { - typedef std::string C; - static_assert(std::is_nothrow_move_constructible<C>::value, ""); - } - { - typedef std::basic_string<char, std::char_traits<char>, test_allocator<char>> C; - static_assert(std::is_nothrow_move_constructible<C>::value, ""); - } - { - typedef std::basic_string<char, std::char_traits<char>, limited_allocator<char, 10>> C; -#if TEST_STD_VER <= 14 - static_assert(!std::is_nothrow_move_constructible<C>::value, ""); -#else - static_assert( std::is_nothrow_move_constructible<C>::value, ""); -#endif - } -} diff --git a/test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp b/test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp deleted file mode 100644 index d9d451dc71120..0000000000000 --- a/test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp +++ /dev/null @@ -1,89 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> - -// basic_string(const charT* s, const Allocator& a = Allocator()); - -#include <string> -#include <stdexcept> -#include <algorithm> -#include <cassert> -#include <cstddef> - -#include "test_macros.h" -#include "test_allocator.h" -#include "min_allocator.h" - -template <class charT> -void -test(const charT* s) -{ - typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S; - typedef typename S::traits_type T; - typedef typename S::allocator_type A; - std::size_t n = T::length(s); - S s2(s); - LIBCPP_ASSERT(s2.__invariants()); - assert(s2.size() == n); - assert(T::compare(s2.data(), s, n) == 0); - assert(s2.get_allocator() == A()); - assert(s2.capacity() >= s2.size()); -} - -template <class charT, class A> -void -test(const charT* s, const A& a) -{ - typedef std::basic_string<charT, std::char_traits<charT>, A> S; - typedef typename S::traits_type T; - std::size_t n = T::length(s); - S s2(s, a); - LIBCPP_ASSERT(s2.__invariants()); - assert(s2.size() == n); - assert(T::compare(s2.data(), s, n) == 0); - assert(s2.get_allocator() == a); - assert(s2.capacity() >= s2.size()); -} - -int main() -{ - { - typedef test_allocator<char> A; - - test(""); - test("", A(2)); - - test("1"); - test("1", A(2)); - - test("1234567980"); - test("1234567980", A(2)); - - test("123456798012345679801234567980123456798012345679801234567980"); - test("123456798012345679801234567980123456798012345679801234567980", A(2)); - } -#if TEST_STD_VER >= 11 - { - typedef min_allocator<char> A; - - test(""); - test("", A()); - - test("1"); - test("1", A()); - - test("1234567980"); - test("1234567980", A()); - - test("123456798012345679801234567980123456798012345679801234567980"); - test("123456798012345679801234567980123456798012345679801234567980", A()); - } -#endif -} diff --git a/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp b/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp deleted file mode 100644 index 506ab9374002e..0000000000000 --- a/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp +++ /dev/null @@ -1,73 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> - -// basic_string<charT,traits,Allocator>& -// operator=(const charT* s); - -#include <string> -#include <cassert> - -#include "test_macros.h" -#include "min_allocator.h" - -template <class S> -void -test(S s1, const typename S::value_type* s2) -{ - typedef typename S::traits_type T; - s1 = s2; - LIBCPP_ASSERT(s1.__invariants()); - assert(s1.size() == T::length(s2)); - assert(T::compare(s1.data(), s2, s1.size()) == 0); - assert(s1.capacity() >= s1.size()); -} - -int main() -{ - { - typedef std::string S; - test(S(), ""); - test(S("1"), ""); - test(S(), "1"); - test(S("1"), "2"); - test(S("1"), "2"); - - test(S(), - "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); - test(S("123456789"), - "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), - "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890" - "1234567890123456789012345678901234567890123456789012345678901234567890"), - "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); - } -#if TEST_STD_VER >= 11 - { - typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; - test(S(), ""); - test(S("1"), ""); - test(S(), "1"); - test(S("1"), "2"); - test(S("1"), "2"); - - test(S(), - "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); - test(S("123456789"), - "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), - "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890" - "1234567890123456789012345678901234567890123456789012345678901234567890"), - "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); - } -#endif -} diff --git a/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp b/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp deleted file mode 100644 index 6d660fd10e8e5..0000000000000 --- a/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp +++ /dev/null @@ -1,94 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> - -// basic_string(const charT* s, size_type n, const Allocator& a = Allocator()); - -#include <string> -#include <stdexcept> -#include <algorithm> -#include <cassert> - -#include "test_macros.h" -#include "test_allocator.h" -#include "min_allocator.h" - -template <class charT> -void -test(const charT* s, unsigned n) -{ - typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S; - typedef typename S::traits_type T; - typedef typename S::allocator_type A; - S s2(s, n); - LIBCPP_ASSERT(s2.__invariants()); - assert(s2.size() == n); - assert(T::compare(s2.data(), s, n) == 0); - assert(s2.get_allocator() == A()); - assert(s2.capacity() >= s2.size()); -} - -template <class charT, class A> -void -test(const charT* s, unsigned n, const A& a) -{ - typedef std::basic_string<charT, std::char_traits<charT>, A> S; - typedef typename S::traits_type T; - S s2(s, n, a); - LIBCPP_ASSERT(s2.__invariants()); - assert(s2.size() == n); - assert(T::compare(s2.data(), s, n) == 0); - assert(s2.get_allocator() == a); - assert(s2.capacity() >= s2.size()); -} - -int main() -{ - { - typedef test_allocator<char> A; - - test("", 0); - test("", 0, A(2)); - - test("1", 1); - test("1", 1, A(2)); - - test("1234567980", 10); - test("1234567980", 10, A(2)); - - test("123456798012345679801234567980123456798012345679801234567980", 60); - test("123456798012345679801234567980123456798012345679801234567980", 60, A(2)); - } -#if TEST_STD_VER >= 11 - { - typedef min_allocator<char> A; - - test("", 0); - test("", 0, A()); - - test("1", 1); - test("1", 1, A()); - - test("1234567980", 10); - test("1234567980", 10, A()); - - test("123456798012345679801234567980123456798012345679801234567980", 60); - test("123456798012345679801234567980123456798012345679801234567980", 60, A()); - } -#endif - -#if TEST_STD_VER > 3 - { // LWG 2946 - std::string s({"abc", 1}); - assert(s.size() == 1); - assert(s == "a"); - } -#endif -} diff --git a/test/std/strings/basic.string/string.cons/size_char_alloc.pass.cpp b/test/std/strings/basic.string/string.cons/size_char_alloc.pass.cpp deleted file mode 100644 index 2adf0049a0b5c..0000000000000 --- a/test/std/strings/basic.string/string.cons/size_char_alloc.pass.cpp +++ /dev/null @@ -1,124 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> - -// basic_string(size_type n, charT c, const Allocator& a = Allocator()); - -#include <string> -#include <stdexcept> -#include <algorithm> -#include <cassert> -#include <cstddef> - -#include "test_macros.h" -#include "test_allocator.h" -#include "min_allocator.h" - -template <class charT> -void -test(unsigned n, charT c) -{ - typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S; - typedef typename S::allocator_type A; - S s2(n, c); - LIBCPP_ASSERT(s2.__invariants()); - assert(s2.size() == n); - for (unsigned i = 0; i < n; ++i) - assert(s2[i] == c); - assert(s2.get_allocator() == A()); - assert(s2.capacity() >= s2.size()); -} - -template <class charT, class A> -void -test(unsigned n, charT c, const A& a) -{ - typedef std::basic_string<charT, std::char_traits<charT>, A> S; - S s2(n, c, a); - LIBCPP_ASSERT(s2.__invariants()); - assert(s2.size() == n); - for (unsigned i = 0; i < n; ++i) - assert(s2[i] == c); - assert(s2.get_allocator() == a); - assert(s2.capacity() >= s2.size()); -} - -template <class Tp> -void -test(Tp n, Tp c) -{ - typedef char charT; - typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S; - typedef typename S::allocator_type A; - S s2(n, c); - LIBCPP_ASSERT(s2.__invariants()); - assert(s2.size() == static_cast<std::size_t>(n)); - for (int i = 0; i < n; ++i) - assert(s2[i] == c); - assert(s2.get_allocator() == A()); - assert(s2.capacity() >= s2.size()); -} - -template <class Tp, class A> -void -test(Tp n, Tp c, const A& a) -{ - typedef char charT; - typedef std::basic_string<charT, std::char_traits<charT>, A> S; - S s2(n, c, a); - LIBCPP_ASSERT(s2.__invariants()); - assert(s2.size() == static_cast<std::size_t>(n)); - for (int i = 0; i < n; ++i) - assert(s2[i] == c); - assert(s2.get_allocator() == a); - assert(s2.capacity() >= s2.size()); -} - -int main() -{ - { - typedef test_allocator<char> A; - - test(0, 'a'); - test(0, 'a', A(2)); - - test(1, 'a'); - test(1, 'a', A(2)); - - test(10, 'a'); - test(10, 'a', A(2)); - - test(100, 'a'); - test(100, 'a', A(2)); - - test(static_cast<char>(100), static_cast<char>(65)); - test(static_cast<char>(100), static_cast<char>(65), A(3)); - } -#if TEST_STD_VER >= 11 - { - typedef min_allocator<char> A; - - test(0, 'a'); - test(0, 'a', A()); - - test(1, 'a'); - test(1, 'a', A()); - - test(10, 'a'); - test(10, 'a', A()); - - test(100, 'a'); - test(100, 'a', A()); - - test(static_cast<char>(100), static_cast<char>(65)); - test(static_cast<char>(100), static_cast<char>(65), A()); - } -#endif -} diff --git a/test/std/strings/basic.string/string.cons/string_view.fail.cpp b/test/std/strings/basic.string/string.cons/string_view.fail.cpp deleted file mode 100644 index 3d3bf4178fd21..0000000000000 --- a/test/std/strings/basic.string/string.cons/string_view.fail.cpp +++ /dev/null @@ -1,23 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> - -// explicit basic_string(basic_string_view<CharT, traits> sv, const Allocator& a = Allocator()); - -#include <string> -#include <string_view> - -void foo ( const string &s ) {} - -int main() -{ - std::string_view sv = "ABCDE"; - foo(sv); // requires implicit conversion from string_view to string -} diff --git a/test/std/strings/basic.string/string.cons/string_view.pass.cpp b/test/std/strings/basic.string/string.cons/string_view.pass.cpp deleted file mode 100644 index 78ceae70e2d1a..0000000000000 --- a/test/std/strings/basic.string/string.cons/string_view.pass.cpp +++ /dev/null @@ -1,111 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> - -// explicit basic_string(basic_string_view<CharT, traits> sv, const Allocator& a = Allocator()); - -#include <string> -#include <string_view> -#include <stdexcept> -#include <algorithm> -#include <cassert> - -#include "test_macros.h" -#include "test_allocator.h" -#include "min_allocator.h" - -template <class charT> -void -test(std::basic_string_view<charT> sv) -{ - typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S; - typedef typename S::traits_type T; - typedef typename S::allocator_type A; - { - S s2(sv); - LIBCPP_ASSERT(s2.__invariants()); - assert(s2.size() == sv.size()); - assert(T::compare(s2.data(), sv.data(), sv.size()) == 0); - assert(s2.get_allocator() == A()); - assert(s2.capacity() >= s2.size()); - } - { - S s2; - s2 = sv; - LIBCPP_ASSERT(s2.__invariants()); - assert(s2.size() == sv.size()); - assert(T::compare(s2.data(), sv.data(), sv.size()) == 0); - assert(s2.get_allocator() == A()); - assert(s2.capacity() >= s2.size()); - } -} - -template <class charT, class A> -void -test(std::basic_string_view<charT> sv, const A& a) -{ - typedef std::basic_string<charT, std::char_traits<charT>, A> S; - typedef typename S::traits_type T; - { - S s2(sv, a); - LIBCPP_ASSERT(s2.__invariants()); - assert(s2.size() == sv.size()); - assert(T::compare(s2.data(), sv.data(), sv.size()) == 0); - assert(s2.get_allocator() == a); - assert(s2.capacity() >= s2.size()); - } - { - S s2(a); - s2 = sv; - LIBCPP_ASSERT(s2.__invariants()); - assert(s2.size() == sv.size()); - assert(T::compare(s2.data(), sv.data(), sv.size()) == 0); - assert(s2.get_allocator() == a); - assert(s2.capacity() >= s2.size()); - } -} - -int main() -{ - { - typedef test_allocator<char> A; - typedef std::basic_string_view<char, std::char_traits<char> > SV; - - test(SV("")); - test(SV(""), A(2)); - - test(SV("1")); - test(SV("1") ,A(2)); - - test(SV("1234567980")); - test(SV("1234567980"), A(2)); - - test(SV("123456798012345679801234567980123456798012345679801234567980")); - test(SV("123456798012345679801234567980123456798012345679801234567980"), A(2)); - } -#if TEST_STD_VER >= 11 - { - typedef min_allocator<char> A; - typedef std::basic_string_view<char, std::char_traits<char> > SV; - - test(SV("")); - test(SV(""), A()); - - test(SV("1")); - test(SV("1") ,A()); - - test(SV("1234567980")); - test(SV("1234567980"), A()); - - test(SV("123456798012345679801234567980123456798012345679801234567980")); - test(SV("123456798012345679801234567980123456798012345679801234567980"), A()); - } -#endif -} diff --git a/test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp b/test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp deleted file mode 100644 index 1d400b79b1c84..0000000000000 --- a/test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp +++ /dev/null @@ -1,74 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> - -// basic_string<charT,traits,Allocator>& operator=(basic_string_view<charT, traits> sv); - -#include <string> -#include <cassert> - -#include "test_macros.h" -#include "min_allocator.h" - -template <class S, class SV> -void -test(S s1, SV sv) -{ - typedef typename S::traits_type T; - s1 = sv; - LIBCPP_ASSERT(s1.__invariants()); - assert(s1.size() == sv.size()); - assert(T::compare(s1.data(), sv.data(), s1.size()) == 0); - assert(s1.capacity() >= s1.size()); -} - -int main() -{ - { - typedef std::string S; - typedef std::string_view SV; - test(S(), SV("")); - test(S("1"), SV("")); - test(S(), SV("1")); - test(S("1"), SV("2")); - test(S("1"), SV("2")); - - test(S(), - SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - test(S("123456789"), - SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), - SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890" - "1234567890123456789012345678901234567890123456789012345678901234567890"), - SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - } -#if TEST_STD_VER >= 11 - { - typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; - typedef std::string_view SV; - test(S(), SV("")); - test(S("1"), SV("")); - test(S(), SV("1")); - test(S("1"), SV("2")); - test(S("1"), SV("2")); - - test(S(), - SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - test(S("123456789"), - SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), - SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890" - "1234567890123456789012345678901234567890123456789012345678901234567890"), - SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); - } -#endif -} diff --git a/test/std/strings/basic.string/string.cons/string_view_deduction.fail.cpp b/test/std/strings/basic.string/string.cons/string_view_deduction.fail.cpp deleted file mode 100644 index b2fece8da8c25..0000000000000 --- a/test/std/strings/basic.string/string.cons/string_view_deduction.fail.cpp +++ /dev/null @@ -1,41 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> -// UNSUPPORTED: c++98, c++03, c++11, c++14 -// XFAIL: libcpp-no-deduction-guides - -// template<class InputIterator> -// basic_string(InputIterator begin, InputIterator end, -// const Allocator& a = Allocator()); - -// template<class charT, -// class traits, -// class Allocator = allocator<charT> -// > -// basic_string(basic_string_view<charT, traits>, const Allocator& = Allocator()) -// -> basic_string<charT, traits, Allocator>; -// -// The deduction guide shall not participate in overload resolution if Allocator -// is a type that does not qualify as an allocator. - - -#include <string> -#include <string_view> -#include <iterator> -#include <cassert> -#include <cstddef> - -int main() -{ - { - std::string_view sv = "12345678901234"; - std::basic_string s1{sv, 23}; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'basic_string'}} - } -} diff --git a/test/std/strings/basic.string/string.cons/string_view_deduction.pass.cpp b/test/std/strings/basic.string/string.cons/string_view_deduction.pass.cpp deleted file mode 100644 index a1f3c4b51f946..0000000000000 --- a/test/std/strings/basic.string/string.cons/string_view_deduction.pass.cpp +++ /dev/null @@ -1,107 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> -// UNSUPPORTED: c++98, c++03, c++11, c++14 -// XFAIL: libcpp-no-deduction-guides - -// template<class InputIterator> -// basic_string(InputIterator begin, InputIterator end, -// const Allocator& a = Allocator()); - -// template<class charT, -// class traits, -// class Allocator = allocator<charT> -// > -// basic_string(basic_string_view<charT, traits>, const Allocator& = Allocator()) -// -> basic_string<charT, traits, Allocator>; -// -// The deduction guide shall not participate in overload resolution if Allocator -// is a type that does not qualify as an allocator. - - -#include <string> -#include <string_view> -#include <iterator> -#include <memory> -#include <type_traits> -#include <cassert> -#include <cstddef> - -#include "test_macros.h" -#include "test_allocator.h" -#include "../input_iterator.h" -#include "min_allocator.h" - -int main() -{ - { - std::string_view sv = "12345678901234"; - std::basic_string s1(sv); - using S = decltype(s1); // what type did we get? - static_assert(std::is_same_v<S::value_type, char>, ""); - static_assert(std::is_same_v<S::traits_type, std::char_traits<char>>, ""); - static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, ""); - assert(s1.size() == sv.size()); - assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0); - } - - { - std::string_view sv = "12345678901234"; - std::basic_string s1{sv, std::allocator<char>{}}; - using S = decltype(s1); // what type did we get? - static_assert(std::is_same_v<S::value_type, char>, ""); - static_assert(std::is_same_v<S::traits_type, std::char_traits<char>>, ""); - static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, ""); - assert(s1.size() == sv.size()); - assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0); - } - { - std::wstring_view sv = L"12345678901234"; - std::basic_string s1{sv, test_allocator<wchar_t>{}}; - using S = decltype(s1); // what type did we get? - static_assert(std::is_same_v<S::value_type, wchar_t>, ""); - static_assert(std::is_same_v<S::traits_type, std::char_traits<wchar_t>>, ""); - static_assert(std::is_same_v<S::allocator_type, test_allocator<wchar_t>>, ""); - assert(s1.size() == sv.size()); - assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0); - } -#if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L - { - std::u8string_view sv = u8"12345678901234"; - std::basic_string s1{sv, min_allocator<char8_t>{}}; - using S = decltype(s1); // what type did we get? - static_assert(std::is_same_v<S::value_type, char8_t>, ""); - static_assert(std::is_same_v<S::traits_type, std::char_traits<char8_t>>, ""); - static_assert(std::is_same_v<S::allocator_type, min_allocator<char8_t>>, ""); - assert(s1.size() == sv.size()); - assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0); - } -#endif - { - std::u16string_view sv = u"12345678901234"; - std::basic_string s1{sv, min_allocator<char16_t>{}}; - using S = decltype(s1); // what type did we get? - static_assert(std::is_same_v<S::value_type, char16_t>, ""); - static_assert(std::is_same_v<S::traits_type, std::char_traits<char16_t>>, ""); - static_assert(std::is_same_v<S::allocator_type, min_allocator<char16_t>>, ""); - assert(s1.size() == sv.size()); - assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0); - } - { - std::u32string_view sv = U"12345678901234"; - std::basic_string s1{sv, explicit_allocator<char32_t>{}}; - using S = decltype(s1); // what type did we get? - static_assert(std::is_same_v<S::value_type, char32_t>, ""); - static_assert(std::is_same_v<S::traits_type, std::char_traits<char32_t>>, ""); - static_assert(std::is_same_v<S::allocator_type, explicit_allocator<char32_t>>, ""); - assert(s1.size() == sv.size()); - assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0); - } -} diff --git a/test/std/strings/basic.string/string.cons/string_view_size_size_deduction.fail.cpp b/test/std/strings/basic.string/string.cons/string_view_size_size_deduction.fail.cpp deleted file mode 100644 index 17cb7dd167e12..0000000000000 --- a/test/std/strings/basic.string/string.cons/string_view_size_size_deduction.fail.cpp +++ /dev/null @@ -1,47 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> -// UNSUPPORTED: c++98, c++03, c++11, c++14 -// XFAIL: libcpp-no-deduction-guides - -// template<class InputIterator> -// basic_string(InputIterator begin, InputIterator end, -// const Allocator& a = Allocator()); - -// template<class charT, -// class traits, -// class Allocator = allocator<charT> -// > -// basic_string(basic_string_view<charT, traits>, -// typename see below::size_type, -// typename see below::size_type, -// const Allocator& = Allocator()) -// -> basic_string<charT, traits, Allocator>; -// -// A size_type parameter type in a basic_string deduction guide refers to the size_type -// member type of the type deduced by the deduction guide. -// -// The deduction guide shall not participate in overload resolution if Allocator -// is a type that does not qualify as an allocator. - - -#include <string> -#include <string_view> -#include <iterator> -#include <cassert> -#include <cstddef> - -int main() -{ - { - std::string_view sv = "12345678901234"; - std::basic_string s1{sv, 0, 4, 23}; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'basic_string'}} - } -} diff --git a/test/std/strings/basic.string/string.cons/string_view_size_size_deduction.pass.cpp b/test/std/strings/basic.string/string.cons/string_view_size_size_deduction.pass.cpp deleted file mode 100644 index fd9684e1fa999..0000000000000 --- a/test/std/strings/basic.string/string.cons/string_view_size_size_deduction.pass.cpp +++ /dev/null @@ -1,111 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> -// UNSUPPORTED: c++98, c++03, c++11, c++14 -// XFAIL: libcpp-no-deduction-guides - -// template<class InputIterator> -// basic_string(InputIterator begin, InputIterator end, -// const Allocator& a = Allocator()); - -// template<class charT, -// class traits, -// class Allocator = allocator<charT> -// > -// basic_string(basic_string_view<charT, traits>, -// typename see below::size_type, -// typename see below::size_type, -// const Allocator& = Allocator()) -// -> basic_string<charT, traits, Allocator>; -// -// A size_type parameter type in a basic_string deduction guide refers to the size_type -// member type of the type deduced by the deduction guide. -// -// The deduction guide shall not participate in overload resolution if Allocator -// is a type that does not qualify as an allocator. - - -#include <string> -#include <string_view> -#include <iterator> -#include <cassert> -#include <cstddef> - -#include "test_macros.h" -#include "test_allocator.h" -#include "../input_iterator.h" -#include "min_allocator.h" - -int main() -{ - { - std::string_view sv = "12345678901234"; - std::basic_string s1{sv, 0, 4}; - using S = decltype(s1); // what type did we get? - static_assert(std::is_same_v<S::value_type, char>, ""); - static_assert(std::is_same_v<S::traits_type, std::char_traits<char>>, ""); - static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, ""); - assert(s1.size() == 4); - assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0); - } - - { - std::string_view sv = "12345678901234"; - std::basic_string s1{sv, 0, 4, std::allocator<char>{}}; - using S = decltype(s1); // what type did we get? - static_assert(std::is_same_v<S::value_type, char>, ""); - static_assert(std::is_same_v<S::traits_type, std::char_traits<char>>, ""); - static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, ""); - assert(s1.size() == 4); - assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0); - } - { - std::wstring_view sv = L"12345678901234"; - std::basic_string s1{sv, 0, 4, test_allocator<wchar_t>{}}; - using S = decltype(s1); // what type did we get? - static_assert(std::is_same_v<S::value_type, wchar_t>, ""); - static_assert(std::is_same_v<S::traits_type, std::char_traits<wchar_t>>, ""); - static_assert(std::is_same_v<S::allocator_type, test_allocator<wchar_t>>, ""); - assert(s1.size() == 4); - assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0); - } -#if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L - { - std::u8string_view sv = u8"12345678901234"; - std::basic_string s1{sv, 0, 4, min_allocator<char8_t>{}}; - using S = decltype(s1); // what type did we get? - static_assert(std::is_same_v<S::value_type, char8_t>, ""); - static_assert(std::is_same_v<S::traits_type, std::char_traits<char8_t>>, ""); - static_assert(std::is_same_v<S::allocator_type, min_allocator<char8_t>>, ""); - assert(s1.size() == 4); - assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0); - } -#endif - { - std::u16string_view sv = u"12345678901234"; - std::basic_string s1{sv, 0, 4, min_allocator<char16_t>{}}; - using S = decltype(s1); // what type did we get? - static_assert(std::is_same_v<S::value_type, char16_t>, ""); - static_assert(std::is_same_v<S::traits_type, std::char_traits<char16_t>>, ""); - static_assert(std::is_same_v<S::allocator_type, min_allocator<char16_t>>, ""); - assert(s1.size() == 4); - assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0); - } - { - std::u32string_view sv = U"12345678901234"; - std::basic_string s1{sv, 0, 4, explicit_allocator<char32_t>{}}; - using S = decltype(s1); // what type did we get? - static_assert(std::is_same_v<S::value_type, char32_t>, ""); - static_assert(std::is_same_v<S::traits_type, std::char_traits<char32_t>>, ""); - static_assert(std::is_same_v<S::allocator_type, explicit_allocator<char32_t>>, ""); - assert(s1.size() == 4); - assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0); - } -} diff --git a/test/std/strings/basic.string/string.cons/substr.pass.cpp b/test/std/strings/basic.string/string.cons/substr.pass.cpp deleted file mode 100644 index 13a9a4b96aaba..0000000000000 --- a/test/std/strings/basic.string/string.cons/substr.pass.cpp +++ /dev/null @@ -1,228 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <string> - -// basic_string(const basic_string<charT,traits,Allocator>& str, -// size_type pos, size_type n, -// const Allocator& a = Allocator()); -// -// basic_string(const basic_string<charT,traits,Allocator>& str, -// size_type pos, -// const Allocator& a = Allocator()); - -#include <string> -#include <stdexcept> -#include <algorithm> -#include <vector> -#include <scoped_allocator> -#include <cassert> - -#include "test_macros.h" -#include "test_allocator.h" -#include "min_allocator.h" - -template <class S> -void -test(S str, unsigned pos) -{ - typedef typename S::traits_type T; - typedef typename S::allocator_type A; - - if (pos <= str.size()) - { - S s2(str, pos); - LIBCPP_ASSERT(s2.__invariants()); - typename S::size_type rlen = str.size() - pos; - assert(s2.size() == rlen); - assert(T::compare(s2.data(), str.data() + pos, rlen) == 0); - assert(s2.get_allocator() == A()); - assert(s2.capacity() >= s2.size()); - } -#ifndef TEST_HAS_NO_EXCEPTIONS - else - { - try - { - S s2(str, pos); - assert(false); - } - catch (std::out_of_range&) - { - assert(pos > str.size()); - } - } -#endif -} - -template <class S> -void -test(S str, unsigned pos, unsigned n) -{ - typedef typename S::traits_type T; - typedef typename S::allocator_type A; - if (pos <= str.size()) - { - S s2(str, pos, n); - LIBCPP_ASSERT(s2.__invariants()); - typename S::size_type rlen = std::min<typename S::size_type>(str.size() - pos, n); - assert(s2.size() == rlen); - assert(T::compare(s2.data(), str.data() + pos, rlen) == 0); - assert(s2.get_allocator() == A()); - assert(s2.capacity() >= s2.size()); - } -#ifndef TEST_HAS_NO_EXCEPTIONS - else - { - try - { - S s2(str, pos, n); - assert(false); - } - catch (std::out_of_range&) - { - assert(pos > str.size()); - } - } -#endif -} - -template <class S> -void -test(S str, unsigned pos, unsigned n, const typename S::allocator_type& a) -{ - typedef typename S::traits_type T; - - if (pos <= str.size()) - { - S s2(str, pos, n, a); - LIBCPP_ASSERT(s2.__invariants()); - typename S::size_type rlen = std::min<typename S::size_type>(str.size() - pos, n); - assert(s2.size() == rlen); - assert(T::compare(s2.data(), str.data() + pos, rlen) == 0); - assert(s2.get_allocator() == a); - assert(s2.capacity() >= s2.size()); - } -#ifndef TEST_HAS_NO_EXCEPTIONS - else - { - try - { - S s2(str, pos, n, a); - assert(false); - } - catch (std::out_of_range&) - { - assert(pos > str.size()); - } - } -#endif -} - -#if TEST_STD_VER >= 11 -#ifndef TEST_HAS_NO_EXCEPTIONS -void test2583() -{ // LWG #2583 - typedef std::basic_string<char, std::char_traits<char>, test_allocator<char> > StringA; - std::vector<StringA, std::scoped_allocator_adaptor<test_allocator<StringA>>> 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 -#endif - -int main() -{ - { - typedef test_allocator<char> A; - typedef std::basic_string<char, std::char_traits<char>, A> S; - - test(S(A(3)), 0); - test(S(A(3)), 1); - test(S("1", A(5)), 0); - test(S("1", A(5)), 1); - test(S("1", A(5)), 2); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 0); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 5); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 500); - - test(S(A(3)), 0, 0); - test(S(A(3)), 0, 1); - test(S(A(3)), 1, 0); - test(S(A(3)), 1, 1); - test(S(A(3)), 1, 2); - test(S("1", A(5)), 0, 0); - test(S("1", A(5)), 0, 1); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 0); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 1); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 10); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 100); - - test(S(A(3)), 0, 0, A(4)); - test(S(A(3)), 0, 1, A(4)); - test(S(A(3)), 1, 0, A(4)); - test(S(A(3)), 1, 1, A(4)); - test(S(A(3)), 1, 2, A(4)); - test(S("1", A(5)), 0, 0, A(6)); - test(S("1", A(5)), 0, 1, A(6)); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 0, A(8)); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 1, A(8)); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 10, A(8)); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 100, A(8)); - } -#if TEST_STD_VER >= 11 - { - typedef min_allocator<char> A; - typedef std::basic_string<char, std::char_traits<char>, A> S; - - test(S(A()), 0); - test(S(A()), 1); - test(S("1", A()), 0); - test(S("1", A()), 1); - test(S("1", A()), 2); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 0); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 5); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 500); - - test(S(A()), 0, 0); - test(S(A()), 0, 1); - test(S(A()), 1, 0); - test(S(A()), 1, 1); - test(S(A()), 1, 2); - test(S("1", A()), 0, 0); - test(S("1", A()), 0, 1); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 0); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 1); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 10); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 100); - - test(S(A()), 0, 0, A()); - test(S(A()), 0, 1, A()); - test(S(A()), 1, 0, A()); - test(S(A()), 1, 1, A()); - test(S(A()), 1, 2, A()); - test(S("1", A()), 0, 0, A()); - test(S("1", A()), 0, 1, A()); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 0, A()); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 1, A()); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 10, A()); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 100, A()); - } - -#ifndef TEST_HAS_NO_EXCEPTIONS - test2583(); -#endif -#endif -} |
