[libcxx-commits] [PATCH] D90968: Fix for the Bug 41784

Ruslan Arutyunyan via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jan 25 14:45:36 PST 2021


rarutyun updated this revision to Diff 319131.
rarutyun set the repository for this revision to rG LLVM Github Monorepo.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90968/new/

https://reviews.llvm.org/D90968

Files:
  libcxx/include/atomic
  libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/copy.assign.ptr.volatile.verify.cpp
  libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/copy.assign.volatile.verify.cpp


Index: libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/copy.assign.volatile.verify.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/copy.assign.volatile.verify.cpp
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// std::atomic
+
+// atomic& operator=( const atomic& ) volatile = delete;
+
+#include <atomic>
+
+int main(int, char**) {
+  volatile std::atomic<int> obj1;
+  std::atomic<int> obj2;
+  obj1 = obj2; // expected-error {{overload resolution selected deleted operator '='}}
+}
Index: libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/copy.assign.ptr.volatile.verify.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/copy.assign.ptr.volatile.verify.cpp
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// std::atomic
+
+// atomic& operator=( const atomic& ) volatile = delete;
+
+#include <atomic>
+
+int main(int, char**)
+{
+    volatile std::atomic<int*> obj1;
+    std::atomic<int*> obj2;
+    obj1 = obj2; // expected-error {{overload resolution selected deleted operator '='}}
+}
Index: libcxx/include/atomic
===================================================================
--- libcxx/include/atomic
+++ libcxx/include/atomic
@@ -1681,16 +1681,10 @@
 
 #ifndef _LIBCPP_CXX03_LANG
     __atomic_base(const __atomic_base&) = delete;
-    __atomic_base& operator=(const __atomic_base&) = delete;
-    __atomic_base& operator=(const __atomic_base&) volatile = delete;
 #else
 private:
     _LIBCPP_INLINE_VISIBILITY
     __atomic_base(const __atomic_base&);
-    _LIBCPP_INLINE_VISIBILITY
-    __atomic_base& operator=(const __atomic_base&);
-    _LIBCPP_INLINE_VISIBILITY
-    __atomic_base& operator=(const __atomic_base&) volatile;
 #endif
 };
 
@@ -1800,6 +1794,12 @@
     _LIBCPP_INLINE_VISIBILITY
     _Tp operator=(_Tp __d) _NOEXCEPT
         {__base::store(__d); return __d;}
+
+    // delete explicitly in the most derived class to satisfy the requirement
+    // that atomic (possibly volatile qualified) variables are not copyable
+    // For mor information see https://bugs.llvm.org/show_bug.cgi?id=41784
+    atomic& operator=(const atomic&) = delete;
+    atomic& operator=(const atomic&) volatile = delete;
 };
 
 // atomic<T*>
@@ -1862,6 +1862,12 @@
     _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
     _LIBCPP_INLINE_VISIBILITY
     _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT          {return fetch_sub(__op) - __op;}
+
+    // delete explicitly in the most derived class to satisfy the requirement
+    // that atomic (possibly volatile qualified) variables are not copyable
+    // For mor information see https://bugs.llvm.org/show_bug.cgi?id=41784
+    atomic& operator=(const atomic&) = delete;
+    atomic& operator=(const atomic&) volatile = delete;
 };
 
 // atomic_is_lock_free


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90968.319131.patch
Type: text/x-patch
Size: 3779 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210125/6572ef5a/attachment.bin>


More information about the libcxx-commits mailing list