]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Use type_identity_t for non-deducible std::atomic_xxx args
authorJonathan Wakely <jwakely@redhat.com>
Mon, 13 Jun 2022 15:36:14 +0000 (16:36 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 15 Jun 2022 08:14:28 +0000 (09:14 +0100)
This is LWG 3220 which is about to become Tentatively Ready.

libstdc++-v3/ChangeLog:

* include/std/atomic (__atomic_val_t): Use __type_identity_t
instead of atomic<T>::value_type, as per LWG 3220.
* testsuite/29_atomics/atomic/lwg3220.cc: New test.

(cherry picked from commit 30cc1b65e4efa1a2c57fec5574fcae7a446b822f)

libstdc++-v3/include/std/atomic
libstdc++-v3/testsuite/29_atomics/atomic/lwg3220.cc [new file with mode: 0644]

index d511dfe7b60bb4a3a501717120a37f881b6adee0..c585f95dc9e950b41c9218e14f39f0eee9d645a3 100644 (file)
@@ -1173,9 +1173,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   atomic_flag_clear(volatile atomic_flag* __a) noexcept
   { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
 
-
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 3220. P0558 broke conforming C++14 uses of atomic shared_ptr
   template<typename _Tp>
-    using __atomic_val_t = typename atomic<_Tp>::value_type;
+    using __atomic_val_t = __type_identity_t<_Tp>;
   template<typename _Tp>
     using __atomic_diff_t = typename atomic<_Tp>::difference_type;
 
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/lwg3220.cc b/libstdc++-v3/testsuite/29_atomics/atomic/lwg3220.cc
new file mode 100644 (file)
index 0000000..d2ff6cf
--- /dev/null
@@ -0,0 +1,13 @@
+// { dg-do compile { target c++11 } }
+// DR 3220. P0558 broke conforming C++14 uses of atomic shared_ptr
+
+#include <atomic>
+#include <memory>
+
+struct Abstract { virtual void test() = 0; };
+struct Concrete : Abstract { virtual void test() override {} };
+
+int main() {
+  std::shared_ptr<Abstract> ptr;
+  std::atomic_store<Abstract>(&ptr, std::make_shared<Concrete>());
+}