You've already forked Zygisk-Assistant
mirror of
https://github.com/snake-4/Zygisk-Assistant.git
synced 2025-09-06 06:37:02 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// size_type capacity() const; // constexpr since C++20
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_allocator.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(S s, test_allocator_statistics& alloc_stats)
|
||||
{
|
||||
alloc_stats.throw_after = 0;
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
try
|
||||
#endif
|
||||
{
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
alloc_stats.throw_after = INT_MAX;
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
test_allocator_statistics alloc_stats;
|
||||
typedef std::basic_string<char, std::char_traits<char>, test_allocator<char> > S;
|
||||
S s((test_allocator<char>(&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<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
S s;
|
||||
assert(s.capacity() > 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// void clear(); // constexpr since C++20
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(S s)
|
||||
{
|
||||
s.clear();
|
||||
assert(s.size() == 0);
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
S s;
|
||||
test(s);
|
||||
|
||||
s.assign(10, 'a');
|
||||
s.erase(5);
|
||||
test(s);
|
||||
|
||||
s.assign(100, 'a');
|
||||
s.erase(50);
|
||||
test(s);
|
||||
}
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
S s;
|
||||
test(s);
|
||||
|
||||
s.assign(10, 'a');
|
||||
s.erase(5);
|
||||
test(s);
|
||||
|
||||
s.assign(100, 'a');
|
||||
s.erase(50);
|
||||
test(s);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// bool empty() const noexcept; // constexpr since C++20
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(const S& s)
|
||||
{
|
||||
ASSERT_NOEXCEPT(s.empty());
|
||||
assert(s.empty() == (s.size() == 0));
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S());
|
||||
test(S("123"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"));
|
||||
}
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test(S());
|
||||
test(S("123"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"));
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// class deque
|
||||
|
||||
// bool empty() const noexcept; // constexpr since C++20
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
std::string c;
|
||||
c.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// size_type length() const; // constexpr since C++20
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(const S& s)
|
||||
{
|
||||
assert(s.length() == s.size());
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S());
|
||||
test(S("123"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"));
|
||||
}
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test(S());
|
||||
test(S("123"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"));
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: no-exceptions
|
||||
// <string>
|
||||
|
||||
// size_type max_size() const; // constexpr since C++20
|
||||
|
||||
// NOTE: asan and msan will fail for one of two reasons
|
||||
// 1. If allocator_may_return_null=0 then they will fail because the allocation
|
||||
// returns null.
|
||||
// 2. If allocator_may_return_null=1 then they will fail because the allocation
|
||||
// is too large to succeed.
|
||||
// UNSUPPORTED: sanitizer-new-delete
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
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 <class S>
|
||||
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 <class S>
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(const S& s)
|
||||
{
|
||||
assert(s.max_size() >= s.size());
|
||||
test1(s);
|
||||
test2(s);
|
||||
}
|
||||
|
||||
void test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S());
|
||||
test(S("123"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"));
|
||||
}
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test(S());
|
||||
test(S("123"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if TEST_STD_VER > 17
|
||||
constexpr bool test_constexpr() {
|
||||
std::string str;
|
||||
|
||||
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());
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: no-exceptions
|
||||
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11}}
|
||||
|
||||
// Prior to http://llvm.org/D123580, there was a bug with how the max_size()
|
||||
// was calculated. That was inlined into some functions in the dylib, which leads
|
||||
// to failures when running this test against an older system dylib.
|
||||
// XFAIL: use_system_cxx_lib && target=arm64-apple-macosx{{11.0|12.0}}
|
||||
|
||||
// <string>
|
||||
|
||||
// size_type max_size() const; // constexpr since C++20
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
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 );
|
||||
}
|
||||
|
||||
bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S());
|
||||
test(S("123"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"));
|
||||
}
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test(S());
|
||||
test(S("123"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"));
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
test();
|
||||
|
||||
return 0;
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// void reserve(); // Deprecated in C++20
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17
|
||||
|
||||
#include <string>
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
std::string s;
|
||||
s.reserve(); // expected-warning {{'reserve' is deprecated}}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// void reserve(); // Deprecated in C++20.
|
||||
|
||||
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
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());
|
||||
}
|
||||
|
||||
bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
{
|
||||
test<S>(0, 0);
|
||||
test<S>(10, 5);
|
||||
test<S>(100, 50);
|
||||
}
|
||||
}
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
{
|
||||
test<S>(0, 0);
|
||||
test<S>(10, 5);
|
||||
test<S>(100, 50);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
test();
|
||||
|
||||
return 0;
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// void reserve(size_type res_arg); // constexpr since C++20
|
||||
|
||||
// This test relies on https://llvm.org/PR45368 being fixed, which isn't in
|
||||
// older Apple dylibs
|
||||
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx{{10.9|10.10|10.11|10.12|10.13|10.14|10.15|11.0}}
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
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.
|
||||
|
||||
#if TEST_STD_VER > 17
|
||||
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());
|
||||
#if TEST_STD_VER > 17
|
||||
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());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
{
|
||||
test<S>(0, 0, 5);
|
||||
test<S>(0, 0, 10);
|
||||
test<S>(0, 0, 50);
|
||||
}
|
||||
{
|
||||
test<S>(100, 50, 5);
|
||||
test<S>(100, 50, 10);
|
||||
test<S>(100, 50, 50);
|
||||
test<S>(100, 50, 100);
|
||||
test<S>(100, 50, 1000);
|
||||
test<S>(100, 50, S::npos);
|
||||
}
|
||||
}
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
{
|
||||
test<S>(0, 0, 5);
|
||||
test<S>(0, 0, 10);
|
||||
test<S>(0, 0, 50);
|
||||
}
|
||||
{
|
||||
test<S>(100, 50, 5);
|
||||
test<S>(100, 50, 10);
|
||||
test<S>(100, 50, 50);
|
||||
test<S>(100, 50, 100);
|
||||
test<S>(100, 50, 1000);
|
||||
test<S>(100, 50, S::npos);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <string>
|
||||
|
||||
// template<class Operation>
|
||||
// void resize_and_overwrite(size_type n, Operation op)
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
|
||||
#include "make_string.h"
|
||||
#include "test_macros.h"
|
||||
|
||||
template <class S>
|
||||
constexpr void test_appending(size_t k, size_t N, size_t new_capacity) {
|
||||
assert(N > k);
|
||||
assert(new_capacity >= N);
|
||||
auto s = S(k, 'a');
|
||||
s.resize_and_overwrite(new_capacity, [&](auto* p, auto n) {
|
||||
assert(n == new_capacity);
|
||||
LIBCPP_ASSERT(s.size() == new_capacity);
|
||||
LIBCPP_ASSERT(s.begin().base() == p);
|
||||
assert(std::all_of(p, p + k, [](const auto ch) { return ch == 'a'; }));
|
||||
std::fill(p + k, p + n, 'b');
|
||||
p[n] = 'c'; // will be overwritten
|
||||
return N;
|
||||
});
|
||||
const S expected = S(k, 'a') + S(N - k, 'b');
|
||||
assert(s == expected);
|
||||
assert(s.c_str()[N] == '\0');
|
||||
}
|
||||
|
||||
template <class S>
|
||||
constexpr void test_truncating(size_t o, size_t N) {
|
||||
assert(N < o);
|
||||
auto s = S(o, 'a');
|
||||
s.resize_and_overwrite(N, [&](auto* p, auto n) {
|
||||
assert(n == N);
|
||||
LIBCPP_ASSERT(s.size() == n);
|
||||
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
|
||||
return n;
|
||||
});
|
||||
const S expected = S(N - 1, 'a') + S(1, 'b');
|
||||
assert(s == expected);
|
||||
assert(s.c_str()[N] == '\0');
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
constexpr bool test() {
|
||||
using S = std::basic_string<CharT>;
|
||||
test_appending<S>(10, 15, 15);
|
||||
test_appending<S>(10, 15, 20);
|
||||
test_appending<S>(10, 40, 40);
|
||||
test_appending<S>(10, 40, 50);
|
||||
test_appending<S>(30, 35, 35);
|
||||
test_appending<S>(30, 35, 45);
|
||||
test_appending<S>(10, 15, 30);
|
||||
test_truncating<S>(15, 10);
|
||||
test_truncating<S>(40, 35);
|
||||
test_truncating<S>(40, 10);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void test_value_categories() {
|
||||
std::string s;
|
||||
s.resize_and_overwrite(10, [](char*&&, size_t&&) { return 0; });
|
||||
s.resize_and_overwrite(10, [](char* const&, const size_t&) { return 0; });
|
||||
struct RefQualified {
|
||||
int operator()(char*, size_t) && { return 0; }
|
||||
};
|
||||
s.resize_and_overwrite(10, RefQualified{});
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<char>();
|
||||
test<char8_t>();
|
||||
test<char16_t>();
|
||||
test<char32_t>();
|
||||
|
||||
static_assert(test<char>());
|
||||
static_assert(test<char8_t>());
|
||||
static_assert(test<char16_t>());
|
||||
static_assert(test<char32_t>());
|
||||
|
||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
test<wchar_t>();
|
||||
static_assert(test<wchar_t>());
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// void resize(size_type n); // constexpr since C++20
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
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());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S(), 0, S());
|
||||
test(S(), 1, S(1, '\0'));
|
||||
test(S(), 10, S(10, '\0'));
|
||||
test(S(), 100, S(100, '\0'));
|
||||
test(S("12345"), 0, S());
|
||||
test(S("12345"), 2, S("12"));
|
||||
test(S("12345"), 5, S("12345"));
|
||||
test(S("12345"), 15, S("12345\0\0\0\0\0\0\0\0\0\0", 15));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 0, S());
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 10,
|
||||
S("1234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 50,
|
||||
S("12345678901234567890123456789012345678901234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 60,
|
||||
S("12345678901234567890123456789012345678901234567890\0\0\0\0\0\0\0\0\0\0", 60));
|
||||
test(S(), S::npos, S("not going to happen"));
|
||||
}
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test(S(), 0, S());
|
||||
test(S(), 1, S(1, '\0'));
|
||||
test(S(), 10, S(10, '\0'));
|
||||
test(S(), 100, S(100, '\0'));
|
||||
test(S("12345"), 0, S());
|
||||
test(S("12345"), 2, S("12"));
|
||||
test(S("12345"), 5, S("12345"));
|
||||
test(S("12345"), 15, S("12345\0\0\0\0\0\0\0\0\0\0", 15));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 0, S());
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 10,
|
||||
S("1234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 50,
|
||||
S("12345678901234567890123456789012345678901234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 60,
|
||||
S("12345678901234567890123456789012345678901234567890\0\0\0\0\0\0\0\0\0\0", 60));
|
||||
test(S(), S::npos, S("not going to happen"));
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// void resize(size_type n, charT c); // constexpr since C++20
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
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());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S(), 0, 'a', S());
|
||||
test(S(), 1, 'a', S("a"));
|
||||
test(S(), 10, 'a', S(10, 'a'));
|
||||
test(S(), 100, 'a', S(100, 'a'));
|
||||
test(S("12345"), 0, 'a', S());
|
||||
test(S("12345"), 2, 'a', S("12"));
|
||||
test(S("12345"), 5, 'a', S("12345"));
|
||||
test(S("12345"), 15, 'a', S("12345aaaaaaaaaa"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 0, 'a', S());
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 10, 'a',
|
||||
S("1234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 50, 'a',
|
||||
S("12345678901234567890123456789012345678901234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 60, 'a',
|
||||
S("12345678901234567890123456789012345678901234567890aaaaaaaaaa"));
|
||||
test(S(), S::npos, 'a', S("not going to happen"));
|
||||
}
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test(S(), 0, 'a', S());
|
||||
test(S(), 1, 'a', S("a"));
|
||||
test(S(), 10, 'a', S(10, 'a'));
|
||||
test(S(), 100, 'a', S(100, 'a'));
|
||||
test(S("12345"), 0, 'a', S());
|
||||
test(S("12345"), 2, 'a', S("12"));
|
||||
test(S("12345"), 5, 'a', S("12345"));
|
||||
test(S("12345"), 15, 'a', S("12345aaaaaaaaaa"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 0, 'a', S());
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 10, 'a',
|
||||
S("1234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 50, 'a',
|
||||
S("12345678901234567890123456789012345678901234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 60, 'a',
|
||||
S("12345678901234567890123456789012345678901234567890aaaaaaaaaa"));
|
||||
test(S(), S::npos, 'a', S("not going to happen"));
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// This test checks that we can explicitly instantiate std::string with a custom
|
||||
// character type and traits and then use `shrink_to_fit`. In particular, this is
|
||||
// a regression test for the bug that was reported at https://stackoverflow.com/q/69520633/627587
|
||||
// and https://seedcentral.apple.com/sm/feedback_collector/radar/85053279.
|
||||
|
||||
// RUN: %{cxx} %{flags} %{compile_flags} %s %{link_flags} -DTU1 -c -o %t.tu1.o
|
||||
// RUN: %{cxx} %{flags} %{compile_flags} %s %{link_flags} -DTU2 -c -o %t.tu2.o
|
||||
// RUN: %{cxx} %{flags} %t.tu1.o %t.tu2.o %{link_flags} -o %t.exe
|
||||
|
||||
// UNSUPPORTED: no-localization
|
||||
|
||||
#include <cstdint>
|
||||
#include <ios>
|
||||
#include <string>
|
||||
|
||||
typedef std::uint16_t char16;
|
||||
|
||||
struct string16_char_traits {
|
||||
typedef char16 char_type;
|
||||
typedef int int_type;
|
||||
|
||||
typedef std::streamoff off_type;
|
||||
typedef std::mbstate_t state_type;
|
||||
typedef std::fpos<state_type> pos_type;
|
||||
|
||||
static void assign(char_type&, const char_type&) { }
|
||||
static bool eq(const char_type&, const char_type&) { return false; }
|
||||
static bool lt(const char_type&, const char_type&) { return false; }
|
||||
static int compare(const char_type*, const char_type*, size_t) { return 0; }
|
||||
static size_t length(const char_type*) { return 0; }
|
||||
static const char_type* find(const char_type*, size_t, const char_type&) { return nullptr; }
|
||||
static char_type* move(char_type*, const char_type*, size_t) { return nullptr; }
|
||||
static char_type* copy(char_type*, const char_type*, size_t) { return nullptr; }
|
||||
static char_type* assign(char_type*, size_t, char_type) { return nullptr; }
|
||||
static int_type not_eof(const int_type&) { return 0; }
|
||||
static char_type to_char_type(const int_type&) { return char_type(); }
|
||||
static int_type to_int_type(const char_type&) { return int_type(); }
|
||||
static bool eq_int_type(const int_type&, const int_type&) { return false; }
|
||||
static int_type eof() { return int_type(); }
|
||||
};
|
||||
|
||||
#if defined(TU1)
|
||||
template class std::basic_string<char16, string16_char_traits>;
|
||||
#else
|
||||
extern template class std::basic_string<char16, string16_char_traits>;
|
||||
|
||||
int main() {
|
||||
std::basic_string<char16, string16_char_traits> s;
|
||||
s.shrink_to_fit();
|
||||
}
|
||||
#endif
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// void shrink_to_fit(); // constexpr since C++20
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
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 bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
S s;
|
||||
test(s);
|
||||
|
||||
s.assign(10, 'a');
|
||||
s.erase(5);
|
||||
test(s);
|
||||
|
||||
s.assign(100, 'a');
|
||||
s.erase(50);
|
||||
test(s);
|
||||
}
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
S s;
|
||||
test(s);
|
||||
|
||||
s.assign(10, 'a');
|
||||
s.erase(5);
|
||||
test(s);
|
||||
|
||||
s.assign(100, 'a');
|
||||
s.erase(50);
|
||||
test(s);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// size_type size() const; // constexpr since C++20
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test(const S& s, typename S::size_type c)
|
||||
{
|
||||
assert(s.size() == c);
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S(), 0);
|
||||
test(S("123"), 3);
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 50);
|
||||
}
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test(S(), 0);
|
||||
test(S("123"), 3);
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 50);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user