Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct Throws {
bool Throws::sThrows = false;
#endif

int main(int, char**)
TEST_CONSTEXPR_CXX20 bool tests()
{
int a1[] = {1, 2, 3};
{
Expand Down Expand Up @@ -140,19 +140,30 @@ int main(int, char**)
assert(is_contiguous_container_asan_correct(outer[1]));
}
#endif

return true;
}

int main(int, char**)
{
tests();
#if TEST_STD_VER > 17
static_assert(tests());
#endif

#ifndef TEST_HAS_NO_EXCEPTIONS
// Test for LWG2853:
// Throws: Nothing unless an exception is thrown by the assignment operator or move assignment operator of T.
{
Throws arr[] = {1, 2, 3};
std::vector<Throws> v(arr, arr+3);
Throws::sThrows = true;
v.erase(v.begin(), --v.end());
assert(v.size() == 1);
v.erase(v.begin(), v.end());
assert(v.size() == 0);
Throws arr[] = {1, 2, 3};
std::vector<Throws> v(arr, arr+3);
Throws::sThrows = true;
v.erase(v.begin(), --v.end());
assert(v.size() == 1);
v.erase(v.begin(), v.end());
assert(v.size() == 0);
}
#endif

return 0;
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ void test_throwing() {
}
#endif // TEST_HAS_NO_EXCEPTIONS

int main(int, char**) {
#ifndef TEST_HAS_NO_EXCEPTIONS
test_throwing();
#endif
TEST_CONSTEXPR_CXX20 bool tests()
{
{
std::vector<int> d(10, 1);
std::vector<int>::iterator i = d.insert(d.cbegin() + 2, {3, 4, 5, 6});
Expand Down Expand Up @@ -101,5 +99,16 @@ int main(int, char**) {
assert(d[13] == 1);
}

return true;
}

int main(int, char**) {
#ifndef TEST_HAS_NO_EXCEPTIONS
test_throwing();
#endif
tests();
#if TEST_STD_VER > 17
static_assert(tests());
#endif
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct S {};
void make_move_iterator(S*) {}
}

int main(int, char**)
TEST_CONSTEXPR_CXX20 bool tests()
{
{
typedef std::vector<int> V;
Expand Down Expand Up @@ -182,5 +182,14 @@ int main(int, char**)
s.insert(s.end(), cpp17_input_iterator<adl::S*>(nullptr), cpp17_input_iterator<adl::S*>(nullptr));
}

return 0;
return true;
}

int main(int, char**)
{
tests();
#if TEST_STD_VER > 17
static_assert(tests());
#endif
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include "min_allocator.h"
#include "asan_testing.h"

int main(int, char**)
{
TEST_CONSTEXPR_CXX20 bool test() {

{
std::vector<int> v(100);
const int lvalue = 1;
Expand Down Expand Up @@ -116,5 +116,15 @@ int main(int, char**)
}
#endif

return true;
}

int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "min_allocator.h"
#include "asan_testing.h"

int main(int, char**)
TEST_CONSTEXPR_CXX20 bool tests()
{
{
std::vector<MoveOnly> v(100);
Expand Down Expand Up @@ -63,5 +63,14 @@ int main(int, char**)
assert(v[j] == MoveOnly());
}

return 0;
return true;
}

int main(int, char**)
{
tests();
#if TEST_STD_VER > 17
static_assert(tests());
#endif
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "min_allocator.h"
#include "asan_testing.h"

int main(int, char**)
TEST_CONSTEXPR_CXX20 bool tests()
{
{
std::vector<int> v(100);
Expand Down Expand Up @@ -112,5 +112,14 @@ int main(int, char**)
}
#endif

return 0;
return true;
}

int main(int, char**)
{
tests();
#if TEST_STD_VER > 17
static_assert(tests());
#endif
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "min_allocator.h"


int main(int, char**)
TEST_CONSTEXPR_CXX20 bool tests()
{
{
std::vector<int> c;
Expand Down Expand Up @@ -50,5 +50,14 @@ int main(int, char**)
assert(c[i] == i);
}

return 0;
return true;
}

int main(int, char**)
{
tests();
#if TEST_STD_VER > 17
static_assert(tests());
#endif
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "min_allocator.h"
#include "asan_testing.h"

int main(int, char**)
TEST_CONSTEXPR_CXX20 bool tests()
{
{
std::vector<int> c;
Expand Down Expand Up @@ -110,5 +110,14 @@ int main(int, char**)
}
#endif

return 0;
return true;
}

int main(int, char**)
{
tests();
#if TEST_STD_VER > 17
static_assert(tests());
#endif
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "min_allocator.h"
#include "asan_testing.h"

int main(int, char**)
TEST_CONSTEXPR_CXX20 bool tests()
{
{
std::vector<MoveOnly> c;
Expand Down Expand Up @@ -111,5 +111,14 @@ int main(int, char**)
assert(c[j] == MoveOnly(j));
}

return 0;
return true;
}

int main(int, char**)
{
tests();
#if TEST_STD_VER > 17
static_assert(tests());
#endif
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "min_allocator.h"
#include "asan_testing.h"

int main(int, char**)
TEST_CONSTEXPR_CXX20 bool tests()
{
{
int a1[] = {1, 3, 7, 9, 10};
Expand Down Expand Up @@ -180,5 +180,14 @@ int main(int, char**)
}
#endif

return 0;
return true;
}

int main(int, char**)
{
tests();
#if TEST_STD_VER > 17
static_assert(tests());
#endif
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

// UNSUPPORTED: c++03, c++11

// XFAIL: libcpp-has-debug-mode

#include <experimental/coroutine>
#include <vector>
#include <cassert>
Expand Down
21 changes: 11 additions & 10 deletions libcxx/test/support/allocators.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef ALLOCATORS_H
#define ALLOCATORS_H

#include <memory>
#include <type_traits>
#include <utility>

Expand Down Expand Up @@ -201,43 +202,43 @@ class MaybePOCCAAllocator {
typedef MaybePOCCAAllocator<U, POCCAValue> other;
};

MaybePOCCAAllocator() = default;
MaybePOCCAAllocator(int id, bool* copy_assigned_into)
TEST_CONSTEXPR MaybePOCCAAllocator() = default;
TEST_CONSTEXPR MaybePOCCAAllocator(int id, bool* copy_assigned_into)
: id_(id), copy_assigned_into_(copy_assigned_into) {}

template <class U>
MaybePOCCAAllocator(const MaybePOCCAAllocator<U, POCCAValue>& that)
: id_(that.id_), copy_assigned_into_(that.copy_assigned_into_) {}

MaybePOCCAAllocator(const MaybePOCCAAllocator&) = default;
MaybePOCCAAllocator& operator=(const MaybePOCCAAllocator& a)
TEST_CONSTEXPR_CXX14 MaybePOCCAAllocator& operator=(const MaybePOCCAAllocator& a)
{
id_ = a.id();
if (copy_assigned_into_)
*copy_assigned_into_ = true;
return *this;
}

T* allocate(std::size_t n)
TEST_CONSTEXPR_CXX20 T* allocate(std::size_t n)
{
return static_cast<T*>(::operator new(n * sizeof(T)));
return std::allocator<T>().allocate(n);
}

void deallocate(T* ptr, std::size_t)
TEST_CONSTEXPR_CXX20 void deallocate(T* ptr, std::size_t n)
{
::operator delete(ptr);
std::allocator<T>().deallocate(ptr, n);
}

int id() const { return id_; }
TEST_CONSTEXPR int id() const { return id_; }

template <class U>
friend bool operator==(const MaybePOCCAAllocator& lhs, const MaybePOCCAAllocator<U, POCCAValue>& rhs)
TEST_CONSTEXPR friend bool operator==(const MaybePOCCAAllocator& lhs, const MaybePOCCAAllocator<U, POCCAValue>& rhs)
{
return lhs.id() == rhs.id();
}

template <class U>
friend bool operator!=(const MaybePOCCAAllocator& lhs, const MaybePOCCAAllocator<U, POCCAValue>& rhs)
TEST_CONSTEXPR friend bool operator!=(const MaybePOCCAAllocator& lhs, const MaybePOCCAAllocator<U, POCCAValue>& rhs)
{
return !(lhs == rhs);
}
Expand Down
10 changes: 6 additions & 4 deletions libcxx/test/support/asan_testing.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ extern "C" int __sanitizer_verify_contiguous_container
( const void *beg, const void *mid, const void *end );

template <typename T, typename Alloc>
bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &c )
TEST_CONSTEXPR bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &c )
{
if ( std::is_same<Alloc, std::allocator<T> >::value && c.data() != NULL)
return __sanitizer_verify_contiguous_container (
if (std::__libcpp_is_constant_evaluated())
return true;
if (std::is_same<Alloc, std::allocator<T> >::value && c.data() != NULL)
return __sanitizer_verify_contiguous_container(
c.data(), c.data() + c.size(), c.data() + c.capacity()) != 0;
return true;
}

#else
template <typename T, typename Alloc>
bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &)
TEST_CONSTEXPR bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &)
{
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions libcxx/test/support/poisoned_hash_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ template <class ...Args> struct TypeList;

// Test that the specified Hash meets the requirements of an enabled hash
template <class Hash, class Key, class InputKey = Key>
void test_hash_enabled(InputKey const& key = InputKey{});
TEST_CONSTEXPR_CXX20 void test_hash_enabled(InputKey const& key = InputKey{});

template <class T, class InputKey = T>
void test_hash_enabled_for_type(InputKey const& key = InputKey{}) {
TEST_CONSTEXPR_CXX20 void test_hash_enabled_for_type(InputKey const& key = InputKey{}) {
return test_hash_enabled<std::hash<T>, T, InputKey>(key);
}

Expand Down Expand Up @@ -129,7 +129,7 @@ constexpr bool can_hash() {
} // namespace PoisonedHashDetail

template <class Hash, class Key, class InputKey>
void test_hash_enabled(InputKey const& key) {
TEST_CONSTEXPR_CXX20 void test_hash_enabled(InputKey const& key) {
using namespace PoisonedHashDetail;

static_assert(std::is_destructible<Hash>::value, "");
Expand Down
23 changes: 16 additions & 7 deletions libcxx/test/support/test_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "test_macros.h"

template <class Alloc>
inline typename std::allocator_traits<Alloc>::size_type alloc_max_size(Alloc const& a) {
TEST_CONSTEXPR_CXX20 inline typename std::allocator_traits<Alloc>::size_type alloc_max_size(Alloc const& a) {
typedef std::allocator_traits<Alloc> AT;
return AT::max_size(a);
}
Expand Down Expand Up @@ -165,8 +165,12 @@ class test_allocator {
TEST_CONSTEXPR size_type max_size() const TEST_NOEXCEPT { return UINT_MAX / sizeof(T); }

template <class U>
TEST_CONSTEXPR_CXX14 void construct(pointer p, U&& val) {
TEST_CONSTEXPR_CXX20 void construct(pointer p, U&& val) {
#if TEST_STD_VER > 17
std::construct_at(std::to_address(p), std::forward<U>(val));
#else
::new (static_cast<void*>(p)) T(std::forward<U>(val));
#endif
}

TEST_CONSTEXPR_CXX14 void destroy(pointer p) { p->~T(); }
Expand Down Expand Up @@ -399,12 +403,16 @@ class TaggingAllocator {
TEST_CONSTEXPR TaggingAllocator(const TaggingAllocator<U>&) {}

template <typename... Args>
void construct(Tag_X* p, Args&&... args) {
::new ((void*)p) Tag_X(Ctor_Tag(), std::forward<Args>(args)...);
TEST_CONSTEXPR_CXX20 void construct(Tag_X* p, Args&&... args) {
#if TEST_STD_VER > 17
std::construct_at(p, Ctor_Tag{}, std::forward<Args>(args)...);
#else
::new (static_cast<void*>(p)) Tag_X(Ctor_Tag(), std::forward<Args>(args)...);
#endif
}

template <typename U>
void destroy(U* p) {
TEST_CONSTEXPR_CXX20 void destroy(U* p) {
p->~U();
}

Expand All @@ -421,9 +429,10 @@ struct limited_alloc_handle {
TEST_CONSTEXPR_CXX20 T* allocate(std::size_t N) {
if (N + outstanding_ > MaxAllocs)
TEST_THROW(std::bad_alloc());
last_alloc_ = std::allocator<T>().allocate(N);
auto alloc = std::allocator<T>().allocate(N);
last_alloc_ = alloc;
outstanding_ += N;
return static_cast<T*>(last_alloc_);
return alloc;
}

template <class T>
Expand Down