diff --git a/libcxx/test/libcxx/strings/basic.string/string.access/assert.back.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.access/assert.back.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.access/assert.back.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.access/assert.back.pass.cpp @@ -20,17 +20,15 @@ #include "check_assertion.h" #include "min_allocator.h" +template +void test() { + S s; + TEST_LIBCPP_ASSERT_FAILURE(s.back(), "string::back(): string is empty"); +} + int main(int, char**) { - { - std::string s; - TEST_LIBCPP_ASSERT_FAILURE(s.back(), "string::back(): string is empty"); - } - - { - typedef std::basic_string, min_allocator > S; - S s; - TEST_LIBCPP_ASSERT_FAILURE(s.back(), "string::back(): string is empty"); - } + test(); + test, min_allocator > >(); return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.access/assert.cback.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.access/assert.cback.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.access/assert.cback.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.access/assert.cback.pass.cpp @@ -20,17 +20,15 @@ #include "check_assertion.h" #include "min_allocator.h" +template +void test() { + const S s; + TEST_LIBCPP_ASSERT_FAILURE(s.back(), "string::back(): string is empty"); +} + int main(int, char**) { - { - std::string const s; - TEST_LIBCPP_ASSERT_FAILURE(s.back(), "string::back(): string is empty"); - } - - { - typedef std::basic_string, min_allocator > S; - const S s; - TEST_LIBCPP_ASSERT_FAILURE(s.back(), "string::back(): string is empty"); - } + test(); + test, min_allocator > >(); return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.access/assert.cfront.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.access/assert.cfront.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.access/assert.cfront.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.access/assert.cfront.pass.cpp @@ -20,18 +20,15 @@ #include "check_assertion.h" #include "min_allocator.h" +template +void test() { + const S s; + TEST_LIBCPP_ASSERT_FAILURE(s.front(), "string::front(): string is empty"); +} + int main(int, char**) { - { - typedef std::string S; - const S s; - TEST_LIBCPP_ASSERT_FAILURE(s.front(), "string::front(): string is empty"); - } - - { - typedef std::basic_string, min_allocator > S; - const S s; - TEST_LIBCPP_ASSERT_FAILURE(s.front(), "string::front(): string is empty"); - } + test(); + test, min_allocator > >(); return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.access/assert.cindex.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.access/assert.cindex.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.access/assert.cindex.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.access/assert.cindex.pass.cpp @@ -21,20 +21,16 @@ #include "check_assertion.h" #include "min_allocator.h" +template +void test() { + const S s; + assert(s[0] == 0); + TEST_LIBCPP_ASSERT_FAILURE(s[1], "string index out of bounds"); +} + int main(int, char**) { - { - typedef std::basic_string, min_allocator > S; - const S s; - assert(s[0] == 0); - TEST_LIBCPP_ASSERT_FAILURE(s[1], "string index out of bounds"); - } - - { - typedef std::string S; - const S s; - assert(s[0] == 0); - TEST_LIBCPP_ASSERT_FAILURE(s[1], "string index out of bounds"); - } + test(); + test, min_allocator > >(); return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.access/assert.front.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.access/assert.front.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.access/assert.front.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.access/assert.front.pass.cpp @@ -21,18 +21,15 @@ #include "check_assertion.h" #include "min_allocator.h" +template +void test() { + S s; + TEST_LIBCPP_ASSERT_FAILURE(s.front(), "string::front(): string is empty"); +} + int main(int, char**) { - { - typedef std::string S; - S s; - TEST_LIBCPP_ASSERT_FAILURE(s.front(), "string::front(): string is empty"); - } - - { - typedef std::basic_string, min_allocator > S; - S s; - TEST_LIBCPP_ASSERT_FAILURE(s.front(), "string::front(): string is empty"); - } + test(); + test, min_allocator > >(); return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.access/assert.index.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.access/assert.index.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.access/assert.index.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.access/assert.index.pass.cpp @@ -21,20 +21,16 @@ #include "check_assertion.h" #include "min_allocator.h" +template +void test() { + S s; + assert(s[0] == 0); + TEST_LIBCPP_ASSERT_FAILURE(s[1], "string index out of bounds"); +} + int main(int, char**) { - { - typedef std::string S; - S s; - assert(s[0] == 0); - TEST_LIBCPP_ASSERT_FAILURE(s[1], "string index out of bounds"); - } - - { - typedef std::basic_string, min_allocator > S; - S s; - assert(s[0] == 0); - TEST_LIBCPP_ASSERT_FAILURE(s[1], "string index out of bounds"); - } + test(); + test, min_allocator > >(); return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.add.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.add.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.add.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.add.pass.cpp @@ -19,26 +19,19 @@ #include "check_assertion.h" #include "min_allocator.h" +template +void test() { + C c(1, '\0'); + typename C::iterator i = c.begin(); + i += 1; + assert(i == c.end()); + i = c.begin(); + TEST_LIBCPP_ASSERT_FAILURE(i += 2, "Attempted to add/subtract an iterator outside its valid range"); +} + int main(int, char**) { - { - typedef std::string C; - C c(1, '\0'); - C::iterator i = c.begin(); - i += 1; - assert(i == c.end()); - i = c.begin(); - TEST_LIBCPP_ASSERT_FAILURE(i += 2, "Attempted to add/subtract an iterator outside its valid range"); - } - - { - typedef std::basic_string, min_allocator > C; - C c(1, '\0'); - C::iterator i = c.begin(); - i += 1; - assert(i == c.end()); - i = c.begin(); - TEST_LIBCPP_ASSERT_FAILURE(i += 2, "Attempted to add/subtract an iterator outside its valid range"); - } + test(); + test, min_allocator > >(); return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.compare.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.compare.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.compare.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.compare.pass.cpp @@ -18,20 +18,16 @@ #include "check_assertion.h" #include "min_allocator.h" +template +void test() { + S s1; + S s2; + TEST_LIBCPP_ASSERT_FAILURE(s1.begin() < s2.begin(), "Attempted to compare incomparable iterators"); +} + int main(int, char**) { - { - typedef std::string S; - S s1; - S s2; - TEST_LIBCPP_ASSERT_FAILURE(s1.begin() < s2.begin(), "Attempted to compare incomparable iterators"); - } - - { - typedef std::basic_string, min_allocator > S; - S s1; - S s2; - TEST_LIBCPP_ASSERT_FAILURE(s1.begin() < s2.begin(), "Attempted to compare incomparable iterators"); - } + test(); + test, min_allocator > >(); return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.decrement.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.decrement.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.decrement.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.decrement.pass.cpp @@ -19,24 +19,18 @@ #include "check_assertion.h" #include "min_allocator.h" +template +void test() { + C c(1, '\0'); + typename C::iterator i = c.end(); + --i; + assert(i == c.begin()); + TEST_LIBCPP_ASSERT_FAILURE(--i, "Attempted to decrement a non-decrementable iterator"); +} + int main(int, char**) { - { - typedef std::string C; - C c(1, '\0'); - C::iterator i = c.end(); - --i; - assert(i == c.begin()); - TEST_LIBCPP_ASSERT_FAILURE(--i, "Attempted to decrement a non-decrementable iterator"); - } - - { - typedef std::basic_string, min_allocator > C; - C c(1, '\0'); - C::iterator i = c.end(); - --i; - assert(i == c.begin()); - TEST_LIBCPP_ASSERT_FAILURE(--i, "Attempted to decrement a non-decrementable iterator"); - } + test(); + test, min_allocator > >(); return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.dereference.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.dereference.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.dereference.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.dereference.pass.cpp @@ -18,20 +18,16 @@ #include "check_assertion.h" #include "min_allocator.h" +template +void test() { + C c(1, '\0'); + typename C::iterator i = c.end(); + TEST_LIBCPP_ASSERT_FAILURE(*i, "Attempted to dereference a non-dereferenceable iterator"); +} + int main(int, char**) { - { - typedef std::string C; - C c(1, '\0'); - C::iterator i = c.end(); - TEST_LIBCPP_ASSERT_FAILURE(*i, "Attempted to dereference a non-dereferenceable iterator"); - } - - { - typedef std::basic_string, min_allocator > C; - C c(1, '\0'); - C::iterator i = c.end(); - TEST_LIBCPP_ASSERT_FAILURE(*i, "Attempted to dereference a non-dereferenceable iterator"); - } + test(); + test, min_allocator > >(); return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.increment.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.increment.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.increment.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.increment.pass.cpp @@ -19,24 +19,18 @@ #include "check_assertion.h" #include "min_allocator.h" +template +void test() { + C c(1, '\0'); + typename C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + TEST_LIBCPP_ASSERT_FAILURE(++i, "Attempted to increment a non-incrementable iterator"); +} + int main(int, char**) { - { - typedef std::string C; - C c(1, '\0'); - C::iterator i = c.begin(); - ++i; - assert(i == c.end()); - TEST_LIBCPP_ASSERT_FAILURE(++i, "Attempted to increment a non-incrementable iterator"); - } - - { - typedef std::basic_string, min_allocator > C; - C c(1, '\0'); - C::iterator i = c.begin(); - ++i; - assert(i == c.end()); - TEST_LIBCPP_ASSERT_FAILURE(++i, "Attempted to increment a non-incrementable iterator"); - } + test(); + test, min_allocator > >(); return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.index.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.index.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.index.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.index.pass.cpp @@ -19,23 +19,18 @@ #include "check_assertion.h" #include "min_allocator.h" -int main(int, char**) { +template +void test() { using T = decltype(std::uint8_t() - std::uint8_t()); - { - typedef std::string C; - C c(1, '\0'); - C::iterator i = c.begin(); - assert(i[0] == 0); - TEST_LIBCPP_ASSERT_FAILURE(i[1], "Attempted to subscript an iterator outside its valid range"); - } - - { - typedef std::basic_string, min_allocator > C; - C c(1, '\0'); - C::iterator i = c.begin(); - assert(i[0] == 0); - TEST_LIBCPP_ASSERT_FAILURE(i[1], "Attempted to subscript an iterator outside its valid range"); - } + C c(1, '\0'); + C::iterator i = c.begin(); + assert(i[0] == 0); + TEST_LIBCPP_ASSERT_FAILURE(i[1], "Attempted to subscript an iterator outside its valid range"); +} + +int main(int, char**) { + test(); + test, min_allocator > >(); return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.subtract.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.subtract.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.subtract.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.subtract.pass.cpp @@ -18,20 +18,16 @@ #include "check_assertion.h" #include "min_allocator.h" +template +void test() { + S s1; + S s2; + TEST_LIBCPP_ASSERT_FAILURE(s1.begin() - s2.begin(), "Attempted to subtract incompatible iterators"); +} + int main(int, char**) { - { - typedef std::string S; - S s1; - S s2; - TEST_LIBCPP_ASSERT_FAILURE(s1.begin() - s2.begin(), "Attempted to subtract incompatible iterators"); - } - - { - typedef std::basic_string, min_allocator > S; - S s1; - S s2; - TEST_LIBCPP_ASSERT_FAILURE(s1.begin() - s2.begin(), "Attempted to subtract incompatible iterators"); - } + test(); + test, min_allocator > >(); return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.erase_iter.null.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.erase_iter.null.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.erase_iter.null.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.erase_iter.null.pass.cpp @@ -20,19 +20,16 @@ #include "check_assertion.h" #include "min_allocator.h" +template +void test() { + S l1("123"); + typename S::const_iterator i = l1.end(); + TEST_LIBCPP_ASSERT_FAILURE(l1.erase(i), "string::erase(iterator) called with a non-dereferenceable iterator"); +} + int main(int, char**) { - { - typedef std::basic_string, min_allocator > S; - S l1("123"); - S::const_iterator i = l1.end(); - TEST_LIBCPP_ASSERT_FAILURE(l1.erase(i), "string::erase(iterator) called with a non-dereferenceable iterator"); - } - - { - std::string l1("123"); - std::string::const_iterator i = l1.end(); - TEST_LIBCPP_ASSERT_FAILURE(l1.erase(i), "string::erase(iterator) called with a non-dereferenceable iterator"); - } + test(); + test, min_allocator > >(); return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.pop_back.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.pop_back.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.pop_back.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.pop_back.pass.cpp @@ -19,9 +19,14 @@ #include "check_assertion.h" -int main(int, char**) { - std::string s; +template +void test() { + S s; TEST_LIBCPP_ASSERT_FAILURE(s.pop_back(), "string::pop_back(): string is already empty"); +} + +int main(int, char**) { + test(); return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.erase.iter.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.erase.iter.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.erase.iter.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.erase.iter.pass.cpp @@ -18,23 +18,18 @@ #include "check_assertion.h" #include "min_allocator.h" +template +void test() { + S l1("123"); + S l2("123"); + typename S::const_iterator i = l2.begin(); + TEST_LIBCPP_ASSERT_FAILURE( + l1.erase(i), "string::erase(iterator) called with an iterator not referring to this string"); +} + int main(int, char**) { - { - std::string l1("123"); - std::string l2("123"); - std::string::const_iterator i = l2.begin(); - TEST_LIBCPP_ASSERT_FAILURE( - l1.erase(i), "string::erase(iterator) called with an iterator not referring to this string"); - } - - { - typedef std::basic_string, min_allocator > S; - S l1("123"); - S l2("123"); - S::const_iterator i = l2.begin(); - TEST_LIBCPP_ASSERT_FAILURE( - l1.erase(i), "string::erase(iterator) called with an iterator not referring to this string"); - } + test(); + test, min_allocator > >(); return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.erase.iter_iter.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.erase.iter_iter.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.erase.iter_iter.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.erase.iter_iter.pass.cpp @@ -18,64 +18,44 @@ #include "check_assertion.h" #include "min_allocator.h" -int main(int, char**) { +template +void test() { // With first iterator from another container - {{std::string l1("123"); - std::string l2("123"); - TEST_LIBCPP_ASSERT_FAILURE(l1.erase(l2.cbegin(), l1.cbegin() + 1), - "string::erase(iterator, iterator) called with an iterator not referring to this string"); -} -{ - typedef std::basic_string, min_allocator > S; - S l1("123"); - S l2("123"); - TEST_LIBCPP_ASSERT_FAILURE(l1.erase(l2.cbegin(), l1.cbegin() + 1), - "string::erase(iterator, iterator) called with an iterator not referring to this string"); -} -} - -// With second iterator from another container -{{std::string l1("123"); -std::string l2("123"); -TEST_LIBCPP_ASSERT_FAILURE(l1.erase(l1.cbegin(), l2.cbegin() + 1), "Attempted to compare incomparable iterators"); -} -{ - typedef std::basic_string, min_allocator > S; - S l1("123"); - S l2("123"); - TEST_LIBCPP_ASSERT_FAILURE(l1.erase(l1.cbegin(), l2.cbegin() + 1), "Attempted to compare incomparable iterators"); -} -} + { + S l1("123"); + S l2("123"); + TEST_LIBCPP_ASSERT_FAILURE( + l1.erase(l2.cbegin(), l1.cbegin() + 1), + "string::erase(iterator, iterator) called with an iterator not referring to this string"); + } -// With both iterators from another container -{{std::string l1("123"); -std::string l2("123"); -TEST_LIBCPP_ASSERT_FAILURE(l1.erase(l2.cbegin(), l2.cbegin() + 1), - "string::erase(iterator, iterator) called with an iterator not referring to this string"); -} -{ - typedef std::basic_string, min_allocator > S; - S l1("123"); - S l2("123"); - TEST_LIBCPP_ASSERT_FAILURE(l1.erase(l2.cbegin(), l2.cbegin() + 1), - "string::erase(iterator, iterator) called with an iterator not referring to this string"); -} -} + // With second iterator from another container + { + S l1("123"); + S l2("123"); + TEST_LIBCPP_ASSERT_FAILURE(l1.erase(l1.cbegin(), l2.cbegin() + 1), "Attempted to compare incomparable iterators"); + } -// With an invalid range -{ + // With both iterators from another container { - std::string l1("123"); + S l1("123"); + S l2("123"); TEST_LIBCPP_ASSERT_FAILURE( - l1.erase(l1.cbegin() + 1, l1.cbegin()), "string::erase(first, last) called with invalid range"); + l1.erase(l2.cbegin(), l2.cbegin() + 1), + "string::erase(iterator, iterator) called with an iterator not referring to this string"); } + + // With an invalid range { - typedef std::basic_string, min_allocator > S; S l1("123"); TEST_LIBCPP_ASSERT_FAILURE( l1.erase(l1.cbegin() + 1, l1.cbegin()), "string::erase(first, last) called with invalid range"); } } -return 0; +int main(int, char**) { + test(); + test, min_allocator > >(); + + return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.insert.iter_char.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.insert.iter_char.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.insert.iter_char.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.insert.iter_char.pass.cpp @@ -23,13 +23,17 @@ #include "check_assertion.h" -int main(int, char**) { - typedef std::string S; +template +void test() { S s; S s2; TEST_LIBCPP_ASSERT_FAILURE( s.insert(s2.begin(), '1'), "string::insert(iterator, character) called with an iterator not referring to this string"); +} + +int main(int, char**) { + test(); return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.insert.iter_iter_iter.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.insert.iter_iter_iter.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.insert.iter_iter_iter.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.insert.iter_iter_iter.pass.cpp @@ -18,13 +18,18 @@ #include "check_assertion.h" -int main(int, char**) { - std::string v; - std::string v2; +template +void test() { + S v; + S v2; char a[] = "123"; const int N = sizeof(a) / sizeof(a[0]); TEST_LIBCPP_ASSERT_FAILURE( v.insert(v2.cbegin() + 10, a, a + N), "Attempted to add/subtract an iterator outside its valid range"); +} + +int main(int, char**) { + test(); return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.insert.iter_size_char.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.insert.iter_size_char.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.insert.iter_size_char.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.modifiers/debug.insert.iter_size_char.pass.cpp @@ -17,11 +17,16 @@ #include "check_assertion.h" -int main(int, char**) { - std::string s; - std::string s2; +template +void test() { + S s; + S s2; TEST_LIBCPP_ASSERT_FAILURE(s.insert(s2.begin(), 1, 'a'), "string::insert(iterator, n, value) called with an iterator not referring to this string"); +} + +int main(int, char**) { + test(); return 0; } diff --git a/libcxx/test/libcxx/strings/basic.string/string.modifiers/resize_default_initialized.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.modifiers/resize_default_initialized.pass.cpp --- a/libcxx/test/libcxx/strings/basic.string/string.modifiers/resize_default_initialized.pass.cpp +++ b/libcxx/test/libcxx/strings/basic.string/string.modifiers/resize_default_initialized.pass.cpp @@ -22,11 +22,12 @@ buf[size] = '\0'; } +template TEST_CONSTEXPR_CXX20 void test_buffer_usage() { { unsigned buff_size = 125; unsigned used_size = buff_size - 16; - std::string s; + S s; s.__resize_default_init(buff_size); write_c_str(&s[0], used_size); assert(s.size() == buff_size); @@ -40,9 +41,10 @@ } } +template TEST_CONSTEXPR_CXX20 void test_basic() { { - std::string s; + S s; s.__resize_default_init(3); assert(s.size() == 3); assert(s.data()[3] == '\0'); @@ -55,17 +57,18 @@ } } +template TEST_CONSTEXPR_CXX20 bool test() { - test_basic(); - test_buffer_usage(); + test_basic(); + test_buffer_usage(); return true; } int main(int, char**) { - test(); + test(); #if TEST_STD_VER > 17 - static_assert(test()); + static_assert(test()); #endif return 0; diff --git a/libcxx/test/std/strings/basic.string/string.capacity/capacity.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/capacity.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.capacity/capacity.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/capacity.pass.cpp @@ -19,7 +19,7 @@ #include "test_macros.h" template -TEST_CONSTEXPR_CXX20 void test(S s, test_allocator_statistics& alloc_stats) { +TEST_CONSTEXPR_CXX20 void test_invariant(S s, test_allocator_statistics& alloc_stats) { alloc_stats.throw_after = 0; #ifndef TEST_HAS_NO_EXCEPTIONS try @@ -37,33 +37,52 @@ alloc_stats.throw_after = INT_MAX; } +template +TEST_CONSTEXPR_CXX20 void test_string(const Alloc& a) { + using S = std::basic_string, Alloc>; + { + S const s((Alloc(a))); + assert(s.capacity() >= 0); + } + { + S const s(3, 'x', Alloc(a)); + assert(s.capacity() >= 3); + } +#if TEST_STD_VER >= 11 + // Check that we perform SSO + { + S const s; + assert(s.capacity() > 0); + ASSERT_NOEXCEPT(s.capacity()); + } +#endif +} + TEST_CONSTEXPR_CXX20 bool test() { + test_string(std::allocator()); + test_string(test_allocator()); + test_string(test_allocator(3)); + test_string(min_allocator()); + { test_allocator_statistics alloc_stats; typedef std::basic_string, test_allocator > S; S s((test_allocator(&alloc_stats))); - test(s, alloc_stats); + test_invariant(s, alloc_stats); s.assign(10, 'a'); s.erase(5); - test(s, alloc_stats); + test_invariant(s, alloc_stats); s.assign(100, 'a'); s.erase(50); - test(s, alloc_stats); - } -#if TEST_STD_VER >= 11 - { - typedef std::basic_string, min_allocator> S; - S s; - assert(s.capacity() > 0); + test_invariant(s, alloc_stats); } -#endif return true; } int main(int, char**) { test(); -#if TEST_STD_VER > 17 +#if TEST_STD_VER >= 20 static_assert(test()); #endif diff --git a/libcxx/test/std/strings/basic.string/string.capacity/max_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/max_size.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.capacity/max_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/max_size.pass.cpp @@ -26,7 +26,7 @@ #include "min_allocator.h" template -TEST_CONSTEXPR_CXX20 void test1(const S& s) { +TEST_CONSTEXPR_CXX20 void test_resize_max_size_minus_1(const S& s) { S s2(s); const std::size_t sz = s2.max_size() - 1; try { @@ -38,7 +38,7 @@ } template -TEST_CONSTEXPR_CXX20 void test2(const S& s) { +TEST_CONSTEXPR_CXX20 void test_resize_max_size(const S& s) { S s2(s); const std::size_t sz = s2.max_size(); try { @@ -49,45 +49,50 @@ assert(s.size() == sz); } -template -TEST_CONSTEXPR_CXX20 void test(const S& s) { - assert(s.max_size() >= s.size()); - test1(s); - test2(s); -} - template TEST_CONSTEXPR_CXX20 void test_string() { - test(S()); - test(S("123")); - test(S("12345678901234567890123456789012345678901234567890")); + { + S s; + assert(s.max_size() >= s.size()); + assert(s.max_size() > 0); + if (!TEST_IS_CONSTANT_EVALUATED) { + test_resize_max_size_minus_1(s); + test_resize_max_size(s); + } + } + { + S s("123"); + assert(s.max_size() >= s.size()); + assert(s.max_size() > 0); + if (!TEST_IS_CONSTANT_EVALUATED) { + test_resize_max_size_minus_1(s); + test_resize_max_size(s); + } + } + { + S s("12345678901234567890123456789012345678901234567890"); + assert(s.max_size() >= s.size()); + assert(s.max_size() > 0); + if (!TEST_IS_CONSTANT_EVALUATED) { + test_resize_max_size_minus_1(s); + test_resize_max_size(s); + } + } } TEST_CONSTEXPR_CXX20 bool test() { test_string(); #if TEST_STD_VER >= 11 - test_string, min_allocator>>(); + test_string, min_allocator > >(); #endif return true; } -#if TEST_STD_VER > 17 -constexpr bool test_constexpr() { - std::string str; - - std::size_t size = str.max_size(); - assert(size > 0); - - return true; -} -#endif - int main(int, char**) { test(); -#if TEST_STD_VER > 17 - test_constexpr(); - static_assert(test_constexpr()); +#if TEST_STD_VER >= 20 + static_assert(test()); #endif return 0; diff --git a/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.pass.cpp @@ -57,19 +57,18 @@ assert(s.c_str()[N] == '\0'); } -template +template constexpr bool test() { - using S = std::basic_string; - test_appending(10, 15, 15); - test_appending(10, 15, 20); - test_appending(10, 40, 40); - test_appending(10, 40, 50); - test_appending(30, 35, 35); - test_appending(30, 35, 45); - test_appending(10, 15, 30); - test_truncating(15, 10); - test_truncating(40, 35); - test_truncating(40, 10); + test_appending(10, 15, 15); + test_appending(10, 15, 20); + test_appending(10, 40, 40); + test_appending(10, 40, 50); + test_appending(30, 35, 35); + test_appending(30, 35, 45); + test_appending(10, 15, 30); + test_truncating(15, 10); + test_truncating(40, 35); + test_truncating(40, 10); return true; } @@ -85,19 +84,19 @@ } int main(int, char**) { - test(); - test(); - test(); - test(); + test, std::allocator>>(); + test, std::allocator>>(); + test, std::allocator>>(); + test, std::allocator>>(); - static_assert(test()); - static_assert(test()); - static_assert(test()); - static_assert(test()); + static_assert(test, std::allocator>>()); + static_assert(test, std::allocator>>()); + static_assert(test, std::allocator>>()); + static_assert(test, std::allocator>>()); #ifndef TEST_HAS_NO_WIDE_CHARACTERS - test(); - static_assert(test()); + test, std::allocator>>(); + static_assert(test, std::allocator>>()); #endif return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.cons/T_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/T_size_size.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.cons/T_size_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.cons/T_size_size.pass.cpp @@ -77,68 +77,44 @@ #endif } -TEST_CONSTEXPR_CXX20 bool test() { - { - typedef test_allocator A; - typedef std::basic_string_view > SV; - typedef std::basic_string, A> S; - - test(SV(), 0, 0); - test(SV(), 0, 1); - test(SV(), 1, 0); - test(SV(), 1, 1); - test(SV(), 1, 2); - test(SV("1"), 0, 0); - test(SV("1"), 0, 1); - test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 0); - test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 1); - test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 10); - test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 100); - - test(SV(), 0, 0, A(4)); - test(SV(), 0, 1, A(4)); - test(SV(), 1, 0, A(4)); - test(SV(), 1, 1, A(4)); - test(SV(), 1, 2, A(4)); - test(SV("1"), 0, 0, A(6)); - test(SV("1"), 0, 1, A(6)); - test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 0, A(8)); - test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 1, A(8)); - test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 10, A(8)); - test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 100, A(8)); - } +template +TEST_CONSTEXPR_CXX20 void test_string(const Alloc& a) { + typedef std::basic_string_view > SV; + typedef std::basic_string, Alloc> S; + + test(SV(), 0, 0); + test(SV(), 0, 1); + test(SV(), 1, 0); + test(SV(), 1, 1); + test(SV(), 1, 2); + test(SV("1"), 0, 0); + test(SV("1"), 0, 1); + test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 0); + test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 1); + test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 10); + test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 100); + + test(SV(), 0, 0, Alloc(a)); + test(SV(), 0, 1, Alloc(a)); + test(SV(), 1, 0, Alloc(a)); + test(SV(), 1, 1, Alloc(a)); + test(SV(), 1, 2, Alloc(a)); + test(SV("1"), 0, 0, Alloc(a)); + test(SV("1"), 0, 1, Alloc(a)); + test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 0, Alloc(a)); + test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 1, Alloc(a)); + test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 10, Alloc(a)); + test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 100, Alloc(a)); +} +TEST_CONSTEXPR_CXX20 bool test() { + test_string(std::allocator()); + test_string(test_allocator()); + test_string(test_allocator(8)); #if TEST_STD_VER >= 11 - { - typedef min_allocator A; - typedef std::basic_string_view > SV; - typedef std::basic_string, A> S; - - test(SV(), 0, 0); - test(SV(), 0, 1); - test(SV(), 1, 0); - test(SV(), 1, 1); - test(SV(), 1, 2); - test(SV("1"), 0, 0); - test(SV("1"), 0, 1); - test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 0); - test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 1); - test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 10); - test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 100); - - test(SV(), 0, 0, A()); - test(SV(), 0, 1, A()); - test(SV(), 1, 0, A()); - test(SV(), 1, 1, A()); - test(SV(), 1, 2, A()); - test(SV("1"), 0, 0, A()); - test(SV("1"), 0, 1, A()); - test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 0, A()); - test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 1, A()); - test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 10, A()); - test(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 100, A()); - } + test_string(min_allocator()); #endif + { typedef std::string S; typedef std::string_view SV; diff --git a/libcxx/test/std/strings/basic.string/string.cons/copy.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/copy.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.cons/copy.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.cons/copy.pass.cpp @@ -26,22 +26,20 @@ assert(s2.get_allocator() == s1.get_allocator()); } +template +TEST_CONSTEXPR_CXX20 void test_string(const Alloc& a) { + typedef std::basic_string, Alloc> S; + test(S(Alloc(a))); + test(S("1", Alloc(a))); + test(S("1234567890123456789012345678901234567890123456789012345678901234567890", Alloc(a))); +} + TEST_CONSTEXPR_CXX20 bool test() { - { - typedef test_allocator A; - typedef std::basic_string, A> S; - test(S(A(3))); - test(S("1", A(5))); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7))); - } + test_string(std::allocator()); + test_string(test_allocator()); + test_string(test_allocator(3)); #if TEST_STD_VER >= 11 - { - typedef min_allocator A; - typedef std::basic_string, A> S; - test(S(A{})); - test(S("1", A())); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A())); - } + test_string(min_allocator()); #endif return true; diff --git a/libcxx/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp @@ -85,23 +85,23 @@ assert(s2.get_allocator() == a); } +template +TEST_CONSTEXPR_CXX20 void test_string(const Alloc& a) { + typedef std::basic_string, Alloc> S; + test(S(), Alloc(a)); + test(S("1"), Alloc(a)); + test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), Alloc(a)); +} + TEST_CONSTEXPR_CXX20 bool test() { - { - typedef test_allocator A; - typedef std::basic_string, A> S; - test(S(), A(3)); - test(S("1"), A(5)); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7)); - } + test_string(std::allocator()); + test_string(test_allocator()); + test_string(test_allocator(3)); #if TEST_STD_VER >= 11 - { - typedef min_allocator A; - typedef std::basic_string, A> S; - test(S(), A()); - test(S("1"), A()); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A()); - } + test_string(min_allocator()); +#endif +#if TEST_STD_VER >= 11 # ifndef TEST_HAS_NO_EXCEPTIONS if (!TEST_IS_CONSTANT_EVALUATED) { typedef poca_alloc A; diff --git a/libcxx/test/std/strings/basic.string/string.cons/initializer_list.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/initializer_list.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.cons/initializer_list.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.cons/initializer_list.pass.cpp @@ -19,31 +19,25 @@ #include "test_allocator.h" #include "min_allocator.h" -TEST_CONSTEXPR_CXX20 bool test() { - { - std::string s = {'a', 'b', 'c'}; - assert(s == "abc"); - } -#ifndef TEST_HAS_NO_WIDE_CHARACTERS - { - std::wstring s; - s = {L'a', L'b', L'c'}; - assert(s == L"abc"); - } -#endif +// clang-format off +template