QtCore: mark some operations nothrow

This shotgun-surgery approach is motivated by trying to get a
clean(er) build for -Wnoexcept on GCC, so it is expected that
for any class touched here, there will be more operations that
can be marked nothrow. But they don't show up in conditional
noexcept clauses, yet, so they are deferred to some later
commit.

Change-Id: I0eb10d75a26c361fb22cf785399e83b434bdf233
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2015-01-08 15:08:22 +01:00
parent 2c2801860d
commit 390b16aea8
19 changed files with 72 additions and 68 deletions

View File

@ -85,7 +85,7 @@ public:
inline QDebug(const QDebug &o):stream(o.stream) { ++stream->ref; }
inline QDebug &operator=(const QDebug &other);
~QDebug();
inline void swap(QDebug &other) { qSwap(stream, other.stream); }
inline void swap(QDebug &other) Q_DECL_NOTHROW { qSwap(stream, other.stream); }
QDebug &resetFormat();

View File

@ -98,7 +98,7 @@ public:
QByteArray key;
uint hash;
};
inline uint qHash(const QProcEnvKey &key) { return key.hash; }
inline uint qHash(const QProcEnvKey &key) Q_DECL_NOTHROW { return key.hash; }
class QProcEnvValue
{

View File

@ -173,14 +173,14 @@ public:
QUrl &operator=(const QString &url);
#endif
#ifdef Q_COMPILER_RVALUE_REFS
QUrl(QUrl &&other) : d(0)
{ qSwap(d, other.d); }
inline QUrl &operator=(QUrl &&other)
QUrl(QUrl &&other) Q_DECL_NOTHROW : d(other.d)
{ other.d = Q_NULLPTR; }
inline QUrl &operator=(QUrl &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
~QUrl();
inline void swap(QUrl &other) { qSwap(d, other.d); }
inline void swap(QUrl &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
void setUrl(const QString &url, ParsingMode mode = TolerantMode);
QString url(FormattingOptions options = FormattingOptions(PrettyDecoded)) const;

View File

@ -91,7 +91,7 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QModelIndex &);
class QPersistentModelIndexData;
// qHash is a friend, but we can't use default arguments for friends (§8.3.6.4)
uint qHash(const QPersistentModelIndex &index, uint seed = 0);
uint qHash(const QPersistentModelIndex &index, uint seed = 0) Q_DECL_NOTHROW;
class Q_CORE_EXPORT QPersistentModelIndex
{
@ -106,11 +106,12 @@ public:
{ return !operator==(other); }
QPersistentModelIndex &operator=(const QPersistentModelIndex &other);
#ifdef Q_COMPILER_RVALUE_REFS
inline QPersistentModelIndex(QPersistentModelIndex &&other) : d(other.d) { other.d = 0; }
inline QPersistentModelIndex &operator=(QPersistentModelIndex &&other)
inline QPersistentModelIndex(QPersistentModelIndex &&other) Q_DECL_NOTHROW
: d(other.d) { other.d = Q_NULLPTR; }
inline QPersistentModelIndex &operator=(QPersistentModelIndex &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QPersistentModelIndex &other) { qSwap(d, other.d); }
inline void swap(QPersistentModelIndex &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
bool operator==(const QModelIndex &other) const;
bool operator!=(const QModelIndex &other) const;
QPersistentModelIndex &operator=(const QModelIndex &other);
@ -128,14 +129,14 @@ public:
bool isValid() const;
private:
QPersistentModelIndexData *d;
friend uint qHash(const QPersistentModelIndex &, uint seed);
friend uint qHash(const QPersistentModelIndex &, uint seed) Q_DECL_NOTHROW;
#ifndef QT_NO_DEBUG_STREAM
friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QPersistentModelIndex &);
#endif
};
Q_DECLARE_SHARED(QPersistentModelIndex)
inline uint qHash(const QPersistentModelIndex &index, uint seed)
inline uint qHash(const QPersistentModelIndex &index, uint seed) Q_DECL_NOTHROW
{ return qHash(index.d, seed); }

View File

@ -318,7 +318,7 @@ QCoreApplication *QCoreApplication::self = 0;
uint QCoreApplicationPrivate::attribs = (1 << Qt::AA_SynthesizeMouseForUnhandledTouchEvents);
struct QCoreApplicationData {
QCoreApplicationData() {
QCoreApplicationData() Q_DECL_NOTHROW {
#ifndef QT_NO_LIBRARY
app_libpaths = 0;
#endif

View File

@ -253,13 +253,13 @@ class Q_CORE_EXPORT QVariant
QVariant& operator=(const QVariant &other);
#ifdef Q_COMPILER_RVALUE_REFS
inline QVariant(QVariant &&other) : d(other.d)
inline QVariant(QVariant &&other) Q_DECL_NOTHROW : d(other.d)
{ other.d = Private(); }
inline QVariant &operator=(QVariant &&other)
inline QVariant &operator=(QVariant &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QVariant &other) { qSwap(d, other.d); }
inline void swap(QVariant &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
Type type() const;
int userType() const;
@ -360,15 +360,15 @@ class Q_CORE_EXPORT QVariant
};
struct Private
{
inline Private(): type(Invalid), is_shared(false), is_null(true)
inline Private() Q_DECL_NOTHROW : type(Invalid), is_shared(false), is_null(true)
{ data.ptr = 0; }
// Internal constructor for initialized variants.
explicit inline Private(uint variantType)
explicit inline Private(uint variantType) Q_DECL_NOTHROW
: type(variantType), is_shared(false), is_null(false)
{}
inline Private(const Private &other)
inline Private(const Private &other) Q_DECL_NOTHROW
: data(other.data), type(other.type),
is_shared(other.is_shared), is_null(other.is_null)
{}

View File

@ -113,7 +113,7 @@ struct Q_CORE_EXPORT QArrayData
size_t alignment) Q_DECL_NOTHROW;
static const QArrayData shared_null[2];
static QArrayData *sharedNull() { return const_cast<QArrayData*>(shared_null); }
static QArrayData *sharedNull() Q_DECL_NOTHROW { return const_cast<QArrayData*>(shared_null); }
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QArrayData::AllocationOptions)
@ -237,7 +237,7 @@ struct QTypedArrayData
return result;
}
static QTypedArrayData *sharedNull()
static QTypedArrayData *sharedNull() Q_DECL_NOTHROW
{
Q_STATIC_ASSERT(sizeof(QTypedArrayData) == sizeof(QArrayData));
return static_cast<QTypedArrayData *>(QArrayData::sharedNull());

View File

@ -53,12 +53,12 @@ public:
QBitArray(const QBitArray &other) : d(other.d) {}
inline QBitArray &operator=(const QBitArray &other) { d = other.d; return *this; }
#ifdef Q_COMPILER_RVALUE_REFS
inline QBitArray(QBitArray &&other) : d(std::move(other.d)) {}
inline QBitArray &operator=(QBitArray &&other)
inline QBitArray(QBitArray &&other) Q_DECL_NOTHROW : d(std::move(other.d)) {}
inline QBitArray &operator=(QBitArray &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QBitArray &other) { qSwap(d, other.d); }
inline void swap(QBitArray &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
inline int size() const { return (d.size() << 3) - *d.constData(); }
inline int count() const { return (d.size() << 3) - *d.constData(); }

View File

@ -195,12 +195,13 @@ public:
QByteArray &operator=(const QByteArray &);
QByteArray &operator=(const char *str);
#ifdef Q_COMPILER_RVALUE_REFS
inline QByteArray(QByteArray && other) : d(other.d) { other.d = Data::sharedNull(); }
inline QByteArray &operator=(QByteArray &&other)
inline QByteArray(QByteArray && other) Q_DECL_NOTHROW : d(other.d) { other.d = Data::sharedNull(); }
inline QByteArray &operator=(QByteArray &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QByteArray &other) { qSwap(d, other.d); }
inline void swap(QByteArray &other) Q_DECL_NOTHROW
{ qSwap(d, other.d); }
inline int size() const;
bool isEmpty() const;

View File

@ -83,7 +83,7 @@ class QCache
Q_DISABLE_COPY(QCache)
public:
inline explicit QCache(int maxCost = 100);
inline explicit QCache(int maxCost = 100) Q_DECL_NOTHROW;
inline ~QCache() { clear(); }
inline int maxCost() const { return mx; }
@ -110,7 +110,7 @@ private:
};
template <class Key, class T>
inline QCache<Key, T>::QCache(int amaxCost)
inline QCache<Key, T>::QCache(int amaxCost) Q_DECL_NOTHROW
: f(0), l(0), mx(amaxCost), total(0) {}
template <class Key, class T>

View File

@ -52,10 +52,10 @@ public:
~QCollatorSortKey();
QCollatorSortKey &operator=(const QCollatorSortKey &other);
#ifdef Q_COMPILER_RVALUE_REFS
inline QCollatorSortKey &operator=(QCollatorSortKey &&other)
inline QCollatorSortKey &operator=(QCollatorSortKey &&other) Q_DECL_NOTHROW
{ swap(other); return *this; }
#endif
void swap(QCollatorSortKey &other)
void swap(QCollatorSortKey &other) Q_DECL_NOTHROW
{ d.swap(other.d); }
int compare(const QCollatorSortKey &key) const;
@ -82,13 +82,13 @@ public:
~QCollator();
QCollator &operator=(const QCollator &);
#ifdef Q_COMPILER_RVALUE_REFS
QCollator(QCollator &&other)
QCollator(QCollator &&other) Q_DECL_NOTHROW
: d(other.d) { other.d = 0; }
QCollator &operator=(QCollator &&other)
QCollator &operator=(QCollator &&other) Q_DECL_NOTHROW
{ swap(other); return *this; }
#endif
void swap(QCollator &other)
void swap(QCollator &other) Q_DECL_NOTHROW
{ qSwap(d, other.d); }
void setLocale(const QLocale &locale);

View File

@ -328,7 +328,7 @@ class QHash
static inline int alignOfNode() { return qMax<int>(sizeof(void*), Q_ALIGNOF(Node)); }
public:
inline QHash() : d(const_cast<QHashData *>(&QHashData::shared_null)) { }
inline QHash() Q_DECL_NOTHROW : d(const_cast<QHashData *>(&QHashData::shared_null)) { }
#ifdef Q_COMPILER_INITIALIZER_LISTS
inline QHash(std::initializer_list<std::pair<Key,T> > list)
: d(const_cast<QHashData *>(&QHashData::shared_null))
@ -343,11 +343,11 @@ public:
QHash<Key, T> &operator=(const QHash<Key, T> &other);
#ifdef Q_COMPILER_RVALUE_REFS
inline QHash(QHash<Key, T> &&other) : d(other.d) { other.d = const_cast<QHashData *>(&QHashData::shared_null); }
inline QHash<Key, T> &operator=(QHash<Key, T> &&other)
inline QHash(QHash<Key, T> &&other) Q_DECL_NOTHROW : d(other.d) { other.d = const_cast<QHashData *>(&QHashData::shared_null); }
inline QHash<Key, T> &operator=(QHash<Key, T> &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QHash<Key, T> &other) { qSwap(d, other.d); }
inline void swap(QHash<Key, T> &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
bool operator==(const QHash<Key, T> &other) const;
inline bool operator!=(const QHash<Key, T> &other) const { return !(*this == other); }

View File

@ -112,7 +112,7 @@ class QList : public QListSpecialMethods<T>
union { QListData p; QListData::Data *d; };
public:
inline QList() : d(const_cast<QListData::Data *>(&QListData::shared_null)) { }
inline QList() Q_DECL_NOTHROW : d(const_cast<QListData::Data *>(&QListData::shared_null)) { }
QList(const QList<T> &l);
~QList();
QList<T> &operator=(const QList<T> &l);

View File

@ -77,11 +77,11 @@ public:
QRegularExpression &operator=(const QRegularExpression &re);
#ifdef Q_COMPILER_RVALUE_REFS
inline QRegularExpression &operator=(QRegularExpression &&re)
QRegularExpression &operator=(QRegularExpression &&re) Q_DECL_NOTHROW
{ d.swap(re.d); return *this; }
#endif
inline void swap(QRegularExpression &re) { d.swap(re.d); }
void swap(QRegularExpression &other) Q_DECL_NOTHROW { d.swap(other.d); }
QString pattern() const;
void setPattern(const QString &pattern);
@ -169,10 +169,10 @@ public:
QRegularExpressionMatch &operator=(const QRegularExpressionMatch &match);
#ifdef Q_COMPILER_RVALUE_REFS
inline QRegularExpressionMatch &operator=(QRegularExpressionMatch &&match)
QRegularExpressionMatch &operator=(QRegularExpressionMatch &&match) Q_DECL_NOTHROW
{ d.swap(match.d); return *this; }
#endif
inline void swap(QRegularExpressionMatch &match) { d.swap(match.d); }
void swap(QRegularExpressionMatch &other) Q_DECL_NOTHROW { d.swap(other.d); }
QRegularExpression regularExpression() const;
QRegularExpression::MatchType matchType() const;
@ -226,10 +226,10 @@ public:
QRegularExpressionMatchIterator(const QRegularExpressionMatchIterator &iterator);
QRegularExpressionMatchIterator &operator=(const QRegularExpressionMatchIterator &iterator);
#ifdef Q_COMPILER_RVALUE_REFS
inline QRegularExpressionMatchIterator &operator=(QRegularExpressionMatchIterator &&iterator)
QRegularExpressionMatchIterator &operator=(QRegularExpressionMatchIterator &&iterator) Q_DECL_NOTHROW
{ d.swap(iterator.d); return *this; }
#endif
void swap(QRegularExpressionMatchIterator &iterator) { d.swap(iterator.d); }
void swap(QRegularExpressionMatchIterator &other) Q_DECL_NOTHROW { d.swap(other.d); }
bool isValid() const;

View File

@ -79,7 +79,7 @@ public:
inline QSharedDataPointer() { d = 0; }
inline ~QSharedDataPointer() { if (d && !d->ref.deref()) delete d; }
explicit QSharedDataPointer(T *data);
explicit QSharedDataPointer(T *data) Q_DECL_NOTHROW;
inline QSharedDataPointer(const QSharedDataPointer<T> &o) : d(o.d) { if (d) d->ref.ref(); }
inline QSharedDataPointer<T> & operator=(const QSharedDataPointer<T> &o) {
if (o.d != d) {
@ -104,14 +104,14 @@ public:
return *this;
}
#ifdef Q_COMPILER_RVALUE_REFS
QSharedDataPointer(QSharedDataPointer &&o) : d(o.d) { o.d = 0; }
inline QSharedDataPointer<T> &operator=(QSharedDataPointer<T> &&other)
QSharedDataPointer(QSharedDataPointer &&o) Q_DECL_NOTHROW : d(o.d) { o.d = Q_NULLPTR; }
inline QSharedDataPointer<T> &operator=(QSharedDataPointer<T> &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
inline bool operator!() const { return !d; }
inline void swap(QSharedDataPointer &other)
inline void swap(QSharedDataPointer &other) Q_DECL_NOTHROW
{ qSwap(d, other.d); }
protected:
@ -155,7 +155,7 @@ public:
inline QExplicitlySharedDataPointer() { d = 0; }
inline ~QExplicitlySharedDataPointer() { if (d && !d->ref.deref()) delete d; }
explicit QExplicitlySharedDataPointer(T *data);
explicit QExplicitlySharedDataPointer(T *data) Q_DECL_NOTHROW;
inline QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<T> &o) : d(o.d) { if (d) d->ref.ref(); }
template<class X>
@ -193,14 +193,14 @@ public:
return *this;
}
#ifdef Q_COMPILER_RVALUE_REFS
inline QExplicitlySharedDataPointer(QExplicitlySharedDataPointer &&o) : d(o.d) { o.d = 0; }
inline QExplicitlySharedDataPointer<T> &operator=(QExplicitlySharedDataPointer<T> &&other)
inline QExplicitlySharedDataPointer(QExplicitlySharedDataPointer &&o) Q_DECL_NOTHROW : d(o.d) { o.d = Q_NULLPTR; }
inline QExplicitlySharedDataPointer<T> &operator=(QExplicitlySharedDataPointer<T> &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
inline bool operator!() const { return !d; }
inline void swap(QExplicitlySharedDataPointer &other)
inline void swap(QExplicitlySharedDataPointer &other) Q_DECL_NOTHROW
{ qSwap(d, other.d); }
protected:
@ -213,7 +213,8 @@ private:
};
template <class T>
Q_INLINE_TEMPLATE QSharedDataPointer<T>::QSharedDataPointer(T *adata) : d(adata)
Q_INLINE_TEMPLATE QSharedDataPointer<T>::QSharedDataPointer(T *adata) Q_DECL_NOTHROW
: d(adata)
{ if (d) d->ref.ref(); }
template <class T>
@ -249,7 +250,8 @@ Q_OUTOFLINE_TEMPLATE void QExplicitlySharedDataPointer<T>::detach_helper()
}
template <class T>
Q_INLINE_TEMPLATE QExplicitlySharedDataPointer<T>::QExplicitlySharedDataPointer(T *adata) : d(adata)
Q_INLINE_TEMPLATE QExplicitlySharedDataPointer<T>::QExplicitlySharedDataPointer(T *adata) Q_DECL_NOTHROW
: d(adata)
{ if (d) d->ref.ref(); }
template <class T>
@ -273,12 +275,12 @@ namespace std {
QT_BEGIN_NAMESPACE
template <class T>
Q_INLINE_TEMPLATE uint qHash(const QSharedDataPointer<T> &ptr, uint seed = 0)
Q_INLINE_TEMPLATE uint qHash(const QSharedDataPointer<T> &ptr, uint seed = 0) Q_DECL_NOTHROW
{
return qHash(ptr.data(), seed);
}
template <class T>
Q_INLINE_TEMPLATE uint qHash(const QExplicitlySharedDataPointer<T> &ptr, uint seed = 0)
Q_INLINE_TEMPLATE uint qHash(const QExplicitlySharedDataPointer<T> &ptr, uint seed = 0) Q_DECL_NOTHROW
{
return qHash(ptr.data(), seed);
}

View File

@ -210,7 +210,7 @@ class Q_CORE_EXPORT QString
public:
typedef QStringData Data;
inline QString();
inline QString() Q_DECL_NOTHROW;
explicit QString(const QChar *unicode, int size = -1);
QString(QChar c);
QString(int size, QChar c);
@ -221,11 +221,11 @@ public:
QString &operator=(const QString &);
inline QString &operator=(QLatin1String latin1);
#ifdef Q_COMPILER_RVALUE_REFS
inline QString(QString && other) : d(other.d) { other.d = Data::sharedNull(); }
inline QString &operator=(QString &&other)
inline QString(QString && other) Q_DECL_NOTHROW : d(other.d) { other.d = Data::sharedNull(); }
inline QString &operator=(QString &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
inline void swap(QString &other) { qSwap(d, other.d); }
inline void swap(QString &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
inline int size() const { return d->size; }
inline int count() const { return d->size; }
inline int length() const;
@ -1040,7 +1040,7 @@ inline void QCharRef::setRow(uchar arow) { QChar(*this).setRow(arow); }
inline void QCharRef::setCell(uchar acell) { QChar(*this).setCell(acell); }
inline QString::QString() : d(Data::sharedNull()) {}
inline QString::QString() Q_DECL_NOTHROW : d(Data::sharedNull()) {}
inline QString::~QString() { if (!d->ref.deref()) Data::deallocate(d); }
inline void QString::reserve(int asize)

View File

@ -90,11 +90,11 @@ class QStringList : public QList<QString>
{
#endif
public:
inline QStringList() { }
inline QStringList() Q_DECL_NOTHROW { }
inline explicit QStringList(const QString &i) { append(i); }
inline QStringList(const QList<QString> &l) : QList<QString>(l) { }
#ifdef Q_COMPILER_RVALUE_REFS
inline QStringList(QList<QString> &&l) : QList<QString>(std::move(l)) { }
inline QStringList(QList<QString> &&l) Q_DECL_NOTHROW : QList<QString>(std::move(l)) { }
#endif
#ifdef Q_COMPILER_INITIALIZER_LISTS
inline QStringList(std::initializer_list<QString> args) : QList<QString>(args) { }
@ -103,7 +103,7 @@ public:
QStringList &operator=(const QList<QString> &other)
{ QList<QString>::operator=(other); return *this; }
#ifdef Q_COMPILER_RVALUE_REFS
QStringList &operator=(QList<QString> &&other)
QStringList &operator=(QList<QString> &&other) Q_DECL_NOTHROW
{ QList<QString>::operator=(std::move(other)); return *this; }
#endif

View File

@ -79,10 +79,10 @@ public:
QTimeZone &operator=(const QTimeZone &other);
#ifdef Q_COMPILER_RVALUE_REFS
QTimeZone &operator=(QTimeZone &&other) { swap(other); return *this; }
QTimeZone &operator=(QTimeZone &&other) Q_DECL_NOTHROW { swap(other); return *this; }
#endif
void swap(QTimeZone &other)
void swap(QTimeZone &other) Q_DECL_NOTHROW
{ d.swap(other.d); }
bool operator==(const QTimeZone &other) const;

View File

@ -61,7 +61,7 @@ class QVector
Data *d;
public:
inline QVector() : d(Data::sharedNull()) { }
inline QVector() Q_DECL_NOTHROW : d(Data::sharedNull()) { }
explicit QVector(int size);
QVector(int size, const T &t);
inline QVector(const QVector<T> &v);