From 99c04cc73a225ffa493d37f0d584568b8fbc8a6d Mon Sep 17 00:00:00 2001 From: Shengxin Pei Date: Thu, 20 Aug 2026 17:42:13 +0800 Subject: [PATCH 1/2] Deprecate volatile atomic increment, decrement, and wait/notify operations --- stl/inc/atomic | 11 ++++ tests/std/test.lst | 1 + .../env.lst | 4 ++ .../test.cpp | 50 +++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 tests/std/tests/P1831R1_deprecated_volatile_atomic/env.lst create mode 100644 tests/std/tests/P1831R1_deprecated_volatile_atomic/test.cpp diff --git a/stl/inc/atomic b/stl/inc/atomic index 74e81813616..ecd01a238a2 100644 --- a/stl/inc/atomic +++ b/stl/inc/atomic @@ -1662,19 +1662,23 @@ struct _Atomic_integral_facade : _Atomic_integral<_Ty> { using _Base::operator++; _Ty operator++(int) volatile noexcept { + (void) _Deprecate_non_lock_free_volatile<_Ty>; return const_cast<_Atomic_integral_facade*>(this)->_Base::operator++(0); } _Ty operator++() volatile noexcept { + (void) _Deprecate_non_lock_free_volatile<_Ty>; return const_cast<_Atomic_integral_facade*>(this)->_Base::operator++(); } using _Base::operator--; _Ty operator--(int) volatile noexcept { + (void) _Deprecate_non_lock_free_volatile<_Ty>; return const_cast<_Atomic_integral_facade*>(this)->_Base::operator--(0); } _Ty operator--() volatile noexcept { + (void) _Deprecate_non_lock_free_volatile<_Ty>; return const_cast<_Atomic_integral_facade*>(this)->_Base::operator--(); } @@ -1960,6 +1964,7 @@ struct _Atomic_pointer : _Atomic_storage<_Ty> { } _Ty operator++(int) volatile noexcept { + (void) _Deprecate_non_lock_free_volatile<_Ty>; return fetch_add(1); } @@ -1968,6 +1973,7 @@ struct _Atomic_pointer : _Atomic_storage<_Ty> { } _Ty operator++() volatile noexcept { + (void) _Deprecate_non_lock_free_volatile<_Ty>; return fetch_add(1) + 1; } @@ -1976,6 +1982,7 @@ struct _Atomic_pointer : _Atomic_storage<_Ty> { } _Ty operator--(int) volatile noexcept { + (void) _Deprecate_non_lock_free_volatile<_Ty>; return fetch_add(-1); } @@ -1984,6 +1991,7 @@ struct _Atomic_pointer : _Atomic_storage<_Ty> { } _Ty operator--() volatile noexcept { + (void) _Deprecate_non_lock_free_volatile<_Ty>; return fetch_add(-1) - 1; } @@ -2242,16 +2250,19 @@ public: #if _HAS_CXX20 using _Base::wait; void wait(const _Ty _Expected, const memory_order _Order = memory_order_seq_cst) const volatile noexcept { + (void) _Deprecate_non_lock_free_volatile<_Ty>; const_cast(this)->_Base::wait(_Expected, _Order); } using _Base::notify_one; void notify_one() volatile noexcept { + (void) _Deprecate_non_lock_free_volatile<_Ty>; const_cast(this)->_Base::notify_one(); } using _Base::notify_all; void notify_all() volatile noexcept { + (void) _Deprecate_non_lock_free_volatile<_Ty>; const_cast(this)->_Base::notify_all(); } #endif // _HAS_CXX20 diff --git a/tests/std/test.lst b/tests/std/test.lst index cce97d793eb..c5204f5176c 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -640,6 +640,7 @@ tests\P1645R1_constexpr_numeric tests\P1659R3_ranges_alg_ends_with tests\P1659R3_ranges_alg_starts_with tests\P1682R3_to_underlying +tests\P1831R1_deprecated_volatile_atomic tests\P1899R3_views_stride tests\P1899R3_views_stride_death tests\P1951R1_default_arguments_pair_forward_ctor diff --git a/tests/std/tests/P1831R1_deprecated_volatile_atomic/env.lst b/tests/std/tests/P1831R1_deprecated_volatile_atomic/env.lst new file mode 100644 index 00000000000..642f530ffad --- /dev/null +++ b/tests/std/tests/P1831R1_deprecated_volatile_atomic/env.lst @@ -0,0 +1,4 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +RUNALL_INCLUDE ..\usual_latest_matrix.lst diff --git a/tests/std/tests/P1831R1_deprecated_volatile_atomic/test.cpp b/tests/std/tests/P1831R1_deprecated_volatile_atomic/test.cpp new file mode 100644 index 00000000000..5528b35b4bc --- /dev/null +++ b/tests/std/tests/P1831R1_deprecated_volatile_atomic/test.cpp @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include +#include + +using namespace std; + +#pragma warning(push) +#pragma warning(disable : 4996) + +void test_volatile_inc_dec() { + volatile atomic ai{10}; + (void) ai++; + (void) ++ai; + (void) ai--; + (void) --ai; + + int arr[5] = {0}; + volatile atomic ap{arr}; + (void) ap++; + (void) ++ap; + (void) ap--; + (void) --ap; +} + +#if _HAS_CXX20 +void test_volatile_wait_notify() { + volatile atomic ai{0}; + ai.notify_one(); + ai.notify_all(); + ai.wait(1); + + int dummy = 0; + volatile atomic ap{&dummy}; + ap.notify_one(); + ap.notify_all(); + int other = 0; + ap.wait(&other); +} +#endif // _HAS_CXX20 + +#pragma warning(pop) + +int main() { + test_volatile_inc_dec(); +#if _HAS_CXX20 + test_volatile_wait_notify(); +#endif +} From f53191a9684639da81a7628bbee68e2e6c585482 Mon Sep 17 00:00:00 2001 From: Shengxin Pei Date: Fri, 21 Aug 2026 00:14:19 +0800 Subject: [PATCH 2/2] use static_assert and update test --- stl/inc/atomic | 22 +++++++++---------- .../test.cpp | 7 ++---- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/stl/inc/atomic b/stl/inc/atomic index ecd01a238a2..d3c2195b221 100644 --- a/stl/inc/atomic +++ b/stl/inc/atomic @@ -1662,23 +1662,23 @@ struct _Atomic_integral_facade : _Atomic_integral<_Ty> { using _Base::operator++; _Ty operator++(int) volatile noexcept { - (void) _Deprecate_non_lock_free_volatile<_Ty>; + static_assert(_Deprecate_non_lock_free_volatile<_Ty>, "Never fails"); return const_cast<_Atomic_integral_facade*>(this)->_Base::operator++(0); } _Ty operator++() volatile noexcept { - (void) _Deprecate_non_lock_free_volatile<_Ty>; + static_assert(_Deprecate_non_lock_free_volatile<_Ty>, "Never fails"); return const_cast<_Atomic_integral_facade*>(this)->_Base::operator++(); } using _Base::operator--; _Ty operator--(int) volatile noexcept { - (void) _Deprecate_non_lock_free_volatile<_Ty>; + static_assert(_Deprecate_non_lock_free_volatile<_Ty>, "Never fails"); return const_cast<_Atomic_integral_facade*>(this)->_Base::operator--(0); } _Ty operator--() volatile noexcept { - (void) _Deprecate_non_lock_free_volatile<_Ty>; + static_assert(_Deprecate_non_lock_free_volatile<_Ty>, "Never fails"); return const_cast<_Atomic_integral_facade*>(this)->_Base::operator--(); } @@ -1964,7 +1964,7 @@ struct _Atomic_pointer : _Atomic_storage<_Ty> { } _Ty operator++(int) volatile noexcept { - (void) _Deprecate_non_lock_free_volatile<_Ty>; + static_assert(_Deprecate_non_lock_free_volatile<_Ty>, "Never fails"); return fetch_add(1); } @@ -1973,7 +1973,7 @@ struct _Atomic_pointer : _Atomic_storage<_Ty> { } _Ty operator++() volatile noexcept { - (void) _Deprecate_non_lock_free_volatile<_Ty>; + static_assert(_Deprecate_non_lock_free_volatile<_Ty>, "Never fails"); return fetch_add(1) + 1; } @@ -1982,7 +1982,7 @@ struct _Atomic_pointer : _Atomic_storage<_Ty> { } _Ty operator--(int) volatile noexcept { - (void) _Deprecate_non_lock_free_volatile<_Ty>; + static_assert(_Deprecate_non_lock_free_volatile<_Ty>, "Never fails"); return fetch_add(-1); } @@ -1991,7 +1991,7 @@ struct _Atomic_pointer : _Atomic_storage<_Ty> { } _Ty operator--() volatile noexcept { - (void) _Deprecate_non_lock_free_volatile<_Ty>; + static_assert(_Deprecate_non_lock_free_volatile<_Ty>, "Never fails"); return fetch_add(-1) - 1; } @@ -2250,19 +2250,19 @@ public: #if _HAS_CXX20 using _Base::wait; void wait(const _Ty _Expected, const memory_order _Order = memory_order_seq_cst) const volatile noexcept { - (void) _Deprecate_non_lock_free_volatile<_Ty>; + static_assert(_Deprecate_non_lock_free_volatile<_Ty>, "Never fails"); const_cast(this)->_Base::wait(_Expected, _Order); } using _Base::notify_one; void notify_one() volatile noexcept { - (void) _Deprecate_non_lock_free_volatile<_Ty>; + static_assert(_Deprecate_non_lock_free_volatile<_Ty>, "Never fails"); const_cast(this)->_Base::notify_one(); } using _Base::notify_all; void notify_all() volatile noexcept { - (void) _Deprecate_non_lock_free_volatile<_Ty>; + static_assert(_Deprecate_non_lock_free_volatile<_Ty>, "Never fails"); const_cast(this)->_Base::notify_all(); } #endif // _HAS_CXX20 diff --git a/tests/std/tests/P1831R1_deprecated_volatile_atomic/test.cpp b/tests/std/tests/P1831R1_deprecated_volatile_atomic/test.cpp index 5528b35b4bc..27acc33406a 100644 --- a/tests/std/tests/P1831R1_deprecated_volatile_atomic/test.cpp +++ b/tests/std/tests/P1831R1_deprecated_volatile_atomic/test.cpp @@ -1,14 +1,13 @@ // Copyright (c) Microsoft Corporation. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +#define _SILENCE_CXX20_VOLATILE_DEPRECATION_WARNING + #include #include using namespace std; -#pragma warning(push) -#pragma warning(disable : 4996) - void test_volatile_inc_dec() { volatile atomic ai{10}; (void) ai++; @@ -40,8 +39,6 @@ void test_volatile_wait_notify() { } #endif // _HAS_CXX20 -#pragma warning(pop) - int main() { test_volatile_inc_dec(); #if _HAS_CXX20