gcc/libstdc++-v3/testsuite/experimental/synchronized_value.cc
Jonathan Wakely 25264f6b3a libstdc++: Fix some AIX test failures
AIX <sys/thread.h> defines struct tstate with non-reserved names, so
adjust the 17_intro/names.cc test. It also defines struct user, which
conflicts with namespace user in some tests.

Replacing the global operator new doesn't work on AIX the same way as it
does for ELF, so skip some tests that depend on replacing it.

Add missing DG directives to synchronized_value test so it doesn't run
for the single-threaded AIX multilib.

libstdc++-v3/ChangeLog:

	* testsuite/17_intro/names.cc [_AIX]: Do not define policy.
	* testsuite/19_diagnostics/error_code/cons/lwg3629.cc: Rename
	namespace to avoid clashing with libc struct.
	* testsuite/19_diagnostics/error_condition/cons/lwg3629.cc:
	Likewise.
	* testsuite/23_containers/unordered_map/96088.cc: Skip on AIX.
	* testsuite/23_containers/unordered_multimap/96088.cc: Likewise.
	* testsuite/23_containers/unordered_multiset/96088.cc: Likewise.
	* testsuite/23_containers/unordered_set/96088.cc: Likewise.
	* testsuite/experimental/synchronized_value.cc: Require gthreads
	and add missing option for pthreads targets.
2023-04-12 23:25:17 +01:00

44 lines
894 B
C++

// { dg-do run { target c++17 } }
// { dg-additional-options "-pthread" { target pthread } }
// { dg-require-gthreads "" }
#include <experimental/synchronized_value>
#include <testsuite_hooks.h>
#include <string>
using std::experimental::synchronized_value;
synchronized_value<std::string> s;
std::string read_value(){
return apply([](auto& x){return x;},s);
}
void set_value(std::string const& new_val){
apply([&](auto& x){ x = new_val; }, s);
}
void
test_single()
{
set_value("new value");
VERIFY( read_value() == "new value" );
}
void
test_multi()
{
synchronized_value<int> a(1), b(2), c(3);
int sum = apply([](auto&... ints) { return (ints++ + ...); }, a, b, c);
VERIFY( sum == 6 );
auto get = [](int& i) { return i; };
VERIFY( apply(get, a) == 2 );
VERIFY( apply(get, b) == 3 );
VERIFY( apply(get, c) == 4 );
}
int main()
{
test_single();
test_multi();
}