[libc++] Prepare string tests for constexpr
These are the last™ changes to the tests for constexpr preparation. Reviewed By: Quuxplusone, #libc, Mordante Spies: Mordante, EricWF, libcxx-commits Differential Revision: https://reviews.llvm.org/D120951
This commit is contained in:
@@ -43,7 +43,7 @@ test(SV sv, std::size_t pos, std::size_t n)
|
||||
assert(s2.capacity() >= s2.size());
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else
|
||||
else if (!TEST_IS_CONSTANT_EVALUATED)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -76,7 +76,7 @@ test(SV sv, std::size_t pos, std::size_t n, const typename S::allocator_type& a)
|
||||
assert(s2.capacity() >= s2.size());
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else
|
||||
else if (!TEST_IS_CONSTANT_EVALUATED)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(S s1, typename S::value_type s2)
|
||||
{
|
||||
typedef typename S::traits_type T;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(S s1)
|
||||
{
|
||||
S s2 = s1;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
struct alloc_imp {
|
||||
bool active;
|
||||
|
||||
alloc_imp() : active(true) {}
|
||||
TEST_CONSTEXPR alloc_imp() : active(true) {}
|
||||
|
||||
template <class T>
|
||||
T* allocate(std::size_t n)
|
||||
@@ -45,10 +45,10 @@ struct poca_alloc {
|
||||
|
||||
alloc_imp *imp;
|
||||
|
||||
poca_alloc(alloc_imp *imp_) : imp (imp_) {}
|
||||
TEST_CONSTEXPR poca_alloc(alloc_imp *imp_) : imp (imp_) {}
|
||||
|
||||
template <class U>
|
||||
poca_alloc(const poca_alloc<U>& other) : imp(other.imp) {}
|
||||
TEST_CONSTEXPR poca_alloc(const poca_alloc<U>& other) : imp(other.imp) {}
|
||||
|
||||
T* allocate (std::size_t n) { return imp->allocate<T>(n);}
|
||||
void deallocate(T* p, std::size_t n) { imp->deallocate(p, n); }
|
||||
@@ -67,7 +67,7 @@ bool operator!=(const poca_alloc<T>& lhs, const poca_alloc<U>& rhs)
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void test_assign(S &s1, const S& s2)
|
||||
TEST_CONSTEXPR_CXX20 void test_assign(S &s1, const S& s2)
|
||||
{
|
||||
try { s1 = s2; }
|
||||
catch ( std::bad_alloc &) { return; }
|
||||
@@ -78,7 +78,7 @@ void test_assign(S &s1, const S& s2)
|
||||
|
||||
|
||||
template <class S>
|
||||
void
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(S s1, const typename S::allocator_type& a)
|
||||
{
|
||||
S s2(s1, a);
|
||||
@@ -106,7 +106,7 @@ bool test() {
|
||||
}
|
||||
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
{
|
||||
if (!TEST_IS_CONSTANT_EVALUATED) {
|
||||
typedef poca_alloc<char> A;
|
||||
typedef std::basic_string<char, std::char_traits<char>, A> S;
|
||||
const char * p1 = "This is my first string";
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class charT>
|
||||
void
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(std::basic_string_view<charT> sv)
|
||||
{
|
||||
typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
|
||||
@@ -47,7 +47,7 @@ test(std::basic_string_view<charT> sv)
|
||||
}
|
||||
|
||||
template <class charT, class A>
|
||||
void
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(std::basic_string_view<charT> sv, const A& a)
|
||||
{
|
||||
typedef std::basic_string<charT, std::char_traits<charT>, A> S;
|
||||
|
||||
@@ -45,7 +45,7 @@ test(S str, unsigned pos)
|
||||
assert(s2.capacity() >= s2.size());
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else
|
||||
else if (!TEST_IS_CONSTANT_EVALUATED)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -77,7 +77,7 @@ test(S str, unsigned pos, unsigned n)
|
||||
assert(s2.capacity() >= s2.size());
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else
|
||||
else if (!TEST_IS_CONSTANT_EVALUATED)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -109,7 +109,7 @@ test(S str, unsigned pos, unsigned n, const typename S::allocator_type& a)
|
||||
assert(s2.capacity() >= s2.size());
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else
|
||||
else if (!TEST_IS_CONSTANT_EVALUATED)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -124,11 +124,10 @@ test(S str, unsigned pos, unsigned n, const typename S::allocator_type& a)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if TEST_STD_VER >= 11
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
void test2583()
|
||||
{ // LWG #2583
|
||||
typedef std::basic_string<char, std::char_traits<char>, test_allocator<char> > StringA;
|
||||
void test_lwg2583()
|
||||
{
|
||||
#if TEST_STD_VER >= 11 && !defined(TEST_HAS_NO_EXCEPTIONS)
|
||||
typedef std::basic_string<char, std::char_traits<char>, test_allocator<char>> StringA;
|
||||
std::vector<StringA, std::scoped_allocator_adaptor<test_allocator<StringA>>> vs;
|
||||
StringA s{"1234"};
|
||||
vs.emplace_back(s, 2);
|
||||
@@ -136,9 +135,8 @@ void test2583()
|
||||
try { vs.emplace_back(s, 5); }
|
||||
catch (const std::out_of_range&) { return; }
|
||||
assert(false);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bool test() {
|
||||
{
|
||||
@@ -218,10 +216,6 @@ bool test() {
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 10, A());
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 100, A());
|
||||
}
|
||||
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
test2583();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return true;
|
||||
@@ -233,6 +227,7 @@ int main(int, char**)
|
||||
#if TEST_STD_VER > 17
|
||||
// static_assert(test());
|
||||
#endif
|
||||
test_lwg2583();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user