QNetworkRequest: make the default ctor implicit

As in QVarLengthArray (c34242c679aaea6ee1badf6c1e5f274f925f5f50), this will
probably bite someone someday, so fix it before there's a bug report.

Use ctor delegation to keep code size increase small.

There's also the benefit that default-constructing a QNetworkRequest now
no longer creates an expensive QUrl object just to destroy it unused again.

Add an auto-test.

Change-Id: I5ceb5402ca3946048d695244d1b1c36564a1e80a
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Marc Mutz 2019-07-13 22:52:30 +02:00
parent efa183309e
commit a7383b4b6d
3 changed files with 21 additions and 2 deletions

View File

@ -467,6 +467,17 @@ public:
QString peerVerifyName;
};
/*!
Constructs a QNetworkRequest object with no URL to be requested.
Use setUrl() to set one.
\sa url(), setUrl()
*/
QNetworkRequest::QNetworkRequest()
: d(new QNetworkRequestPrivate)
{
}
/*!
Constructs a QNetworkRequest object with \a url as the URL to be
requested.
@ -474,7 +485,7 @@ public:
\sa url(), setUrl()
*/
QNetworkRequest::QNetworkRequest(const QUrl &url)
: d(new QNetworkRequestPrivate)
: QNetworkRequest()
{
d->url = url;
}

View File

@ -128,7 +128,8 @@ public:
};
explicit QNetworkRequest(const QUrl &url = QUrl());
QNetworkRequest();
explicit QNetworkRequest(const QUrl &url);
QNetworkRequest(const QNetworkRequest &other);
~QNetworkRequest();
QNetworkRequest &operator=(QNetworkRequest &&other) noexcept { swap(other); return *this; }

View File

@ -41,6 +41,7 @@ class tst_QNetworkRequest: public QObject
private slots:
void ctor_data();
void ctor();
void implicitDefaultCtor();
void setUrl_data();
void setUrl();
void setRawHeader_data();
@ -78,6 +79,12 @@ void tst_QNetworkRequest::ctor()
}
}
void tst_QNetworkRequest::implicitDefaultCtor()
{
QNetworkRequest r = {};
Q_UNUSED(r);
}
void tst_QNetworkRequest::setUrl_data()
{
ctor_data();