@@ -45,12 +45,12 @@ template <class T, class StoreOp, class LoadOp>
4545void test_seq_cst (StoreOp store_op, LoadOp load_op) {
4646#ifndef TEST_HAS_NO_THREADS
4747 for (int i = 0 ; i < 100 ; ++i) {
48- T old_value (make_value<T >(0 ));
49- T new_value (make_value<T >(1 ));
48+ T old_value (make_value<std:: remove_cv_t <T> >(0 ));
49+ T new_value (make_value<std:: remove_cv_t <T> >(1 ));
5050
51- T copy_x = old_value;
51+ T copy_x = const_cast <std:: remove_cv_t <T> const &>( old_value) ;
5252 std::atomic_ref<T> const x (copy_x);
53- T copy_y = old_value;
53+ T copy_y = const_cast <std:: remove_cv_t <T> const &>( old_value) ;
5454 std::atomic_ref<T> const y (copy_y);
5555
5656 std::atomic_bool x_updated_first (false );
@@ -61,19 +61,19 @@ void test_seq_cst(StoreOp store_op, LoadOp load_op) {
6161 auto t2 = support::make_test_thread ([&] { store_op (y, old_value, new_value); });
6262
6363 auto t3 = support::make_test_thread ([&] {
64- while (!equals (load_op (x), new_value)) {
64+ while (!equals (load_op (x), const_cast <std:: remove_cv_t <T> const &>( new_value) )) {
6565 std::this_thread::yield ();
6666 }
67- if (!equals (load_op (y), new_value)) {
67+ if (!equals (load_op (y), const_cast <std:: remove_cv_t <T> const &>( new_value) )) {
6868 x_updated_first.store (true , std::memory_order_relaxed);
6969 }
7070 });
7171
7272 auto t4 = support::make_test_thread ([&] {
73- while (!equals (load_op (y), new_value)) {
73+ while (!equals (load_op (y), const_cast <std:: remove_cv_t <T> const &>( new_value) )) {
7474 std::this_thread::yield ();
7575 }
76- if (!equals (load_op (x), new_value)) {
76+ if (!equals (load_op (x), const_cast <std:: remove_cv_t <T> const &>( new_value) )) {
7777 y_updated_first.store (true , std::memory_order_relaxed);
7878 }
7979 });
@@ -98,10 +98,10 @@ template <class T, class StoreOp, class LoadOp>
9898void test_acquire_release (StoreOp store_op, LoadOp load_op) {
9999#ifndef TEST_HAS_NO_THREADS
100100 for (auto i = 0 ; i < 100 ; ++i) {
101- T old_value (make_value<T >(0 ));
102- T new_value (make_value<T >(1 ));
101+ T old_value (make_value<std:: remove_cv_t <T> >(0 ));
102+ T new_value (make_value<std:: remove_cv_t <T> >(1 ));
103103
104- T copy = old_value;
104+ T copy = const_cast <std:: remove_cv_t <T> const &>( old_value) ;
105105 std::atomic_ref<T> const at (copy);
106106 int non_atomic = 5 ;
107107
@@ -110,14 +110,15 @@ void test_acquire_release(StoreOp store_op, LoadOp load_op) {
110110 threads.reserve (number_of_threads);
111111
112112 for (auto j = 0 ; j < number_of_threads; ++j) {
113- threads.push_back (support::make_test_thread ([&at, &non_atomic, load_op, new_value] {
114- while (!equals (load_op (at), new_value)) {
115- std::this_thread::yield ();
116- }
117- // Other thread's writes before the release store are visible
118- // in this thread's read after the acquire load
119- assert (non_atomic == 6 );
120- }));
113+ threads.push_back (support::make_test_thread (
114+ [&at, &non_atomic, load_op, new_value = const_cast <std::remove_cv_t <T> const &>(new_value)] {
115+ while (!equals (load_op (at), new_value)) {
116+ std::this_thread::yield ();
117+ }
118+ // Other thread's writes before the release store are visible
119+ // in this thread's read after the acquire load
120+ assert (non_atomic == 6 );
121+ }));
121122 }
122123
123124 non_atomic = 6 ;
0 commit comments