[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:
@@ -19,8 +19,8 @@ template<class T> struct Holder { T t; };
|
||||
template<class T>
|
||||
struct Charlike {
|
||||
char ch_;
|
||||
Charlike(char ch) : ch_(ch) {}
|
||||
operator char() const { return ch_; }
|
||||
TEST_CONSTEXPR Charlike(char ch) : ch_(ch) {}
|
||||
TEST_CONSTEXPR operator char() const { return ch_; }
|
||||
};
|
||||
|
||||
bool test() {
|
||||
|
||||
@@ -30,7 +30,7 @@ test(S s, SV sv, typename S::size_type pos, typename S::size_type n, S expected)
|
||||
assert(s == expected);
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else
|
||||
else if (!TEST_IS_CONSTANT_EVALUATED)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -56,7 +56,7 @@ test_npos(S s, SV sv, typename S::size_type pos, S expected)
|
||||
assert(s == expected);
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else
|
||||
else if (!TEST_IS_CONSTANT_EVALUATED)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -172,7 +172,7 @@ bool test() {
|
||||
}
|
||||
#endif
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
{ // test iterator operations that throw
|
||||
if (!TEST_IS_CONSTANT_EVALUATED) { // test iterator operations that throw
|
||||
typedef std::string S;
|
||||
typedef ThrowingIterator<char> TIter;
|
||||
typedef cpp17_input_iterator<TIter> IIter;
|
||||
@@ -219,17 +219,20 @@ bool test() {
|
||||
std::string s_short = "hello";
|
||||
std::string s_long = "Lorem ipsum dolor sit amet, consectetur/";
|
||||
std::string s_othertype = "hello";
|
||||
const unsigned char *first = reinterpret_cast<const unsigned char*>(s_othertype.data());
|
||||
std::string s_sneaky = "hello";
|
||||
|
||||
test(s_short, s_short.data() + s_short.size(), s_short.data() + s_short.size() + 1,
|
||||
std::string("hello\0", 6));
|
||||
test(s_long, s_long.data() + s_long.size(), s_long.data() + s_long.size() + 1,
|
||||
std::string("Lorem ipsum dolor sit amet, consectetur/\0", 41));
|
||||
test(s_othertype, first + 2, first + 5, std::string("hellollo"));
|
||||
|
||||
s_sneaky.reserve(12);
|
||||
test(s_sneaky, s_sneaky.data(), s_sneaky.data() + 6, std::string("hellohello\0", 11));
|
||||
|
||||
if (!TEST_IS_CONSTANT_EVALUATED) {
|
||||
const unsigned char *first = reinterpret_cast<const unsigned char*>(s_othertype.data());
|
||||
test(s_othertype, first + 2, first + 5, std::string("hellollo"));
|
||||
}
|
||||
}
|
||||
|
||||
{ // test with a move iterator that returns char&&
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(S s, const typename S::value_type* str, S expected)
|
||||
{
|
||||
s.append(str);
|
||||
|
||||
@@ -30,7 +30,7 @@ test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected)
|
||||
assert(s == expected);
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else
|
||||
else if (!TEST_IS_CONSTANT_EVALUATED)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -56,7 +56,7 @@ test_npos(S s, S str, typename S::size_type pos, S expected)
|
||||
assert(s == expected);
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else
|
||||
else if (!TEST_IS_CONSTANT_EVALUATED)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S, class SV>
|
||||
void
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(S s, SV sv, typename S::size_type pos, typename S::size_type n, S expected)
|
||||
{
|
||||
if (pos <= sv.size())
|
||||
@@ -29,7 +29,7 @@ test(S s, SV sv, typename S::size_type pos, typename S::size_type n, S expected)
|
||||
assert(s == expected);
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else
|
||||
else if (!TEST_IS_CONSTANT_EVALUATED)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -45,7 +45,7 @@ test(S s, SV sv, typename S::size_type pos, typename S::size_type n, S expected)
|
||||
}
|
||||
|
||||
template <class S, class SV>
|
||||
void
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test_npos(S s, SV sv, typename S::size_type pos, S expected)
|
||||
{
|
||||
if (pos <= sv.size())
|
||||
@@ -55,7 +55,7 @@ test_npos(S s, SV sv, typename S::size_type pos, S expected)
|
||||
assert(s == expected);
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
else
|
||||
else if (!TEST_IS_CONSTANT_EVALUATED)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S, class It>
|
||||
void
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(S s, It first, It last, S expected)
|
||||
{
|
||||
s.assign(first, last);
|
||||
@@ -172,7 +172,7 @@ bool test() {
|
||||
}
|
||||
#endif
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
{ // test iterator operations that throw
|
||||
if (!TEST_IS_CONSTANT_EVALUATED) { // test iterator operations that throw
|
||||
typedef std::string S;
|
||||
typedef ThrowingIterator<char> TIter;
|
||||
typedef cpp17_input_iterator<TIter> IIter;
|
||||
|
||||
Reference in New Issue
Block a user