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"); - } - - return 0; + 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"); - } - - return 0; + 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(uint8_t() - 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'); + typename 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" +template +void test() { + S s; + TEST_LIBCPP_ASSERT_FAILURE(s.pop_back(), "string::pop_back(): string is already empty"); +} + int main(int, char**) { - std::string s; - TEST_LIBCPP_ASSERT_FAILURE(s.pop_back(), "string::pop_back(): string is already empty"); + test(); - return 0; + 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,21 +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"); - } - - return 0; + 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,74 +18,44 @@ #include "check_assertion.h" #include "min_allocator.h" -int main(int, char**) { - - // 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"); - } - } - - // 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"); - } - } +template +void test() { + // With first iterator from another container + { + 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 + { + S l1("123"); + S l2("123"); + TEST_LIBCPP_ASSERT_FAILURE(l1.erase(l1.cbegin(), l2.cbegin() + 1), "Attempted to compare incomparable iterators"); + } + + // With both iterators from another container + { + 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 an invalid range + { + S l1("123"); + TEST_LIBCPP_ASSERT_FAILURE( + l1.erase(l1.cbegin() + 1, l1.cbegin()), "string::erase(first, last) called with invalid range"); + } +} - // With an invalid range - { - { - std::string l1("123"); - TEST_LIBCPP_ASSERT_FAILURE(l1.erase(l1.cbegin() + 1, l1.cbegin()), - "string::erase(first, last) called with 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"); - } - } +int main(int, char**) { + test(); + test, min_allocator > >(); - return 0; + 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,12 +23,17 @@ #include "check_assertion.h" +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**) { - typedef std::string S; - 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"); + test(); - return 0; + 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" +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**) { - std::string v; - std::string 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"); - - return 0; + 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,12 +17,16 @@ #include "check_assertion.h" +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**) { - std::string s; - std::string 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"); + test(); - return 0; + 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,12 +22,12 @@ buf[size] = '\0'; } -TEST_CONSTEXPR_CXX20 void test_buffer_usage() -{ +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); @@ -41,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'); @@ -56,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/libcxx/strings/char.traits/char.traits.specializations/arbitrary_char_type.deprecated.verify.cpp b/libcxx/test/libcxx/strings/char.traits/char.traits.specializations/arbitrary_char_type.deprecated.verify.cpp --- a/libcxx/test/libcxx/strings/char.traits/char.traits.specializations/arbitrary_char_type.deprecated.verify.cpp +++ b/libcxx/test/libcxx/strings/char.traits/char.traits.specializations/arbitrary_char_type.deprecated.verify.cpp @@ -15,7 +15,10 @@ #include void f() { - std::char_traits t1; (void)t1; // expected-warning{{'char_traits' is deprecated}} - std::char_traits t2; (void)t2; // expected-warning{{'char_traits' is deprecated}} - std::char_traits t3; (void)t3; // expected-warning{{'char_traits' is deprecated}} + std::char_traits t1; // expected-warning{{'char_traits' is deprecated}} + std::char_traits t2; // expected-warning{{'char_traits' is deprecated}} + std::char_traits t3; // expected-warning{{'char_traits' is deprecated}} + (void)t1; + (void)t2; + (void)t3; } diff --git a/libcxx/test/std/strings/basic.string/string.access/at.pass.cpp b/libcxx/test/std/strings/basic.string/string.access/at.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.access/at.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.access/at.pass.cpp @@ -22,37 +22,27 @@ #include "type_algorithms.h" template -TEST_CONSTEXPR_CXX20 void -test(S s, typename S::size_type pos) -{ - const S& cs = s; - if (pos < s.size()) - { - assert(s.at(pos) == s[pos]); - assert(cs.at(pos) == cs[pos]); - } +TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type pos) { + const S& cs = s; + if (pos < s.size()) { + assert(s.at(pos) == s[pos]); + assert(cs.at(pos) == cs[pos]); + } #ifndef TEST_HAS_NO_EXCEPTIONS - else if (!TEST_IS_CONSTANT_EVALUATED) - { - try - { - TEST_IGNORE_NODISCARD s.at(pos); - assert(false); - } - catch (std::out_of_range&) - { - assert(pos >= s.size()); - } - try - { - TEST_IGNORE_NODISCARD cs.at(pos); - assert(false); - } - catch (std::out_of_range&) - { - assert(pos >= s.size()); - } + else if (!TEST_IS_CONSTANT_EVALUATED) { + try { + TEST_IGNORE_NODISCARD s.at(pos); + assert(false); + } catch (std::out_of_range&) { + assert(pos >= s.size()); } + try { + TEST_IGNORE_NODISCARD cs.at(pos); + assert(false); + } catch (std::out_of_range&) { + assert(pos >= s.size()); + } + } #endif } @@ -81,8 +71,7 @@ return true; } -int main(int, char**) -{ +int main(int, char**) { test(); #if TEST_STD_VER > 17 static_assert(test()); diff --git a/libcxx/test/std/strings/basic.string/string.access/back.pass.cpp b/libcxx/test/std/strings/basic.string/string.access/back.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.access/back.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.access/back.pass.cpp @@ -18,18 +18,16 @@ #include "min_allocator.h" template -TEST_CONSTEXPR_CXX20 void -test(S s) -{ - const S& cs = s; - ASSERT_SAME_TYPE(decltype( s.back()), typename S::reference); - ASSERT_SAME_TYPE(decltype(cs.back()), typename S::const_reference); - LIBCPP_ASSERT_NOEXCEPT( s.back()); - LIBCPP_ASSERT_NOEXCEPT( cs.back()); - assert(&cs.back() == &cs[cs.size()-1]); - assert(&s.back() == &s[cs.size()-1]); - s.back() = typename S::value_type('z'); - assert(s.back() == typename S::value_type('z')); +TEST_CONSTEXPR_CXX20 void test(S s) { + const S& cs = s; + ASSERT_SAME_TYPE(decltype(s.back()), typename S::reference); + ASSERT_SAME_TYPE(decltype(cs.back()), typename S::const_reference); + LIBCPP_ASSERT_NOEXCEPT(s.back()); + LIBCPP_ASSERT_NOEXCEPT(cs.back()); + assert(&cs.back() == &cs[cs.size() - 1]); + assert(&s.back() == &s[cs.size() - 1]); + s.back() = typename S::value_type('z'); + assert(s.back() == typename S::value_type('z')); } template @@ -41,14 +39,13 @@ TEST_CONSTEXPR_CXX20 bool test() { test_string(); #if TEST_STD_VER >= 11 - test_string, min_allocator>>(); + test_string, min_allocator > >(); #endif return true; } -int main(int, char**) -{ +int main(int, char**) { test(); #if TEST_STD_VER > 17 static_assert(test()); diff --git a/libcxx/test/std/strings/basic.string/string.access/front.pass.cpp b/libcxx/test/std/strings/basic.string/string.access/front.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.access/front.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.access/front.pass.cpp @@ -18,18 +18,16 @@ #include "min_allocator.h" template -TEST_CONSTEXPR_CXX20 void -test(S s) -{ - const S& cs = s; - ASSERT_SAME_TYPE(decltype( s.front()), typename S::reference); - ASSERT_SAME_TYPE(decltype(cs.front()), typename S::const_reference); - LIBCPP_ASSERT_NOEXCEPT( s.front()); - LIBCPP_ASSERT_NOEXCEPT( cs.front()); - assert(&cs.front() == &cs[0]); - assert(&s.front() == &s[0]); - s.front() = typename S::value_type('z'); - assert(s.front() == typename S::value_type('z')); +TEST_CONSTEXPR_CXX20 void test(S s) { + const S& cs = s; + ASSERT_SAME_TYPE(decltype(s.front()), typename S::reference); + ASSERT_SAME_TYPE(decltype(cs.front()), typename S::const_reference); + LIBCPP_ASSERT_NOEXCEPT(s.front()); + LIBCPP_ASSERT_NOEXCEPT(cs.front()); + assert(&cs.front() == &cs[0]); + assert(&s.front() == &s[0]); + s.front() = typename S::value_type('z'); + assert(s.front() == typename S::value_type('z')); } template @@ -41,14 +39,13 @@ TEST_CONSTEXPR_CXX20 bool test() { test_string(); #if TEST_STD_VER >= 11 - test_string, min_allocator>>(); + test_string, min_allocator > >(); #endif return true; } -int main(int, char**) -{ +int main(int, char**) { test(); #if TEST_STD_VER > 17 static_assert(test()); diff --git a/libcxx/test/std/strings/basic.string/string.access/index.pass.cpp b/libcxx/test/std/strings/basic.string/string.access/index.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.access/index.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.access/index.pass.cpp @@ -38,14 +38,13 @@ TEST_CONSTEXPR_CXX20 bool test() { test_string(); #if TEST_STD_VER >= 11 - test_string, min_allocator>>(); + test_string, min_allocator > >(); #endif return true; } -int main(int, char**) -{ +int main(int, char**) { test(); #if TEST_STD_VER > 17 static_assert(test()); 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,53 +19,53 @@ #include "test_macros.h" template -TEST_CONSTEXPR_CXX20 void -test(S s, test_allocator_statistics& alloc_stats) -{ - alloc_stats.throw_after = 0; +TEST_CONSTEXPR_CXX20 void test(S s, test_allocator_statistics& alloc_stats) { + alloc_stats.throw_after = 0; #ifndef TEST_HAS_NO_EXCEPTIONS - try + try #endif - { - while (s.size() < s.capacity()) - s.push_back(typename S::value_type()); - assert(s.size() == s.capacity()); - } + { + while (s.size() < s.capacity()) + s.push_back(typename S::value_type()); + assert(s.size() == s.capacity()); + } #ifndef TEST_HAS_NO_EXCEPTIONS - catch (...) - { - assert(false); - } + catch (...) { + assert(false); + } #endif - alloc_stats.throw_after = INT_MAX; + alloc_stats.throw_after = INT_MAX; +} + +template +TEST_CONSTEXPR_CXX20 void test_string() { + S s; + assert(s.capacity() > 0); +} + +template <> +TEST_CONSTEXPR_CXX20 void test_string, test_allocator > >() { + using S = std::basic_string, test_allocator >; + test_allocator_statistics alloc_stats; + S s((test_allocator(&alloc_stats))); + test(s, alloc_stats); + s.assign(10, 'a'); + s.erase(5); + test(s, alloc_stats); + s.assign(100, 'a'); + s.erase(50); + test(s, alloc_stats); } TEST_CONSTEXPR_CXX20 bool test() { - { - test_allocator_statistics alloc_stats; - typedef std::basic_string, test_allocator > S; - S s((test_allocator(&alloc_stats))); - test(s, alloc_stats); - s.assign(10, 'a'); - s.erase(5); - test(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_string, min_allocator > >(); #endif return true; } -int main(int, char**) -{ +int main(int, char**) { test(); #if TEST_STD_VER > 17 static_assert(test()); diff --git a/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp @@ -17,11 +17,9 @@ #include "min_allocator.h" template -TEST_CONSTEXPR_CXX20 void -test(S s) -{ - s.clear(); - assert(s.size() == 0); +TEST_CONSTEXPR_CXX20 void test(S s) { + s.clear(); + assert(s.size() == 0); } template @@ -41,14 +39,13 @@ TEST_CONSTEXPR_CXX20 bool test() { test_string(); #if TEST_STD_VER >= 11 - test_string, min_allocator>>(); + test_string, min_allocator > >(); #endif return true; } -int main(int, char**) -{ +int main(int, char**) { test(); #if TEST_STD_VER > 17 static_assert(test()); diff --git a/libcxx/test/std/strings/basic.string/string.capacity/empty.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/empty.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.capacity/empty.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/empty.pass.cpp @@ -17,11 +17,9 @@ #include "min_allocator.h" template -TEST_CONSTEXPR_CXX20 void -test(const S& s) -{ - ASSERT_NOEXCEPT(s.empty()); - assert(s.empty() == (s.size() == 0)); +TEST_CONSTEXPR_CXX20 void test(const S& s) { + ASSERT_NOEXCEPT(s.empty()); + assert(s.empty() == (s.size() == 0)); } template @@ -34,14 +32,13 @@ TEST_CONSTEXPR_CXX20 bool test() { test_string(); #if TEST_STD_VER >= 11 - test_string, min_allocator>>(); + test_string, min_allocator > >(); #endif return true; } -int main(int, char**) -{ +int main(int, char**) { test(); #if TEST_STD_VER > 17 static_assert(test()); diff --git a/libcxx/test/std/strings/basic.string/string.capacity/length.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/length.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.capacity/length.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/length.pass.cpp @@ -17,10 +17,8 @@ #include "min_allocator.h" template -TEST_CONSTEXPR_CXX20 void -test(const S& s) -{ - assert(s.length() == s.size()); +TEST_CONSTEXPR_CXX20 void test(const S& s) { + assert(s.length() == s.size()); } template @@ -33,14 +31,13 @@ TEST_CONSTEXPR_CXX20 bool test() { test_string(); #if TEST_STD_VER >= 11 - test_string, min_allocator>>(); + test_string, min_allocator > >(); #endif return true; } -int main(int, char**) -{ +int main(int, char**) { test(); #if TEST_STD_VER > 17 static_assert(test()); 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,34 +26,34 @@ #include "min_allocator.h" template -TEST_CONSTEXPR_CXX20 void -test1(const S& s) -{ - S s2(s); - const size_t sz = s2.max_size() - 1; - try { s2.resize(sz, 'x'); } - catch ( const std::bad_alloc & ) { return ; } - assert ( s2.size() == sz ); +TEST_CONSTEXPR_CXX20 void test1(const S& s) { + S s2(s); + const size_t sz = s2.max_size() - 1; + try { + s2.resize(sz, 'x'); + } catch (const std::bad_alloc&) { + return; + } + assert(s2.size() == sz); } template -TEST_CONSTEXPR_CXX20 void -test2(const S& s) -{ - S s2(s); - const size_t sz = s2.max_size(); - try { s2.resize(sz, 'x'); } - catch ( const std::bad_alloc & ) { return ; } - assert ( s.size() == sz ); +TEST_CONSTEXPR_CXX20 void test2(const S& s) { + S s2(s); + const size_t sz = s2.max_size(); + try { + s2.resize(sz, 'x'); + } catch (const std::bad_alloc&) { + return; + } + assert(s.size() == sz); } template -TEST_CONSTEXPR_CXX20 void -test(const S& s) -{ - assert(s.max_size() >= s.size()); - test1(s); - test2(s); +TEST_CONSTEXPR_CXX20 void test(const S& s) { + assert(s.max_size() >= s.size()); + test1(s); + test2(s); } template @@ -63,28 +63,33 @@ test(S("12345678901234567890123456789012345678901234567890")); } -TEST_CONSTEXPR_CXX20 bool test() { +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; +template +TEST_CONSTEXPR_CXX20 void test_string_constexpr() { + S str; size_t size = str.max_size(); assert(size > 0); +} + +TEST_CONSTEXPR_CXX20 bool test_constexpr() { + test_string_constexpr(); return true; } #endif -int main(int, char**) -{ +int main(int, char**) { test(); #if TEST_STD_VER > 17 test_constexpr(); diff --git a/libcxx/test/std/strings/basic.string/string.capacity/over_max_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/over_max_size.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.capacity/over_max_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/over_max_size.pass.cpp @@ -26,15 +26,16 @@ #include "min_allocator.h" template -void -test(const S& s) -{ - assert(s.max_size() >= s.size()); - S s2(s); - const size_t sz = s2.max_size() + 1; - try { s2.resize(sz, 'x'); } - catch ( const std::length_error & ) { return ; } - assert ( false ); +TEST_CONSTEXPR_CXX20 void test(const S& s) { + assert(s.max_size() >= s.size()); + S s2(s); + const size_t sz = s2.max_size() + 1; + try { + s2.resize(sz, 'x'); + } catch (const std::length_error&) { + return; + } + assert(false); } template @@ -47,14 +48,13 @@ bool test() { test_string(); #if TEST_STD_VER >= 11 - test_string, min_allocator>>(); + test_string, min_allocator > >(); #endif return true; } -int main(int, char**) -{ +int main(int, char**) { test(); return 0; diff --git a/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp @@ -20,21 +20,19 @@ #include "min_allocator.h" template -void -test(typename S::size_type min_cap, typename S::size_type erased_index) -{ - S s(min_cap, 'a'); - s.erase(erased_index); - assert(s.size() == erased_index); - assert(s.capacity() >= min_cap); // Check that we really have at least this capacity. - - typename S::size_type old_cap = s.capacity(); - S s0 = s; - s.reserve(); - LIBCPP_ASSERT(s.__invariants()); - assert(s == s0); - assert(s.capacity() <= old_cap); - assert(s.capacity() >= s.size()); +void test(typename S::size_type min_cap, typename S::size_type erased_index) { + S s(min_cap, 'a'); + s.erase(erased_index); + assert(s.size() == erased_index); + assert(s.capacity() >= min_cap); // Check that we really have at least this capacity. + + typename S::size_type old_cap = s.capacity(); + S s0 = s; + s.reserve(); + LIBCPP_ASSERT(s.__invariants()); + assert(s == s0); + assert(s.capacity() <= old_cap); + assert(s.capacity() >= s.size()); } template @@ -47,14 +45,13 @@ bool test() { test_string(); #if TEST_STD_VER >= 11 - test_string, min_allocator>>(); + test_string, min_allocator > >(); #endif return true; } -int main(int, char**) -{ +int main(int, char**) { test(); return 0; diff --git a/libcxx/test/std/strings/basic.string/string.capacity/reserve_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/reserve_size.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.capacity/reserve_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/reserve_size.pass.cpp @@ -23,42 +23,36 @@ template TEST_CONSTEXPR_CXX20 void -test(typename S::size_type min_cap, typename S::size_type erased_index, typename S::size_type res_arg) -{ - S s(min_cap, 'a'); - s.erase(erased_index); - assert(s.size() == erased_index); - assert(s.capacity() >= min_cap); // Check that we really have at least this capacity. +test(typename S::size_type min_cap, typename S::size_type erased_index, typename S::size_type res_arg) { + S s(min_cap, 'a'); + s.erase(erased_index); + assert(s.size() == erased_index); + assert(s.capacity() >= min_cap); // Check that we really have at least this capacity. #if TEST_STD_VER > 17 - typename S::size_type old_cap = s.capacity(); + typename S::size_type old_cap = s.capacity(); #endif - S s0 = s; - if (res_arg <= s.max_size()) - { - s.reserve(res_arg); - LIBCPP_ASSERT(s.__invariants()); - assert(s == s0); - assert(s.capacity() >= res_arg); - assert(s.capacity() >= s.size()); + S s0 = s; + if (res_arg <= s.max_size()) { + s.reserve(res_arg); + LIBCPP_ASSERT(s.__invariants()); + assert(s == s0); + assert(s.capacity() >= res_arg); + assert(s.capacity() >= s.size()); #if TEST_STD_VER > 17 - assert(s.capacity() >= old_cap); // reserve never shrinks as of P0966 (C++20) + assert(s.capacity() >= old_cap); // reserve never shrinks as of P0966 (C++20) #endif - } + } #ifndef TEST_HAS_NO_EXCEPTIONS - else if (!TEST_IS_CONSTANT_EVALUATED) - { - try - { - s.reserve(res_arg); - LIBCPP_ASSERT(s.__invariants()); - assert(false); - } - catch (std::length_error&) - { - assert(res_arg > s.max_size()); - } + else if (!TEST_IS_CONSTANT_EVALUATED) { + try { + s.reserve(res_arg); + LIBCPP_ASSERT(s.__invariants()); + assert(false); + } catch (std::length_error&) { + assert(res_arg > s.max_size()); } + } #endif } @@ -82,14 +76,13 @@ TEST_CONSTEXPR_CXX20 bool test() { test_string(); #if TEST_STD_VER >= 11 - test_string, min_allocator>>(); + test_string, min_allocator > >(); #endif return true; } -int main(int, char**) -{ +int main(int, char**) { test(); #if TEST_STD_VER > 17 static_assert(test()); 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 @@ -49,7 +49,7 @@ LIBCPP_ASSERT(s.begin().base() == p); assert(std::all_of(p, p + n, [](auto ch) { return ch == 'a'; })); p[n - 1] = 'b'; - p[n] = 'c'; // will be overwritten + p[n] = 'c'; // will be overwritten return n; }); const S expected = S(N - 1, 'a') + S(1, 'b'); @@ -57,9 +57,9 @@ assert(s.c_str()[N] == '\0'); } -template -constexpr bool test() { - using S = std::basic_string; +template class Alloc> +constexpr bool test_string() { + using S = std::basic_string, Alloc >; test_appending(10, 15, 15); test_appending(10, 15, 20); test_appending(10, 40, 40); @@ -85,19 +85,26 @@ } int main(int, char**) { - test(); - test(); - test(); - test(); + test_string(); + + test_string(); + + test_string(); + + test_string(); - static_assert(test()); - static_assert(test()); - static_assert(test()); - static_assert(test()); + static_assert(test_string()); + + static_assert(test_string()); + + static_assert(test_string()); + + static_assert(test_string()); #ifndef TEST_HAS_NO_WIDE_CHARACTERS - test(); - static_assert(test()); + test_string(); + + static_assert(test_string()); #endif return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp @@ -18,28 +18,21 @@ #include "min_allocator.h" template -TEST_CONSTEXPR_CXX20 void -test(S s, typename S::size_type n, S expected) -{ - if (n <= s.max_size()) - { - s.resize(n); - LIBCPP_ASSERT(s.__invariants()); - assert(s == expected); - } +TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type n, S expected) { + if (n <= s.max_size()) { + s.resize(n); + LIBCPP_ASSERT(s.__invariants()); + assert(s == expected); + } #ifndef TEST_HAS_NO_EXCEPTIONS - else if (!TEST_IS_CONSTANT_EVALUATED) - { - try - { - s.resize(n); - assert(false); - } - catch (std::length_error&) - { - assert(n > s.max_size()); - } + else if (!TEST_IS_CONSTANT_EVALUATED) { + try { + s.resize(n); + assert(false); + } catch (std::length_error&) { + assert(n > s.max_size()); } + } #endif } @@ -65,15 +58,15 @@ TEST_CONSTEXPR_CXX20 bool test() { test_string(); + #if TEST_STD_VER >= 11 - test_string, min_allocator>>(); + test_string, min_allocator > >(); #endif return true; } -int main(int, char**) -{ +int main(int, char**) { test(); #if TEST_STD_VER > 17 static_assert(test()); diff --git a/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp @@ -18,28 +18,21 @@ #include "min_allocator.h" template -TEST_CONSTEXPR_CXX20 void -test(S s, typename S::size_type n, typename S::value_type c, S expected) -{ - if (n <= s.max_size()) - { - s.resize(n, c); - LIBCPP_ASSERT(s.__invariants()); - assert(s == expected); - } +TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type n, typename S::value_type c, S expected) { + if (n <= s.max_size()) { + s.resize(n, c); + LIBCPP_ASSERT(s.__invariants()); + assert(s == expected); + } #ifndef TEST_HAS_NO_EXCEPTIONS - else if (!TEST_IS_CONSTANT_EVALUATED) - { - try - { - s.resize(n, c); - assert(false); - } - catch (std::length_error&) - { - assert(n > s.max_size()); - } + else if (!TEST_IS_CONSTANT_EVALUATED) { + try { + s.resize(n, c); + assert(false); + } catch (std::length_error&) { + assert(n > s.max_size()); } + } #endif } @@ -66,14 +59,13 @@ TEST_CONSTEXPR_CXX20 bool test() { test_string(); #if TEST_STD_VER >= 11 - test_string, min_allocator>>(); + test_string, min_allocator > >(); #endif return true; } -int main(int, char**) -{ +int main(int, char**) { test(); #if TEST_STD_VER > 17 static_assert(test()); diff --git a/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp @@ -17,16 +17,14 @@ #include "min_allocator.h" template -TEST_CONSTEXPR_CXX20 void -test(S s) -{ - typename S::size_type old_cap = s.capacity(); - S s0 = s; - s.shrink_to_fit(); - LIBCPP_ASSERT(s.__invariants()); - assert(s == s0); - assert(s.capacity() <= old_cap); - assert(s.capacity() >= s.size()); +TEST_CONSTEXPR_CXX20 void test(S s) { + typename S::size_type old_cap = s.capacity(); + S s0 = s; + s.shrink_to_fit(); + LIBCPP_ASSERT(s.__invariants()); + assert(s == s0); + assert(s.capacity() <= old_cap); + assert(s.capacity() >= s.size()); } template @@ -46,14 +44,13 @@ TEST_CONSTEXPR_CXX20 bool test() { test_string(); #if TEST_STD_VER >= 11 - test_string, min_allocator>>(); + test_string, min_allocator > >(); #endif return true; } -int main(int, char**) -{ +int main(int, char**) { test(); #if TEST_STD_VER > 17 static_assert(test()); diff --git a/libcxx/test/std/strings/basic.string/string.capacity/size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/size.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.capacity/size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/size.pass.cpp @@ -17,10 +17,8 @@ #include "min_allocator.h" template -TEST_CONSTEXPR_CXX20 void -test(const S& s, typename S::size_type c) -{ - assert(s.size() == c); +TEST_CONSTEXPR_CXX20 void test(const S& s, typename S::size_type c) { + assert(s.size() == c); } template @@ -33,14 +31,13 @@ TEST_CONSTEXPR_CXX20 bool test() { test_string(); #if TEST_STD_VER >= 11 - test_string, min_allocator>>(); + test_string, min_allocator > >(); #endif return true; } -int main(int, char**) -{ +int main(int, char**) { test(); #if TEST_STD_VER > 17 static_assert(test()); 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 @@ -25,168 +25,159 @@ #include "min_allocator.h" template -TEST_CONSTEXPR_CXX20 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(pos), static_cast(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()); - } +TEST_CONSTEXPR_CXX20 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(pos), static_cast(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 if (!TEST_IS_CONSTANT_EVALUATED) - { - try - { - S s2(sv, static_cast(pos), static_cast(n)); - assert(false); - } - catch (std::out_of_range&) - { - assert(pos > sv.size()); - } + else if (!TEST_IS_CONSTANT_EVALUATED) { + try { + S s2(sv, static_cast(pos), static_cast(n)); + assert(false); + } catch (std::out_of_range&) { + assert(pos > sv.size()); } + } #endif } template -TEST_CONSTEXPR_CXX20 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(pos), static_cast(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()); - } +TEST_CONSTEXPR_CXX20 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(pos), static_cast(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 if (!TEST_IS_CONSTANT_EVALUATED) - { - try - { - S s2(sv, static_cast(pos), static_cast(n), a); - assert(false); - } - catch (std::out_of_range&) - { - assert(pos > sv.size()); - } + else if (!TEST_IS_CONSTANT_EVALUATED) { + try { + S s2(sv, static_cast(pos), static_cast(n), a); + assert(false); + } catch (std::out_of_range&) { + assert(pos > sv.size()); } + } #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 class Alloc> +TEST_CONSTEXPR_CXX20 void test_string() { + using A = Alloc; + using S = std::basic_string, A>; + using SV = std::basic_string_view< CharT, std::char_traits >; + + 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()); +} + +template <> +TEST_CONSTEXPR_CXX20 void test_string() { + using A = test_allocator; + using S = std::basic_string, A>; + using SV = std::basic_string_view< char, std::char_traits >; + + 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)); +} +TEST_CONSTEXPR_CXX20 bool test() { + test_string(); + test_string(); #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(); #endif { - typedef std::string S; - typedef std::string_view SV; - S s = "ABCD"; - SV sv = "EFGH"; + using S = std::string; + using SV = std::string_view; + S s = "ABCD"; + SV sv = "EFGH"; char arr[] = "IJKL"; - S s1("CDEF", 4); // calls ctor(const char *, len) + 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) + 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) + S s4(sv, 0, 3); // calls ctor(T, pos, len) assert(s4 == "EFG"); - S s5(arr, 0, 2); // calls ctor(const char *, len) + S s5(arr, 0, 2); // calls ctor(const char *, len) assert(s5 == "IJ"); - S s6(arr, 0); // calls ctor(const char *, len) + S s6(arr, 0); // calls ctor(const char *, len) assert(s6 == ""); - S s7(s.data(), 2); // calls ctor(const char *, len) + S s7(s.data(), 2); // calls ctor(const char *, len) assert(s7 == "AB"); } return true; } -int main(int, char**) -{ +int main(int, char**) { test(); #if TEST_STD_VER > 17 static_assert(test()); diff --git a/libcxx/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp @@ -17,15 +17,13 @@ #include "min_allocator.h" template -TEST_CONSTEXPR_CXX20 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()); +TEST_CONSTEXPR_CXX20 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()); } template @@ -39,14 +37,13 @@ TEST_CONSTEXPR_CXX20 bool test() { test_string(); #if TEST_STD_VER >= 11 - test_string, min_allocator>>(); + test_string, min_allocator > >(); #endif return true; } -int main(int, char**) -{ +int main(int, char**) { test(); #if TEST_STD_VER > 17 static_assert(test()); 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 @@ -18,39 +18,43 @@ #include "min_allocator.h" template -TEST_CONSTEXPR_CXX20 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()); +TEST_CONSTEXPR_CXX20 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()); +} + +template class Alloc> +TEST_CONSTEXPR_CXX20 void test_string() { + using A = Alloc; + using S = std::basic_string, A>; + test(S(A())); + test(S("1", A())); + test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A())); +} + +template <> +TEST_CONSTEXPR_CXX20 void test_string() { + using A = test_allocator; + using S = std::basic_string, A>; + test(S(A(3))); + test(S("1", A(5))); + test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7))); } 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(); + test_string(); #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(); #endif return true; } -int main(int, char**) -{ +int main(int, char**) { test(); #if TEST_STD_VER > 17 static_assert(test()); 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 @@ -19,98 +19,101 @@ #ifndef TEST_HAS_NO_EXCEPTIONS struct alloc_imp { - bool active; - - TEST_CONSTEXPR alloc_imp() : active(true) {} - - template - T* allocate(std::size_t n) - { - if (active) - return static_cast(std::malloc(n * sizeof(T))); - else - throw std::bad_alloc(); - } - - template - void deallocate(T* p, std::size_t) { std::free(p); } - void activate () { active = true; } - void deactivate() { active = false; } + bool active; + + TEST_CONSTEXPR alloc_imp() : active(true) {} + + template + T* allocate(std::size_t n) { + if (active) + return static_cast(std::malloc(n * sizeof(T))); + else + throw std::bad_alloc(); + } + + template + void deallocate(T* p, std::size_t) { + std::free(p); + } + void activate() { active = true; } + void deactivate() { active = false; } }; template struct poca_alloc { - typedef T value_type; - typedef std::true_type propagate_on_container_copy_assignment; + typedef T value_type; + typedef std::true_type propagate_on_container_copy_assignment; - alloc_imp *imp; + alloc_imp* imp; - TEST_CONSTEXPR poca_alloc(alloc_imp *imp_) : imp (imp_) {} + TEST_CONSTEXPR poca_alloc(alloc_imp* imp_) : imp(imp_) {} - template - TEST_CONSTEXPR poca_alloc(const poca_alloc& other) : imp(other.imp) {} + template + TEST_CONSTEXPR poca_alloc(const poca_alloc& 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); } + T* allocate(std::size_t n) { return imp->allocate(n); } + void deallocate(T* p, std::size_t n) { imp->deallocate(p, n); } }; template -bool operator==(const poca_alloc& lhs, const poca_alloc& rhs) -{ - return lhs.imp == rhs.imp; +bool operator==(const poca_alloc& lhs, const poca_alloc& rhs) { + return lhs.imp == rhs.imp; } template -bool operator!=(const poca_alloc& lhs, const poca_alloc& rhs) -{ - return lhs.imp != rhs.imp; +bool operator!=(const poca_alloc& lhs, const poca_alloc& rhs) { + return lhs.imp != rhs.imp; } template -TEST_CONSTEXPR_CXX20 void test_assign(S &s1, const S& s2) -{ - try { s1 = s2; } - catch ( std::bad_alloc &) { return; } - assert(false); +TEST_CONSTEXPR_CXX20 void test_assign(S& s1, const S& s2) { + try { + s1 = s2; + } catch (std::bad_alloc&) { + return; + } + assert(false); } #endif +template +TEST_CONSTEXPR_CXX20 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); +} +template class Alloc> +TEST_CONSTEXPR_CXX20 void test_string() { + using A = Alloc; + using S = std::basic_string, A>; + test(S(), A()); + test(S("1"), A()); + test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A()); +} -template -TEST_CONSTEXPR_CXX20 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); +template <> +TEST_CONSTEXPR_CXX20 void test_string() { + using A = test_allocator; + using S = std::basic_string, A>; + test(S(), A(3)); + test(S("1"), A(5)); + test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7)); } 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(); #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(); -#ifndef TEST_HAS_NO_EXCEPTIONS +# ifndef TEST_HAS_NO_EXCEPTIONS if (!TEST_IS_CONSTANT_EVALUATED) { typedef poca_alloc A; typedef std::basic_string, A> S; - const char * p1 = "This is my first string"; - const char * p2 = "This is my second string"; + const char* p1 = "This is my first string"; + const char* p2 = "This is my second string"; alloc_imp imp1; alloc_imp imp2; @@ -125,14 +128,13 @@ assert(s1 == p1); assert(s2 == p2); } -#endif +# endif #endif return true; } -int main(int, char**) -{ +int main(int, char**) { test(); #if TEST_STD_VER > 17 static_assert(test()); diff --git a/libcxx/test/std/strings/basic.string/string.cons/default.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/default.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.cons/default.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.cons/default.pass.cpp @@ -20,9 +20,11 @@ // Test the noexcept specification, which is a conforming extension LIBCPP_STATIC_ASSERT(std::is_nothrow_default_constructible::value, ""); LIBCPP_STATIC_ASSERT(std::is_nothrow_default_constructible< - std::basic_string, test_allocator>>::value, ""); + std::basic_string, test_allocator > >::value, + ""); LIBCPP_STATIC_ASSERT(!std::is_nothrow_default_constructible< - std::basic_string, limited_allocator>>::value, ""); + std::basic_string, limited_allocator > >::value, + ""); #endif TEST_CONSTEXPR_CXX20 bool test() { diff --git a/libcxx/test/std/strings/basic.string/string.cons/dtor.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/dtor.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.cons/dtor.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.cons/dtor.pass.cpp @@ -35,15 +35,15 @@ #endif static_assert(std::is_nothrow_destructible::value, ""); -static_assert(std::is_nothrow_destructible< - std::basic_string, test_allocator>>::value, ""); -LIBCPP_STATIC_ASSERT(!std::is_nothrow_destructible< - std::basic_string, throwing_alloc>>::value, ""); +static_assert( + std::is_nothrow_destructible< std::basic_string, test_allocator > >::value, ""); +LIBCPP_STATIC_ASSERT( + !std::is_nothrow_destructible< std::basic_string, throwing_alloc > >::value, ""); TEST_CONSTEXPR_CXX20 bool test() { test_allocator_statistics alloc_stats; { - std::basic_string, test_allocator> str2((test_allocator(&alloc_stats))); + std::basic_string, test_allocator > str2((test_allocator(&alloc_stats))); str2 = "long long string so no SSO"; assert(alloc_stats.alloc_count == 1); } 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,37 +19,28 @@ #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 - { - typedef std::basic_string, min_allocator> S; - S s = {'a', 'b', 'c'}; - assert(s == "abc"); - } +template