[libcxx-commits] [libcxx] [libcxx] Implementation of P1831R1 (PR #101439)
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Aug 4 03:34:40 PDT 2024
================
@@ -0,0 +1,107 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <atomic>
+
+// UNSUPPORTED: c++03, c++11, c++17
+
+#include <atomic>
+
+struct arr {
+ int x[32];
+ int y;
+
+ void method() {}
+};
+
+void f() {
+ std::memory_order ord = std::memory_order_relaxed;
+
+ int expected = 0, desired = 0;
+ std::atomic<int> i{};
+ i.operator=(0);
+ i.store(0, ord);
+ i.load(ord);
+ i.operator int();
+ i.exchange(0, ord);
+ i.compare_exchange_weak(expected, desired, ord);
+ i.compare_exchange_weak(expected, desired, ord, ord);
+ i.compare_exchange_strong(expected, desired, ord);
+ i.compare_exchange_strong(expected, desired, ord, ord);
+
+ volatile std::atomic<int> vi{};
+ vi.operator=(0);
+ vi.store(0, ord);
+ vi.load(ord);
+ vi.operator int();
+ vi.exchange(0, ord);
+ vi.compare_exchange_weak(expected, desired, ord);
+ vi.compare_exchange_weak(expected, desired, ord, ord);
+ vi.compare_exchange_strong(expected, desired, ord);
+ vi.compare_exchange_strong(expected, desired, ord, ord);
+
+ arr test_value;
+
+ volatile std::atomic<arr> va{};
+
+ // expected-warning at __atomic/atomic.h:* {{'__deprecated_if_not_awlays_lock_free<arr, false>' is deprecated: volatile atomic operations are deprecated when std::atomic<T>::is_always_lock_free is false}}
----------------
mordante wrote:
We typically don't care about the file generating the diagnostic. This makes it easier to refactor our headers without updating a lot of tests.
```suggestion
// expected-warning@*:* {{'__deprecated_if_not_awlays_lock_free<arr, false>' is deprecated: volatile atomic operations are deprecated when std::atomic<T>::is_always_lock_free is false}}
```
https://github.com/llvm/llvm-project/pull/101439
More information about the libcxx-commits
mailing list