llvm-project/libcxx/test/support/test_execution_policies.h
Louis Dionne 9ff36c24a0 [libc++] Guard terminate_successful with TEST_HAS_NO_EXCEPTIONS
This one is a bit twisted. Some platforms don't have support for
exiting in a clean manner, so they don't provide std::exit(). As
a result, defining `terminate_successful()` on those platforms won't
work, and the PSTL tests that rely on `terminate_successful()` also
won't work.

However, we don't have a notion of "no clean termination" in libc++,
so we can't properly guard this. Since embedded platforms that don't
support clean termination usually also don't enable exceptions, we
don't need to be able to run those `terminate_successful` PSTL tests,
and guarding the definition of `terminate_successful` with
TEST_HAS_NO_EXCEPTIONS works pretty well.

This is kind of a hack for the lack of having a concept of "no clean
termination" in the library and in the test suite.

Differential Revision: https://reviews.llvm.org/D153302
2023-06-21 08:34:51 -04:00

66 lines
2.4 KiB
C++

//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef TEST_SUPPORT_TEST_EXECUTION_POLICIES
#define TEST_SUPPORT_TEST_EXECUTION_POLICIES
#include <cstdlib>
#include <exception>
#include <execution>
#include <type_traits>
#include <utility>
#include "test_macros.h"
#define EXECUTION_POLICY_SFINAE_TEST(function) \
template <class, class...> \
struct sfinae_test_##function##_impl : std::true_type {}; \
\
template <class... Args> \
struct sfinae_test_##function##_impl<std::void_t<decltype(std::function(std::declval<Args>()...))>, Args...> \
: std::false_type {}; \
\
template <class... Args> \
constexpr bool sfinae_test_##function = sfinae_test_##function##_impl<void, Args...>::value;
template <class Functor>
bool test_execution_policies(Functor func) {
func(std::execution::seq);
#if TEST_STD_VER >= 20
func(std::execution::unseq);
#endif
func(std::execution::par);
func(std::execution::par_unseq);
return true;
}
template <template <class Iter> class TestClass>
struct TestIteratorWithPolicies {
template <class Iter>
void operator()() {
test_execution_policies(TestClass<Iter>{});
}
};
struct Bool {
bool b_;
Bool() = default;
Bool(bool b) : b_(b) {}
operator bool&() {
return b_;
}
};
#ifndef TEST_HAS_NO_EXCEPTIONS
[[noreturn]] inline void terminate_successful() { std::exit(0); }
#endif
#endif // TEST_SUPPORT_TEST_EXECUTION_POLICIES