Replace qt_make_unique with std::make_unique

We can depend on C++14 now.

Change-Id: Iee9796cd22dbfbb70d4bdb25f0eee1662a026d6d
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Allan Sandfeld Jensen 2020-11-17 13:40:00 +01:00
parent 03ab48657d
commit f61f8bb966
16 changed files with 30 additions and 123 deletions

View File

@ -43,7 +43,6 @@ qt_internal_add_module(Core
global/qlibraryinfo.cpp global/qlibraryinfo.h
global/qlogging.cpp global/qlogging.h
global/qmalloc.cpp
global/qmemory_p.h
# global/qnamespace.h # special case
global/qnumeric.cpp global/qnumeric.h global/qnumeric_p.h
global/qoperatingsystemversion.cpp global/qoperatingsystemversion.h global/qoperatingsystemversion_p.h

View File

@ -8,7 +8,6 @@ HEADERS += \
global/qcompilerdetection.h \
global/qcontainerinfo.h \
global/qprocessordetection.h \
global/qmemory_p.h \
global/qnamespace.h \
global/qendian.h \
global/qendian_p.h \

View File

@ -1,71 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2019 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QMEMORY_P_H
#define QMEMORY_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtCore/qglobal.h>
#include <memory>
#include <type_traits>
#include <utility>
QT_BEGIN_NAMESPACE
// Like std::make_unique, but less ambitious, so keep as private API, for use in Qt itself:
template <typename T, typename... Args>
typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
qt_make_unique(Args &&...args)
{
return std::unique_ptr<T>{new T(std::forward<Args>(args)...)};
}
QT_END_NAMESPACE
#endif /* QMEMORY_P_H */

View File

@ -55,8 +55,6 @@
# include "qcoreapplication.h"
#endif
#include <private/qmemory_p.h>
#ifdef QT_NO_QOBJECT
#define tr(X) QString::fromLatin1(X)
#endif
@ -87,7 +85,7 @@ QFilePrivate::openExternalFile(int flags, int fd, QFile::FileHandleFlags handleF
Q_UNUSED(fd);
return false;
#else
auto fs = qt_make_unique<QFSFileEngine>();
auto fs = std::make_unique<QFSFileEngine>();
auto fe = fs.get();
fileEngine = std::move(fs);
return fe->open(QIODevice::OpenMode(flags), fd, handleFlags);
@ -102,7 +100,7 @@ QFilePrivate::openExternalFile(int flags, FILE *fh, QFile::FileHandleFlags handl
Q_UNUSED(fh);
return false;
#else
auto fs = qt_make_unique<QFSFileEngine>();
auto fs = std::make_unique<QFSFileEngine>();
auto fe = fs.get();
fileEngine = std::move(fs);
return fe->open(QIODevice::OpenMode(flags), fh, handleFlags);

View File

@ -42,8 +42,6 @@
#include "qfiledevice_p.h"
#include "qfsfileengine_p.h"
#include <private/qmemory_p.h>
#ifdef QT_NO_QOBJECT
#define tr(X) QString::fromLatin1(X)
#endif
@ -66,7 +64,7 @@ QFileDevicePrivate::~QFileDevicePrivate() = default;
QAbstractFileEngine *QFileDevicePrivate::engine() const
{
if (!fileEngine)
fileEngine = qt_make_unique<QFSFileEngine>();
fileEngine = std::make_unique<QFSFileEngine>();
return fileEngine.get();
}

View File

@ -418,7 +418,6 @@
#include "private/qipaddress_p.h"
#include "qurlquery.h"
#include "private/qdir_p.h"
#include <private/qmemory_p.h>
QT_BEGIN_NAMESPACE
@ -617,7 +616,7 @@ inline QUrlPrivate::~QUrlPrivate()
std::unique_ptr<QUrlPrivate::Error> QUrlPrivate::cloneError() const
{
return error ? qt_make_unique<Error>(*error) : nullptr;
return error ? std::make_unique<Error>(*error) : nullptr;
}
inline void QUrlPrivate::clearError()
@ -631,7 +630,7 @@ inline void QUrlPrivate::setError(ErrorCode errorCode, const QString &source, in
// don't overwrite an error set in a previous section during parsing
return;
}
error = qt_make_unique<Error>();
error = std::make_unique<Error>();
error->code = errorCode;
error->source = source;
error->position = supplement;

View File

@ -52,8 +52,6 @@
#include "qjson_p.h"
#include "qdatastream.h"
#include <private/qmemory_p.h>
QT_BEGIN_NAMESPACE
/*! \class QJsonDocument
@ -139,7 +137,7 @@ QJsonDocument::QJsonDocument(const QJsonArray &array)
\internal
*/
QJsonDocument::QJsonDocument(const QCborValue &data)
: d(qt_make_unique<QJsonDocumentPrivate>(data))
: d(std::make_unique<QJsonDocumentPrivate>(data))
{
Q_ASSERT(d);
}
@ -158,7 +156,7 @@ QJsonDocument::QJsonDocument(const QJsonDocument &other)
{
if (other.d) {
if (!d)
d = qt_make_unique<QJsonDocumentPrivate>();
d = std::make_unique<QJsonDocumentPrivate>();
d->value = other.d->value;
} else {
d.reset();
@ -184,7 +182,7 @@ QJsonDocument &QJsonDocument::operator =(const QJsonDocument &other)
if (this != &other) {
if (other.d) {
if (!d)
d = qt_make_unique<QJsonDocumentPrivate>();
d = std::make_unique<QJsonDocumentPrivate>();
else
d->clearRawData();
d->value = other.d->value;
@ -239,7 +237,7 @@ QJsonDocument QJsonDocument::fromVariant(const QVariant &variant)
doc.setArray(QJsonArray::fromVariantList(variant.toList()));
break;
case QMetaType::QStringList:
doc.d = qt_make_unique<QJsonDocumentPrivate>();
doc.d = std::make_unique<QJsonDocumentPrivate>();
doc.d->value = QCborArray::fromStringList(variant.toStringList());
break;
default:
@ -320,7 +318,7 @@ QJsonDocument QJsonDocument::fromJson(const QByteArray &json, QJsonParseError *e
QJsonDocument result;
const QCborValue val = parser.parse(error);
if (val.isArray() || val.isMap()) {
result.d = qt_make_unique<QJsonDocumentPrivate>();
result.d = std::make_unique<QJsonDocumentPrivate>();
result.d->value = val;
}
return result;
@ -405,7 +403,7 @@ QJsonArray QJsonDocument::array() const
void QJsonDocument::setObject(const QJsonObject &object)
{
if (!d)
d = qt_make_unique<QJsonDocumentPrivate>();
d = std::make_unique<QJsonDocumentPrivate>();
else
d->clearRawData();
@ -420,7 +418,7 @@ void QJsonDocument::setObject(const QJsonObject &object)
void QJsonDocument::setArray(const QJsonArray &array)
{
if (!d)
d = qt_make_unique<QJsonDocumentPrivate>();
d = std::make_unique<QJsonDocumentPrivate>();
else
d->clearRawData();

View File

@ -63,7 +63,6 @@ public: \
{ return QString::fromUtf8(sourceText); } \
private:
#endif
#include <private/qmemory_p.h>
#include <iterator>
#include "qxmlstream_p.h"
@ -875,7 +874,7 @@ void QXmlStreamReaderPrivate::parseEntity(const QString &value)
if (!entityParser)
entityParser = qt_make_unique<QXmlStreamReaderPrivate>(q);
entityParser = std::make_unique<QXmlStreamReaderPrivate>(q);
else
entityParser->init();
entityParser->inParseEntity = true;

View File

@ -67,7 +67,6 @@
#if defined(Q_OS_UNIX)
#include <QtCore/qdir.h>
#endif
#include <QtCore/private/qmemory_p.h>
#include <QtCore/private/qduplicatetracker_p.h>
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
#include <link.h>
@ -658,12 +657,12 @@ struct LoadedOpenSsl {
static bool tryToLoadOpenSslWin32Library(QLatin1String ssleay32LibName, QLatin1String libeay32LibName, LoadedOpenSsl &result)
{
auto ssleay32 = qt_make_unique<QSystemLibrary>(ssleay32LibName);
auto ssleay32 = std::make_unique<QSystemLibrary>(ssleay32LibName);
if (!ssleay32->load(false)) {
return FALSE;
}
auto libeay32 = qt_make_unique<QSystemLibrary>(libeay32LibName);
auto libeay32 = std::make_unique<QSystemLibrary>(libeay32LibName);
if (!libeay32->load(false)) {
return FALSE;
}
@ -700,7 +699,7 @@ struct LoadedOpenSsl {
static LoadedOpenSsl loadOpenSsl()
{
LoadedOpenSsl result = {qt_make_unique<QLibrary>(), qt_make_unique<QLibrary>()};
LoadedOpenSsl result = { std::make_unique<QLibrary>(), std::make_unique<QLibrary>() };
# if defined(Q_OS_UNIX)
QLibrary * const libssl = result.ssl.get();

View File

@ -48,7 +48,6 @@
#include <QtDeviceDiscoverySupport/private/qdevicediscovery_p.h>
#include <private/qguiapplication_p.h>
#include <private/qinputdevicemanager_p_p.h>
#include <private/qmemory_p.h>
QT_BEGIN_NAMESPACE
@ -96,7 +95,7 @@ QEvdevTabletManager::~QEvdevTabletManager()
void QEvdevTabletManager::addDevice(const QString &deviceNode)
{
qCDebug(qLcEvdevTablet, "Adding device at %ls", qUtf16Printable(deviceNode));
auto handler = qt_make_unique<QEvdevTabletHandlerThread>(deviceNode, m_spec);
auto handler = std::make_unique<QEvdevTabletHandlerThread>(deviceNode, m_spec);
if (handler) {
m_activeDevices.add(deviceNode, std::move(handler));
updateDeviceCount();

View File

@ -48,7 +48,6 @@
#include <QtDeviceDiscoverySupport/private/qdevicediscovery_p.h>
#include <private/qguiapplication_p.h>
#include <private/qinputdevicemanager_p_p.h>
#include <private/qmemory_p.h>
QT_BEGIN_NAMESPACE
@ -96,7 +95,7 @@ QEvdevTouchManager::~QEvdevTouchManager()
void QEvdevTouchManager::addDevice(const QString &deviceNode)
{
qCDebug(qLcEvdevTouch, "evdevtouch: Adding device at %ls", qUtf16Printable(deviceNode));
auto handler = qt_make_unique<QEvdevTouchScreenHandlerThread>(deviceNode, m_spec);
auto handler = std::make_unique<QEvdevTouchScreenHandlerThread>(deviceNode, m_spec);
if (handler) {
connect(handler.get(), &QEvdevTouchScreenHandlerThread::touchDeviceRegistered, this, &QEvdevTouchManager::updateInputDeviceCount);
m_activeDevices.add(deviceNode, std::move(handler));

View File

@ -51,8 +51,6 @@
#include <QtWidgets/QStyleOptionTitleBar>
#include <QtWidgets/QGraphicsSceneMouseEvent>
#include <private/qmemory_p.h>
QT_BEGIN_NAMESPACE
void QGraphicsWidgetPrivate::init(QGraphicsItem *parentItem, Qt::WindowFlags wFlags)
@ -121,7 +119,7 @@ QGraphicsWidgetPrivate::~QGraphicsWidgetPrivate()
void QGraphicsWidgetPrivate::ensureMargins() const
{
if (!margins)
margins = qt_make_unique<QMarginsF>();
margins = std::make_unique<QMarginsF>();
}
/*!
@ -133,7 +131,7 @@ void QGraphicsWidgetPrivate::ensureMargins() const
void QGraphicsWidgetPrivate::ensureWindowFrameMargins() const
{
if (!windowFrameMargins)
windowFrameMargins = qt_make_unique<QMarginsF>();
windowFrameMargins = std::make_unique<QMarginsF>();
}
/*!
@ -145,7 +143,7 @@ void QGraphicsWidgetPrivate::ensureWindowFrameMargins() const
void QGraphicsWidgetPrivate::ensureWindowData()
{
if (!windowData)
windowData = qt_make_unique<WindowData>();
windowData = std::make_unique<WindowData>();
}
void QGraphicsWidgetPrivate::setPalette_helper(const QPalette &palette)

View File

@ -113,8 +113,6 @@
#include "qwindowcontainer_p.h"
#include <private/qmemory_p.h>
// widget/widget data creation count
//#define QWIDGET_EXTRA_DEBUG
//#define ALIEN_DEBUG
@ -1570,7 +1568,7 @@ void QWidgetPrivate::createTLExtra()
if (!extra)
createExtra();
if (!extra->topextra) {
extra->topextra = qt_make_unique<QTLWExtra>();
extra->topextra = std::make_unique<QTLWExtra>();
QTLWExtra* x = extra->topextra.get();
x->backingStore = nullptr;
x->sharedPainter = nullptr;
@ -1601,7 +1599,7 @@ void QWidgetPrivate::createTLExtra()
void QWidgetPrivate::createExtra()
{
if (!extra) { // if not exists
extra = qt_make_unique<QWExtra>();
extra = std::make_unique<QWExtra>();
extra->glContext = nullptr;
#if QT_CONFIG(graphicsview)
extra->proxyWidget = nullptr;
@ -4807,7 +4805,7 @@ void QWidget::setCursor(const QCursor &cursor)
|| (d->extra && d->extra->curs))
{
d->createExtra();
d->extra->curs = qt_make_unique<QCursor>(cursor);
d->extra->curs = std::make_unique<QCursor>(cursor);
}
setAttribute(Qt::WA_SetCursor);
d->setCursor_sys(cursor);
@ -6028,7 +6026,7 @@ void QWidget::setWindowIcon(const QIcon &icon)
d->createTLExtra();
if (!d->extra->topextra->icon)
d->extra->topextra->icon = qt_make_unique<QIcon>(icon);
d->extra->topextra->icon = std::make_unique<QIcon>(icon);
else
*d->extra->topextra->icon = icon;
@ -11970,7 +11968,7 @@ QOpenGLContext *QWidgetPrivate::shareContext() const
return nullptr;
if (!extra->topextra->shareContext) {
auto ctx = qt_make_unique<QOpenGLContext>();
auto ctx = std::make_unique<QOpenGLContext>();
ctx->setShareContext(qt_gl_global_share_context());
ctx->setFormat(extra->topextra->window->format());
ctx->setScreen(extra->topextra->window->screen());

View File

@ -63,8 +63,6 @@
#include <qpa/qplatformbackingstore.h>
#include <private/qmemory_p.h>
QT_BEGIN_NAMESPACE
#ifndef QT_NO_OPENGL
@ -653,7 +651,7 @@ static void findAllTextureWidgetsRecursively(QWidget *tlw, QWidget *widget)
// textureChildSeen does not take native child widgets into account and that's good.
if (QWidgetPrivate::get(widget)->textureChildSeen) {
QList<QWidget *> nativeChildren;
auto tl = qt_make_unique<QPlatformTextureList>();
auto tl = std::make_unique<QPlatformTextureList>();
// Look for texture widgets (incl. widget itself) from 'widget' down,
// but skip subtrees with a parent of a native child widget.
findTextureWidgetsRecursively(tlw, widget, tl.get(), &nativeChildren);

View File

@ -52,8 +52,6 @@
#endif
#include <qabstractbutton.h>
#include <private/qmemory_p.h>
#include "qframe_p.h"
QT_BEGIN_NAMESPACE
@ -349,7 +347,7 @@ int QToolBox::insertItem(int index, QWidget *widget, const QIcon &icon, const QS
Q_D(QToolBox);
connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(_q_widgetDestroyed(QObject*)));
auto newPage = qt_make_unique<QToolBoxPrivate::Page>();
auto newPage = std::make_unique<QToolBoxPrivate::Page>();
auto &c = *newPage;
c.widget = widget;
c.button = new QToolBoxButton(this);

View File

@ -28,7 +28,6 @@
#include <QtCore/QtCore>
#include <QtTest/QtTest>
#include <QtCore/private/qmemory_p.h>
#include <mutex>
#if __has_include(<shared_mutex>)
#if __cplusplus > 201103L
@ -154,7 +153,7 @@ void testReadOnly()
Mutex lock;
std::vector<std::unique_ptr<Thread>> threads;
for (int i = 0; i < threadCount; ++i) {
auto t = qt_make_unique<Thread>();
auto t = std::make_unique<Thread>();
t->lock = &lock;
threads.push_back(std::move(t));
}
@ -215,7 +214,7 @@ void testWriteOnly()
Mutex lock;
std::vector<std::unique_ptr<Thread>> threads;
for (int i = 0; i < threadCount; ++i) {
auto t = qt_make_unique<Thread>();
auto t = std::make_unique<Thread>();
t->lock = &lock;
threads.push_back(std::move(t));
}