From 6a93ec2435b8a453d43956fef6afa5f091d70ffc Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Wed, 13 Sep 2023 10:35:34 +0200 Subject: QAtomic: remove the copy ctor and assignment operator These special member functions have no purpose. We never *documented* their semantics. Any code using them is unconditionally wrong (which semantics was it assuming?), so we can accept the SIC (type A). If a user needs such a copy, they would have to reason on the intended semantics (relaxed? acquire/release?) and be explicit in their code. Especially for assignment, they would need understand the consequences of the memory ordering that apply on _each_ atomic object involved and not on the assignment operation as a whole (there are no such semantics). Testing this change on qtbase has already found bugs. From a purely technical point of view: we don't guarantee lock-free atomics nor we require them from the underlying platform. An atomic is therefore allowed to be implemented as a mutex protecting a value, and mutexes are not copiable. std::atomic follows the exactly same pattern (not copiable nor copy-assignable) for exactly the same reasons, and Qt atomics are implemented on top of std:: ones. [ChangeLog][QtCore] The copy constructor and assignment operators of Qt atomic classes (QAtomicInteger, QAtomicPointer) have been removed. Their usage in user code should be considered a programming error, as no memory ordering semantics were ever documented for these operations (and therefore relying on any specific semantic would be relying on undocumented, unportable behavior). This matches the API of the std::atomic class in C++. Note that you can still use explicit load/store operations to transfer a value across two Qt atomic objects, and therefore use the memory ordering specified for the load/store operations. Change-Id: Iab653bad761afb8b3e3b6a967ece7b28713aa944 Reviewed-by: Qt CI Bot Reviewed-by: Thiago Macieira --- src/corelib/thread/qatomic.cpp | 27 --------------------------- 1 file changed, 27 deletions(-) (limited to 'src/corelib/thread/qatomic.cpp') diff --git a/src/corelib/thread/qatomic.cpp b/src/corelib/thread/qatomic.cpp index 4843556eb5..948f30bb98 100644 --- a/src/corelib/thread/qatomic.cpp +++ b/src/corelib/thread/qatomic.cpp @@ -210,20 +210,6 @@ Constructs a QAtomicInteger with the given \a value. */ -/*! - \fn template QAtomicInteger::QAtomicInteger(const QAtomicInteger &other) - - Constructs a copy of \a other. -*/ - -/*! - \fn template QAtomicInteger &QAtomicInteger::operator=(const QAtomicInteger &other) - - Assigns \a other to this QAtomicInteger and returns a reference to - this QAtomicInteger. -*/ - - /*! \fn template T QAtomicInteger::loadRelaxed() const \since 5.14 @@ -1368,19 +1354,6 @@ Constructs a QAtomicPointer with the given \a value. */ -/*! - \fn template QAtomicPointer::QAtomicPointer(const QAtomicPointer &other) - - Constructs a copy of \a other. -*/ - -/*! - \fn template QAtomicPointer &QAtomicPointer::operator=(const QAtomicPointer &other) - - Assigns \a other to this QAtomicPointer and returns a reference to - this QAtomicPointer. -*/ - /*! \fn template T *QAtomicPointer::loadRelaxed() const \since 5.14 -- cgit v1.2.3