diff options
Diffstat (limited to 'src/corelib')
263 files changed, 4277 insertions, 4275 deletions
diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index b507049cc4..0be37b7dca 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -152,6 +152,7 @@ #include <QtCore/qthreadstorage.h> #include <QtCore/qcoreevent.h> #include <QtCore/qpointer.h> +#include <QtCore/qscopedvaluerollback.h> #define DEFAULT_TIMER_INTERVAL 16 #define PAUSE_TIMER_COARSE_THRESHOLD 2000 @@ -315,14 +316,13 @@ void QUnifiedTimer::updateAnimationTimers(qint64 currentTick) //* it might happen in some cases that the delta is negative because the animation driver // advances faster than time.elapsed() if (delta > 0) { - insideTick = true; + QScopedValueRollback<bool> guard(insideTick, true); if (profilerCallback) profilerCallback(delta); for (currentAnimationIdx = 0; currentAnimationIdx < animationTimers.count(); ++currentAnimationIdx) { QAbstractAnimationTimer *animation = animationTimers.at(currentAnimationIdx); animation->updateAnimationsTime(delta); } - insideTick = false; currentAnimationIdx = 0; } } @@ -361,10 +361,11 @@ void QUnifiedTimer::localRestart() void QUnifiedTimer::restart() { - insideRestart = true; - for (int i = 0; i < animationTimers.count(); ++i) - animationTimers.at(i)->restartAnimationTimer(); - insideRestart = false; + { + QScopedValueRollback<bool> guard(insideRestart, true); + for (int i = 0; i < animationTimers.count(); ++i) + animationTimers.at(i)->restartAnimationTimer(); + } localRestart(); } @@ -599,14 +600,13 @@ void QAnimationTimer::updateAnimationsTime(qint64 delta) //it might happen in some cases that the time doesn't change because events are delayed //when the CPU load is high if (delta) { - insideTick = true; + QScopedValueRollback<bool> guard(insideTick, true); for (currentAnimationIdx = 0; currentAnimationIdx < animations.count(); ++currentAnimationIdx) { QAbstractAnimation *animation = animations.at(currentAnimationIdx); int elapsed = QAbstractAnimationPrivate::get(animation)->totalCurrentTime + (animation->direction() == QAbstractAnimation::Forward ? delta : -delta); animation->setCurrentTime(elapsed); } - insideTick = false; currentAnimationIdx = 0; } } diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h index 3b6e8d6cc4..037d3be74f 100644 --- a/src/corelib/animation/qabstractanimation_p.h +++ b/src/corelib/animation/qabstractanimation_p.h @@ -78,7 +78,7 @@ public: hasRegisteredTimer(false), isPause(false), isGroup(false), - group(0) + group(nullptr) { } diff --git a/src/corelib/animation/qanimationgroup_p.h b/src/corelib/animation/qanimationgroup_p.h index ff759d11fd..215734b656 100644 --- a/src/corelib/animation/qanimationgroup_p.h +++ b/src/corelib/animation/qanimationgroup_p.h @@ -76,7 +76,7 @@ public: void disconnectUncontrolledAnimation(QAbstractAnimation *anim) { //0 for the signal here because we might be called from the animation destructor - QObject::disconnect(anim, 0, q_func(), SLOT(_q_uncontrolledAnimationFinished())); + QObject::disconnect(anim, nullptr, q_func(), SLOT(_q_uncontrolledAnimationFinished())); } void connectUncontrolledAnimation(QAbstractAnimation *anim) diff --git a/src/corelib/animation/qpropertyanimation_p.h b/src/corelib/animation/qpropertyanimation_p.h index 479762f573..cbd3ce287d 100644 --- a/src/corelib/animation/qpropertyanimation_p.h +++ b/src/corelib/animation/qpropertyanimation_p.h @@ -64,7 +64,7 @@ class QPropertyAnimationPrivate : public QVariantAnimationPrivate Q_DECLARE_PUBLIC(QPropertyAnimation) public: QPropertyAnimationPrivate() - : targetValue(0), propertyType(0), propertyIndex(-1) + : targetValue(nullptr), propertyType(0), propertyIndex(-1) { } diff --git a/src/corelib/animation/qsequentialanimationgroup_p.h b/src/corelib/animation/qsequentialanimationgroup_p.h index 88dac4f566..c082d6b524 100644 --- a/src/corelib/animation/qsequentialanimationgroup_p.h +++ b/src/corelib/animation/qsequentialanimationgroup_p.h @@ -63,7 +63,7 @@ class QSequentialAnimationGroupPrivate : public QAnimationGroupPrivate Q_DECLARE_PUBLIC(QSequentialAnimationGroup) public: QSequentialAnimationGroupPrivate() - : currentAnimation(0), currentAnimationIndex(-1), lastLoop(0) + : currentAnimation(nullptr), currentAnimationIndex(-1), lastLoop(0) { } diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp index ffd8a2ce93..602b97e32e 100644 --- a/src/corelib/codecs/qtextcodec.cpp +++ b/src/corelib/codecs/qtextcodec.cpp @@ -1061,7 +1061,7 @@ QString QTextDecoder::toUnicode(const char *chars, int len) } // in qstring.cpp: -void qt_from_latin1(ushort *dst, const char *str, size_t size) Q_DECL_NOTHROW; +void qt_from_latin1(ushort *dst, const char *str, size_t size) noexcept; /*! \overload diff --git a/src/corelib/codecs/qtextcodec_p.h b/src/corelib/codecs/qtextcodec_p.h index 0e449d994c..7fcf6df984 100644 --- a/src/corelib/codecs/qtextcodec_p.h +++ b/src/corelib/codecs/qtextcodec_p.h @@ -98,7 +98,7 @@ public: struct ConverterState { ConverterState(ConversionFlags f = DefaultConversion) - : flags(f), remainingChars(0), invalidChars(0), d(0) { state_data[0] = state_data[1] = state_data[2] = 0; } + : flags(f), remainingChars(0), invalidChars(0), d(nullptr) { state_data[0] = state_data[1] = state_data[2] = 0; } ~ConverterState() { } ConversionFlags flags; int remainingChars; diff --git a/src/corelib/codecs/qutfcodec.cpp b/src/corelib/codecs/qutfcodec.cpp index 643c8ee475..85736fdf02 100644 --- a/src/corelib/codecs/qutfcodec.cpp +++ b/src/corelib/codecs/qutfcodec.cpp @@ -54,7 +54,7 @@ static const uchar utf8bom[] = { 0xef, 0xbb, 0xbf }; #if (defined(__SSE2__) && defined(QT_COMPILER_SUPPORTS_SSE2)) \ || (defined(__ARM_NEON__) && defined(Q_PROCESSOR_ARM_64)) -static Q_ALWAYS_INLINE uint qBitScanReverse(unsigned v) Q_DECL_NOTHROW +static Q_ALWAYS_INLINE uint qBitScanReverse(unsigned v) noexcept { uint result = qCountLeadingZeroBits(v); // Now Invert the result: clz will count *down* from the msb to the lsb, so the msb index is 31 @@ -504,7 +504,7 @@ QString QUtf8::convertToUnicode(const char *chars, int len) This function never throws. */ -QChar *QUtf8::convertToUnicode(QChar *buffer, const char *chars, int len) Q_DECL_NOTHROW +QChar *QUtf8::convertToUnicode(QChar *buffer, const char *chars, int len) noexcept { ushort *dst = reinterpret_cast<ushort *>(buffer); const uchar *src = reinterpret_cast<const uchar *>(chars); diff --git a/src/corelib/codecs/qutfcodec_p.h b/src/corelib/codecs/qutfcodec_p.h index b24283ac5e..083e16317a 100644 --- a/src/corelib/codecs/qutfcodec_p.h +++ b/src/corelib/codecs/qutfcodec_p.h @@ -291,7 +291,7 @@ enum DataEndianness struct QUtf8 { - static QChar *convertToUnicode(QChar *, const char *, int) Q_DECL_NOTHROW; + static QChar *convertToUnicode(QChar *, const char *, int) noexcept; static QString convertToUnicode(const char *, int); static QString convertToUnicode(const char *, int, QTextCodec::ConverterState *); static QByteArray convertFromUnicode(const QChar *, int); diff --git a/src/corelib/configure.json b/src/corelib/configure.json index b7eefb58c8..a6091d4825 100644 --- a/src/corelib/configure.json +++ b/src/corelib/configure.json @@ -12,7 +12,7 @@ "inotify": "boolean", "journald": "boolean", "mimetype-database": "boolean", - "pcre": { "type": "enum", "values": [ "qt", "system" ] }, + "pcre": { "type": "enum", "values": [ "no", "qt", "system" ] }, "posix-ipc": { "type": "boolean", "name": "ipc_posix" }, "pps": { "type": "boolean", "name": "qqnx_pps" }, "slog2": "boolean", @@ -684,15 +684,18 @@ "condition": "features.mimetype", "output": [ "privateFeature" ] }, + "pcre2": { + "label": "PCRE2", + "disable": "input.pcre == 'no' || input.pcre == 'system'", + "enable": "input.pcre == 'qt'", + "output": [ "privateConfig" ] + }, "system-pcre2": { - "label": "Using system PCRE2", - "disable": "input.pcre == 'qt'", + "label": " Using system PCRE2", + "disable": "input.pcre == 'no' || input.pcre == 'qt'", "enable": "input.pcre == 'system'", "condition": "libs.pcre2", - "output": [ - "privateFeature", - { "type": "privateConfig", "negative": true, "name": "pcre2" } - ] + "output": [ "privateFeature" ] }, "poll_ppoll": { "label": "Native ppoll()", @@ -771,6 +774,7 @@ "label": "QRegularExpression", "purpose": "Provides an API to Perl-compatible regular expressions.", "section": "Kernel", + "condition": "features.system-pcre2 || features.pcre2", "output": [ "publicFeature", "feature" ] }, "sharedmemory": { @@ -1071,6 +1075,7 @@ Please apply the patch corresponding to your Standard Library vendor, found in "args": "qqnx_pps", "condition": "config.qnx" }, + "pcre2", "system-pcre2" ] } diff --git a/src/corelib/corelib.pro b/src/corelib/corelib.pro index 4b758532e6..dc43e56836 100644 --- a/src/corelib/corelib.pro +++ b/src/corelib/corelib.pro @@ -68,8 +68,6 @@ integrity { QMAKE_DYNAMIC_LIST_FILE = $$PWD/QtCore.dynlist -contains(DEFINES,QT_EVAL):include(eval.pri) - HOST_BINS = $$[QT_HOST_BINS] host_bins.name = host_bins host_bins.variable = HOST_BINS diff --git a/src/corelib/eval.pri b/src/corelib/eval.pri deleted file mode 100644 index efda56b16a..0000000000 --- a/src/corelib/eval.pri +++ /dev/null @@ -1,4 +0,0 @@ -SOURCES += \ - $$QT_SOURCE_TREE/src/corelib/kernel/qtcore_eval.cpp -INCLUDEPATH += \ - $$QT_BUILD_TREE/src/corelib/global diff --git a/src/corelib/global/global.pri b/src/corelib/global/global.pri index 029357ff43..428c674307 100644 --- a/src/corelib/global/global.pri +++ b/src/corelib/global/global.pri @@ -12,7 +12,6 @@ HEADERS += \ global/qendian_p.h \ global/qnumeric_p.h \ global/qnumeric.h \ - global/qfloat16_p.h \ global/qfloat16.h \ global/qglobalstatic.h \ global/qlibraryinfo.h \ diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index 345ab9e8ad..e47f284a42 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -110,12 +110,6 @@ # define Q_CC_INTEL __INTEL_COMPILER # endif -/* only defined for MSVC since that's the only compiler that actually optimizes for this */ -/* might get overridden further down when Q_COMPILER_NOEXCEPT is detected */ -# ifdef __cplusplus -# define Q_DECL_NOTHROW throw() -# endif - #elif defined(__BORLANDC__) || defined(__TURBOC__) # define Q_CC_BOR # define Q_INLINE_TEMPLATE @@ -1128,16 +1122,11 @@ #ifdef Q_COMPILER_NOEXCEPT # define Q_DECL_NOEXCEPT noexcept # define Q_DECL_NOEXCEPT_EXPR(x) noexcept(x) -# ifdef Q_DECL_NOTHROW -# undef Q_DECL_NOTHROW /* override with C++11 noexcept if available */ -# endif #else # define Q_DECL_NOEXCEPT # define Q_DECL_NOEXCEPT_EXPR(x) #endif -#ifndef Q_DECL_NOTHROW -# define Q_DECL_NOTHROW Q_DECL_NOEXCEPT -#endif +#define Q_DECL_NOTHROW Q_DECL_NOEXCEPT #if defined(Q_COMPILER_ALIGNOF) # undef Q_ALIGNOF diff --git a/src/corelib/global/qflags.h b/src/corelib/global/qflags.h index e9fee5f23e..65f4892472 100644 --- a/src/corelib/global/qflags.h +++ b/src/corelib/global/qflags.h @@ -54,21 +54,21 @@ class QFlag { int i; public: - Q_DECL_CONSTEXPR inline QFlag(int value) Q_DECL_NOTHROW : i(value) {} - Q_DECL_CONSTEXPR inline operator int() const Q_DECL_NOTHROW { return i; } + Q_DECL_CONSTEXPR inline QFlag(int value) noexcept : i(value) {} + Q_DECL_CONSTEXPR inline operator int() const noexcept { return i; } #if !defined(Q_CC_MSVC) // Microsoft Visual Studio has buggy behavior when it comes to // unsigned enums: even if the enum is unsigned, the enum tags are // always signed # if !defined(__LP64__) && !defined(Q_CLANG_QDOC) - Q_DECL_CONSTEXPR inline QFlag(long value) Q_DECL_NOTHROW : i(int(value)) {} - Q_DECL_CONSTEXPR inline QFlag(ulong value) Q_DECL_NOTHROW : i(int(long(value))) {} + Q_DECL_CONSTEXPR inline QFlag(long value) noexcept : i(int(value)) {} + Q_DECL_CONSTEXPR inline QFlag(ulong value) noexcept : i(int(long(value))) {} # endif - Q_DECL_CONSTEXPR inline QFlag(uint value) Q_DECL_NOTHROW : i(int(value)) {} - Q_DECL_CONSTEXPR inline QFlag(short value) Q_DECL_NOTHROW : i(int(value)) {} - Q_DECL_CONSTEXPR inline QFlag(ushort value) Q_DECL_NOTHROW : i(int(uint(value))) {} - Q_DECL_CONSTEXPR inline operator uint() const Q_DECL_NOTHROW { return uint(i); } + Q_DECL_CONSTEXPR inline QFlag(uint value) noexcept : i(int(value)) {} + Q_DECL_CONSTEXPR inline QFlag(short value) noexcept : i(int(value)) {} + Q_DECL_CONSTEXPR inline QFlag(ushort value) noexcept : i(int(uint(value))) {} + Q_DECL_CONSTEXPR inline operator uint() const noexcept { return uint(i); } #endif }; Q_DECLARE_TYPEINFO(QFlag, Q_PRIMITIVE_TYPE); @@ -77,12 +77,12 @@ class QIncompatibleFlag { int i; public: - Q_DECL_CONSTEXPR inline explicit QIncompatibleFlag(int i) Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline operator int() const Q_DECL_NOTHROW { return i; } + Q_DECL_CONSTEXPR inline explicit QIncompatibleFlag(int i) noexcept; + Q_DECL_CONSTEXPR inline operator int() const noexcept { return i; } }; Q_DECLARE_TYPEINFO(QIncompatibleFlag, Q_PRIMITIVE_TYPE); -Q_DECL_CONSTEXPR inline QIncompatibleFlag::QIncompatibleFlag(int value) Q_DECL_NOTHROW : i(value) {} +Q_DECL_CONSTEXPR inline QIncompatibleFlag::QIncompatibleFlag(int value) noexcept : i(value) {} #ifndef Q_NO_TYPESAFE_FLAGS @@ -117,38 +117,38 @@ public: Q_DECL_CONSTEXPR inline QFlags(const QFlags &other); Q_DECL_CONSTEXPR inline QFlags &operator=(const QFlags &other); #endif - Q_DECL_CONSTEXPR inline QFlags(Enum flags) Q_DECL_NOTHROW : i(Int(flags)) {} - Q_DECL_CONSTEXPR inline QFlags(Zero = Q_NULLPTR) Q_DECL_NOTHROW : i(0) {} - Q_DECL_CONSTEXPR inline QFlags(QFlag flag) Q_DECL_NOTHROW : i(flag) {} + Q_DECL_CONSTEXPR inline QFlags(Enum flags) noexcept : i(Int(flags)) {} + Q_DECL_CONSTEXPR inline QFlags(Zero = nullptr) noexcept : i(0) {} + Q_DECL_CONSTEXPR inline QFlags(QFlag flag) noexcept : i(flag) {} #ifdef Q_COMPILER_INITIALIZER_LISTS - Q_DECL_CONSTEXPR inline QFlags(std::initializer_list<Enum> flags) Q_DECL_NOTHROW + Q_DECL_CONSTEXPR inline QFlags(std::initializer_list<Enum> flags) noexcept : i(initializer_list_helper(flags.begin(), flags.end())) {} #endif - Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator&=(int mask) Q_DECL_NOTHROW { i &= mask; return *this; } - Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator&=(uint mask) Q_DECL_NOTHROW { i &= mask; return *this; } - Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator&=(Enum mask) Q_DECL_NOTHROW { i &= Int(mask); return *this; } - Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator|=(QFlags other) Q_DECL_NOTHROW { i |= other.i; return *this; } - Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator|=(Enum other) Q_DECL_NOTHROW { i |= Int(other); return *this; } - Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator^=(QFlags other) Q_DECL_NOTHROW { i ^= other.i; return *this; } - Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator^=(Enum other) Q_DECL_NOTHROW { i ^= Int(other); return *this; } - - Q_DECL_CONSTEXPR inline operator Int() const Q_DECL_NOTHROW { return i; } - - Q_DECL_CONSTEXPR inline QFlags operator|(QFlags other) const Q_DECL_NOTHROW { return QFlags(QFlag(i | other.i)); } - Q_DECL_CONSTEXPR inline QFlags operator|(Enum other) const Q_DECL_NOTHROW { return QFlags(QFlag(i | Int(other))); } - Q_DECL_CONSTEXPR inline QFlags operator^(QFlags other) const Q_DECL_NOTHROW { return QFlags(QFlag(i ^ other.i)); } - Q_DECL_CONSTEXPR inline QFlags operator^(Enum other) const Q_DECL_NOTHROW { return QFlags(QFlag(i ^ Int(other))); } - Q_DECL_CONSTEXPR inline QFlags operator&(int mask) const Q_DECL_NOTHROW { return QFlags(QFlag(i & mask)); } - Q_DECL_CONSTEXPR inline QFlags operator&(uint mask) const Q_DECL_NOTHROW { return QFlags(QFlag(i & mask)); } - Q_DECL_CONSTEXPR inline QFlags operator&(Enum other) const Q_DECL_NOTHROW { return QFlags(QFlag(i & Int(other))); } - Q_DECL_CONSTEXPR inline QFlags operator~() const Q_DECL_NOTHROW { return QFlags(QFlag(~i)); } - - Q_DECL_CONSTEXPR inline bool operator!() const Q_DECL_NOTHROW { return !i; } - - Q_DECL_CONSTEXPR inline bool testFlag(Enum flag) const Q_DECL_NOTHROW { return (i & Int(flag)) == Int(flag) && (Int(flag) != 0 || i == Int(flag) ); } - Q_DECL_RELAXED_CONSTEXPR inline QFlags &setFlag(Enum flag, bool on = true) Q_DECL_NOTHROW + Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator&=(int mask) noexcept { i &= mask; return *this; } + Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator&=(uint mask) noexcept { i &= mask; return *this; } + Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator&=(Enum mask) noexcept { i &= Int(mask); return *this; } + Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator|=(QFlags other) noexcept { i |= other.i; return *this; } + Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator|=(Enum other) noexcept { i |= Int(other); return *this; } + Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator^=(QFlags other) noexcept { i ^= other.i; return *this; } + Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator^=(Enum other) noexcept { i ^= Int(other); return *this; } + + Q_DECL_CONSTEXPR inline operator Int() const noexcept { return i; } + + Q_DECL_CONSTEXPR inline QFlags operator|(QFlags other) const noexcept { return QFlags(QFlag(i | other.i)); } + Q_DECL_CONSTEXPR inline QFlags operator|(Enum other) const noexcept { return QFlags(QFlag(i | Int(other))); } + Q_DECL_CONSTEXPR inline QFlags operator^(QFlags other) const noexcept { return QFlags(QFlag(i ^ other.i)); } + Q_DECL_CONSTEXPR inline QFlags operator^(Enum other) const noexcept { return QFlags(QFlag(i ^ Int(other))); } + Q_DECL_CONSTEXPR inline QFlags operator&(int mask) const noexcept { return QFlags(QFlag(i & mask)); } + Q_DECL_CONSTEXPR inline QFlags operator&(uint mask) const noexcept { return QFlags(QFlag(i & mask)); } + Q_DECL_CONSTEXPR inline QFlags operator&(Enum other) const noexcept { return QFlags(QFlag(i & Int(other))); } + Q_DECL_CONSTEXPR inline QFlags operator~() const noexcept { return QFlags(QFlag(~i)); } + + Q_DECL_CONSTEXPR inline bool operator!() const noexcept { return !i; } + + Q_DECL_CONSTEXPR inline bool testFlag(Enum flag) const noexcept { return (i & Int(flag)) == Int(flag) && (Int(flag) != 0 || i == Int(flag) ); } + Q_DECL_RELAXED_CONSTEXPR inline QFlags &setFlag(Enum flag, bool on = true) noexcept { return on ? (*this |= flag) : (*this &= ~Int(flag)); } @@ -157,7 +157,7 @@ private: #ifdef Q_COMPILER_INITIALIZER_LISTS Q_DECL_CONSTEXPR static inline Int initializer_list_helper(typename std::initializer_list<Enum>::const_iterator it, typename std::initializer_list<Enum>::const_iterator end) - Q_DECL_NOTHROW + noexcept { return (it == end ? Int(0) : (Int(*it) | initializer_list_helper(it + 1, end))); } @@ -172,13 +172,13 @@ typedef QFlags<Enum> Flags; #endif #define Q_DECLARE_INCOMPATIBLE_FLAGS(Flags) \ -Q_DECL_CONSTEXPR inline QIncompatibleFlag operator|(Flags::enum_type f1, int f2) Q_DECL_NOTHROW \ +Q_DECL_CONSTEXPR inline QIncompatibleFlag operator|(Flags::enum_type f1, int f2) noexcept \ { return QIncompatibleFlag(int(f1) | f2); } #define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags) \ -Q_DECL_CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) Q_DECL_NOTHROW \ +Q_DECL_CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) noexcept \ { return QFlags<Flags::enum_type>(f1) | f2; } \ -Q_DECL_CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> f2) Q_DECL_NOTHROW \ +Q_DECL_CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> f2) noexcept \ { return f2 | f1; } Q_DECLARE_INCOMPATIBLE_FLAGS(Flags) diff --git a/src/corelib/global/qfloat16.cpp b/src/corelib/global/qfloat16.cpp index fd608efe55..680268c59b 100644 --- a/src/corelib/global/qfloat16.cpp +++ b/src/corelib/global/qfloat16.cpp @@ -37,7 +37,7 @@ ** ****************************************************************************/ -#include "qfloat16_p.h" +#include "qfloat16.h" #include "private/qsimd_p.h" QT_BEGIN_NAMESPACE @@ -65,28 +65,31 @@ QT_BEGIN_NAMESPACE */ /*! - Returns true if the \c qfloat16 \a {f} is equivalent to infinity. + \fn bool qIsInf(qfloat16 f) \relates <QFloat16> + Returns true if the \c qfloat16 \a {f} is equivalent to infinity. + \sa qIsInf */ -Q_REQUIRED_RESULT bool qIsInf(qfloat16 f) Q_DECL_NOTHROW { return qt_is_inf(f); } /*! - Returns true if the \c qfloat16 \a {f} is not a number (NaN). + \fn bool qIsNaN(qfloat16 f) \relates <QFloat16> + Returns true if the \c qfloat16 \a {f} is not a number (NaN). + \sa qIsNaN */ -Q_REQUIRED_RESULT bool qIsNaN(qfloat16 f) Q_DECL_NOTHROW { return qt_is_nan(f); } /*! - Returns true if the \c qfloat16 \a {f} is a finite number. + \fn bool qIsFinite(qfloat16 f) \relates <QFloat16> + Returns true if the \c qfloat16 \a {f} is a finite number. + \sa qIsFinite */ -Q_REQUIRED_RESULT bool qIsFinite(qfloat16 f) Q_DECL_NOTHROW { return qt_is_finite(f); } /*! \fn int qRound(qfloat16 value) \relates <QFloat16> @@ -129,8 +132,8 @@ extern "C" { # define f16cextern extern #endif -f16cextern void qFloatToFloat16_fast(quint16 *out, const float *in, qsizetype len) Q_DECL_NOTHROW; -f16cextern void qFloatFromFloat16_fast(float *out, const quint16 *in, qsizetype len) Q_DECL_NOTHROW; +f16cextern void qFloatToFloat16_fast(quint16 *out, const float *in, qsizetype len) noexcept; +f16cextern void qFloatFromFloat16_fast(float *out, const quint16 *in, qsizetype len) noexcept; #undef f16cextern } @@ -141,7 +144,7 @@ static inline bool hasFastF16() return true; } -static void qFloatToFloat16_fast(quint16 *out, const float *in, qsizetype len) Q_DECL_NOTHROW +static void qFloatToFloat16_fast(quint16 *out, const float *in, qsizetype len) noexcept { __fp16 *out_f16 = reinterpret_cast<__fp16 *>(out); qsizetype i = 0; @@ -151,7 +154,7 @@ static void qFloatToFloat16_fast(quint16 *out, const float *in, qsizetype len) Q out_f16[i] = __fp16(in[i]); } -static void qFloatFromFloat16_fast(float *out, const quint16 *in, qsizetype len) Q_DECL_NOTHROW +static void qFloatFromFloat16_fast(float *out, const quint16 *in, qsizetype len) noexcept { const __fp16 *in_f16 = reinterpret_cast<const __fp16 *>(in); qsizetype i = 0; @@ -166,12 +169,12 @@ static inline bool hasFastF16() return false; } -static void qFloatToFloat16_fast(quint16 *, const float *, qsizetype) Q_DECL_NOTHROW +static void qFloatToFloat16_fast(quint16 *, const float *, qsizetype) noexcept { Q_UNREACHABLE(); } -static void qFloatFromFloat16_fast(float *, const quint16 *, qsizetype) Q_DECL_NOTHROW +static void qFloatFromFloat16_fast(float *, const quint16 *, qsizetype) noexcept { Q_UNREACHABLE(); } @@ -183,7 +186,7 @@ static void qFloatFromFloat16_fast(float *, const quint16 *, qsizetype) Q_DECL_N Converts \a len floats from \a in to qfloat16 and stores them in \a out. Both \a in and \a out must have \a len allocated entries. */ -Q_CORE_EXPORT void qFloatToFloat16(qfloat16 *out, const float *in, qsizetype len) Q_DECL_NOTHROW +Q_CORE_EXPORT void qFloatToFloat16(qfloat16 *out, const float *in, qsizetype len) noexcept { if (hasFastF16()) return qFloatToFloat16_fast(reinterpret_cast<quint16 *>(out), in, len); @@ -199,7 +202,7 @@ Q_CORE_EXPORT void qFloatToFloat16(qfloat16 *out, const float *in, qsizetype len Converts \a len qfloat16 from \a in to floats and stores them in \a out. Both \a in and \a out must have \a len allocated entries. */ -Q_CORE_EXPORT void qFloatFromFloat16(float *out, const qfloat16 *in, qsizetype len) Q_DECL_NOTHROW +Q_CORE_EXPORT void qFloatFromFloat16(float *out, const qfloat16 *in, qsizetype len) noexcept { if (hasFastF16()) return qFloatFromFloat16_fast(out, reinterpret_cast<const quint16 *>(in), len); diff --git a/src/corelib/global/qfloat16.h b/src/corelib/global/qfloat16.h index 42cb1357f1..243aea98be 100644 --- a/src/corelib/global/qfloat16.h +++ b/src/corelib/global/qfloat16.h @@ -67,10 +67,14 @@ QT_BEGIN_NAMESPACE class qfloat16 { public: - Q_DECL_CONSTEXPR inline qfloat16() Q_DECL_NOTHROW : b16(0) { } - inline qfloat16(float f) Q_DECL_NOTHROW; - inline operator float() const Q_DECL_NOTHROW; - + constexpr inline qfloat16() noexcept : b16(0) {} + inline qfloat16(float f) noexcept; + inline operator float() const noexcept; + + // Support for qIs{Inf,NaN,Finite}: + bool isInf() const noexcept { return ((b16 >> 8) & 0x7e) == 0x7c; } + bool isNaN() const noexcept { return ((b16 >> 8) & 0x7e) == 0x7e; } + bool isFinite() const noexcept { return ((b16 >> 8) & 0x7c) != 0x7c; } private: quint16 b16; @@ -80,27 +84,29 @@ private: Q_CORE_EXPORT static const quint32 basetable[]; Q_CORE_EXPORT static const quint32 shifttable[]; - friend bool qIsNull(qfloat16 f) Q_DECL_NOTHROW; - friend qfloat16 operator-(qfloat16 a) Q_DECL_NOTHROW; + friend bool qIsNull(qfloat16 f) noexcept; + friend qfloat16 operator-(qfloat16 a) noexcept; }; Q_DECLARE_TYPEINFO(qfloat16, Q_PRIMITIVE_TYPE); -Q_CORE_EXPORT void qFloatToFloat16(qfloat16 *, const float *, qsizetype length) Q_DECL_NOTHROW; -Q_CORE_EXPORT void qFloatFromFloat16(float *, const qfloat16 *, qsizetype length) Q_DECL_NOTHROW; +Q_CORE_EXPORT void qFloatToFloat16(qfloat16 *, const float *, qsizetype length) noexcept; +Q_CORE_EXPORT void qFloatFromFloat16(float *, const qfloat16 *, qsizetype length) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT bool qIsInf(qfloat16 f) Q_DECL_NOTHROW; // complements qnumeric.h -Q_REQUIRED_RESULT Q_CORE_EXPORT bool qIsNaN(qfloat16 f) Q_DECL_NOTHROW; // complements qnumeric.h -Q_REQUIRED_RESULT Q_CORE_EXPORT bool qIsFinite(qfloat16 f) Q_DECL_NOTHROW; // complements qnumeric.h +// Complement qnumeric.h: +Q_REQUIRED_RESULT inline bool qIsInf(qfloat16 f) noexcept { return f.isInf(); } +Q_REQUIRED_RESULT inline bool qIsNaN(qfloat16 f) noexcept { return f.isNaN(); } +Q_REQUIRED_RESULT inline bool qIsFinite(qfloat16 f) noexcept { return f.isFinite(); } +// Q_REQUIRED_RESULT quint32 qFloatDistance(qfloat16 a, qfloat16 b); // The remainder of these utility functions complement qglobal.h -Q_REQUIRED_RESULT inline int qRound(qfloat16 d) Q_DECL_NOTHROW +Q_REQUIRED_RESULT inline int qRound(qfloat16 d) noexcept { return qRound(static_cast<float>(d)); } -Q_REQUIRED_RESULT inline qint64 qRound64(qfloat16 d) Q_DECL_NOTHROW +Q_REQUIRED_RESULT inline qint64 qRound64(qfloat16 d) noexcept { return qRound64(static_cast<float>(d)); } -Q_REQUIRED_RESULT inline bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) Q_DECL_NOTHROW +Q_REQUIRED_RESULT inline bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept { float f1 = static_cast<float>(p1); float f2 = static_cast<float>(p2); @@ -113,19 +119,19 @@ Q_REQUIRED_RESULT inline bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) Q_DECL_NOT return (qAbs(f1 - f2) * 102.5f <= qMin(qAbs(f1), qAbs(f2))); } -Q_REQUIRED_RESULT inline bool qIsNull(qfloat16 f) Q_DECL_NOTHROW +Q_REQUIRED_RESULT inline bool qIsNull(qfloat16 f) noexcept { return (f.b16 & static_cast<quint16>(0x7fff)) == 0; } -inline int qIntCast(qfloat16 f) Q_DECL_NOTHROW +inline int qIntCast(qfloat16 f) noexcept { return int(static_cast<float>(f)); } #ifndef Q_QDOC QT_WARNING_PUSH QT_WARNING_DISABLE_CLANG("-Wc99-extensions") QT_WARNING_DISABLE_GCC("-Wold-style-cast") -inline qfloat16::qfloat16(float f) Q_DECL_NOTHROW +inline qfloat16::qfloat16(float f) noexcept { #if defined(QT_COMPILER_SUPPORTS_F16C) && defined(__F16C__) __m128 packsingle = _mm_set_ss(f); @@ -143,7 +149,7 @@ inline qfloat16::qfloat16(float f) Q_DECL_NOTHROW } QT_WARNING_POP -inline qfloat16::operator float() const Q_DECL_NOTHROW +inline qfloat16::operator float() const noexcept { #if defined(QT_COMPILER_SUPPORTS_F16C) && defined(__F16C__) __m128i packhalf = _mm_cvtsi32_si128(b16); @@ -163,23 +169,23 @@ inline qfloat16::operator float() const Q_DECL_NOTHROW } #endif -inline qfloat16 operator-(qfloat16 a) Q_DECL_NOTHROW +inline qfloat16 operator-(qfloat16 a) noexcept { qfloat16 f; f.b16 = a.b16 ^ quint16(0x8000); return f; } -inline qfloat16 operator+(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return qfloat16(static_cast<float>(a) + static_cast<float>(b)); } -inline qfloat16 operator-(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return qfloat16(static_cast<float>(a) - static_cast<float>(b)); } -inline qfloat16 operator*(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return qfloat16(static_cast<float>(a) * static_cast<float>(b)); } -inline qfloat16 operator/(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return qfloat16(static_cast<float>(a) / static_cast<float>(b)); } +inline qfloat16 operator+(qfloat16 a, qfloat16 b) noexcept { return qfloat16(static_cast<float>(a) + static_cast<float>(b)); } +inline qfloat16 operator-(qfloat16 a, qfloat16 b) noexcept { return qfloat16(static_cast<float>(a) - static_cast<float>(b)); } +inline qfloat16 operator*(qfloat16 a, qfloat16 b) noexcept { return qfloat16(static_cast<float>(a) * static_cast<float>(b)); } +inline qfloat16 operator/(qfloat16 a, qfloat16 b) noexcept { return qfloat16(static_cast<float>(a) / static_cast<float>(b)); } #define QF16_MAKE_ARITH_OP_FP(FP, OP) \ - inline FP operator OP(qfloat16 lhs, FP rhs) Q_DECL_NOTHROW { return static_cast<FP>(lhs) OP rhs; } \ - inline FP operator OP(FP lhs, qfloat16 rhs) Q_DECL_NOTHROW { return lhs OP static_cast<FP>(rhs); } + inline FP operator OP(qfloat16 lhs, FP rhs) noexcept { return static_cast<FP>(lhs) OP rhs; } \ + inline FP operator OP(FP lhs, qfloat16 rhs) noexcept { return lhs OP static_cast<FP>(rhs); } #define QF16_MAKE_ARITH_OP_EQ_FP(FP, OP_EQ, OP) \ - inline qfloat16& operator OP_EQ(qfloat16& lhs, FP rhs) Q_DECL_NOTHROW \ + inline qfloat16& operator OP_EQ(qfloat16& lhs, FP rhs) noexcept \ { lhs = qfloat16(float(static_cast<FP>(lhs) OP rhs)); return lhs; } #define QF16_MAKE_ARITH_OP(FP) \ QF16_MAKE_ARITH_OP_FP(FP, +) \ @@ -197,8 +203,8 @@ QF16_MAKE_ARITH_OP(float) #undef QF16_MAKE_ARITH_OP_FP #define QF16_MAKE_ARITH_OP_INT(OP) \ - inline double operator OP(qfloat16 lhs, int rhs) Q_DECL_NOTHROW { return static_cast<double>(lhs) OP rhs; } \ - inline double operator OP(int lhs, qfloat16 rhs) Q_DECL_NOTHROW { return lhs OP static_cast<double>(rhs); } + inline double operator OP(qfloat16 lhs, int rhs) noexcept { return static_cast<double>(lhs) OP rhs; } \ + inline double operator OP(int lhs, qfloat16 rhs) noexcept { return lhs OP static_cast<double>(rhs); } QF16_MAKE_ARITH_OP_INT(+) QF16_MAKE_ARITH_OP_INT(-) QF16_MAKE_ARITH_OP_INT(*) @@ -209,16 +215,16 @@ QT_WARNING_PUSH QT_WARNING_DISABLE_CLANG("-Wfloat-equal") QT_WARNING_DISABLE_GCC("-Wfloat-equal") -inline bool operator>(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return static_cast<float>(a) > static_cast<float>(b); } -inline bool operator<(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return static_cast<float>(a) < static_cast<float>(b); } -inline bool operator>=(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return static_cast<float>(a) >= static_cast<float>(b); } -inline bool operator<=(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return static_cast<float>(a) <= static_cast<float>(b); } -inline bool operator==(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return static_cast<float>(a) == static_cast<float>(b); } -inline bool operator!=(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return static_cast<float>(a) != static_cast<float>(b); } +inline bool operator>(qfloat16 a, qfloat16 b) noexcept { return static_cast<float>(a) > static_cast<float>(b); } +inline bool operator<(qfloat16 a, qfloat16 b) noexcept { return static_cast<float>(a) < static_cast<float>(b); } +inline bool operator>=(qfloat16 a, qfloat16 b) noexcept { return static_cast<float>(a) >= static_cast<float>(b); } +inline bool operator<=(qfloat16 a, qfloat16 b) noexcept { return static_cast<float>(a) <= static_cast<float>(b); } +inline bool operator==(qfloat16 a, qfloat16 b) noexcept { return static_cast<float>(a) == static_cast<float>(b); } +inline bool operator!=(qfloat16 a, qfloat16 b) noexcept { return static_cast<float>(a) != static_cast<float>(b); } #define QF16_MAKE_BOOL_OP_FP(FP, OP) \ - inline bool operator OP(qfloat16 lhs, FP rhs) Q_DECL_NOTHROW { return static_cast<FP>(lhs) OP rhs; } \ - inline bool operator OP(FP lhs, qfloat16 rhs) Q_DECL_NOTHROW { return lhs OP static_cast<FP>(rhs); } + inline bool operator OP(qfloat16 lhs, FP rhs) noexcept { return static_cast<FP>(lhs) OP rhs; } \ + inline bool operator OP(FP lhs, qfloat16 rhs) noexcept { return lhs OP static_cast<FP>(rhs); } #define QF16_MAKE_BOOL_OP(FP) \ QF16_MAKE_BOOL_OP_FP(FP, <) \ QF16_MAKE_BOOL_OP_FP(FP, >) \ @@ -233,8 +239,8 @@ QF16_MAKE_BOOL_OP(float) #undef QF16_MAKE_BOOL_OP_FP #define QF16_MAKE_BOOL_OP_INT(OP) \ - inline bool operator OP(qfloat16 a, int b) Q_DECL_NOTHROW { return static_cast<float>(a) OP b; } \ - inline bool operator OP(int a, qfloat16 b) Q_DECL_NOTHROW { return a OP static_cast<float>(b); } + inline bool operator OP(qfloat16 a, int b) noexcept { return static_cast<float>(a) OP b; } \ + inline bool operator OP(int a, qfloat16 b) noexcept { return a OP static_cast<float>(b); } QF16_MAKE_BOOL_OP_INT(>) QF16_MAKE_BOOL_OP_INT(<) QF16_MAKE_BOOL_OP_INT(>=) @@ -248,7 +254,7 @@ QT_WARNING_POP /*! \internal */ -Q_REQUIRED_RESULT inline bool qFuzzyIsNull(qfloat16 f) Q_DECL_NOTHROW +Q_REQUIRED_RESULT inline bool qFuzzyIsNull(qfloat16 f) noexcept { return qAbs(static_cast<float>(f)) <= 0.001f; } diff --git a/src/corelib/global/qfloat16_f16c.c b/src/corelib/global/qfloat16_f16c.c index a7eadc71b7..ba1e16f481 100644 --- a/src/corelib/global/qfloat16_f16c.c +++ b/src/corelib/global/qfloat16_f16c.c @@ -54,7 +54,7 @@ extern "C" { #endif QT_FUNCTION_TARGET(F16C) -void qFloatToFloat16_fast(quint16 *out, const float *in, qsizetype len) Q_DECL_NOTHROW +void qFloatToFloat16_fast(quint16 *out, const float *in, qsizetype len) Q_DECL_NOEXCEPT { qsizetype i = 0; int epilog_i; @@ -70,7 +70,7 @@ void qFloatToFloat16_fast(quint16 *out, const float *in, qsizetype len) Q_DECL_N } QT_FUNCTION_TARGET(F16C) -void qFloatFromFloat16_fast(float *out, const quint16 *in, qsizetype len) Q_DECL_NOTHROW +void qFloatFromFloat16_fast(float *out, const quint16 *in, qsizetype len) Q_DECL_NOEXCEPT { qsizetype i = 0; int epilog_i; diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 7879109930..d95064af27 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -1147,12 +1147,12 @@ Q_STATIC_ASSERT((std::is_same<qsizetype, qptrdiff>::value)); \sa QT_VERSION_STR, QLibraryInfo::version() */ -const char *qVersion() Q_DECL_NOTHROW +const char *qVersion() noexcept { return QT_VERSION_STR; } -bool qSharedBuild() Q_DECL_NOTHROW +bool qSharedBuild() noexcept { #ifdef QT_SHARED return true; @@ -3206,7 +3206,7 @@ QByteArray QSysInfo::bootUniqueId() The Q_CHECK_PTR macro calls this function if an allocation check fails. */ -void qt_check_pointer(const char *n, int l) Q_DECL_NOTHROW +void qt_check_pointer(const char *n, int l) noexcept { // make separate printing calls so that the first one may flush; // the second one could want to allocate memory (fputs prints a @@ -3233,7 +3233,7 @@ void qBadAlloc() Allows you to call std::terminate() without including <exception>. Called internally from QT_TERMINATE_ON_EXCEPTION */ -Q_NORETURN void qTerminate() Q_DECL_NOTHROW +Q_NORETURN void qTerminate() noexcept { std::terminate(); } @@ -3242,7 +3242,7 @@ Q_NORETURN void qTerminate() Q_DECL_NOTHROW /* The Q_ASSERT macro calls this function when the test fails. */ -void qt_assert(const char *assertion, const char *file, int line) Q_DECL_NOTHROW +void qt_assert(const char *assertion, const char *file, int line) noexcept { QMessageLogger(file, line, nullptr).fatal("ASSERT: \"%s\" in file %s, line %d", assertion, file, line); } @@ -3250,7 +3250,7 @@ void qt_assert(const char *assertion, const char *file, int line) Q_DECL_NOTHROW /* The Q_ASSERT_X macro calls this function when the test fails. */ -void qt_assert_x(const char *where, const char *what, const char *file, int line) Q_DECL_NOTHROW +void qt_assert_x(const char *where, const char *what, const char *file, int line) noexcept { QMessageLogger(file, line, nullptr).fatal("ASSERT failure in %s: \"%s\", file %s, line %d", where, what, file, line); } @@ -3457,7 +3457,7 @@ QString qEnvironmentVariable(const char *varName) \sa qgetenv(), qEnvironmentVariable(), qEnvironmentVariableIsSet() */ -bool qEnvironmentVariableIsEmpty(const char *varName) Q_DECL_NOEXCEPT +bool qEnvironmentVariableIsEmpty(const char *varName) noexcept { QMutexLocker locker(&environmentMutex); #ifdef Q_CC_MSVC @@ -3492,7 +3492,7 @@ bool qEnvironmentVariableIsEmpty(const char *varName) Q_DECL_NOEXCEPT \sa qgetenv(), qEnvironmentVariable(), qEnvironmentVariableIsSet() */ -int qEnvironmentVariableIntValue(const char *varName, bool *ok) Q_DECL_NOEXCEPT +int qEnvironmentVariableIntValue(const char *varName, bool *ok) noexcept { static const int NumBinaryDigitsPerOctalDigit = 3; static const int MaxDigitsForOctalInt = @@ -3561,7 +3561,7 @@ int qEnvironmentVariableIntValue(const char *varName, bool *ok) Q_DECL_NOEXCEPT \sa qgetenv(), qEnvironmentVariable(), qEnvironmentVariableIsEmpty() */ -bool qEnvironmentVariableIsSet(const char *varName) Q_DECL_NOEXCEPT +bool qEnvironmentVariableIsSet(const char *varName) noexcept { QMutexLocker locker(&environmentMutex); #ifdef Q_CC_MSVC diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 223ebbcabe..a0207b483d 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -411,7 +411,7 @@ typedef double qreal; #if !defined(QT_NAMESPACE) && defined(__cplusplus) && !defined(Q_QDOC) extern "C" #endif -Q_CORE_EXPORT Q_DECL_CONST_FUNCTION const char *qVersion(void) Q_DECL_NOTHROW; +Q_CORE_EXPORT Q_DECL_CONST_FUNCTION const char *qVersion(void) Q_DECL_NOEXCEPT; #if defined(__cplusplus) @@ -730,7 +730,7 @@ inline void qt_noop(void) {} # define QT_CATCH(A) catch (A) # define QT_THROW(A) throw A # define QT_RETHROW throw -Q_NORETURN Q_DECL_COLD_FUNCTION Q_CORE_EXPORT void qTerminate() Q_DECL_NOTHROW; +Q_NORETURN Q_DECL_COLD_FUNCTION Q_CORE_EXPORT void qTerminate() noexcept; # ifdef Q_COMPILER_NOEXCEPT # define QT_TERMINATE_ON_EXCEPTION(expr) do { expr; } while (false) # else @@ -738,7 +738,7 @@ Q_NORETURN Q_DECL_COLD_FUNCTION Q_CORE_EXPORT void qTerminate() Q_DECL_NOTHROW; # endif #endif -Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qSharedBuild() Q_DECL_NOTHROW; +Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qSharedBuild() noexcept; #ifndef Q_OUTOFLINE_TEMPLATE # define Q_OUTOFLINE_TEMPLATE @@ -781,7 +781,7 @@ Q_CORE_EXPORT QString qt_error_string(int errorCode = -1); Q_NORETURN #endif Q_DECL_COLD_FUNCTION -Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int line) Q_DECL_NOTHROW; +Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int line) noexcept; #if !defined(Q_ASSERT) # if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) @@ -799,7 +799,7 @@ Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int line) Q_NORETURN #endif Q_DECL_COLD_FUNCTION -Q_CORE_EXPORT void qt_assert_x(const char *where, const char *what, const char *file, int line) Q_DECL_NOTHROW; +Q_CORE_EXPORT void qt_assert_x(const char *where, const char *what, const char *file, int line) noexcept; #if !defined(Q_ASSERT_X) # if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) @@ -809,7 +809,7 @@ Q_CORE_EXPORT void qt_assert_x(const char *where, const char *what, const char * # endif #endif -Q_NORETURN Q_CORE_EXPORT void qt_check_pointer(const char *, int) Q_DECL_NOTHROW; +Q_NORETURN Q_CORE_EXPORT void qt_check_pointer(const char *, int) noexcept; Q_DECL_COLD_FUNCTION Q_CORE_EXPORT void qBadAlloc(); @@ -910,14 +910,14 @@ namespace SwapExceptionTester { // insulate users from the "using std::swap" bel using std::swap; // import std::swap template <typename T> void checkSwap(T &t) - Q_DECL_NOEXCEPT_EXPR(noexcept(swap(t, t))); + noexcept(noexcept(swap(t, t))); // declared, but not implemented (only to be used in unevaluated contexts (noexcept operator)) } } // namespace QtPrivate template <typename T> inline void qSwap(T &value1, T &value2) - Q_DECL_NOEXCEPT_EXPR(noexcept(QtPrivate::SwapExceptionTester::checkSwap(value1))) + noexcept(noexcept(QtPrivate::SwapExceptionTester::checkSwap(value1))) { using std::swap; swap(value1, value2); @@ -968,7 +968,7 @@ QT_WARNING_DISABLE_MSVC(4530) /* C++ exception handler used, but unwind semantic // this adds const to non-const objects (like std::as_const) template <typename T> -Q_DECL_CONSTEXPR typename std::add_const<T>::type &qAsConst(T &t) Q_DECL_NOTHROW { return t; } +Q_DECL_CONSTEXPR typename std::add_const<T>::type &qAsConst(T &t) noexcept { return t; } // prevent rvalue arguments: template <typename T> void qAsConst(const T &&) Q_DECL_EQ_DELETE; @@ -1130,11 +1130,11 @@ template <typename... Args> struct QNonConstOverload { template <typename R, typename T> - Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...)) const Q_DECL_NOTHROW -> decltype(ptr) + Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...)) const noexcept -> decltype(ptr) { return ptr; } template <typename R, typename T> - static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...)) Q_DECL_NOTHROW -> decltype(ptr) + static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...)) noexcept -> decltype(ptr) { return ptr; } }; @@ -1142,11 +1142,11 @@ template <typename... Args> struct QConstOverload { template <typename R, typename T> - Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...) const) const Q_DECL_NOTHROW -> decltype(ptr) + Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...) const) const noexcept -> decltype(ptr) { return ptr; } template <typename R, typename T> - static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...) const) Q_DECL_NOTHROW -> decltype(ptr) + static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...) const) noexcept -> decltype(ptr) { return ptr; } }; @@ -1159,11 +1159,11 @@ struct QOverload : QConstOverload<Args...>, QNonConstOverload<Args...> using QNonConstOverload<Args...>::operator(); template <typename R> - Q_DECL_CONSTEXPR auto operator()(R (*ptr)(Args...)) const Q_DECL_NOTHROW -> decltype(ptr) + Q_DECL_CONSTEXPR auto operator()(R (*ptr)(Args...)) const noexcept -> decltype(ptr) { return ptr; } template <typename R> - static Q_DECL_CONSTEXPR auto of(R (*ptr)(Args...)) Q_DECL_NOTHROW -> decltype(ptr) + static Q_DECL_CONSTEXPR auto of(R (*ptr)(Args...)) noexcept -> decltype(ptr) { return ptr; } }; @@ -1184,9 +1184,9 @@ Q_CORE_EXPORT QString qEnvironmentVariable(const char *varName, const QString &d Q_CORE_EXPORT bool qputenv(const char *varName, const QByteArray& value); Q_CORE_EXPORT bool qunsetenv(const char *varName); -Q_CORE_EXPORT bool qEnvironmentVariableIsEmpty(const char *varName) Q_DECL_NOEXCEPT; -Q_CORE_EXPORT bool qEnvironmentVariableIsSet(const char *varName) Q_DECL_NOEXCEPT; -Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) Q_DECL_NOEXCEPT; +Q_CORE_EXPORT bool qEnvironmentVariableIsEmpty(const char *varName) noexcept; +Q_CORE_EXPORT bool qEnvironmentVariableIsSet(const char *varName) noexcept; +Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept; inline int qIntCast(double f) { return int(f); } inline int qIntCast(float f) { return int(f); } diff --git a/src/corelib/global/qglobalstatic.h b/src/corelib/global/qglobalstatic.h index 555bdf04c1..4f89876793 100644 --- a/src/corelib/global/qglobalstatic.h +++ b/src/corelib/global/qglobalstatic.h @@ -79,14 +79,14 @@ enum GuardValues { Q_GLOBAL_STATIC_INTERNAL_DECORATION Type *innerFunction() \ { \ struct HolderBase { \ - ~HolderBase() Q_DECL_NOTHROW \ + ~HolderBase() noexcept \ { if (guard.load() == QtGlobalStatic::Initialized) \ guard.store(QtGlobalStatic::Destroyed); } \ }; \ static struct Holder : public HolderBase { \ Type value; \ Holder() \ - Q_DECL_NOEXCEPT_EXPR(noexcept(Type ARGS)) \ + noexcept(noexcept(Type ARGS)) \ : value ARGS \ { guard.store(QtGlobalStatic::Initialized); } \ } holder; \ @@ -131,8 +131,8 @@ struct QGlobalStatic bool isDestroyed() const { return guard.load() <= QtGlobalStatic::Destroyed; } bool exists() const { return guard.load() == QtGlobalStatic::Initialized; } - operator Type *() { if (isDestroyed()) return 0; return innerFunction(); } - Type *operator()() { if (isDestroyed()) return 0; return innerFunction(); } + operator Type *() { if (isDestroyed()) return nullptr; return innerFunction(); } + Type *operator()() { if (isDestroyed()) return nullptr; return innerFunction(); } Type *operator->() { Q_ASSERT_X(!isDestroyed(), "Q_GLOBAL_STATIC", "The global static was used after being destroyed"); diff --git a/src/corelib/global/qhooks.cpp b/src/corelib/global/qhooks.cpp index bbddb1cbf1..020dee3710 100644 --- a/src/corelib/global/qhooks.cpp +++ b/src/corelib/global/qhooks.cpp @@ -67,7 +67,7 @@ quintptr Q_CORE_EXPORT qtHookData[] = { // The required sizes and offsets are tested in tests/auto/other/toolsupport. // When this fails and the change was intentional, adjust the test and // adjust this value here. - 16 + 17 }; Q_STATIC_ASSERT(QHooks::LastHookIndex == sizeof(qtHookData) / sizeof(qtHookData[0])); diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index 4119012d85..c3eb469767 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -350,7 +350,7 @@ QLibraryInfo::buildDate() \since 5.3 */ -const char *QLibraryInfo::build() Q_DECL_NOTHROW +const char *QLibraryInfo::build() noexcept { return QT_BUILD_STR; } @@ -377,7 +377,7 @@ QLibraryInfo::isDebugBuild() \sa qVersion() */ -QVersionNumber QLibraryInfo::version() Q_DECL_NOTHROW +QVersionNumber QLibraryInfo::version() noexcept { return QVersionNumber(QT_VERSION_MAJOR, QT_VERSION_MINOR, QT_VERSION_PATCH); } @@ -717,11 +717,6 @@ void qt_core_boilerplate() QT_PREPEND_NAMESPACE(qDumpCPUFeatures)(); -#ifdef QT_EVAL - extern void qt_core_eval_init(QCoreApplicationPrivate::Type); - qt_core_eval_init(QCoreApplicationPrivate::Tty); -#endif - exit(0); } diff --git a/src/corelib/global/qlibraryinfo.h b/src/corelib/global/qlibraryinfo.h index 80fc5bd4fc..20fd3897f7 100644 --- a/src/corelib/global/qlibraryinfo.h +++ b/src/corelib/global/qlibraryinfo.h @@ -62,12 +62,12 @@ public: #endif // QT_DEPRECATED_SINCE(5, 5) #endif // datestring - static const char * build() Q_DECL_NOTHROW; + static const char * build() noexcept; static bool isDebugBuild(); #ifndef QT_BOOTSTRAPPED - static QVersionNumber version() Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; + static QVersionNumber version() noexcept Q_DECL_CONST_FUNCTION; #endif enum LibraryLocation diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index ece97077c1..4941ca45aa 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -347,7 +347,7 @@ using namespace QtPrivate; */ #if defined(Q_CC_MSVC) && defined(QT_DEBUG) && defined(_DEBUG) && defined(_CRT_ERROR) -static inline void convert_to_wchar_t_elided(wchar_t *d, size_t space, const char *s) Q_DECL_NOEXCEPT +static inline void convert_to_wchar_t_elided(wchar_t *d, size_t space, const char *s) noexcept { size_t len = qstrlen(s); if (len + 1 > space) { @@ -530,7 +530,7 @@ QDebug QMessageLogger::debug(QMessageLogger::CategoryFunction catFunc) const \sa QNoDebug, qDebug() */ -QNoDebug QMessageLogger::noDebug() const Q_DECL_NOTHROW +QNoDebug QMessageLogger::noDebug() const noexcept { return QNoDebug(); } @@ -876,7 +876,7 @@ QDebug QMessageLogger::critical(QMessageLogger::CategoryFunction catFunc) const \sa qFatal() */ -void QMessageLogger::fatal(const char *msg, ...) const Q_DECL_NOTHROW +void QMessageLogger::fatal(const char *msg, ...) const noexcept { QString message; diff --git a/src/corelib/global/qlogging.h b/src/corelib/global/qlogging.h index dded09999b..8f39780112 100644 --- a/src/corelib/global/qlogging.h +++ b/src/corelib/global/qlogging.h @@ -121,7 +121,7 @@ public: Q_NORETURN #endif Q_DECL_COLD_FUNCTION - void fatal(const char *msg, ...) const Q_DECL_NOTHROW Q_ATTRIBUTE_FORMAT_PRINTF(2, 3); + void fatal(const char *msg, ...) const noexcept Q_ATTRIBUTE_FORMAT_PRINTF(2, 3); #ifndef QT_NO_DEBUG_STREAM QDebug debug() const; @@ -137,7 +137,7 @@ public: QDebug critical(const QLoggingCategory &cat) const; QDebug critical(CategoryFunction catFunc) const; - QNoDebug noDebug() const Q_DECL_NOTHROW; + QNoDebug noDebug() const noexcept; #endif // QT_NO_DEBUG_STREAM private: diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index 6488426e64..06aef81afc 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -50,10 +50,10 @@ QT_BEGIN_NAMESPACE #if !defined(Q_QDOC) && !defined(Q_MOC_RUN) struct QMetaObject; -const QMetaObject *qt_getQtMetaObject() Q_DECL_NOEXCEPT; // defined in qobject.h (which can't be included here) +const QMetaObject *qt_getQtMetaObject() noexcept; // defined in qobject.h (which can't be included here) #define QT_Q_ENUM(ENUM) \ - inline const QMetaObject *qt_getEnumMetaObject(ENUM) Q_DECL_NOEXCEPT { return qt_getQtMetaObject(); } \ - inline Q_DECL_CONSTEXPR const char *qt_getEnumName(ENUM) Q_DECL_NOEXCEPT { return #ENUM; } + inline const QMetaObject *qt_getEnumMetaObject(ENUM) noexcept { return qt_getQtMetaObject(); } \ + inline Q_DECL_CONSTEXPR const char *qt_getEnumName(ENUM) noexcept { return #ENUM; } #define QT_Q_FLAG(ENUM) QT_Q_ENUM(ENUM) #else #define QT_Q_ENUM Q_ENUM @@ -1198,7 +1198,8 @@ public: enum TextFormat { PlainText, RichText, - AutoText + AutoText, + MarkdownText }; enum AspectRatioMode { @@ -1614,7 +1615,7 @@ public: TitleBarArea // For move }; -#if defined(Q_COMPILER_CLASS_ENUM) && defined(Q_COMPILER_CONSTEXPR) +#if defined(Q_COMPILER_CONSTEXPR) enum class Initialization { Uninitialized }; diff --git a/src/corelib/global/qnumeric.cpp b/src/corelib/global/qnumeric.cpp index fc2b052edf..e6ba62f530 100644 --- a/src/corelib/global/qnumeric.cpp +++ b/src/corelib/global/qnumeric.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -46,6 +46,7 @@ QT_BEGIN_NAMESPACE /*! Returns \c true if the double \a {d} is equivalent to infinity. \relates <QtGlobal> + \sa qInf() */ Q_CORE_EXPORT bool qIsInf(double d) { return qt_is_inf(d); } @@ -64,6 +65,7 @@ Q_CORE_EXPORT bool qIsFinite(double d) { return qt_is_finite(d); } /*! Returns \c true if the float \a {f} is equivalent to infinity. \relates <QtGlobal> + \sa qInf() */ Q_CORE_EXPORT bool qIsInf(float f) { return qt_is_inf(f); } @@ -88,15 +90,36 @@ Q_CORE_EXPORT double qSNaN() { return qt_snan(); } /*! Returns the bit pattern of a quiet NaN as a double. \relates <QtGlobal> + \sa qIsNaN() */ Q_CORE_EXPORT double qQNaN() { return qt_qnan(); } /*! Returns the bit pattern for an infinite number as a double. \relates <QtGlobal> + \sa qIsInf() */ Q_CORE_EXPORT double qInf() { return qt_inf(); } +/*! + \relates <QtGlobal> + Classifies a floating-point value. + + The return values are defined in \c{<cmath>}: returns one of the following, + determined by the floating-point class of \a val: + \list + \li FP_NAN not a number + \li FP_INFINITE infinities (positive or negative) + \li FP_NORMAL finite with a full mantissa + \li FP_SUBNORMAL finite with a reduced mantissa + \endlist +*/ +Q_CORE_EXPORT int qFpClassify(double val) { return qt_fpclassify(val); } + +/*! + \overload +*/ +Q_CORE_EXPORT int qFpClassify(float val) { return qt_fpclassify(val); } /*! diff --git a/src/corelib/global/qnumeric.h b/src/corelib/global/qnumeric.h index 535a96aaec..6a0c64712f 100644 --- a/src/corelib/global/qnumeric.h +++ b/src/corelib/global/qnumeric.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -48,9 +48,11 @@ QT_BEGIN_NAMESPACE Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsInf(double d); Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsNaN(double d); Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsFinite(double d); +Q_CORE_EXPORT Q_DECL_CONST_FUNCTION int qFpClassify(double val); Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsInf(float f); Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsNaN(float f); Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsFinite(float f); +Q_CORE_EXPORT Q_DECL_CONST_FUNCTION int qFpClassify(float val); Q_CORE_EXPORT Q_DECL_CONST_FUNCTION double qSNaN(); Q_CORE_EXPORT Q_DECL_CONST_FUNCTION double qQNaN(); Q_CORE_EXPORT Q_DECL_CONST_FUNCTION double qInf(); diff --git a/src/corelib/global/qnumeric_p.h b/src/corelib/global/qnumeric_p.h index 4a225b2599..21f9cfbef0 100644 --- a/src/corelib/global/qnumeric_p.h +++ b/src/corelib/global/qnumeric_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Copyright (C) 2018 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** @@ -85,9 +85,11 @@ namespace qnumeric_std_wrapper { Q_DECL_CONST_FUNCTION static inline bool math_h_isnan(double d) { using namespace std; return isnan(d); } Q_DECL_CONST_FUNCTION static inline bool math_h_isinf(double d) { using namespace std; return isinf(d); } Q_DECL_CONST_FUNCTION static inline bool math_h_isfinite(double d) { using namespace std; return isfinite(d); } +Q_DECL_CONST_FUNCTION static inline int math_h_fpclassify(double d) { using namespace std; return fpclassify(d); } Q_DECL_CONST_FUNCTION static inline bool math_h_isnan(float f) { using namespace std; return isnan(f); } Q_DECL_CONST_FUNCTION static inline bool math_h_isinf(float f) { using namespace std; return isinf(f); } Q_DECL_CONST_FUNCTION static inline bool math_h_isfinite(float f) { using namespace std; return isfinite(f); } +Q_DECL_CONST_FUNCTION static inline int math_h_fpclassify(float f) { using namespace std; return fpclassify(f); } } QT_END_NAMESPACE // These macros from math.h conflict with the real functions in the std namespace. @@ -95,6 +97,7 @@ QT_END_NAMESPACE # undef isnan # undef isinf # undef isfinite +# undef fpclassify # endif // defined(isnan) #endif @@ -106,20 +109,24 @@ namespace qnumeric_std_wrapper { Q_DECL_CONST_FUNCTION static inline bool isnan(double d) { return math_h_isnan(d); } Q_DECL_CONST_FUNCTION static inline bool isinf(double d) { return math_h_isinf(d); } Q_DECL_CONST_FUNCTION static inline bool isfinite(double d) { return math_h_isfinite(d); } +Q_DECL_CONST_FUNCTION static inline int fpclassify(double d) { return math_h_fpclassify(d); } Q_DECL_CONST_FUNCTION static inline bool isnan(float f) { return math_h_isnan(f); } Q_DECL_CONST_FUNCTION static inline bool isinf(float f) { return math_h_isinf(f); } Q_DECL_CONST_FUNCTION static inline bool isfinite(float f) { return math_h_isfinite(f); } +Q_DECL_CONST_FUNCTION static inline int fpclassify(float f) { return math_h_fpclassify(f); } #else Q_DECL_CONST_FUNCTION static inline bool isnan(double d) { return std::isnan(d); } Q_DECL_CONST_FUNCTION static inline bool isinf(double d) { return std::isinf(d); } Q_DECL_CONST_FUNCTION static inline bool isfinite(double d) { return std::isfinite(d); } +Q_DECL_CONST_FUNCTION static inline int fpclassify(double d) { return std::fpclassify(d); } Q_DECL_CONST_FUNCTION static inline bool isnan(float f) { return std::isnan(f); } Q_DECL_CONST_FUNCTION static inline bool isinf(float f) { return std::isinf(f); } Q_DECL_CONST_FUNCTION static inline bool isfinite(float f) { return std::isfinite(f); } +Q_DECL_CONST_FUNCTION static inline int fpclassify(float f) { return std::fpclassify(f); } #endif } -Q_DECL_CONSTEXPR Q_DECL_CONST_FUNCTION static inline double qt_inf() Q_DECL_NOEXCEPT +Q_DECL_CONSTEXPR Q_DECL_CONST_FUNCTION static inline double qt_inf() noexcept { Q_STATIC_ASSERT_X(std::numeric_limits<double>::has_infinity, "platform has no definition for infinity for type double"); @@ -127,7 +134,7 @@ Q_DECL_CONSTEXPR Q_DECL_CONST_FUNCTION static inline double qt_inf() Q_DECL_NOEX } // Signaling NaN -Q_DECL_CONSTEXPR Q_DECL_CONST_FUNCTION static inline double qt_snan() Q_DECL_NOEXCEPT +Q_DECL_CONSTEXPR Q_DECL_CONST_FUNCTION static inline double qt_snan() noexcept { Q_STATIC_ASSERT_X(std::numeric_limits<double>::has_signaling_NaN, "platform has no definition for signaling NaN for type double"); @@ -135,7 +142,7 @@ Q_DECL_CONSTEXPR Q_DECL_CONST_FUNCTION static inline double qt_snan() Q_DECL_NOE } // Quiet NaN -Q_DECL_CONSTEXPR Q_DECL_CONST_FUNCTION static inline double qt_qnan() Q_DECL_NOEXCEPT +Q_DECL_CONSTEXPR Q_DECL_CONST_FUNCTION static inline double qt_qnan() noexcept { Q_STATIC_ASSERT_X(std::numeric_limits<double>::has_quiet_NaN, "platform has no definition for quiet NaN for type double"); @@ -157,6 +164,11 @@ Q_DECL_CONST_FUNCTION static inline bool qt_is_finite(double d) return qnumeric_std_wrapper::isfinite(d); } +Q_DECL_CONST_FUNCTION static inline int qt_fpclassify(double d) +{ + return qnumeric_std_wrapper::fpclassify(d); +} + Q_DECL_CONST_FUNCTION static inline bool qt_is_inf(float f) { return qnumeric_std_wrapper::isinf(f); @@ -172,6 +184,11 @@ Q_DECL_CONST_FUNCTION static inline bool qt_is_finite(float f) return qnumeric_std_wrapper::isfinite(f); } +Q_DECL_CONST_FUNCTION static inline int qt_fpclassify(float f) +{ + return qnumeric_std_wrapper::fpclassify(f); +} + #ifndef Q_CLANG_QDOC namespace { /*! diff --git a/src/corelib/global/qrandom.cpp b/src/corelib/global/qrandom.cpp index 90df8653a7..2ee8f0dd01 100644 --- a/src/corelib/global/qrandom.cpp +++ b/src/corelib/global/qrandom.cpp @@ -91,7 +91,7 @@ DECLSPEC_IMPORT BOOLEAN WINAPI SystemFunction036(PVOID RandomBuffer, ULONG Rando QT_BEGIN_NAMESPACE #if defined(Q_PROCESSOR_X86) && QT_COMPILER_SUPPORTS_HERE(RDRND) -static qsizetype qt_random_cpu(void *buffer, qsizetype count) Q_DECL_NOTHROW; +static qsizetype qt_random_cpu(void *buffer, qsizetype count) noexcept; # ifdef Q_PROCESSOR_X86_64 # define _rdrandXX_step _rdrand64_step @@ -99,7 +99,7 @@ static qsizetype qt_random_cpu(void *buffer, qsizetype count) Q_DECL_NOTHROW; # define _rdrandXX_step _rdrand32_step # endif -static QT_FUNCTION_TARGET(RDRND) qsizetype qt_random_cpu(void *buffer, qsizetype count) Q_DECL_NOTHROW +static QT_FUNCTION_TARGET(RDRND) qsizetype qt_random_cpu(void *buffer, qsizetype count) noexcept { unsigned *ptr = reinterpret_cast<unsigned *>(buffer); unsigned *end = ptr + count; @@ -134,7 +134,7 @@ enum { struct QRandomGenerator::SystemGenerator { #if QT_CONFIG(getentropy) - static qsizetype fillBuffer(void *buffer, qsizetype count) Q_DECL_NOTHROW + static qsizetype fillBuffer(void *buffer, qsizetype count) noexcept { // getentropy can read at most 256 bytes, so break the reading qsizetype read = 0; @@ -204,13 +204,13 @@ struct QRandomGenerator::SystemGenerator } #elif defined(Q_OS_WIN) && !defined(Q_OS_WINRT) - qsizetype fillBuffer(void *buffer, qsizetype count) Q_DECL_NOTHROW + qsizetype fillBuffer(void *buffer, qsizetype count) noexcept { auto RtlGenRandom = SystemFunction036; return RtlGenRandom(buffer, ULONG(count)) ? count: 0; } #elif defined(Q_OS_WINRT) - qsizetype fillBuffer(void *, qsizetype) Q_DECL_NOTHROW + qsizetype fillBuffer(void *, qsizetype) noexcept { // always use the fallback return 0; @@ -219,7 +219,7 @@ struct QRandomGenerator::SystemGenerator static SystemGenerator &self(); typedef quint32 result_type; - void generate(quint32 *begin, quint32 *end) Q_DECL_NOEXCEPT_EXPR(FillBufferNoexcept); + void generate(quint32 *begin, quint32 *end) noexcept(FillBufferNoexcept); // For std::mersenne_twister_engine implementations that use something // other than quint32 (unsigned int) to fill their buffers. @@ -242,7 +242,7 @@ struct QRandomGenerator::SystemGenerator #if defined(Q_OS_WIN) static void fallback_update_seed(unsigned) {} -static void fallback_fill(quint32 *ptr, qsizetype left) Q_DECL_NOTHROW +static void fallback_fill(quint32 *ptr, qsizetype left) noexcept { // on Windows, rand_s is a high-quality random number generator // and it requires no seeding @@ -254,14 +254,14 @@ static void fallback_fill(quint32 *ptr, qsizetype left) Q_DECL_NOTHROW } #elif QT_CONFIG(getentropy) static void fallback_update_seed(unsigned) {} -static void fallback_fill(quint32 *, qsizetype) Q_DECL_NOTHROW +static void fallback_fill(quint32 *, qsizetype) noexcept { // no fallback necessary, getentropy cannot fail under normal circumstances Q_UNREACHABLE(); } #elif defined(Q_OS_BSD4) && !defined(__GLIBC__) static void fallback_update_seed(unsigned) {} -static void fallback_fill(quint32 *ptr, qsizetype left) Q_DECL_NOTHROW +static void fallback_fill(quint32 *ptr, qsizetype left) noexcept { // BSDs have arc4random(4) and these work even in chroot(2) arc4random_buf(ptr, left * sizeof(*ptr)); @@ -280,7 +280,7 @@ Q_NEVER_INLINE #ifdef Q_CC_GNU __attribute__((cold)) // this function is pretty big, so optimize for size #endif -static void fallback_fill(quint32 *ptr, qsizetype left) Q_DECL_NOTHROW +static void fallback_fill(quint32 *ptr, qsizetype left) noexcept { quint32 scratch[12]; // see element count below quint32 *end = scratch; @@ -354,7 +354,7 @@ static void fallback_fill(quint32 *ptr, qsizetype left) Q_DECL_NOTHROW #endif Q_NEVER_INLINE void QRandomGenerator::SystemGenerator::generate(quint32 *begin, quint32 *end) - Q_DECL_NOEXCEPT_EXPR(FillBufferNoexcept) + noexcept(FillBufferNoexcept) { quint32 *buffer = begin; qsizetype count = end - begin; @@ -1167,7 +1167,7 @@ QRandomGenerator &QRandomGenerator::operator=(const QRandomGenerator &other) return *this; } -QRandomGenerator::QRandomGenerator(std::seed_seq &sseq) Q_DECL_NOTHROW +QRandomGenerator::QRandomGenerator(std::seed_seq &sseq) noexcept : type(MersenneTwister) { Q_ASSERT(this != system()); diff --git a/src/corelib/global/qrandom.h b/src/corelib/global/qrandom.h index 46d3e0e152..2f72528266 100644 --- a/src/corelib/global/qrandom.h +++ b/src/corelib/global/qrandom.h @@ -68,7 +68,7 @@ public: QRandomGenerator(const quint32 *seedBuffer, qsizetype len) : QRandomGenerator(seedBuffer, seedBuffer + len) {} - Q_CORE_EXPORT QRandomGenerator(std::seed_seq &sseq) Q_DECL_NOTHROW; + Q_CORE_EXPORT QRandomGenerator(std::seed_seq &sseq) noexcept; Q_CORE_EXPORT QRandomGenerator(const quint32 *begin, const quint32 *end); // copy constructor & assignment operator (move unnecessary) @@ -165,7 +165,7 @@ public: typedef quint32 result_type; result_type operator()() { return generate(); } void seed(quint32 s = 1) { *this = { s }; } - void seed(std::seed_seq &sseq) Q_DECL_NOTHROW { *this = { sseq }; } + void seed(std::seed_seq &sseq) noexcept { *this = { sseq }; } Q_CORE_EXPORT void discard(unsigned long long z); static Q_DECL_CONSTEXPR result_type min() { return std::numeric_limits<result_type>::min(); } static Q_DECL_CONSTEXPR result_type max() { return std::numeric_limits<result_type>::max(); } @@ -228,7 +228,7 @@ public: QRandomGenerator64(const quint32 *seedBuffer, qsizetype len) : QRandomGenerator(seedBuffer, len) {} - QRandomGenerator64(std::seed_seq &sseq) Q_DECL_NOTHROW + QRandomGenerator64(std::seed_seq &sseq) noexcept : QRandomGenerator(sseq) {} QRandomGenerator64(const quint32 *begin, const quint32 *end) diff --git a/src/corelib/global/qtrace_p.h b/src/corelib/global/qtrace_p.h index 20f2beac98..b72fdd886d 100644 --- a/src/corelib/global/qtrace_p.h +++ b/src/corelib/global/qtrace_p.h @@ -122,6 +122,7 @@ QT_BEGIN_NAMESPACE #if defined(Q_TRACEPOINT) && !defined(QT_BOOTSTRAPPED) +# define Q_HAS_TRACEPOINTS 1 # define Q_TRACE(x, ...) QtPrivate::trace_ ## x(__VA_ARGS__) # define Q_TRACE_EXIT(x, ...) \ const auto qTraceExit_ ## x ## __COUNTER__ = qScopeGuard([&]() { Q_TRACE(x, __VA_ARGS__); }); @@ -131,6 +132,7 @@ QT_BEGIN_NAMESPACE # define Q_UNCONDITIONAL_TRACE(x, ...) QtPrivate::do_trace_ ## x(__VA_ARGS__) # define Q_TRACE_ENABLED(x) QtPrivate::trace_ ## x ## _enabled() #else +# define Q_HAS_TRACEPOINTS 0 # define Q_TRACE(x, ...) # define Q_TRACE_EXIT(x, ...) # define Q_TRACE_SCOPE(x, ...) diff --git a/src/corelib/global/qtypeinfo.h b/src/corelib/global/qtypeinfo.h index 567ff5c08e..636dc24c07 100644 --- a/src/corelib/global/qtypeinfo.h +++ b/src/corelib/global/qtypeinfo.h @@ -308,7 +308,7 @@ Q_DECLARE_TYPEINFO_BODY(QFlags<T>, Q_PRIMITIVE_TYPE); #define Q_DECLARE_SHARED_IMPL(TYPE, FLAGS) \ Q_DECLARE_TYPEINFO(TYPE, FLAGS); \ inline void swap(TYPE &value1, TYPE &value2) \ - Q_DECL_NOEXCEPT_EXPR(noexcept(value1.swap(value2))) \ + noexcept(noexcept(value1.swap(value2))) \ { value1.swap(value2); } #define Q_DECLARE_SHARED(TYPE) Q_DECLARE_SHARED_IMPL(TYPE, Q_MOVABLE_TYPE) #define Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(TYPE) \ diff --git a/src/corelib/io/qabstractfileengine_p.h b/src/corelib/io/qabstractfileengine_p.h index 4a7fe7bff5..c88b66c7ce 100644 --- a/src/corelib/io/qabstractfileengine_p.h +++ b/src/corelib/io/qabstractfileengine_p.h @@ -193,7 +193,7 @@ public: uchar *address; }; - virtual bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0); + virtual bool extension(Extension extension, const ExtensionOption *option = nullptr, ExtensionReturn *output = nullptr); virtual bool supportsExtension(Extension extension) const; // Factory diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index 91fde75fa5..f9dc4203db 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -116,7 +116,7 @@ public: inline QDebug(const QDebug &o):stream(o.stream) { ++stream->ref; } inline QDebug &operator=(const QDebug &other); ~QDebug(); - inline void swap(QDebug &other) Q_DECL_NOTHROW { qSwap(stream, other.stream); } + inline void swap(QDebug &other) noexcept { qSwap(stream, other.stream); } QDebug &resetFormat(); @@ -161,9 +161,7 @@ public: inline QDebug &operator<<(QLatin1String t) { putByteArray(t.latin1(), t.size(), ContainsLatin1); return maybeSpace(); } inline QDebug &operator<<(const QByteArray & t) { putByteArray(t.constData(), t.size(), ContainsBinary); return maybeSpace(); } inline QDebug &operator<<(const void * t) { stream->ts << t; return maybeSpace(); } -#ifdef Q_COMPILER_NULLPTR inline QDebug &operator<<(std::nullptr_t) { stream->ts << "(nullptr)"; return maybeSpace(); } -#endif inline QDebug &operator<<(QTextStreamFunction f) { stream->ts << f; return *this; diff --git a/src/corelib/io/qdir.h b/src/corelib/io/qdir.h index 9abb833ab1..45a40995f8 100644 --- a/src/corelib/io/qdir.h +++ b/src/corelib/io/qdir.h @@ -109,11 +109,9 @@ public: QT_DEPRECATED_X("Use QDir::setPath() instead") QDir &operator=(const QString &path); #endif -#ifdef Q_COMPILER_RVALUE_REFS - QDir &operator=(QDir &&other) Q_DECL_NOTHROW { swap(other); return *this; } -#endif + QDir &operator=(QDir &&other) noexcept { swap(other); return *this; } - void swap(QDir &other) Q_DECL_NOTHROW + void swap(QDir &other) noexcept { qSwap(d_ptr, other.d_ptr); } void setPath(const QString &path); @@ -190,7 +188,7 @@ public: static QFileInfoList drives(); - Q_DECL_CONSTEXPR static inline QChar listSeparator() Q_DECL_NOTHROW + Q_DECL_CONSTEXPR static inline QChar listSeparator() noexcept { #if defined(Q_OS_WIN) return QLatin1Char(';'); diff --git a/src/corelib/io/qdiriterator.cpp b/src/corelib/io/qdiriterator.cpp index 648593b020..69d61bf5a8 100644 --- a/src/corelib/io/qdiriterator.cpp +++ b/src/corelib/io/qdiriterator.cpp @@ -93,6 +93,7 @@ #include "qdir_p.h" #include "qabstractfileengine_p.h" +#include <QtCore/qregexp.h> #include <QtCore/qset.h> #include <QtCore/qstack.h> #include <QtCore/qvariant.h> diff --git a/src/corelib/io/qfileinfo.h b/src/corelib/io/qfileinfo.h index baea18fab1..111517325d 100644 --- a/src/corelib/io/qfileinfo.h +++ b/src/corelib/io/qfileinfo.h @@ -67,11 +67,9 @@ public: ~QFileInfo(); QFileInfo &operator=(const QFileInfo &fileinfo); -#ifdef Q_COMPILER_RVALUE_REFS - QFileInfo &operator=(QFileInfo &&other) Q_DECL_NOTHROW { swap(other); return *this; } -#endif + QFileInfo &operator=(QFileInfo &&other) noexcept { swap(other); return *this; } - void swap(QFileInfo &other) Q_DECL_NOTHROW + void swap(QFileInfo &other) noexcept { qSwap(d_ptr, other.d_ptr); } bool operator==(const QFileInfo &fileinfo) const; diff --git a/src/corelib/io/qfileinfo_p.h b/src/corelib/io/qfileinfo_p.h index e4b28f4519..36f440812f 100644 --- a/src/corelib/io/qfileinfo_p.h +++ b/src/corelib/io/qfileinfo_p.h @@ -80,7 +80,7 @@ public: }; inline QFileInfoPrivate() - : QSharedData(), fileEngine(0), + : QSharedData(), fileEngine(nullptr), cachedFlags(0), isDefaultConstructed(true), cache_enabled(true), fileFlags(0), fileSize(0) diff --git a/src/corelib/io/qfilesystemengine_p.h b/src/corelib/io/qfilesystemengine_p.h index 09ec2d6a10..e44837747c 100644 --- a/src/corelib/io/qfilesystemengine_p.h +++ b/src/corelib/io/qfilesystemengine_p.h @@ -130,7 +130,7 @@ public: static bool removeFile(const QFileSystemEntry &entry, QSystemError &error); static bool setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QSystemError &error, - QFileSystemMetaData *data = 0); + QFileSystemMetaData *data = nullptr); // unused, therefore not implemented static bool setFileTime(const QFileSystemEntry &entry, const QDateTime &newDate, diff --git a/src/corelib/io/qfilesystemmetadata_p.h b/src/corelib/io/qfilesystemmetadata_p.h index 4d2a5acb9b..81f4b3ba13 100644 --- a/src/corelib/io/qfilesystemmetadata_p.h +++ b/src/corelib/io/qfilesystemmetadata_p.h @@ -76,7 +76,7 @@ class Q_AUTOTEST_EXPORT QFileSystemMetaData { public: QFileSystemMetaData() - : knownFlagsMask(0), + : knownFlagsMask(nullptr), size_(-1) { } @@ -184,7 +184,7 @@ public: void clear() { - knownFlagsMask = 0; + knownFlagsMask = nullptr; } void clearFlags(MetaDataFlags flags = AllMetaDataFlags) diff --git a/src/corelib/io/qfilesystemwatcher_fsevents.mm b/src/corelib/io/qfilesystemwatcher_fsevents.mm index f594fad803..fb3b6f86fd 100644 --- a/src/corelib/io/qfilesystemwatcher_fsevents.mm +++ b/src/corelib/io/qfilesystemwatcher_fsevents.mm @@ -407,7 +407,7 @@ QStringList QFseventsFileSystemWatcherEngine::addPaths(const QStringList &paths, stopStream(); if (!startStream()) { // ok, something went wrong, let's try to restore the previous state - watchingState = qMove(oldState); + watchingState = std::move(oldState); // and because we don't know which path caused the issue (if any), fail on all of them p = paths; @@ -474,7 +474,7 @@ QStringList QFseventsFileSystemWatcherEngine::removePaths(const QStringList &pat if (needsRestart) { if (!restartStream()) { - watchingState = qMove(oldState); + watchingState = std::move(oldState); startStream(); } } diff --git a/src/corelib/io/qfilesystemwatcher_win.cpp b/src/corelib/io/qfilesystemwatcher_win.cpp index 66985f8982..7f4f9d345b 100644 --- a/src/corelib/io/qfilesystemwatcher_win.cpp +++ b/src/corelib/io/qfilesystemwatcher_win.cpp @@ -108,7 +108,11 @@ public: // Call from QFileSystemWatcher::addPaths() to set up notifications on drives void addPath(const QString &path); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + bool nativeEventFilter(const QByteArray &, void *messageIn, qintptr *) override; +#else bool nativeEventFilter(const QByteArray &, void *messageIn, long *) override; +#endif signals: void driveAdded(); @@ -255,7 +259,11 @@ inline void QWindowsRemovableDriveListener::handleDbtDriveArrivalRemoval(const M } } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +bool QWindowsRemovableDriveListener::nativeEventFilter(const QByteArray &, void *messageIn, qintptr *) +#else bool QWindowsRemovableDriveListener::nativeEventFilter(const QByteArray &, void *messageIn, long *) +#endif { const MSG *msg = reinterpret_cast<const MSG *>(messageIn); if (msg->message == WM_DEVICECHANGE) { diff --git a/src/corelib/io/qfsfileengine_p.h b/src/corelib/io/qfsfileengine_p.h index 6b091a8eef..0f416f4886 100644 --- a/src/corelib/io/qfsfileengine_p.h +++ b/src/corelib/io/qfsfileengine_p.h @@ -115,7 +115,7 @@ public: virtual bool isUnnamedFile() const { return false; } - bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0) override; + bool extension(Extension extension, const ExtensionOption *option = nullptr, ExtensionReturn *output = nullptr) override; bool supportsExtension(Extension extension) const override; //FS only!! diff --git a/src/corelib/io/qloggingcategory.h b/src/corelib/io/qloggingcategory.h index 91e3144300..5825095729 100644 --- a/src/corelib/io/qloggingcategory.h +++ b/src/corelib/io/qloggingcategory.h @@ -111,8 +111,6 @@ private: #define Q_DECLARE_LOGGING_CATEGORY(name) \ extern const QLoggingCategory &name(); -#if defined(Q_COMPILER_VARIADIC_MACROS) || defined(Q_MOC_RUN) - #define Q_LOGGING_CATEGORY(name, ...) \ const QLoggingCategory &name() \ { \ @@ -148,39 +146,6 @@ private: for (bool qt_category_enabled = category().isCriticalEnabled(); qt_category_enabled; qt_category_enabled = false) \ QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC, category().categoryName()).critical(__VA_ARGS__) -#else // defined(Q_COMPILER_VARIADIC_MACROS) || defined(Q_MOC_RUN) - -// Optional msgType argument not supported -#define Q_LOGGING_CATEGORY(name, string) \ - const QLoggingCategory &name() \ - { \ - static const QLoggingCategory category(string); \ - return category; \ - } - -// check for enabled category inside QMessageLogger. -#if !defined(QT_NO_DEBUG_OUTPUT) -# define qCDebug qDebug -#else -# define qCDebug(category) QT_NO_QDEBUG_MACRO() -#endif - -#if !defined(QT_NO_INFO_OUTPUT) -# define qCInfo qInfo -#else -# define qCInfo(category) QT_NO_QDEBUG_MACRO() -#endif - -#if !defined(QT_NO_WARNING_OUTPUT) -# define qCWarning qWarning -#else -# define qCWarning(category) QT_NO_QDEBUG_MACRO() -#endif - -#define qCCritical qCritical - -#endif // Q_COMPILER_VARIADIC_MACROS || defined(Q_MOC_RUN) - QT_END_NAMESPACE #endif // QLOGGINGCATEGORY_H diff --git a/src/corelib/io/qnoncontiguousbytedevice.cpp b/src/corelib/io/qnoncontiguousbytedevice.cpp index beca6ccbf7..d1806aa12b 100644 --- a/src/corelib/io/qnoncontiguousbytedevice.cpp +++ b/src/corelib/io/qnoncontiguousbytedevice.cpp @@ -534,7 +534,7 @@ QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QSharedPointer */ QSharedPointer<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QSharedPointer<QRingBuffer> ringBuffer) { - return QSharedPointer<QNonContiguousByteDeviceRingBufferImpl>::create(qMove(ringBuffer)); + return QSharedPointer<QNonContiguousByteDeviceRingBufferImpl>::create(std::move(ringBuffer)); } /*! diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index d5d67d86f3..c7635cc7b4 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -42,6 +42,7 @@ #include <qdebug.h> #include <qdir.h> +#include <qscopedvaluerollback.h> #if defined(Q_OS_WIN) #include <qtimer.h> #endif @@ -1062,9 +1063,8 @@ bool QProcessPrivate::tryReadFromChannel(Channel *channel) if (currentReadChannel == channelIdx) { didRead = true; if (!emittedReadyRead) { - emittedReadyRead = true; + QScopedValueRollback<bool> guard(emittedReadyRead, true); emit q->readyRead(); - emittedReadyRead = false; } } emit q->channelReadyRead(int(channelIdx)); diff --git a/src/corelib/io/qprocess.h b/src/corelib/io/qprocess.h index a2e3c01f7c..9fda5fba11 100644 --- a/src/corelib/io/qprocess.h +++ b/src/corelib/io/qprocess.h @@ -72,12 +72,10 @@ public: QProcessEnvironment(); QProcessEnvironment(const QProcessEnvironment &other); ~QProcessEnvironment(); -#ifdef Q_COMPILER_RVALUE_REFS - QProcessEnvironment &operator=(QProcessEnvironment && other) Q_DECL_NOTHROW { swap(other); return *this; } -#endif + QProcessEnvironment &operator=(QProcessEnvironment && other) noexcept { swap(other); return *this; } QProcessEnvironment &operator=(const QProcessEnvironment &other); - void swap(QProcessEnvironment &other) Q_DECL_NOTHROW { qSwap(d, other.d); } + void swap(QProcessEnvironment &other) noexcept { qSwap(d, other.d); } bool operator==(const QProcessEnvironment &other) const; inline bool operator!=(const QProcessEnvironment &other) const diff --git a/src/corelib/io/qprocess_p.h b/src/corelib/io/qprocess_p.h index aa7ecbe91d..1bc63240fe 100644 --- a/src/corelib/io/qprocess_p.h +++ b/src/corelib/io/qprocess_p.h @@ -247,7 +247,7 @@ public: // if you add "= 4" here, increase the number of bits below }; - Channel() : process(0), notifier(0), type(Normal), closed(false), append(false) + Channel() : process(nullptr), notifier(nullptr), type(Normal), closed(false), append(false) { pipe[0] = INVALID_Q_PIPE; pipe[1] = INVALID_Q_PIPE; diff --git a/src/corelib/io/qresource_p.h b/src/corelib/io/qresource_p.h index 7451de8809..fedf95bb33 100644 --- a/src/corelib/io/qresource_p.h +++ b/src/corelib/io/qresource_p.h @@ -108,7 +108,7 @@ public: Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) override; Iterator *endEntryList() override; - bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0) override; + bool extension(Extension extension, const ExtensionOption *option = nullptr, ExtensionReturn *output = nullptr) override; bool supportsExtension(Extension extension) const override; }; diff --git a/src/corelib/io/qstorageinfo.h b/src/corelib/io/qstorageinfo.h index 4ab7a353ef..237e68d2a1 100644 --- a/src/corelib/io/qstorageinfo.h +++ b/src/corelib/io/qstorageinfo.h @@ -62,11 +62,9 @@ public: ~QStorageInfo(); QStorageInfo &operator=(const QStorageInfo &other); -#ifdef Q_COMPILER_RVALUE_REFS - QStorageInfo &operator=(QStorageInfo &&other) Q_DECL_NOTHROW { swap(other); return *this; } -#endif + QStorageInfo &operator=(QStorageInfo &&other) noexcept { swap(other); return *this; } - inline void swap(QStorageInfo &other) Q_DECL_NOTHROW + inline void swap(QStorageInfo &other) noexcept { qSwap(d, other.d); } void setPath(const QString &path); diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 6d82981fd6..b4090f710e 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -4159,7 +4159,7 @@ QList<QUrl> QUrl::fromStringList(const QStringList &urls, ParsingMode mode) \relates QHash \since 5.0 */ -uint qHash(const QUrl &url, uint seed) Q_DECL_NOTHROW +uint qHash(const QUrl &url, uint seed) noexcept { if (!url.d) return qHash(-1, seed); // the hash of an unset port (-1) diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h index 5062ef7905..94269e4369 100644 --- a/src/corelib/io/qurl.h +++ b/src/corelib/io/qurl.h @@ -119,7 +119,7 @@ class QTypeInfo<QUrlTwoFlags<E1, E2> > : public QTypeInfoMerger<QUrlTwoFlags<E1, class QUrl; // qHash is a friend, but we can't use default arguments for friends (§8.3.6.4) -Q_CORE_EXPORT uint qHash(const QUrl &url, uint seed = 0) Q_DECL_NOTHROW; +Q_CORE_EXPORT uint qHash(const QUrl &url, uint seed = 0) noexcept; class Q_CORE_EXPORT QUrl { @@ -182,15 +182,13 @@ public: QUrl(const QString &url, ParsingMode mode = TolerantMode); QUrl &operator=(const QString &url); #endif -#ifdef Q_COMPILER_RVALUE_REFS - QUrl(QUrl &&other) Q_DECL_NOTHROW : d(other.d) + QUrl(QUrl &&other) noexcept : d(other.d) { other.d = nullptr; } - inline QUrl &operator=(QUrl &&other) Q_DECL_NOTHROW + inline QUrl &operator=(QUrl &&other) noexcept { qSwap(d, other.d); return *this; } -#endif ~QUrl(); - inline void swap(QUrl &other) Q_DECL_NOTHROW { qSwap(d, other.d); } + inline void swap(QUrl &other) noexcept { qSwap(d, other.d); } void setUrl(const QString &url, ParsingMode mode = TolerantMode); QString url(FormattingOptions options = FormattingOptions(PrettyDecoded)) const; @@ -361,7 +359,7 @@ public: static QList<QUrl> fromStringList(const QStringList &uris, ParsingMode mode = TolerantMode); static void setIdnWhitelist(const QStringList &); - friend Q_CORE_EXPORT uint qHash(const QUrl &url, uint seed) Q_DECL_NOTHROW; + friend Q_CORE_EXPORT uint qHash(const QUrl &url, uint seed) noexcept; private: QUrlPrivate *d; diff --git a/src/corelib/io/qurl_p.h b/src/corelib/io/qurl_p.h index 1b9237e58a..e75de32e03 100644 --- a/src/corelib/io/qurl_p.h +++ b/src/corelib/io/qurl_p.h @@ -59,7 +59,7 @@ QT_BEGIN_NAMESPACE // in qurlrecode.cpp extern Q_AUTOTEST_EXPORT int qt_urlRecode(QString &appendTo, const QChar *begin, const QChar *end, - QUrl::ComponentFormattingOptions encoding, const ushort *tableModifications = 0); + QUrl::ComponentFormattingOptions encoding, const ushort *tableModifications = nullptr); // in qurlidna.cpp enum AceLeadingDot { AllowLeadingDot, ForbidLeadingDot }; diff --git a/src/corelib/io/qurlquery.cpp b/src/corelib/io/qurlquery.cpp index 10c3f836c8..d76107abfd 100644 --- a/src/corelib/io/qurlquery.cpp +++ b/src/corelib/io/qurlquery.cpp @@ -434,7 +434,7 @@ bool QUrlQuery::operator ==(const QUrlQuery &other) const Returns the hash value for \a key, using \a seed to seed the calculation. */ -uint qHash(const QUrlQuery &key, uint seed) Q_DECL_NOTHROW +uint qHash(const QUrlQuery &key, uint seed) noexcept { if (const QUrlQueryPrivate *d = key.d) { QtPrivate::QHashCombine hash; diff --git a/src/corelib/io/qurlquery.h b/src/corelib/io/qurlquery.h index e3688aae2c..89d0f88059 100644 --- a/src/corelib/io/qurlquery.h +++ b/src/corelib/io/qurlquery.h @@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE -Q_CORE_EXPORT uint qHash(const QUrlQuery &key, uint seed = 0) Q_DECL_NOTHROW; +Q_CORE_EXPORT uint qHash(const QUrlQuery &key, uint seed = 0) noexcept; class QUrlQueryPrivate; class Q_CORE_EXPORT QUrlQuery @@ -70,16 +70,14 @@ public: QUrlQuery(const QUrlQuery &other); QUrlQuery &operator=(const QUrlQuery &other); -#ifdef Q_COMPILER_RVALUE_REFS - QUrlQuery &operator=(QUrlQuery &&other) Q_DECL_NOTHROW { swap(other); return *this; } -#endif + QUrlQuery &operator=(QUrlQuery &&other) noexcept { swap(other); return *this; } ~QUrlQuery(); bool operator==(const QUrlQuery &other) const; bool operator!=(const QUrlQuery &other) const { return !(*this == other); } - void swap(QUrlQuery &other) Q_DECL_NOTHROW { qSwap(d, other.d); } + void swap(QUrlQuery &other) noexcept { qSwap(d, other.d); } bool isEmpty() const; bool isDetached() const; @@ -111,7 +109,7 @@ public: private: friend class QUrl; - friend Q_CORE_EXPORT uint qHash(const QUrlQuery &key, uint seed) Q_DECL_NOTHROW; + friend Q_CORE_EXPORT uint qHash(const QUrlQuery &key, uint seed) noexcept; QSharedDataPointer<QUrlQueryPrivate> d; public: typedef QSharedDataPointer<QUrlQueryPrivate> DataPtr; diff --git a/src/corelib/io/qurlrecode.cpp b/src/corelib/io/qurlrecode.cpp index 443ae18b21..f23480c755 100644 --- a/src/corelib/io/qurlrecode.cpp +++ b/src/corelib/io/qurlrecode.cpp @@ -692,7 +692,7 @@ qt_urlRecode(QString &appendTo, const QChar *begin, const QChar *end, } // qstring.cpp -bool qt_is_ascii(const char *&ptr, const char *end) Q_DECL_NOTHROW; +bool qt_is_ascii(const char *&ptr, const char *end) noexcept; /*! \internal diff --git a/src/corelib/io/qwindowspipereader.cpp b/src/corelib/io/qwindowspipereader.cpp index 15c9f52cf3..1f03ac5d5a 100644 --- a/src/corelib/io/qwindowspipereader.cpp +++ b/src/corelib/io/qwindowspipereader.cpp @@ -40,6 +40,7 @@ #include "qwindowspipereader_p.h" #include "qiodevice_p.h" #include <qelapsedtimer.h> +#include <qscopedvaluerollback.h> QT_BEGIN_NAMESPACE @@ -301,9 +302,8 @@ void QWindowsPipeReader::emitPendingReadyRead() { if (readyReadPending) { readyReadPending = false; - inReadyRead = true; + QScopedValueRollback<bool> guard(inReadyRead, true); emit readyRead(); - inReadyRead = false; } } diff --git a/src/corelib/io/qwindowspipewriter.cpp b/src/corelib/io/qwindowspipewriter.cpp index 92e8b6db52..32536f495b 100644 --- a/src/corelib/io/qwindowspipewriter.cpp +++ b/src/corelib/io/qwindowspipewriter.cpp @@ -39,6 +39,7 @@ #include "qwindowspipewriter_p.h" #include "qiodevice_p.h" +#include <qscopedvaluerollback.h> QT_BEGIN_NAMESPACE @@ -111,9 +112,8 @@ void QWindowsPipeWriter::emitPendingBytesWrittenValue() emit canWrite(); if (!inBytesWritten) { - inBytesWritten = true; + QScopedValueRollback<bool> guard(inBytesWritten, true); emit bytesWritten(bytes); - inBytesWritten = false; } } } diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 25a80a640c..d171b313e6 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -45,6 +45,7 @@ #include <qmimedata.h> #include <qdebug.h> #include <qvector.h> +#include <qregexp.h> #include <qstack.h> #include <qbitarray.h> #include <qdatetime.h> diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h index c34876d1d6..43649cf79b 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.h +++ b/src/corelib/itemmodels/qabstractitemmodel.h @@ -57,12 +57,12 @@ class Q_CORE_EXPORT QModelIndex { friend class QAbstractItemModel; public: - Q_DECL_CONSTEXPR inline QModelIndex() Q_DECL_NOTHROW : r(-1), c(-1), i(0), m(nullptr) {} + Q_DECL_CONSTEXPR inline QModelIndex() noexcept : r(-1), c(-1), i(0), m(nullptr) {} // compiler-generated copy/move ctors/assignment operators are fine! - Q_DECL_CONSTEXPR inline int row() const Q_DECL_NOTHROW { return r; } - Q_DECL_CONSTEXPR inline int column() const Q_DECL_NOTHROW { return c; } - Q_DECL_CONSTEXPR inline quintptr internalId() const Q_DECL_NOTHROW { return i; } - inline void *internalPointer() const Q_DECL_NOTHROW { return reinterpret_cast<void*>(i); } + Q_DECL_CONSTEXPR inline int row() const noexcept { return r; } + Q_DECL_CONSTEXPR inline int column() const noexcept { return c; } + Q_DECL_CONSTEXPR inline quintptr internalId() const noexcept { return i; } + inline void *internalPointer() const noexcept { return reinterpret_cast<void*>(i); } inline QModelIndex parent() const; inline QModelIndex sibling(int row, int column) const; inline QModelIndex siblingAtColumn(int column) const; @@ -72,13 +72,13 @@ public: #endif inline QVariant data(int role = Qt::DisplayRole) const; inline Qt::ItemFlags flags() const; - Q_DECL_CONSTEXPR inline const QAbstractItemModel *model() const Q_DECL_NOTHROW { return m; } - Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOTHROW { return (r >= 0) && (c >= 0) && (m != nullptr); } - Q_DECL_CONSTEXPR inline bool operator==(const QModelIndex &other) const Q_DECL_NOTHROW + Q_DECL_CONSTEXPR inline const QAbstractItemModel *model() const noexcept { return m; } + Q_DECL_CONSTEXPR inline bool isValid() const noexcept { return (r >= 0) && (c >= 0) && (m != nullptr); } + Q_DECL_CONSTEXPR inline bool operator==(const QModelIndex &other) const noexcept { return (other.r == r) && (other.i == i) && (other.c == c) && (other.m == m); } - Q_DECL_CONSTEXPR inline bool operator!=(const QModelIndex &other) const Q_DECL_NOTHROW + Q_DECL_CONSTEXPR inline bool operator!=(const QModelIndex &other) const noexcept { return !(*this == other); } - Q_DECL_CONSTEXPR inline bool operator<(const QModelIndex &other) const Q_DECL_NOTHROW + Q_DECL_CONSTEXPR inline bool operator<(const QModelIndex &other) const noexcept { return r < other.r || (r == other.r && (c < other.c @@ -86,9 +86,9 @@ public: || (i == other.i && std::less<const QAbstractItemModel *>()(m, other.m)))))); } private: - inline QModelIndex(int arow, int acolumn, void *ptr, const QAbstractItemModel *amodel) Q_DECL_NOTHROW + inline QModelIndex(int arow, int acolumn, void *ptr, const QAbstractItemModel *amodel) noexcept : r(arow), c(acolumn), i(reinterpret_cast<quintptr>(ptr)), m(amodel) {} - Q_DECL_CONSTEXPR inline QModelIndex(int arow, int acolumn, quintptr id, const QAbstractItemModel *amodel) Q_DECL_NOTHROW + Q_DECL_CONSTEXPR inline QModelIndex(int arow, int acolumn, quintptr id, const QAbstractItemModel *amodel) noexcept : r(arow), c(acolumn), i(id), m(amodel) {} int r, c; quintptr i; @@ -103,7 +103,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) Q_DECL_NOTHROW; +uint qHash(const QPersistentModelIndex &index, uint seed = 0) noexcept; class Q_CORE_EXPORT QPersistentModelIndex { @@ -117,13 +117,11 @@ public: inline bool operator!=(const QPersistentModelIndex &other) const { return !operator==(other); } QPersistentModelIndex &operator=(const QPersistentModelIndex &other); -#ifdef Q_COMPILER_RVALUE_REFS - inline QPersistentModelIndex(QPersistentModelIndex &&other) Q_DECL_NOTHROW + inline QPersistentModelIndex(QPersistentModelIndex &&other) noexcept : d(other.d) { other.d = nullptr; } - inline QPersistentModelIndex &operator=(QPersistentModelIndex &&other) Q_DECL_NOTHROW + inline QPersistentModelIndex &operator=(QPersistentModelIndex &&other) noexcept { qSwap(d, other.d); return *this; } -#endif - inline void swap(QPersistentModelIndex &other) Q_DECL_NOTHROW { qSwap(d, other.d); } + inline void swap(QPersistentModelIndex &other) noexcept { qSwap(d, other.d); } bool operator==(const QModelIndex &other) const; bool operator!=(const QModelIndex &other) const; QPersistentModelIndex &operator=(const QModelIndex &other); @@ -143,14 +141,14 @@ public: bool isValid() const; private: QPersistentModelIndexData *d; - friend uint qHash(const QPersistentModelIndex &, uint seed) Q_DECL_NOTHROW; + friend uint qHash(const QPersistentModelIndex &, uint seed) noexcept; #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) Q_DECL_NOTHROW +inline uint qHash(const QPersistentModelIndex &index, uint seed) noexcept { return qHash(index.d, seed); } @@ -464,7 +462,7 @@ inline QVariant QModelIndex::data(int arole) const inline Qt::ItemFlags QModelIndex::flags() const { return m ? m->flags(*this) : Qt::ItemFlags(); } -inline uint qHash(const QModelIndex &index) Q_DECL_NOTHROW +inline uint qHash(const QModelIndex &index) noexcept { return uint((uint(index.row()) << 4) + index.column() + index.internalId()); } QT_END_NAMESPACE diff --git a/src/corelib/itemmodels/qabstractitemmodel_p.h b/src/corelib/itemmodels/qabstractitemmodel_p.h index e6085eca94..92a440a125 100644 --- a/src/corelib/itemmodels/qabstractitemmodel_p.h +++ b/src/corelib/itemmodels/qabstractitemmodel_p.h @@ -98,7 +98,7 @@ public: void itemsMoved(const QModelIndex &srcParent, int srcFirst, int srcLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation orientation); bool allowMove(const QModelIndex &srcParent, int srcFirst, int srcLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation orientation); - inline QModelIndex createIndex(int row, int column, void *data = 0) const { + inline QModelIndex createIndex(int row, int column, void *data = nullptr) const { return q_func()->createIndex(row, column, data); } diff --git a/src/corelib/itemmodels/qabstractproxymodel_p.h b/src/corelib/itemmodels/qabstractproxymodel_p.h index f7bd5cc691..a95687c970 100644 --- a/src/corelib/itemmodels/qabstractproxymodel_p.h +++ b/src/corelib/itemmodels/qabstractproxymodel_p.h @@ -62,7 +62,7 @@ class Q_CORE_EXPORT QAbstractProxyModelPrivate : public QAbstractItemModelPrivat { Q_DECLARE_PUBLIC(QAbstractProxyModel) public: - QAbstractProxyModelPrivate() : QAbstractItemModelPrivate(), model(0) {} + QAbstractProxyModelPrivate() : QAbstractItemModelPrivate(), model(nullptr) {} QAbstractItemModel *model; virtual void _q_sourceModelDestroyed(); void mapDropCoordinatesToSource(int row, int column, const QModelIndex &parent, diff --git a/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp b/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp index a20024f468..0319d215a1 100644 --- a/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp +++ b/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp @@ -55,7 +55,7 @@ public: struct SourceModelForRowResult { - SourceModelForRowResult() : sourceModel(Q_NULLPTR), sourceRow(-1) {} + SourceModelForRowResult() : sourceModel(nullptr), sourceRow(-1) {} QAbstractItemModel *sourceModel; int sourceRow; }; diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index 1bacb63b17..c93a4d15b9 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -1273,10 +1273,10 @@ struct IsNotValid { typedef bool result_type; struct is_transparent : std::true_type {}; template <typename T> - Q_DECL_CONSTEXPR bool operator()(T &t) const Q_DECL_NOEXCEPT_EXPR(noexcept(t.isValid())) + Q_DECL_CONSTEXPR bool operator()(T &t) const noexcept(noexcept(t.isValid())) { return !t.isValid(); } template <typename T> - Q_DECL_CONSTEXPR bool operator()(T *t) const Q_DECL_NOEXCEPT_EXPR(noexcept(t->isValid())) + Q_DECL_CONSTEXPR bool operator()(T *t) const noexcept(noexcept(t->isValid())) { return !t->isValid(); } }; } diff --git a/src/corelib/itemmodels/qitemselectionmodel.h b/src/corelib/itemmodels/qitemselectionmodel.h index 1c924053a5..3c3f9fb1ac 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.h +++ b/src/corelib/itemmodels/qitemselectionmodel.h @@ -60,19 +60,17 @@ public: // ### Qt 6: remove them all, the compiler-generated ones are fine inline QItemSelectionRange(const QItemSelectionRange &other) : tl(other.tl), br(other.br) {} -# ifdef Q_COMPILER_RVALUE_REFS - QItemSelectionRange(QItemSelectionRange &&other) Q_DECL_NOTHROW + QItemSelectionRange(QItemSelectionRange &&other) noexcept : tl(std::move(other.tl)), br(std::move(other.br)) {} - QItemSelectionRange &operator=(QItemSelectionRange &&other) Q_DECL_NOTHROW + QItemSelectionRange &operator=(QItemSelectionRange &&other) noexcept { tl = std::move(other.tl); br = std::move(other.br); return *this; } -# endif QItemSelectionRange &operator=(const QItemSelectionRange &other) { tl = other.tl; br = other.br; return *this; } #endif // Qt < 6 QItemSelectionRange(const QModelIndex &topL, const QModelIndex &bottomR) : tl(topL), br(bottomR) {} explicit QItemSelectionRange(const QModelIndex &index) : tl(index), br(tl) {} - void swap(QItemSelectionRange &other) Q_DECL_NOTHROW + void swap(QItemSelectionRange &other) noexcept { qSwap(tl, other.tl); qSwap(br, other.br); @@ -249,7 +247,7 @@ Q_TEMPLATE_EXTERN template class Q_CORE_EXPORT QList<QItemSelectionRange>; class Q_CORE_EXPORT QItemSelection : public QList<QItemSelectionRange> { public: - QItemSelection() Q_DECL_NOTHROW : QList<QItemSelectionRange>() {} + QItemSelection() noexcept : QList<QItemSelectionRange>() {} QItemSelection(const QModelIndex &topLeft, const QModelIndex &bottomRight); // reusing QList::swap() here is OK! diff --git a/src/corelib/itemmodels/qitemselectionmodel_p.h b/src/corelib/itemmodels/qitemselectionmodel_p.h index e12a0c2928..ba85f22be3 100644 --- a/src/corelib/itemmodels/qitemselectionmodel_p.h +++ b/src/corelib/itemmodels/qitemselectionmodel_p.h @@ -62,7 +62,7 @@ class QItemSelectionModelPrivate: public QObjectPrivate Q_DECLARE_PUBLIC(QItemSelectionModel) public: QItemSelectionModelPrivate() - : model(0), + : model(nullptr), currentCommand(QItemSelectionModel::NoUpdate), tableSelected(false), tableColCount(0), tableRowCount(0) {} diff --git a/src/corelib/kernel/kernel.pri b/src/corelib/kernel/kernel.pri index 3f7bf3cd47..789bcb7927 100644 --- a/src/corelib/kernel/kernel.pri +++ b/src/corelib/kernel/kernel.pri @@ -7,7 +7,7 @@ HEADERS += \ kernel/qdeadlinetimer.h \ kernel/qdeadlinetimer_p.h \ kernel/qelapsedtimer.h \ - kernel/qeventloop.h\ + kernel/qeventloop.h \ kernel/qpointer.h \ kernel/qcorecmdlineargs_p.h \ kernel/qcoreapplication.h \ diff --git a/src/corelib/kernel/qabstracteventdispatcher.cpp b/src/corelib/kernel/qabstracteventdispatcher.cpp index ea08ff571f..186c2e743b 100644 --- a/src/corelib/kernel/qabstracteventdispatcher.cpp +++ b/src/corelib/kernel/qabstracteventdispatcher.cpp @@ -470,7 +470,11 @@ void QAbstractEventDispatcher::removeNativeEventFilter(QAbstractNativeEventFilte \sa installNativeEventFilter(), QAbstractNativeEventFilter::nativeEventFilter() \since 5.0 */ +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +bool QAbstractEventDispatcher::filterNativeEvent(const QByteArray &eventType, void *message, qintptr *result) +#else bool QAbstractEventDispatcher::filterNativeEvent(const QByteArray &eventType, void *message, long *result) +#endif { Q_D(QAbstractEventDispatcher); if (!d->eventFilters.isEmpty()) { diff --git a/src/corelib/kernel/qabstracteventdispatcher.h b/src/corelib/kernel/qabstracteventdispatcher.h index bd8da5c35d..4ef9c068df 100644 --- a/src/corelib/kernel/qabstracteventdispatcher.h +++ b/src/corelib/kernel/qabstracteventdispatcher.h @@ -110,7 +110,11 @@ public: void installNativeEventFilter(QAbstractNativeEventFilter *filterObj); void removeNativeEventFilter(QAbstractNativeEventFilter *filterObj); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + bool filterNativeEvent(const QByteArray &eventType, void *message, qintptr *result); +#else bool filterNativeEvent(const QByteArray &eventType, void *message, long *result); +#endif #if QT_DEPRECATED_SINCE(5, 0) QT_DEPRECATED bool filterEvent(void *message) { return filterNativeEvent("", message, nullptr); } diff --git a/src/corelib/kernel/qabstractnativeeventfilter.cpp b/src/corelib/kernel/qabstractnativeeventfilter.cpp index dcbb92f044..eaadea4c12 100644 --- a/src/corelib/kernel/qabstractnativeeventfilter.cpp +++ b/src/corelib/kernel/qabstractnativeeventfilter.cpp @@ -74,6 +74,7 @@ QAbstractNativeEventFilter::~QAbstractNativeEventFilter() eventDispatcher->removeNativeEventFilter(this); } +// ### fixme Qt 6: result will be qintptr * /*! \fn bool QAbstractNativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result) diff --git a/src/corelib/kernel/qabstractnativeeventfilter.h b/src/corelib/kernel/qabstractnativeeventfilter.h index d7baa42513..a468bffd61 100644 --- a/src/corelib/kernel/qabstractnativeeventfilter.h +++ b/src/corelib/kernel/qabstractnativeeventfilter.h @@ -52,7 +52,11 @@ public: QAbstractNativeEventFilter(); virtual ~QAbstractNativeEventFilter(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + virtual bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) = 0; +#else virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) = 0; +#endif private: Q_DISABLE_COPY(QAbstractNativeEventFilter) diff --git a/src/corelib/kernel/qcore_foundation.mm b/src/corelib/kernel/qcore_foundation.mm index 56eabc4b8c..623d462749 100644 --- a/src/corelib/kernel/qcore_foundation.mm +++ b/src/corelib/kernel/qcore_foundation.mm @@ -501,7 +501,7 @@ NSTimeZone *QTimeZone::toNSTimeZone() const \sa QRectF::fromCGRect() */ -CGRect QRect::toCGRect() const Q_DECL_NOTHROW +CGRect QRect::toCGRect() const noexcept { return CGRectMake(x(), y(), width(), height()); } @@ -513,7 +513,7 @@ CGRect QRect::toCGRect() const Q_DECL_NOTHROW \sa fromCGRect() */ -CGRect QRectF::toCGRect() const Q_DECL_NOTHROW +CGRect QRectF::toCGRect() const noexcept { return CGRectMake(x(), y(), width(), height()); } @@ -525,7 +525,7 @@ CGRect QRectF::toCGRect() const Q_DECL_NOTHROW \sa toCGRect() */ -QRectF QRectF::fromCGRect(CGRect rect) Q_DECL_NOTHROW +QRectF QRectF::fromCGRect(CGRect rect) noexcept { return QRectF(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); } @@ -539,7 +539,7 @@ QRectF QRectF::fromCGRect(CGRect rect) Q_DECL_NOTHROW \sa QPointF::fromCGPoint() */ -CGPoint QPoint::toCGPoint() const Q_DECL_NOTHROW +CGPoint QPoint::toCGPoint() const noexcept { return CGPointMake(x(), y()); } @@ -551,7 +551,7 @@ CGPoint QPoint::toCGPoint() const Q_DECL_NOTHROW \sa fromCGPoint() */ -CGPoint QPointF::toCGPoint() const Q_DECL_NOTHROW +CGPoint QPointF::toCGPoint() const noexcept { return CGPointMake(x(), y()); } @@ -563,7 +563,7 @@ CGPoint QPointF::toCGPoint() const Q_DECL_NOTHROW \sa toCGPoint() */ -QPointF QPointF::fromCGPoint(CGPoint point) Q_DECL_NOTHROW +QPointF QPointF::fromCGPoint(CGPoint point) noexcept { return QPointF(point.x, point.y); } @@ -577,7 +577,7 @@ QPointF QPointF::fromCGPoint(CGPoint point) Q_DECL_NOTHROW \sa QSizeF::fromCGSize() */ -CGSize QSize::toCGSize() const Q_DECL_NOTHROW +CGSize QSize::toCGSize() const noexcept { return CGSizeMake(width(), height()); } @@ -589,7 +589,7 @@ CGSize QSize::toCGSize() const Q_DECL_NOTHROW \sa fromCGSize() */ -CGSize QSizeF::toCGSize() const Q_DECL_NOTHROW +CGSize QSizeF::toCGSize() const noexcept { return CGSizeMake(width(), height()); } @@ -601,7 +601,7 @@ CGSize QSizeF::toCGSize() const Q_DECL_NOTHROW \sa toCGSize() */ -QSizeF QSizeF::fromCGSize(CGSize size) Q_DECL_NOTHROW +QSizeF QSizeF::fromCGSize(CGSize size) noexcept { return QSizeF(size.width, size.height); } diff --git a/src/corelib/kernel/qcore_mac_objc.mm b/src/corelib/kernel/qcore_mac_objc.mm index 6687eb88a5..6b51eb65d9 100644 --- a/src/corelib/kernel/qcore_mac_objc.mm +++ b/src/corelib/kernel/qcore_mac_objc.mm @@ -371,7 +371,7 @@ bool operator<(const KeyPair &entry, const Qt::Key &key) struct qtKey2CocoaKeySortLessThan { typedef bool result_type; - Q_DECL_CONSTEXPR result_type operator()(const KeyPair &entry1, const KeyPair &entry2) const Q_DECL_NOTHROW + Q_DECL_CONSTEXPR result_type operator()(const KeyPair &entry1, const KeyPair &entry2) const noexcept { return entry1.qtKey < entry2.qtKey; } diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h index f96e7358a2..920105ee9e 100644 --- a/src/corelib/kernel/qcore_mac_p.h +++ b/src/corelib/kernel/qcore_mac_p.h @@ -90,7 +90,7 @@ public: QAppleRefCounted(const QAppleRefCounted &other) : value(other.value) { if (value) RetainFunction(value); } ~QAppleRefCounted() { if (value) ReleaseFunction(value); } operator T() const { return value; } - void swap(QAppleRefCounted &other) Q_DECL_NOEXCEPT_EXPR(noexcept(qSwap(value, other.value))) + void swap(QAppleRefCounted &other) noexcept(noexcept(qSwap(value, other.value))) { qSwap(value, other.value); } QAppleRefCounted &operator=(const QAppleRefCounted &other) { QAppleRefCounted copy(other); swap(copy); return *this; } diff --git a/src/corelib/kernel/qcore_unix_p.h b/src/corelib/kernel/qcore_unix_p.h index 5a2a29a327..7f58813535 100644 --- a/src/corelib/kernel/qcore_unix_p.h +++ b/src/corelib/kernel/qcore_unix_p.h @@ -171,7 +171,7 @@ inline void qt_ignore_sigpipe() struct sigaction noaction; memset(&noaction, 0, sizeof(noaction)); noaction.sa_handler = SIG_IGN; - ::sigaction(SIGPIPE, &noaction, 0); + ::sigaction(SIGPIPE, &noaction, nullptr); atom.store(1); } } @@ -347,7 +347,7 @@ static inline pid_t qt_safe_waitpid(pid_t pid, int *status, int options) #endif // in qelapsedtimer_mac.cpp or qtimestamp_unix.cpp -timespec qt_gettime() Q_DECL_NOTHROW; +timespec qt_gettime() noexcept; void qt_nanosleep(timespec amount); QByteArray qt_readlink(const char *path); diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 30994d3056..d9fdb7f785 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -256,15 +256,6 @@ void QCoreApplicationPrivate::processCommandLineArguments() // Support for introspection -#ifndef QT_NO_QOBJECT -QSignalSpyCallbackSet Q_CORE_EXPORT qt_signal_spy_callback_set = { 0, 0, 0, 0 }; - -void qt_register_signal_spy_callbacks(const QSignalSpyCallbackSet &callback_set) -{ - qt_signal_spy_callback_set = callback_set; -} -#endif - extern "C" void Q_CORE_EXPORT qt_startup_hook() { } @@ -378,7 +369,7 @@ uint QCoreApplicationPrivate::attribs = (1 << Qt::AA_SynthesizeMouseForUnhandledTabletEvents); struct QCoreApplicationData { - QCoreApplicationData() Q_DECL_NOTHROW { + QCoreApplicationData() noexcept { applicationNameSet = false; applicationVersionSet = false; } @@ -866,11 +857,6 @@ void QCoreApplicationPrivate::init() eventDispatcherReady(); #endif -#ifdef QT_EVAL - extern void qt_core_eval_init(QCoreApplicationPrivate::Type); - qt_core_eval_init(application_type); -#endif - processCommandLineArguments(); qt_call_pre_routines(); diff --git a/src/corelib/kernel/qcoreapplication_p.h b/src/corelib/kernel/qcoreapplication_p.h index b3479414ab..14ca3efd7f 100644 --- a/src/corelib/kernel/qcoreapplication_p.h +++ b/src/corelib/kernel/qcoreapplication_p.h @@ -149,7 +149,7 @@ public: QString cachedApplicationDirPath; static QString *cachedApplicationFilePath; static void setApplicationFilePath(const QString &path); - static inline void clearApplicationFilePath() { delete cachedApplicationFilePath; cachedApplicationFilePath = 0; } + static inline void clearApplicationFilePath() { delete cachedApplicationFilePath; cachedApplicationFilePath = nullptr; } #ifndef QT_NO_QOBJECT void execCleanup(); diff --git a/src/corelib/kernel/qcoreevent.cpp b/src/corelib/kernel/qcoreevent.cpp index cacbb1e495..aabd32b4a8 100644 --- a/src/corelib/kernel/qcoreevent.cpp +++ b/src/corelib/kernel/qcoreevent.cpp @@ -421,7 +421,7 @@ struct QBasicAtomicBitField { QBasicAtomicInteger<uint> next; QBasicAtomicInteger<uint> data[NumInts]; - bool allocateSpecific(int which) Q_DECL_NOTHROW + bool allocateSpecific(int which) noexcept { QBasicAtomicInteger<uint> &entry = data[which / BitsPerInt]; const uint old = entry.load(); @@ -437,7 +437,7 @@ struct QBasicAtomicBitField { // loop. } - int allocateNext() Q_DECL_NOTHROW + int allocateNext() noexcept { // Unroll loop to iterate over ints, then bits? Would save // potentially a lot of cmpxchgs, because we can scan the @@ -463,7 +463,7 @@ typedef QBasicAtomicBitField<QEvent::MaxUser - QEvent::User + 1> UserEventTypeRe static UserEventTypeRegistry userEventTypeRegistry; -static inline int registerEventTypeZeroBased(int id) Q_DECL_NOTHROW +static inline int registerEventTypeZeroBased(int id) noexcept { // if the type hint hasn't been registered yet, take it: if (id < UserEventTypeRegistry::NumBits && id >= 0 && userEventTypeRegistry.allocateSpecific(id)) @@ -486,7 +486,7 @@ static inline int registerEventTypeZeroBased(int id) Q_DECL_NOTHROW Returns -1 if all available values are already taken or the program is shutting down. */ -int QEvent::registerEventType(int hint) Q_DECL_NOTHROW +int QEvent::registerEventType(int hint) noexcept { const int result = registerEventTypeZeroBased(QEvent::MaxUser - hint); return result < 0 ? -1 : QEvent::MaxUser - result ; diff --git a/src/corelib/kernel/qcoreevent.h b/src/corelib/kernel/qcoreevent.h index ac974ba411..05af1a6132 100644 --- a/src/corelib/kernel/qcoreevent.h +++ b/src/corelib/kernel/qcoreevent.h @@ -307,7 +307,7 @@ public: inline void accept() { m_accept = true; } inline void ignore() { m_accept = false; } - static int registerEventType(int hint = -1) Q_DECL_NOTHROW; + static int registerEventType(int hint = -1) noexcept; protected: QEventPrivate *d; diff --git a/src/corelib/kernel/qdeadlinetimer.cpp b/src/corelib/kernel/qdeadlinetimer.cpp index 6aa886cfe1..e0d9d9de73 100644 --- a/src/corelib/kernel/qdeadlinetimer.cpp +++ b/src/corelib/kernel/qdeadlinetimer.cpp @@ -188,7 +188,7 @@ Q_DECL_CONST_FUNCTION static inline QPair<qint64, qint64> toSecsAndNSecs(qint64 \sa hasExpired(), isForever(), remainingTime(), setRemainingTime() */ -QDeadlineTimer::QDeadlineTimer(qint64 msecs, Qt::TimerType type) Q_DECL_NOTHROW +QDeadlineTimer::QDeadlineTimer(qint64 msecs, Qt::TimerType type) noexcept : t2(0) { setRemainingTime(msecs, type); @@ -260,7 +260,7 @@ QDeadlineTimer::QDeadlineTimer(qint64 msecs, Qt::TimerType type) Q_DECL_NOTHROW \sa setPreciseRemainingTime(), hasExpired(), isForever(), remainingTime() */ -void QDeadlineTimer::setRemainingTime(qint64 msecs, Qt::TimerType timerType) Q_DECL_NOTHROW +void QDeadlineTimer::setRemainingTime(qint64 msecs, Qt::TimerType timerType) noexcept { if (msecs == -1) *this = QDeadlineTimer(Forever, timerType); @@ -279,7 +279,7 @@ void QDeadlineTimer::setRemainingTime(qint64 msecs, Qt::TimerType timerType) Q_D \sa setRemainingTime(), hasExpired(), isForever(), remainingTime() */ -void QDeadlineTimer::setPreciseRemainingTime(qint64 secs, qint64 nsecs, Qt::TimerType timerType) Q_DECL_NOTHROW +void QDeadlineTimer::setPreciseRemainingTime(qint64 secs, qint64 nsecs, Qt::TimerType timerType) noexcept { if (secs == -1) { *this = QDeadlineTimer(Forever, timerType); @@ -342,7 +342,7 @@ void QDeadlineTimer::setPreciseRemainingTime(qint64 secs, qint64 nsecs, Qt::Time \sa isForever(), remainingTime() */ -bool QDeadlineTimer::hasExpired() const Q_DECL_NOTHROW +bool QDeadlineTimer::hasExpired() const noexcept { if (isForever()) return false; @@ -389,7 +389,7 @@ void QDeadlineTimer::setTimerType(Qt::TimerType timerType) \sa remainingTimeNSecs(), isForever(), hasExpired() */ -qint64 QDeadlineTimer::remainingTime() const Q_DECL_NOTHROW +qint64 QDeadlineTimer::remainingTime() const noexcept { qint64 ns = remainingTimeNSecs(); return ns <= 0 ? ns : (ns + 999999) / (1000 * 1000); @@ -403,7 +403,7 @@ qint64 QDeadlineTimer::remainingTime() const Q_DECL_NOTHROW \sa remainingTime(), isForever(), hasExpired() */ -qint64 QDeadlineTimer::remainingTimeNSecs() const Q_DECL_NOTHROW +qint64 QDeadlineTimer::remainingTimeNSecs() const noexcept { if (isForever()) return -1; @@ -416,7 +416,7 @@ qint64 QDeadlineTimer::remainingTimeNSecs() const Q_DECL_NOTHROW Same as remainingTimeNSecs, but may return negative remaining times. Does not deal with Forever. */ -qint64 QDeadlineTimer::rawRemainingTimeNSecs() const Q_DECL_NOTHROW +qint64 QDeadlineTimer::rawRemainingTimeNSecs() const noexcept { QDeadlineTimer now = current(timerType()); if (QDeadlineTimerNanosecondsInT2) @@ -444,7 +444,7 @@ qint64 QDeadlineTimer::rawRemainingTimeNSecs() const Q_DECL_NOTHROW \sa remainingTime(), deadlineNSecs(), setDeadline() */ -qint64 QDeadlineTimer::deadline() const Q_DECL_NOTHROW +qint64 QDeadlineTimer::deadline() const noexcept { if (isForever()) return t1; @@ -471,7 +471,7 @@ qint64 QDeadlineTimer::deadline() const Q_DECL_NOTHROW \sa remainingTime(), deadlineNSecs() */ -qint64 QDeadlineTimer::deadlineNSecs() const Q_DECL_NOTHROW +qint64 QDeadlineTimer::deadlineNSecs() const noexcept { if (isForever()) return t1; @@ -492,7 +492,7 @@ qint64 QDeadlineTimer::deadlineNSecs() const Q_DECL_NOTHROW \sa setPreciseDeadline(), deadline(), deadlineNSecs(), setRemainingTime() */ -void QDeadlineTimer::setDeadline(qint64 msecs, Qt::TimerType timerType) Q_DECL_NOTHROW +void QDeadlineTimer::setDeadline(qint64 msecs, Qt::TimerType timerType) noexcept { if (msecs == (std::numeric_limits<qint64>::max)()) { setPreciseDeadline(msecs, 0, timerType); // msecs == MAX implies Forever @@ -513,7 +513,7 @@ void QDeadlineTimer::setDeadline(qint64 msecs, Qt::TimerType timerType) Q_DECL_N \sa setDeadline(), deadline(), deadlineNSecs(), setRemainingTime() */ -void QDeadlineTimer::setPreciseDeadline(qint64 secs, qint64 nsecs, Qt::TimerType timerType) Q_DECL_NOTHROW +void QDeadlineTimer::setPreciseDeadline(qint64 secs, qint64 nsecs, Qt::TimerType timerType) noexcept { type = timerType; if (secs == (std::numeric_limits<qint64>::max)() || nsecs == (std::numeric_limits<qint64>::max)()) { @@ -534,7 +534,7 @@ void QDeadlineTimer::setPreciseDeadline(qint64 secs, qint64 nsecs, Qt::TimerType \note if \a dt was created as expired, its deadline is indeterminate and adding an amount of time may or may not cause it to become unexpired. */ -QDeadlineTimer QDeadlineTimer::addNSecs(QDeadlineTimer dt, qint64 nsecs) Q_DECL_NOTHROW +QDeadlineTimer QDeadlineTimer::addNSecs(QDeadlineTimer dt, qint64 nsecs) noexcept { if (dt.isForever() || nsecs == (std::numeric_limits<qint64>::max)()) { dt = QDeadlineTimer(Forever, dt.timerType()); diff --git a/src/corelib/kernel/qdeadlinetimer.h b/src/corelib/kernel/qdeadlinetimer.h index 1a4ee04a96..8032ee9018 100644 --- a/src/corelib/kernel/qdeadlinetimer.h +++ b/src/corelib/kernel/qdeadlinetimer.h @@ -63,49 +63,49 @@ class Q_CORE_EXPORT QDeadlineTimer public: enum ForeverConstant { Forever }; - Q_DECL_CONSTEXPR QDeadlineTimer(Qt::TimerType type_ = Qt::CoarseTimer) Q_DECL_NOTHROW + Q_DECL_CONSTEXPR QDeadlineTimer(Qt::TimerType type_ = Qt::CoarseTimer) noexcept : t1(0), t2(0), type(type_) {} - Q_DECL_CONSTEXPR QDeadlineTimer(ForeverConstant, Qt::TimerType type_ = Qt::CoarseTimer) Q_DECL_NOTHROW + Q_DECL_CONSTEXPR QDeadlineTimer(ForeverConstant, Qt::TimerType type_ = Qt::CoarseTimer) noexcept : t1(std::numeric_limits<qint64>::max()), t2(0), type(type_) {} - explicit QDeadlineTimer(qint64 msecs, Qt::TimerType type = Qt::CoarseTimer) Q_DECL_NOTHROW; + explicit QDeadlineTimer(qint64 msecs, Qt::TimerType type = Qt::CoarseTimer) noexcept; - void swap(QDeadlineTimer &other) Q_DECL_NOTHROW + void swap(QDeadlineTimer &other) noexcept { qSwap(t1, other.t1); qSwap(t2, other.t2); qSwap(type, other.type); } - Q_DECL_CONSTEXPR bool isForever() const Q_DECL_NOTHROW + Q_DECL_CONSTEXPR bool isForever() const noexcept { return t1 == (std::numeric_limits<qint64>::max)(); } - bool hasExpired() const Q_DECL_NOTHROW; + bool hasExpired() const noexcept; - Qt::TimerType timerType() const Q_DECL_NOTHROW + Qt::TimerType timerType() const noexcept { return Qt::TimerType(type & 0xff); } void setTimerType(Qt::TimerType type); - qint64 remainingTime() const Q_DECL_NOTHROW; - qint64 remainingTimeNSecs() const Q_DECL_NOTHROW; - void setRemainingTime(qint64 msecs, Qt::TimerType type = Qt::CoarseTimer) Q_DECL_NOTHROW; + qint64 remainingTime() const noexcept; + qint64 remainingTimeNSecs() const noexcept; + void setRemainingTime(qint64 msecs, Qt::TimerType type = Qt::CoarseTimer) noexcept; void setPreciseRemainingTime(qint64 secs, qint64 nsecs = 0, - Qt::TimerType type = Qt::CoarseTimer) Q_DECL_NOTHROW; + Qt::TimerType type = Qt::CoarseTimer) noexcept; - qint64 deadline() const Q_DECL_NOTHROW Q_DECL_PURE_FUNCTION; - qint64 deadlineNSecs() const Q_DECL_NOTHROW Q_DECL_PURE_FUNCTION; - void setDeadline(qint64 msecs, Qt::TimerType timerType = Qt::CoarseTimer) Q_DECL_NOTHROW; + qint64 deadline() const noexcept Q_DECL_PURE_FUNCTION; + qint64 deadlineNSecs() const noexcept Q_DECL_PURE_FUNCTION; + void setDeadline(qint64 msecs, Qt::TimerType timerType = Qt::CoarseTimer) noexcept; void setPreciseDeadline(qint64 secs, qint64 nsecs = 0, - Qt::TimerType type = Qt::CoarseTimer) Q_DECL_NOTHROW; + Qt::TimerType type = Qt::CoarseTimer) noexcept; - static QDeadlineTimer addNSecs(QDeadlineTimer dt, qint64 nsecs) Q_DECL_NOTHROW Q_DECL_PURE_FUNCTION; - static QDeadlineTimer current(Qt::TimerType timerType = Qt::CoarseTimer) Q_DECL_NOTHROW; + static QDeadlineTimer addNSecs(QDeadlineTimer dt, qint64 nsecs) noexcept Q_DECL_PURE_FUNCTION; + static QDeadlineTimer current(Qt::TimerType timerType = Qt::CoarseTimer) noexcept; - friend bool operator==(QDeadlineTimer d1, QDeadlineTimer d2) Q_DECL_NOTHROW + friend bool operator==(QDeadlineTimer d1, QDeadlineTimer d2) noexcept { return d1.t1 == d2.t1 && d1.t2 == d2.t2; } - friend bool operator!=(QDeadlineTimer d1, QDeadlineTimer d2) Q_DECL_NOTHROW + friend bool operator!=(QDeadlineTimer d1, QDeadlineTimer d2) noexcept { return !(d1 == d2); } - friend bool operator<(QDeadlineTimer d1, QDeadlineTimer d2) Q_DECL_NOTHROW + friend bool operator<(QDeadlineTimer d1, QDeadlineTimer d2) noexcept { return d1.t1 < d2.t1 || (d1.t1 == d2.t1 && d1.t2 < d2.t2); } - friend bool operator<=(QDeadlineTimer d1, QDeadlineTimer d2) Q_DECL_NOTHROW + friend bool operator<=(QDeadlineTimer d1, QDeadlineTimer d2) noexcept { return d1 == d2 || d1 < d2; } - friend bool operator>(QDeadlineTimer d1, QDeadlineTimer d2) Q_DECL_NOTHROW + friend bool operator>(QDeadlineTimer d1, QDeadlineTimer d2) noexcept { return d2 < d1; } - friend bool operator>=(QDeadlineTimer d1, QDeadlineTimer d2) Q_DECL_NOTHROW + friend bool operator>=(QDeadlineTimer d1, QDeadlineTimer d2) noexcept { return !(d1 < d2); } friend QDeadlineTimer operator+(QDeadlineTimer dt, qint64 msecs) @@ -160,7 +160,7 @@ public: setPreciseRemainingTime(0, std::chrono::nanoseconds(remaining).count(), type_); } - std::chrono::nanoseconds remainingTimeAsDuration() const Q_DECL_NOTHROW + std::chrono::nanoseconds remainingTimeAsDuration() const noexcept { if (isForever()) return std::chrono::nanoseconds::max(); @@ -186,7 +186,7 @@ private: unsigned t2; unsigned type; - qint64 rawRemainingTimeNSecs() const Q_DECL_NOTHROW; + qint64 rawRemainingTimeNSecs() const noexcept; public: // This is not a public function, it's here only for Qt's internal convenience... diff --git a/src/corelib/kernel/qelapsedtimer.cpp b/src/corelib/kernel/qelapsedtimer.cpp index e578b5b8b3..adb554b624 100644 --- a/src/corelib/kernel/qelapsedtimer.cpp +++ b/src/corelib/kernel/qelapsedtimer.cpp @@ -236,7 +236,7 @@ static const qint64 invalidData = Q_INT64_C(0x8000000000000000); \sa isValid(), start(), restart() */ -void QElapsedTimer::invalidate() Q_DECL_NOTHROW +void QElapsedTimer::invalidate() noexcept { t1 = t2 = invalidData; } @@ -247,7 +247,7 @@ void QElapsedTimer::invalidate() Q_DECL_NOTHROW \sa invalidate(), start(), restart() */ -bool QElapsedTimer::isValid() const Q_DECL_NOTHROW +bool QElapsedTimer::isValid() const noexcept { return t1 != invalidData && t2 != invalidData; } @@ -260,7 +260,7 @@ bool QElapsedTimer::isValid() const Q_DECL_NOTHROW \sa elapsed(), QDeadlineTimer */ -bool QElapsedTimer::hasExpired(qint64 timeout) const Q_DECL_NOTHROW +bool QElapsedTimer::hasExpired(qint64 timeout) const noexcept { // if timeout is -1, quint64(timeout) is LLINT_MAX, so this will be // considered as never expired diff --git a/src/corelib/kernel/qelapsedtimer.h b/src/corelib/kernel/qelapsedtimer.h index 7954b41bf4..873847f6b6 100644 --- a/src/corelib/kernel/qelapsedtimer.h +++ b/src/corelib/kernel/qelapsedtimer.h @@ -62,28 +62,28 @@ public: { } - static ClockType clockType() Q_DECL_NOTHROW; - static bool isMonotonic() Q_DECL_NOTHROW; + static ClockType clockType() noexcept; + static bool isMonotonic() noexcept; - void start() Q_DECL_NOTHROW; - qint64 restart() Q_DECL_NOTHROW; - void invalidate() Q_DECL_NOTHROW; - bool isValid() const Q_DECL_NOTHROW; + void start() noexcept; + qint64 restart() noexcept; + void invalidate() noexcept; + bool isValid() const noexcept; - qint64 nsecsElapsed() const Q_DECL_NOTHROW; - qint64 elapsed() const Q_DECL_NOTHROW; - bool hasExpired(qint64 timeout) const Q_DECL_NOTHROW; + qint64 nsecsElapsed() const noexcept; + qint64 elapsed() const noexcept; + bool hasExpired(qint64 timeout) const noexcept; - qint64 msecsSinceReference() const Q_DECL_NOTHROW; - qint64 msecsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW; - qint64 secsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW; + qint64 msecsSinceReference() const noexcept; + qint64 msecsTo(const QElapsedTimer &other) const noexcept; + qint64 secsTo(const QElapsedTimer &other) const noexcept; - bool operator==(const QElapsedTimer &other) const Q_DECL_NOTHROW + bool operator==(const QElapsedTimer &other) const noexcept { return t1 == other.t1 && t2 == other.t2; } - bool operator!=(const QElapsedTimer &other) const Q_DECL_NOTHROW + bool operator!=(const QElapsedTimer &other) const noexcept { return !(*this == other); } - friend bool Q_CORE_EXPORT operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) Q_DECL_NOTHROW; + friend bool Q_CORE_EXPORT operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) noexcept; private: qint64 t1; diff --git a/src/corelib/kernel/qelapsedtimer_generic.cpp b/src/corelib/kernel/qelapsedtimer_generic.cpp index fdeb385188..fe959e3c94 100644 --- a/src/corelib/kernel/qelapsedtimer_generic.cpp +++ b/src/corelib/kernel/qelapsedtimer_generic.cpp @@ -48,7 +48,7 @@ QT_BEGIN_NAMESPACE \sa isMonotonic() */ -QElapsedTimer::ClockType QElapsedTimer::clockType() Q_DECL_NOTHROW +QElapsedTimer::ClockType QElapsedTimer::clockType() noexcept { return SystemTime; } @@ -60,7 +60,7 @@ QElapsedTimer::ClockType QElapsedTimer::clockType() Q_DECL_NOTHROW \sa clockType(), QElapsedTimer::ClockType */ -bool QElapsedTimer::isMonotonic() Q_DECL_NOTHROW +bool QElapsedTimer::isMonotonic() noexcept { return false; } @@ -75,7 +75,7 @@ bool QElapsedTimer::isMonotonic() Q_DECL_NOTHROW \sa restart(), invalidate(), elapsed() */ -void QElapsedTimer::start() Q_DECL_NOTHROW +void QElapsedTimer::start() noexcept { restart(); } @@ -97,7 +97,7 @@ void QElapsedTimer::start() Q_DECL_NOTHROW \sa start(), invalidate(), elapsed(), isValid() */ -qint64 QElapsedTimer::restart() Q_DECL_NOTHROW +qint64 QElapsedTimer::restart() noexcept { qint64 old = t1; t1 = QDateTime::currentMSecsSinceEpoch(); @@ -118,7 +118,7 @@ qint64 QElapsedTimer::restart() Q_DECL_NOTHROW \sa start(), restart(), hasExpired(), invalidate() */ -qint64 QElapsedTimer::nsecsElapsed() const Q_DECL_NOTHROW +qint64 QElapsedTimer::nsecsElapsed() const noexcept { return elapsed() * 1000000; } @@ -132,7 +132,7 @@ qint64 QElapsedTimer::nsecsElapsed() const Q_DECL_NOTHROW \sa start(), restart(), hasExpired(), isValid(), invalidate() */ -qint64 QElapsedTimer::elapsed() const Q_DECL_NOTHROW +qint64 QElapsedTimer::elapsed() const noexcept { return QDateTime::currentMSecsSinceEpoch() - t1; } @@ -152,7 +152,7 @@ qint64 QElapsedTimer::elapsed() const Q_DECL_NOTHROW \sa clockType(), elapsed() */ -qint64 QElapsedTimer::msecsSinceReference() const Q_DECL_NOTHROW +qint64 QElapsedTimer::msecsSinceReference() const noexcept { return t1; } @@ -167,7 +167,7 @@ qint64 QElapsedTimer::msecsSinceReference() const Q_DECL_NOTHROW \sa secsTo(), elapsed() */ -qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW +qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const noexcept { qint64 diff = other.t1 - t1; return diff; @@ -183,7 +183,7 @@ qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW \sa msecsTo(), elapsed() */ -qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW +qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const noexcept { return msecsTo(other) / 1000; } @@ -197,12 +197,12 @@ qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW and the other isn't. However, two invalid timers are equal and thus this function will return false. */ -bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) Q_DECL_NOTHROW +bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) noexcept { return v1.t1 < v2.t1; } -QDeadlineTimer QDeadlineTimer::current(Qt::TimerType timerType) Q_DECL_NOTHROW +QDeadlineTimer QDeadlineTimer::current(Qt::TimerType timerType) noexcept { QDeadlineTimer result; result.t1 = QDateTime::currentMSecsSinceEpoch() * 1000 * 1000; diff --git a/src/corelib/kernel/qelapsedtimer_mac.cpp b/src/corelib/kernel/qelapsedtimer_mac.cpp index 7490693991..5370cf7b3d 100644 --- a/src/corelib/kernel/qelapsedtimer_mac.cpp +++ b/src/corelib/kernel/qelapsedtimer_mac.cpp @@ -58,12 +58,12 @@ typedef __int128_t LargeInt; typedef qint64 LargeInt; #endif -QElapsedTimer::ClockType QElapsedTimer::clockType() Q_DECL_NOTHROW +QElapsedTimer::ClockType QElapsedTimer::clockType() noexcept { return MachAbsoluteTime; } -bool QElapsedTimer::isMonotonic() Q_DECL_NOTHROW +bool QElapsedTimer::isMonotonic() noexcept { return true; } @@ -87,7 +87,7 @@ static qint64 absoluteToMSecs(qint64 cpuTime) return absoluteToNSecs(cpuTime) / 1000000; } -timespec qt_gettime() Q_DECL_NOTHROW +timespec qt_gettime() noexcept { timespec tv; @@ -107,13 +107,13 @@ void qt_nanosleep(timespec amount) EINTR_LOOP(r, nanosleep(&amount, &amount)); } -void QElapsedTimer::start() Q_DECL_NOTHROW +void QElapsedTimer::start() noexcept { t1 = mach_absolute_time(); t2 = 0; } -qint64 QElapsedTimer::restart() Q_DECL_NOTHROW +qint64 QElapsedTimer::restart() noexcept { qint64 old = t1; t1 = mach_absolute_time(); @@ -122,39 +122,39 @@ qint64 QElapsedTimer::restart() Q_DECL_NOTHROW return absoluteToMSecs(t1 - old); } -qint64 QElapsedTimer::nsecsElapsed() const Q_DECL_NOTHROW +qint64 QElapsedTimer::nsecsElapsed() const noexcept { uint64_t cpu_time = mach_absolute_time(); return absoluteToNSecs(cpu_time - t1); } -qint64 QElapsedTimer::elapsed() const Q_DECL_NOTHROW +qint64 QElapsedTimer::elapsed() const noexcept { uint64_t cpu_time = mach_absolute_time(); return absoluteToMSecs(cpu_time - t1); } -qint64 QElapsedTimer::msecsSinceReference() const Q_DECL_NOTHROW +qint64 QElapsedTimer::msecsSinceReference() const noexcept { return absoluteToMSecs(t1); } -qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW +qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const noexcept { return absoluteToMSecs(other.t1 - t1); } -qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW +qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const noexcept { return msecsTo(other) / 1000; } -bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) Q_DECL_NOTHROW +bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) noexcept { return v1.t1 < v2.t1; } -QDeadlineTimer QDeadlineTimer::current(Qt::TimerType timerType) Q_DECL_NOTHROW +QDeadlineTimer QDeadlineTimer::current(Qt::TimerType timerType) noexcept { Q_STATIC_ASSERT(!QDeadlineTimerNanosecondsInT2); QDeadlineTimer result; diff --git a/src/corelib/kernel/qelapsedtimer_unix.cpp b/src/corelib/kernel/qelapsedtimer_unix.cpp index e166d4e3d2..ccc2eeafa3 100644 --- a/src/corelib/kernel/qelapsedtimer_unix.cpp +++ b/src/corelib/kernel/qelapsedtimer_unix.cpp @@ -150,12 +150,12 @@ static int unixCheckClockType() #endif } -bool QElapsedTimer::isMonotonic() Q_DECL_NOTHROW +bool QElapsedTimer::isMonotonic() noexcept { return clockType() == MonotonicClock; } -QElapsedTimer::ClockType QElapsedTimer::clockType() Q_DECL_NOTHROW +QElapsedTimer::ClockType QElapsedTimer::clockType() noexcept { return unixCheckClockType() == CLOCK_REALTIME ? SystemTime : MonotonicClock; } @@ -169,7 +169,7 @@ static inline void do_gettime(qint64 *sec, qint64 *frac) } // used in qcore_unix.cpp and qeventdispatcher_unix.cpp -struct timespec qt_gettime() Q_DECL_NOTHROW +struct timespec qt_gettime() noexcept { qint64 sec, frac; do_gettime(&sec, &frac); @@ -204,17 +204,17 @@ static qint64 elapsedAndRestart(qint64 sec, qint64 frac, return (sec * Q_INT64_C(1000000000) + frac) / Q_INT64_C(1000000); } -void QElapsedTimer::start() Q_DECL_NOTHROW +void QElapsedTimer::start() noexcept { do_gettime(&t1, &t2); } -qint64 QElapsedTimer::restart() Q_DECL_NOTHROW +qint64 QElapsedTimer::restart() noexcept { return elapsedAndRestart(t1, t2, &t1, &t2); } -qint64 QElapsedTimer::nsecsElapsed() const Q_DECL_NOTHROW +qint64 QElapsedTimer::nsecsElapsed() const noexcept { qint64 sec, frac; do_gettime(&sec, &frac); @@ -223,34 +223,34 @@ qint64 QElapsedTimer::nsecsElapsed() const Q_DECL_NOTHROW return sec * Q_INT64_C(1000000000) + frac; } -qint64 QElapsedTimer::elapsed() const Q_DECL_NOTHROW +qint64 QElapsedTimer::elapsed() const noexcept { return nsecsElapsed() / Q_INT64_C(1000000); } -qint64 QElapsedTimer::msecsSinceReference() const Q_DECL_NOTHROW +qint64 QElapsedTimer::msecsSinceReference() const noexcept { return t1 * Q_INT64_C(1000) + t2 / Q_INT64_C(1000000); } -qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW +qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const noexcept { qint64 secs = other.t1 - t1; qint64 fraction = other.t2 - t2; return (secs * Q_INT64_C(1000000000) + fraction) / Q_INT64_C(1000000); } -qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW +qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const noexcept { return other.t1 - t1; } -bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) Q_DECL_NOTHROW +bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) noexcept { return v1.t1 < v2.t1 || (v1.t1 == v2.t1 && v1.t2 < v2.t2); } -QDeadlineTimer QDeadlineTimer::current(Qt::TimerType timerType) Q_DECL_NOTHROW +QDeadlineTimer QDeadlineTimer::current(Qt::TimerType timerType) noexcept { Q_STATIC_ASSERT(QDeadlineTimerNanosecondsInT2); QDeadlineTimer result; diff --git a/src/corelib/kernel/qelapsedtimer_win.cpp b/src/corelib/kernel/qelapsedtimer_win.cpp index 3beb158b8a..8becb17461 100644 --- a/src/corelib/kernel/qelapsedtimer_win.cpp +++ b/src/corelib/kernel/qelapsedtimer_win.cpp @@ -101,25 +101,25 @@ quint64 qt_msectime() return ticksToNanoseconds(getTickCount()) / 1000000; } -QElapsedTimer::ClockType QElapsedTimer::clockType() Q_DECL_NOTHROW +QElapsedTimer::ClockType QElapsedTimer::clockType() noexcept { resolveCounterFrequency(); return counterFrequency > 0 ? PerformanceCounter : TickCounter; } -bool QElapsedTimer::isMonotonic() Q_DECL_NOTHROW +bool QElapsedTimer::isMonotonic() noexcept { return true; } -void QElapsedTimer::start() Q_DECL_NOTHROW +void QElapsedTimer::start() noexcept { t1 = getTickCount(); t2 = 0; } -qint64 QElapsedTimer::restart() Q_DECL_NOTHROW +qint64 QElapsedTimer::restart() noexcept { qint64 oldt1 = t1; t1 = getTickCount(); @@ -127,40 +127,40 @@ qint64 QElapsedTimer::restart() Q_DECL_NOTHROW return ticksToNanoseconds(t1 - oldt1) / 1000000; } -qint64 QElapsedTimer::nsecsElapsed() const Q_DECL_NOTHROW +qint64 QElapsedTimer::nsecsElapsed() const noexcept { qint64 elapsed = getTickCount() - t1; return ticksToNanoseconds(elapsed); } -qint64 QElapsedTimer::elapsed() const Q_DECL_NOTHROW +qint64 QElapsedTimer::elapsed() const noexcept { qint64 elapsed = getTickCount() - t1; return ticksToNanoseconds(elapsed) / 1000000; } -qint64 QElapsedTimer::msecsSinceReference() const Q_DECL_NOTHROW +qint64 QElapsedTimer::msecsSinceReference() const noexcept { return ticksToNanoseconds(t1) / 1000000; } -qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW +qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const noexcept { qint64 difference = other.t1 - t1; return ticksToNanoseconds(difference) / 1000000; } -qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW +qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const noexcept { return msecsTo(other) / 1000; } -bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) Q_DECL_NOTHROW +bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) noexcept { return (v1.t1 - v2.t1) < 0; } -QDeadlineTimer QDeadlineTimer::current(Qt::TimerType timerType) Q_DECL_NOTHROW +QDeadlineTimer QDeadlineTimer::current(Qt::TimerType timerType) noexcept { Q_STATIC_ASSERT(!QDeadlineTimerNanosecondsInT2); QDeadlineTimer result; diff --git a/src/corelib/kernel/qeventdispatcher_glib_p.h b/src/corelib/kernel/qeventdispatcher_glib_p.h index 88ff316ee5..313825d0a7 100644 --- a/src/corelib/kernel/qeventdispatcher_glib_p.h +++ b/src/corelib/kernel/qeventdispatcher_glib_p.h @@ -66,8 +66,8 @@ class Q_CORE_EXPORT QEventDispatcherGlib : public QAbstractEventDispatcher Q_DECLARE_PRIVATE(QEventDispatcherGlib) public: - explicit QEventDispatcherGlib(QObject *parent = 0); - explicit QEventDispatcherGlib(GMainContext *context, QObject *parent = 0); + explicit QEventDispatcherGlib(QObject *parent = nullptr); + explicit QEventDispatcherGlib(GMainContext *context, QObject *parent = nullptr); ~QEventDispatcherGlib(); bool processEvents(QEventLoop::ProcessEventsFlags flags) override; @@ -102,7 +102,7 @@ class Q_CORE_EXPORT QEventDispatcherGlibPrivate : public QAbstractEventDispatche { public: - QEventDispatcherGlibPrivate(GMainContext *context = 0); + QEventDispatcherGlibPrivate(GMainContext *context = nullptr); GMainContext *mainContext; GPostEventSource *postEventSource; GSocketNotifierSource *socketNotifierSource; diff --git a/src/corelib/kernel/qeventdispatcher_unix_p.h b/src/corelib/kernel/qeventdispatcher_unix_p.h index 0fd068b074..f37edfc967 100644 --- a/src/corelib/kernel/qeventdispatcher_unix_p.h +++ b/src/corelib/kernel/qeventdispatcher_unix_p.h @@ -64,10 +64,10 @@ class QEventDispatcherUNIXPrivate; struct Q_CORE_EXPORT QSocketNotifierSetUNIX final { - inline QSocketNotifierSetUNIX() Q_DECL_NOTHROW; + inline QSocketNotifierSetUNIX() noexcept; - inline bool isEmpty() const Q_DECL_NOTHROW; - inline short events() const Q_DECL_NOTHROW; + inline bool isEmpty() const noexcept; + inline short events() const noexcept; QSocketNotifier *notifiers[3]; }; @@ -102,7 +102,7 @@ class Q_CORE_EXPORT QEventDispatcherUNIX : public QAbstractEventDispatcher Q_DECLARE_PRIVATE(QEventDispatcherUNIX) public: - explicit QEventDispatcherUNIX(QObject *parent = 0); + explicit QEventDispatcherUNIX(QObject *parent = nullptr); ~QEventDispatcherUNIX(); bool processEvents(QEventLoop::ProcessEventsFlags flags) override; @@ -123,7 +123,7 @@ public: void flush() override; protected: - QEventDispatcherUNIX(QEventDispatcherUNIXPrivate &dd, QObject *parent = 0); + QEventDispatcherUNIX(QEventDispatcherUNIXPrivate &dd, QObject *parent = nullptr); }; class Q_CORE_EXPORT QEventDispatcherUNIXPrivate : public QAbstractEventDispatcherPrivate @@ -150,19 +150,19 @@ public: QAtomicInt interrupt; // bool }; -inline QSocketNotifierSetUNIX::QSocketNotifierSetUNIX() Q_DECL_NOTHROW +inline QSocketNotifierSetUNIX::QSocketNotifierSetUNIX() noexcept { - notifiers[0] = 0; - notifiers[1] = 0; - notifiers[2] = 0; + notifiers[0] = nullptr; + notifiers[1] = nullptr; + notifiers[2] = nullptr; } -inline bool QSocketNotifierSetUNIX::isEmpty() const Q_DECL_NOTHROW +inline bool QSocketNotifierSetUNIX::isEmpty() const noexcept { return !notifiers[0] && !notifiers[1] && !notifiers[2]; } -inline short QSocketNotifierSetUNIX::events() const Q_DECL_NOTHROW +inline short QSocketNotifierSetUNIX::events() const noexcept { short result = 0; diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp index 685d765adb..84378454ca 100644 --- a/src/corelib/kernel/qeventdispatcher_win.cpp +++ b/src/corelib/kernel/qeventdispatcher_win.cpp @@ -136,7 +136,11 @@ LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPA msg.wParam = wp; msg.lParam = lp; QAbstractEventDispatcher* dispatcher = QAbstractEventDispatcher::instance(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + qintptr result; +#else long result; +#endif if (!dispatcher) { if (message == WM_TIMER) KillTimer(hwnd, wp); diff --git a/src/corelib/kernel/qfunctions_fake_env_p.h b/src/corelib/kernel/qfunctions_fake_env_p.h index 7010d2cf5d..68d17ed4a1 100644 --- a/src/corelib/kernel/qfunctions_fake_env_p.h +++ b/src/corelib/kernel/qfunctions_fake_env_p.h @@ -72,8 +72,8 @@ Q_DECLARE_TYPEINFO(Variable, Q_MOVABLE_TYPE); struct NameEquals { typedef bool result_type; const char *name; - explicit NameEquals(const char *name) Q_DECL_NOTHROW : name(name) {} - result_type operator()(const Variable &other) const Q_DECL_NOTHROW + explicit NameEquals(const char *name) noexcept : name(name) {} + result_type operator()(const Variable &other) const noexcept { return qstrcmp(other.name, name) == 0; } }; diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 8b2febbbb7..56217262f2 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -341,7 +341,7 @@ const char *QMetaObject::className() const \since 5.7 */ -bool QMetaObject::inherits(const QMetaObject *metaObject) const Q_DECL_NOEXCEPT +bool QMetaObject::inherits(const QMetaObject *metaObject) const noexcept { const QMetaObject *m = this; do { @@ -3023,6 +3023,18 @@ int QMetaProperty::propertyIndex() const } /*! + \since 5.14 + + Returns this property's index relative within the enclosing meta object. +*/ +int QMetaProperty::relativePropertyIndex() const +{ + if (!mobj) + return -1; + return idx; +} + +/*! Returns \c true if the property's type is an enumeration value that is used as a flag; otherwise returns \c false. diff --git a/src/corelib/kernel/qmetaobject.h b/src/corelib/kernel/qmetaobject.h index 51ace3d5f7..6c5f78d208 100644 --- a/src/corelib/kernel/qmetaobject.h +++ b/src/corelib/kernel/qmetaobject.h @@ -253,6 +253,7 @@ public: QVariant::Type type() const; int userType() const; int propertyIndex() const; + int relativePropertyIndex() const; bool isReadable() const; bool isWritable() const; diff --git a/src/corelib/kernel/qmetaobject_moc_p.h b/src/corelib/kernel/qmetaobject_moc_p.h index ad258acfcd..8c7900767b 100644 --- a/src/corelib/kernel/qmetaobject_moc_p.h +++ b/src/corelib/kernel/qmetaobject_moc_p.h @@ -138,7 +138,7 @@ static QByteArray normalizeTypeInternal(const char *t, const char *e, bool fixSc { "struct ", 7 }, { "class ", 6 }, { "enum ", 5 }, - { 0, 0 } + { nullptr, 0 } }; int i = 0; do { @@ -146,7 +146,7 @@ static QByteArray normalizeTypeInternal(const char *t, const char *e, bool fixSc t += optional[i].len; break; } - } while (optional[++i].keyword != 0); + } while (optional[++i].keyword != nullptr); } bool star = false; diff --git a/src/corelib/kernel/qmetaobject_p.h b/src/corelib/kernel/qmetaobject_p.h index 522bd78e42..0cd9da2eac 100644 --- a/src/corelib/kernel/qmetaobject_p.h +++ b/src/corelib/kernel/qmetaobject_p.h @@ -54,6 +54,7 @@ #include <QtCore/qglobal.h> #include <QtCore/qobjectdefs.h> +#include <QtCore/qmutex.h> #ifndef QT_NO_QOBJECT #include <private/qobject_p.h> // For QObjectPrivate::Connection #endif @@ -168,7 +169,6 @@ Q_DECLARE_TYPEINFO(QArgumentType, Q_MOVABLE_TYPE); typedef QVarLengthArray<QArgumentType, 10> QArgumentTypeArray; class QMetaMethodPrivate; -class QMutex; struct QMetaObjectPrivate { @@ -226,15 +226,15 @@ struct QMetaObjectPrivate static QObjectPrivate::Connection *connect(const QObject *sender, int signal_index, const QMetaObject *smeta, const QObject *receiver, int method_index_relative, - const QMetaObject *rmeta = 0, - int type = 0, int *types = 0); + const QMetaObject *rmeta = nullptr, + int type = 0, int *types = nullptr); static bool disconnect(const QObject *sender, int signal_index, const QMetaObject *smeta, const QObject *receiver, int method_index, void **slot, DisconnectType = DisconnectAll); - static inline bool disconnectHelper(QObjectPrivate::Connection *c, + static inline bool disconnectHelper(QObjectPrivate::ConnectionData *connections, int signalIndex, const QObject *receiver, int method_index, void **slot, - QMutex *senderMutex, DisconnectType = DisconnectAll); + QBasicMutex *senderMutex, DisconnectType = DisconnectAll); #endif }; diff --git a/src/corelib/kernel/qmetaobjectbuilder_p.h b/src/corelib/kernel/qmetaobjectbuilder_p.h index 6100835bad..6d43be7811 100644 --- a/src/corelib/kernel/qmetaobjectbuilder_p.h +++ b/src/corelib/kernel/qmetaobjectbuilder_p.h @@ -173,7 +173,7 @@ public: void setStaticMetacallFunction(QMetaObjectBuilder::StaticMetacallFunction value); QMetaObject *toMetaObject() const; - QByteArray toRelocatableData(bool * = 0) const; + QByteArray toRelocatableData(bool * = nullptr) const; static void fromRelocatableData(QMetaObject *, const QMetaObject *, const QByteArray &); #ifndef QT_NO_DATASTREAM @@ -196,7 +196,7 @@ private: class Q_CORE_EXPORT QMetaMethodBuilder { public: - QMetaMethodBuilder() : _mobj(0), _index(0) {} + QMetaMethodBuilder() : _mobj(nullptr), _index(0) {} int index() const; @@ -238,7 +238,7 @@ private: class Q_CORE_EXPORT QMetaPropertyBuilder { public: - QMetaPropertyBuilder() : _mobj(0), _index(0) {} + QMetaPropertyBuilder() : _mobj(nullptr), _index(0) {} int index() const { return _index; } @@ -294,7 +294,7 @@ private: class Q_CORE_EXPORT QMetaEnumBuilder { public: - QMetaEnumBuilder() : _mobj(0), _index(0) {} + QMetaEnumBuilder() : _mobj(nullptr), _index(0) {} int index() const { return _index; } diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 45d0b5df6c..855d36794d 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -51,6 +51,7 @@ #include "quuid.h" #include "qvariant.h" #include "qdatastream.h" +#include "qregexp.h" #include "qmetatypeswitcher_p.h" #if QT_CONFIG(regularexpression) @@ -915,7 +916,7 @@ template <int... TypeIds> struct MetaTypeOffsets<QtPrivate::IndexesList<TypeIds. short offsets[sizeof...(TypeIds)]; constexpr MetaTypeOffsets() : offsets{calculateOffsetForTypeId(TypeIds)...} {} - const char *operator[](int typeId) const Q_DECL_NOTHROW + const char *operator[](int typeId) const noexcept { short o = offsets[typeId]; return o < 0 ? nullptr : metaTypeStrings + o; diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index d03b9fafb1..73b655cb36 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Copyright (C) 2016 Intel Corporation. ** Copyright (C) 2013 Olivier Goffart <ogoffart@woboq.com> ** Contact: https://www.qt.io/licensing/ @@ -77,6 +77,12 @@ QT_BEGIN_NAMESPACE static int DIRECT_CONNECTION_ONLY = 0; +Q_CORE_EXPORT QBasicAtomicPointer<QSignalSpyCallbackSet> qt_signal_spy_callback_set = Q_BASIC_ATOMIC_INITIALIZER(nullptr); + +void qt_register_signal_spy_callbacks(QSignalSpyCallbackSet *callback_set) +{ + qt_signal_spy_callback_set.store(callback_set); +} QDynamicMetaObjectData::~QDynamicMetaObjectData() { @@ -146,10 +152,9 @@ static QBasicMutex _q_ObjectMutexPool[131]; * \internal * mutex to be locked when accessing the connectionlists or the senders list */ -static inline QMutex *signalSlotLock(const QObject *o) +static inline QBasicMutex *signalSlotLock(const QObject *o) { - return static_cast<QMutex *>(&_q_ObjectMutexPool[ - uint(quintptr(o)) % sizeof(_q_ObjectMutexPool)/sizeof(QBasicMutex)]); + return &_q_ObjectMutexPool[uint(quintptr(o)) % sizeof(_q_ObjectMutexPool)/sizeof(QBasicMutex)]; } #if QT_VERSION < 0x60000 @@ -160,39 +165,6 @@ extern "C" Q_CORE_EXPORT void qt_removeObject(QObject *) {} #endif -struct QConnectionSenderSwitcher { - QObject *receiver; - QObjectPrivate::Sender *previousSender; - QObjectPrivate::Sender currentSender; - bool switched; - - inline QConnectionSenderSwitcher() : switched(false) {} - - inline QConnectionSenderSwitcher(QObject *receiver, QObject *sender, int signal_absolute_id) - { - switchSender(receiver, sender, signal_absolute_id); - } - - inline void switchSender(QObject *receiver, QObject *sender, int signal_absolute_id) - { - this->receiver = receiver; - currentSender.sender = sender; - currentSender.signal = signal_absolute_id; - currentSender.ref = 1; - previousSender = QObjectPrivate::setCurrentSender(receiver, ¤tSender); - switched = true; - } - - inline ~QConnectionSenderSwitcher() - { - if (switched) - QObjectPrivate::resetCurrentSender(receiver, ¤tSender, previousSender); - } -private: - Q_DISABLE_COPY(QConnectionSenderSwitcher) -}; - - void (*QAbstractDeclarativeData::destroyed)(QAbstractDeclarativeData *, QObject *) = 0; void (*QAbstractDeclarativeData::destroyed_qml1)(QAbstractDeclarativeData *, QObject *) = 0; void (*QAbstractDeclarativeData::parentChanged)(QAbstractDeclarativeData *, QObject *, QObject *) = 0; @@ -209,7 +181,7 @@ QMetaObject *QObjectData::dynamicMetaObject() const } QObjectPrivate::QObjectPrivate(int version) - : threadData(0), connectionLists(0), senders(0), currentSender(0), currentChildBeingDeleted(0) + : threadData(0), currentChildBeingDeleted(0) { #ifdef QT_BUILD_INTERNAL // Don't check the version parameter in internal builds. @@ -232,7 +204,6 @@ QObjectPrivate::QObjectPrivate(int version) receiveChildEvents = true; postedEvents = 0; extraData = 0; - connectedSignals[0] = connectedSignals[1] = 0; metaObject = 0; isWindow = false; deleteLaterCalled = false; @@ -285,59 +256,22 @@ static void computeOffsets(const QMetaObject *metaobject, int *signalOffset, int } } -/* - This vector contains the all connections from an object. - - Each object may have one vector containing the lists of - connections for a given signal. The index in the vector correspond - to the signal index. The signal index is the one returned by - QObjectPrivate::signalIndex (not QMetaObject::indexOfSignal). - Negative index means connections to all signals. - - This vector is protected by the object mutex (signalSlotMutexes()) - - Each Connection is also part of a 'senders' linked list. The mutex - of the receiver must be locked when touching the pointers of this - linked list. -*/ -class QObjectConnectionListVector : public QVector<QObjectPrivate::ConnectionList> -{ -public: - bool orphaned; //the QObject owner of this vector has been destroyed while the vector was inUse - bool dirty; //some Connection have been disconnected (their receiver is 0) but not removed from the list yet - int inUse; //number of functions that are currently accessing this object or its connections - QObjectPrivate::ConnectionList allsignals; - - QObjectConnectionListVector() - : QVector<QObjectPrivate::ConnectionList>(), orphaned(false), dirty(false), inUse(0) - { } - - QObjectPrivate::ConnectionList &operator[](int at) - { - if (at < 0) - return allsignals; - return QVector<QObjectPrivate::ConnectionList>::operator[](at); - } -}; - // Used by QAccessibleWidget bool QObjectPrivate::isSender(const QObject *receiver, const char *signal) const { Q_Q(const QObject); int signal_index = signalIndex(signal); - if (signal_index < 0) + ConnectionData *cd = connections.load(); + if (signal_index < 0 || !cd) return false; - QMutexLocker locker(signalSlotLock(q)); - if (connectionLists) { - if (signal_index < connectionLists->count()) { - const QObjectPrivate::Connection *c = - connectionLists->at(signal_index).first; - - while (c) { - if (c->receiver == receiver) - return true; - c = c->nextConnectionList; - } + QBasicMutexLocker locker(signalSlotLock(q)); + if (signal_index < cd->signalVectorCount()) { + const QObjectPrivate::Connection *c = cd->signalVector.load()->at(signal_index).first.load(); + + while (c) { + if (c->receiver.load() == receiver) + return true; + c = c->nextConnectionList.load(); } } return false; @@ -346,21 +280,19 @@ bool QObjectPrivate::isSender(const QObject *receiver, const char *signal) const // Used by QAccessibleWidget QObjectList QObjectPrivate::receiverList(const char *signal) const { - Q_Q(const QObject); QObjectList returnValue; int signal_index = signalIndex(signal); - if (signal_index < 0) + ConnectionData *cd = connections.load(); + if (signal_index < 0 || !cd) return returnValue; - QMutexLocker locker(signalSlotLock(q)); - if (connectionLists) { - if (signal_index < connectionLists->count()) { - const QObjectPrivate::Connection *c = connectionLists->at(signal_index).first; - - while (c) { - if (c->receiver) - returnValue << c->receiver; - c = c->nextConnectionList; - } + if (signal_index < cd->signalVectorCount()) { + const QObjectPrivate::Connection *c = cd->signalVector.load()->at(signal_index).first.load(); + + while (c) { + QObject *r = c->receiver.load(); + if (r) + returnValue << r; + c = c->nextConnectionList.load(); } } return returnValue; @@ -370,9 +302,12 @@ QObjectList QObjectPrivate::receiverList(const char *signal) const QObjectList QObjectPrivate::senderList() const { QObjectList returnValue; - QMutexLocker locker(signalSlotLock(q_func())); - for (Connection *c = senders; c; c = c->next) - returnValue << c->sender; + ConnectionData *cd = connections.load(); + if (cd) { + QBasicMutexLocker locker(signalSlotLock(q_func())); + for (Connection *c = cd->senders; c; c = c->next) + returnValue << c->sender; + } return returnValue; } @@ -389,79 +324,187 @@ QObjectList QObjectPrivate::senderList() const void QObjectPrivate::addConnection(int signal, Connection *c) { Q_ASSERT(c->sender == q_ptr); - if (!connectionLists) - connectionLists = new QObjectConnectionListVector(); - if (signal >= connectionLists->count()) - connectionLists->resize(signal + 1); - - ConnectionList &connectionList = (*connectionLists)[signal]; - if (connectionList.last) { - connectionList.last->nextConnectionList = c; + ensureConnectionData(); + ConnectionData *cd = connections.load(); + cd->resizeSignalVector(signal + 1); + + ConnectionList &connectionList = cd->connectionsForSignal(signal); + if (connectionList.last.load()) { + Q_ASSERT(connectionList.last.load()->receiver.load()); + connectionList.last.load()->nextConnectionList.store(c); } else { - connectionList.first = c; + connectionList.first.store(c); } - connectionList.last = c; + c->id = ++cd->currentConnectionId; + c->prevConnectionList = connectionList.last.load(); + connectionList.last.store(c); - cleanConnectionLists(); + QObjectPrivate *rd = QObjectPrivate::get(c->receiver.load()); + rd->ensureConnectionData(); - c->prev = &(QObjectPrivate::get(c->receiver)->senders); + c->prev = &(rd->connections.load()->senders); c->next = *c->prev; *c->prev = c; if (c->next) c->next->prev = &c->next; +} + +void QObjectPrivate::ConnectionData::removeConnection(QObjectPrivate::Connection *c) +{ + Q_ASSERT(c->receiver.load()); + ConnectionList &connections = signalVector.load()->at(c->signal_index); + c->receiver.store(nullptr); + QThreadData *td = c->receiverThreadData.load(); + if (td) + td->deref(); + c->receiverThreadData.store(nullptr); - if (signal < 0) { - connectedSignals[0] = connectedSignals[1] = ~0; - } else if (signal < (int)sizeof(connectedSignals) * 8) { - connectedSignals[signal >> 5] |= (1 << (signal & 0x1f)); +#ifndef QT_NO_DEBUG + bool found = false; + for (Connection *cc = connections.first.load(); cc; cc = cc->nextConnectionList.load()) { + if (cc == c) { + found = true; + break; + } } + Q_ASSERT(found); +#endif + + // remove from the senders linked list + *c->prev = c->next; + if (c->next) + c->next->prev = c->prev; + c->prev = nullptr; + + if (connections.first.load() == c) + connections.first.store(c->nextConnectionList.load()); + if (connections.last.load() == c) + connections.last.store(c->prevConnectionList); + Q_ASSERT(signalVector.load()->at(c->signal_index).first.load() != c); + Q_ASSERT(signalVector.load()->at(c->signal_index).last.load() != c); + + // keep c->nextConnectionList intact, as it might still get accessed by activate + Connection *n = c->nextConnectionList.load(); + if (n) + n->prevConnectionList = c->prevConnectionList; + if (c->prevConnectionList) + c->prevConnectionList->nextConnectionList.store(n); + c->prevConnectionList = nullptr; + + Q_ASSERT(c != orphaned.load()); + // add c to orphanedConnections + c->nextInOrphanList = orphaned.load(); + orphaned.store(c); + +#ifndef QT_NO_DEBUG + found = false; + for (Connection *cc = connections.first.load(); cc; cc = cc->nextConnectionList.load()) { + if (cc == c) { + found = true; + break; + } + } + Q_ASSERT(!found); +#endif + } -void QObjectPrivate::cleanConnectionLists() +void QObjectPrivate::ConnectionData::cleanOrphanedConnectionsImpl(QObject *sender) { - if (connectionLists->dirty && !connectionLists->inUse) { - // remove broken connections - bool allConnected = false; - for (int signal = -1; signal < connectionLists->count(); ++signal) { - QObjectPrivate::ConnectionList &connectionList = - (*connectionLists)[signal]; - - // Set to the last entry in the connection list that was *not* - // deleted. This is needed to update the list's last pointer - // at the end of the cleanup. - QObjectPrivate::Connection *last = 0; - - QObjectPrivate::Connection **prev = &connectionList.first; - QObjectPrivate::Connection *c = *prev; - bool connected = false; // whether the signal is still connected somewhere - while (c) { - if (c->receiver) { - last = c; - prev = &c->nextConnectionList; - c = *prev; - connected = true; - } else { - QObjectPrivate::Connection *next = c->nextConnectionList; - *prev = next; - c->deref(); - c = next; - } - } + ConnectionOrSignalVector *c = nullptr; + { + QBasicMutexLocker l(signalSlotLock(sender)); + if (ref > 1) + return; - // Correct the connection list's last pointer. - // As conectionList.last could equal last, this could be a noop - connectionList.last = last; + // Since ref == 1, no activate() is in process since we locked the mutex. That implies, + // that nothing can reference the orphaned connection objects anymore and they can + // be safely deleted + c = orphaned.load(); + orphaned.store(nullptr); + } + deleteOrphaned(c); +} - if (!allConnected && !connected && signal >= 0 - && size_t(signal) < sizeof(connectedSignals) * 8) { - // This signal is no longer connected - connectedSignals[signal >> 5] &= ~(1 << (signal & 0x1f)); - } else if (signal == -1) { - allConnected = connected; - } +void QObjectPrivate::ConnectionData::deleteOrphaned(QObjectPrivate::ConnectionOrSignalVector *o) +{ + while (o) { + QObjectPrivate::ConnectionOrSignalVector *next = nullptr; + if (SignalVector *v = ConnectionOrSignalVector::asSignalVector(o)) { + next = v->nextInOrphanList; + free(v); + } else { + QObjectPrivate::Connection *c = static_cast<Connection *>(o); + next = c->nextInOrphanList; + Q_ASSERT(!c->receiver.load()); + Q_ASSERT(!c->prev); + c->freeSlotObject(); + c->deref(); } - connectionLists->dirty = false; + o = next; + } +} + +/*! \internal + + Returns \c true if the signal with index \a signal_index from object \a sender is connected. + + \a signal_index must be the index returned by QObjectPrivate::signalIndex; +*/ +bool QObjectPrivate::isSignalConnected(uint signalIndex, bool checkDeclarative) const +{ + if (checkDeclarative && isDeclarativeSignalConnected(signalIndex)) + return true; + + ConnectionData *cd = connections.load(); + if (!cd) + return false; + SignalVector *signalVector = cd->signalVector.load(); + if (!signalVector) + return false; + + if (signalVector->at(-1).first.load()) + return true; + + if (signalIndex < uint(cd->signalVectorCount())) { + const QObjectPrivate::Connection *c = signalVector->at(signalIndex).first.load(); + while (c) { + if (c->receiver.load()) + return true; + c = c->nextConnectionList.load(); + } + } + return false; +} + +bool QObjectPrivate::maybeSignalConnected(uint signalIndex) const +{ + ConnectionData *cd = connections.load(); + if (!cd) + return false; + SignalVector *signalVector = cd->signalVector.load(); + if (!signalVector) + return false; + + if (signalVector->at(-1).first) + return true; + + if (signalIndex < uint(cd->signalVectorCount())) { + const QObjectPrivate::Connection *c = signalVector->at(signalIndex).first; + return c != nullptr; } + return false; +} + +/*! + \internal + */ +QAbstractMetaCallEvent::~QAbstractMetaCallEvent() +{ +#if QT_CONFIG(thread) + if (semaphore_) + semaphore_->release(); +#endif } /*! @@ -470,8 +513,8 @@ void QObjectPrivate::cleanConnectionLists() QMetaCallEvent::QMetaCallEvent(ushort method_offset, ushort method_relative, QObjectPrivate::StaticMetaCallFunction callFunction, const QObject *sender, int signalId, int nargs, int *types, void **args, QSemaphore *semaphore) - : QEvent(MetaCall), slotObj_(0), sender_(sender), signalId_(signalId), - nargs_(nargs), types_(types), args_(args), semaphore_(semaphore), + : QAbstractMetaCallEvent(sender, signalId, semaphore), + slotObj_(nullptr), nargs_(nargs), types_(types), args_(args), callFunction_(callFunction), method_offset_(method_offset), method_relative_(method_relative) { } @@ -480,9 +523,9 @@ QMetaCallEvent::QMetaCallEvent(ushort method_offset, ushort method_relative, QOb */ QMetaCallEvent::QMetaCallEvent(QtPrivate::QSlotObjectBase *slotO, const QObject *sender, int signalId, int nargs, int *types, void **args, QSemaphore *semaphore) - : QEvent(MetaCall), slotObj_(slotO), sender_(sender), signalId_(signalId), - nargs_(nargs), types_(types), args_(args), semaphore_(semaphore), - callFunction_(0), method_offset_(0), method_relative_(ushort(-1)) + : QAbstractMetaCallEvent(sender, signalId, semaphore), + slotObj_(slotO), nargs_(nargs), types_(types), args_(args), + callFunction_(nullptr), method_offset_(0), method_relative_(ushort(-1)) { if (slotObj_) slotObj_->ref(); @@ -501,10 +544,6 @@ QMetaCallEvent::~QMetaCallEvent() free(types_); free(args_); } -#if QT_CONFIG(thread) - if (semaphore_) - semaphore_->release(); -#endif if (slotObj_) slotObj_->destroyIfLastRef(); } @@ -921,92 +960,56 @@ QObject::~QObject() } } - // set ref to zero to indicate that this object has been deleted - if (d->currentSender != 0) - d->currentSender->ref = 0; - d->currentSender = 0; + QObjectPrivate::ConnectionData *cd = d->connections.load(); + if (cd) { + if (cd->currentSender) { + cd->currentSender->receiverDeleted(); + cd->currentSender = nullptr; + } - if (d->connectionLists || d->senders) { - QMutex *signalSlotMutex = signalSlotLock(this); - QMutexLocker locker(signalSlotMutex); + QBasicMutex *signalSlotMutex = signalSlotLock(this); + QBasicMutexLocker locker(signalSlotMutex); // disconnect all receivers - if (d->connectionLists) { - ++d->connectionLists->inUse; - int connectionListsCount = d->connectionLists->count(); - for (int signal = -1; signal < connectionListsCount; ++signal) { - QObjectPrivate::ConnectionList &connectionList = - (*d->connectionLists)[signal]; - - while (QObjectPrivate::Connection *c = connectionList.first) { - if (!c->receiver) { - connectionList.first = c->nextConnectionList; - c->deref(); - continue; - } + int receiverCount = cd->signalVectorCount(); + for (int signal = -1; signal < receiverCount; ++signal) { + QObjectPrivate::ConnectionList &connectionList = cd->connectionsForSignal(signal); - QMutex *m = signalSlotLock(c->receiver); - bool needToUnlock = QOrderedMutexLocker::relock(signalSlotMutex, m); + while (QObjectPrivate::Connection *c = connectionList.first.load()) { + Q_ASSERT(c->receiver); - if (c->receiver) { - *c->prev = c->next; - if (c->next) c->next->prev = c->prev; - } - c->receiver = 0; - if (needToUnlock) - m->unlock(); - - connectionList.first = c->nextConnectionList; - - // The destroy operation must happen outside the lock - if (c->isSlotObject) { - c->isSlotObject = false; - locker.unlock(); - c->slotObj->destroyIfLastRef(); - locker.relock(); - } - c->deref(); + QBasicMutex *m = signalSlotLock(c->receiver.load()); + bool needToUnlock = QOrderedMutexLocker::relock(signalSlotMutex, m); + if (c->receiver) { + cd->removeConnection(c); + Q_ASSERT(connectionList.first.load() != c); } + if (needToUnlock) + m->unlock(); } - - if (!--d->connectionLists->inUse) { - delete d->connectionLists; - } else { - d->connectionLists->orphaned = true; - } - d->connectionLists = 0; } /* Disconnect all senders: - * This loop basically just does - * for (node = d->senders; node; node = node->next) { ... } - * - * We need to temporarily unlock the receiver mutex to destroy the functors or to lock the - * sender's mutex. And when the mutex is released, node->next might be destroyed by another - * thread. That's why we set node->prev to &node, that way, if node is destroyed, node will - * be updated. */ - QObjectPrivate::Connection *node = d->senders; - while (node) { + while (QObjectPrivate::Connection *node = cd->senders) { + Q_ASSERT(node->receiver); QObject *sender = node->sender; // Send disconnectNotify before removing the connection from sender's connection list. // This ensures any eventual destructor of sender will block on getting receiver's lock // and not finish until we release it. sender->disconnectNotify(QMetaObjectPrivate::signal(sender->metaObject(), node->signal_index)); - QMutex *m = signalSlotLock(sender); - node->prev = &node; + QBasicMutex *m = signalSlotLock(sender); bool needToUnlock = QOrderedMutexLocker::relock(signalSlotMutex, m); //the node has maybe been removed while the mutex was unlocked in relock? - if (!node || node->sender != sender) { + if (node != cd->senders) { // We hold the wrong mutex Q_ASSERT(needToUnlock); m->unlock(); continue; } - node->receiver = 0; - QObjectConnectionListVector *senderLists = sender->d_func()->connectionLists; - if (senderLists) - senderLists->dirty = true; + + QObjectPrivate::ConnectionData *senderData = sender->d_func()->connections.load(); + Q_ASSERT(senderData); QtPrivate::QSlotObjectBase *slotObj = nullptr; if (node->isSlotObject) { @@ -1014,19 +1017,24 @@ QObject::~QObject() node->isSlotObject = false; } - node = node->next; + senderData->removeConnection(node); if (needToUnlock) m->unlock(); if (slotObj) { - if (node) - node->prev = &node; locker.unlock(); slotObj->destroyIfLastRef(); locker.relock(); } } + + // invalidate all connections on the object and make sure + // activate() will skip them + cd->currentConnectionId.store(0); } + if (cd && !cd->ref.deref()) + delete cd; + d->connections.store(nullptr); if (!d->children.isEmpty()) d->deleteChildren(); @@ -1253,9 +1261,13 @@ bool QObject::event(QEvent *e) case QEvent::MetaCall: { - QMetaCallEvent *mce = static_cast<QMetaCallEvent*>(e); + QAbstractMetaCallEvent *mce = static_cast<QAbstractMetaCallEvent*>(e); - QConnectionSenderSwitcher sw(this, const_cast<QObject*>(mce->sender()), mce->signalId()); + if (!d_func()->connections.load()) { + QBasicMutexLocker locker(signalSlotLock(this)); + d_func()->ensureConnectionData(); + } + QObjectPrivate::Sender sender(this, const_cast<QObject*>(mce->sender()), mce->signalId()); mce->placeMetaCall(this); break; @@ -1415,7 +1427,7 @@ bool QObject::eventFilter(QObject * /* watched */, QEvent * /* event */) \sa signalsBlocked(), QSignalBlocker */ -bool QObject::blockSignals(bool block) Q_DECL_NOTHROW +bool QObject::blockSignals(bool block) noexcept { Q_D(QObject); bool previous = d->blockSig; @@ -1510,6 +1522,9 @@ void QObject::moveToThread(QThread *targetThread) if (!targetData) targetData = new QThreadData(0); + // make sure nobody adds/removes connections to this object while we're moving it + QMutexLocker l(signalSlotLock(this)); + QOrderedMutexLocker locker(¤tData->postEventList.mutex, &targetData->postEventList.mutex); @@ -1559,9 +1574,31 @@ void QObjectPrivate::setThreadData_helper(QThreadData *currentData, QThreadData } // the current emitting thread shouldn't restore currentSender after calling moveToThread() - if (currentSender) - currentSender->ref = 0; - currentSender = 0; + ConnectionData *cd = connections.load(); + if (cd) { + if (cd->currentSender) { + cd->currentSender->receiverDeleted(); + cd->currentSender = nullptr; + } + + // adjust the receiverThreadId values in the Connections + if (cd) { + auto *c = cd->senders; + while (c) { + QObject *r = c->receiver.load(); + if (r) { + Q_ASSERT(r == q); + targetData->ref(); + QThreadData *old = c->receiverThreadData.load(); + if (old) + old->deref(); + c->receiverThreadData.store(targetData); + } + c = c->next; + } + } + + } // set new thread data targetData->ref(); @@ -2370,13 +2407,14 @@ QObject *QObject::sender() const { Q_D(const QObject); - QMutexLocker locker(signalSlotLock(this)); - if (!d->currentSender) - return 0; + QBasicMutexLocker locker(signalSlotLock(this)); + QObjectPrivate::ConnectionData *cd = d->connections.load(); + if (!cd || !cd->currentSender) + return nullptr; - for (QObjectPrivate::Connection *c = d->senders; c; c = c->next) { - if (c->sender == d->currentSender->sender) - return d->currentSender->sender; + for (QObjectPrivate::Connection *c = cd->senders; c; c = c->next) { + if (c->sender == cd->currentSender->sender) + return cd->currentSender->sender; } return 0; @@ -2411,14 +2449,15 @@ int QObject::senderSignalIndex() const { Q_D(const QObject); - QMutexLocker locker(signalSlotLock(this)); - if (!d->currentSender) + QBasicMutexLocker locker(signalSlotLock(this)); + QObjectPrivate::ConnectionData *cd = d->connections.load(); + if (!cd || !cd->currentSender) return -1; - for (QObjectPrivate::Connection *c = d->senders; c; c = c->next) { - if (c->sender == d->currentSender->sender) { + for (QObjectPrivate::Connection *c = cd->senders; c; c = c->next) { + if (c->sender == cd->currentSender->sender) { // Convert from signal range to method range - return QMetaObjectPrivate::signal(c->sender->metaObject(), d->currentSender->signal).methodIndex(); + return QMetaObjectPrivate::signal(c->sender->metaObject(), cd->currentSender->signal).methodIndex(); } } @@ -2474,15 +2513,13 @@ int QObject::receivers(const char *signal) const signal_index); } - QMutexLocker locker(signalSlotLock(this)); - if (d->connectionLists) { - if (signal_index < d->connectionLists->count()) { - const QObjectPrivate::Connection *c = - d->connectionLists->at(signal_index).first; - while (c) { - receivers += c->receiver ? 1 : 0; - c = c->nextConnectionList; - } + QObjectPrivate::ConnectionData *cd = d->connections.load(); + QBasicMutexLocker locker(signalSlotLock(this)); + if (cd && signal_index < cd->signalVectorCount()) { + const QObjectPrivate::Connection *c = cd->signalVector.load()->at(signal_index).first.load(); + while (c) { + receivers += c->receiver.load() ? 1 : 0; + c = c->nextConnectionList.load(); } } } @@ -2522,22 +2559,8 @@ bool QObject::isSignalConnected(const QMetaMethod &signal) const signalIndex += QMetaObjectPrivate::signalOffset(signal.mobj); - QMutexLocker locker(signalSlotLock(this)); - if (d->connectionLists) { - if (signalIndex < sizeof(d->connectedSignals) * 8 && !d->connectionLists->dirty) - return d->isSignalConnected(signalIndex); - - if (signalIndex < uint(d->connectionLists->count())) { - const QObjectPrivate::Connection *c = - d->connectionLists->at(signalIndex).first; - while (c) { - if (c->receiver) - return true; - c = c->nextConnectionList; - } - } - } - return d->isDeclarativeSignalConnected(signalIndex); + QBasicMutexLocker locker(signalSlotLock(this)); + return d->isSignalConnected(signalIndex, true); } /*! @@ -3300,24 +3323,22 @@ QObjectPrivate::Connection *QMetaObjectPrivate::connect(const QObject *sender, int method_offset = rmeta ? rmeta->methodOffset() : 0; Q_ASSERT(!rmeta || QMetaObjectPrivate::get(rmeta)->revision >= 6); - QObjectPrivate::StaticMetaCallFunction callFunction = - rmeta ? rmeta->d.static_metacall : 0; + QObjectPrivate::StaticMetaCallFunction callFunction = rmeta ? rmeta->d.static_metacall : nullptr; QOrderedMutexLocker locker(signalSlotLock(sender), signalSlotLock(receiver)); - if (type & Qt::UniqueConnection) { - QObjectConnectionListVector *connectionLists = QObjectPrivate::get(s)->connectionLists; - if (connectionLists && connectionLists->count() > signal_index) { - const QObjectPrivate::Connection *c2 = - (*connectionLists)[signal_index].first; + QObjectPrivate::ConnectionData *scd = QObjectPrivate::get(s)->connections.load(); + if (type & Qt::UniqueConnection && scd) { + if (scd->signalVectorCount() > signal_index) { + const QObjectPrivate::Connection *c2 = scd->signalVector.load()->at(signal_index).first.load(); int method_index_absolute = method_index + method_offset; while (c2) { - if (!c2->isSlotObject && c2->receiver == receiver && c2->method() == method_index_absolute) - return 0; - c2 = c2->nextConnectionList; + if (!c2->isSlotObject && c2->receiver.load() == receiver && c2->method() == method_index_absolute) + return nullptr; + c2 = c2->nextConnectionList.load(); } } type &= Qt::UniqueConnection - 1; @@ -3326,13 +3347,15 @@ QObjectPrivate::Connection *QMetaObjectPrivate::connect(const QObject *sender, QScopedPointer<QObjectPrivate::Connection> c(new QObjectPrivate::Connection); c->sender = s; c->signal_index = signal_index; - c->receiver = r; + c->receiver.store(r); + QThreadData *td = r->d_func()->threadData; + td->ref(); + c->receiverThreadData.store(td); c->method_relative = method_index; c->method_offset = method_offset; c->connectionType = type; c->isSlotObject = false; c->argumentTypes.store(types); - c->nextConnectionList = 0; c->callFunction = callFunction; QObjectPrivate::get(s)->addConnection(signal_index, c.data()); @@ -3378,47 +3401,38 @@ bool QMetaObject::disconnectOne(const QObject *sender, int signal_index, \internal Helper function to remove the connection from the senders list and setting the receivers to 0 */ -bool QMetaObjectPrivate::disconnectHelper(QObjectPrivate::Connection *c, +bool QMetaObjectPrivate::disconnectHelper(QObjectPrivate::ConnectionData *connections, int signalIndex, const QObject *receiver, int method_index, void **slot, - QMutex *senderMutex, DisconnectType disconnectType) + QBasicMutex *senderMutex, DisconnectType disconnectType) { bool success = false; + + auto &connectionList = connections->connectionsForSignal(signalIndex); + auto *c = connectionList.first.load(); while (c) { - if (c->receiver - && (receiver == 0 || (c->receiver == receiver + QObject *r = c->receiver.load(); + if (r && (receiver == nullptr || (r == receiver && (method_index < 0 || (!c->isSlotObject && c->method() == method_index)) - && (slot == 0 || (c->isSlotObject && c->slotObj->compare(slot)))))) { + && (slot == nullptr || (c->isSlotObject && c->slotObj->compare(slot)))))) { bool needToUnlock = false; - QMutex *receiverMutex = 0; - if (c->receiver) { - receiverMutex = signalSlotLock(c->receiver); + QBasicMutex *receiverMutex = nullptr; + if (r) { + receiverMutex = signalSlotLock(r); // need to relock this receiver and sender in the correct order needToUnlock = QOrderedMutexLocker::relock(senderMutex, receiverMutex); } - if (c->receiver) { - *c->prev = c->next; - if (c->next) - c->next->prev = c->prev; - } + if (c->receiver.load()) + connections->removeConnection(c); if (needToUnlock) receiverMutex->unlock(); - c->receiver = 0; - - if (c->isSlotObject) { - c->isSlotObject = false; - senderMutex->unlock(); - c->slotObj->destroyIfLastRef(); - senderMutex->lock(); - } - success = true; if (disconnectType == DisconnectOne) return success; } - c = c->nextConnectionList; + c = c->nextConnectionList.load(); } return success; } @@ -3437,43 +3451,34 @@ bool QMetaObjectPrivate::disconnect(const QObject *sender, QObject *s = const_cast<QObject *>(sender); - QMutex *senderMutex = signalSlotLock(sender); - QMutexLocker locker(senderMutex); + QBasicMutex *senderMutex = signalSlotLock(sender); + QBasicMutexLocker locker(senderMutex); - QObjectConnectionListVector *connectionLists = QObjectPrivate::get(s)->connectionLists; - if (!connectionLists) + QObjectPrivate::ConnectionData *scd = QObjectPrivate::get(s)->connections.load(); + if (!scd) return false; - // prevent incoming connections changing the connectionLists while unlocked - ++connectionLists->inUse; - bool success = false; - if (signal_index < 0) { - // remove from all connection lists - for (int sig_index = -1; sig_index < connectionLists->count(); ++sig_index) { - QObjectPrivate::Connection *c = - (*connectionLists)[sig_index].first; - if (disconnectHelper(c, receiver, method_index, slot, senderMutex, disconnectType)) { - success = true; - connectionLists->dirty = true; + { + // prevent incoming connections changing the connections->receivers while unlocked + QObjectPrivate::ConnectionDataPointer connections(scd); + + if (signal_index < 0) { + // remove from all connection lists + for (int sig_index = -1; sig_index < scd->signalVectorCount(); ++sig_index) { + if (disconnectHelper(connections.data(), sig_index, receiver, method_index, slot, senderMutex, disconnectType)) + success = true; } - } - } else if (signal_index < connectionLists->count()) { - QObjectPrivate::Connection *c = - (*connectionLists)[signal_index].first; - if (disconnectHelper(c, receiver, method_index, slot, senderMutex, disconnectType)) { - success = true; - connectionLists->dirty = true; + } else if (signal_index < scd->signalVectorCount()) { + if (disconnectHelper(connections.data(), signal_index, receiver, method_index, slot, senderMutex, disconnectType)) + success = true; } } - --connectionLists->inUse; - Q_ASSERT(connectionLists->inUse >= 0); - if (connectionLists->orphaned && !connectionLists->inUse) - delete connectionLists; - locker.unlock(); if (success) { + scd->cleanOrphanedConnections(s); + QMetaMethod smethod = QMetaObjectPrivate::signal(smeta, signal_index); if (smethod.isValid()) s->disconnectNotify(smethod); @@ -3589,8 +3594,7 @@ void QMetaObject::connectSlotsByName(QObject *o) \a signal must be in the signal index range (see QObjectPrivate::signalIndex()). */ -static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connection *c, void **argv, - QMutexLocker &locker) +static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connection *c, void **argv) { const int *argumentTypes = c->argumentTypes.load(); if (!argumentTypes) { @@ -3620,134 +3624,111 @@ static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connect for (int n = 1; n < nargs; ++n) types[n] = argumentTypes[n-1]; - locker.unlock(); for (int n = 1; n < nargs; ++n) args[n] = QMetaType::create(types[n], argv[n]); - locker.relock(); - - if (!c->receiver) { - locker.unlock(); - // we have been disconnected while the mutex was unlocked - for (int n = 1; n < nargs; ++n) - QMetaType::destroy(types[n], args[n]); - free(types); - free(args); - locker.relock(); - return; - } + } + + QBasicMutexLocker locker(signalSlotLock(c->receiver.load())); + if (!c->receiver.load()) { + // the connection has been disconnected before we got the lock + locker.unlock(); + for (int n = 1; n < nargs; ++n) + QMetaType::destroy(types[n], args[n]); + free(types); + free(args); + return; } QMetaCallEvent *ev = c->isSlotObject ? new QMetaCallEvent(c->slotObj, sender, signal, nargs, types, args) : new QMetaCallEvent(c->method_offset, c->method_relative, c->callFunction, sender, signal, nargs, types, args); - QCoreApplication::postEvent(c->receiver, ev); + QCoreApplication::postEvent(c->receiver.load(), ev); } -/*! - \internal - */ -void QMetaObject::activate(QObject *sender, const QMetaObject *m, int local_signal_index, - void **argv) -{ - activate(sender, QMetaObjectPrivate::signalOffset(m), local_signal_index, argv); -} - -/*! - \internal - */ -void QMetaObject::activate(QObject *sender, int signalOffset, int local_signal_index, void **argv) +template <bool callbacks_enabled> +void doActivate(QObject *sender, int signal_index, void **argv) { - int signal_index = signalOffset + local_signal_index; + QObjectPrivate *sp = QObjectPrivate::get(sender); - if (sender->d_func()->blockSig) + if (sp->blockSig) return; - if (sender->d_func()->isDeclarativeSignalConnected(signal_index) + if (sp->isDeclarativeSignalConnected(signal_index) && QAbstractDeclarativeData::signalEmitted) { Q_TRACE(QMetaObject_activate_begin_declarative_signal, sender, signal_index); - QAbstractDeclarativeData::signalEmitted(sender->d_func()->declarativeData, sender, + QAbstractDeclarativeData::signalEmitted(sp->declarativeData, sender, signal_index, argv); Q_TRACE(QMetaObject_activate_end_declarative_signal, sender, signal_index); } - if (!sender->d_func()->isSignalConnected(signal_index, /*checkDeclarative =*/ false) - && !qt_signal_spy_callback_set.signal_begin_callback - && !qt_signal_spy_callback_set.signal_end_callback - && !Q_TRACE_ENABLED(QMetaObject_activate_begin_signal) - && !Q_TRACE_ENABLED(QMetaObject_activate_end_signal)) { - // The possible declarative connection is done, and nothing else is connected, so: - return; - } + const QSignalSpyCallbackSet *signal_spy_set = callbacks_enabled ? qt_signal_spy_callback_set.load() : nullptr; void *empty_argv[] = { nullptr }; if (!argv) argv = empty_argv; - if (qt_signal_spy_callback_set.signal_begin_callback != 0) { - qt_signal_spy_callback_set.signal_begin_callback(sender, signal_index, argv); + if (!sp->maybeSignalConnected(signal_index)) { + // The possible declarative connection is done, and nothing else is connected + if (callbacks_enabled && signal_spy_set->signal_begin_callback != nullptr) + signal_spy_set->signal_begin_callback(sender, signal_index, argv); + Q_TRACE(QMetaObject_activate_begin_signal, sender, signal_index); + Q_TRACE(QMetaObject_activate_end_signal, sender, signal_index); + if (callbacks_enabled && signal_spy_set->signal_end_callback != nullptr) + signal_spy_set->signal_end_callback(sender, signal_index); + return; } + + if (callbacks_enabled && signal_spy_set->signal_begin_callback != nullptr) + signal_spy_set->signal_begin_callback(sender, signal_index, argv); Q_TRACE(QMetaObject_activate_begin_signal, sender, signal_index); + bool senderDeleted = false; { - QMutexLocker locker(signalSlotLock(sender)); - struct ConnectionListsRef { - QObjectConnectionListVector *connectionLists; - ConnectionListsRef(QObjectConnectionListVector *connectionLists) : connectionLists(connectionLists) - { - if (connectionLists) - ++connectionLists->inUse; - } - ~ConnectionListsRef() - { - if (!connectionLists) - return; - - --connectionLists->inUse; - Q_ASSERT(connectionLists->inUse >= 0); - if (connectionLists->orphaned) { - if (!connectionLists->inUse) - delete connectionLists; - } - } - - QObjectConnectionListVector *operator->() const { return connectionLists; } - }; - ConnectionListsRef connectionLists = sender->d_func()->connectionLists; - if (!connectionLists.connectionLists) { - locker.unlock(); - if (qt_signal_spy_callback_set.signal_end_callback != 0) - qt_signal_spy_callback_set.signal_end_callback(sender, signal_index); - Q_TRACE(QMetaObject_activate_end_signal, sender, signal_index); - return; - } + Q_ASSERT(sp->connections); + QObjectPrivate::ConnectionDataPointer connections(sp->connections.load()); + QObjectPrivate::SignalVector *signalVector = connections->signalVector.load(); const QObjectPrivate::ConnectionList *list; - if (signal_index < connectionLists->count()) - list = &connectionLists->at(signal_index); + if (signal_index < signalVector->count()) + list = &signalVector->at(signal_index); else - list = &connectionLists->allsignals; + list = &signalVector->at(-1); Qt::HANDLE currentThreadId = QThread::currentThreadId(); + bool inSenderThread = currentThreadId == QObjectPrivate::get(sender)->threadData->threadId.load(); + // We need to check against the highest connection id to ensure that signals added + // during the signal emission are not emitted in this emission. + uint highestConnectionId = connections->currentConnectionId.load(); do { - QObjectPrivate::Connection *c = list->first; - if (!c) continue; - // We need to check against last here to ensure that signals added - // during the signal emission are not emitted in this emission. - QObjectPrivate::Connection *last = list->last; + QObjectPrivate::Connection *c = list->first.load(); + if (!c) + continue; do { - if (!c->receiver) + QObject * const receiver = c->receiver.load(); + if (!receiver) continue; - QObject * const receiver = c->receiver; - const bool receiverInSameThread = currentThreadId == receiver->d_func()->threadData->threadId.load(); + QThreadData *td = c->receiverThreadData.load(); + if (!td) + continue; + + bool receiverInSameThread; + if (inSenderThread) { + receiverInSameThread = currentThreadId == td->threadId.load(); + } else { + // need to lock before reading the threadId, because moveToThread() could interfere + QMutexLocker lock(signalSlotLock(receiver)); + receiverInSameThread = currentThreadId == td->threadId.load(); + } + // determine if this connection should be sent immediately or // put into the event queue if ((c->connectionType == Qt::AutoConnection && !receiverInSameThread) || (c->connectionType == Qt::QueuedConnection)) { - queued_activate(sender, signal_index, c, argv, locker); + queued_activate(sender, signal_index, c, argv); continue; #if QT_CONFIG(thread) } else if (c->connectionType == Qt::BlockingQueuedConnection) { @@ -3758,89 +3739,103 @@ void QMetaObject::activate(QObject *sender, int signalOffset, int local_signal_i receiver->metaObject()->className(), receiver); } QSemaphore semaphore; - QMetaCallEvent *ev = c->isSlotObject ? - new QMetaCallEvent(c->slotObj, sender, signal_index, 0, 0, argv, &semaphore) : - new QMetaCallEvent(c->method_offset, c->method_relative, c->callFunction, sender, signal_index, 0, 0, argv, &semaphore); - QCoreApplication::postEvent(receiver, ev); - locker.unlock(); + { + QBasicMutexLocker locker(signalSlotLock(sender)); + if (!c->receiver) + continue; + QMetaCallEvent *ev = c->isSlotObject ? + new QMetaCallEvent(c->slotObj, sender, signal_index, 0, 0, argv, &semaphore) : + new QMetaCallEvent(c->method_offset, c->method_relative, c->callFunction, sender, signal_index, 0, 0, argv, &semaphore); + QCoreApplication::postEvent(receiver, ev); + } semaphore.acquire(); - locker.relock(); continue; #endif } - QConnectionSenderSwitcher sw; + QObjectPrivate::Sender senderData(receiverInSameThread ? receiver : nullptr, sender, signal_index); - if (receiverInSameThread) { - sw.switchSender(receiver, sender, signal_index); - } if (c->isSlotObject) { c->slotObj->ref(); QScopedPointer<QtPrivate::QSlotObjectBase, QSlotObjectBaseDeleter> obj(c->slotObj); - locker.unlock(); Q_TRACE(QMetaObject_activate_begin_slot_functor, obj.data()); obj->call(receiver, argv); Q_TRACE(QMetaObject_activate_end_slot_functor, obj.data()); - - // Make sure the slot object gets destroyed before the mutex is locked again, as the - // destructor of the slot object might also lock a mutex from the signalSlotLock() mutex pool, - // and that would deadlock if the pool happens to return the same mutex. - obj.reset(); - - locker.relock(); } else if (c->callFunction && c->method_offset <= receiver->metaObject()->methodOffset()) { //we compare the vtable to make sure we are not in the destructor of the object. - const int methodIndex = c->method(); const int method_relative = c->method_relative; const auto callFunction = c->callFunction; - locker.unlock(); - if (qt_signal_spy_callback_set.slot_begin_callback != 0) - qt_signal_spy_callback_set.slot_begin_callback(receiver, methodIndex, argv); + const int methodIndex = (Q_HAS_TRACEPOINTS || callbacks_enabled) ? c->method() : 0; + if (callbacks_enabled && signal_spy_set->slot_begin_callback != nullptr) + signal_spy_set->slot_begin_callback(receiver, methodIndex, argv); Q_TRACE(QMetaObject_activate_begin_slot, receiver, methodIndex); callFunction(receiver, QMetaObject::InvokeMetaMethod, method_relative, argv); Q_TRACE(QMetaObject_activate_end_slot, receiver, methodIndex); - if (qt_signal_spy_callback_set.slot_end_callback != 0) - qt_signal_spy_callback_set.slot_end_callback(receiver, methodIndex); - locker.relock(); + if (callbacks_enabled && signal_spy_set->slot_end_callback != nullptr) + signal_spy_set->slot_end_callback(receiver, methodIndex); } else { const int method = c->method_relative + c->method_offset; - locker.unlock(); - if (qt_signal_spy_callback_set.slot_begin_callback != 0) { - qt_signal_spy_callback_set.slot_begin_callback(receiver, method, argv); + if (callbacks_enabled && signal_spy_set->slot_begin_callback != nullptr) { + signal_spy_set->slot_begin_callback(receiver, method, argv); } Q_TRACE(QMetaObject_activate_begin_slot, receiver, method); - metacall(receiver, QMetaObject::InvokeMetaMethod, method, argv); + QMetaObject::metacall(receiver, QMetaObject::InvokeMetaMethod, method, argv); Q_TRACE(QMetaObject_activate_end_slot, receiver, method); - if (qt_signal_spy_callback_set.slot_end_callback != 0) - qt_signal_spy_callback_set.slot_end_callback(receiver, method); - - locker.relock(); + if (callbacks_enabled && signal_spy_set->slot_end_callback != nullptr) + signal_spy_set->slot_end_callback(receiver, method); } + } while ((c = c->nextConnectionList.load()) != nullptr && c->id <= highestConnectionId); - if (connectionLists->orphaned) - break; - } while (c != last && (c = c->nextConnectionList) != 0); - - if (connectionLists->orphaned) - break; - } while (list != &connectionLists->allsignals && + } while (list != &signalVector->at(-1) && //start over for all signals; - ((list = &connectionLists->allsignals), true)); + ((list = &signalVector->at(-1)), true)); + if (connections->currentConnectionId.load() == 0) + senderDeleted = true; } + if (!senderDeleted) + sp->connections.load()->cleanOrphanedConnections(sender); - if (qt_signal_spy_callback_set.signal_end_callback != 0) - qt_signal_spy_callback_set.signal_end_callback(sender, signal_index); + if (callbacks_enabled && signal_spy_set->signal_end_callback != nullptr) + signal_spy_set->signal_end_callback(sender, signal_index); Q_TRACE(QMetaObject_activate_end_signal, sender, signal_index); + +} + +/*! + \internal + */ +void QMetaObject::activate(QObject *sender, const QMetaObject *m, int local_signal_index, + void **argv) +{ + int signal_index = local_signal_index + QMetaObjectPrivate::signalOffset(m); + + if (Q_UNLIKELY(qt_signal_spy_callback_set.load())) + doActivate<true>(sender, signal_index, argv); + else + doActivate<false>(sender, signal_index, argv); } /*! \internal + */ +void QMetaObject::activate(QObject *sender, int signalOffset, int local_signal_index, void **argv) +{ + int signal_index = signalOffset + local_signal_index; + + if (Q_UNLIKELY(qt_signal_spy_callback_set.load())) + doActivate<true>(sender, signal_index, argv); + else + doActivate<false>(sender, signal_index, argv); + } + +/*! + \internal signal_index comes from indexOfMethod() */ void QMetaObject::activate(QObject *sender, int signal_index, void **argv) @@ -3853,7 +3848,7 @@ void QMetaObject::activate(QObject *sender, int signal_index, void **argv) /*! \internal - Returns the signal index used in the internal connectionLists vector. + Returns the signal index used in the internal connections->receivers vector. It is different from QMetaObject::indexOfSignal(): indexOfSignal is the same as indexOfMethod while QObjectPrivate::signalIndex is smaller because it doesn't give index to slots. @@ -4093,37 +4088,40 @@ void QObject::dumpObjectInfo() const objectName().isEmpty() ? "unnamed" : objectName().toLocal8Bit().data()); Q_D(const QObject); - QMutexLocker locker(signalSlotLock(this)); + QBasicMutexLocker locker(signalSlotLock(this)); // first, look for connections where this object is the sender qDebug(" SIGNALS OUT"); - if (d->connectionLists) { - for (int signal_index = 0; signal_index < d->connectionLists->count(); ++signal_index) { + QObjectPrivate::ConnectionData *cd = d->connections.load(); + if (cd && cd->signalVectorCount()) { + QObjectPrivate::SignalVector *signalVector = cd->signalVector.load(); + for (int signal_index = 0; signal_index < signalVector->count(); ++signal_index) { + const QObjectPrivate::Connection *c = signalVector->at(signal_index).first.load(); + if (!c) + continue; const QMetaMethod signal = QMetaObjectPrivate::signal(metaObject(), signal_index); qDebug(" signal: %s", signal.methodSignature().constData()); // receivers - const QObjectPrivate::Connection *c = - d->connectionLists->at(signal_index).first; while (c) { - if (!c->receiver) { + if (!c->receiver.load()) { qDebug(" <Disconnected receiver>"); - c = c->nextConnectionList; + c = c->nextConnectionList.load(); continue; } if (c->isSlotObject) { qDebug(" <functor or function pointer>"); - c = c->nextConnectionList; + c = c->nextConnectionList.load(); continue; } - const QMetaObject *receiverMetaObject = c->receiver->metaObject(); + const QMetaObject *receiverMetaObject = c->receiver.load()->metaObject(); const QMetaMethod method = receiverMetaObject->method(c->method()); qDebug(" --> %s::%s %s", receiverMetaObject->className(), - c->receiver->objectName().isEmpty() ? "unnamed" : qPrintable(c->receiver->objectName()), + c->receiver.load()->objectName().isEmpty() ? "unnamed" : qPrintable(c->receiver.load()->objectName()), method.methodSignature().constData()); - c = c->nextConnectionList; + c = c->nextConnectionList.load(); } } } else { @@ -4133,8 +4131,8 @@ void QObject::dumpObjectInfo() const // now look for connections where this object is the receiver qDebug(" SIGNALS IN"); - if (d->senders) { - for (QObjectPrivate::Connection *s = d->senders; s; s = s->next) { + if (cd && cd->senders) { + for (QObjectPrivate::Connection *s = cd->senders; s; s = s->next) { QByteArray slotName = QByteArrayLiteral("<unknown>"); if (!s->isSlotObject) { const QMetaMethod slot = metaObject()->method(s->method()); @@ -4869,18 +4867,17 @@ QMetaObject::Connection QObjectPrivate::connectImpl(const QObject *sender, int s QOrderedMutexLocker locker(signalSlotLock(sender), signalSlotLock(receiver)); - if (type & Qt::UniqueConnection && slot) { - QObjectConnectionListVector *connectionLists = QObjectPrivate::get(s)->connectionLists; - if (connectionLists && connectionLists->count() > signal_index) { - const QObjectPrivate::Connection *c2 = - (*connectionLists)[signal_index].first; + if (type & Qt::UniqueConnection && slot && QObjectPrivate::get(s)->connections.load()) { + QObjectPrivate::ConnectionData *connections = QObjectPrivate::get(s)->connections.load(); + if (connections->signalVectorCount() > signal_index) { + const QObjectPrivate::Connection *c2 = connections->signalVector.load()->at(signal_index).first.load(); while (c2) { - if (c2->receiver == receiver && c2->isSlotObject && c2->slotObj->compare(slot)) { + if (c2->receiver.load() == receiver && c2->isSlotObject && c2->slotObj->compare(slot)) { slotObj->destroyIfLastRef(); return QMetaObject::Connection(); } - c2 = c2->nextConnectionList; + c2 = c2->nextConnectionList.load(); } } type = static_cast<Qt::ConnectionType>(type ^ Qt::UniqueConnection); @@ -4889,7 +4886,10 @@ QMetaObject::Connection QObjectPrivate::connectImpl(const QObject *sender, int s QScopedPointer<QObjectPrivate::Connection> c(new QObjectPrivate::Connection); c->sender = s; c->signal_index = signal_index; - c->receiver = r; + QThreadData *td = r->d_func()->threadData; + td->ref(); + c->receiverThreadData.store(td); + c->receiver.store(r); c->slotObj = slotObj; c->connectionType = type; c->isSlotObject = true; @@ -4921,35 +4921,35 @@ bool QObject::disconnect(const QMetaObject::Connection &connection) { QObjectPrivate::Connection *c = static_cast<QObjectPrivate::Connection *>(connection.d_ptr); - if (!c || !c->receiver) + if (!c) + return false; + QObject *receiver = c->receiver.load(); + if (!receiver) return false; - QMutex *senderMutex = signalSlotLock(c->sender); - QMutex *receiverMutex = signalSlotLock(c->receiver); + QBasicMutex *senderMutex = signalSlotLock(c->sender); + QBasicMutex *receiverMutex = signalSlotLock(receiver); + QObjectPrivate::ConnectionData *connections; { QOrderedMutexLocker locker(senderMutex, receiverMutex); - QObjectConnectionListVector *connectionLists = QObjectPrivate::get(c->sender)->connectionLists; - Q_ASSERT(connectionLists); - connectionLists->dirty = true; + // load receiver once again and recheck to ensure nobody else has removed the connection in the meantime + receiver = c->receiver.load(); + if (!receiver) + return false; - *c->prev = c->next; - if (c->next) - c->next->prev = c->prev; - c->receiver = 0; + connections = QObjectPrivate::get(c->sender)->connections.load(); + Q_ASSERT(connections); + connections->removeConnection(c); } - // destroy the QSlotObject, if possible - if (c->isSlotObject) { - c->slotObj->destroyIfLastRef(); - c->isSlotObject = false; - } + connections->cleanOrphanedConnections(c->sender); c->sender->disconnectNotify(QMetaObjectPrivate::signal(c->sender->metaObject(), c->signal_index)); - const_cast<QMetaObject::Connection &>(connection).d_ptr = 0; + const_cast<QMetaObject::Connection &>(connection).d_ptr = nullptr; c->deref(); // has been removed from the QMetaObject::Connection object return true; @@ -5131,7 +5131,7 @@ bool QMetaObject::Connection::isConnected_helper() const Q_ASSERT(d_ptr); // we're only called from operator RestrictedBool() const QObjectPrivate::Connection *c = static_cast<QObjectPrivate::Connection *>(d_ptr); - return c->receiver; + return c->receiver.load(); } diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index 63c5a9ad73..1d83731441 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -142,8 +142,8 @@ public: inline bool isWidgetType() const { return d_ptr->isWidget; } inline bool isWindowType() const { return d_ptr->isWindow; } - inline bool signalsBlocked() const Q_DECL_NOTHROW { return d_ptr->blockSig; } - bool blockSignals(bool b) Q_DECL_NOTHROW; + inline bool signalsBlocked() const noexcept { return d_ptr->blockSig; } + bool blockSignals(bool b) noexcept; QThread *thread() const; void moveToThread(QThread *thread); @@ -436,7 +436,7 @@ protected: QScopedPointer<QObjectData> d_ptr; static const QMetaObject staticQtMetaObject; - friend inline const QMetaObject *qt_getQtMetaObject() Q_DECL_NOEXCEPT; + friend inline const QMetaObject *qt_getQtMetaObject() noexcept; friend struct QMetaObject; friend struct QMetaObjectPrivate; @@ -467,7 +467,7 @@ inline QMetaObject::Connection QObject::connect(const QObject *asender, const ch const char *amember, Qt::ConnectionType atype) const { return connect(asender, asignal, this, amember, atype); } -inline const QMetaObject *qt_getQtMetaObject() Q_DECL_NOEXCEPT +inline const QMetaObject *qt_getQtMetaObject() noexcept { return &QObject::staticQtMetaObject; } #ifndef QT_NO_USERDATA @@ -540,17 +540,15 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QObject *); class QSignalBlocker { public: - inline explicit QSignalBlocker(QObject *o) Q_DECL_NOTHROW; - inline explicit QSignalBlocker(QObject &o) Q_DECL_NOTHROW; + inline explicit QSignalBlocker(QObject *o) noexcept; + inline explicit QSignalBlocker(QObject &o) noexcept; inline ~QSignalBlocker(); -#ifdef Q_COMPILER_RVALUE_REFS - inline QSignalBlocker(QSignalBlocker &&other) Q_DECL_NOTHROW; - inline QSignalBlocker &operator=(QSignalBlocker &&other) Q_DECL_NOTHROW; -#endif + inline QSignalBlocker(QSignalBlocker &&other) noexcept; + inline QSignalBlocker &operator=(QSignalBlocker &&other) noexcept; - inline void reblock() Q_DECL_NOTHROW; - inline void unblock() Q_DECL_NOTHROW; + inline void reblock() noexcept; + inline void unblock() noexcept; private: Q_DISABLE_COPY(QSignalBlocker) QObject * m_o; @@ -558,20 +556,19 @@ private: bool m_inhibited; }; -QSignalBlocker::QSignalBlocker(QObject *o) Q_DECL_NOTHROW +QSignalBlocker::QSignalBlocker(QObject *o) noexcept : m_o(o), m_blocked(o && o->blockSignals(true)), m_inhibited(false) {} -QSignalBlocker::QSignalBlocker(QObject &o) Q_DECL_NOTHROW +QSignalBlocker::QSignalBlocker(QObject &o) noexcept : m_o(&o), m_blocked(o.blockSignals(true)), m_inhibited(false) {} -#ifdef Q_COMPILER_RVALUE_REFS -QSignalBlocker::QSignalBlocker(QSignalBlocker &&other) Q_DECL_NOTHROW +QSignalBlocker::QSignalBlocker(QSignalBlocker &&other) noexcept : m_o(other.m_o), m_blocked(other.m_blocked), m_inhibited(other.m_inhibited) @@ -579,7 +576,7 @@ QSignalBlocker::QSignalBlocker(QSignalBlocker &&other) Q_DECL_NOTHROW other.m_o = nullptr; } -QSignalBlocker &QSignalBlocker::operator=(QSignalBlocker &&other) Q_DECL_NOTHROW +QSignalBlocker &QSignalBlocker::operator=(QSignalBlocker &&other) noexcept { if (this != &other) { // if both *this and other block the same object's signals: @@ -594,7 +591,6 @@ QSignalBlocker &QSignalBlocker::operator=(QSignalBlocker &&other) Q_DECL_NOTHROW } return *this; } -#endif QSignalBlocker::~QSignalBlocker() { @@ -602,13 +598,13 @@ QSignalBlocker::~QSignalBlocker() m_o->blockSignals(m_blocked); } -void QSignalBlocker::reblock() Q_DECL_NOTHROW +void QSignalBlocker::reblock() noexcept { if (m_o) m_o->blockSignals(true); m_inhibited = false; } -void QSignalBlocker::unblock() Q_DECL_NOTHROW +void QSignalBlocker::unblock() noexcept { if (m_o) m_o->blockSignals(m_blocked); m_inhibited = true; diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h index a762e6f529..2fb11ecc64 100644 --- a/src/corelib/kernel/qobject_p.h +++ b/src/corelib/kernel/qobject_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Copyright (C) 2013 Olivier Goffart <ogoffart@woboq.com> ** Contact: https://www.qt.io/licensing/ ** @@ -79,9 +79,9 @@ struct QSignalSpyCallbackSet EndCallback signal_end_callback, slot_end_callback; }; -void Q_CORE_EXPORT qt_register_signal_spy_callbacks(const QSignalSpyCallbackSet &callback_set); +void Q_CORE_EXPORT qt_register_signal_spy_callbacks(QSignalSpyCallbackSet *callback_set); -extern QSignalSpyCallbackSet Q_CORE_EXPORT qt_signal_spy_callback_set; +extern Q_CORE_EXPORT QBasicAtomicPointer<QSignalSpyCallbackSet> qt_signal_spy_callback_set; enum { QObjectPrivateVersion = QT_VERSION }; @@ -124,54 +124,199 @@ public: }; typedef void (*StaticMetaCallFunction)(QObject *, QMetaObject::Call, int, void **); - struct Connection + struct Connection; + struct SignalVector; + + struct ConnectionOrSignalVector { + union { + // linked list of orphaned connections that need cleaning up + ConnectionOrSignalVector *nextInOrphanList; + // linked list of connections connected to slots in this object + Connection *next; + }; + + static SignalVector *asSignalVector(ConnectionOrSignalVector *c) { + if (reinterpret_cast<quintptr>(c) & 1) + return reinterpret_cast<SignalVector *>(reinterpret_cast<quintptr>(c) & ~quintptr(1u)); + return nullptr; + } + static Connection *fromSignalVector(SignalVector *v) { + return reinterpret_cast<Connection *>(reinterpret_cast<quintptr>(v) | quintptr(1u)); + } + }; + + struct Connection : public ConnectionOrSignalVector { + // linked list of connections connected to slots in this object, next is in base class + Connection **prev; + // linked list of connections connected to signals in this object + QAtomicPointer<Connection> nextConnectionList; + Connection *prevConnectionList; + QObject *sender; - QObject *receiver; + QAtomicPointer<QObject> receiver; + QAtomicPointer<QThreadData> receiverThreadData; union { StaticMetaCallFunction callFunction; QtPrivate::QSlotObjectBase *slotObj; }; - // The next pointer for the singly-linked ConnectionList - Connection *nextConnectionList; - //senders linked list - Connection *next; - Connection **prev; QAtomicPointer<const int> argumentTypes; QAtomicInt ref_; + uint id = 0; ushort method_offset; ushort method_relative; - uint signal_index : 27; // In signal range (see QObjectPrivate::signalIndex()) + int signal_index : 27; // In signal range (see QObjectPrivate::signalIndex()) ushort connectionType : 3; // 0 == auto, 1 == direct, 2 == queued, 4 == blocking ushort isSlotObject : 1; ushort ownArgumentTypes : 1; - Connection() : nextConnectionList(nullptr), ref_(2), ownArgumentTypes(true) { + Connection() : ref_(2), ownArgumentTypes(true) { //ref_ is 2 for the use in the internal lists, and for the use in QMetaObject::Connection } ~Connection(); int method() const { Q_ASSERT(!isSlotObject); return method_offset + method_relative; } void ref() { ref_.ref(); } + void freeSlotObject() + { + if (isSlotObject) { + slotObj->destroyIfLastRef(); + isSlotObject = false; + } + } void deref() { if (!ref_.deref()) { - Q_ASSERT(!receiver); + Q_ASSERT(!receiver.load()); + Q_ASSERT(!isSlotObject); delete this; } } }; // ConnectionList is a singly-linked list struct ConnectionList { - ConnectionList() : first(nullptr), last(nullptr) {} - Connection *first; - Connection *last; + QAtomicPointer<Connection> first; + QAtomicPointer<Connection> last; }; struct Sender { + Sender(QObject *receiver, QObject *sender, int signal) + : receiver(receiver), sender(sender), signal(signal) + { + if (receiver) { + ConnectionData *cd = receiver->d_func()->connections.load(); + previous = cd->currentSender; + cd->currentSender = this; + } + } + ~Sender() + { + if (receiver) + receiver->d_func()->connections.load()->currentSender = previous; + } + void receiverDeleted() + { + Sender *s = this; + while (s) { + s->receiver = nullptr; + s = s->previous; + } + } + Sender *previous; + QObject *receiver; QObject *sender; int signal; - int ref; }; + struct SignalVector : public ConnectionOrSignalVector { + quintptr allocated; + // ConnectionList signals[] + ConnectionList &at(int i) + { + return reinterpret_cast<ConnectionList *>(this + 1)[i + 1]; + } + const ConnectionList &at(int i) const + { + return reinterpret_cast<const ConnectionList *>(this + 1)[i + 1]; + } + int count() { return static_cast<int>(allocated); } + }; + + + + /* + This contains the all connections from and to an object. + + The signalVector contains the lists of connections for a given signal. The index in the vector correspond + to the signal index. The signal index is the one returned by QObjectPrivate::signalIndex (not + QMetaObject::indexOfSignal). allsignals contains a list of special connections that will get invoked on + any signal emission. This is done by connecting to signal index -1. + + This vector is protected by the object mutex (signalSlotLock()) + + Each Connection is also part of a 'senders' linked list. This one contains all connections connected + to a slot in this object. The mutex of the receiver must be locked when touching the pointers of this + linked list. + */ + struct ConnectionData { + // the id below is used to avoid activating new connections. When the object gets + // deleted it's set to 0, so that signal emission stops + QAtomicInteger<uint> currentConnectionId; + QAtomicInt ref; + QAtomicPointer<SignalVector> signalVector; + Connection *senders = nullptr; + Sender *currentSender = nullptr; // object currently activating the object + QAtomicPointer<Connection> orphaned; + + ~ConnectionData() + { + deleteOrphaned(orphaned.load()); + SignalVector *v = signalVector.load(); + if (v) + free(v); + } + + // must be called on the senders connection data + // assumes the senders and receivers lock are held + void removeConnection(Connection *c); + void cleanOrphanedConnections(QObject *sender) + { + if (orphaned.load() && ref == 1) + cleanOrphanedConnectionsImpl(sender); + } + void cleanOrphanedConnectionsImpl(QObject *sender); + + ConnectionList &connectionsForSignal(int signal) + { + return signalVector.load()->at(signal); + } + + void resizeSignalVector(uint size) { + SignalVector *vector = this->signalVector.load(); + if (vector && vector->allocated > size) + return; + size = (size + 7) & ~7; + SignalVector *newVector = reinterpret_cast<SignalVector *>(malloc(sizeof(SignalVector) + (size + 1) * sizeof(ConnectionList))); + int start = -1; + if (vector) { + memcpy(newVector, vector, sizeof(SignalVector) + (vector->allocated + 1) * sizeof(ConnectionList)); + start = vector->count(); + } + for (int i = start; i < int(size); ++i) + newVector->at(i) = ConnectionList(); + newVector->next = nullptr; + newVector->allocated = size; + + signalVector.store(newVector); + if (vector) { + vector->nextInOrphanList = orphaned.load(); + orphaned.store(ConnectionOrSignalVector::fromSignalVector(vector)); + } + } + int signalVectorCount() const { + return signalVector ? signalVector.load()->count() : -1; + } + + static void deleteOrphaned(ConnectionOrSignalVector *c); + }; QObjectPrivate(int version = QObjectPrivateVersion); virtual ~QObjectPrivate(); @@ -187,13 +332,6 @@ public: QObjectList senderList() const; void addConnection(int signal, Connection *c); - void cleanConnectionLists(); - - static inline Sender *setCurrentSender(QObject *receiver, - Sender *sender); - static inline void resetCurrentSender(QObject *receiver, - Sender *currentSender, - Sender *previousSender); static QObjectPrivate *get(QObject *o) { return o->d_func(); @@ -201,7 +339,8 @@ public: static const QObjectPrivate *get(const QObject *o) { return o->d_func(); } int signalIndex(const char *signalName, const QMetaObject **meta = nullptr) const; - inline bool isSignalConnected(uint signalIdx, bool checkDeclarative = true) const; + bool isSignalConnected(uint signalIdx, bool checkDeclarative = true) const; + bool maybeSignalConnected(uint signalIndex) const; inline bool isDeclarativeSignalConnected(uint signalIdx) const; // To allow abitrary objects to call connectNotify()/disconnectNotify() without making @@ -224,15 +363,21 @@ public: const int *types, const QMetaObject *senderMetaObject); static QMetaObject::Connection connect(const QObject *sender, int signal_index, QtPrivate::QSlotObjectBase *slotObj, Qt::ConnectionType type); static bool disconnect(const QObject *sender, int signal_index, void **slot); + + void ensureConnectionData() + { + if (connections.load()) + return; + ConnectionData *cd = new ConnectionData; + cd->ref.ref(); + connections.store(cd); + } public: ExtraData *extraData; // extra data set by the user QThreadData *threadData; // id of the thread that owns the object - QObjectConnectionListVector *connectionLists; - - Connection *senders; // linked list of connections connected to this object - Sender *currentSender; // object currently activating the object - mutable quint32 connectedSignals[2]; + using ConnectionDataPointer = QExplicitlySharedDataPointer<ConnectionData>; + QAtomicPointer<ConnectionData> connections; union { QObject *currentChildBeingDeleted; // should only be used when QObjectData::isDeletingChildren is set @@ -246,47 +391,12 @@ public: Q_DECLARE_TYPEINFO(QObjectPrivate::ConnectionList, Q_MOVABLE_TYPE); -/*! \internal - - Returns \c true if the signal with index \a signal_index from object \a sender is connected. - Signals with indices above a certain range are always considered connected (see connectedSignals - in QObjectPrivate). - - \a signal_index must be the index returned by QObjectPrivate::signalIndex; -*/ -inline bool QObjectPrivate::isSignalConnected(uint signal_index, bool checkDeclarative) const -{ - return signal_index >= sizeof(connectedSignals) * 8 - || (connectedSignals[signal_index >> 5] & (1 << (signal_index & 0x1f)) - || (checkDeclarative && isDeclarativeSignalConnected(signal_index))); -} - inline bool QObjectPrivate::isDeclarativeSignalConnected(uint signal_index) const { return declarativeData && QAbstractDeclarativeData::isSignalConnected && QAbstractDeclarativeData::isSignalConnected(declarativeData, q_func(), signal_index); } -inline QObjectPrivate::Sender *QObjectPrivate::setCurrentSender(QObject *receiver, - Sender *sender) -{ - Sender *previousSender = receiver->d_func()->currentSender; - receiver->d_func()->currentSender = sender; - return previousSender; -} - -inline void QObjectPrivate::resetCurrentSender(QObject *receiver, - Sender *currentSender, - Sender *previousSender) -{ - // ref is set to zero when this object is deleted during the metacall - if (currentSender->ref == 1) - receiver->d_func()->currentSender = previousSender; - // if we've recursed, we need to tell the caller about the objects deletion - if (previousSender) - previousSender->ref = currentSender->ref; -} - inline void QObjectPrivate::connectNotify(const QMetaMethod &signal) { q_ptr->connectNotify(signal); @@ -372,7 +482,26 @@ Q_DECLARE_TYPEINFO(QObjectPrivate::Connection, Q_MOVABLE_TYPE); Q_DECLARE_TYPEINFO(QObjectPrivate::Sender, Q_MOVABLE_TYPE); class QSemaphore; -class Q_CORE_EXPORT QMetaCallEvent : public QEvent +class Q_CORE_EXPORT QAbstractMetaCallEvent : public QEvent +{ +public: + QAbstractMetaCallEvent(const QObject *sender, int signalId, QSemaphore *semaphore = nullptr) + : QEvent(MetaCall), signalId_(signalId), sender_(sender), semaphore_(semaphore) + {} + ~QAbstractMetaCallEvent(); + + virtual void placeMetaCall(QObject *object) = 0; + + inline const QObject *sender() const { return sender_; } + inline int signalId() const { return signalId_; } + +private: + int signalId_; + const QObject *sender_; + QSemaphore *semaphore_; +}; + +class Q_CORE_EXPORT QMetaCallEvent : public QAbstractMetaCallEvent { public: QMetaCallEvent(ushort method_offset, ushort method_relative, QObjectPrivate::StaticMetaCallFunction callFunction , const QObject *sender, int signalId, @@ -383,23 +512,18 @@ public: QMetaCallEvent(QtPrivate::QSlotObjectBase *slotObj, const QObject *sender, int signalId, int nargs = 0, int *types = nullptr, void **args = nullptr, QSemaphore *semaphore = nullptr); - ~QMetaCallEvent(); + ~QMetaCallEvent() override; inline int id() const { return method_offset_ + method_relative_; } - inline const QObject *sender() const { return sender_; } - inline int signalId() const { return signalId_; } inline void **args() const { return args_; } - virtual void placeMetaCall(QObject *object); + virtual void placeMetaCall(QObject *object) override; private: QtPrivate::QSlotObjectBase *slotObj_; - const QObject *sender_; - int signalId_; int nargs_; int *types_; void **args_; - QSemaphore *semaphore_; QObjectPrivate::StaticMetaCallFunction callFunction_; ushort method_offset_; ushort method_relative_; diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h index 059bb44e10..0bceab6fb4 100644 --- a/src/corelib/kernel/qobjectdefs.h +++ b/src/corelib/kernel/qobjectdefs.h @@ -64,11 +64,7 @@ class QString; // The following macros can be defined by tools that understand Qt // to have the information from the macro. #ifndef QT_ANNOTATE_CLASS -# ifndef Q_COMPILER_VARIADIC_MACROS -# define QT_ANNOTATE_CLASS(type, x) -# else -# define QT_ANNOTATE_CLASS(type, ...) -# endif +# define QT_ANNOTATE_CLASS(type, ...) #endif #ifndef QT_ANNOTATE_CLASS2 # define QT_ANNOTATE_CLASS2(type, a1, a2) @@ -105,11 +101,7 @@ class QString; #endif #define Q_PLUGIN_METADATA(x) QT_ANNOTATE_CLASS(qt_plugin_metadata, x) #define Q_INTERFACES(x) QT_ANNOTATE_CLASS(qt_interfaces, x) -#ifdef Q_COMPILER_VARIADIC_MACROS -# define Q_PROPERTY(...) QT_ANNOTATE_CLASS(qt_property, __VA_ARGS__) -#else -# define Q_PROPERTY(text) QT_ANNOTATE_CLASS(qt_property, text) -#endif +#define Q_PROPERTY(...) QT_ANNOTATE_CLASS(qt_property, __VA_ARGS__) #define Q_PRIVATE_PROPERTY(d, text) QT_ANNOTATE_CLASS2(qt_private_property, d, text) #ifndef Q_REVISION # define Q_REVISION(v) @@ -119,13 +111,13 @@ class QString; #define Q_ENUMS(x) QT_ANNOTATE_CLASS(qt_enums, x) #define Q_FLAGS(x) QT_ANNOTATE_CLASS(qt_enums, x) #define Q_ENUM_IMPL(ENUM) \ - friend Q_DECL_CONSTEXPR const QMetaObject *qt_getEnumMetaObject(ENUM) Q_DECL_NOEXCEPT { return &staticMetaObject; } \ - friend Q_DECL_CONSTEXPR const char *qt_getEnumName(ENUM) Q_DECL_NOEXCEPT { return #ENUM; } + friend Q_DECL_CONSTEXPR const QMetaObject *qt_getEnumMetaObject(ENUM) noexcept { return &staticMetaObject; } \ + friend Q_DECL_CONSTEXPR const char *qt_getEnumName(ENUM) noexcept { return #ENUM; } #define Q_ENUM(x) Q_ENUMS(x) Q_ENUM_IMPL(x) #define Q_FLAG(x) Q_FLAGS(x) Q_ENUM_IMPL(x) #define Q_ENUM_NS_IMPL(ENUM) \ - inline Q_DECL_CONSTEXPR const QMetaObject *qt_getEnumMetaObject(ENUM) Q_DECL_NOEXCEPT { return &staticMetaObject; } \ - inline Q_DECL_CONSTEXPR const char *qt_getEnumName(ENUM) Q_DECL_NOEXCEPT { return #ENUM; } + inline Q_DECL_CONSTEXPR const QMetaObject *qt_getEnumMetaObject(ENUM) noexcept { return &staticMetaObject; } \ + inline Q_DECL_CONSTEXPR const char *qt_getEnumName(ENUM) noexcept { return #ENUM; } #define Q_ENUM_NS(x) Q_ENUMS(x) Q_ENUM_NS_IMPL(x) #define Q_FLAG_NS(x) Q_FLAGS(x) Q_ENUM_NS_IMPL(x) #define Q_SCRIPTABLE QT_ANNOTATE_FUNCTION(qt_scriptable) @@ -340,7 +332,7 @@ struct Q_CORE_EXPORT QMetaObject const char *className() const; const QMetaObject *superClass() const; - bool inherits(const QMetaObject *metaObject) const Q_DECL_NOEXCEPT; + bool inherits(const QMetaObject *metaObject) const noexcept; QObject *cast(QObject *obj) const; const QObject *cast(const QObject *obj) const; @@ -584,6 +576,7 @@ struct Q_CORE_EXPORT QMetaObject private: static bool invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *slot, Qt::ConnectionType type, void *ret); + friend class QTimer; }; class Q_CORE_EXPORT QMetaObject::Connection { @@ -605,8 +598,8 @@ public: operator RestrictedBool() const { return d_ptr && isConnected_helper() ? &Connection::d_ptr : nullptr; } #endif - Connection(Connection &&o) Q_DECL_NOTHROW : d_ptr(o.d_ptr) { o.d_ptr = nullptr; } - Connection &operator=(Connection &&other) Q_DECL_NOTHROW + Connection(Connection &&o) noexcept : d_ptr(o.d_ptr) { o.d_ptr = nullptr; } + Connection &operator=(Connection &&other) noexcept { qSwap(d_ptr, other.d_ptr); return *this; } }; diff --git a/src/corelib/kernel/qobjectdefs_impl.h b/src/corelib/kernel/qobjectdefs_impl.h index aa6bd84e95..31ecc8b20d 100644 --- a/src/corelib/kernel/qobjectdefs_impl.h +++ b/src/corelib/kernel/qobjectdefs_impl.h @@ -386,8 +386,8 @@ namespace QtPrivate { public: explicit QSlotObjectBase(ImplFn fn) : m_ref(1), m_impl(fn) {} - inline int ref() Q_DECL_NOTHROW { return m_ref.ref(); } - inline void destroyIfLastRef() Q_DECL_NOTHROW + inline int ref() noexcept { return m_ref.ref(); } + inline void destroyIfLastRef() noexcept { if (!m_ref.deref()) m_impl(Destroy, this, nullptr, nullptr, nullptr); } inline bool compare(void **a) { bool ret = false; m_impl(Compare, this, nullptr, a, &ret); return ret; } diff --git a/src/corelib/kernel/qppsattribute.cpp b/src/corelib/kernel/qppsattribute.cpp index 6be462edb5..166d590872 100644 --- a/src/corelib/kernel/qppsattribute.cpp +++ b/src/corelib/kernel/qppsattribute.cpp @@ -145,7 +145,6 @@ QPpsAttribute &QPpsAttribute::operator=(const QPpsAttribute &other) return *this; } -#ifdef Q_COMPILER_RVALUE_REFS QPpsAttribute::QPpsAttribute(QPpsAttribute &&other) : d(other.d) { other.d->type = QPpsAttribute::None; @@ -156,7 +155,6 @@ QPpsAttribute &QPpsAttribute::operator=(QPpsAttribute &&other) qSwap(d, other.d); return *this; } -#endif bool QPpsAttribute::operator==(const QPpsAttribute &other) const { diff --git a/src/corelib/kernel/qppsattribute_p.h b/src/corelib/kernel/qppsattribute_p.h index b59dcd5851..d6611cb675 100644 --- a/src/corelib/kernel/qppsattribute_p.h +++ b/src/corelib/kernel/qppsattribute_p.h @@ -96,10 +96,8 @@ public: bool operator==(const QPpsAttribute &other) const; bool operator!=(const QPpsAttribute &other) const; -#ifdef Q_COMPILER_RVALUE_REFS QPpsAttribute(QPpsAttribute &&other); QPpsAttribute &operator=(QPpsAttribute &&other); -#endif bool isValid() const; Type type() const; diff --git a/src/corelib/kernel/qsharedmemory_p.h b/src/corelib/kernel/qsharedmemory_p.h index 95fe0d1083..59802eb6ce 100644 --- a/src/corelib/kernel/qsharedmemory_p.h +++ b/src/corelib/kernel/qsharedmemory_p.h @@ -98,7 +98,7 @@ public: { if (q_sm && q_sm->lock()) return true; - q_sm = 0; + q_sm = nullptr; return false; } diff --git a/src/corelib/kernel/qtcore_eval.cpp b/src/corelib/kernel/qtcore_eval.cpp deleted file mode 100644 index 5437210699..0000000000 --- a/src/corelib/kernel/qtcore_eval.cpp +++ /dev/null @@ -1,560 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://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$ -** -****************************************************************************/ - -#include <qcoreevent.h> -#include <qdatetime.h> -#include <qlibraryinfo.h> -#include <qobject.h> -#include <qcoreapplication.h> -#include <private/qcoreapplication_p.h> - -#include "stdio.h" -#include "stdlib.h" - -QT_BEGIN_NAMESPACE - -#include "qconfig_eval.cpp" - -static const char boilerplate_supported_but_time_limited[] = - "\nQt %1 Evaluation License\n" - "Copyright (C) 2016 The Qt Company Ltd.\n" - "This trial version may only be used for evaluation purposes\n" - "and will shut down after 120 minutes.\n" - "Registered to:\n" - " Licensee: %2\n\n" - "The evaluation expires in %4 days\n\n" - "Contact http://www.qt.io/contact-us for pricing and purchasing information.\n"; - -static const char boilerplate_supported[] = - "\nQt %1 Evaluation License\n" - "Copyright (C) 2016 The Qt Company Ltd.\n" - "This trial version may only be used for evaluation purposes\n" - "Registered to:\n" - " Licensee: %2\n\n" - "The evaluation expires in %4 days\n\n" - "Contact http://www.qt.io/contact-us for pricing and purchasing information.\n"; - -static const char boilerplate_expired[] = - "This software is using the trial version of the Qt GUI toolkit.\n" - "The trial period has expired. If you need more time to\n" - "evaluate Qt, or if you have any questions about Qt, contact us\n" - "at: http://www.qt.io/contact-us.\n\n"; - -static const char will_shutdown_1min[] = - "\nThe evaluation of Qt will SHUT DOWN in 1 minute.\n" - "Contact http://www.qt.io/contact-us for pricing and purchasing information.\n"; - -static const char will_shutdown_now[] = - "\nThe evaluation of Qt has now reached its automatic\n" - "timeout and will shut down.\n" - "Contact http://www.qt.io/contact-us for pricing and purchasing information.\n"; - -enum EvaluationStatus { - EvaluationNotSupported = 0, - EvaluationSupportedButTimeLimited, - EvaluationSupported -}; - -static EvaluationStatus qt_eval_is_supported() -{ - const volatile char *const license_key = qt_eval_key_data + 12; - - // fast fail - if (!qt_eval_key_data[0] || !*license_key) - return EvaluationNotSupported; - - // is this an unsupported evaluation? - const volatile char *typecode = license_key; - int field = 2; - for ( ; field && *typecode; ++typecode) - if (*typecode == '-') - --field; - - if (!field && typecode[1] == '4' && typecode[2] == 'M') { - if (typecode[0] == 'Q') - return EvaluationSupportedButTimeLimited; - else if (typecode[0] == 'R' || typecode[0] == 'Z') - return EvaluationSupported; - } - return EvaluationNotSupported; -} - -static int qt_eval_days_left() -{ - const volatile char *const expiry_date = qt_eval_expiry_date + 12; - - QDate today = QDate::currentDate(); - QDate lastday = QDate::fromString( - QString::fromLatin1(const_cast<const char*>(expiry_date)), Qt::ISODate); - return today.daysTo(lastday); -} - -static bool qt_eval_is_expired() -{ - return qt_eval_days_left() < 0; -} - -static QString qt_eval_string() -{ - const char *msg; - switch (qt_eval_is_supported()) { - case EvaluationSupportedButTimeLimited: - msg = boilerplate_supported_but_time_limited; - break; - case EvaluationSupported: - msg = boilerplate_supported; - break; - default: - return QString(); - } - - return QString::fromLatin1(msg) - .arg(QLatin1String(QT_VERSION_STR)) - .arg(QLibraryInfo::licensee()) - .arg(qt_eval_days_left()); -} - -#define WARN_TIMEOUT 60 * 1000 * 119 -#define KILL_DELAY 60 * 1000 * 1 - -class QCoreFuriCuri : public QObject -{ -public: - - int warn; - int kill; - - QCoreFuriCuri() : QObject(), warn(-1), kill(-1) - { - if (qt_eval_is_supported() == EvaluationSupportedButTimeLimited) { - warn = startTimer(WARN_TIMEOUT); - kill = 0; - } - } - - void timerEvent(QTimerEvent *e) override { - if (e->timerId() == warn) { - killTimer(warn); - fprintf(stderr, "%s\n", will_shutdown_1min); - kill = startTimer(KILL_DELAY); - } else if (e->timerId() == kill) { - fprintf(stderr, "%s\n", will_shutdown_now); - QCoreApplication::instance()->quit(); - } - } -}; - -#if defined(QT_BUILD_CORE_LIB) || defined (QT_BOOTSTRAPPED) - -void qt_core_eval_init(QCoreApplicationPrivate::Type type) -{ - if (type != QCoreApplicationPrivate::Tty) - return; - - if (!qt_eval_is_supported()) - return; - - if (qt_eval_is_expired()) { - fprintf(stderr, "%s\n", boilerplate_expired); - exit(0); - } else { - fprintf(stderr, "%s\n", qPrintable(qt_eval_string())); - Q_UNUSED(new QCoreFuriCuri()); - } -} -#endif - -#ifdef QT_BUILD_WIDGETS_LIB - -QT_BEGIN_INCLUDE_NAMESPACE -#include <qdialog.h> -#include <qlabel.h> -#include <qlayout.h> -#include <qmessagebox.h> -#if QT_CONFIG(pushbutton) -#include <qpushbutton.h> -#endif -#include <qtimer.h> -#include <qapplication.h> -QT_END_INCLUDE_NAMESPACE - - -static const char * const qtlogo_eval_xpm[] = { -/* columns rows colors chars-per-pixel */ -"46 55 174 2", -" c #002E02", -". c #00370D", -"X c #003A0E", -"o c #003710", -"O c #013C13", -"+ c #043E1A", -"@ c #084F0A", -"# c #0B520C", -"$ c #054413", -"% c #0C4C17", -"& c #07421D", -"* c #09451D", -"= c #0D491E", -"- c #125515", -"; c #13541A", -": c #17591B", -"> c #1B5C1D", -", c #1F611F", -"< c #20621E", -"1 c #337B1E", -"2 c #0B4521", -"3 c #0F4923", -"4 c #114B24", -"5 c #154D2A", -"6 c #175323", -"7 c #1C5924", -"8 c #1C532F", -"9 c #1E5432", -"0 c #245936", -"q c #265938", -"w c #295C3B", -"e c #246324", -"r c #266823", -"t c #2A6C24", -"y c #276628", -"u c #2D7026", -"i c #327427", -"p c #367927", -"a c #37782A", -"s c #397C2A", -"d c #2E613E", -"f c #336C37", -"g c #2F6040", -"h c #356545", -"j c #3C6B4E", -"k c #3F6C51", -"l c #406E4F", -"z c #406D52", -"x c #477457", -"c c #497557", -"v c #4B7857", -"b c #517B5E", -"n c #3C8423", -"m c #3E812C", -"M c #53A61D", -"N c #41862C", -"B c #458A2D", -"V c #498F2D", -"C c #479324", -"Z c #489226", -"A c #4D952C", -"S c #478B30", -"D c #488C30", -"F c #4D9232", -"G c #509632", -"H c #549A33", -"J c #589F35", -"K c #56A526", -"L c #57A821", -"P c #5BAA27", -"I c #57A32A", -"U c #5CA72E", -"Y c #5DAB2A", -"T c #5CA336", -"R c #60AD2E", -"E c #63B12D", -"W c #65AF35", -"Q c #62A53F", -"! c #65AE39", -"~ c #66B036", -"^ c #6AB437", -"/ c #67B138", -"( c #6AB339", -") c #6DB838", -"_ c #70BA3C", -"` c #4D8545", -"' c #4E8942", -"] c #548851", -"[ c #6FAF4A", -"{ c #6DB243", -"} c #71B546", -"| c #70B840", -" . c #73B648", -".. c #79BA4E", -"X. c #7CBB53", -"o. c #598266", -"O. c #62886D", -"+. c #6A8F75", -"@. c #6B9173", -"#. c #70937A", -"$. c #799F79", -"%. c #7BAF66", -"&. c #81BD5B", -"*. c #85BF60", -"=. c #85AC7F", -"-. c #8DBA7B", -";. c #87C061", -":. c #8AC364", -">. c #8DC46A", -",. c #90C56E", -"<. c #93C771", -"1. c #96CA73", -"2. c #9ACB7C", -"3. c #9FD07D", -"4. c #779981", -"5. c #7F9F89", -"6. c #809F88", -"7. c #82A18B", -"8. c #86A192", -"9. c #8DA994", -"0. c #8FA998", -"q. c #94AF9B", -"w. c #97B991", -"e. c #97B19E", -"r. c #9DB6A3", -"t. c #A3BCA7", -"y. c #A6BCAB", -"u. c #A9BEB1", -"i. c #9ECD81", -"p. c #A2CF85", -"a. c #A5D284", -"s. c #A6D189", -"d. c #A9D28E", -"f. c #ABD491", -"g. c #B1D797", -"h. c #B1D699", -"j. c #B5D89E", -"k. c #ADC5AC", -"l. c #B1CAAE", -"z. c #B9DAA3", -"x. c #BDDDA8", -"c. c #ADC1B4", -"v. c #B2C6B6", -"b. c #B5C6BC", -"n. c #B6C9BA", -"m. c #BCD1BA", -"M. c #C6E1B4", -"N. c #CDE5BD", -"B. c #C2D2C6", -"V. c #CADEC2", -"C. c #C6D3CC", -"Z. c #C8D7CB", -"A. c #CEDAD2", -"S. c #D2DDD4", -"D. c #D3E9C6", -"F. c #D7EBC9", -"G. c #D9EBCD", -"H. c #DEEED4", -"J. c #D6E0D9", -"K. c #DAE4DC", -"L. c #E0EFD7", -"P. c #E5F2DD", -"I. c #DFE8E0", -"U. c #E4EBE5", -"Y. c #E9EFEA", -"T. c #EDF4EB", -"R. c #F0FAE6", -"E. c #F1F8EC", -"W. c #EDF0F0", -"Q. c #F4F7F3", -"!. c #F6F9F4", -"~. c #F8FAF7", -"^. c #FEFEFE", -"/. c None", -/* pixels */ -"/././././.c h ' Q / W _ &.p././././././././././././././././././././././././././././././././.", -"/././.4 O % Z ~ ~ W ~ W R U R R ( X.>.p././././././././././././././././././././././././././.", -"/./.. * = J _ ~ ~ ~ ~ ~ / / / / W W U P P U W .;.2././././././././././././././././././././.", -"/.= = & a ) W ~ ~ ~ ~ ~ / W / ~ ~ ~ ^ ( ( ^ ~ R R U P Y ~ .;.2././././././././././././././.", -"O.O = = T ^ W ~ ~ ~ ~ ~ ~ W W / W ~ ~ ~ ~ ~ ~ ~ ( ( ( ( ~ W Y Y Y Y W { &.1././././././././.", -"0 = * 7 ~ ~ ~ ~ ~ ~ ~ ~ ~ / / W ~ ~ ~ ~ ~ ~ ~ ~ W W W ~ ~ ~ ~ ( ( ( W W R U P U W { X.1.f./.", -"= = & e ^ W ~ ~ ~ ~ ~ ~ ~ ~ / / ~ ~ ~ ~ ~ ~ ~ ~ W ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ^ ( ( / ~ W R U U Y ", -"= = & e ^ W ~ ~ ~ ~ ~ ~ ~ ~ W W ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W ( W ~ ~ ~ ^ ^ ( ", -"= = * e ^ W ~ ~ ~ ~ ~ ~ / W / W ! ( / ~ W ^ ( ( ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W ~ W W ~ ~ ~ ~ ~ ~ ", -"= = & e ^ ! ~ ~ ~ ~ ~ ~ W W ^ _ ~ K Y W W R P Y W ( ~ ~ ~ ~ ~ ~ ~ W / ~ ~ ~ ^ W ~ ~ ~ ~ ~ ~ ", -"= = & e ^ W ~ ~ ~ ~ ~ ~ W ) W 1 ` w.V.L.H.D.z.,.~ Y ^ ~ ~ ~ ~ ~ W ~ ~ ~ ( ~ W W ~ ~ ~ ~ ~ ~ ", -"= = & e ^ W ~ ~ ~ ~ ~ W ) V = 8.~.^.^.^.^.^.^.^.U.<.Y ~ ~ ~ ~ ~ W W ! ~ Y W ^ W ~ ~ ~ ~ ~ ~ ", -"= = & e ^ W ~ ~ ~ ~ W ^ B O u.^.~.^.^.^.^.~.~.^.^.^.h.Y ^ ~ ~ ^ F $ k.R.G.1.Y / ~ ~ ~ ~ ~ ~ ", -"= = & e ^ ~ ~ ~ / W ( J X 7.^.~.^.^.^.^.^.^.^.^.^.^.^.s.Y / W ) a 2 U.^.^.d.U ( ~ ~ ~ ~ ~ ~ ", -"= = & e ^ W / ~ ~ ~ ^ > w ~.^.^.^.^.^.F.%.v c.^.^.^.^.~.X.W ~ ^ > h ^.^.^.d.P ( ~ ~ ~ ~ ~ ~ ", -"= = & e ^ W ~ ~ W ^ H o e.^.^.^.^.^.G.Y E n . y.^.^.^.^.M.Y ( ! $ @.^.~.^.f.U ( / ~ ~ W ~ ~ ", -"= = & e ^ W ~ W ! ) t 4 U.^.^.^.^.^.>.U ( _ , 9 ~.^.^.^.~...^ A y.^.~.^.s.M W Y ~ ~ ~ ~ ~ ", -"= 3 & e ^ W ~ ( ^ ( $ c ^.^.^.^.^.E.) ~ ~ ^ S o n.^.^.^.^.=.- l.v.Y.^.^.^.M.:.:.X.~ ~ ~ ~ ~ ", -"= = & e ^ ! W W ( J X 7.^.^.^.^.^.F.Y ( W ^ T X 6.^.^.~.^.c.. J.^.^.^.^.^.^.^.^.P.~ ~ ~ ~ ~ ", -"= = & r ^ W / W ) B o v.^.~.^.^.^.M.U / ~ ~ ! $ o.^.^.^.^.K.* S.^.^.^.^.^.^.^.^.P.~ ~ ~ ~ ~ ", -"= = & e ^ ! ~ W ) a + S.^.^.^.^.^.z.P ( W ~ ( % z ^.^.^.^.~.f t.U.^.^.^.^.~.^.^.P.~ ~ ~ ~ ~ ", -"* = & e ^ W ~ W ) t 3 Y.^.^.^.^.^.f.P ( ~ ~ ^ ; h ^.^.^.^.^.:.@ j ^.^.^.^.h.{ X.&.~ ~ ~ ~ ~ ", -"3 = & e ^ W ~ ~ ^ e 8 Q.^.^.^.^.^.s.P ~ ~ W ^ > 0 ~.^.^.^.^.1.# z ^.^.^.^.d.L W R ~ ~ ~ ~ ~ ", -"= = & e ^ W ~ ~ ^ > q ~.^.^.^.^.^.p.U ^ ~ W ) e 9 ~.^.^.^.^.3.# k ^.^.^.^.f.Y ( / ~ ~ ~ ~ ~ ", -"= = & e ^ W / W ^ > w ~.^.^.^.^.^.i.Y / ~ W ^ e 8 Q.^.^.^.^.a.# z ^.^.^.^.f.Y / ~ ~ ~ ~ ~ ~ ", -"= = & e ^ W / W ^ > w ^.^.^.^.^.^.2.Y / ~ ~ ) e 8 Q.^.^.^.^.s.# z ^.^.^.^.d.P ( ~ ~ ~ ~ ~ ~ ", -"= = & e ^ W W W ^ > q ^.^.^.^.^.^.p.Y / ~ ~ ^ e 9 Q.^.^.^.^.a.@ z ^.^.^.^.f.U / ~ ~ ~ ~ ~ ~ ", -"= = & e ^ W / W ) 7 9 Q.^.^.^.^.^.a.P / ~ W ) , 9 Q.^.^.^.^.3.# z ^.^.~.^.f.P ^ ~ ~ ~ ~ ~ ~ ", -"= = & e ^ W / W ) r 5 T.^.^.^.^.^.d.Y / ~ W ) > q ~.^.^.^.^.1.# k ^.^.^.^.f.Y ( ~ ~ ~ ~ ~ ~ ", -"= = & e ^ / / W ) i 2 I.^.^.^.^.^.h.P ( ~ W ( > g ^.^.^.^.^.:.# z ^.^.^.^.f.P / ~ ~ ~ ~ ~ ~ ", -"= = & e ( W / W ) m O Z.^.^.^.^.^.x.P / ~ ~ ( ; j ^.^.^.^.~.&.- k ^.^.~.^.f.P / ~ ~ ~ ~ ~ ~ ", -"= = & e ( W / W ) F o y.^.~.^.^.^.N.U ( ~ ~ W $ b ^.^.^.^.R._ - k ^.^.^.^.f.Y ( ~ ~ ~ ~ ~ ~ ", -"= = & e ^ W ~ ~ ^ J X 4.^.^.^.^.^.L.~ ~ W ^ T X #.^.^.^.^.F.~ ; j ^.^.^.^.f.U ( ~ ~ ~ ~ ~ ~ ", -"= = & e ^ ~ ~ ~ / ^ % l ^.^.^.^.^.!. .R ^ ^ G . r.^.~.^.^.j.E : j ^.^.^.^.f.P ) ( ~ ~ ~ ~ ~ ", -"= = & e ^ W ~ ~ W ) u = U.^.^.^.^.^.1.Y ! ) a & K.^.^.^.^.;.~ : j ^.^.~.^.z.M I I / ~ ~ W ~ ", -"= = & e ( W ~ ~ W ( G . q.^.^.^.^.^.D.U ^ ! X o.^.^.^.^.P.~ ^ > g ^.^.^.^.E.-.$.m.X.W ~ ~ ~ ", -"= = & e ^ / ~ ~ ^ ! ( > w ~.^.^.^.^.^.h.T > j T.^.^.~.^.a.Y _ i 3 U.^.^.^.^.^.^.^.X.R ~ ~ ~ ", -"= = & e ^ / ~ ~ W W ^ H . 9.^.~.^.^.^.^.K.C.~.^.^.^.^.H.W W ^ T . q.^.~.^.^.^.^.^.X.R ~ ~ ~ ", -"= = + e ^ W / ~ W W W ) m + B.^.~.^.^.^.^.^.^.^.^.^.E.X.Y ( W ^ B 6 y.^.^.^.E.D.2.( ~ ~ ~ ~ ", -"= = * e ^ ! / ! W ^ W W ) a 4 b.^.^.^.^.^.^.^.^.^.P...Y ( ! W ! ^ W Z [ *.X.{ Y U ~ ~ ~ ~ ~ ", -"= = & e ( W ~ ~ W / W / W ) A < +.A.~.^.^.^.^.!.p.W R ~ ~ ~ ~ ~ W / ) E U W W / ^ ~ ~ ~ ~ ~ ", -"= = & e ^ W ~ ~ / W / / / W ( _ Z X 6.^.^.^.^.E.W ~ ^ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ / ~ ~ ~ ~ ~ ~ ~ ~ ", -"= = & e ^ ~ ~ ~ W W / W ~ ~ ~ ~ ) ; h ^.^.^.^.^.d.M U ~ / ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W ", -"= = & e ^ W ~ ~ ^ W W / ~ ~ ~ W ) p + S.^.^.^.^.~.M.f. .W ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ .", -"= = & e ^ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W ( T O +.^.~.^.^.^.^.^.&.Y ( ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W ( Y 2.", -"= = & e ( W ~ ~ ~ ~ ~ ~ ~ ~ ~ / W ) N + b.^.^.^.^.^.^.&.R ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W /.", -"= = & e ^ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W ^ N 7 r.W.^.^.^.!.X.W ~ ~ W ~ W ~ ~ ~ ~ ~ ~ / ( ( K p./.", -"= = & e ( W ~ ~ W ~ ~ ~ ~ ~ ~ ~ ~ ~ W ( W C Q &.:.X.| ~ ~ ~ ~ W ~ / ~ ( / ( ~ W E U P 1././.", -"= = + e ^ / / / ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W / ) ^ R Y W W ~ ~ ( / ( / W R Y Y U R ( X.,././././.", -"= = * e ( / ~ / ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W W W ! ( ( ( W W E U P Y W ( X.,.d./././././././././.", -"= = * e ( W ~ ~ ~ ~ W ! ~ W ~ W ~ ( ( / ^ W W U Y P W ( X.,.d./././././././././././././././.", -"8 $ * e ( W ~ ~ ~ ! ( ( ( / ( W R Y Y Y R ( X.>.d./././././././././././././././././././././.", -"/.d . y ^ / / / ( W Y Y P P W ( X.>.d./././././././././././././././././././././././././././.", -"/./.h : ^ R R R W ( X.<.f./././././././././././././././././././././././././././././././././.", -"/././.] _ *.3./././././././././././././././././././././././././././././././././././././././." -}; - -class EvalMessageBox : public QDialog -{ -public: - EvalMessageBox(bool expired) - { - setWindowTitle(QLatin1String(" ")); - - QString str = expired ? QLatin1String(boilerplate_expired) : qt_eval_string(); - str = str.trimmed(); - - QFrame *border = new QFrame(this); - - QLabel *pixmap_label = new QLabel(border); - pixmap_label->setPixmap(QPixmap(qtlogo_eval_xpm)); - pixmap_label->setAlignment(Qt::AlignTop); - - QLabel *text_label = new QLabel(str, border); - - QHBoxLayout *pm_and_text_layout = new QHBoxLayout(); - pm_and_text_layout->addWidget(pixmap_label); - pm_and_text_layout->addWidget(text_label); - - QVBoxLayout *master_layout = new QVBoxLayout(border); - master_layout->addLayout(pm_and_text_layout); - - QVBoxLayout *border_layout = new QVBoxLayout(this); - border_layout->setMargin(0); - border_layout->addWidget(border); - - if (expired) { - QPushButton *cmd = new QPushButton(QLatin1String("OK"), border); - cmd->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - cmd->setDefault(true); - - QHBoxLayout *button_layout = new QHBoxLayout(); - master_layout->addLayout(button_layout); - button_layout->addWidget(cmd); - - connect(cmd, SIGNAL(clicked()), this, SLOT(close())); - } else { - border->setFrameShape(QFrame::WinPanel); - border->setFrameShadow(QFrame::Raised); - setParent(parentWidget(), Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); - QTimer::singleShot(7000, this, SLOT(close())); - setAttribute(Qt::WA_DeleteOnClose); - setAttribute(Qt::WA_QuitOnClose, false); - } - - setFixedSize(sizeHint()); - } -}; - -class QGuiFuriCuri : public QCoreFuriCuri -{ -public: - void timerEvent(QTimerEvent *e) { - if (e->timerId() == warn) { - killTimer(warn); - QMessageBox::information(0, QLatin1String("Automatic Timeout"), QLatin1String(will_shutdown_1min)); - kill = startTimer(KILL_DELAY); - } else if (e->timerId() == kill) { - killTimer(kill); - QMessageBox::information(0, QLatin1String("Automatic Timeout"), QLatin1String(will_shutdown_now)); - qApp->quit(); - } - } -}; - - -void qt_gui_eval_init(QCoreApplicationPrivate::Type type) -{ - Q_UNUSED(type); - - if (!qt_eval_is_supported()) - return; - - if (qt_eval_is_expired()) { - EvalMessageBox box(true); - box.exec(); - ::exit(0); - } else { - Q_UNUSED(new QGuiFuriCuri()); - } -} - -static QString qt_eval_title_prefix() -{ - return QLatin1String("[Qt Evaluation] "); -} - -QString qt_eval_adapt_window_title(const QString &title) -{ - if (!qt_eval_is_supported()) - return title; - return qt_eval_title_prefix() + title; -} - -void qt_eval_init_widget(QWidget *w) -{ - if (!qt_eval_is_supported()) - return; - if (w->isTopLevel() && w->windowTitle().isEmpty() && w->windowType() != Qt::Desktop ) { - w->setWindowTitle(QLatin1String(" ")); - } -} -#endif - -QT_END_NAMESPACE diff --git a/src/corelib/kernel/qtestsupport_core.cpp b/src/corelib/kernel/qtestsupport_core.cpp index c54b933f94..7bd81ed498 100644 --- a/src/corelib/kernel/qtestsupport_core.cpp +++ b/src/corelib/kernel/qtestsupport_core.cpp @@ -102,7 +102,7 @@ Q_CORE_EXPORT void QTest::qWait(int ms) int remaining = ms; do { QCoreApplication::processEvents(QEventLoop::AllEvents, remaining); - QCoreApplication::sendPostedEvents(Q_NULLPTR, QEvent::DeferredDelete); + QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); remaining = timer.remainingTime(); if (remaining <= 0) break; diff --git a/src/corelib/kernel/qtimer.cpp b/src/corelib/kernel/qtimer.cpp index 13f027074a..188d529f04 100644 --- a/src/corelib/kernel/qtimer.cpp +++ b/src/corelib/kernel/qtimer.cpp @@ -42,6 +42,8 @@ #include "qabstracteventdispatcher.h" #include "qcoreapplication.h" #include "qobject_p.h" +#include "qthread.h" +#include "qcoreapplication_p.h" QT_BEGIN_NAMESPACE @@ -343,6 +345,33 @@ void QTimer::singleShotImpl(int msec, Qt::TimerType timerType, const QObject *receiver, QtPrivate::QSlotObjectBase *slotObj) { + if (msec == 0) { + bool deleteReceiver = false; + // Optimize: set a receiver context when none is given, such that we can use + // QMetaObject::invokeMethod which is more efficient than going through a timer. + // We need a QObject living in the current thread. But the QThread itself lives + // in a different thread - with the exception of the main QThread which lives in + // itself. And QThread::currentThread() is among the few QObjects we know that will + // most certainly be there. Note that one can actually call singleShot before the + // QApplication is created! + if (!receiver && QThread::currentThread() == QCoreApplicationPrivate::mainThread()) { + // reuse main thread as context object + receiver = QThread::currentThread(); + } else if (!receiver) { + // Create a receiver context object on-demand. According to the benchmarks, + // this is still more efficient than going through a timer. + receiver = new QObject; + deleteReceiver = true; + } + + QMetaObject::invokeMethodImpl(const_cast<QObject *>(receiver), slotObj, + Qt::QueuedConnection, nullptr); + + if (deleteReceiver) + const_cast<QObject *>(receiver)->deleteLater(); + return; + } + new QSingleShotTimer(msec, timerType, receiver, slotObj); } diff --git a/src/corelib/kernel/qtimer.h b/src/corelib/kernel/qtimer.h index 66f317c567..ae5552f1c9 100644 --- a/src/corelib/kernel/qtimer.h +++ b/src/corelib/kernel/qtimer.h @@ -218,7 +218,7 @@ private: inline int startTimer(int){ return -1;} inline void killTimer(int){} - static Q_DECL_CONSTEXPR Qt::TimerType defaultTypeFor(int msecs) Q_DECL_NOTHROW + static Q_DECL_CONSTEXPR Qt::TimerType defaultTypeFor(int msecs) noexcept { return msecs >= 2000 ? Qt::CoarseTimer : Qt::PreciseTimer; } static void singleShotImpl(int msec, Qt::TimerType timerType, const QObject *receiver, QtPrivate::QSlotObjectBase *slotObj); diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 18c7f7648d..4af2073365 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Copyright (C) 2018 Intel Corporation. ** Copyright (C) 2015 Olivier Goffart <ogoffart@woboq.com> ** Contact: https://www.qt.io/licensing/ @@ -55,6 +55,7 @@ #include "qstringlist.h" #include "qurl.h" #include "qlocale.h" +#include "qregexp.h" #include "quuid.h" #if QT_CONFIG(itemmodel) #include "qabstractitemmodel.h" @@ -1462,6 +1463,7 @@ static void customConstruct(QVariant::Private *d, const void *copy) if (size <= sizeof(QVariant::Private::Data) && (type.flags() & (QMetaType::MovableType | QMetaType::IsEnumeration))) { type.construct(&d->data.ptr, copy); + d->is_null = d->data.ptr == nullptr; d->is_shared = false; } else { // Private::Data contains long long, and long double is the biggest standard type. @@ -1472,6 +1474,7 @@ static void customConstruct(QVariant::Private *d, const void *copy) void *data = operator new(offset + size); void *ptr = static_cast<char *>(data) + offset; type.construct(ptr, copy); + d->is_null = ptr == nullptr; d->is_shared = true; d->data.shared = new (data) QVariant::PrivateShared(ptr); } @@ -4002,8 +4005,8 @@ static int numericCompare(const QVariant::Private *d1, const QVariant::Private * return 0; // only do fuzzy comparisons for finite, non-zero numbers - int c1 = std::fpclassify(r1); - int c2 = std::fpclassify(r2); + int c1 = qFpClassify(r1); + int c2 = qFpClassify(r2); if ((c1 == FP_NORMAL || c1 == FP_SUBNORMAL) && (c2 == FP_NORMAL || c2 == FP_SUBNORMAL)) { if (qFuzzyCompare(r1, r2)) return 0; @@ -4280,6 +4283,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p) \sa fromValue() */ +#if QT_DEPRECATED_SINCE(5, 14) /*! \fn template<typename T> QVariant qVariantFromValue(const T &value) \relates QVariant @@ -4317,6 +4321,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p) \sa QVariant::setValue() */ +#endif /*! \fn template<typename T> T qvariant_cast(const QVariant &value) diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index f95502e75f..2247c7adc8 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -92,9 +92,6 @@ class QUrl; class QVariant; class QVariantComparisonHelper; -template <typename T> -inline QVariant qVariantFromValue(const T &); - template<typename T> inline T qvariant_cast(const QVariant &); @@ -204,7 +201,7 @@ class Q_CORE_EXPORT QVariant LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type }; - QVariant() Q_DECL_NOTHROW : d() {} + QVariant() noexcept : d() {} ~QVariant(); QVariant(Type type); QVariant(int typeId, const void *copy); @@ -270,14 +267,12 @@ class Q_CORE_EXPORT QVariant #endif QVariant& operator=(const QVariant &other); -#ifdef Q_COMPILER_RVALUE_REFS - inline QVariant(QVariant &&other) Q_DECL_NOTHROW : d(other.d) + inline QVariant(QVariant &&other) noexcept : d(other.d) { other.d = Private(); } - inline QVariant &operator=(QVariant &&other) Q_DECL_NOTHROW + inline QVariant &operator=(QVariant &&other) noexcept { qSwap(d, other.d); return *this; } -#endif - inline void swap(QVariant &other) Q_DECL_NOTHROW { qSwap(d, other.d); } + inline void swap(QVariant &other) noexcept { qSwap(d, other.d); } Type type() const; int userType() const; @@ -365,7 +360,7 @@ class Q_CORE_EXPORT QVariant template<typename T> static inline QVariant fromValue(const T &value) - { return qVariantFromValue(value); } + { return QVariant(qMetaTypeId<T>(), &value, QTypeInfo<T>::isPointer); } #if QT_HAS_INCLUDE(<variant>) && __cplusplus >= 201703L template<typename... Types> @@ -390,15 +385,15 @@ class Q_CORE_EXPORT QVariant }; struct Private { - inline Private() Q_DECL_NOTHROW : type(Invalid), is_shared(false), is_null(true) + inline Private() noexcept : type(Invalid), is_shared(false), is_null(true) { data.ptr = nullptr; } // Internal constructor for initialized variants. - explicit inline Private(uint variantType) Q_DECL_NOTHROW + explicit inline Private(uint variantType) noexcept : type(variantType), is_shared(false), is_null(false) {} - inline Private(const Private &other) Q_DECL_NOTHROW + inline Private(const Private &other) noexcept : data(other.data), type(other.type), is_shared(other.is_shared), is_null(other.is_null) {} @@ -516,50 +511,61 @@ public: inline const DataPtr &data_ptr() const { return d; } }; +#if QT_DEPRECATED_SINCE(5, 14) template <typename T> +QT_DEPRECATED_X("Use QVariant::fromValue() instead.") inline QVariant qVariantFromValue(const T &t) { - return QVariant(qMetaTypeId<T>(), &t, QTypeInfo<T>::isPointer); + return QVariant::fromValue(t); +} + +template <typename T> +QT_DEPRECATED_X("Use QVariant::setValue() instead.") +inline void qVariantSetValue(QVariant &v, const T &t) +{ + v.setValue(t); } +#endif -template <> -inline QVariant qVariantFromValue(const QVariant &t) { return t; } +template<> +inline QVariant QVariant::fromValue(const QVariant &value) +{ + return value; +} #if QT_HAS_INCLUDE(<variant>) && __cplusplus >= 201703L -template <> -inline QVariant qVariantFromValue(const std::monostate &) { return QVariant(); } +template<> +inline QVariant QVariant::fromValue(const std::monostate &) +{ + return QVariant(); +} #endif -template <typename T> -inline void qVariantSetValue(QVariant &v, const T &t) +inline bool QVariant::isValid() const { return d.type != Invalid; } + +template<typename T> +inline void QVariant::setValue(const T &avalue) { - //if possible we reuse the current QVariant private + // If possible we reuse the current QVariant private. const uint type = qMetaTypeId<T>(); - QVariant::Private &d = v.data_ptr(); - if (v.isDetached() && (type == d.type || (type <= uint(QVariant::Char) && d.type <= uint(QVariant::Char)))) { + if (isDetached() && (type == d.type || (type <= uint(QVariant::Char) && d.type <= uint(QVariant::Char)))) { d.type = type; d.is_null = false; T *old = reinterpret_cast<T*>(d.is_shared ? d.data.shared->ptr : &d.data.ptr); if (QTypeInfo<T>::isComplex) old->~T(); - new (old) T(t); //call the copy constructor + new (old) T(avalue); // call the copy constructor } else { - v = QVariant(type, &t, QTypeInfo<T>::isPointer); + *this = QVariant(type, &avalue, QTypeInfo<T>::isPointer); } } -template <> -inline void qVariantSetValue<QVariant>(QVariant &v, const QVariant &t) +template<> +inline void QVariant::setValue(const QVariant &avalue) { - v = t; + *this = avalue; } -inline bool QVariant::isValid() const { return d.type != Invalid; } - -template<typename T> -inline void QVariant::setValue(const T &avalue) -{ qVariantSetValue(*this, avalue); } - #ifndef QT_NO_DATASTREAM Q_CORE_EXPORT QDataStream& operator>> (QDataStream& s, QVariant& p); Q_CORE_EXPORT QDataStream& operator<< (QDataStream& s, const QVariant& p); diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h index b22b7c231e..3d87beac83 100644 --- a/src/corelib/kernel/qvariant_p.h +++ b/src/corelib/kernel/qvariant_p.h @@ -88,7 +88,7 @@ inline T *v_cast(const QVariant::Private *nd, T * = 0) #else // every other compiler in this world template <typename T> -inline const T *v_cast(const QVariant::Private *d, T * = 0) +inline const T *v_cast(const QVariant::Private *d, T * = nullptr) { return !QVariantIntegrator<T>::CanUseInternalSpace ? static_cast<const T *>(d->data.shared->ptr) @@ -96,7 +96,7 @@ inline const T *v_cast(const QVariant::Private *d, T * = 0) } template <typename T> -inline T *v_cast(QVariant::Private *d, T * = 0) +inline T *v_cast(QVariant::Private *d, T * = nullptr) { return !QVariantIntegrator<T>::CanUseInternalSpace ? static_cast<T *>(d->data.shared->ptr) @@ -154,7 +154,7 @@ inline void v_construct(QVariant::Private *x, const T &t) // constructs a new variant if copy is 0, otherwise copy-constructs template <class T> -inline void v_construct(QVariant::Private *x, const void *copy, T * = 0) +inline void v_construct(QVariant::Private *x, const void *copy, T * = nullptr) { if (copy) v_construct<T>(x, *static_cast<const T *>(copy)); @@ -164,7 +164,7 @@ inline void v_construct(QVariant::Private *x, const void *copy, T * = 0) // deletes the internal structures template <class T> -inline void v_clear(QVariant::Private *d, T* = 0) +inline void v_clear(QVariant::Private *d, T* = nullptr) { if (!QVariantIntegrator<T>::CanUseInternalSpace) { @@ -264,7 +264,7 @@ class QVariantIsNull struct No { char unused[2]; }; Q_STATIC_ASSERT(sizeof(Yes) != sizeof(No)); - template<class C> static decltype(static_cast<const C*>(0)->isNull(), Yes()) test(int); + template<class C> static decltype(static_cast<const C*>(nullptr)->isNull(), Yes()) test(int); template<class C> static No test(...); public: static const bool Value = (sizeof(test<T>(0)) == sizeof(Yes)); diff --git a/src/corelib/mimetypes/qmimeglobpattern_p.h b/src/corelib/mimetypes/qmimeglobpattern_p.h index bb6f64320b..cf27d6ab30 100644 --- a/src/corelib/mimetypes/qmimeglobpattern_p.h +++ b/src/corelib/mimetypes/qmimeglobpattern_p.h @@ -88,7 +88,7 @@ public: { } - void swap(QMimeGlobPattern &other) Q_DECL_NOTHROW + void swap(QMimeGlobPattern &other) noexcept { qSwap(m_pattern, other.m_pattern); qSwap(m_mimeType, other.m_mimeType); diff --git a/src/corelib/mimetypes/qmimemagicrule_p.h b/src/corelib/mimetypes/qmimemagicrule_p.h index 6962a6ca59..5091d483b6 100644 --- a/src/corelib/mimetypes/qmimemagicrule_p.h +++ b/src/corelib/mimetypes/qmimemagicrule_p.h @@ -69,7 +69,7 @@ public: QMimeMagicRule(const QString &typeStr, const QByteArray &value, const QString &offsets, const QByteArray &mask, QString *errorString); - void swap(QMimeMagicRule &other) Q_DECL_NOTHROW + void swap(QMimeMagicRule &other) noexcept { qSwap(m_type, other.m_type); qSwap(m_value, other.m_value); diff --git a/src/corelib/mimetypes/qmimemagicrulematcher_p.h b/src/corelib/mimetypes/qmimemagicrulematcher_p.h index 5e74e2e3fc..fe714987e6 100644 --- a/src/corelib/mimetypes/qmimemagicrulematcher_p.h +++ b/src/corelib/mimetypes/qmimemagicrulematcher_p.h @@ -66,7 +66,7 @@ class QMimeMagicRuleMatcher public: explicit QMimeMagicRuleMatcher(const QString &mime, unsigned priority = 65535); - void swap(QMimeMagicRuleMatcher &other) Q_DECL_NOTHROW + void swap(QMimeMagicRuleMatcher &other) noexcept { qSwap(m_list, other.m_list); qSwap(m_priority, other.m_priority); diff --git a/src/corelib/mimetypes/qmimeprovider.cpp b/src/corelib/mimetypes/qmimeprovider.cpp index 37c8e3b157..7e2696b719 100644 --- a/src/corelib/mimetypes/qmimeprovider.cpp +++ b/src/corelib/mimetypes/qmimeprovider.cpp @@ -460,6 +460,7 @@ void QMimeBinaryProvider::addAllMimeTypes(QList<QMimeType> &result) void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data) { #ifdef QT_NO_XMLSTREAMREADER + Q_UNUSED(data); qWarning("Cannot load mime type since QXmlStreamReader is not available."); return; #else diff --git a/src/corelib/mimetypes/qmimetype.cpp b/src/corelib/mimetypes/qmimetype.cpp index 55c7de0c87..cf01c9503b 100644 --- a/src/corelib/mimetypes/qmimetype.cpp +++ b/src/corelib/mimetypes/qmimetype.cpp @@ -192,7 +192,7 @@ bool QMimeType::operator==(const QMimeType &other) const Returns the hash value for \a key, using \a seed to seed the calculation. */ -uint qHash(const QMimeType &key, uint seed) Q_DECL_NOTHROW +uint qHash(const QMimeType &key, uint seed) noexcept { return qHash(key.d->name, seed); } diff --git a/src/corelib/mimetypes/qmimetype.h b/src/corelib/mimetypes/qmimetype.h index 8287f1434b..6d6f9eb488 100644 --- a/src/corelib/mimetypes/qmimetype.h +++ b/src/corelib/mimetypes/qmimetype.h @@ -55,7 +55,7 @@ class QMimeTypePrivate; class QStringList; class QMimeType; -Q_CORE_EXPORT uint qHash(const QMimeType &key, uint seed = 0) Q_DECL_NOTHROW; +Q_CORE_EXPORT uint qHash(const QMimeType &key, uint seed = 0) noexcept; class Q_CORE_EXPORT QMimeType { @@ -78,10 +78,8 @@ public: QMimeType(); QMimeType(const QMimeType &other); QMimeType &operator=(const QMimeType &other); -#ifdef Q_COMPILER_RVALUE_REFS - QMimeType &operator=(QMimeType &&other) Q_DECL_NOTHROW { swap(other); return *this; } -#endif - void swap(QMimeType &other) Q_DECL_NOTHROW + QMimeType &operator=(QMimeType &&other) noexcept { swap(other); return *this; } + void swap(QMimeType &other) noexcept { qSwap(d, other.d); } @@ -121,7 +119,7 @@ protected: friend class QMimeXMLProvider; friend class QMimeBinaryProvider; friend class QMimeTypePrivate; - friend Q_CORE_EXPORT uint qHash(const QMimeType &key, uint seed) Q_DECL_NOTHROW; + friend Q_CORE_EXPORT uint qHash(const QMimeType &key, uint seed) noexcept; QExplicitlySharedDataPointer<QMimeTypePrivate> d; }; diff --git a/src/corelib/mimetypes/qmimetype_p.h b/src/corelib/mimetypes/qmimetype_p.h index 5a36e6613c..2918309ad7 100644 --- a/src/corelib/mimetypes/qmimetype_p.h +++ b/src/corelib/mimetypes/qmimetype_p.h @@ -103,7 +103,6 @@ QT_END_NAMESPACE } \ QT_END_NAMESPACE -#ifdef Q_COMPILER_RVALUE_REFS #define QMIMETYPE_BUILDER_FROM_RVALUE_REFS \ QT_BEGIN_NAMESPACE \ static QMimeType buildQMimeType ( \ @@ -122,6 +121,5 @@ QT_END_NAMESPACE return QMimeType(qMimeTypeData); \ } \ QT_END_NAMESPACE -#endif #endif // QMIMETYPE_P_H diff --git a/src/corelib/mimetypes/qmimetypeparser.cpp b/src/corelib/mimetypes/qmimetypeparser.cpp index d10575cfe9..815e0aa03b 100644 --- a/src/corelib/mimetypes/qmimetypeparser.cpp +++ b/src/corelib/mimetypes/qmimetypeparser.cpp @@ -194,8 +194,9 @@ static CreateMagicMatchRuleResult createMagicMatchRule(const QXmlStreamAttribute bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString *errorMessage) { #ifdef QT_NO_XMLSTREAMREADER + Q_UNUSED(dev); if (errorMessage) - *errorMessage = QString::fromLatin1("QXmlStreamReader is not available, cannot parse."); + *errorMessage = QString::fromLatin1("QXmlStreamReader is not available, cannot parse '%1'.").arg(fileName); return false; #else QMimeTypePrivate data; diff --git a/src/corelib/plugin/qlibrary_p.h b/src/corelib/plugin/qlibrary_p.h index 3f650501c8..1a216c98b5 100644 --- a/src/corelib/plugin/qlibrary_p.h +++ b/src/corelib/plugin/qlibrary_p.h @@ -96,7 +96,7 @@ public: void setLoadHints(QLibrary::LoadHints lh); static QLibraryPrivate *findOrCreate(const QString &fileName, const QString &version = QString(), - QLibrary::LoadHints loadHints = 0); + QLibrary::LoadHints loadHints = nullptr); static QStringList suffixes_sys(const QString &fullVersion); static QStringList prefixes_sys(); diff --git a/src/corelib/plugin/qplugin_p.h b/src/corelib/plugin/qplugin_p.h index 717129268b..ce45ebf700 100644 --- a/src/corelib/plugin/qplugin_p.h +++ b/src/corelib/plugin/qplugin_p.h @@ -60,7 +60,8 @@ enum class QtPluginMetaDataKeys { Requirements, IID, ClassName, - MetaData + MetaData, + URI }; // F(IntKey, StringKey, Description) @@ -68,7 +69,8 @@ enum class QtPluginMetaDataKeys { #define QT_PLUGIN_FOREACH_METADATA(F) \ F(QtPluginMetaDataKeys::IID, "IID", "Plugin's Interface ID") \ F(QtPluginMetaDataKeys::ClassName, "className", "Plugin class name") \ - F(QtPluginMetaDataKeys::MetaData, "MetaData", "Other meta data") + F(QtPluginMetaDataKeys::MetaData, "MetaData", "Other meta data") \ + F(QtPluginMetaDataKeys::URI, "URI", "Plugin URI") QT_END_NAMESPACE diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp index 8bb5e1463a..83873edf6f 100644 --- a/src/corelib/plugin/quuid.cpp +++ b/src/corelib/plugin/quuid.cpp @@ -397,7 +397,7 @@ QUuid::QUuid(const QString &text) \sa toString(), QUuid() */ -QUuid QUuid::fromString(QStringView text) Q_DECL_NOTHROW +QUuid QUuid::fromString(QStringView text) noexcept { if (text.size() > MaxStringUuidLength) text = text.left(MaxStringUuidLength); // text.truncate(MaxStringUuidLength); @@ -427,7 +427,7 @@ QUuid QUuid::fromString(QStringView text) Q_DECL_NOTHROW \sa toString(), QUuid() */ -QUuid QUuid::fromString(QLatin1String text) Q_DECL_NOTHROW +QUuid QUuid::fromString(QLatin1String text) noexcept { if (Q_UNLIKELY(text.size() < MaxStringUuidLength - 2 || (text.front() == QLatin1Char('{') && text.size() < MaxStringUuidLength - 1))) { @@ -864,7 +864,7 @@ QDataStream &operator>>(QDataStream &s, QUuid &id) Returns \c true if this is the null UUID {00000000-0000-0000-0000-000000000000}; otherwise returns \c false. */ -bool QUuid::isNull() const Q_DECL_NOTHROW +bool QUuid::isNull() const noexcept { return data4[0] == 0 && data4[1] == 0 && data4[2] == 0 && data4[3] == 0 && data4[4] == 0 && data4[5] == 0 && data4[6] == 0 && data4[7] == 0 && @@ -913,7 +913,7 @@ bool QUuid::isNull() const Q_DECL_NOTHROW \sa version() */ -QUuid::Variant QUuid::variant() const Q_DECL_NOTHROW +QUuid::Variant QUuid::variant() const noexcept { if (isNull()) return VarUnknown; @@ -934,7 +934,7 @@ QUuid::Variant QUuid::variant() const Q_DECL_NOTHROW \sa variant() */ -QUuid::Version QUuid::version() const Q_DECL_NOTHROW +QUuid::Version QUuid::version() const noexcept { // Check the 4 MSB of data3 Version ver = (Version)(data3>>12); @@ -957,7 +957,7 @@ QUuid::Version QUuid::version() const Q_DECL_NOTHROW \sa variant() */ -bool QUuid::operator<(const QUuid &other) const Q_DECL_NOTHROW +bool QUuid::operator<(const QUuid &other) const noexcept { if (variant() != other.variant()) return variant() < other.variant(); @@ -984,7 +984,7 @@ bool QUuid::operator<(const QUuid &other) const Q_DECL_NOTHROW \sa variant() */ -bool QUuid::operator>(const QUuid &other) const Q_DECL_NOTHROW +bool QUuid::operator>(const QUuid &other) const noexcept { return other < *this; } @@ -1089,7 +1089,7 @@ QDebug operator<<(QDebug dbg, const QUuid &id) \relates QUuid Returns a hash of the UUID \a uuid, using \a seed to seed the calculation. */ -uint qHash(const QUuid &uuid, uint seed) Q_DECL_NOTHROW +uint qHash(const QUuid &uuid, uint seed) noexcept { return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16) ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3]) diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h index 08a1843640..713ca070c8 100644 --- a/src/corelib/plugin/quuid.h +++ b/src/corelib/plugin/quuid.h @@ -93,13 +93,13 @@ public: #if defined(Q_COMPILER_UNIFORM_INIT) && !defined(Q_CLANG_QDOC) - Q_DECL_CONSTEXPR QUuid() Q_DECL_NOTHROW : data1(0), data2(0), data3(0), data4{0,0,0,0,0,0,0,0} {} + Q_DECL_CONSTEXPR QUuid() noexcept : data1(0), data2(0), data3(0), data4{0,0,0,0,0,0,0,0} {} Q_DECL_CONSTEXPR QUuid(uint l, ushort w1, ushort w2, uchar b1, uchar b2, uchar b3, - uchar b4, uchar b5, uchar b6, uchar b7, uchar b8) Q_DECL_NOTHROW + uchar b4, uchar b5, uchar b6, uchar b7, uchar b8) noexcept : data1(l), data2(w1), data3(w2), data4{b1, b2, b3, b4, b5, b6, b7, b8} {} #else - QUuid() Q_DECL_NOTHROW + QUuid() noexcept { data1 = 0; data2 = 0; @@ -107,7 +107,7 @@ public: for(int i = 0; i < 8; i++) data4[i] = 0; } - QUuid(uint l, ushort w1, ushort w2, uchar b1, uchar b2, uchar b3, uchar b4, uchar b5, uchar b6, uchar b7, uchar b8) Q_DECL_NOTHROW + QUuid(uint l, ushort w1, ushort w2, uchar b1, uchar b2, uchar b3, uchar b4, uchar b5, uchar b6, uchar b7, uchar b8) noexcept { data1 = l; data2 = w1; @@ -124,8 +124,8 @@ public: #endif QUuid(const QString &); - static QUuid fromString(QStringView string) Q_DECL_NOTHROW; - static QUuid fromString(QLatin1String string) Q_DECL_NOTHROW; + static QUuid fromString(QStringView string) noexcept; + static QUuid fromString(QLatin1String string) noexcept; QUuid(const char *); QString toString() const; QString toString(StringFormat mode) const; // ### Qt6: merge with previous @@ -134,9 +134,9 @@ public: QByteArray toByteArray(StringFormat mode) const; // ### Qt6: merge with previous QByteArray toRfc4122() const; static QUuid fromRfc4122(const QByteArray &); - bool isNull() const Q_DECL_NOTHROW; + bool isNull() const noexcept; - Q_DECL_RELAXED_CONSTEXPR bool operator==(const QUuid &orig) const Q_DECL_NOTHROW + Q_DECL_RELAXED_CONSTEXPR bool operator==(const QUuid &orig) const noexcept { if (data1 != orig.data1 || data2 != orig.data2 || data3 != orig.data3) @@ -149,24 +149,24 @@ public: return true; } - Q_DECL_RELAXED_CONSTEXPR bool operator!=(const QUuid &orig) const Q_DECL_NOTHROW + Q_DECL_RELAXED_CONSTEXPR bool operator!=(const QUuid &orig) const noexcept { return !(*this == orig); } - bool operator<(const QUuid &other) const Q_DECL_NOTHROW; - bool operator>(const QUuid &other) const Q_DECL_NOTHROW; + bool operator<(const QUuid &other) const noexcept; + bool operator>(const QUuid &other) const noexcept; #if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC) // On Windows we have a type GUID that is used by the platform API, so we // provide convenience operators to cast from and to this type. #if defined(Q_COMPILER_UNIFORM_INIT) && !defined(Q_CLANG_QDOC) - Q_DECL_CONSTEXPR QUuid(const GUID &guid) Q_DECL_NOTHROW + Q_DECL_CONSTEXPR QUuid(const GUID &guid) noexcept : data1(guid.Data1), data2(guid.Data2), data3(guid.Data3), data4{guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]} {} #else - QUuid(const GUID &guid) Q_DECL_NOTHROW + QUuid(const GUID &guid) noexcept { data1 = guid.Data1; data2 = guid.Data2; @@ -176,24 +176,24 @@ public: } #endif - Q_DECL_RELAXED_CONSTEXPR QUuid &operator=(const GUID &guid) Q_DECL_NOTHROW + Q_DECL_RELAXED_CONSTEXPR QUuid &operator=(const GUID &guid) noexcept { *this = QUuid(guid); return *this; } - Q_DECL_RELAXED_CONSTEXPR operator GUID() const Q_DECL_NOTHROW + Q_DECL_RELAXED_CONSTEXPR operator GUID() const noexcept { GUID guid = { data1, data2, data3, { data4[0], data4[1], data4[2], data4[3], data4[4], data4[5], data4[6], data4[7] } }; return guid; } - Q_DECL_RELAXED_CONSTEXPR bool operator==(const GUID &guid) const Q_DECL_NOTHROW + Q_DECL_RELAXED_CONSTEXPR bool operator==(const GUID &guid) const noexcept { return *this == QUuid(guid); } - Q_DECL_RELAXED_CONSTEXPR bool operator!=(const GUID &guid) const Q_DECL_NOTHROW + Q_DECL_RELAXED_CONSTEXPR bool operator!=(const GUID &guid) const noexcept { return !(*this == guid); } @@ -216,8 +216,8 @@ public: } - QUuid::Variant variant() const Q_DECL_NOTHROW; - QUuid::Version version() const Q_DECL_NOTHROW; + QUuid::Variant variant() const noexcept; + QUuid::Version version() const noexcept; #if defined(Q_OS_DARWIN) || defined(Q_CLANG_QDOC) static QUuid fromCFUUID(CFUUIDRef uuid); @@ -243,11 +243,11 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QUuid &); Q_CORE_EXPORT QDebug operator<<(QDebug, const QUuid &); #endif -Q_CORE_EXPORT uint qHash(const QUuid &uuid, uint seed = 0) Q_DECL_NOTHROW; +Q_CORE_EXPORT uint qHash(const QUuid &uuid, uint seed = 0) noexcept; -inline bool operator<=(const QUuid &lhs, const QUuid &rhs) Q_DECL_NOTHROW +inline bool operator<=(const QUuid &lhs, const QUuid &rhs) noexcept { return !(rhs < lhs); } -inline bool operator>=(const QUuid &lhs, const QUuid &rhs) Q_DECL_NOTHROW +inline bool operator>=(const QUuid &lhs, const QUuid &rhs) noexcept { return !(lhs < rhs); } QT_END_NAMESPACE diff --git a/src/corelib/serialization/qdatastream.cpp b/src/corelib/serialization/qdatastream.cpp index ead6ed5083..b44d55cb8f 100644 --- a/src/corelib/serialization/qdatastream.cpp +++ b/src/corelib/serialization/qdatastream.cpp @@ -98,6 +98,10 @@ QT_BEGIN_NAMESPACE ensures that you get integers of the size you want and insulates you from compiler and platform differences. + Enumerations can be serialized through QDataStream without the + need of manually defining streaming operators. Enum classes are + serialized using the declared size. + To take one example, a \c{char *} string is written as a 32-bit integer equal to the length of the string including the '\\0' byte, followed by all the characters of the string including the @@ -561,6 +565,7 @@ void QDataStream::setByteOrder(ByteOrder bo) \value Qt_5_11 Same as Qt_5_6 \value Qt_5_12 Version 18 (Qt 5.12) \value Qt_5_13 Version 19 (Qt 5.13) + \value Qt_5_14 Same as Qt_5_13 \omitvalue Qt_DefaultCompiledVersion \sa setVersion(), version() diff --git a/src/corelib/serialization/qdatastream.h b/src/corelib/serialization/qdatastream.h index 81134f74b0..2acf7d8c4b 100644 --- a/src/corelib/serialization/qdatastream.h +++ b/src/corelib/serialization/qdatastream.h @@ -100,10 +100,11 @@ public: Qt_5_11 = Qt_5_10, Qt_5_12 = 18, Qt_5_13 = 19, -#if QT_VERSION >= 0x050e00 + Qt_5_14 = Qt_5_13, +#if QT_VERSION >= 0x050f00 #error Add the datastream version for this Qt version and update Qt_DefaultCompiledVersion #endif - Qt_DefaultCompiledVersion = Qt_5_13 + Qt_DefaultCompiledVersion = Qt_5_14 }; enum ByteOrder { @@ -377,6 +378,16 @@ inline QDataStream &operator>>(QDataStream &s, QFlags<Enum> &e) { return s >> e.i; } template <typename T> +typename std::enable_if<std::is_enum<T>::value, QDataStream &>::type& +operator<<(QDataStream &s, const T &t) +{ return s << static_cast<typename std::underlying_type<T>::type>(t); } + +template <typename T> +typename std::enable_if<std::is_enum<T>::value, QDataStream &>::type& +operator>>(QDataStream &s, T &t) +{ return s >> reinterpret_cast<typename std::underlying_type<T>::type &>(t); } + +template <typename T> inline QDataStream &operator>>(QDataStream &s, QList<T> &l) { return QtPrivate::readArrayBasedContainer(s, l); diff --git a/src/corelib/serialization/qjson_p.h b/src/corelib/serialization/qjson_p.h index 40b2414e4a..85fb2a1254 100644 --- a/src/corelib/serialization/qjson_p.h +++ b/src/corelib/serialization/qjson_p.h @@ -304,7 +304,7 @@ public: return *this; } - QLatin1String toQLatin1String() const Q_DECL_NOTHROW { + QLatin1String toQLatin1String() const noexcept { return QLatin1String(d->latin1, d->length); } @@ -339,23 +339,23 @@ public: }; #define DEF_OP(op) \ - inline bool operator op(Latin1String lhs, Latin1String rhs) Q_DECL_NOTHROW \ + inline bool operator op(Latin1String lhs, Latin1String rhs) noexcept \ { \ return lhs.toQLatin1String() op rhs.toQLatin1String(); \ } \ - inline bool operator op(QLatin1String lhs, Latin1String rhs) Q_DECL_NOTHROW \ + inline bool operator op(QLatin1String lhs, Latin1String rhs) noexcept \ { \ return lhs op rhs.toQLatin1String(); \ } \ - inline bool operator op(Latin1String lhs, QLatin1String rhs) Q_DECL_NOTHROW \ + inline bool operator op(Latin1String lhs, QLatin1String rhs) noexcept \ { \ return lhs.toQLatin1String() op rhs; \ } \ - inline bool operator op(const QString &lhs, Latin1String rhs) Q_DECL_NOTHROW \ + inline bool operator op(const QString &lhs, Latin1String rhs) noexcept \ { \ return lhs op rhs.toQLatin1String(); \ } \ - inline bool operator op(Latin1String lhs, const QString &rhs) Q_DECL_NOTHROW \ + inline bool operator op(Latin1String lhs, const QString &rhs) noexcept \ { \ return lhs.toQLatin1String() op rhs; \ } \ @@ -686,7 +686,7 @@ public: { } inline Data(int reserved, QJsonValue::Type valueType) - : rawData(0), compactionCounter(0), ownsData(true) + : rawData(nullptr), compactionCounter(0), ownsData(true) { Q_ASSERT(valueType == QJsonValue::Array || valueType == QJsonValue::Object); @@ -728,7 +728,7 @@ public: size = qMax(size + reserve, qMin(size *2, (int)Value::MaxSize)); if (size > Value::MaxSize) { qWarning("QJson: Document too large to store in data structure"); - return 0; + return nullptr; } } char *raw = (char *)malloc(size); diff --git a/src/corelib/serialization/qjsonarray.h b/src/corelib/serialization/qjsonarray.h index ba346fb848..86b7bf9d76 100644 --- a/src/corelib/serialization/qjsonarray.h +++ b/src/corelib/serialization/qjsonarray.h @@ -72,7 +72,7 @@ public: QJsonArray(const QJsonArray &other); QJsonArray &operator =(const QJsonArray &other); - QJsonArray(QJsonArray &&other) Q_DECL_NOTHROW + QJsonArray(QJsonArray &&other) noexcept : d(other.d), a(other.a) { @@ -80,7 +80,7 @@ public: other.a = nullptr; } - QJsonArray &operator =(QJsonArray &&other) Q_DECL_NOTHROW + QJsonArray &operator =(QJsonArray &&other) noexcept { swap(other); return *this; @@ -115,7 +115,7 @@ public: bool operator==(const QJsonArray &other) const; bool operator!=(const QJsonArray &other) const; - void swap(QJsonArray &other) Q_DECL_NOTHROW + void swap(QJsonArray &other) noexcept { qSwap(d, other.d); qSwap(a, other.a); diff --git a/src/corelib/serialization/qjsondocument.h b/src/corelib/serialization/qjsondocument.h index a749439b7d..a8006a6cc5 100644 --- a/src/corelib/serialization/qjsondocument.h +++ b/src/corelib/serialization/qjsondocument.h @@ -93,19 +93,19 @@ public: QJsonDocument(const QJsonDocument &other); QJsonDocument &operator =(const QJsonDocument &other); - QJsonDocument(QJsonDocument &&other) Q_DECL_NOTHROW + QJsonDocument(QJsonDocument &&other) noexcept : d(other.d) { other.d = nullptr; } - QJsonDocument &operator =(QJsonDocument &&other) Q_DECL_NOTHROW + QJsonDocument &operator =(QJsonDocument &&other) noexcept { swap(other); return *this; } - void swap(QJsonDocument &other) Q_DECL_NOTHROW + void swap(QJsonDocument &other) noexcept { qSwap(d, other.d); } diff --git a/src/corelib/serialization/qjsonobject.h b/src/corelib/serialization/qjsonobject.h index 80fe6b2f3f..92d45cc838 100644 --- a/src/corelib/serialization/qjsonobject.h +++ b/src/corelib/serialization/qjsonobject.h @@ -74,20 +74,20 @@ public: QJsonObject(const QJsonObject &other); QJsonObject &operator =(const QJsonObject &other); - QJsonObject(QJsonObject &&other) Q_DECL_NOTHROW + QJsonObject(QJsonObject &&other) noexcept : d(other.d), o(other.o) { other.d = nullptr; other.o = nullptr; } - QJsonObject &operator =(QJsonObject &&other) Q_DECL_NOTHROW + QJsonObject &operator =(QJsonObject &&other) noexcept { swap(other); return *this; } - void swap(QJsonObject &other) Q_DECL_NOTHROW + void swap(QJsonObject &other) noexcept { qSwap(d, other.d); qSwap(o, other.o); diff --git a/src/corelib/serialization/qjsonvalue.h b/src/corelib/serialization/qjsonvalue.h index 0339eb59f7..37d84f9e60 100644 --- a/src/corelib/serialization/qjsonvalue.h +++ b/src/corelib/serialization/qjsonvalue.h @@ -92,7 +92,7 @@ public: QJsonValue(const QJsonValue &other); QJsonValue &operator =(const QJsonValue &other); - QJsonValue(QJsonValue &&other) Q_DECL_NOTHROW + QJsonValue(QJsonValue &&other) noexcept : ui(other.ui), d(other.d), t(other.t) @@ -102,13 +102,13 @@ public: other.t = Null; } - QJsonValue &operator =(QJsonValue &&other) Q_DECL_NOTHROW + QJsonValue &operator =(QJsonValue &&other) noexcept { swap(other); return *this; } - void swap(QJsonValue &other) Q_DECL_NOTHROW + void swap(QJsonValue &other) noexcept { qSwap(ui, other.ui); qSwap(d, other.d); diff --git a/src/corelib/serialization/qtextstream.cpp b/src/corelib/serialization/qtextstream.cpp index c9ba183a50..0d83bb6cd4 100644 --- a/src/corelib/serialization/qtextstream.cpp +++ b/src/corelib/serialization/qtextstream.cpp @@ -135,30 +135,30 @@ static const int QTEXTSTREAM_BUFFERSIZE = 16384; \table \header \li Manipulator \li Description - \row \li \c bin \li Same as setIntegerBase(2). - \row \li \c oct \li Same as setIntegerBase(8). - \row \li \c dec \li Same as setIntegerBase(10). - \row \li \c hex \li Same as setIntegerBase(16). - \row \li \c showbase \li Same as setNumberFlags(numberFlags() | ShowBase). - \row \li \c forcesign \li Same as setNumberFlags(numberFlags() | ForceSign). - \row \li \c forcepoint \li Same as setNumberFlags(numberFlags() | ForcePoint). - \row \li \c noshowbase \li Same as setNumberFlags(numberFlags() & ~ShowBase). - \row \li \c noforcesign \li Same as setNumberFlags(numberFlags() & ~ForceSign). - \row \li \c noforcepoint \li Same as setNumberFlags(numberFlags() & ~ForcePoint). - \row \li \c uppercasebase \li Same as setNumberFlags(numberFlags() | UppercaseBase). - \row \li \c uppercasedigits \li Same as setNumberFlags(numberFlags() | UppercaseDigits). - \row \li \c lowercasebase \li Same as setNumberFlags(numberFlags() & ~UppercaseBase). - \row \li \c lowercasedigits \li Same as setNumberFlags(numberFlags() & ~UppercaseDigits). - \row \li \c fixed \li Same as setRealNumberNotation(FixedNotation). - \row \li \c scientific \li Same as setRealNumberNotation(ScientificNotation). - \row \li \c left \li Same as setFieldAlignment(AlignLeft). - \row \li \c right \li Same as setFieldAlignment(AlignRight). - \row \li \c center \li Same as setFieldAlignment(AlignCenter). - \row \li \c endl \li Same as operator<<('\\n') and flush(). - \row \li \c flush \li Same as flush(). - \row \li \c reset \li Same as reset(). - \row \li \c ws \li Same as skipWhiteSpace(). - \row \li \c bom \li Same as setGenerateByteOrderMark(true). + \row \li \c Qt::bin \li Same as setIntegerBase(2). + \row \li \c Qt::oct \li Same as setIntegerBase(8). + \row \li \c Qt::dec \li Same as setIntegerBase(10). + \row \li \c Qt::hex \li Same as setIntegerBase(16). + \row \li \c Qt::showbase \li Same as setNumberFlags(numberFlags() | ShowBase). + \row \li \c Qt::forcesign \li Same as setNumberFlags(numberFlags() | ForceSign). + \row \li \c Qt::forcepoint \li Same as setNumberFlags(numberFlags() | ForcePoint). + \row \li \c Qt::noshowbase \li Same as setNumberFlags(numberFlags() & ~ShowBase). + \row \li \c Qt::noforcesign \li Same as setNumberFlags(numberFlags() & ~ForceSign). + \row \li \c Qt::noforcepoint \li Same as setNumberFlags(numberFlags() & ~ForcePoint). + \row \li \c Qt::uppercasebase \li Same as setNumberFlags(numberFlags() | UppercaseBase). + \row \li \c Qt::uppercasedigits \li Same as setNumberFlags(numberFlags() | UppercaseDigits). + \row \li \c Qt::lowercasebase \li Same as setNumberFlags(numberFlags() & ~UppercaseBase). + \row \li \c Qt::lowercasedigits \li Same as setNumberFlags(numberFlags() & ~UppercaseDigits). + \row \li \c Qt::fixed \li Same as setRealNumberNotation(FixedNotation). + \row \li \c Qt::scientific \li Same as setRealNumberNotation(ScientificNotation). + \row \li \c Qt::left \li Same as setFieldAlignment(AlignLeft). + \row \li \c Qt::right \li Same as setFieldAlignment(AlignRight). + \row \li \c Qt::center \li Same as setFieldAlignment(AlignCenter). + \row \li \c Qt::endl \li Same as operator<<('\\n') and flush(). + \row \li \c Qt::flush \li Same as flush(). + \row \li \c Qt::reset \li Same as reset(). + \row \li \c Qt::ws \li Same as skipWhiteSpace(). + \row \li \c Qt::bom \li Same as setGenerateByteOrderMark(true). \endtable In addition, Qt provides three global manipulators that take a @@ -2689,6 +2689,11 @@ QTextStream &QTextStream::operator<<(const void *ptr) d->params.numberFlags = oldFlags; return *this; } +#if defined(Q_QDOC) || QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +namespace Qt { +#else +namespace QTextStreamFunctions { +#endif /*! \relates QTextStream @@ -3015,6 +3020,8 @@ QTextStream &ws(QTextStream &stream) return stream; } +} // namespace QTextStreamFunctions + /*! \fn QTextStreamManipulator qSetFieldWidth(int width) \relates QTextStream @@ -3037,6 +3044,12 @@ QTextStream &ws(QTextStream &stream) */ #if QT_CONFIG(textcodec) + +#if defined(Q_QDOC) || QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +namespace Qt { +#else +namespace QTextStreamFunctions { +#endif /*! \relates QTextStream @@ -3051,6 +3064,8 @@ QTextStream &bom(QTextStream &stream) return stream; } +} // namespace QTextStreamFunctions + /*! Sets the codec for this stream to \a codec. The codec is used for decoding any data that is read from the assigned device, and for @@ -3200,6 +3215,43 @@ QLocale QTextStream::locale() const return d->locale; } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && !defined(Q_QDOC) +// Binary compatible definitions for Qt<5.14 +Q_CORE_EXPORT QTextStream &bin(QTextStream &s) { return Qt::bin(s); } +Q_CORE_EXPORT QTextStream &oct(QTextStream &s) { return Qt::oct(s); } +Q_CORE_EXPORT QTextStream &dec(QTextStream &s) { return Qt::dec(s); } +Q_CORE_EXPORT QTextStream &hex(QTextStream &s) { return Qt::hex(s); } + +Q_CORE_EXPORT QTextStream &showbase(QTextStream &s) { return Qt::showbase(s); } +Q_CORE_EXPORT QTextStream &forcesign(QTextStream &s) { return Qt::forcesign(s); } +Q_CORE_EXPORT QTextStream &forcepoint(QTextStream &s) { return Qt::forcepoint(s); } +Q_CORE_EXPORT QTextStream &noshowbase(QTextStream &s) { return Qt::noshowbase(s); } +Q_CORE_EXPORT QTextStream &noforcesign(QTextStream &s) { return Qt::noforcesign(s); } +Q_CORE_EXPORT QTextStream &noforcepoint(QTextStream &s) { return Qt::noforcepoint(s); } + +Q_CORE_EXPORT QTextStream &uppercasebase(QTextStream &s) { return Qt::uppercasebase(s); } +Q_CORE_EXPORT QTextStream &uppercasedigits(QTextStream &s) { return Qt::uppercasedigits(s); } +Q_CORE_EXPORT QTextStream &lowercasebase(QTextStream &s) { return Qt::lowercasebase(s); } +Q_CORE_EXPORT QTextStream &lowercasedigits(QTextStream &s) { return Qt::lowercasedigits(s); } + +Q_CORE_EXPORT QTextStream &fixed(QTextStream &s) { return Qt::fixed(s); } +Q_CORE_EXPORT QTextStream &scientific(QTextStream &s) { return Qt::scientific(s); } + +Q_CORE_EXPORT QTextStream &left(QTextStream &s) { return Qt::left(s); } +Q_CORE_EXPORT QTextStream &right(QTextStream &s) { return Qt::right(s); } +Q_CORE_EXPORT QTextStream ¢er(QTextStream &s) { return Qt::center(s); } + +Q_CORE_EXPORT QTextStream &endl(QTextStream &s) { return Qt::endl(s); } +Q_CORE_EXPORT QTextStream &flush(QTextStream &s) { return Qt::flush(s); } +Q_CORE_EXPORT QTextStream &reset(QTextStream &s) { return Qt::reset(s); } + +Q_CORE_EXPORT QTextStream &ws(QTextStream &s) { return Qt::ws(s); } + +#if QT_CONFIG(textcodec) +Q_CORE_EXPORT QTextStream &bom(QTextStream &s) { return Qt::bom(s); } +#endif +#endif + QT_END_NAMESPACE #ifndef QT_NO_QOBJECT diff --git a/src/corelib/serialization/qtextstream.h b/src/corelib/serialization/qtextstream.h index 1d86a18b9c..4efa84f1f1 100644 --- a/src/corelib/serialization/qtextstream.h +++ b/src/corelib/serialization/qtextstream.h @@ -213,8 +213,8 @@ typedef void (QTextStream::*QTSMFC)(QChar); // manipulator w/QChar argument class Q_CORE_EXPORT QTextStreamManipulator { public: - Q_DECL_CONSTEXPR QTextStreamManipulator(QTSMFI m, int a) Q_DECL_NOTHROW : mf(m), mc(nullptr), arg(a), ch() {} - Q_DECL_CONSTEXPR QTextStreamManipulator(QTSMFC m, QChar c) Q_DECL_NOTHROW : mf(nullptr), mc(m), arg(-1), ch(c) {} + Q_DECL_CONSTEXPR QTextStreamManipulator(QTSMFI m, int a) noexcept : mf(m), mc(nullptr), arg(a), ch() {} + Q_DECL_CONSTEXPR QTextStreamManipulator(QTSMFC m, QChar c) noexcept : mf(nullptr), mc(m), arg(-1), ch(c) {} void exec(QTextStream &s) { if (mf) { (s.*mf)(arg); } else { (s.*mc)(ch); } } private: @@ -233,6 +233,13 @@ inline QTextStream &operator<<(QTextStream &s, QTextStreamFunction f) inline QTextStream &operator<<(QTextStream &s, QTextStreamManipulator m) { m.exec(s); return s; } +#if defined(Q_QDOC) || QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +namespace Qt { +#else +// This namespace only exists for 'using namespace' declarations. +namespace QTextStreamFunctions { +#endif + Q_CORE_EXPORT QTextStream &bin(QTextStream &s); Q_CORE_EXPORT QTextStream &oct(QTextStream &s); Q_CORE_EXPORT QTextStream &dec(QTextStream &s); @@ -265,6 +272,18 @@ Q_CORE_EXPORT QTextStream &bom(QTextStream &s); Q_CORE_EXPORT QTextStream &ws(QTextStream &s); +} // namespace QTextStreamFunctions + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && !defined(Q_QDOC) +namespace Qt { +using namespace QTextStreamFunctions; +} + +// We use 'using namespace' as that doesn't cause +// conflicting definitions compiler errors. +using namespace QTextStreamFunctions; +#endif // QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && !defined(Q_QDOC) + inline QTextStreamManipulator qSetFieldWidth(int width) { QTSMFI func = &QTextStream::setFieldWidth; diff --git a/src/corelib/serialization/qxmlstream.h b/src/corelib/serialization/qxmlstream.h index d30c6bc01f..55dcc4e4e8 100644 --- a/src/corelib/serialization/qxmlstream.h +++ b/src/corelib/serialization/qxmlstream.h @@ -59,19 +59,15 @@ public: inline QXmlStreamStringRef(const QStringRef &aString) :m_string(aString.string()?*aString.string():QString()), m_position(aString.position()), m_size(aString.size()){} QXmlStreamStringRef(const QString &aString) : m_string(aString), m_position(0), m_size(m_string.size()) {} -#ifdef Q_COMPILER_RVALUE_REFS - QXmlStreamStringRef(QString &&aString) Q_DECL_NOTHROW : m_string(std::move(aString)), m_position(0), m_size(m_string.size()) {} -#endif + QXmlStreamStringRef(QString &&aString) noexcept : m_string(std::move(aString)), m_position(0), m_size(m_string.size()) {} #if QT_VERSION < QT_VERSION_CHECK(6,0,0) QXmlStreamStringRef(const QXmlStreamStringRef &other) // = default : m_string(other.m_string), m_position(other.m_position), m_size(other.m_size) {} -#ifdef Q_COMPILER_RVALUE_REFS - QXmlStreamStringRef(QXmlStreamStringRef &&other) Q_DECL_NOTHROW // = default + QXmlStreamStringRef(QXmlStreamStringRef &&other) noexcept // = default : m_string(std::move(other.m_string)), m_position(other.m_position), m_size(other.m_size) {} - QXmlStreamStringRef &operator=(QXmlStreamStringRef &&other) Q_DECL_NOTHROW // = default + QXmlStreamStringRef &operator=(QXmlStreamStringRef &&other) noexcept // = default { swap(other); return *this; } -#endif QXmlStreamStringRef &operator=(const QXmlStreamStringRef &other) // = default { m_string = other.m_string; m_position = other.m_position; m_size = other.m_size; return *this; } inline ~QXmlStreamStringRef() {} // ### this prevents (or deprecates) all the move/copy special member functions, @@ -79,7 +75,7 @@ public: // ### Qt 5, since that would change the way its passed to functions. In Qt 6, remove all. #endif // Qt < 6.0 - void swap(QXmlStreamStringRef &other) Q_DECL_NOTHROW + void swap(QXmlStreamStringRef &other) noexcept { qSwap(m_string, other.m_string); qSwap(m_position, other.m_position); @@ -111,8 +107,7 @@ public: #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QXmlStreamAttribute(const QString &namespaceUri, const QString &name, const QString &value); QXmlStreamAttribute(const QXmlStreamAttribute &); -#ifdef Q_COMPILER_RVALUE_REFS - QXmlStreamAttribute(QXmlStreamAttribute &&other) Q_DECL_NOTHROW // = default; + QXmlStreamAttribute(QXmlStreamAttribute &&other) noexcept // = default; : m_name(std::move(other.m_name)), m_namespaceUri(std::move(other.m_namespaceUri)), m_qualifiedName(std::move(other.m_qualifiedName)), @@ -122,7 +117,7 @@ public: { other.reserved = nullptr; } - QXmlStreamAttribute &operator=(QXmlStreamAttribute &&other) Q_DECL_NOTHROW // = default; + QXmlStreamAttribute &operator=(QXmlStreamAttribute &&other) noexcept // = default; { m_name = std::move(other.m_name); m_namespaceUri = std::move(other.m_namespaceUri); @@ -132,7 +127,6 @@ public: m_isDefault = other.m_isDefault; return *this; } -#endif QXmlStreamAttribute& operator=(const QXmlStreamAttribute &); ~QXmlStreamAttribute(); #endif // < Qt 6 @@ -199,14 +193,14 @@ public: QXmlStreamNamespaceDeclaration(); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QXmlStreamNamespaceDeclaration(const QXmlStreamNamespaceDeclaration &); - QXmlStreamNamespaceDeclaration(QXmlStreamNamespaceDeclaration &&other) Q_DECL_NOTHROW // = default + QXmlStreamNamespaceDeclaration(QXmlStreamNamespaceDeclaration &&other) noexcept // = default : m_prefix(std::move(other.m_prefix)), m_namespaceUri(std::move(other.m_namespaceUri)), reserved(other.reserved) { other.reserved = nullptr; } - QXmlStreamNamespaceDeclaration &operator=(QXmlStreamNamespaceDeclaration &&other) Q_DECL_NOTHROW // = default + QXmlStreamNamespaceDeclaration &operator=(QXmlStreamNamespaceDeclaration &&other) noexcept // = default { m_prefix = std::move(other.m_prefix); m_namespaceUri = std::move(other.m_namespaceUri); @@ -242,7 +236,7 @@ public: #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) ~QXmlStreamNotationDeclaration(); QXmlStreamNotationDeclaration(const QXmlStreamNotationDeclaration &); - QXmlStreamNotationDeclaration(QXmlStreamNotationDeclaration &&other) Q_DECL_NOTHROW // = default + QXmlStreamNotationDeclaration(QXmlStreamNotationDeclaration &&other) noexcept // = default : m_name(std::move(other.m_name)), m_systemId(std::move(other.m_systemId)), m_publicId(std::move(other.m_publicId)), @@ -251,7 +245,7 @@ public: other.reserved = nullptr; } QXmlStreamNotationDeclaration& operator=(const QXmlStreamNotationDeclaration &); - QXmlStreamNotationDeclaration &operator=(QXmlStreamNotationDeclaration &&other) Q_DECL_NOTHROW // = default + QXmlStreamNotationDeclaration &operator=(QXmlStreamNotationDeclaration &&other) noexcept // = default { m_name = std::move(other.m_name); m_systemId = std::move(other.m_systemId); @@ -287,7 +281,7 @@ public: #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) ~QXmlStreamEntityDeclaration(); QXmlStreamEntityDeclaration(const QXmlStreamEntityDeclaration &); - QXmlStreamEntityDeclaration(QXmlStreamEntityDeclaration &&other) Q_DECL_NOTHROW // = default + QXmlStreamEntityDeclaration(QXmlStreamEntityDeclaration &&other) noexcept // = default : m_name(std::move(other.m_name)), m_notationName(std::move(other.m_notationName)), m_systemId(std::move(other.m_systemId)), @@ -298,7 +292,7 @@ public: other.reserved = nullptr; } QXmlStreamEntityDeclaration& operator=(const QXmlStreamEntityDeclaration &); - QXmlStreamEntityDeclaration &operator=(QXmlStreamEntityDeclaration &&other) Q_DECL_NOTHROW // = default + QXmlStreamEntityDeclaration &operator=(QXmlStreamEntityDeclaration &&other) noexcept // = default { m_name = std::move(other.m_name); m_notationName = std::move(other.m_notationName); diff --git a/src/corelib/serialization/qxmlstream_p.h b/src/corelib/serialization/qxmlstream_p.h index 61f501f81b..cde66a48a3 100644 --- a/src/corelib/serialization/qxmlstream_p.h +++ b/src/corelib/serialization/qxmlstream_p.h @@ -162,12 +162,12 @@ public: const char *const QXmlStreamReader_Table::spell [] = { - "end of file", 0, " ", "<", ">", "&", "#", "\'", "\"", "[", + "end of file", nullptr, " ", "<", ">", "&", "#", "\'", "\"", "[", "]", "(", ")", "|", "=", "%", "/", ":", ";", ",", "-", "+", "*", ".", "?", "!", "[a-zA-Z]", "[0-9]", "[CDATA[", "DOCTYPE", "ELEMENT", "ATTLIST", "ENTITY", "NOTATION", "SYSTEM", "PUBLIC", "NDATA", "REQUIRED", "IMPLIED", "FIXED", - "EMPTY", "ANY", "PCDATA", 0, 0, 0, 0, "CDATA", "ID", "IDREF", - "IDREFS", "ENTITIES", "NMTOKEN", "NMTOKENS", "<?xml", "version", 0}; + "EMPTY", "ANY", "PCDATA", nullptr, nullptr, nullptr, nullptr, "CDATA", "ID", "IDREF", + "IDREFS", "ENTITIES", "NMTOKEN", "NMTOKENS", "<?xml", "version", nullptr}; const short QXmlStreamReader_Table::lhs [] = { 57, 57, 59, 59, 59, 59, 59, 59, 59, 59, @@ -645,7 +645,7 @@ template <typename T> class QXmlStreamSimpleStack { T *data; int tos, cap; public: - inline QXmlStreamSimpleStack():data(0), tos(-1), cap(0){} + inline QXmlStreamSimpleStack():data(nullptr), tos(-1), cap(0){} inline ~QXmlStreamSimpleStack(){ if (data) free(data); } inline void reserve(int extraCapacity) { @@ -995,7 +995,7 @@ public: int fastScanLiteralContent(); int fastScanSpace(); int fastScanContentCharList(); - int fastScanName(int *prefix = 0); + int fastScanName(int *prefix = nullptr); inline int fastScanNMTOKEN(); diff --git a/src/corelib/statemachine/qstate_p.h b/src/corelib/statemachine/qstate_p.h index 7fb40392e7..ec746caae1 100644 --- a/src/corelib/statemachine/qstate_p.h +++ b/src/corelib/statemachine/qstate_p.h @@ -68,14 +68,14 @@ QT_BEGIN_NAMESPACE struct QPropertyAssignment { QPropertyAssignment() - : object(0), explicitlySet(true) {} + : object(nullptr), explicitlySet(true) {} QPropertyAssignment(QObject *o, const QByteArray &n, const QVariant &v, bool es = true) : object(o), propertyName(n), value(v), explicitlySet(es) {} bool objectDeleted() const { return !object; } - void write() const { Q_ASSERT(object != 0); object->setProperty(propertyName, value); } + void write() const { Q_ASSERT(object != nullptr); object->setProperty(propertyName, value); } bool hasTarget(QObject *o, const QByteArray &pn) const { return object == o && propertyName == pn; } @@ -99,8 +99,8 @@ public: QStatePrivate(); ~QStatePrivate(); - static QStatePrivate *get(QState *q) { return q ? q->d_func() : 0; } - static const QStatePrivate *get(const QState *q) { return q? q->d_func() : 0; } + static QStatePrivate *get(QState *q) { return q ? q->d_func() : nullptr; } + static const QStatePrivate *get(const QState *q) { return q? q->d_func() : nullptr; } QList<QAbstractState*> childStates() const; QList<QHistoryState*> historyStates() const; diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h index f3366ca5f7..d6fdd72dc1 100644 --- a/src/corelib/statemachine/qstatemachine_p.h +++ b/src/corelib/statemachine/qstatemachine_p.h @@ -108,7 +108,7 @@ public: ~QStateMachinePrivate(); static QStateMachinePrivate *get(QStateMachine *q) - { return q ? q->d_func() : 0; } + { return q ? q->d_func() : nullptr; } QState *findLCA(const QList<QAbstractState*> &states, bool onlyCompound = false) const; QState *findLCCA(const QList<QAbstractState*> &states) const; @@ -218,18 +218,18 @@ public: QByteArray prop; // two overloads because friends can't have default arguments friend uint qHash(const RestorableId &key, uint seed) - Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(std::declval<QByteArray>()))) + noexcept(noexcept(qHash(std::declval<QByteArray>()))) { return qHash(qMakePair(key.obj, key.prop), seed); } - friend uint qHash(const RestorableId &key) Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(key, 0U))) + friend uint qHash(const RestorableId &key) noexcept(noexcept(qHash(key, 0U))) { return qHash(key, 0U); } - friend bool operator==(const RestorableId &lhs, const RestorableId &rhs) Q_DECL_NOTHROW + friend bool operator==(const RestorableId &lhs, const RestorableId &rhs) noexcept { return lhs.obj == rhs.obj && lhs.prop == rhs.prop; } - friend bool operator!=(const RestorableId &lhs, const RestorableId &rhs) Q_DECL_NOTHROW + friend bool operator!=(const RestorableId &lhs, const RestorableId &rhs) noexcept { return !operator==(lhs, rhs); } public: - explicit RestorableId(QObject *o, QByteArray p) Q_DECL_NOTHROW : guard(o), obj(o), prop(qMove(p)) {} - QObject *object() const Q_DECL_NOTHROW { return guard; } - QByteArray propertyName() const Q_DECL_NOTHROW { return prop; } + explicit RestorableId(QObject *o, QByteArray p) noexcept : guard(o), obj(o), prop(std::move(p)) {} + QObject *object() const noexcept { return guard; } + QByteArray propertyName() const noexcept { return prop; } }; QHash<QAbstractState*, QHash<RestorableId, QVariant> > registeredRestorablesForState; bool hasRestorable(QAbstractState *state, QObject *object, const QByteArray &propertyName) const; @@ -271,7 +271,7 @@ public: QList<QAbstractAnimation*> handledAnimations; QList<QAbstractAnimation*> localResetEndValues; - void swap(InitializeAnimationResult &other) Q_DECL_NOTHROW + void swap(InitializeAnimationResult &other) noexcept { qSwap(handledAnimations, other.handledAnimations); qSwap(localResetEndValues, other.localResetEndValues); @@ -313,7 +313,7 @@ public: DelayedEvent(QEvent *e, int tid) : event(e), timerId(tid) {} DelayedEvent() - : event(0), timerId(0) {} + : event(nullptr), timerId(0) {} }; QHash<int, DelayedEvent> delayedEvents; QHash<int, int> timerIdToDelayedEventId; diff --git a/src/corelib/thread/qatomic.h b/src/corelib/thread/qatomic.h index f842534c38..280ce96b76 100644 --- a/src/corelib/thread/qatomic.h +++ b/src/corelib/thread/qatomic.h @@ -57,15 +57,15 @@ class QAtomicInteger : public QBasicAtomicInteger<T> public: // Non-atomic API #ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS - constexpr QAtomicInteger(T value = 0) Q_DECL_NOTHROW : QBasicAtomicInteger<T>(value) {} + constexpr QAtomicInteger(T value = 0) noexcept : QBasicAtomicInteger<T>(value) {} #else - inline QAtomicInteger(T value = 0) Q_DECL_NOTHROW + inline QAtomicInteger(T value = 0) noexcept { this->_q_value = value; } #endif - inline QAtomicInteger(const QAtomicInteger &other) Q_DECL_NOTHROW + inline QAtomicInteger(const QAtomicInteger &other) noexcept #ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS : QBasicAtomicInteger<T>() #endif @@ -73,7 +73,7 @@ public: this->storeRelease(other.loadAcquire()); } - inline QAtomicInteger &operator=(const QAtomicInteger &other) Q_DECL_NOTHROW + inline QAtomicInteger &operator=(const QAtomicInteger &other) noexcept { this->storeRelease(other.loadAcquire()); return *this; @@ -159,7 +159,7 @@ public: #ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS constexpr #endif - QAtomicInt(int value = 0) Q_DECL_NOTHROW : QAtomicInteger<int>(value) {} + QAtomicInt(int value = 0) noexcept : QAtomicInteger<int>(value) {} }; // High-level atomic pointer operations @@ -168,14 +168,14 @@ class QAtomicPointer : public QBasicAtomicPointer<T> { public: #ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS - constexpr QAtomicPointer(T *value = nullptr) Q_DECL_NOTHROW : QBasicAtomicPointer<T>(value) {} + constexpr QAtomicPointer(T *value = nullptr) noexcept : QBasicAtomicPointer<T>(value) {} #else - inline QAtomicPointer(T *value = nullptr) Q_DECL_NOTHROW + inline QAtomicPointer(T *value = nullptr) noexcept { this->store(value); } #endif - inline QAtomicPointer(const QAtomicPointer<T> &other) Q_DECL_NOTHROW + inline QAtomicPointer(const QAtomicPointer<T> &other) noexcept #ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS : QBasicAtomicPointer<T>() #endif @@ -183,7 +183,7 @@ public: this->storeRelease(other.loadAcquire()); } - inline QAtomicPointer<T> &operator=(const QAtomicPointer<T> &other) Q_DECL_NOTHROW + inline QAtomicPointer<T> &operator=(const QAtomicPointer<T> &other) noexcept { this->storeRelease(other.loadAcquire()); return *this; diff --git a/src/corelib/thread/qatomic_bootstrap.h b/src/corelib/thread/qatomic_bootstrap.h index b463f817bd..c4279ee7b1 100644 --- a/src/corelib/thread/qatomic_bootstrap.h +++ b/src/corelib/thread/qatomic_bootstrap.h @@ -56,16 +56,16 @@ template <typename T> struct QAtomicOps: QGenericAtomicOps<QAtomicOps<T> > { typedef T Type; - static bool ref(T &_q_value) Q_DECL_NOTHROW + static bool ref(T &_q_value) noexcept { return ++_q_value != 0; } - static bool deref(T &_q_value) Q_DECL_NOTHROW + static bool deref(T &_q_value) noexcept { return --_q_value != 0; } - static bool testAndSetRelaxed(T &_q_value, T expectedValue, T newValue, T *currentValue = 0) Q_DECL_NOTHROW + static bool testAndSetRelaxed(T &_q_value, T expectedValue, T newValue, T *currentValue = nullptr) noexcept { if (currentValue) *currentValue = _q_value; @@ -76,7 +76,7 @@ template <typename T> struct QAtomicOps: QGenericAtomicOps<QAtomicOps<T> > return false; } - static T fetchAndStoreRelaxed(T &_q_value, T newValue) Q_DECL_NOTHROW + static T fetchAndStoreRelaxed(T &_q_value, T newValue) noexcept { T tmp = _q_value; _q_value = newValue; @@ -84,7 +84,7 @@ template <typename T> struct QAtomicOps: QGenericAtomicOps<QAtomicOps<T> > } template <typename AdditiveType> static - T fetchAndAddRelaxed(T &_q_value, AdditiveType valueToAdd) Q_DECL_NOTHROW + T fetchAndAddRelaxed(T &_q_value, AdditiveType valueToAdd) noexcept { T returnValue = _q_value; _q_value += valueToAdd; diff --git a/src/corelib/thread/qatomic_cxx11.h b/src/corelib/thread/qatomic_cxx11.h index 2fc0bf5419..32d27734fc 100644 --- a/src/corelib/thread/qatomic_cxx11.h +++ b/src/corelib/thread/qatomic_cxx11.h @@ -222,43 +222,43 @@ template <typename X> struct QAtomicOps typedef std::atomic<X> Type; template <typename T> static inline - T load(const std::atomic<T> &_q_value) Q_DECL_NOTHROW + T load(const std::atomic<T> &_q_value) noexcept { return _q_value.load(std::memory_order_relaxed); } template <typename T> static inline - T load(const volatile std::atomic<T> &_q_value) Q_DECL_NOTHROW + T load(const volatile std::atomic<T> &_q_value) noexcept { return _q_value.load(std::memory_order_relaxed); } template <typename T> static inline - T loadAcquire(const std::atomic<T> &_q_value) Q_DECL_NOTHROW + T loadAcquire(const std::atomic<T> &_q_value) noexcept { return _q_value.load(std::memory_order_acquire); } template <typename T> static inline - T loadAcquire(const volatile std::atomic<T> &_q_value) Q_DECL_NOTHROW + T loadAcquire(const volatile std::atomic<T> &_q_value) noexcept { return _q_value.load(std::memory_order_acquire); } template <typename T> static inline - void store(std::atomic<T> &_q_value, T newValue) Q_DECL_NOTHROW + void store(std::atomic<T> &_q_value, T newValue) noexcept { _q_value.store(newValue, std::memory_order_relaxed); } template <typename T> static inline - void storeRelease(std::atomic<T> &_q_value, T newValue) Q_DECL_NOTHROW + void storeRelease(std::atomic<T> &_q_value, T newValue) noexcept { _q_value.store(newValue, std::memory_order_release); } - static inline Q_DECL_CONSTEXPR bool isReferenceCountingNative() Q_DECL_NOTHROW { return isTestAndSetNative(); } - static inline Q_DECL_CONSTEXPR bool isReferenceCountingWaitFree() Q_DECL_NOTHROW { return false; } + static inline Q_DECL_CONSTEXPR bool isReferenceCountingNative() noexcept { return isTestAndSetNative(); } + static inline Q_DECL_CONSTEXPR bool isReferenceCountingWaitFree() noexcept { return false; } template <typename T> static inline bool ref(std::atomic<T> &_q_value) { @@ -266,17 +266,17 @@ template <typename X> struct QAtomicOps } template <typename T> - static inline bool deref(std::atomic<T> &_q_value) Q_DECL_NOTHROW + static inline bool deref(std::atomic<T> &_q_value) noexcept { return --_q_value != 0; } - static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW + static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() noexcept { return QAtomicTraits<sizeof(X)>::isLockFree(); } - static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; } + static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() noexcept { return false; } template <typename T> - static bool testAndSetRelaxed(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = nullptr) Q_DECL_NOTHROW + static bool testAndSetRelaxed(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = nullptr) noexcept { bool tmp = _q_value.compare_exchange_strong(expectedValue, newValue, std::memory_order_relaxed, std::memory_order_relaxed); if (currentValue) @@ -285,7 +285,7 @@ template <typename X> struct QAtomicOps } template <typename T> - static bool testAndSetAcquire(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = nullptr) Q_DECL_NOTHROW + static bool testAndSetAcquire(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = nullptr) noexcept { bool tmp = _q_value.compare_exchange_strong(expectedValue, newValue, std::memory_order_acquire, std::memory_order_acquire); if (currentValue) @@ -294,7 +294,7 @@ template <typename X> struct QAtomicOps } template <typename T> - static bool testAndSetRelease(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = nullptr) Q_DECL_NOTHROW + static bool testAndSetRelease(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = nullptr) noexcept { bool tmp = _q_value.compare_exchange_strong(expectedValue, newValue, std::memory_order_release, std::memory_order_relaxed); if (currentValue) @@ -303,7 +303,7 @@ template <typename X> struct QAtomicOps } template <typename T> - static bool testAndSetOrdered(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = nullptr) Q_DECL_NOTHROW + static bool testAndSetOrdered(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = nullptr) noexcept { bool tmp = _q_value.compare_exchange_strong(expectedValue, newValue, std::memory_order_acq_rel, std::memory_order_acquire); if (currentValue) @@ -311,152 +311,152 @@ template <typename X> struct QAtomicOps return tmp; } - static inline Q_DECL_CONSTEXPR bool isFetchAndStoreNative() Q_DECL_NOTHROW { return isTestAndSetNative(); } - static inline Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return false; } + static inline Q_DECL_CONSTEXPR bool isFetchAndStoreNative() noexcept { return isTestAndSetNative(); } + static inline Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() noexcept { return false; } template <typename T> - static T fetchAndStoreRelaxed(std::atomic<T> &_q_value, T newValue) Q_DECL_NOTHROW + static T fetchAndStoreRelaxed(std::atomic<T> &_q_value, T newValue) noexcept { return _q_value.exchange(newValue, std::memory_order_relaxed); } template <typename T> - static T fetchAndStoreAcquire(std::atomic<T> &_q_value, T newValue) Q_DECL_NOTHROW + static T fetchAndStoreAcquire(std::atomic<T> &_q_value, T newValue) noexcept { return _q_value.exchange(newValue, std::memory_order_acquire); } template <typename T> - static T fetchAndStoreRelease(std::atomic<T> &_q_value, T newValue) Q_DECL_NOTHROW + static T fetchAndStoreRelease(std::atomic<T> &_q_value, T newValue) noexcept { return _q_value.exchange(newValue, std::memory_order_release); } template <typename T> - static T fetchAndStoreOrdered(std::atomic<T> &_q_value, T newValue) Q_DECL_NOTHROW + static T fetchAndStoreOrdered(std::atomic<T> &_q_value, T newValue) noexcept { return _q_value.exchange(newValue, std::memory_order_acq_rel); } - static inline Q_DECL_CONSTEXPR bool isFetchAndAddNative() Q_DECL_NOTHROW { return isTestAndSetNative(); } - static inline Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return false; } + static inline Q_DECL_CONSTEXPR bool isFetchAndAddNative() noexcept { return isTestAndSetNative(); } + static inline Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() noexcept { return false; } template <typename T> static inline - T fetchAndAddRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndAddRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_add(valueToAdd, std::memory_order_relaxed); } template <typename T> static inline - T fetchAndAddAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndAddAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_add(valueToAdd, std::memory_order_acquire); } template <typename T> static inline - T fetchAndAddRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndAddRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_add(valueToAdd, std::memory_order_release); } template <typename T> static inline - T fetchAndAddOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndAddOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_add(valueToAdd, std::memory_order_acq_rel); } template <typename T> static inline - T fetchAndSubRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndSubRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_sub(valueToAdd, std::memory_order_relaxed); } template <typename T> static inline - T fetchAndSubAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndSubAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_sub(valueToAdd, std::memory_order_acquire); } template <typename T> static inline - T fetchAndSubRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndSubRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_sub(valueToAdd, std::memory_order_release); } template <typename T> static inline - T fetchAndSubOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndSubOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_sub(valueToAdd, std::memory_order_acq_rel); } template <typename T> static inline - T fetchAndAndRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndAndRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_and(valueToAdd, std::memory_order_relaxed); } template <typename T> static inline - T fetchAndAndAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndAndAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_and(valueToAdd, std::memory_order_acquire); } template <typename T> static inline - T fetchAndAndRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndAndRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_and(valueToAdd, std::memory_order_release); } template <typename T> static inline - T fetchAndAndOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndAndOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_and(valueToAdd, std::memory_order_acq_rel); } template <typename T> static inline - T fetchAndOrRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndOrRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_or(valueToAdd, std::memory_order_relaxed); } template <typename T> static inline - T fetchAndOrAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndOrAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_or(valueToAdd, std::memory_order_acquire); } template <typename T> static inline - T fetchAndOrRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndOrRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_or(valueToAdd, std::memory_order_release); } template <typename T> static inline - T fetchAndOrOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndOrOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_or(valueToAdd, std::memory_order_acq_rel); } template <typename T> static inline - T fetchAndXorRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndXorRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_xor(valueToAdd, std::memory_order_relaxed); } template <typename T> static inline - T fetchAndXorAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndXorAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_xor(valueToAdd, std::memory_order_acquire); } template <typename T> static inline - T fetchAndXorRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndXorRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_xor(valueToAdd, std::memory_order_release); } template <typename T> static inline - T fetchAndXorOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndXorOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return _q_value.fetch_xor(valueToAdd, std::memory_order_acq_rel); } diff --git a/src/corelib/thread/qatomic_msvc.h b/src/corelib/thread/qatomic_msvc.h index 5eae2bdc48..67b5224cd7 100644 --- a/src/corelib/thread/qatomic_msvc.h +++ b/src/corelib/thread/qatomic_msvc.h @@ -269,24 +269,24 @@ template <> struct QAtomicWindowsType<4> { typedef long Type; }; template <int N> struct QAtomicOpsBySize : QGenericAtomicOps<QAtomicOpsBySize<N> > { - static inline Q_DECL_CONSTEXPR bool isReferenceCountingNative() Q_DECL_NOTHROW { return true; } - static inline Q_DECL_CONSTEXPR bool isReferenceCountingWaitFree() Q_DECL_NOTHROW { return true; } - template <typename T> static bool ref(T &_q_value) Q_DECL_NOTHROW; - template <typename T> static bool deref(T &_q_value) Q_DECL_NOTHROW; - - static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return true; } - static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return true; } - template <typename T> static bool testAndSetRelaxed(T &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW; + static inline Q_DECL_CONSTEXPR bool isReferenceCountingNative() noexcept { return true; } + static inline Q_DECL_CONSTEXPR bool isReferenceCountingWaitFree() noexcept { return true; } + template <typename T> static bool ref(T &_q_value) noexcept; + template <typename T> static bool deref(T &_q_value) noexcept; + + static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() noexcept { return true; } + static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() noexcept { return true; } + template <typename T> static bool testAndSetRelaxed(T &_q_value, T expectedValue, T newValue) noexcept; template <typename T> - static bool testAndSetRelaxed(T &_q_value, T expectedValue, T newValue, T *currentValue) Q_DECL_NOTHROW; + static bool testAndSetRelaxed(T &_q_value, T expectedValue, T newValue, T *currentValue) noexcept; - static inline Q_DECL_CONSTEXPR bool isFetchAndStoreNative() Q_DECL_NOTHROW { return true; } - static inline Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return true; } - template <typename T> static T fetchAndStoreRelaxed(T &_q_value, T newValue) Q_DECL_NOTHROW; + static inline Q_DECL_CONSTEXPR bool isFetchAndStoreNative() noexcept { return true; } + static inline Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() noexcept { return true; } + template <typename T> static T fetchAndStoreRelaxed(T &_q_value, T newValue) noexcept; - static inline Q_DECL_CONSTEXPR bool isFetchAndAddNative() Q_DECL_NOTHROW { return true; } - static inline Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return true; } - template <typename T> static T fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW; + static inline Q_DECL_CONSTEXPR bool isFetchAndAddNative() noexcept { return true; } + static inline Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() noexcept { return true; } + template <typename T> static T fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept; private: typedef typename QAtomicWindowsType<N>::Type Type; @@ -303,76 +303,76 @@ struct QAtomicOps : QAtomicOpsBySize<sizeof(T)> }; template<> template<typename T> -inline bool QAtomicOpsBySize<4>::ref(T &_q_value) Q_DECL_NOTHROW +inline bool QAtomicOpsBySize<4>::ref(T &_q_value) noexcept { return QT_INTERLOCKED_FUNCTION(Increment)(atomic(&_q_value)) != 0; } template<> template<typename T> -inline bool QAtomicOpsBySize<4>::deref(T &_q_value) Q_DECL_NOTHROW +inline bool QAtomicOpsBySize<4>::deref(T &_q_value) noexcept { return QT_INTERLOCKED_FUNCTION(Decrement)(atomic(&_q_value)) != 0; } template<> template<typename T> -inline bool QAtomicOpsBySize<4>::testAndSetRelaxed(T &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW +inline bool QAtomicOpsBySize<4>::testAndSetRelaxed(T &_q_value, T expectedValue, T newValue) noexcept { return QT_INTERLOCKED_FUNCTION(CompareExchange)(atomic(&_q_value), value(newValue), value(expectedValue)) == value(expectedValue); } template<> template <typename T> -inline bool QAtomicOpsBySize<4>::testAndSetRelaxed(T &_q_value, T expectedValue, T newValue, T *currentValue) Q_DECL_NOTHROW +inline bool QAtomicOpsBySize<4>::testAndSetRelaxed(T &_q_value, T expectedValue, T newValue, T *currentValue) noexcept { *currentValue = T(QT_INTERLOCKED_FUNCTION(CompareExchange)(atomic(&_q_value), newValue, expectedValue)); return *currentValue == expectedValue; } template<> template<typename T> -inline T QAtomicOpsBySize<4>::fetchAndStoreRelaxed(T &_q_value, T newValue) Q_DECL_NOTHROW +inline T QAtomicOpsBySize<4>::fetchAndStoreRelaxed(T &_q_value, T newValue) noexcept { return QT_INTERLOCKED_FUNCTION(Exchange)(atomic(&_q_value), value(newValue)); } template<> template<typename T> -inline T QAtomicOpsBySize<4>::fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW +inline T QAtomicOpsBySize<4>::fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return QT_INTERLOCKED_FUNCTION(ExchangeAdd)(atomic(&_q_value), value<T>(valueToAdd * QAtomicAdditiveType<T>::AddScale)); } #ifdef Q_ATOMIC_INT16_IS_SUPPORTED template<> template<typename T> -inline bool QAtomicOpsBySize<2>::ref(T &_q_value) Q_DECL_NOTHROW +inline bool QAtomicOpsBySize<2>::ref(T &_q_value) noexcept { return QT_INTERLOCKED_FUNCTION(Increment16)(atomic(&_q_value)) != 0; } template<> template<typename T> -inline bool QAtomicOpsBySize<2>::deref(T &_q_value) Q_DECL_NOTHROW +inline bool QAtomicOpsBySize<2>::deref(T &_q_value) noexcept { return QT_INTERLOCKED_FUNCTION(Decrement16)(atomic(&_q_value)) != 0; } template<> template<typename T> -inline bool QAtomicOpsBySize<2>::testAndSetRelaxed(T &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW +inline bool QAtomicOpsBySize<2>::testAndSetRelaxed(T &_q_value, T expectedValue, T newValue) noexcept { return QT_INTERLOCKED_FUNCTION(CompareExchange16)(atomic(&_q_value), value(newValue), value(expectedValue)) == value(expectedValue); } template<> template <typename T> -inline bool QAtomicOpsBySize<2>::testAndSetRelaxed(T &_q_value, T expectedValue, T newValue, T *currentValue) Q_DECL_NOTHROW +inline bool QAtomicOpsBySize<2>::testAndSetRelaxed(T &_q_value, T expectedValue, T newValue, T *currentValue) noexcept { *currentValue = T(QT_INTERLOCKED_FUNCTION(CompareExchange16)(atomic(&_q_value), newValue, expectedValue)); return *currentValue == expectedValue; } template<> template<typename T> -inline T QAtomicOpsBySize<2>::fetchAndStoreRelaxed(T &_q_value, T newValue) Q_DECL_NOTHROW +inline T QAtomicOpsBySize<2>::fetchAndStoreRelaxed(T &_q_value, T newValue) noexcept { return QT_INTERLOCKED_FUNCTION(Exchange16)(atomic(&_q_value), value(newValue)); } template<> template<typename T> -inline T QAtomicOpsBySize<2>::fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW +inline T QAtomicOpsBySize<2>::fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return QT_INTERLOCKED_FUNCTION(ExchangeAdd16)(atomic(&_q_value), value<T>(valueToAdd * QAtomicAdditiveType<T>::AddScale)); } @@ -380,38 +380,38 @@ inline T QAtomicOpsBySize<2>::fetchAndAddRelaxed(T &_q_value, typename QAtomicAd #ifdef Q_ATOMIC_INT64_IS_SUPPORTED template<> template<typename T> -inline bool QAtomicOpsBySize<8>::ref(T &_q_value) Q_DECL_NOTHROW +inline bool QAtomicOpsBySize<8>::ref(T &_q_value) noexcept { return QT_INTERLOCKED_FUNCTION(Increment64)(atomic(&_q_value)) != 0; } template<> template<typename T> -inline bool QAtomicOpsBySize<8>::deref(T &_q_value) Q_DECL_NOTHROW +inline bool QAtomicOpsBySize<8>::deref(T &_q_value) noexcept { return QT_INTERLOCKED_FUNCTION(Decrement64)(atomic(&_q_value)) != 0; } template<> template<typename T> -inline bool QAtomicOpsBySize<8>::testAndSetRelaxed(T &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW +inline bool QAtomicOpsBySize<8>::testAndSetRelaxed(T &_q_value, T expectedValue, T newValue) noexcept { return QT_INTERLOCKED_FUNCTION(CompareExchange64)(atomic(&_q_value), value(newValue), value(expectedValue)) == value(expectedValue); } template<> template <typename T> -inline bool QAtomicOpsBySize<8>::testAndSetRelaxed(T &_q_value, T expectedValue, T newValue, T *currentValue) Q_DECL_NOTHROW +inline bool QAtomicOpsBySize<8>::testAndSetRelaxed(T &_q_value, T expectedValue, T newValue, T *currentValue) noexcept { *currentValue = T(QT_INTERLOCKED_FUNCTION(CompareExchange64)(atomic(&_q_value), newValue, expectedValue)); return *currentValue == expectedValue; } template<> template<typename T> -inline T QAtomicOpsBySize<8>::fetchAndStoreRelaxed(T &_q_value, T newValue) Q_DECL_NOTHROW +inline T QAtomicOpsBySize<8>::fetchAndStoreRelaxed(T &_q_value, T newValue) noexcept { return QT_INTERLOCKED_FUNCTION(Exchange64)(atomic(&_q_value), value(newValue)); } template<> template<typename T> -inline T QAtomicOpsBySize<8>::fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW +inline T QAtomicOpsBySize<8>::fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { return QT_INTERLOCKED_FUNCTION(ExchangeAdd64)(atomic(&_q_value), value<T>(valueToAdd * QAtomicAdditiveType<T>::AddScale)); } @@ -423,41 +423,41 @@ struct QAtomicOps<T *> : QGenericAtomicOps<QAtomicOps<T *> > { typedef T *Type; - static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return true; } - static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return true; } - static bool testAndSetRelaxed(T *&_q_value, T *expectedValue, T *newValue) Q_DECL_NOTHROW; - static bool testAndSetRelaxed(T *&_q_value, T *expectedValue, T *newValue, T **currentValue) Q_DECL_NOTHROW; + static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() noexcept { return true; } + static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() noexcept { return true; } + static bool testAndSetRelaxed(T *&_q_value, T *expectedValue, T *newValue) noexcept; + static bool testAndSetRelaxed(T *&_q_value, T *expectedValue, T *newValue, T **currentValue) noexcept; - static inline Q_DECL_CONSTEXPR bool isFetchAndStoreNative() Q_DECL_NOTHROW { return true; } - static inline Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return true; } - static T *fetchAndStoreRelaxed(T *&_q_value, T *newValue) Q_DECL_NOTHROW; + static inline Q_DECL_CONSTEXPR bool isFetchAndStoreNative() noexcept { return true; } + static inline Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() noexcept { return true; } + static T *fetchAndStoreRelaxed(T *&_q_value, T *newValue) noexcept; - static inline Q_DECL_CONSTEXPR bool isFetchAndAddNative() Q_DECL_NOTHROW { return true; } - static inline Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return true; } - static T *fetchAndAddRelaxed(T *&_q_value, qptrdiff valueToAdd) Q_DECL_NOTHROW; + static inline Q_DECL_CONSTEXPR bool isFetchAndAddNative() noexcept { return true; } + static inline Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() noexcept { return true; } + static T *fetchAndAddRelaxed(T *&_q_value, qptrdiff valueToAdd) noexcept; }; template <typename T> -inline bool QAtomicOps<T *>::testAndSetRelaxed(T *&_q_value, T *expectedValue, T *newValue) Q_DECL_NOTHROW +inline bool QAtomicOps<T *>::testAndSetRelaxed(T *&_q_value, T *expectedValue, T *newValue) noexcept { return QT_INTERLOCKED_COMPARE_EXCHANGE_POINTER(&_q_value, newValue, expectedValue) == expectedValue; } template <typename T> -inline bool QAtomicOps<T *>::testAndSetRelaxed(T *&_q_value, T *expectedValue, T *newValue, T **currentValue) Q_DECL_NOTHROW +inline bool QAtomicOps<T *>::testAndSetRelaxed(T *&_q_value, T *expectedValue, T *newValue, T **currentValue) noexcept { *currentValue = reinterpret_cast<T *>(QT_INTERLOCKED_COMPARE_EXCHANGE_POINTER(&_q_value, newValue, expectedValue)); return *currentValue == expectedValue; } template <typename T> -inline T *QAtomicOps<T *>::fetchAndStoreRelaxed(T *&_q_value, T *newValue) Q_DECL_NOTHROW +inline T *QAtomicOps<T *>::fetchAndStoreRelaxed(T *&_q_value, T *newValue) noexcept { return reinterpret_cast<T *>(QT_INTERLOCKED_EXCHANGE_POINTER(&_q_value, newValue)); } template <typename T> -inline T *QAtomicOps<T *>::fetchAndAddRelaxed(T *&_q_value, qptrdiff valueToAdd) Q_DECL_NOTHROW +inline T *QAtomicOps<T *>::fetchAndAddRelaxed(T *&_q_value, qptrdiff valueToAdd) noexcept { return reinterpret_cast<T *>(QT_INTERLOCKED_EXCHANGE_ADD_POINTER(&_q_value, valueToAdd * sizeof(T))); } diff --git a/src/corelib/thread/qbasicatomic.h b/src/corelib/thread/qbasicatomic.h index 6b6ac10713..4c3c1fc01f 100644 --- a/src/corelib/thread/qbasicatomic.h +++ b/src/corelib/thread/qbasicatomic.h @@ -100,125 +100,125 @@ public: // Everything below is either implemented in ../arch/qatomic_XXX.h or (as fallback) in qgenericatomic.h - T load() const Q_DECL_NOTHROW { return Ops::load(_q_value); } - void store(T newValue) Q_DECL_NOTHROW { Ops::store(_q_value, newValue); } + T load() const noexcept { return Ops::load(_q_value); } + void store(T newValue) noexcept { Ops::store(_q_value, newValue); } - T loadAcquire() const Q_DECL_NOTHROW { return Ops::loadAcquire(_q_value); } - void storeRelease(T newValue) Q_DECL_NOTHROW { Ops::storeRelease(_q_value, newValue); } - operator T() const Q_DECL_NOTHROW { return loadAcquire(); } - T operator=(T newValue) Q_DECL_NOTHROW { storeRelease(newValue); return newValue; } + T loadAcquire() const noexcept { return Ops::loadAcquire(_q_value); } + void storeRelease(T newValue) noexcept { Ops::storeRelease(_q_value, newValue); } + operator T() const noexcept { return loadAcquire(); } + T operator=(T newValue) noexcept { storeRelease(newValue); return newValue; } - static Q_DECL_CONSTEXPR bool isReferenceCountingNative() Q_DECL_NOTHROW { return Ops::isReferenceCountingNative(); } - static Q_DECL_CONSTEXPR bool isReferenceCountingWaitFree() Q_DECL_NOTHROW { return Ops::isReferenceCountingWaitFree(); } + static Q_DECL_CONSTEXPR bool isReferenceCountingNative() noexcept { return Ops::isReferenceCountingNative(); } + static Q_DECL_CONSTEXPR bool isReferenceCountingWaitFree() noexcept { return Ops::isReferenceCountingWaitFree(); } - bool ref() Q_DECL_NOTHROW { return Ops::ref(_q_value); } - bool deref() Q_DECL_NOTHROW { return Ops::deref(_q_value); } + bool ref() noexcept { return Ops::ref(_q_value); } + bool deref() noexcept { return Ops::deref(_q_value); } - static Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return Ops::isTestAndSetNative(); } - static Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return Ops::isTestAndSetWaitFree(); } + static Q_DECL_CONSTEXPR bool isTestAndSetNative() noexcept { return Ops::isTestAndSetNative(); } + static Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() noexcept { return Ops::isTestAndSetWaitFree(); } - bool testAndSetRelaxed(T expectedValue, T newValue) Q_DECL_NOTHROW + bool testAndSetRelaxed(T expectedValue, T newValue) noexcept { return Ops::testAndSetRelaxed(_q_value, expectedValue, newValue); } - bool testAndSetAcquire(T expectedValue, T newValue) Q_DECL_NOTHROW + bool testAndSetAcquire(T expectedValue, T newValue) noexcept { return Ops::testAndSetAcquire(_q_value, expectedValue, newValue); } - bool testAndSetRelease(T expectedValue, T newValue) Q_DECL_NOTHROW + bool testAndSetRelease(T expectedValue, T newValue) noexcept { return Ops::testAndSetRelease(_q_value, expectedValue, newValue); } - bool testAndSetOrdered(T expectedValue, T newValue) Q_DECL_NOTHROW + bool testAndSetOrdered(T expectedValue, T newValue) noexcept { return Ops::testAndSetOrdered(_q_value, expectedValue, newValue); } - bool testAndSetRelaxed(T expectedValue, T newValue, T ¤tValue) Q_DECL_NOTHROW + bool testAndSetRelaxed(T expectedValue, T newValue, T ¤tValue) noexcept { return Ops::testAndSetRelaxed(_q_value, expectedValue, newValue, ¤tValue); } - bool testAndSetAcquire(T expectedValue, T newValue, T ¤tValue) Q_DECL_NOTHROW + bool testAndSetAcquire(T expectedValue, T newValue, T ¤tValue) noexcept { return Ops::testAndSetAcquire(_q_value, expectedValue, newValue, ¤tValue); } - bool testAndSetRelease(T expectedValue, T newValue, T ¤tValue) Q_DECL_NOTHROW + bool testAndSetRelease(T expectedValue, T newValue, T ¤tValue) noexcept { return Ops::testAndSetRelease(_q_value, expectedValue, newValue, ¤tValue); } - bool testAndSetOrdered(T expectedValue, T newValue, T ¤tValue) Q_DECL_NOTHROW + bool testAndSetOrdered(T expectedValue, T newValue, T ¤tValue) noexcept { return Ops::testAndSetOrdered(_q_value, expectedValue, newValue, ¤tValue); } - static Q_DECL_CONSTEXPR bool isFetchAndStoreNative() Q_DECL_NOTHROW { return Ops::isFetchAndStoreNative(); } - static Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return Ops::isFetchAndStoreWaitFree(); } + static Q_DECL_CONSTEXPR bool isFetchAndStoreNative() noexcept { return Ops::isFetchAndStoreNative(); } + static Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() noexcept { return Ops::isFetchAndStoreWaitFree(); } - T fetchAndStoreRelaxed(T newValue) Q_DECL_NOTHROW + T fetchAndStoreRelaxed(T newValue) noexcept { return Ops::fetchAndStoreRelaxed(_q_value, newValue); } - T fetchAndStoreAcquire(T newValue) Q_DECL_NOTHROW + T fetchAndStoreAcquire(T newValue) noexcept { return Ops::fetchAndStoreAcquire(_q_value, newValue); } - T fetchAndStoreRelease(T newValue) Q_DECL_NOTHROW + T fetchAndStoreRelease(T newValue) noexcept { return Ops::fetchAndStoreRelease(_q_value, newValue); } - T fetchAndStoreOrdered(T newValue) Q_DECL_NOTHROW + T fetchAndStoreOrdered(T newValue) noexcept { return Ops::fetchAndStoreOrdered(_q_value, newValue); } - static Q_DECL_CONSTEXPR bool isFetchAndAddNative() Q_DECL_NOTHROW { return Ops::isFetchAndAddNative(); } - static Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return Ops::isFetchAndAddWaitFree(); } + static Q_DECL_CONSTEXPR bool isFetchAndAddNative() noexcept { return Ops::isFetchAndAddNative(); } + static Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() noexcept { return Ops::isFetchAndAddWaitFree(); } - T fetchAndAddRelaxed(T valueToAdd) Q_DECL_NOTHROW + T fetchAndAddRelaxed(T valueToAdd) noexcept { return Ops::fetchAndAddRelaxed(_q_value, valueToAdd); } - T fetchAndAddAcquire(T valueToAdd) Q_DECL_NOTHROW + T fetchAndAddAcquire(T valueToAdd) noexcept { return Ops::fetchAndAddAcquire(_q_value, valueToAdd); } - T fetchAndAddRelease(T valueToAdd) Q_DECL_NOTHROW + T fetchAndAddRelease(T valueToAdd) noexcept { return Ops::fetchAndAddRelease(_q_value, valueToAdd); } - T fetchAndAddOrdered(T valueToAdd) Q_DECL_NOTHROW + T fetchAndAddOrdered(T valueToAdd) noexcept { return Ops::fetchAndAddOrdered(_q_value, valueToAdd); } - T fetchAndSubRelaxed(T valueToAdd) Q_DECL_NOTHROW + T fetchAndSubRelaxed(T valueToAdd) noexcept { return Ops::fetchAndSubRelaxed(_q_value, valueToAdd); } - T fetchAndSubAcquire(T valueToAdd) Q_DECL_NOTHROW + T fetchAndSubAcquire(T valueToAdd) noexcept { return Ops::fetchAndSubAcquire(_q_value, valueToAdd); } - T fetchAndSubRelease(T valueToAdd) Q_DECL_NOTHROW + T fetchAndSubRelease(T valueToAdd) noexcept { return Ops::fetchAndSubRelease(_q_value, valueToAdd); } - T fetchAndSubOrdered(T valueToAdd) Q_DECL_NOTHROW + T fetchAndSubOrdered(T valueToAdd) noexcept { return Ops::fetchAndSubOrdered(_q_value, valueToAdd); } - T fetchAndAndRelaxed(T valueToAdd) Q_DECL_NOTHROW + T fetchAndAndRelaxed(T valueToAdd) noexcept { return Ops::fetchAndAndRelaxed(_q_value, valueToAdd); } - T fetchAndAndAcquire(T valueToAdd) Q_DECL_NOTHROW + T fetchAndAndAcquire(T valueToAdd) noexcept { return Ops::fetchAndAndAcquire(_q_value, valueToAdd); } - T fetchAndAndRelease(T valueToAdd) Q_DECL_NOTHROW + T fetchAndAndRelease(T valueToAdd) noexcept { return Ops::fetchAndAndRelease(_q_value, valueToAdd); } - T fetchAndAndOrdered(T valueToAdd) Q_DECL_NOTHROW + T fetchAndAndOrdered(T valueToAdd) noexcept { return Ops::fetchAndAndOrdered(_q_value, valueToAdd); } - T fetchAndOrRelaxed(T valueToAdd) Q_DECL_NOTHROW + T fetchAndOrRelaxed(T valueToAdd) noexcept { return Ops::fetchAndOrRelaxed(_q_value, valueToAdd); } - T fetchAndOrAcquire(T valueToAdd) Q_DECL_NOTHROW + T fetchAndOrAcquire(T valueToAdd) noexcept { return Ops::fetchAndOrAcquire(_q_value, valueToAdd); } - T fetchAndOrRelease(T valueToAdd) Q_DECL_NOTHROW + T fetchAndOrRelease(T valueToAdd) noexcept { return Ops::fetchAndOrRelease(_q_value, valueToAdd); } - T fetchAndOrOrdered(T valueToAdd) Q_DECL_NOTHROW + T fetchAndOrOrdered(T valueToAdd) noexcept { return Ops::fetchAndOrOrdered(_q_value, valueToAdd); } - T fetchAndXorRelaxed(T valueToAdd) Q_DECL_NOTHROW + T fetchAndXorRelaxed(T valueToAdd) noexcept { return Ops::fetchAndXorRelaxed(_q_value, valueToAdd); } - T fetchAndXorAcquire(T valueToAdd) Q_DECL_NOTHROW + T fetchAndXorAcquire(T valueToAdd) noexcept { return Ops::fetchAndXorAcquire(_q_value, valueToAdd); } - T fetchAndXorRelease(T valueToAdd) Q_DECL_NOTHROW + T fetchAndXorRelease(T valueToAdd) noexcept { return Ops::fetchAndXorRelease(_q_value, valueToAdd); } - T fetchAndXorOrdered(T valueToAdd) Q_DECL_NOTHROW + T fetchAndXorOrdered(T valueToAdd) noexcept { return Ops::fetchAndXorOrdered(_q_value, valueToAdd); } - T operator++() Q_DECL_NOTHROW + T operator++() noexcept { return fetchAndAddOrdered(1) + 1; } - T operator++(int) Q_DECL_NOTHROW + T operator++(int) noexcept { return fetchAndAddOrdered(1); } - T operator--() Q_DECL_NOTHROW + T operator--() noexcept { return fetchAndSubOrdered(1) - 1; } - T operator--(int) Q_DECL_NOTHROW + T operator--(int) noexcept { return fetchAndSubOrdered(1); } - T operator+=(T v) Q_DECL_NOTHROW + T operator+=(T v) noexcept { return fetchAndAddOrdered(v) + v; } - T operator-=(T v) Q_DECL_NOTHROW + T operator-=(T v) noexcept { return fetchAndSubOrdered(v) - v; } - T operator&=(T v) Q_DECL_NOTHROW + T operator&=(T v) noexcept { return fetchAndAndOrdered(v) & v; } - T operator|=(T v) Q_DECL_NOTHROW + T operator|=(T v) noexcept { return fetchAndOrOrdered(v) | v; } - T operator^=(T v) Q_DECL_NOTHROW + T operator^=(T v) noexcept { return fetchAndXorOrdered(v) ^ v; } #ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS QBasicAtomicInteger() = default; - constexpr QBasicAtomicInteger(T value) Q_DECL_NOTHROW : _q_value(value) {} + constexpr QBasicAtomicInteger(T value) noexcept : _q_value(value) {} QBasicAtomicInteger(const QBasicAtomicInteger &) = delete; QBasicAtomicInteger &operator=(const QBasicAtomicInteger &) = delete; QBasicAtomicInteger &operator=(const QBasicAtomicInteger &) volatile = delete; @@ -236,85 +236,85 @@ public: AtomicType _q_value; - Type load() const Q_DECL_NOTHROW { return Ops::load(_q_value); } - void store(Type newValue) Q_DECL_NOTHROW { Ops::store(_q_value, newValue); } - operator Type() const Q_DECL_NOTHROW { return loadAcquire(); } - Type operator=(Type newValue) Q_DECL_NOTHROW { storeRelease(newValue); return newValue; } + Type load() const noexcept { return Ops::load(_q_value); } + void store(Type newValue) noexcept { Ops::store(_q_value, newValue); } + operator Type() const noexcept { return loadAcquire(); } + Type operator=(Type newValue) noexcept { storeRelease(newValue); return newValue; } // Atomic API, implemented in qatomic_XXX.h - Type loadAcquire() const Q_DECL_NOTHROW { return Ops::loadAcquire(_q_value); } - void storeRelease(Type newValue) Q_DECL_NOTHROW { Ops::storeRelease(_q_value, newValue); } + Type loadAcquire() const noexcept { return Ops::loadAcquire(_q_value); } + void storeRelease(Type newValue) noexcept { Ops::storeRelease(_q_value, newValue); } - static Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return Ops::isTestAndSetNative(); } - static Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return Ops::isTestAndSetWaitFree(); } + static Q_DECL_CONSTEXPR bool isTestAndSetNative() noexcept { return Ops::isTestAndSetNative(); } + static Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() noexcept { return Ops::isTestAndSetWaitFree(); } - bool testAndSetRelaxed(Type expectedValue, Type newValue) Q_DECL_NOTHROW + bool testAndSetRelaxed(Type expectedValue, Type newValue) noexcept { return Ops::testAndSetRelaxed(_q_value, expectedValue, newValue); } - bool testAndSetAcquire(Type expectedValue, Type newValue) Q_DECL_NOTHROW + bool testAndSetAcquire(Type expectedValue, Type newValue) noexcept { return Ops::testAndSetAcquire(_q_value, expectedValue, newValue); } - bool testAndSetRelease(Type expectedValue, Type newValue) Q_DECL_NOTHROW + bool testAndSetRelease(Type expectedValue, Type newValue) noexcept { return Ops::testAndSetRelease(_q_value, expectedValue, newValue); } - bool testAndSetOrdered(Type expectedValue, Type newValue) Q_DECL_NOTHROW + bool testAndSetOrdered(Type expectedValue, Type newValue) noexcept { return Ops::testAndSetOrdered(_q_value, expectedValue, newValue); } - bool testAndSetRelaxed(Type expectedValue, Type newValue, Type ¤tValue) Q_DECL_NOTHROW + bool testAndSetRelaxed(Type expectedValue, Type newValue, Type ¤tValue) noexcept { return Ops::testAndSetRelaxed(_q_value, expectedValue, newValue, ¤tValue); } - bool testAndSetAcquire(Type expectedValue, Type newValue, Type ¤tValue) Q_DECL_NOTHROW + bool testAndSetAcquire(Type expectedValue, Type newValue, Type ¤tValue) noexcept { return Ops::testAndSetAcquire(_q_value, expectedValue, newValue, ¤tValue); } - bool testAndSetRelease(Type expectedValue, Type newValue, Type ¤tValue) Q_DECL_NOTHROW + bool testAndSetRelease(Type expectedValue, Type newValue, Type ¤tValue) noexcept { return Ops::testAndSetRelease(_q_value, expectedValue, newValue, ¤tValue); } - bool testAndSetOrdered(Type expectedValue, Type newValue, Type ¤tValue) Q_DECL_NOTHROW + bool testAndSetOrdered(Type expectedValue, Type newValue, Type ¤tValue) noexcept { return Ops::testAndSetOrdered(_q_value, expectedValue, newValue, ¤tValue); } - static Q_DECL_CONSTEXPR bool isFetchAndStoreNative() Q_DECL_NOTHROW { return Ops::isFetchAndStoreNative(); } - static Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return Ops::isFetchAndStoreWaitFree(); } + static Q_DECL_CONSTEXPR bool isFetchAndStoreNative() noexcept { return Ops::isFetchAndStoreNative(); } + static Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() noexcept { return Ops::isFetchAndStoreWaitFree(); } - Type fetchAndStoreRelaxed(Type newValue) Q_DECL_NOTHROW + Type fetchAndStoreRelaxed(Type newValue) noexcept { return Ops::fetchAndStoreRelaxed(_q_value, newValue); } - Type fetchAndStoreAcquire(Type newValue) Q_DECL_NOTHROW + Type fetchAndStoreAcquire(Type newValue) noexcept { return Ops::fetchAndStoreAcquire(_q_value, newValue); } - Type fetchAndStoreRelease(Type newValue) Q_DECL_NOTHROW + Type fetchAndStoreRelease(Type newValue) noexcept { return Ops::fetchAndStoreRelease(_q_value, newValue); } - Type fetchAndStoreOrdered(Type newValue) Q_DECL_NOTHROW + Type fetchAndStoreOrdered(Type newValue) noexcept { return Ops::fetchAndStoreOrdered(_q_value, newValue); } - static Q_DECL_CONSTEXPR bool isFetchAndAddNative() Q_DECL_NOTHROW { return Ops::isFetchAndAddNative(); } - static Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return Ops::isFetchAndAddWaitFree(); } + static Q_DECL_CONSTEXPR bool isFetchAndAddNative() noexcept { return Ops::isFetchAndAddNative(); } + static Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() noexcept { return Ops::isFetchAndAddWaitFree(); } - Type fetchAndAddRelaxed(qptrdiff valueToAdd) Q_DECL_NOTHROW + Type fetchAndAddRelaxed(qptrdiff valueToAdd) noexcept { return Ops::fetchAndAddRelaxed(_q_value, valueToAdd); } - Type fetchAndAddAcquire(qptrdiff valueToAdd) Q_DECL_NOTHROW + Type fetchAndAddAcquire(qptrdiff valueToAdd) noexcept { return Ops::fetchAndAddAcquire(_q_value, valueToAdd); } - Type fetchAndAddRelease(qptrdiff valueToAdd) Q_DECL_NOTHROW + Type fetchAndAddRelease(qptrdiff valueToAdd) noexcept { return Ops::fetchAndAddRelease(_q_value, valueToAdd); } - Type fetchAndAddOrdered(qptrdiff valueToAdd) Q_DECL_NOTHROW + Type fetchAndAddOrdered(qptrdiff valueToAdd) noexcept { return Ops::fetchAndAddOrdered(_q_value, valueToAdd); } - Type fetchAndSubRelaxed(qptrdiff valueToAdd) Q_DECL_NOTHROW + Type fetchAndSubRelaxed(qptrdiff valueToAdd) noexcept { return Ops::fetchAndSubRelaxed(_q_value, valueToAdd); } - Type fetchAndSubAcquire(qptrdiff valueToAdd) Q_DECL_NOTHROW + Type fetchAndSubAcquire(qptrdiff valueToAdd) noexcept { return Ops::fetchAndSubAcquire(_q_value, valueToAdd); } - Type fetchAndSubRelease(qptrdiff valueToAdd) Q_DECL_NOTHROW + Type fetchAndSubRelease(qptrdiff valueToAdd) noexcept { return Ops::fetchAndSubRelease(_q_value, valueToAdd); } - Type fetchAndSubOrdered(qptrdiff valueToAdd) Q_DECL_NOTHROW + Type fetchAndSubOrdered(qptrdiff valueToAdd) noexcept { return Ops::fetchAndSubOrdered(_q_value, valueToAdd); } - Type operator++() Q_DECL_NOTHROW + Type operator++() noexcept { return fetchAndAddOrdered(1) + 1; } - Type operator++(int) Q_DECL_NOTHROW + Type operator++(int) noexcept { return fetchAndAddOrdered(1); } - Type operator--() Q_DECL_NOTHROW + Type operator--() noexcept { return fetchAndSubOrdered(1) - 1; } - Type operator--(int) Q_DECL_NOTHROW + Type operator--(int) noexcept { return fetchAndSubOrdered(1); } - Type operator+=(qptrdiff valueToAdd) Q_DECL_NOTHROW + Type operator+=(qptrdiff valueToAdd) noexcept { return fetchAndAddOrdered(valueToAdd) + valueToAdd; } - Type operator-=(qptrdiff valueToSub) Q_DECL_NOTHROW + Type operator-=(qptrdiff valueToSub) noexcept { return fetchAndSubOrdered(valueToSub) - valueToSub; } #ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS QBasicAtomicPointer() = default; - constexpr QBasicAtomicPointer(Type value) Q_DECL_NOTHROW : _q_value(value) {} + constexpr QBasicAtomicPointer(Type value) noexcept : _q_value(value) {} QBasicAtomicPointer(const QBasicAtomicPointer &) = delete; QBasicAtomicPointer &operator=(const QBasicAtomicPointer &) = delete; QBasicAtomicPointer &operator=(const QBasicAtomicPointer &) volatile = delete; diff --git a/src/corelib/thread/qfutex_p.h b/src/corelib/thread/qfutex_p.h index 483664c783..136f6bca8c 100644 --- a/src/corelib/thread/qfutex_p.h +++ b/src/corelib/thread/qfutex_p.h @@ -85,7 +85,7 @@ QT_BEGIN_NAMESPACE namespace QtLinuxFutex { constexpr inline bool futexAvailable() { return true; } inline int _q_futex(int *addr, int op, int val, quintptr val2 = 0, - int *addr2 = nullptr, int val3 = 0) Q_DECL_NOTHROW + int *addr2 = nullptr, int val3 = 0) noexcept { // we use __NR_futex because some libcs (like Android's bionic) don't // provide SYS_futex etc. diff --git a/src/corelib/thread/qgenericatomic.h b/src/corelib/thread/qgenericatomic.h index 89c4fe9a11..f8333e7de6 100644 --- a/src/corelib/thread/qgenericatomic.h +++ b/src/corelib/thread/qgenericatomic.h @@ -72,32 +72,32 @@ template <typename BaseClass> struct QGenericAtomicOps { template <typename T> struct AtomicType { typedef T Type; typedef T *PointerType; }; - template <typename T> static void acquireMemoryFence(const T &_q_value) Q_DECL_NOTHROW + template <typename T> static void acquireMemoryFence(const T &_q_value) noexcept { BaseClass::orderedMemoryFence(_q_value); } - template <typename T> static void releaseMemoryFence(const T &_q_value) Q_DECL_NOTHROW + template <typename T> static void releaseMemoryFence(const T &_q_value) noexcept { BaseClass::orderedMemoryFence(_q_value); } - template <typename T> static void orderedMemoryFence(const T &) Q_DECL_NOTHROW + template <typename T> static void orderedMemoryFence(const T &) noexcept { } template <typename T> static Q_ALWAYS_INLINE - T load(const T &_q_value) Q_DECL_NOTHROW + T load(const T &_q_value) noexcept { return _q_value; } template <typename T, typename X> static Q_ALWAYS_INLINE - void store(T &_q_value, X newValue) Q_DECL_NOTHROW + void store(T &_q_value, X newValue) noexcept { _q_value = newValue; } template <typename T> static Q_ALWAYS_INLINE - T loadAcquire(const T &_q_value) Q_DECL_NOTHROW + T loadAcquire(const T &_q_value) noexcept { T tmp = *static_cast<const volatile T *>(&_q_value); BaseClass::acquireMemoryFence(_q_value); @@ -105,24 +105,24 @@ template <typename BaseClass> struct QGenericAtomicOps } template <typename T, typename X> static Q_ALWAYS_INLINE - void storeRelease(T &_q_value, X newValue) Q_DECL_NOTHROW + void storeRelease(T &_q_value, X newValue) noexcept { BaseClass::releaseMemoryFence(_q_value); *static_cast<volatile T *>(&_q_value) = newValue; } - static inline Q_DECL_CONSTEXPR bool isReferenceCountingNative() Q_DECL_NOTHROW + static inline Q_DECL_CONSTEXPR bool isReferenceCountingNative() noexcept { return BaseClass::isFetchAndAddNative(); } - static inline Q_DECL_CONSTEXPR bool isReferenceCountingWaitFree() Q_DECL_NOTHROW + static inline Q_DECL_CONSTEXPR bool isReferenceCountingWaitFree() noexcept { return BaseClass::isFetchAndAddWaitFree(); } template <typename T> static Q_ALWAYS_INLINE - bool ref(T &_q_value) Q_DECL_NOTHROW + bool ref(T &_q_value) noexcept { return BaseClass::fetchAndAddRelaxed(_q_value, 1) != T(-1); } template <typename T> static Q_ALWAYS_INLINE - bool deref(T &_q_value) Q_DECL_NOTHROW + bool deref(T &_q_value) noexcept { return BaseClass::fetchAndAddRelaxed(_q_value, -1) != 1; } @@ -130,16 +130,16 @@ template <typename BaseClass> struct QGenericAtomicOps #if 0 // These functions have no default implementation // Archictectures must implement them - static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW; - static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW; + static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() noexcept; + static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() noexcept; template <typename T, typename X> static inline - bool testAndSetRelaxed(T &_q_value, X expectedValue, X newValue) Q_DECL_NOTHROW; + bool testAndSetRelaxed(T &_q_value, X expectedValue, X newValue) noexcept; template <typename T, typename X> static inline - bool testAndSetRelaxed(T &_q_value, X expectedValue, X newValue, X *currentValue) Q_DECL_NOTHROW; + bool testAndSetRelaxed(T &_q_value, X expectedValue, X newValue, X *currentValue) noexcept; #endif template <typename T, typename X> static Q_ALWAYS_INLINE - bool testAndSetAcquire(T &_q_value, X expectedValue, X newValue) Q_DECL_NOTHROW + bool testAndSetAcquire(T &_q_value, X expectedValue, X newValue) noexcept { bool tmp = BaseClass::testAndSetRelaxed(_q_value, expectedValue, newValue); BaseClass::acquireMemoryFence(_q_value); @@ -147,21 +147,21 @@ template <typename BaseClass> struct QGenericAtomicOps } template <typename T, typename X> static Q_ALWAYS_INLINE - bool testAndSetRelease(T &_q_value, X expectedValue, X newValue) Q_DECL_NOTHROW + bool testAndSetRelease(T &_q_value, X expectedValue, X newValue) noexcept { BaseClass::releaseMemoryFence(_q_value); return BaseClass::testAndSetRelaxed(_q_value, expectedValue, newValue); } template <typename T, typename X> static Q_ALWAYS_INLINE - bool testAndSetOrdered(T &_q_value, X expectedValue, X newValue) Q_DECL_NOTHROW + bool testAndSetOrdered(T &_q_value, X expectedValue, X newValue) noexcept { BaseClass::orderedMemoryFence(_q_value); return BaseClass::testAndSetRelaxed(_q_value, expectedValue, newValue); } template <typename T, typename X> static Q_ALWAYS_INLINE - bool testAndSetAcquire(T &_q_value, X expectedValue, X newValue, X *currentValue) Q_DECL_NOTHROW + bool testAndSetAcquire(T &_q_value, X expectedValue, X newValue, X *currentValue) noexcept { bool tmp = BaseClass::testAndSetRelaxed(_q_value, expectedValue, newValue, currentValue); BaseClass::acquireMemoryFence(_q_value); @@ -169,24 +169,24 @@ template <typename BaseClass> struct QGenericAtomicOps } template <typename T, typename X> static Q_ALWAYS_INLINE - bool testAndSetRelease(T &_q_value, X expectedValue, X newValue, X *currentValue) Q_DECL_NOTHROW + bool testAndSetRelease(T &_q_value, X expectedValue, X newValue, X *currentValue) noexcept { BaseClass::releaseMemoryFence(_q_value); return BaseClass::testAndSetRelaxed(_q_value, expectedValue, newValue, currentValue); } template <typename T, typename X> static Q_ALWAYS_INLINE - bool testAndSetOrdered(T &_q_value, X expectedValue, X newValue, X *currentValue) Q_DECL_NOTHROW + bool testAndSetOrdered(T &_q_value, X expectedValue, X newValue, X *currentValue) noexcept { BaseClass::orderedMemoryFence(_q_value); return BaseClass::testAndSetRelaxed(_q_value, expectedValue, newValue, currentValue); } - static inline Q_DECL_CONSTEXPR bool isFetchAndStoreNative() Q_DECL_NOTHROW { return false; } - static inline Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return false; } + static inline Q_DECL_CONSTEXPR bool isFetchAndStoreNative() noexcept { return false; } + static inline Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() noexcept { return false; } template <typename T, typename X> static Q_ALWAYS_INLINE - T fetchAndStoreRelaxed(T &_q_value, X newValue) Q_DECL_NOTHROW + T fetchAndStoreRelaxed(T &_q_value, X newValue) noexcept { // implement fetchAndStore on top of testAndSet Q_FOREVER { @@ -197,7 +197,7 @@ template <typename BaseClass> struct QGenericAtomicOps } template <typename T, typename X> static Q_ALWAYS_INLINE - T fetchAndStoreAcquire(T &_q_value, X newValue) Q_DECL_NOTHROW + T fetchAndStoreAcquire(T &_q_value, X newValue) noexcept { T tmp = BaseClass::fetchAndStoreRelaxed(_q_value, newValue); BaseClass::acquireMemoryFence(_q_value); @@ -205,23 +205,23 @@ template <typename BaseClass> struct QGenericAtomicOps } template <typename T, typename X> static Q_ALWAYS_INLINE - T fetchAndStoreRelease(T &_q_value, X newValue) Q_DECL_NOTHROW + T fetchAndStoreRelease(T &_q_value, X newValue) noexcept { BaseClass::releaseMemoryFence(_q_value); return BaseClass::fetchAndStoreRelaxed(_q_value, newValue); } template <typename T, typename X> static Q_ALWAYS_INLINE - T fetchAndStoreOrdered(T &_q_value, X newValue) Q_DECL_NOTHROW + T fetchAndStoreOrdered(T &_q_value, X newValue) noexcept { BaseClass::orderedMemoryFence(_q_value); return BaseClass::fetchAndStoreRelaxed(_q_value, newValue); } - static inline Q_DECL_CONSTEXPR bool isFetchAndAddNative() Q_DECL_NOTHROW { return false; } - static inline Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return false; } + static inline Q_DECL_CONSTEXPR bool isFetchAndAddNative() noexcept { return false; } + static inline Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() noexcept { return false; } template <typename T> static Q_ALWAYS_INLINE - T fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { // implement fetchAndAdd on top of testAndSet Q_FOREVER { @@ -232,7 +232,7 @@ template <typename BaseClass> struct QGenericAtomicOps } template <typename T> static Q_ALWAYS_INLINE - T fetchAndAddAcquire(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndAddAcquire(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { T tmp = BaseClass::fetchAndAddRelaxed(_q_value, valueToAdd); BaseClass::acquireMemoryFence(_q_value); @@ -240,14 +240,14 @@ template <typename BaseClass> struct QGenericAtomicOps } template <typename T> static Q_ALWAYS_INLINE - T fetchAndAddRelease(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndAddRelease(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { BaseClass::releaseMemoryFence(_q_value); return BaseClass::fetchAndAddRelaxed(_q_value, valueToAdd); } template <typename T> static Q_ALWAYS_INLINE - T fetchAndAddOrdered(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + T fetchAndAddOrdered(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) noexcept { BaseClass::orderedMemoryFence(_q_value); return BaseClass::fetchAndAddRelaxed(_q_value, valueToAdd); @@ -256,7 +256,7 @@ template <typename BaseClass> struct QGenericAtomicOps QT_WARNING_PUSH QT_WARNING_DISABLE_MSVC(4146) // unary minus operator applied to unsigned type, result still unsigned template <typename T> static Q_ALWAYS_INLINE - T fetchAndSubRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT operand) Q_DECL_NOTHROW + T fetchAndSubRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT operand) noexcept { // implement fetchAndSub on top of fetchAndAdd return fetchAndAddRelaxed(_q_value, -operand); @@ -264,7 +264,7 @@ QT_WARNING_DISABLE_MSVC(4146) // unary minus operator applied to unsigned type QT_WARNING_POP template <typename T> static Q_ALWAYS_INLINE - T fetchAndSubAcquire(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT operand) Q_DECL_NOTHROW + T fetchAndSubAcquire(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT operand) noexcept { T tmp = BaseClass::fetchAndSubRelaxed(_q_value, operand); BaseClass::acquireMemoryFence(_q_value); @@ -272,21 +272,21 @@ QT_WARNING_POP } template <typename T> static Q_ALWAYS_INLINE - T fetchAndSubRelease(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT operand) Q_DECL_NOTHROW + T fetchAndSubRelease(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT operand) noexcept { BaseClass::releaseMemoryFence(_q_value); return BaseClass::fetchAndSubRelaxed(_q_value, operand); } template <typename T> static Q_ALWAYS_INLINE - T fetchAndSubOrdered(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT operand) Q_DECL_NOTHROW + T fetchAndSubOrdered(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT operand) noexcept { BaseClass::orderedMemoryFence(_q_value); return BaseClass::fetchAndSubRelaxed(_q_value, operand); } template <typename T> static Q_ALWAYS_INLINE - T fetchAndAndRelaxed(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW + T fetchAndAndRelaxed(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) noexcept { // implement fetchAndAnd on top of testAndSet T tmp = BaseClass::load(_q_value); @@ -297,7 +297,7 @@ QT_WARNING_POP } template <typename T> static Q_ALWAYS_INLINE - T fetchAndAndAcquire(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW + T fetchAndAndAcquire(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) noexcept { T tmp = BaseClass::fetchAndAndRelaxed(_q_value, operand); BaseClass::acquireMemoryFence(_q_value); @@ -305,21 +305,21 @@ QT_WARNING_POP } template <typename T> static Q_ALWAYS_INLINE - T fetchAndAndRelease(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW + T fetchAndAndRelease(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) noexcept { BaseClass::releaseMemoryFence(_q_value); return BaseClass::fetchAndAndRelaxed(_q_value, operand); } template <typename T> static Q_ALWAYS_INLINE - T fetchAndAndOrdered(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW + T fetchAndAndOrdered(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) noexcept { BaseClass::orderedMemoryFence(_q_value); return BaseClass::fetchAndAndRelaxed(_q_value, operand); } template <typename T> static Q_ALWAYS_INLINE - T fetchAndOrRelaxed(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW + T fetchAndOrRelaxed(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) noexcept { // implement fetchAndOr on top of testAndSet T tmp = BaseClass::load(_q_value); @@ -330,7 +330,7 @@ QT_WARNING_POP } template <typename T> static Q_ALWAYS_INLINE - T fetchAndOrAcquire(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW + T fetchAndOrAcquire(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) noexcept { T tmp = BaseClass::fetchAndOrRelaxed(_q_value, operand); BaseClass::acquireMemoryFence(_q_value); @@ -338,21 +338,21 @@ QT_WARNING_POP } template <typename T> static Q_ALWAYS_INLINE - T fetchAndOrRelease(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW + T fetchAndOrRelease(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) noexcept { BaseClass::releaseMemoryFence(_q_value); return BaseClass::fetchAndOrRelaxed(_q_value, operand); } template <typename T> static Q_ALWAYS_INLINE - T fetchAndOrOrdered(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW + T fetchAndOrOrdered(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) noexcept { BaseClass::orderedMemoryFence(_q_value); return BaseClass::fetchAndOrRelaxed(_q_value, operand); } template <typename T> static Q_ALWAYS_INLINE - T fetchAndXorRelaxed(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW + T fetchAndXorRelaxed(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) noexcept { // implement fetchAndXor on top of testAndSet T tmp = BaseClass::load(_q_value); @@ -363,7 +363,7 @@ QT_WARNING_POP } template <typename T> static Q_ALWAYS_INLINE - T fetchAndXorAcquire(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW + T fetchAndXorAcquire(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) noexcept { T tmp = BaseClass::fetchAndXorRelaxed(_q_value, operand); BaseClass::acquireMemoryFence(_q_value); @@ -371,14 +371,14 @@ QT_WARNING_POP } template <typename T> static Q_ALWAYS_INLINE - T fetchAndXorRelease(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW + T fetchAndXorRelease(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) noexcept { BaseClass::releaseMemoryFence(_q_value); return BaseClass::fetchAndXorRelaxed(_q_value, operand); } template <typename T> static Q_ALWAYS_INLINE - T fetchAndXorOrdered(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) Q_DECL_NOTHROW + T fetchAndXorOrdered(T &_q_value, typename std::enable_if<QTypeInfo<T>::isIntegral, T>::type operand) noexcept { BaseClass::orderedMemoryFence(_q_value); return BaseClass::fetchAndXorRelaxed(_q_value, operand); diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp index 3881ac017e..4f55e50fe5 100644 --- a/src/corelib/thread/qmutex.cpp +++ b/src/corelib/thread/qmutex.cpp @@ -82,7 +82,7 @@ public: QMutex mutex; bool lock(int timeout) QT_MUTEX_LOCK_NOEXCEPT; - void unlock() Q_DECL_NOTHROW; + void unlock() noexcept; }; /* @@ -329,7 +329,7 @@ bool QMutex::tryLock(int timeout) QT_MUTEX_LOCK_NOEXCEPT \sa lock() */ -void QMutex::unlock() Q_DECL_NOTHROW +void QMutex::unlock() noexcept { QMutexData *current; if (fastTryUnlock(current)) @@ -348,7 +348,7 @@ void QMutex::unlock() Q_DECL_NOTHROW Returns \c true if the mutex is recursive. */ -bool QBasicMutex::isRecursive() Q_DECL_NOTHROW +bool QBasicMutex::isRecursive() noexcept { return QT_PREPEND_NAMESPACE(isRecursive)(d_ptr.loadAcquire()); } @@ -358,7 +358,7 @@ bool QBasicMutex::isRecursive() Q_DECL_NOTHROW Returns \c true if the mutex is recursive. */ -bool QBasicMutex::isRecursive() const Q_DECL_NOTHROW +bool QBasicMutex::isRecursive() const noexcept { return QT_PREPEND_NAMESPACE(isRecursive)(d_ptr.loadAcquire()); } @@ -600,7 +600,7 @@ bool QBasicMutex::lockInternal(int timeout) QT_MUTEX_LOCK_NOEXCEPT /*! \internal */ -void QBasicMutex::unlockInternal() Q_DECL_NOTHROW +void QBasicMutex::unlockInternal() noexcept { QMutexData *copy = d_ptr.loadAcquire(); Q_ASSERT(copy); //we must be locked @@ -675,7 +675,7 @@ void QMutexPrivate::release() } // atomically subtract "value" to the waiters, and remove the QMutexPrivate::BigNumber flag -void QMutexPrivate::derefWaiters(int value) Q_DECL_NOTHROW +void QMutexPrivate::derefWaiters(int value) noexcept { int old_waiters; int new_waiters; @@ -716,7 +716,7 @@ inline bool QRecursiveMutexPrivate::lock(int timeout) QT_MUTEX_LOCK_NOEXCEPT /*! \internal */ -inline void QRecursiveMutexPrivate::unlock() Q_DECL_NOTHROW +inline void QRecursiveMutexPrivate::unlock() noexcept { if (count > 0) { count--; diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h index 837355a602..d7796092d1 100644 --- a/src/corelib/thread/qmutex.h +++ b/src/corelib/thread/qmutex.h @@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE #if QT_CONFIG(thread) || defined(Q_CLANG_QDOC) #ifdef Q_OS_LINUX -# define QT_MUTEX_LOCK_NOEXCEPT Q_DECL_NOTHROW +# define QT_MUTEX_LOCK_NOEXCEPT noexcept #else # define QT_MUTEX_LOCK_NOEXCEPT #endif @@ -80,39 +80,39 @@ public: } // BasicLockable concept - inline void unlock() Q_DECL_NOTHROW { + inline void unlock() noexcept { Q_ASSERT(d_ptr.load()); //mutex must be locked if (!fastTryUnlock()) unlockInternal(); } - bool tryLock() Q_DECL_NOTHROW { + bool tryLock() noexcept { return fastTryLock(); } // Lockable concept - bool try_lock() Q_DECL_NOTHROW { return tryLock(); } + bool try_lock() noexcept { return tryLock(); } - bool isRecursive() Q_DECL_NOTHROW; //### Qt6: remove me - bool isRecursive() const Q_DECL_NOTHROW; + bool isRecursive() noexcept; //### Qt6: remove me + bool isRecursive() const noexcept; private: - inline bool fastTryLock() Q_DECL_NOTHROW { + inline bool fastTryLock() noexcept { return d_ptr.testAndSetAcquire(nullptr, dummyLocked()); } - inline bool fastTryUnlock() Q_DECL_NOTHROW { + inline bool fastTryUnlock() noexcept { return d_ptr.testAndSetRelease(dummyLocked(), nullptr); } - inline bool fastTryLock(QMutexData *¤t) Q_DECL_NOTHROW { + inline bool fastTryLock(QMutexData *¤t) noexcept { return d_ptr.testAndSetAcquire(nullptr, dummyLocked(), current); } - inline bool fastTryUnlock(QMutexData *¤t) Q_DECL_NOTHROW { + inline bool fastTryUnlock(QMutexData *¤t) noexcept { return d_ptr.testAndSetRelease(dummyLocked(), nullptr, current); } void lockInternal() QT_MUTEX_LOCK_NOEXCEPT; bool lockInternal(int timeout) QT_MUTEX_LOCK_NOEXCEPT; - void unlockInternal() Q_DECL_NOTHROW; + void unlockInternal() noexcept; QBasicAtomicPointer<QMutexData> d_ptr; static inline QMutexData *dummyLocked() { @@ -134,7 +134,7 @@ public: void lock() QT_MUTEX_LOCK_NOEXCEPT; bool tryLock(int timeout = 0) QT_MUTEX_LOCK_NOEXCEPT; // BasicLockable concept - void unlock() Q_DECL_NOTHROW; + void unlock() noexcept; // Lockable concept bool try_lock() QT_MUTEX_LOCK_NOEXCEPT { return tryLock(); } @@ -158,7 +158,7 @@ public: } #endif - bool isRecursive() const Q_DECL_NOTHROW + bool isRecursive() const noexcept { return QBasicMutex::isRecursive(); } private: @@ -212,7 +212,7 @@ public: #endif inline ~QMutexLocker() { unlock(); } - inline void unlock() Q_DECL_NOTHROW + inline void unlock() noexcept { if ((val & quintptr(1u)) == quintptr(1u)) { val &= ~quintptr(1u); @@ -257,24 +257,24 @@ class Q_CORE_EXPORT QMutex public: enum RecursionMode { NonRecursive, Recursive }; - inline Q_DECL_CONSTEXPR explicit QMutex(RecursionMode = NonRecursive) Q_DECL_NOTHROW { } + inline Q_DECL_CONSTEXPR explicit QMutex(RecursionMode = NonRecursive) noexcept { } - inline void lock() Q_DECL_NOTHROW {} - inline bool tryLock(int timeout = 0) Q_DECL_NOTHROW { Q_UNUSED(timeout); return true; } - inline bool try_lock() Q_DECL_NOTHROW { return true; } - inline void unlock() Q_DECL_NOTHROW {} - inline bool isRecursive() const Q_DECL_NOTHROW { return true; } + inline void lock() noexcept {} + inline bool tryLock(int timeout = 0) noexcept { Q_UNUSED(timeout); return true; } + inline bool try_lock() noexcept { return true; } + inline void unlock() noexcept {} + inline bool isRecursive() const noexcept { return true; } #if QT_HAS_INCLUDE(<chrono>) template <class Rep, class Period> - inline bool try_lock_for(std::chrono::duration<Rep, Period> duration) Q_DECL_NOTHROW + inline bool try_lock_for(std::chrono::duration<Rep, Period> duration) noexcept { Q_UNUSED(duration); return true; } template<class Clock, class Duration> - inline bool try_lock_until(std::chrono::time_point<Clock, Duration> timePoint) Q_DECL_NOTHROW + inline bool try_lock_until(std::chrono::time_point<Clock, Duration> timePoint) noexcept { Q_UNUSED(timePoint); return true; @@ -288,12 +288,12 @@ private: class Q_CORE_EXPORT QMutexLocker { public: - inline explicit QMutexLocker(QMutex *) Q_DECL_NOTHROW {} - inline ~QMutexLocker() Q_DECL_NOTHROW {} + inline explicit QMutexLocker(QMutex *) noexcept {} + inline ~QMutexLocker() noexcept {} - inline void unlock() Q_DECL_NOTHROW {} - void relock() Q_DECL_NOTHROW {} - inline QMutex *mutex() const Q_DECL_NOTHROW { return nullptr; } + inline void unlock() noexcept {} + void relock() noexcept {} + inline QMutex *mutex() const noexcept { return nullptr; } private: Q_DISABLE_COPY(QMutexLocker) diff --git a/src/corelib/thread/qmutex_linux.cpp b/src/corelib/thread/qmutex_linux.cpp index 507e72cb76..b006ff1033 100644 --- a/src/corelib/thread/qmutex_linux.cpp +++ b/src/corelib/thread/qmutex_linux.cpp @@ -106,7 +106,7 @@ static inline QMutexData *dummyFutexValue() } template <bool IsTimed> static inline -bool lockInternal_helper(QBasicAtomicPointer<QMutexData> &d_ptr, int timeout = -1, QElapsedTimer *elapsedTimer = 0) Q_DECL_NOTHROW +bool lockInternal_helper(QBasicAtomicPointer<QMutexData> &d_ptr, int timeout = -1, QElapsedTimer *elapsedTimer = 0) noexcept { if (!IsTimed) timeout = -1; @@ -153,13 +153,13 @@ bool lockInternal_helper(QBasicAtomicPointer<QMutexData> &d_ptr, int timeout = - return true; } -void QBasicMutex::lockInternal() Q_DECL_NOTHROW +void QBasicMutex::lockInternal() noexcept { Q_ASSERT(!isRecursive()); lockInternal_helper<false>(d_ptr); } -bool QBasicMutex::lockInternal(int timeout) Q_DECL_NOTHROW +bool QBasicMutex::lockInternal(int timeout) noexcept { Q_ASSERT(!isRecursive()); QElapsedTimer elapsedTimer; @@ -167,7 +167,7 @@ bool QBasicMutex::lockInternal(int timeout) Q_DECL_NOTHROW return lockInternal_helper<true>(d_ptr, timeout, &elapsedTimer); } -void QBasicMutex::unlockInternal() Q_DECL_NOTHROW +void QBasicMutex::unlockInternal() noexcept { QMutexData *d = d_ptr.load(); Q_ASSERT(d); //we must be locked diff --git a/src/corelib/thread/qmutex_mac.cpp b/src/corelib/thread/qmutex_mac.cpp index 9a8d9bc750..923f89f697 100644 --- a/src/corelib/thread/qmutex_mac.cpp +++ b/src/corelib/thread/qmutex_mac.cpp @@ -79,7 +79,7 @@ bool QMutexPrivate::wait(int timeout) return (r == KERN_SUCCESS); } -void QMutexPrivate::wakeUp() Q_DECL_NOTHROW +void QMutexPrivate::wakeUp() noexcept { semaphore_signal(mach_semaphore); } diff --git a/src/corelib/thread/qmutex_p.h b/src/corelib/thread/qmutex_p.h index ec9bfc1152..5025f836b9 100644 --- a/src/corelib/thread/qmutex_p.h +++ b/src/corelib/thread/qmutex_p.h @@ -92,7 +92,7 @@ public: QMutexPrivate(); bool wait(int timeout = -1); - void wakeUp() Q_DECL_NOTHROW; + void wakeUp() noexcept; // Control the lifetime of the privates QAtomicInt refCount; @@ -125,7 +125,7 @@ public: when the mutex is unlocked. */ enum { BigNumber = 0x100000 }; //Must be bigger than the possible number of waiters (number of threads) - void derefWaiters(int value) Q_DECL_NOTHROW; + void derefWaiters(int value) noexcept; //platform specific stuff #if defined(Q_OS_MAC) diff --git a/src/corelib/thread/qmutex_unix.cpp b/src/corelib/thread/qmutex_unix.cpp index 3ee24a292c..a92ac4f943 100644 --- a/src/corelib/thread/qmutex_unix.cpp +++ b/src/corelib/thread/qmutex_unix.cpp @@ -99,7 +99,7 @@ bool QMutexPrivate::wait(int timeout) return true; } -void QMutexPrivate::wakeUp() Q_DECL_NOTHROW +void QMutexPrivate::wakeUp() noexcept { report_error(sem_post(&semaphore), "QMutex::unlock", "sem_post"); } @@ -146,7 +146,7 @@ bool QMutexPrivate::wait(int timeout) return ret; } -void QMutexPrivate::wakeUp() Q_DECL_NOTHROW +void QMutexPrivate::wakeUp() noexcept { report_error(pthread_mutex_lock(&mutex), "QMutex::unlock", "mutex lock"); wakeup = true; diff --git a/src/corelib/thread/qmutex_win.cpp b/src/corelib/thread/qmutex_win.cpp index 3c314a4c0c..e221bc89cb 100644 --- a/src/corelib/thread/qmutex_win.cpp +++ b/src/corelib/thread/qmutex_win.cpp @@ -64,7 +64,7 @@ bool QMutexPrivate::wait(int timeout) return (WaitForSingleObjectEx(event, timeout < 0 ? INFINITE : timeout, FALSE) == WAIT_OBJECT_0); } -void QMutexPrivate::wakeUp() Q_DECL_NOTHROW +void QMutexPrivate::wakeUp() noexcept { SetEvent(event); } QT_END_NAMESPACE diff --git a/src/corelib/thread/qorderedmutexlocker_p.h b/src/corelib/thread/qorderedmutexlocker_p.h index ded102d32d..e0a67388d4 100644 --- a/src/corelib/thread/qorderedmutexlocker_p.h +++ b/src/corelib/thread/qorderedmutexlocker_p.h @@ -58,6 +58,8 @@ QT_BEGIN_NAMESPACE +#if QT_CONFIG(thread) + /* Locks 2 mutexes in a defined order, avoiding a recursive lock if we're trying to lock the same mutex twice. @@ -65,9 +67,9 @@ QT_BEGIN_NAMESPACE class QOrderedMutexLocker { public: - QOrderedMutexLocker(QMutex *m1, QMutex *m2) - : mtx1((m1 == m2) ? m1 : (std::less<QMutex *>()(m1, m2) ? m1 : m2)), - mtx2((m1 == m2) ? 0 : (std::less<QMutex *>()(m1, m2) ? m2 : m1)), + QOrderedMutexLocker(QBasicMutex *m1, QBasicMutex *m2) + : mtx1((m1 == m2) ? m1 : (std::less<QBasicMutex *>()(m1, m2) ? m1 : m2)), + mtx2((m1 == m2) ? 0 : (std::less<QBasicMutex *>()(m1, m2) ? m2 : m1)), locked(false) { relock(); @@ -95,12 +97,12 @@ public: } } - static bool relock(QMutex *mtx1, QMutex *mtx2) + static bool relock(QBasicMutex *mtx1, QBasicMutex *mtx2) { // mtx1 is already locked, mtx2 not... do we need to unlock and relock? if (mtx1 == mtx2) return false; - if (std::less<QMutex *>()(mtx1, mtx2)) { + if (std::less<QBasicMutex *>()(mtx1, mtx2)) { mtx2->lock(); return true; } @@ -113,10 +115,58 @@ public: } private: - QMutex *mtx1, *mtx2; + QBasicMutex *mtx1, *mtx2; bool locked; }; +class QBasicMutexLocker +{ +public: + inline explicit QBasicMutexLocker(QBasicMutex *m) QT_MUTEX_LOCK_NOEXCEPT + : m(m), isLocked(true) + { + m->lock(); + } + inline ~QBasicMutexLocker() { if (isLocked) unlock(); } + + inline void unlock() noexcept + { + isLocked = false; + m->unlock(); + } + + inline void relock() QT_MUTEX_LOCK_NOEXCEPT + { + isLocked = true; + m->lock(); + } + +private: + Q_DISABLE_COPY(QBasicMutexLocker) + + QBasicMutex *m; + bool isLocked; +}; + +#else + +class QOrderedMutexLocker +{ +public: + QOrderedMutexLocker(QBasicMutex *, QBasicMutex *) {} + ~QOrderedMutexLocker() {} + + void relock() {} + void unlock() {} + + static bool relock(QBasicMutex *, QBasicMutex *) {} +}; + +using QBasicMutexLocker = QMutexLocker; + +#endif + + QT_END_NAMESPACE #endif diff --git a/src/corelib/thread/qreadwritelock.h b/src/corelib/thread/qreadwritelock.h index 65fa76fd6d..139fde9214 100644 --- a/src/corelib/thread/qreadwritelock.h +++ b/src/corelib/thread/qreadwritelock.h @@ -180,18 +180,18 @@ class Q_CORE_EXPORT QReadWriteLock { public: enum RecursionMode { NonRecursive, Recursive }; - inline explicit QReadWriteLock(RecursionMode = NonRecursive) Q_DECL_NOTHROW { } + inline explicit QReadWriteLock(RecursionMode = NonRecursive) noexcept { } inline ~QReadWriteLock() { } - static inline void lockForRead() Q_DECL_NOTHROW { } - static inline bool tryLockForRead() Q_DECL_NOTHROW { return true; } - static inline bool tryLockForRead(int timeout) Q_DECL_NOTHROW { Q_UNUSED(timeout); return true; } + static inline void lockForRead() noexcept { } + static inline bool tryLockForRead() noexcept { return true; } + static inline bool tryLockForRead(int timeout) noexcept { Q_UNUSED(timeout); return true; } - static inline void lockForWrite() Q_DECL_NOTHROW { } - static inline bool tryLockForWrite() Q_DECL_NOTHROW { return true; } - static inline bool tryLockForWrite(int timeout) Q_DECL_NOTHROW { Q_UNUSED(timeout); return true; } + static inline void lockForWrite() noexcept { } + static inline bool tryLockForWrite() noexcept { return true; } + static inline bool tryLockForWrite(int timeout) noexcept { Q_UNUSED(timeout); return true; } - static inline void unlock() Q_DECL_NOTHROW { } + static inline void unlock() noexcept { } private: Q_DISABLE_COPY(QReadWriteLock) @@ -200,12 +200,12 @@ private: class Q_CORE_EXPORT QReadLocker { public: - inline QReadLocker(QReadWriteLock *) Q_DECL_NOTHROW { } - inline ~QReadLocker() Q_DECL_NOTHROW { } + inline QReadLocker(QReadWriteLock *) noexcept { } + inline ~QReadLocker() noexcept { } - static inline void unlock() Q_DECL_NOTHROW { } - static inline void relock() Q_DECL_NOTHROW { } - static inline QReadWriteLock *readWriteLock() Q_DECL_NOTHROW { return nullptr; } + static inline void unlock() noexcept { } + static inline void relock() noexcept { } + static inline QReadWriteLock *readWriteLock() noexcept { return nullptr; } private: Q_DISABLE_COPY(QReadLocker) @@ -214,12 +214,12 @@ private: class Q_CORE_EXPORT QWriteLocker { public: - inline explicit QWriteLocker(QReadWriteLock *) Q_DECL_NOTHROW { } - inline ~QWriteLocker() Q_DECL_NOTHROW { } + inline explicit QWriteLocker(QReadWriteLock *) noexcept { } + inline ~QWriteLocker() noexcept { } - static inline void unlock() Q_DECL_NOTHROW { } - static inline void relock() Q_DECL_NOTHROW { } - static inline QReadWriteLock *readWriteLock() Q_DECL_NOTHROW { return nullptr; } + static inline void unlock() noexcept { } + static inline void relock() noexcept { } + static inline QReadWriteLock *readWriteLock() noexcept { return nullptr; } private: Q_DISABLE_COPY(QWriteLocker) diff --git a/src/corelib/thread/qresultstore.h b/src/corelib/thread/qresultstore.h index 1f29e8d187..7a65089396 100644 --- a/src/corelib/thread/qresultstore.h +++ b/src/corelib/thread/qresultstore.h @@ -142,7 +142,7 @@ public: template <typename T> int addResult(int index, const T *result) { - if (result == 0) + if (result == nullptr) return addResult(index, static_cast<void *>(nullptr)); else return addResult(index, static_cast<void *>(new T(*result))); @@ -158,7 +158,7 @@ public: int addResults(int index, const QVector<T> *results, int totalCount) { if (m_filterMode == true && results->count() != totalCount && 0 == results->count()) - return addResults(index, 0, 0, totalCount); + return addResults(index, nullptr, 0, totalCount); else return addResults(index, new QVector<T>(*results), results->count(), totalCount); } diff --git a/src/corelib/thread/qsemaphore.h b/src/corelib/thread/qsemaphore.h index b830ff1bfd..58c12997ad 100644 --- a/src/corelib/thread/qsemaphore.h +++ b/src/corelib/thread/qsemaphore.h @@ -75,14 +75,14 @@ class QSemaphoreReleaser { public: QSemaphoreReleaser() = default; - explicit QSemaphoreReleaser(QSemaphore &sem, int n = 1) Q_DECL_NOTHROW + explicit QSemaphoreReleaser(QSemaphore &sem, int n = 1) noexcept : m_sem(&sem), m_n(n) {} - explicit QSemaphoreReleaser(QSemaphore *sem, int n = 1) Q_DECL_NOTHROW + explicit QSemaphoreReleaser(QSemaphore *sem, int n = 1) noexcept : m_sem(sem), m_n(n) {} - QSemaphoreReleaser(QSemaphoreReleaser &&other) Q_DECL_NOTHROW + QSemaphoreReleaser(QSemaphoreReleaser &&other) noexcept : m_sem(other.m_sem), m_n(other.m_n) { other.m_sem = nullptr; } - QSemaphoreReleaser &operator=(QSemaphoreReleaser &&other) Q_DECL_NOTHROW + QSemaphoreReleaser &operator=(QSemaphoreReleaser &&other) noexcept { QSemaphoreReleaser moved(std::move(other)); swap(moved); return *this; } ~QSemaphoreReleaser() @@ -91,16 +91,16 @@ public: m_sem->release(m_n); } - void swap(QSemaphoreReleaser &other) Q_DECL_NOTHROW + void swap(QSemaphoreReleaser &other) noexcept { qSwap(m_sem, other.m_sem); qSwap(m_n, other.m_n); } - QSemaphore *semaphore() const Q_DECL_NOTHROW + QSemaphore *semaphore() const noexcept { return m_sem; } - QSemaphore *cancel() Q_DECL_NOTHROW + QSemaphore *cancel() noexcept { QSemaphore *old = m_sem; m_sem = nullptr; diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index 9f60de1f87..b9b9f3e354 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -839,7 +839,7 @@ bool QThread::event(QEvent* event) return QObject::event(event); } -Qt::HANDLE QThread::currentThreadId() Q_DECL_NOTHROW +Qt::HANDLE QThread::currentThreadId() noexcept { return Qt::HANDLE(currentThread()); } @@ -849,7 +849,7 @@ QThread *QThread::currentThread() return QThreadData::current()->thread; } -int QThread::idealThreadCount() Q_DECL_NOTHROW +int QThread::idealThreadCount() noexcept { return 1; } diff --git a/src/corelib/thread/qthread.h b/src/corelib/thread/qthread.h index b6c5bf47d0..8e92d75401 100644 --- a/src/corelib/thread/qthread.h +++ b/src/corelib/thread/qthread.h @@ -70,9 +70,9 @@ class Q_CORE_EXPORT QThread : public QObject { Q_OBJECT public: - static Qt::HANDLE currentThreadId() Q_DECL_NOTHROW Q_DECL_PURE_FUNCTION; + static Qt::HANDLE currentThreadId() noexcept Q_DECL_PURE_FUNCTION; static QThread *currentThread(); - static int idealThreadCount() Q_DECL_NOTHROW; + static int idealThreadCount() noexcept; static void yieldCurrentThread(); explicit QThread(QObject *parent = nullptr); diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h index 7d9442ab79..209225de98 100644 --- a/src/corelib/thread/qthread_p.h +++ b/src/corelib/thread/qthread_p.h @@ -89,7 +89,7 @@ public: QEvent *event; int priority; inline QPostEvent() - : receiver(0), event(0), priority(0) + : receiver(nullptr), event(nullptr), priority(0) { } inline QPostEvent(QObject *r, QEvent *e, int p) : receiver(r), event(e), priority(p) @@ -148,7 +148,7 @@ private: class Q_CORE_EXPORT QDaemonThread : public QThread { public: - QDaemonThread(QObject *parent = 0); + QDaemonThread(QObject *parent = nullptr); ~QDaemonThread(); }; @@ -157,7 +157,7 @@ class QThreadPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QThread) public: - QThreadPrivate(QThreadData *d = 0); + QThreadPrivate(QThreadData *d = nullptr); ~QThreadPrivate(); void setPriority(QThread::Priority prio); @@ -187,8 +187,8 @@ public: #endif // Q_OS_UNIX #ifdef Q_OS_WIN - static unsigned int __stdcall start(void *) Q_DECL_NOEXCEPT; - static void finish(void *, bool lockAnyway=true) Q_DECL_NOEXCEPT; + static unsigned int __stdcall start(void *) noexcept; + static void finish(void *, bool lockAnyway=true) noexcept; Qt::HANDLE handle; unsigned int id; @@ -248,7 +248,7 @@ public: #endif static void clearCurrentThreadData(); static QThreadData *get2(QThread *thread) - { Q_ASSERT_X(thread != 0, "QThread", "internal error"); return thread->d_func()->data; } + { Q_ASSERT_X(thread != nullptr, "QThread", "internal error"); return thread->d_func()->data; } void ref(); @@ -281,7 +281,7 @@ public: public: FlaggedDebugSignatures() : idx(0) - { std::fill_n(locations, Count, static_cast<char*>(0)); } + { std::fill_n(locations, Count, static_cast<char*>(nullptr)); } void store(const char* method) { locations[idx++ % Count] = method; } @@ -328,7 +328,7 @@ class QAdoptedThread : public QThread Q_DECLARE_PRIVATE(QThread) public: - QAdoptedThread(QThreadData *data = 0); + QAdoptedThread(QThreadData *data = nullptr); ~QAdoptedThread(); void init(); diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index a13f8ca215..8328e514a8 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -443,7 +443,7 @@ void QThreadPrivate::finish(void *arg) ** QThread *************************************************************************/ -Qt::HANDLE QThread::currentThreadId() Q_DECL_NOTHROW +Qt::HANDLE QThread::currentThreadId() noexcept { // requires a C cast here otherwise we run into trouble on AIX return to_HANDLE(pthread_self()); @@ -454,7 +454,7 @@ Qt::HANDLE QThread::currentThreadId() Q_DECL_NOTHROW # define _SC_NPROCESSORS_ONLN 84 #endif -int QThread::idealThreadCount() Q_DECL_NOTHROW +int QThread::idealThreadCount() noexcept { int cores = 1; diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp index e56fe2c6ae..ee73280707 100644 --- a/src/corelib/thread/qthread_win.cpp +++ b/src/corelib/thread/qthread_win.cpp @@ -372,7 +372,7 @@ QAbstractEventDispatcher *QThreadPrivate::createEventDispatcher(QThreadData *dat #if QT_CONFIG(thread) -unsigned int __stdcall QT_ENSURE_STACK_ALIGNED_FOR_SSE QThreadPrivate::start(void *arg) Q_DECL_NOEXCEPT +unsigned int __stdcall QT_ENSURE_STACK_ALIGNED_FOR_SSE QThreadPrivate::start(void *arg) noexcept { QThread *thr = reinterpret_cast<QThread *>(arg); QThreadData *data = QThreadData::get2(thr); @@ -406,7 +406,7 @@ unsigned int __stdcall QT_ENSURE_STACK_ALIGNED_FOR_SSE QThreadPrivate::start(voi return 0; } -void QThreadPrivate::finish(void *arg, bool lockAnyway) Q_DECL_NOEXCEPT +void QThreadPrivate::finish(void *arg, bool lockAnyway) noexcept { QThread *thr = reinterpret_cast<QThread *>(arg); QThreadPrivate *d = thr->d_func(); @@ -447,12 +447,12 @@ void QThreadPrivate::finish(void *arg, bool lockAnyway) Q_DECL_NOEXCEPT ** QThread *************************************************************************/ -Qt::HANDLE QThread::currentThreadId() Q_DECL_NOTHROW +Qt::HANDLE QThread::currentThreadId() noexcept { return reinterpret_cast<Qt::HANDLE>(quintptr(GetCurrentThreadId())); } -int QThread::idealThreadCount() Q_DECL_NOTHROW +int QThread::idealThreadCount() noexcept { SYSTEM_INFO sysinfo; #ifndef Q_OS_WINRT diff --git a/src/corelib/thread/qthreadpool_p.h b/src/corelib/thread/qthreadpool_p.h index 952e02ef20..01852d8366 100644 --- a/src/corelib/thread/qthreadpool_p.h +++ b/src/corelib/thread/qthreadpool_p.h @@ -162,7 +162,7 @@ public: void tryToStartMoreThreads(); bool tooManyThreadsActive() const; - void startThread(QRunnable *runnable = 0); + void startThread(QRunnable *runnable = nullptr); void reset(); bool waitForDone(int msecs); bool waitForDone(const QDeadlineTimer &timer); diff --git a/src/corelib/thread/qthreadstorage.h b/src/corelib/thread/qthreadstorage.h index 55fc482da3..9eb8672e92 100644 --- a/src/corelib/thread/qthreadstorage.h +++ b/src/corelib/thread/qthreadstorage.h @@ -69,7 +69,7 @@ inline T *&qThreadStorage_localData(QThreadStorageData &d, T **) { void **v = d.get(); - if (!v) v = d.set(0); + if (!v) v = d.set(nullptr); return *(reinterpret_cast<T**>(v)); } @@ -139,7 +139,7 @@ public: inline ~QThreadStorage() { } inline bool hasLocalData() const - { return d.get() != 0; } + { return d.get() != nullptr; } inline T& localData() { return qThreadStorage_localData(d, reinterpret_cast<T*>(0)); } diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h index 0146e22fa3..f1243b5c61 100644 --- a/src/corelib/tools/qalgorithms.h +++ b/src/corelib/tools/qalgorithms.h @@ -533,7 +533,7 @@ QT_DEPRECATED_X("Use std::binary_search") Q_OUTOFLINE_TEMPLATE RandomAccessItera #if defined QT_HAS_CONSTEXPR_BUILTINS #if defined(Q_CC_GNU) || defined(Q_CC_CLANG) # define QT_HAS_BUILTIN_CTZS -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctzs(quint16 v) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctzs(quint16 v) noexcept { # if QT_HAS_BUILTIN(__builtin_ctzs) return __builtin_ctzs(v); @@ -542,7 +542,7 @@ Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctzs(quint16 v) Q_DECL_NOTHROW # endif } #define QT_HAS_BUILTIN_CLZS -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_clzs(quint16 v) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_clzs(quint16 v) noexcept { # if QT_HAS_BUILTIN(__builtin_clzs) return __builtin_clzs(v); @@ -551,40 +551,40 @@ Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_clzs(quint16 v) Q_DECL_NOTHROW # endif } #define QT_HAS_BUILTIN_CTZ -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctz(quint32 v) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctz(quint32 v) noexcept { return __builtin_ctz(v); } #define QT_HAS_BUILTIN_CLZ -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_clz(quint32 v) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_clz(quint32 v) noexcept { return __builtin_clz(v); } #define QT_HAS_BUILTIN_CTZLL -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctzll(quint64 v) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctzll(quint64 v) noexcept { return __builtin_ctzll(v); } #define QT_HAS_BUILTIN_CLZLL -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_clzll(quint64 v) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_clzll(quint64 v) noexcept { return __builtin_clzll(v); } #define QALGORITHMS_USE_BUILTIN_POPCOUNT -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcount(quint32 v) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcount(quint32 v) noexcept { return __builtin_popcount(v); } -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcount(quint8 v) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcount(quint8 v) noexcept { return __builtin_popcount(v); } -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcount(quint16 v) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcount(quint16 v) noexcept { return __builtin_popcount(v); } #define QALGORITHMS_USE_BUILTIN_POPCOUNTLL -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcountll(quint64 v) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcountll(quint64 v) noexcept { return __builtin_popcountll(v); } @@ -630,12 +630,12 @@ Q_ALWAYS_INLINE unsigned long qt_builtin_clzll(quint64 val) } #endif // MSVC 64bit # define QT_HAS_BUILTIN_CTZS -Q_ALWAYS_INLINE uint qt_builtin_ctzs(quint16 v) Q_DECL_NOTHROW +Q_ALWAYS_INLINE uint qt_builtin_ctzs(quint16 v) noexcept { return qt_builtin_ctz(v); } #define QT_HAS_BUILTIN_CLZS -Q_ALWAYS_INLINE uint qt_builtin_clzs(quint16 v) Q_DECL_NOTHROW +Q_ALWAYS_INLINE uint qt_builtin_clzs(quint16 v) noexcept { return qt_builtin_clz(v) - 16U; } @@ -652,19 +652,19 @@ Q_ALWAYS_INLINE uint qt_builtin_clzs(quint16 v) Q_DECL_NOTHROW #if defined(__AVX__) || defined(__SSE4_2__) || defined(__POPCNT__) #define QALGORITHMS_USE_BUILTIN_POPCOUNT #define QALGORITHMS_USE_BUILTIN_POPCOUNTLL -Q_ALWAYS_INLINE uint qt_builtin_popcount(quint32 v) Q_DECL_NOTHROW +Q_ALWAYS_INLINE uint qt_builtin_popcount(quint32 v) noexcept { return __popcnt(v); } -Q_ALWAYS_INLINE uint qt_builtin_popcount(quint8 v) Q_DECL_NOTHROW +Q_ALWAYS_INLINE uint qt_builtin_popcount(quint8 v) noexcept { return __popcnt16(v); } -Q_ALWAYS_INLINE uint qt_builtin_popcount(quint16 v) Q_DECL_NOTHROW +Q_ALWAYS_INLINE uint qt_builtin_popcount(quint16 v) noexcept { return __popcnt16(v); } -Q_ALWAYS_INLINE uint qt_builtin_popcountll(quint64 v) Q_DECL_NOTHROW +Q_ALWAYS_INLINE uint qt_builtin_popcountll(quint64 v) noexcept { #if Q_PROCESSOR_WORDSIZE == 8 return __popcnt64(v); @@ -685,7 +685,7 @@ Q_ALWAYS_INLINE uint qt_builtin_popcountll(quint64 v) Q_DECL_NOTHROW } //namespace QAlgorithmsPrivate -Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint32 v) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint32 v) noexcept { #ifdef QALGORITHMS_USE_BUILTIN_POPCOUNT return QAlgorithmsPrivate::qt_builtin_popcount(v); @@ -698,7 +698,7 @@ Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint32 #endif } -Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint8 v) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint8 v) noexcept { #ifdef QALGORITHMS_USE_BUILTIN_POPCOUNT return QAlgorithmsPrivate::qt_builtin_popcount(v); @@ -708,7 +708,7 @@ Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint8 #endif } -Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint16 v) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint16 v) noexcept { #ifdef QALGORITHMS_USE_BUILTIN_POPCOUNT return QAlgorithmsPrivate::qt_builtin_popcount(v); @@ -719,7 +719,7 @@ Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint16 #endif } -Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint64 v) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint64 v) noexcept { #ifdef QALGORITHMS_USE_BUILTIN_POPCOUNTLL return QAlgorithmsPrivate::qt_builtin_popcountll(v); @@ -734,7 +734,7 @@ Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint64 #endif } -Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(long unsigned int v) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(long unsigned int v) noexcept { return qPopulationCount(static_cast<quint64>(v)); } @@ -744,7 +744,7 @@ Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(long un #endif #undef QT_POPCOUNT_CONSTEXPR -Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint32 v) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint32 v) noexcept { #if defined(QT_HAS_BUILTIN_CTZ) return v ? QAlgorithmsPrivate::qt_builtin_ctz(v) : 32U; @@ -762,7 +762,7 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint32 v) Q_DECL_NO #endif } -Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint8 v) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint8 v) noexcept { #if defined(QT_HAS_BUILTIN_CTZ) return v ? QAlgorithmsPrivate::qt_builtin_ctz(v) : 8U; @@ -777,7 +777,7 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint8 v) Q_DECL_NOT #endif } -Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint16 v) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint16 v) noexcept { #if defined(QT_HAS_BUILTIN_CTZS) return v ? QAlgorithmsPrivate::qt_builtin_ctzs(v) : 16U; @@ -793,7 +793,7 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint16 v) Q_DECL_NO #endif } -Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint64 v) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint64 v) noexcept { #if defined(QT_HAS_BUILTIN_CTZLL) return v ? QAlgorithmsPrivate::qt_builtin_ctzll(v) : 64; @@ -804,12 +804,12 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint64 v) Q_DECL_NO #endif } -Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(unsigned long v) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(unsigned long v) noexcept { return qCountTrailingZeroBits(QIntegerForSizeof<long>::Unsigned(v)); } -Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint32 v) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint32 v) noexcept { #if defined(QT_HAS_BUILTIN_CLZ) return v ? QAlgorithmsPrivate::qt_builtin_clz(v) : 32U; @@ -824,7 +824,7 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint32 v) Q_DECL_NOT #endif } -QT_POPCOUNT_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint8 v) Q_DECL_NOTHROW +QT_POPCOUNT_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint8 v) noexcept { #if defined(QT_HAS_BUILTIN_CLZ) return v ? QAlgorithmsPrivate::qt_builtin_clz(v)-24U : 8U; @@ -836,7 +836,7 @@ QT_POPCOUNT_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint8 v) Q_DECL #endif } -QT_POPCOUNT_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint16 v) Q_DECL_NOTHROW +QT_POPCOUNT_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint16 v) noexcept { #if defined(QT_HAS_BUILTIN_CLZS) return v ? QAlgorithmsPrivate::qt_builtin_clzs(v) : 16U; @@ -849,7 +849,7 @@ QT_POPCOUNT_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint16 v) Q_DEC #endif } -QT_POPCOUNT_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint64 v) Q_DECL_NOTHROW +QT_POPCOUNT_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint64 v) noexcept { #if defined(QT_HAS_BUILTIN_CLZLL) return v ? QAlgorithmsPrivate::qt_builtin_clzll(v) : 64U; @@ -864,7 +864,7 @@ QT_POPCOUNT_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint64 v) Q_DEC #endif } -QT_POPCOUNT_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(unsigned long v) Q_DECL_NOTHROW +QT_POPCOUNT_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(unsigned long v) noexcept { return qCountLeadingZeroBits(QIntegerForSizeof<long>::Unsigned(v)); } diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp index a91d833e3b..bcc0688a91 100644 --- a/src/corelib/tools/qarraydata.cpp +++ b/src/corelib/tools/qarraydata.cpp @@ -87,7 +87,7 @@ static QArrayData *reallocateData(QArrayData *header, size_t allocSize, uint opt } QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment, - size_t capacity, AllocationOptions options) Q_DECL_NOTHROW + size_t capacity, AllocationOptions options) noexcept { // Alignment is a power of two Q_ASSERT(alignment >= Q_ALIGNOF(QArrayData) @@ -135,7 +135,7 @@ QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment, } QArrayData *QArrayData::reallocateUnaligned(QArrayData *data, size_t objectSize, size_t capacity, - AllocationOptions options) Q_DECL_NOTHROW + AllocationOptions options) noexcept { Q_ASSERT(data); Q_ASSERT(data->isMutable()); @@ -150,7 +150,7 @@ QArrayData *QArrayData::reallocateUnaligned(QArrayData *data, size_t objectSize, } void QArrayData::deallocate(QArrayData *data, size_t objectSize, - size_t alignment) Q_DECL_NOTHROW + size_t alignment) noexcept { // Alignment is a power of two Q_ASSERT(alignment >= Q_ALIGNOF(QArrayData) diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index a642fb9b39..7e3f8c9dbd 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -113,14 +113,14 @@ struct Q_CORE_EXPORT QArrayData } Q_REQUIRED_RESULT static QArrayData *allocate(size_t objectSize, size_t alignment, - size_t capacity, AllocationOptions options = Default) Q_DECL_NOTHROW; + size_t capacity, AllocationOptions options = Default) noexcept; Q_REQUIRED_RESULT static QArrayData *reallocateUnaligned(QArrayData *data, size_t objectSize, - size_t newCapacity, AllocationOptions newOptions = Default) Q_DECL_NOTHROW; + size_t newCapacity, AllocationOptions newOptions = Default) noexcept; static void deallocate(QArrayData *data, size_t objectSize, - size_t alignment) Q_DECL_NOTHROW; + size_t alignment) noexcept; static const QArrayData shared_null[2]; - static QArrayData *sharedNull() Q_DECL_NOTHROW { return const_cast<QArrayData*>(shared_null); } + static QArrayData *sharedNull() noexcept { return const_cast<QArrayData*>(shared_null); } }; Q_DECLARE_OPERATORS_FOR_FLAGS(QArrayData::AllocationOptions) @@ -254,7 +254,7 @@ struct QTypedArrayData return result; } - static QTypedArrayData *sharedNull() Q_DECL_NOTHROW + static QTypedArrayData *sharedNull() noexcept { Q_STATIC_ASSERT(sizeof(QTypedArrayData) == sizeof(QArrayData)); return static_cast<QTypedArrayData *>(QArrayData::sharedNull()); @@ -306,8 +306,6 @@ struct QArrayDataPointerRef // accomplished by hiding a static const instance of QStaticArrayData, which is // POD. -#if defined(Q_COMPILER_VARIADIC_MACROS) -#if defined(Q_COMPILER_LAMBDA) // Hide array inside a lambda #define Q_ARRAY_LITERAL(Type, ...) \ ([]() -> QArrayDataPointerRef<Type> { \ @@ -324,10 +322,7 @@ struct QArrayDataPointerRef return StaticWrapper::get(); \ }()) \ /**/ -#endif -#endif // defined(Q_COMPILER_VARIADIC_MACROS) -#if defined(Q_ARRAY_LITERAL) #define Q_ARRAY_LITERAL_IMPL(Type, ...) \ union { Type type_must_be_POD; } dummy; Q_UNUSED(dummy) \ \ @@ -342,31 +337,6 @@ struct QArrayDataPointerRef { static_cast<QTypedArrayData<Type> *>( \ const_cast<QArrayData *>(&literal.header)) }; \ /**/ -#else -// As a fallback, memory is allocated and data copied to the heap. - -// The fallback macro does NOT use variadic macros and does NOT support -// variable number of arguments. It is suitable for char arrays. - -namespace QtPrivate { - template <class T, size_t N> - inline QArrayDataPointerRef<T> qMakeArrayLiteral(const T (&array)[N]) - { - union { T type_must_be_POD; } dummy; Q_UNUSED(dummy) - - QArrayDataPointerRef<T> result = { QTypedArrayData<T>::allocate(N) }; - Q_CHECK_PTR(result.ptr); - - ::memcpy(result.ptr->data(), array, N * sizeof(T)); - result.ptr->size = N; - - return result; - } -} - -#define Q_ARRAY_LITERAL(Type, Array) \ - QT_PREPEND_NAMESPACE(QtPrivate::qMakeArrayLiteral)<Type>( Array ) -#endif // !defined(Q_ARRAY_LITERAL) namespace QtPrivate { struct Q_CORE_EXPORT QContainerImplHelper diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h index 51cfa6e849..0322615f91 100644 --- a/src/corelib/tools/qarraydatapointer.h +++ b/src/corelib/tools/qarraydatapointer.h @@ -52,7 +52,7 @@ private: typedef QArrayDataOps<T> DataOps; public: - QArrayDataPointer() Q_DECL_NOTHROW + QArrayDataPointer() noexcept : d(Data::sharedNull()) { } @@ -82,20 +82,18 @@ public: return *this; } -#ifdef Q_COMPILER_RVALUE_REFS - QArrayDataPointer(QArrayDataPointer &&other) Q_DECL_NOTHROW + QArrayDataPointer(QArrayDataPointer &&other) noexcept : d(other.d) { other.d = Data::sharedNull(); } - QArrayDataPointer &operator=(QArrayDataPointer &&other) Q_DECL_NOTHROW + QArrayDataPointer &operator=(QArrayDataPointer &&other) noexcept { QArrayDataPointer moved(std::move(other)); this->swap(moved); return *this; } -#endif DataOps &operator*() const { @@ -150,7 +148,7 @@ public: bool isSharable() const { return d->isSharable(); } #endif - void swap(QArrayDataPointer &other) Q_DECL_NOTHROW + void swap(QArrayDataPointer &other) noexcept { qSwap(d, other.d); } diff --git a/src/corelib/tools/qbitarray.h b/src/corelib/tools/qbitarray.h index ff40bf5654..9b0e931aca 100644 --- a/src/corelib/tools/qbitarray.h +++ b/src/corelib/tools/qbitarray.h @@ -50,21 +50,19 @@ class Q_CORE_EXPORT QBitArray { friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QBitArray &); friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QBitArray &); - friend Q_CORE_EXPORT uint qHash(const QBitArray &key, uint seed) Q_DECL_NOTHROW; + friend Q_CORE_EXPORT uint qHash(const QBitArray &key, uint seed) noexcept; QByteArray d; public: - inline QBitArray() Q_DECL_NOTHROW {} + inline QBitArray() noexcept {} explicit QBitArray(int size, bool val = false); 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) Q_DECL_NOTHROW : d(std::move(other.d)) {} - inline QBitArray &operator=(QBitArray &&other) Q_DECL_NOTHROW + inline QBitArray(QBitArray &&other) noexcept : d(std::move(other.d)) {} + inline QBitArray &operator=(QBitArray &&other) noexcept { qSwap(d, other.d); return *this; } -#endif - inline void swap(QBitArray &other) Q_DECL_NOTHROW { qSwap(d, other.d); } + inline void swap(QBitArray &other) noexcept { qSwap(d, other.d); } inline int size() const { return (d.size() << 3) - *d.constData(); } inline int count() const { return (d.size() << 3) - *d.constData(); } diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 0f27071176..5f5302107b 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -165,7 +165,7 @@ int qFindByteArray( This function returns SIZE_MAX (~0) on overflow or if the memory block size would not fit an int. */ -size_t qCalculateBlockSize(size_t elementCount, size_t elementSize, size_t headerSize) Q_DECL_NOTHROW +size_t qCalculateBlockSize(size_t elementCount, size_t elementSize, size_t headerSize) noexcept { unsigned count = unsigned(elementCount); unsigned size = unsigned(elementSize); @@ -206,7 +206,7 @@ size_t qCalculateBlockSize(size_t elementCount, size_t elementSize, size_t heade needed. */ CalculateGrowingBlockSizeResult -qCalculateGrowingBlockSize(size_t elementCount, size_t elementSize, size_t headerSize) Q_DECL_NOTHROW +qCalculateGrowingBlockSize(size_t elementCount, size_t elementSize, size_t headerSize) noexcept { CalculateGrowingBlockSizeResult result = { std::numeric_limits<size_t>::max(),std::numeric_limits<size_t>::max() @@ -1281,7 +1281,7 @@ QByteArray qUncompress(const uchar* data, int nbytes) Assigns \a other to this byte array and returns a reference to this byte array. */ -QByteArray &QByteArray::operator=(const QByteArray & other) Q_DECL_NOTHROW +QByteArray &QByteArray::operator=(const QByteArray & other) noexcept { other.d->ref.ref(); if (!d->ref.deref()) @@ -3282,10 +3282,10 @@ static QByteArray toCase_template(T &input, const uchar * table) } if (firstBad == e) - return qMove(input); + return std::move(input); // transform the rest - QByteArray s = qMove(input); // will copy if T is const QByteArray + QByteArray s = std::move(input); // will copy if T is const QByteArray char *b = s.begin(); // will detach if necessary char *p = b + (firstBad - orig_begin); e = b + s.size(); @@ -4136,10 +4136,9 @@ ushort QByteArray::toUShort(bool *ok, int base) const double QByteArray::toDouble(bool *ok) const { - QByteArray nulled = nulTerminated(); bool nonNullOk = false; int processed = 0; - double d = qt_asciiToDouble(nulled.constData(), nulled.length(), + double d = qt_asciiToDouble(constData(), size(), nonNullOk, processed, WhitespacesAllowed); if (ok) *ok = nonNullOk; diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index 8ee3a29ecc..14fcddce7c 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -168,22 +168,20 @@ public: }; Q_DECLARE_FLAGS(Base64Options, Base64Option) - inline QByteArray() Q_DECL_NOTHROW; + inline QByteArray() noexcept; QByteArray(const char *, int size = -1); QByteArray(int size, char c); QByteArray(int size, Qt::Initialization); - inline QByteArray(const QByteArray &) Q_DECL_NOTHROW; + inline QByteArray(const QByteArray &) noexcept; inline ~QByteArray(); - QByteArray &operator=(const QByteArray &) Q_DECL_NOTHROW; + QByteArray &operator=(const QByteArray &) noexcept; QByteArray &operator=(const char *str); -#ifdef Q_COMPILER_RVALUE_REFS - inline QByteArray(QByteArray && other) Q_DECL_NOTHROW : d(other.d) { other.d = Data::sharedNull(); } - inline QByteArray &operator=(QByteArray &&other) Q_DECL_NOTHROW + inline QByteArray(QByteArray && other) noexcept : d(other.d) { other.d = Data::sharedNull(); } + inline QByteArray &operator=(QByteArray &&other) noexcept { qSwap(d, other.d); return *this; } -#endif - inline void swap(QByteArray &other) Q_DECL_NOTHROW + inline void swap(QByteArray &other) noexcept { qSwap(d, other.d); } inline int size() const; @@ -472,7 +470,7 @@ public: Q_DECLARE_OPERATORS_FOR_FLAGS(QByteArray::Base64Options) -inline QByteArray::QByteArray() Q_DECL_NOTHROW : d(Data::sharedNull()) { } +inline QByteArray::QByteArray() noexcept : d(Data::sharedNull()) { } inline QByteArray::~QByteArray() { if (!d->ref.deref()) Data::deallocate(d); } inline int QByteArray::size() const { return d->size; } @@ -502,7 +500,7 @@ inline void QByteArray::detach() { if (d->ref.isShared() || (d->offset != sizeof(QByteArrayData))) reallocData(uint(d->size) + 1u, d->detachFlags()); } inline bool QByteArray::isDetached() const { return !d->ref.isShared(); } -inline QByteArray::QByteArray(const QByteArray &a) Q_DECL_NOTHROW : d(a.d) +inline QByteArray::QByteArray(const QByteArray &a) noexcept : d(a.d) { d->ref.ref(); } inline int QByteArray::capacity() const @@ -617,41 +615,41 @@ inline int QByteArray::compare(const QByteArray &a, Qt::CaseSensitivity cs) cons return cs == Qt::CaseSensitive ? qstrcmp(*this, a) : qstrnicmp(data(), size(), a.data(), a.size()); } -inline bool operator==(const QByteArray &a1, const QByteArray &a2) Q_DECL_NOTHROW +inline bool operator==(const QByteArray &a1, const QByteArray &a2) noexcept { return (a1.size() == a2.size()) && (memcmp(a1.constData(), a2.constData(), a1.size())==0); } -inline bool operator==(const QByteArray &a1, const char *a2) Q_DECL_NOTHROW +inline bool operator==(const QByteArray &a1, const char *a2) noexcept { return a2 ? qstrcmp(a1,a2) == 0 : a1.isEmpty(); } -inline bool operator==(const char *a1, const QByteArray &a2) Q_DECL_NOTHROW +inline bool operator==(const char *a1, const QByteArray &a2) noexcept { return a1 ? qstrcmp(a1,a2) == 0 : a2.isEmpty(); } -inline bool operator!=(const QByteArray &a1, const QByteArray &a2) Q_DECL_NOTHROW +inline bool operator!=(const QByteArray &a1, const QByteArray &a2) noexcept { return !(a1==a2); } -inline bool operator!=(const QByteArray &a1, const char *a2) Q_DECL_NOTHROW +inline bool operator!=(const QByteArray &a1, const char *a2) noexcept { return a2 ? qstrcmp(a1,a2) != 0 : !a1.isEmpty(); } -inline bool operator!=(const char *a1, const QByteArray &a2) Q_DECL_NOTHROW +inline bool operator!=(const char *a1, const QByteArray &a2) noexcept { return a1 ? qstrcmp(a1,a2) != 0 : !a2.isEmpty(); } -inline bool operator<(const QByteArray &a1, const QByteArray &a2) Q_DECL_NOTHROW +inline bool operator<(const QByteArray &a1, const QByteArray &a2) noexcept { return qstrcmp(a1, a2) < 0; } - inline bool operator<(const QByteArray &a1, const char *a2) Q_DECL_NOTHROW + inline bool operator<(const QByteArray &a1, const char *a2) noexcept { return qstrcmp(a1, a2) < 0; } -inline bool operator<(const char *a1, const QByteArray &a2) Q_DECL_NOTHROW +inline bool operator<(const char *a1, const QByteArray &a2) noexcept { return qstrcmp(a1, a2) < 0; } -inline bool operator<=(const QByteArray &a1, const QByteArray &a2) Q_DECL_NOTHROW +inline bool operator<=(const QByteArray &a1, const QByteArray &a2) noexcept { return qstrcmp(a1, a2) <= 0; } -inline bool operator<=(const QByteArray &a1, const char *a2) Q_DECL_NOTHROW +inline bool operator<=(const QByteArray &a1, const char *a2) noexcept { return qstrcmp(a1, a2) <= 0; } -inline bool operator<=(const char *a1, const QByteArray &a2) Q_DECL_NOTHROW +inline bool operator<=(const char *a1, const QByteArray &a2) noexcept { return qstrcmp(a1, a2) <= 0; } -inline bool operator>(const QByteArray &a1, const QByteArray &a2) Q_DECL_NOTHROW +inline bool operator>(const QByteArray &a1, const QByteArray &a2) noexcept { return qstrcmp(a1, a2) > 0; } -inline bool operator>(const QByteArray &a1, const char *a2) Q_DECL_NOTHROW +inline bool operator>(const QByteArray &a1, const char *a2) noexcept { return qstrcmp(a1, a2) > 0; } -inline bool operator>(const char *a1, const QByteArray &a2) Q_DECL_NOTHROW +inline bool operator>(const char *a1, const QByteArray &a2) noexcept { return qstrcmp(a1, a2) > 0; } -inline bool operator>=(const QByteArray &a1, const QByteArray &a2) Q_DECL_NOTHROW +inline bool operator>=(const QByteArray &a1, const QByteArray &a2) noexcept { return qstrcmp(a1, a2) >= 0; } -inline bool operator>=(const QByteArray &a1, const char *a2) Q_DECL_NOTHROW +inline bool operator>=(const QByteArray &a1, const char *a2) noexcept { return qstrcmp(a1, a2) >= 0; } -inline bool operator>=(const char *a1, const QByteArray &a2) Q_DECL_NOTHROW +inline bool operator>=(const char *a1, const QByteArray &a2) noexcept { return qstrcmp(a1, a2) >= 0; } #if !defined(QT_USE_QSTRINGBUILDER) inline const QByteArray operator+(const QByteArray &a1, const QByteArray &a2) diff --git a/src/corelib/tools/qbytearraymatcher.cpp b/src/corelib/tools/qbytearraymatcher.cpp index 72f0e0519d..d2eb4e0e3c 100644 --- a/src/corelib/tools/qbytearraymatcher.cpp +++ b/src/corelib/tools/qbytearraymatcher.cpp @@ -404,7 +404,7 @@ int qFindByteArray( /*! \internal */ -int QStaticByteArrayMatcherBase::indexOfIn(const char *needle, uint nlen, const char *haystack, int hlen, int from) const Q_DECL_NOTHROW +int QStaticByteArrayMatcherBase::indexOfIn(const char *needle, uint nlen, const char *haystack, int hlen, int from) const noexcept { if (from < 0) from = 0; diff --git a/src/corelib/tools/qbytearraymatcher.h b/src/corelib/tools/qbytearraymatcher.h index dafaea9c12..0eedfc1d20 100644 --- a/src/corelib/tools/qbytearraymatcher.h +++ b/src/corelib/tools/qbytearraymatcher.h @@ -90,15 +90,15 @@ class QStaticByteArrayMatcherBase uchar data[256]; } m_skiptable; protected: - explicit Q_DECL_RELAXED_CONSTEXPR QStaticByteArrayMatcherBase(const char *pattern, uint n) Q_DECL_NOTHROW + explicit Q_DECL_RELAXED_CONSTEXPR QStaticByteArrayMatcherBase(const char *pattern, uint n) noexcept : m_skiptable(generate(pattern, n)) {} // compiler-generated copy/more ctors/assignment operators are ok! // compiler-generated dtor is ok! - Q_CORE_EXPORT int indexOfIn(const char *needle, uint nlen, const char *haystack, int hlen, int from) const Q_DECL_NOTHROW; + Q_CORE_EXPORT int indexOfIn(const char *needle, uint nlen, const char *haystack, int hlen, int from) const noexcept; private: - static Q_DECL_RELAXED_CONSTEXPR Skiptable generate(const char *pattern, uint n) Q_DECL_NOTHROW + static Q_DECL_RELAXED_CONSTEXPR Skiptable generate(const char *pattern, uint n) noexcept { const auto uchar_max = (std::numeric_limits<uchar>::max)(); uchar max = n > uchar_max ? uchar_max : n; @@ -140,23 +140,23 @@ class QStaticByteArrayMatcher : QStaticByteArrayMatcherBase char m_pattern[N]; Q_STATIC_ASSERT_X(N > 2, "QStaticByteArrayMatcher makes no sense for finding a single-char pattern"); public: - explicit Q_DECL_RELAXED_CONSTEXPR QStaticByteArrayMatcher(const char (&patternToMatch)[N]) Q_DECL_NOTHROW + explicit Q_DECL_RELAXED_CONSTEXPR QStaticByteArrayMatcher(const char (&patternToMatch)[N]) noexcept : QStaticByteArrayMatcherBase(patternToMatch, N - 1), m_pattern() { for (uint i = 0; i < N; ++i) m_pattern[i] = patternToMatch[i]; } - int indexIn(const QByteArray &haystack, int from = 0) const Q_DECL_NOTHROW + int indexIn(const QByteArray &haystack, int from = 0) const noexcept { return this->indexOfIn(m_pattern, N - 1, haystack.data(), haystack.size(), from); } - int indexIn(const char *haystack, int hlen, int from = 0) const Q_DECL_NOTHROW + int indexIn(const char *haystack, int hlen, int from = 0) const noexcept { return this->indexOfIn(m_pattern, N - 1, haystack, hlen, from); } QByteArray pattern() const { return QByteArray(m_pattern, int(N - 1)); } }; template <uint N> -Q_DECL_RELAXED_CONSTEXPR QStaticByteArrayMatcher<N> qMakeStaticByteArrayMatcher(const char (&pattern)[N]) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR QStaticByteArrayMatcher<N> qMakeStaticByteArrayMatcher(const char (&pattern)[N]) noexcept { return QStaticByteArrayMatcher<N>(pattern); } QT_END_NAMESPACE diff --git a/src/corelib/tools/qcache.h b/src/corelib/tools/qcache.h index 8c0e7860f7..4fcde46fbc 100644 --- a/src/corelib/tools/qcache.h +++ b/src/corelib/tools/qcache.h @@ -51,7 +51,7 @@ class QCache struct Node { inline Node() : keyPtr(0) {} inline Node(T *data, int cost) - : keyPtr(0), t(data), c(cost), p(0), n(0) {} + : keyPtr(nullptr), t(data), c(cost), p(nullptr), n(nullptr) {} const Key *keyPtr; T *t; int c; Node *p,*n; }; Node *f, *l; @@ -71,14 +71,14 @@ class QCache inline T *relink(const Key &key) { typename QHash<Key, Node>::iterator i = hash.find(key); if (typename QHash<Key, Node>::const_iterator(i) == hash.constEnd()) - return 0; + return nullptr; Node &n = *i; if (f != &n) { if (n.p) n.p->n = n.n; if (n.n) n.n->p = n.p; if (l == &n) l = n.p; - n.p = 0; + n.p = nullptr; n.n = f; f->p = &n; f = &n; @@ -89,7 +89,7 @@ class QCache Q_DISABLE_COPY(QCache) public: - inline explicit QCache(int maxCost = 100) Q_DECL_NOTHROW; + inline explicit QCache(int maxCost = 100) noexcept; inline ~QCache() { clear(); } inline int maxCost() const { return mx; } @@ -116,13 +116,13 @@ private: }; template <class Key, class T> -inline QCache<Key, T>::QCache(int amaxCost) Q_DECL_NOTHROW - : f(0), l(0), mx(amaxCost), total(0) {} +inline QCache<Key, T>::QCache(int amaxCost) noexcept + : f(nullptr), l(nullptr), mx(amaxCost), total(0) {} template <class Key, class T> inline void QCache<Key,T>::clear() { while (f) { delete f->t; f = f->n; } - hash.clear(); l = 0; total = 0; } + hash.clear(); l = nullptr; total = 0; } template <class Key, class T> inline void QCache<Key,T>::setMaxCost(int m) @@ -153,11 +153,11 @@ inline T *QCache<Key,T>::take(const Key &key) { typename QHash<Key, Node>::iterator i = hash.find(key); if (i == hash.end()) - return 0; + return nullptr; Node &n = *i; T *t = n.t; - n.t = 0; + n.t = nullptr; unlink(n); return t; } diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp index 47c853084b..d6061defc3 100644 --- a/src/corelib/tools/qchar.cpp +++ b/src/corelib/tools/qchar.cpp @@ -733,7 +733,7 @@ QT_BEGIN_NAMESPACE Note that this gives no indication of whether the character is available in a particular font. */ -bool QChar::isPrint(uint ucs4) Q_DECL_NOTHROW +bool QChar::isPrint(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return false; @@ -766,7 +766,7 @@ bool QChar::isPrint(uint ucs4) Q_DECL_NOTHROW /*! \internal */ -bool QT_FASTCALL QChar::isSpace_helper(uint ucs4) Q_DECL_NOTHROW +bool QT_FASTCALL QChar::isSpace_helper(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return false; @@ -792,7 +792,7 @@ bool QT_FASTCALL QChar::isSpace_helper(uint ucs4) Q_DECL_NOTHROW Returns \c true if the UCS-4-encoded character specified by \a ucs4 is a mark (Mark_* categories); otherwise returns \c false. */ -bool QChar::isMark(uint ucs4) Q_DECL_NOTHROW +bool QChar::isMark(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return false; @@ -816,7 +816,7 @@ bool QChar::isMark(uint ucs4) Q_DECL_NOTHROW Returns \c true if the UCS-4-encoded character specified by \a ucs4 is a punctuation mark (Punctuation_* categories); otherwise returns \c false. */ -bool QChar::isPunct(uint ucs4) Q_DECL_NOTHROW +bool QChar::isPunct(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return false; @@ -844,7 +844,7 @@ bool QChar::isPunct(uint ucs4) Q_DECL_NOTHROW Returns \c true if the UCS-4-encoded character specified by \a ucs4 is a symbol (Symbol_* categories); otherwise returns \c false. */ -bool QChar::isSymbol(uint ucs4) Q_DECL_NOTHROW +bool QChar::isSymbol(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return false; @@ -874,7 +874,7 @@ bool QChar::isSymbol(uint ucs4) Q_DECL_NOTHROW /*! \internal */ -bool QT_FASTCALL QChar::isLetter_helper(uint ucs4) Q_DECL_NOTHROW +bool QT_FASTCALL QChar::isLetter_helper(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return false; @@ -909,7 +909,7 @@ bool QT_FASTCALL QChar::isLetter_helper(uint ucs4) Q_DECL_NOTHROW /*! \internal */ -bool QT_FASTCALL QChar::isNumber_helper(uint ucs4) Q_DECL_NOTHROW +bool QT_FASTCALL QChar::isNumber_helper(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return false; @@ -938,7 +938,7 @@ bool QT_FASTCALL QChar::isNumber_helper(uint ucs4) Q_DECL_NOTHROW /*! \internal */ -bool QT_FASTCALL QChar::isLetterOrNumber_helper(uint ucs4) Q_DECL_NOTHROW +bool QT_FASTCALL QChar::isLetterOrNumber_helper(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return false; @@ -1101,7 +1101,7 @@ bool QT_FASTCALL QChar::isLetterOrNumber_helper(uint ucs4) Q_DECL_NOTHROW Returns the numeric value of the digit specified by the UCS-4-encoded character, \a ucs4, or -1 if the character is not a digit. */ -int QChar::digitValue(uint ucs4) Q_DECL_NOTHROW +int QChar::digitValue(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return -1; @@ -1118,7 +1118,7 @@ int QChar::digitValue(uint ucs4) Q_DECL_NOTHROW \overload Returns the category of the UCS-4-encoded character specified by \a ucs4. */ -QChar::Category QChar::category(uint ucs4) Q_DECL_NOTHROW +QChar::Category QChar::category(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return QChar::Other_NotAssigned; @@ -1135,7 +1135,7 @@ QChar::Category QChar::category(uint ucs4) Q_DECL_NOTHROW \overload Returns the direction of the UCS-4-encoded character specified by \a ucs4. */ -QChar::Direction QChar::direction(uint ucs4) Q_DECL_NOTHROW +QChar::Direction QChar::direction(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return QChar::DirL; @@ -1158,7 +1158,7 @@ QChar::Direction QChar::direction(uint ucs4) Q_DECL_NOTHROW character specified by \a ucs4 (needed for certain languages such as Arabic or Syriac). */ -QChar::JoiningType QChar::joiningType(uint ucs4) Q_DECL_NOTHROW +QChar::JoiningType QChar::joiningType(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return QChar::Joining_None; @@ -1181,7 +1181,7 @@ QChar::JoiningType QChar::joiningType(uint ucs4) Q_DECL_NOTHROW Returns information about the joining properties of the UCS-4-encoded character specified by \a ucs4 (needed for certain languages such as Arabic). */ -QChar::Joining QChar::joining(uint ucs4) Q_DECL_NOTHROW +QChar::Joining QChar::joining(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return QChar::OtherJoining; @@ -1217,7 +1217,7 @@ QChar::Joining QChar::joining(uint ucs4) Q_DECL_NOTHROW \sa mirroredChar() */ -bool QChar::hasMirrored(uint ucs4) Q_DECL_NOTHROW +bool QChar::hasMirrored(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return false; @@ -1299,7 +1299,7 @@ bool QChar::hasMirrored(uint ucs4) Q_DECL_NOTHROW \sa hasMirrored() */ -uint QChar::mirroredChar(uint ucs4) Q_DECL_NOTHROW +uint QChar::mirroredChar(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return ucs4; @@ -1383,7 +1383,7 @@ QString QChar::decomposition(uint ucs4) Returns the tag defining the composition of the UCS-4-encoded character specified by \a ucs4. Returns QChar::NoDecomposition if no decomposition exists. */ -QChar::Decomposition QChar::decompositionTag(uint ucs4) Q_DECL_NOTHROW +QChar::Decomposition QChar::decompositionTag(uint ucs4) noexcept { if (ucs4 >= Hangul_SBase && ucs4 < Hangul_SBase + Hangul_SCount) return QChar::Canonical; @@ -1409,7 +1409,7 @@ QChar::Decomposition QChar::decompositionTag(uint ucs4) Q_DECL_NOTHROW Returns the combining class for the UCS-4-encoded character specified by \a ucs4, as defined in the Unicode standard. */ -unsigned char QChar::combiningClass(uint ucs4) Q_DECL_NOTHROW +unsigned char QChar::combiningClass(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return 0; @@ -1430,7 +1430,7 @@ unsigned char QChar::combiningClass(uint ucs4) Q_DECL_NOTHROW Returns the Unicode script property value for the character specified in its UCS-4-encoded form as \a ucs4. */ -QChar::Script QChar::script(uint ucs4) Q_DECL_NOTHROW +QChar::Script QChar::script(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return QChar::Script_Unknown; @@ -1448,7 +1448,7 @@ QChar::Script QChar::script(uint ucs4) Q_DECL_NOTHROW Returns the Unicode version that introduced the character specified in its UCS-4-encoded form as \a ucs4. */ -QChar::UnicodeVersion QChar::unicodeVersion(uint ucs4) Q_DECL_NOTHROW +QChar::UnicodeVersion QChar::unicodeVersion(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return QChar::Unicode_Unassigned; @@ -1458,14 +1458,14 @@ QChar::UnicodeVersion QChar::unicodeVersion(uint ucs4) Q_DECL_NOTHROW /*! Returns the most recent supported Unicode version. */ -QChar::UnicodeVersion QChar::currentUnicodeVersion() Q_DECL_NOTHROW +QChar::UnicodeVersion QChar::currentUnicodeVersion() noexcept { return UNICODE_DATA_VERSION; } template <typename Traits, typename T> -Q_DECL_CONST_FUNCTION static inline T convertCase_helper(T uc) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION static inline T convertCase_helper(T uc) noexcept { const QUnicodeTables::Properties *prop = qGetProp(uc); @@ -1491,7 +1491,7 @@ Q_DECL_CONST_FUNCTION static inline T convertCase_helper(T uc) Q_DECL_NOTHROW by \a ucs4 if the character is uppercase or titlecase; otherwise returns the character itself. */ -uint QChar::toLower(uint ucs4) Q_DECL_NOTHROW +uint QChar::toLower(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return ucs4; @@ -1511,7 +1511,7 @@ uint QChar::toLower(uint ucs4) Q_DECL_NOTHROW by \a ucs4 if the character is lowercase or titlecase; otherwise returns the character itself. */ -uint QChar::toUpper(uint ucs4) Q_DECL_NOTHROW +uint QChar::toUpper(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return ucs4; @@ -1531,7 +1531,7 @@ uint QChar::toUpper(uint ucs4) Q_DECL_NOTHROW by \a ucs4 if the character is lowercase or uppercase; otherwise returns the character itself. */ -uint QChar::toTitleCase(uint ucs4) Q_DECL_NOTHROW +uint QChar::toTitleCase(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return ucs4; @@ -1546,7 +1546,7 @@ static inline uint foldCase(const ushort *ch, const ushort *start) return convertCase_helper<QUnicodeTables::CasefoldTraits>(ucs4); } -static inline uint foldCase(uint ch, uint &last) Q_DECL_NOTHROW +static inline uint foldCase(uint ch, uint &last) noexcept { uint ucs4 = ch; if (QChar::isLowSurrogate(ucs4) && QChar::isHighSurrogate(last)) @@ -1555,12 +1555,12 @@ static inline uint foldCase(uint ch, uint &last) Q_DECL_NOTHROW return convertCase_helper<QUnicodeTables::CasefoldTraits>(ucs4); } -static inline ushort foldCase(ushort ch) Q_DECL_NOTHROW +static inline ushort foldCase(ushort ch) noexcept { return convertCase_helper<QUnicodeTables::CasefoldTraits>(ch); } -static inline QChar foldCase(QChar ch) Q_DECL_NOTHROW +static inline QChar foldCase(QChar ch) noexcept { return QChar(foldCase(ch.unicode())); } @@ -1577,7 +1577,7 @@ static inline QChar foldCase(QChar ch) Q_DECL_NOTHROW Returns the case folded equivalent of the UCS-4-encoded character specified by \a ucs4. For most Unicode characters this is the same as toLower(). */ -uint QChar::toCaseFolded(uint ucs4) Q_DECL_NOTHROW +uint QChar::toCaseFolded(uint ucs4) noexcept { if (ucs4 > LastValidCodePoint) return ucs4; diff --git a/src/corelib/tools/qchar.h b/src/corelib/tools/qchar.h index 8590b91ba3..be344838ed 100644 --- a/src/corelib/tools/qchar.h +++ b/src/corelib/tools/qchar.h @@ -50,9 +50,9 @@ class QString; struct QLatin1Char { public: - Q_DECL_CONSTEXPR inline explicit QLatin1Char(char c) Q_DECL_NOTHROW : ch(c) {} - Q_DECL_CONSTEXPR inline char toLatin1() const Q_DECL_NOTHROW { return ch; } - Q_DECL_CONSTEXPR inline ushort unicode() const Q_DECL_NOTHROW { return ushort(uchar(ch)); } + Q_DECL_CONSTEXPR inline explicit QLatin1Char(char c) noexcept : ch(c) {} + Q_DECL_CONSTEXPR inline char toLatin1() const noexcept { return ch; } + Q_DECL_CONSTEXPR inline ushort unicode() const noexcept { return ushort(uchar(ch)); } private: char ch; @@ -78,30 +78,30 @@ public: LastValidCodePoint = 0x10ffff }; - Q_DECL_CONSTEXPR QChar() Q_DECL_NOTHROW : ucs(0) {} - Q_DECL_CONSTEXPR QChar(ushort rc) Q_DECL_NOTHROW : ucs(rc) {} // implicit - Q_DECL_CONSTEXPR QChar(uchar c, uchar r) Q_DECL_NOTHROW : ucs(ushort((r << 8) | c)) {} - Q_DECL_CONSTEXPR QChar(short rc) Q_DECL_NOTHROW : ucs(ushort(rc)) {} // implicit - Q_DECL_CONSTEXPR QChar(uint rc) Q_DECL_NOTHROW : ucs(ushort(rc & 0xffff)) {} - Q_DECL_CONSTEXPR QChar(int rc) Q_DECL_NOTHROW : ucs(ushort(rc & 0xffff)) {} - Q_DECL_CONSTEXPR QChar(SpecialCharacter s) Q_DECL_NOTHROW : ucs(ushort(s)) {} // implicit - Q_DECL_CONSTEXPR QChar(QLatin1Char ch) Q_DECL_NOTHROW : ucs(ch.unicode()) {} // implicit + Q_DECL_CONSTEXPR QChar() noexcept : ucs(0) {} + Q_DECL_CONSTEXPR QChar(ushort rc) noexcept : ucs(rc) {} // implicit + Q_DECL_CONSTEXPR QChar(uchar c, uchar r) noexcept : ucs(ushort((r << 8) | c)) {} + Q_DECL_CONSTEXPR QChar(short rc) noexcept : ucs(ushort(rc)) {} // implicit + Q_DECL_CONSTEXPR QChar(uint rc) noexcept : ucs(ushort(rc & 0xffff)) {} + Q_DECL_CONSTEXPR QChar(int rc) noexcept : ucs(ushort(rc & 0xffff)) {} + Q_DECL_CONSTEXPR QChar(SpecialCharacter s) noexcept : ucs(ushort(s)) {} // implicit + Q_DECL_CONSTEXPR QChar(QLatin1Char ch) noexcept : ucs(ch.unicode()) {} // implicit #if defined(Q_COMPILER_UNICODE_STRINGS) - Q_DECL_CONSTEXPR QChar(char16_t ch) Q_DECL_NOTHROW : ucs(ushort(ch)) {} // implicit + Q_DECL_CONSTEXPR QChar(char16_t ch) noexcept : ucs(ushort(ch)) {} // implicit #endif #if defined(Q_OS_WIN) Q_STATIC_ASSERT(sizeof(wchar_t) == sizeof(ushort)); #endif #if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC) # if !defined(_WCHAR_T_DEFINED) || defined(_NATIVE_WCHAR_T_DEFINED) - Q_DECL_CONSTEXPR QChar(wchar_t ch) Q_DECL_NOTHROW : ucs(ushort(ch)) {} // implicit + Q_DECL_CONSTEXPR QChar(wchar_t ch) noexcept : ucs(ushort(ch)) {} // implicit # endif #endif #ifndef QT_NO_CAST_FROM_ASCII - QT_ASCII_CAST_WARN Q_DECL_CONSTEXPR explicit QChar(char c) Q_DECL_NOTHROW : ucs(uchar(c)) { } + QT_ASCII_CAST_WARN Q_DECL_CONSTEXPR explicit QChar(char c) noexcept : ucs(uchar(c)) { } #ifndef QT_RESTRICTED_CAST_FROM_ASCII - QT_ASCII_CAST_WARN Q_DECL_CONSTEXPR explicit QChar(uchar c) Q_DECL_NOTHROW : ucs(c) { } + QT_ASCII_CAST_WARN Q_DECL_CONSTEXPR explicit QChar(uchar c) noexcept : ucs(c) { } #endif #endif // Unicode information @@ -411,11 +411,11 @@ public: }; // ****** WHEN ADDING FUNCTIONS, CONSIDER ADDING TO QCharRef TOO - inline Category category() const Q_DECL_NOTHROW { return QChar::category(ucs); } - inline Direction direction() const Q_DECL_NOTHROW { return QChar::direction(ucs); } - inline JoiningType joiningType() const Q_DECL_NOTHROW { return QChar::joiningType(ucs); } + inline Category category() const noexcept { return QChar::category(ucs); } + inline Direction direction() const noexcept { return QChar::direction(ucs); } + inline JoiningType joiningType() const noexcept { return QChar::joiningType(ucs); } #if QT_DEPRECATED_SINCE(5, 3) - QT_DEPRECATED inline Joining joining() const Q_DECL_NOTHROW + QT_DEPRECATED inline Joining joining() const noexcept { switch (QChar::joiningType(ucs)) { case QChar::Joining_Causing: return QChar::Center; @@ -428,198 +428,198 @@ public: } } #endif - inline unsigned char combiningClass() const Q_DECL_NOTHROW { return QChar::combiningClass(ucs); } + inline unsigned char combiningClass() const noexcept { return QChar::combiningClass(ucs); } - inline QChar mirroredChar() const Q_DECL_NOTHROW { return QChar::mirroredChar(ucs); } - inline bool hasMirrored() const Q_DECL_NOTHROW { return QChar::hasMirrored(ucs); } + inline QChar mirroredChar() const noexcept { return QChar::mirroredChar(ucs); } + inline bool hasMirrored() const noexcept { return QChar::hasMirrored(ucs); } QString decomposition() const; - inline Decomposition decompositionTag() const Q_DECL_NOTHROW { return QChar::decompositionTag(ucs); } + inline Decomposition decompositionTag() const noexcept { return QChar::decompositionTag(ucs); } - inline int digitValue() const Q_DECL_NOTHROW { return QChar::digitValue(ucs); } - inline QChar toLower() const Q_DECL_NOTHROW { return QChar::toLower(ucs); } - inline QChar toUpper() const Q_DECL_NOTHROW { return QChar::toUpper(ucs); } - inline QChar toTitleCase() const Q_DECL_NOTHROW { return QChar::toTitleCase(ucs); } - inline QChar toCaseFolded() const Q_DECL_NOTHROW { return QChar::toCaseFolded(ucs); } + inline int digitValue() const noexcept { return QChar::digitValue(ucs); } + inline QChar toLower() const noexcept { return QChar::toLower(ucs); } + inline QChar toUpper() const noexcept { return QChar::toUpper(ucs); } + inline QChar toTitleCase() const noexcept { return QChar::toTitleCase(ucs); } + inline QChar toCaseFolded() const noexcept { return QChar::toCaseFolded(ucs); } - inline Script script() const Q_DECL_NOTHROW { return QChar::script(ucs); } + inline Script script() const noexcept { return QChar::script(ucs); } - inline UnicodeVersion unicodeVersion() const Q_DECL_NOTHROW { return QChar::unicodeVersion(ucs); } + inline UnicodeVersion unicodeVersion() const noexcept { return QChar::unicodeVersion(ucs); } #if QT_DEPRECATED_SINCE(5, 0) - QT_DEPRECATED Q_DECL_CONSTEXPR inline char toAscii() const Q_DECL_NOTHROW { return toLatin1(); } + QT_DEPRECATED Q_DECL_CONSTEXPR inline char toAscii() const noexcept { return toLatin1(); } #endif - Q_DECL_CONSTEXPR inline char toLatin1() const Q_DECL_NOTHROW { return ucs > 0xff ? '\0' : char(ucs); } - Q_DECL_CONSTEXPR inline ushort unicode() const Q_DECL_NOTHROW { return ucs; } - Q_DECL_RELAXED_CONSTEXPR inline ushort &unicode() Q_DECL_NOTHROW { return ucs; } + Q_DECL_CONSTEXPR inline char toLatin1() const noexcept { return ucs > 0xff ? '\0' : char(ucs); } + Q_DECL_CONSTEXPR inline ushort unicode() const noexcept { return ucs; } + Q_DECL_RELAXED_CONSTEXPR inline ushort &unicode() noexcept { return ucs; } #if QT_DEPRECATED_SINCE(5, 0) - QT_DEPRECATED static Q_DECL_CONSTEXPR inline QChar fromAscii(char c) Q_DECL_NOTHROW + QT_DEPRECATED static Q_DECL_CONSTEXPR inline QChar fromAscii(char c) noexcept { return fromLatin1(c); } #endif - static Q_DECL_CONSTEXPR inline QChar fromLatin1(char c) Q_DECL_NOTHROW { return QChar(ushort(uchar(c))); } - - Q_DECL_CONSTEXPR inline bool isNull() const Q_DECL_NOTHROW { return ucs == 0; } - - inline bool isPrint() const Q_DECL_NOTHROW { return QChar::isPrint(ucs); } - Q_DECL_CONSTEXPR inline bool isSpace() const Q_DECL_NOTHROW { return QChar::isSpace(ucs); } - inline bool isMark() const Q_DECL_NOTHROW { return QChar::isMark(ucs); } - inline bool isPunct() const Q_DECL_NOTHROW { return QChar::isPunct(ucs); } - inline bool isSymbol() const Q_DECL_NOTHROW { return QChar::isSymbol(ucs); } - Q_DECL_CONSTEXPR inline bool isLetter() const Q_DECL_NOTHROW { return QChar::isLetter(ucs); } - Q_DECL_CONSTEXPR inline bool isNumber() const Q_DECL_NOTHROW { return QChar::isNumber(ucs); } - Q_DECL_CONSTEXPR inline bool isLetterOrNumber() const Q_DECL_NOTHROW { return QChar::isLetterOrNumber(ucs); } - Q_DECL_CONSTEXPR inline bool isDigit() const Q_DECL_NOTHROW { return QChar::isDigit(ucs); } - Q_DECL_CONSTEXPR inline bool isLower() const Q_DECL_NOTHROW { return QChar::isLower(ucs); } - Q_DECL_CONSTEXPR inline bool isUpper() const Q_DECL_NOTHROW { return QChar::isUpper(ucs); } - Q_DECL_CONSTEXPR inline bool isTitleCase() const Q_DECL_NOTHROW { return QChar::isTitleCase(ucs); } - - Q_DECL_CONSTEXPR inline bool isNonCharacter() const Q_DECL_NOTHROW { return QChar::isNonCharacter(ucs); } - Q_DECL_CONSTEXPR inline bool isHighSurrogate() const Q_DECL_NOTHROW { return QChar::isHighSurrogate(ucs); } - Q_DECL_CONSTEXPR inline bool isLowSurrogate() const Q_DECL_NOTHROW { return QChar::isLowSurrogate(ucs); } - Q_DECL_CONSTEXPR inline bool isSurrogate() const Q_DECL_NOTHROW { return QChar::isSurrogate(ucs); } - - Q_DECL_CONSTEXPR inline uchar cell() const Q_DECL_NOTHROW { return uchar(ucs & 0xff); } - Q_DECL_CONSTEXPR inline uchar row() const Q_DECL_NOTHROW { return uchar((ucs>>8)&0xff); } - Q_DECL_RELAXED_CONSTEXPR inline void setCell(uchar acell) Q_DECL_NOTHROW { ucs = ushort((ucs & 0xff00) + acell); } - Q_DECL_RELAXED_CONSTEXPR inline void setRow(uchar arow) Q_DECL_NOTHROW { ucs = ushort((ushort(arow)<<8) + (ucs&0xff)); } - - static Q_DECL_CONSTEXPR inline bool isNonCharacter(uint ucs4) Q_DECL_NOTHROW + static Q_DECL_CONSTEXPR inline QChar fromLatin1(char c) noexcept { return QChar(ushort(uchar(c))); } + + Q_DECL_CONSTEXPR inline bool isNull() const noexcept { return ucs == 0; } + + inline bool isPrint() const noexcept { return QChar::isPrint(ucs); } + Q_DECL_CONSTEXPR inline bool isSpace() const noexcept { return QChar::isSpace(ucs); } + inline bool isMark() const noexcept { return QChar::isMark(ucs); } + inline bool isPunct() const noexcept { return QChar::isPunct(ucs); } + inline bool isSymbol() const noexcept { return QChar::isSymbol(ucs); } + Q_DECL_CONSTEXPR inline bool isLetter() const noexcept { return QChar::isLetter(ucs); } + Q_DECL_CONSTEXPR inline bool isNumber() const noexcept { return QChar::isNumber(ucs); } + Q_DECL_CONSTEXPR inline bool isLetterOrNumber() const noexcept { return QChar::isLetterOrNumber(ucs); } + Q_DECL_CONSTEXPR inline bool isDigit() const noexcept { return QChar::isDigit(ucs); } + Q_DECL_CONSTEXPR inline bool isLower() const noexcept { return QChar::isLower(ucs); } + Q_DECL_CONSTEXPR inline bool isUpper() const noexcept { return QChar::isUpper(ucs); } + Q_DECL_CONSTEXPR inline bool isTitleCase() const noexcept { return QChar::isTitleCase(ucs); } + + Q_DECL_CONSTEXPR inline bool isNonCharacter() const noexcept { return QChar::isNonCharacter(ucs); } + Q_DECL_CONSTEXPR inline bool isHighSurrogate() const noexcept { return QChar::isHighSurrogate(ucs); } + Q_DECL_CONSTEXPR inline bool isLowSurrogate() const noexcept { return QChar::isLowSurrogate(ucs); } + Q_DECL_CONSTEXPR inline bool isSurrogate() const noexcept { return QChar::isSurrogate(ucs); } + + Q_DECL_CONSTEXPR inline uchar cell() const noexcept { return uchar(ucs & 0xff); } + Q_DECL_CONSTEXPR inline uchar row() const noexcept { return uchar((ucs>>8)&0xff); } + Q_DECL_RELAXED_CONSTEXPR inline void setCell(uchar acell) noexcept { ucs = ushort((ucs & 0xff00) + acell); } + Q_DECL_RELAXED_CONSTEXPR inline void setRow(uchar arow) noexcept { ucs = ushort((ushort(arow)<<8) + (ucs&0xff)); } + + static Q_DECL_CONSTEXPR inline bool isNonCharacter(uint ucs4) noexcept { return ucs4 >= 0xfdd0 && (ucs4 <= 0xfdef || (ucs4 & 0xfffe) == 0xfffe); } - static Q_DECL_CONSTEXPR inline bool isHighSurrogate(uint ucs4) Q_DECL_NOTHROW + static Q_DECL_CONSTEXPR inline bool isHighSurrogate(uint ucs4) noexcept { return ((ucs4 & 0xfffffc00) == 0xd800); } - static Q_DECL_CONSTEXPR inline bool isLowSurrogate(uint ucs4) Q_DECL_NOTHROW + static Q_DECL_CONSTEXPR inline bool isLowSurrogate(uint ucs4) noexcept { return ((ucs4 & 0xfffffc00) == 0xdc00); } - static Q_DECL_CONSTEXPR inline bool isSurrogate(uint ucs4) Q_DECL_NOTHROW + static Q_DECL_CONSTEXPR inline bool isSurrogate(uint ucs4) noexcept { return (ucs4 - 0xd800u < 2048u); } - static Q_DECL_CONSTEXPR inline bool requiresSurrogates(uint ucs4) Q_DECL_NOTHROW + static Q_DECL_CONSTEXPR inline bool requiresSurrogates(uint ucs4) noexcept { return (ucs4 >= 0x10000); } - static Q_DECL_CONSTEXPR inline uint surrogateToUcs4(ushort high, ushort low) Q_DECL_NOTHROW + static Q_DECL_CONSTEXPR inline uint surrogateToUcs4(ushort high, ushort low) noexcept { return (uint(high)<<10) + low - 0x35fdc00; } - static Q_DECL_CONSTEXPR inline uint surrogateToUcs4(QChar high, QChar low) Q_DECL_NOTHROW + static Q_DECL_CONSTEXPR inline uint surrogateToUcs4(QChar high, QChar low) noexcept { return surrogateToUcs4(high.ucs, low.ucs); } - static Q_DECL_CONSTEXPR inline ushort highSurrogate(uint ucs4) Q_DECL_NOTHROW + static Q_DECL_CONSTEXPR inline ushort highSurrogate(uint ucs4) noexcept { return ushort((ucs4>>10) + 0xd7c0); } - static Q_DECL_CONSTEXPR inline ushort lowSurrogate(uint ucs4) Q_DECL_NOTHROW + static Q_DECL_CONSTEXPR inline ushort lowSurrogate(uint ucs4) noexcept { return ushort(ucs4%0x400 + 0xdc00); } - static Category QT_FASTCALL category(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; - static Direction QT_FASTCALL direction(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; - static JoiningType QT_FASTCALL joiningType(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; + static Category QT_FASTCALL category(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; + static Direction QT_FASTCALL direction(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; + static JoiningType QT_FASTCALL joiningType(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; #if QT_DEPRECATED_SINCE(5, 3) - QT_DEPRECATED static Joining QT_FASTCALL joining(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; + QT_DEPRECATED static Joining QT_FASTCALL joining(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; #endif - static unsigned char QT_FASTCALL combiningClass(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; + static unsigned char QT_FASTCALL combiningClass(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; - static uint QT_FASTCALL mirroredChar(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; - static bool QT_FASTCALL hasMirrored(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; + static uint QT_FASTCALL mirroredChar(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; + static bool QT_FASTCALL hasMirrored(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; static QString QT_FASTCALL decomposition(uint ucs4); - static Decomposition QT_FASTCALL decompositionTag(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; + static Decomposition QT_FASTCALL decompositionTag(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; - static int QT_FASTCALL digitValue(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; - static uint QT_FASTCALL toLower(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; - static uint QT_FASTCALL toUpper(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; - static uint QT_FASTCALL toTitleCase(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; - static uint QT_FASTCALL toCaseFolded(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; + static int QT_FASTCALL digitValue(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; + static uint QT_FASTCALL toLower(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; + static uint QT_FASTCALL toUpper(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; + static uint QT_FASTCALL toTitleCase(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; + static uint QT_FASTCALL toCaseFolded(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; - static Script QT_FASTCALL script(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; + static Script QT_FASTCALL script(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; - static UnicodeVersion QT_FASTCALL unicodeVersion(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; + static UnicodeVersion QT_FASTCALL unicodeVersion(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; - static UnicodeVersion QT_FASTCALL currentUnicodeVersion() Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; + static UnicodeVersion QT_FASTCALL currentUnicodeVersion() noexcept Q_DECL_CONST_FUNCTION; - static bool QT_FASTCALL isPrint(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; - static Q_DECL_CONSTEXPR inline bool isSpace(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION + static bool QT_FASTCALL isPrint(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; + static Q_DECL_CONSTEXPR inline bool isSpace(uint ucs4) noexcept Q_DECL_CONST_FUNCTION { // note that [0x09..0x0d] + 0x85 are exceptional Cc-s and must be handled explicitly return ucs4 == 0x20 || (ucs4 <= 0x0d && ucs4 >= 0x09) || (ucs4 > 127 && (ucs4 == 0x85 || ucs4 == 0xa0 || QChar::isSpace_helper(ucs4))); } - static bool QT_FASTCALL isMark(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; - static bool QT_FASTCALL isPunct(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; - static bool QT_FASTCALL isSymbol(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; - static Q_DECL_CONSTEXPR inline bool isLetter(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION + static bool QT_FASTCALL isMark(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; + static bool QT_FASTCALL isPunct(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; + static bool QT_FASTCALL isSymbol(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; + static Q_DECL_CONSTEXPR inline bool isLetter(uint ucs4) noexcept Q_DECL_CONST_FUNCTION { return (ucs4 >= 'A' && ucs4 <= 'z' && (ucs4 >= 'a' || ucs4 <= 'Z')) || (ucs4 > 127 && QChar::isLetter_helper(ucs4)); } - static Q_DECL_CONSTEXPR inline bool isNumber(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION + static Q_DECL_CONSTEXPR inline bool isNumber(uint ucs4) noexcept Q_DECL_CONST_FUNCTION { return (ucs4 <= '9' && ucs4 >= '0') || (ucs4 > 127 && QChar::isNumber_helper(ucs4)); } - static Q_DECL_CONSTEXPR inline bool isLetterOrNumber(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION + static Q_DECL_CONSTEXPR inline bool isLetterOrNumber(uint ucs4) noexcept Q_DECL_CONST_FUNCTION { return (ucs4 >= 'A' && ucs4 <= 'z' && (ucs4 >= 'a' || ucs4 <= 'Z')) || (ucs4 >= '0' && ucs4 <= '9') || (ucs4 > 127 && QChar::isLetterOrNumber_helper(ucs4)); } - static Q_DECL_CONSTEXPR inline bool isDigit(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION + static Q_DECL_CONSTEXPR inline bool isDigit(uint ucs4) noexcept Q_DECL_CONST_FUNCTION { return (ucs4 <= '9' && ucs4 >= '0') || (ucs4 > 127 && QChar::category(ucs4) == Number_DecimalDigit); } - static Q_DECL_CONSTEXPR inline bool isLower(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION + static Q_DECL_CONSTEXPR inline bool isLower(uint ucs4) noexcept Q_DECL_CONST_FUNCTION { return (ucs4 <= 'z' && ucs4 >= 'a') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Lowercase); } - static Q_DECL_CONSTEXPR inline bool isUpper(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION + static Q_DECL_CONSTEXPR inline bool isUpper(uint ucs4) noexcept Q_DECL_CONST_FUNCTION { return (ucs4 <= 'Z' && ucs4 >= 'A') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Uppercase); } - static Q_DECL_CONSTEXPR inline bool isTitleCase(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION + static Q_DECL_CONSTEXPR inline bool isTitleCase(uint ucs4) noexcept Q_DECL_CONST_FUNCTION { return ucs4 > 127 && QChar::category(ucs4) == Letter_Titlecase; } private: - static bool QT_FASTCALL isSpace_helper(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; - static bool QT_FASTCALL isLetter_helper(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; - static bool QT_FASTCALL isNumber_helper(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; - static bool QT_FASTCALL isLetterOrNumber_helper(uint ucs4) Q_DECL_NOTHROW Q_DECL_CONST_FUNCTION; + static bool QT_FASTCALL isSpace_helper(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; + static bool QT_FASTCALL isLetter_helper(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; + static bool QT_FASTCALL isNumber_helper(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; + static bool QT_FASTCALL isLetterOrNumber_helper(uint ucs4) noexcept Q_DECL_CONST_FUNCTION; #ifdef QT_NO_CAST_FROM_ASCII - QChar(char c) Q_DECL_NOTHROW; - QChar(uchar c) Q_DECL_NOTHROW; + QChar(char c) noexcept; + QChar(uchar c) noexcept; #endif - friend Q_DECL_CONSTEXPR bool operator==(QChar, QChar) Q_DECL_NOTHROW; - friend Q_DECL_CONSTEXPR bool operator< (QChar, QChar) Q_DECL_NOTHROW; + friend Q_DECL_CONSTEXPR bool operator==(QChar, QChar) noexcept; + friend Q_DECL_CONSTEXPR bool operator< (QChar, QChar) noexcept; ushort ucs; }; Q_DECLARE_TYPEINFO(QChar, Q_MOVABLE_TYPE); -Q_DECL_CONSTEXPR inline bool operator==(QChar c1, QChar c2) Q_DECL_NOTHROW { return c1.ucs == c2.ucs; } -Q_DECL_CONSTEXPR inline bool operator< (QChar c1, QChar c2) Q_DECL_NOTHROW { return c1.ucs < c2.ucs; } +Q_DECL_CONSTEXPR inline bool operator==(QChar c1, QChar c2) noexcept { return c1.ucs == c2.ucs; } +Q_DECL_CONSTEXPR inline bool operator< (QChar c1, QChar c2) noexcept { return c1.ucs < c2.ucs; } -Q_DECL_CONSTEXPR inline bool operator!=(QChar c1, QChar c2) Q_DECL_NOTHROW { return !operator==(c1, c2); } -Q_DECL_CONSTEXPR inline bool operator>=(QChar c1, QChar c2) Q_DECL_NOTHROW { return !operator< (c1, c2); } -Q_DECL_CONSTEXPR inline bool operator> (QChar c1, QChar c2) Q_DECL_NOTHROW { return operator< (c2, c1); } -Q_DECL_CONSTEXPR inline bool operator<=(QChar c1, QChar c2) Q_DECL_NOTHROW { return !operator< (c2, c1); } +Q_DECL_CONSTEXPR inline bool operator!=(QChar c1, QChar c2) noexcept { return !operator==(c1, c2); } +Q_DECL_CONSTEXPR inline bool operator>=(QChar c1, QChar c2) noexcept { return !operator< (c1, c2); } +Q_DECL_CONSTEXPR inline bool operator> (QChar c1, QChar c2) noexcept { return operator< (c2, c1); } +Q_DECL_CONSTEXPR inline bool operator<=(QChar c1, QChar c2) noexcept { return !operator< (c2, c1); } -Q_DECL_CONSTEXPR inline bool operator==(QChar lhs, std::nullptr_t) Q_DECL_NOTHROW { return lhs.isNull(); } -Q_DECL_CONSTEXPR inline bool operator< (QChar, std::nullptr_t) Q_DECL_NOTHROW { return false; } -Q_DECL_CONSTEXPR inline bool operator==(std::nullptr_t, QChar rhs) Q_DECL_NOTHROW { return rhs.isNull(); } -Q_DECL_CONSTEXPR inline bool operator< (std::nullptr_t, QChar rhs) Q_DECL_NOTHROW { return !rhs.isNull(); } +Q_DECL_CONSTEXPR inline bool operator==(QChar lhs, std::nullptr_t) noexcept { return lhs.isNull(); } +Q_DECL_CONSTEXPR inline bool operator< (QChar, std::nullptr_t) noexcept { return false; } +Q_DECL_CONSTEXPR inline bool operator==(std::nullptr_t, QChar rhs) noexcept { return rhs.isNull(); } +Q_DECL_CONSTEXPR inline bool operator< (std::nullptr_t, QChar rhs) noexcept { return !rhs.isNull(); } -Q_DECL_CONSTEXPR inline bool operator!=(QChar lhs, std::nullptr_t) Q_DECL_NOTHROW { return !operator==(lhs, nullptr); } -Q_DECL_CONSTEXPR inline bool operator>=(QChar lhs, std::nullptr_t) Q_DECL_NOTHROW { return !operator< (lhs, nullptr); } -Q_DECL_CONSTEXPR inline bool operator> (QChar lhs, std::nullptr_t) Q_DECL_NOTHROW { return operator< (nullptr, lhs); } -Q_DECL_CONSTEXPR inline bool operator<=(QChar lhs, std::nullptr_t) Q_DECL_NOTHROW { return !operator< (nullptr, lhs); } +Q_DECL_CONSTEXPR inline bool operator!=(QChar lhs, std::nullptr_t) noexcept { return !operator==(lhs, nullptr); } +Q_DECL_CONSTEXPR inline bool operator>=(QChar lhs, std::nullptr_t) noexcept { return !operator< (lhs, nullptr); } +Q_DECL_CONSTEXPR inline bool operator> (QChar lhs, std::nullptr_t) noexcept { return operator< (nullptr, lhs); } +Q_DECL_CONSTEXPR inline bool operator<=(QChar lhs, std::nullptr_t) noexcept { return !operator< (nullptr, lhs); } -Q_DECL_CONSTEXPR inline bool operator!=(std::nullptr_t, QChar rhs) Q_DECL_NOTHROW { return !operator==(nullptr, rhs); } -Q_DECL_CONSTEXPR inline bool operator>=(std::nullptr_t, QChar rhs) Q_DECL_NOTHROW { return !operator< (nullptr, rhs); } -Q_DECL_CONSTEXPR inline bool operator> (std::nullptr_t, QChar rhs) Q_DECL_NOTHROW { return operator< (rhs, nullptr); } -Q_DECL_CONSTEXPR inline bool operator<=(std::nullptr_t, QChar rhs) Q_DECL_NOTHROW { return !operator< (rhs, nullptr); } +Q_DECL_CONSTEXPR inline bool operator!=(std::nullptr_t, QChar rhs) noexcept { return !operator==(nullptr, rhs); } +Q_DECL_CONSTEXPR inline bool operator>=(std::nullptr_t, QChar rhs) noexcept { return !operator< (nullptr, rhs); } +Q_DECL_CONSTEXPR inline bool operator> (std::nullptr_t, QChar rhs) noexcept { return operator< (rhs, nullptr); } +Q_DECL_CONSTEXPR inline bool operator<=(std::nullptr_t, QChar rhs) noexcept { return !operator< (rhs, nullptr); } #ifndef QT_NO_DATASTREAM Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, QChar); diff --git a/src/corelib/tools/qcollator.cpp b/src/corelib/tools/qcollator.cpp index 76dcf35833..6e85027462 100644 --- a/src/corelib/tools/qcollator.cpp +++ b/src/corelib/tools/qcollator.cpp @@ -46,7 +46,6 @@ QT_BEGIN_NAMESPACE - /*! \class QCollator \inmodule QtCore @@ -59,20 +58,32 @@ QT_BEGIN_NAMESPACE \ingroup string-processing \ingroup shared - QCollator is initialized with a QLocale and an optional collation strategy. It tries to - initialize the collator with the specified values. The collator can then be used to compare - and sort strings in a locale dependent fashion. + QCollator is initialized with a QLocale and an optional collation strategy. + It tries to initialize the collator with the specified values. The collator + can then be used to compare and sort strings in a locale dependent fashion. - A QCollator object can be used together with template based sorting algorithms such as std::sort - to sort a list of QStrings. + A QCollator object can be used together with template based sorting + algorithms such as std::sort to sort a list of QStrings. - In addition to the locale and collation strategy, several optional flags can be set that influence - the result of the collation. + In addition to the locale and collation strategy, several optional flags can + be set that influence the result of the collation. */ /*! - Constructs a QCollator from \a locale. If \a locale is not specified - the system's default locale is used. + \since 5.13 + + Constructs a QCollator using the system's default collation locale. + + \sa setLocale(), QLocale::collation() +*/ +QCollator::QCollator() + : d(new QCollatorPrivate(QLocale::system().collation())) +{ + d->init(); +} + +/*! + Constructs a QCollator from \a locale. \sa setLocale() */ @@ -128,9 +139,9 @@ QCollator &QCollator::operator=(const QCollator &other) Move constructor. Moves from \a other into this collator. - Note that a moved-from QCollator can only be destroyed or assigned - to. The effect of calling other functions than the destructor or - one of the assignment operators is undefined. + Note that a moved-from QCollator can only be destroyed or assigned to. + The effect of calling other functions than the destructor or one of the + assignment operators is undefined. */ /*! @@ -138,9 +149,9 @@ QCollator &QCollator::operator=(const QCollator &other) Move-assigns from \a other to this collator. - Note that a moved-from QCollator can only be destroyed or assigned - to. The effect of calling other functions than the destructor or - one of the assignment operators is undefined. + Note that a moved-from QCollator can only be destroyed or assigned to. + The effect of calling other functions than the destructor or one of the + assignment operators is undefined. */ /*! @@ -218,7 +229,8 @@ Qt::CaseSensitivity QCollator::caseSensitivity() const Enables numeric sorting mode when \a on is set to true. - This will enable proper sorting of numeric digits, so that e.g. 100 sorts after 99. + This will enable proper sorting of numeric digits, so that e.g. 100 sorts + after 99. By default this mode is off. @@ -248,11 +260,13 @@ bool QCollator::numericMode() const /*! \fn void QCollator::setIgnorePunctuation(bool on) - If \a on is set to true, punctuation characters and symbols are ignored when determining sort order. + If \a on is set to true, punctuation characters and symbols are ignored when + determining sort order. The default is locale dependent. - \note This method is not currently supported if Qt is configured to not use ICU on Linux. + \note This method is not currently supported if Qt is configured to not use + ICU on Linux. \sa ignorePunctuation() */ @@ -268,7 +282,8 @@ void QCollator::setIgnorePunctuation(bool on) /*! \fn bool QCollator::ignorePunctuation() const - Returns \c true if punctuation characters and symbols are ignored when determining sort order. + Returns \c true if punctuation characters and symbols are ignored when + determining sort order. \sa setIgnorePunctuation() */ @@ -278,35 +293,66 @@ bool QCollator::ignorePunctuation() const } /*! - \fn int QCollator::compare(const QString &s1, const QString &s2) const + \since 5.13 + \fn bool QCollator::operator()(QStringView s1, QStringView s2) const + \internal +*/ - Compares \a s1 with \a s2. Returns an integer less than, equal to, or greater than zero - depending on whether \a s1 is smaller, equal or larger than \a s2. - */ +/*! + \since 5.13 + \fn int QCollator::compare(QStringView s1, QStringView s2) const + + Compares \a s1 with \a s2. + Returns an integer less than, equal to, or greater than zero depending on + whether \a s1 sorts before, with or after \a s2. +*/ +#if QT_STRINGVIEW_LEVEL < 2 /*! \fn bool QCollator::operator()(const QString &s1, const QString &s2) const \internal */ /*! - \fn int QCollator::compare(const QStringRef &s1, const QStringRef &s2) const \overload - Compares \a s1 with \a s2. Returns an integer less than, equal to, or greater than zero - depending on whether \a s1 is smaller, equal or larger than \a s2. + Compares \a s1 with \a s2. + + Returns an integer less than, equal to, or greater than zero depending on + whether \a s1 sorts before, with or after \a s2. +*/ +int QCollator::compare(const QString &s1, const QString &s2) const +{ + return compare(QStringView(s1), QStringView(s2)); +} + +/*! + \overload + + Compares \a s1 with \a s2. + + Returns an integer less than, equal to, or greater than zero depending on + whether \a s1 sorts before, with or after \a s2. */ +int QCollator::compare(const QStringRef &s1, const QStringRef &s2) const +{ + return compare(QStringView(s1), QStringView(s2)); +} /*! - \fn int QCollator::compare(const QChar *s1, int len1, const QChar *s2, int len2) const \overload - Compares \a s1 with \a s2. \a len1 and \a len2 specify the length of the - QChar arrays pointer to by \a s1 and \a s2. + Compares \a s1 with \a s2. \a len1 and \a len2 specify the lengths of the + QChar arrays pointed to by \a s1 and \a s2. - Returns an integer less than, equal to, or greater than zero - depending on whether \a s1 is smaller, equal or larger than \a s2. + Returns an integer less than, equal to, or greater than zero depending on + whether \a s1 sorts before, with or after \a s2. */ +int QCollator::compare(const QChar *s1, int len1, const QChar *s2, int len2) const +{ + return compare(QStringView(s1, len1), QStringView(s2, len2)); +} +#endif // QT_STRINGVIEW_LEVEL < 2 /*! \fn QCollatorSortKey QCollator::sortKey(const QString &string) const @@ -314,9 +360,9 @@ bool QCollator::ignorePunctuation() const Returns a sortKey for \a string. Creating the sort key is usually somewhat slower, than using the compare() - methods directly. But if the string is compared repeatedly (e.g. when sorting - a whole list of strings), it's usually faster to create the sort keys for each - string and then sort using the keys. + methods directly. But if the string is compared repeatedly (e.g. when + sorting a whole list of strings), it's usually faster to create the sort + keys for each string and then sort using the keys. \note Not supported with the C (a.k.a. POSIX) locale on Darwin. */ @@ -328,8 +374,8 @@ bool QCollator::ignorePunctuation() const \since 5.2 - The QCollatorSortKey class is always created by QCollator::sortKey() - and is used for fast strings collation, for example when collating many strings. + The QCollatorSortKey class is always created by QCollator::sortKey() and is + used for fast strings collation, for example when collating many strings. \reentrant \ingroup i18n @@ -398,9 +444,11 @@ QCollatorSortKey& QCollatorSortKey::operator=(const QCollatorSortKey &other) /*! \fn int QCollatorSortKey::compare(const QCollatorSortKey &otherKey) const - Compares the key to \a otherKey. Returns a negative value if the key - is less than \a otherKey, 0 if the key is equal to \a otherKey or a - positive value if the key is greater than \a otherKey. + Compares this key to \a otherKey. + + Returns a negative value if the key is less than \a otherKey, 0 if the key + is equal to \a otherKey or a positive value if the key is greater than \a + otherKey. \sa operator<() */ diff --git a/src/corelib/tools/qcollator.h b/src/corelib/tools/qcollator.h index 6fa199cb0f..6bb5038371 100644 --- a/src/corelib/tools/qcollator.h +++ b/src/corelib/tools/qcollator.h @@ -57,11 +57,9 @@ public: QCollatorSortKey(const QCollatorSortKey &other); ~QCollatorSortKey(); QCollatorSortKey &operator=(const QCollatorSortKey &other); -#ifdef Q_COMPILER_RVALUE_REFS - inline QCollatorSortKey &operator=(QCollatorSortKey &&other) Q_DECL_NOTHROW + inline QCollatorSortKey &operator=(QCollatorSortKey &&other) noexcept { swap(other); return *this; } -#endif - void swap(QCollatorSortKey &other) Q_DECL_NOTHROW + void swap(QCollatorSortKey &other) noexcept { d.swap(other.d); } int compare(const QCollatorSortKey &key) const; @@ -83,18 +81,17 @@ inline bool operator<(const QCollatorSortKey &lhs, const QCollatorSortKey &rhs) class Q_CORE_EXPORT QCollator { public: - explicit QCollator(const QLocale &locale = QLocale()); + QCollator(); + explicit QCollator(const QLocale &locale); QCollator(const QCollator &); ~QCollator(); QCollator &operator=(const QCollator &); -#ifdef Q_COMPILER_RVALUE_REFS - QCollator(QCollator &&other) Q_DECL_NOTHROW + QCollator(QCollator &&other) noexcept : d(other.d) { other.d = nullptr; } - QCollator &operator=(QCollator &&other) Q_DECL_NOTHROW + QCollator &operator=(QCollator &&other) noexcept { swap(other); return *this; } -#endif - void swap(QCollator &other) Q_DECL_NOTHROW + void swap(QCollator &other) noexcept { qSwap(d, other.d); } void setLocale(const QLocale &locale); @@ -109,12 +106,18 @@ public: void setIgnorePunctuation(bool on); bool ignorePunctuation() const; +#if QT_STRINGVIEW_LEVEL < 2 int compare(const QString &s1, const QString &s2) const; int compare(const QStringRef &s1, const QStringRef &s2) const; int compare(const QChar *s1, int len1, const QChar *s2, int len2) const; bool operator()(const QString &s1, const QString &s2) const { return compare(s1, s2) < 0; } +#endif + int compare(QStringView s1, QStringView s2) const; + + bool operator()(QStringView s1, QStringView s2) const + { return compare(s1, s2) < 0; } QCollatorSortKey sortKey(const QString &string) const; diff --git a/src/corelib/tools/qcollator_icu.cpp b/src/corelib/tools/qcollator_icu.cpp index ab45b9a1a1..8acda45070 100644 --- a/src/corelib/tools/qcollator_icu.cpp +++ b/src/corelib/tools/qcollator_icu.cpp @@ -78,7 +78,8 @@ void QCollatorPrivate::init() // and does case sensitive comparison. // UCOL_QUATERNARY is used as default in a few languages such as Japanese to take care of some // additional differences in those languages. - UColAttributeValue val = (caseSensitivity == Qt::CaseSensitive) ? UCOL_DEFAULT_STRENGTH : UCOL_SECONDARY; + UColAttributeValue val = (caseSensitivity == Qt::CaseSensitive) + ? UCOL_DEFAULT_STRENGTH : UCOL_SECONDARY; status = U_ZERO_ERROR; ucol_setAttribute(collator, UCOL_STRENGTH, val, &status); @@ -91,7 +92,8 @@ void QCollatorPrivate::init() qWarning("ucol_setAttribute: numeric collation failed: %d", status); status = U_ZERO_ERROR; - ucol_setAttribute(collator, UCOL_ALTERNATE_HANDLING, ignorePunctuation ? UCOL_SHIFTED : UCOL_NON_IGNORABLE, &status); + ucol_setAttribute(collator, UCOL_ALTERNATE_HANDLING, + ignorePunctuation ? UCOL_SHIFTED : UCOL_NON_IGNORABLE, &status); if (U_FAILURE(status)) qWarning("ucol_setAttribute: Alternate handling failed: %d", status); @@ -105,37 +107,20 @@ void QCollatorPrivate::cleanup() collator = nullptr; } -int QCollator::compare(const QChar *s1, int len1, const QChar *s2, int len2) const +int QCollator::compare(QStringView s1, QStringView s2) const { if (d->dirty) d->init(); - if (d->collator) - return ucol_strcoll(d->collator, (const UChar *)s1, len1, (const UChar *)s2, len2); - - return QString::compare_helper(s1, len1, s2, len2, d->caseSensitivity); -} - -int QCollator::compare(const QString &s1, const QString &s2) const -{ - if (d->dirty) - d->init(); - - if (d->collator) - return compare(s1.constData(), s1.size(), s2.constData(), s2.size()); - - return QString::compare(s1, s2, d->caseSensitivity); -} - -int QCollator::compare(const QStringRef &s1, const QStringRef &s2) const -{ - if (d->dirty) - d->init(); - - if (d->collator) - return compare(s1.constData(), s1.size(), s2.constData(), s2.size()); + if (d->collator) { + return ucol_strcoll(d->collator, + reinterpret_cast<const UChar *>(s1.data()), s1.size(), + reinterpret_cast<const UChar *>(s2.data()), s2.size()); + } - return QStringRef::compare(s1, s2, d->caseSensitivity); + return QString::compare_helper(s1.data(), s1.size(), + s2.data(), s2.size(), + d->caseSensitivity); } QCollatorSortKey QCollator::sortKey(const QString &string) const diff --git a/src/corelib/tools/qcollator_macx.cpp b/src/corelib/tools/qcollator_macx.cpp index 42e67e0c12..071d7c048f 100644 --- a/src/corelib/tools/qcollator_macx.cpp +++ b/src/corelib/tools/qcollator_macx.cpp @@ -65,12 +65,12 @@ void QCollatorPrivate::init() return; LocaleRef localeRef; - int rc = LocaleRefFromLocaleString(QLocalePrivate::get(locale)->bcp47Name().constData(), &localeRef); - if (rc != 0) - qWarning("couldn't initialize the locale"); + OSStatus status = + LocaleRefFromLocaleString(QLocalePrivate::get(locale)->bcp47Name().constData(), &localeRef); + if (status != 0) + qWarning("Couldn't initialize the locale (%d)", int(status)); UInt32 options = 0; - if (caseSensitivity == Qt::CaseInsensitive) options |= kUCCollateCaseInsensitiveMask; if (numericMode) @@ -78,14 +78,9 @@ void QCollatorPrivate::init() if (!ignorePunctuation) options |= kUCCollatePunctuationSignificantMask; - OSStatus status = UCCreateCollator( - localeRef, - 0, - options, - &collator - ); + status = UCCreateCollator(localeRef, 0, options, &collator); if (status != 0) - qWarning("Couldn't initialize the collator"); + qWarning("Couldn't initialize the collator (%d)", int(status)); dirty = false; } @@ -97,18 +92,18 @@ void QCollatorPrivate::cleanup() collator = 0; } -int QCollator::compare(const QChar *s1, int len1, const QChar *s2, int len2) const +int QCollator::compare(QStringView s1, QStringView s2) const { if (d->dirty) d->init(); if (!d->collator) - return QStringView(s1, len1).compare(QStringView(s2, len2), caseSensitivity()); + return s1.compare(s2, caseSensitivity()); SInt32 result; Boolean equivalent; UCCompareText(d->collator, - reinterpret_cast<const UniChar *>(s1), len1, - reinterpret_cast<const UniChar *>(s2), len2, + reinterpret_cast<const UniChar *>(s1.data()), s1.size(), + reinterpret_cast<const UniChar *>(s2.data()), s2.size(), &equivalent, &result); if (equivalent) @@ -116,16 +111,6 @@ int QCollator::compare(const QChar *s1, int len1, const QChar *s2, int len2) con return result < 0 ? -1 : 1; } -int QCollator::compare(const QString &str1, const QString &str2) const -{ - return compare(str1.constData(), str1.size(), str2.constData(), str2.size()); -} - -int QCollator::compare(const QStringRef &s1, const QStringRef &s2) const -{ - return compare(s1.constData(), s1.size(), s2.constData(), s2.size()); -} - QCollatorSortKey QCollator::sortKey(const QString &string) const { if (d->dirty) @@ -139,13 +124,14 @@ QCollatorSortKey QCollator::sortKey(const QString &string) const //Documentation recommends having it 5 times as big as the input QVector<UCCollationValue> ret(string.size() * 5); ItemCount actualSize; - int status = UCGetCollationKey(d->collator, reinterpret_cast<const UniChar *>(string.constData()), string.count(), - ret.size(), &actualSize, ret.data()); + int status = UCGetCollationKey(d->collator, + reinterpret_cast<const UniChar *>(string.constData()), + string.count(), ret.size(), &actualSize, ret.data()); - ret.resize(actualSize+1); + ret.resize(actualSize + 1); if (status == kUCOutputBufferTooSmall) { - UCGetCollationKey(d->collator, reinterpret_cast<const UniChar *>(string.constData()), string.count(), - ret.size(), &actualSize, ret.data()); + UCGetCollationKey(d->collator, reinterpret_cast<const UniChar *>(string.constData()), + string.count(), ret.size(), &actualSize, ret.data()); } ret[actualSize] = 0; return QCollatorSortKey(new QCollatorSortKeyPrivate(std::move(ret))); diff --git a/src/corelib/tools/qcollator_posix.cpp b/src/corelib/tools/qcollator_posix.cpp index 81f97a02e1..9cbc539ebe 100644 --- a/src/corelib/tools/qcollator_posix.cpp +++ b/src/corelib/tools/qcollator_posix.cpp @@ -65,7 +65,7 @@ void QCollatorPrivate::cleanup() { } -static void stringToWCharArray(QVarLengthArray<wchar_t> &ret, const QString &string) +static void stringToWCharArray(QVarLengthArray<wchar_t> &ret, QStringView string) { ret.resize(string.length()); int len = string.toWCharArray(ret.data()); @@ -73,12 +73,7 @@ static void stringToWCharArray(QVarLengthArray<wchar_t> &ret, const QString &str ret[len] = 0; } -int QCollator::compare(const QChar *s1, int len1, const QChar *s2, int len2) const -{ - return compare(QString::fromRawData(s1, len1), QString::fromRawData(s2, len2)); -} - -int QCollator::compare(const QString &s1, const QString &s2) const +int QCollator::compare(QStringView s1, QStringView s2) const { if (d->isC()) return s1.compare(s2, caseSensitivity()); @@ -91,11 +86,6 @@ int QCollator::compare(const QString &s1, const QString &s2) const return std::wcscoll(array1.constData(), array2.constData()); } -int QCollator::compare(const QStringRef &s1, const QStringRef &s2) const -{ - return compare(s1.toString(), s2.toString()); -} - QCollatorSortKey QCollator::sortKey(const QString &string) const { if (d->dirty) diff --git a/src/corelib/tools/qcollator_win.cpp b/src/corelib/tools/qcollator_win.cpp index 10cfdaa264..9d81de882f 100644 --- a/src/corelib/tools/qcollator_win.cpp +++ b/src/corelib/tools/qcollator_win.cpp @@ -87,30 +87,30 @@ void QCollatorPrivate::cleanup() { } - -int QCollator::compare(const QChar *s1, int len1, const QChar *s2, int len2) const +int QCollator::compare(QStringView s1, QStringView s2) const { if (d->isC()) - return QString::compare_helper(s1, len1, s2, len2, d->caseSensitivity); + return s1.compare(s2, d->caseSensitivity); if (d->dirty) d->init(); //* from Windows documentation * - // Returns one of the following values if successful. To maintain the C runtime convention of - // comparing strings, the value 2 can be subtracted from a nonzero return value. Then, the - // meaning of <0, ==0, and >0 is consistent with the C runtime. + // Returns one of the following values if successful. To maintain the C + // runtime convention of comparing strings, the value 2 can be subtracted + // from a nonzero return value. Then, the meaning of <0, ==0, and >0 is + // consistent with the C runtime. // [...] The function returns 0 if it does not succeed. // https://docs.microsoft.com/en-us/windows/desktop/api/stringapiset/nf-stringapiset-comparestringex#return-value #ifndef USE_COMPARESTRINGEX const int ret = CompareString(d->localeID, d->collator, - reinterpret_cast<const wchar_t*>(s1), len1, - reinterpret_cast<const wchar_t*>(s2), len2); + reinterpret_cast<const wchar_t *>(s1.data()), s1.size(), + reinterpret_cast<const wchar_t *>(s2.data()), s2.size()); #else const int ret = CompareStringEx(LPCWSTR(d->localeName.utf16()), d->collator, - reinterpret_cast<LPCWSTR>(s1), len1, - reinterpret_cast<LPCWSTR>(s2), len2, + reinterpret_cast<LPCWSTR>(s1.data()), s1.size(), + reinterpret_cast<LPCWSTR>(s2.data()), s2.size(), nullptr, nullptr, 0); #endif if (Q_LIKELY(ret)) @@ -132,16 +132,6 @@ int QCollator::compare(const QChar *s1, int len1, const QChar *s2, int len2) con return 0; } -int QCollator::compare(const QString &str1, const QString &str2) const -{ - return compare(str1.constData(), str1.size(), str2.constData(), str2.size()); -} - -int QCollator::compare(const QStringRef &s1, const QStringRef &s2) const -{ - return compare(s1.constData(), s1.size(), s2.constData(), s2.size()); -} - QCollatorSortKey QCollator::sortKey(const QString &string) const { if (d->dirty) @@ -170,7 +160,9 @@ QCollatorSortKey QCollator::sortKey(const QString &string) const NULL, NULL, 0); #endif if (finalSize == 0) { - qWarning() << "there were problems when generating the ::sortKey by LCMapStringW with error:" << GetLastError(); + qWarning() + << "there were problems when generating the ::sortKey by LCMapStringW with error:" + << GetLastError(); } return QCollatorSortKey(new QCollatorSortKeyPrivate(std::move(ret))); } diff --git a/src/corelib/tools/qcommandlineoption.cpp b/src/corelib/tools/qcommandlineoption.cpp index c2b86014ba..aff684fad2 100644 --- a/src/corelib/tools/qcommandlineoption.cpp +++ b/src/corelib/tools/qcommandlineoption.cpp @@ -254,7 +254,7 @@ namespace { typedef QString argument_type; Q_NEVER_INLINE - result_type operator()(const QString &name) const Q_DECL_NOEXCEPT + result_type operator()(const QString &name) const noexcept { if (Q_UNLIKELY(name.isEmpty())) return warn("be empty"); @@ -271,7 +271,7 @@ namespace { } Q_NEVER_INLINE - static bool warn(const char *what) Q_DECL_NOEXCEPT + static bool warn(const char *what) noexcept { qWarning("QCommandLineOption: Option names cannot %s", what); return true; diff --git a/src/corelib/tools/qcommandlineoption.h b/src/corelib/tools/qcommandlineoption.h index 276be042de..e2ca64acef 100644 --- a/src/corelib/tools/qcommandlineoption.h +++ b/src/corelib/tools/qcommandlineoption.h @@ -71,11 +71,9 @@ public: ~QCommandLineOption(); QCommandLineOption &operator=(const QCommandLineOption &other); -#ifdef Q_COMPILER_RVALUE_REFS - QCommandLineOption &operator=(QCommandLineOption &&other) Q_DECL_NOTHROW { swap(other); return *this; } -#endif + QCommandLineOption &operator=(QCommandLineOption &&other) noexcept { swap(other); return *this; } - void swap(QCommandLineOption &other) Q_DECL_NOTHROW + void swap(QCommandLineOption &other) noexcept { qSwap(d, other.d); } QStringList names() const; diff --git a/src/corelib/tools/qcommandlineparser.cpp b/src/corelib/tools/qcommandlineparser.cpp index 6817d73143..489724ac47 100644 --- a/src/corelib/tools/qcommandlineparser.cpp +++ b/src/corelib/tools/qcommandlineparser.cpp @@ -362,8 +362,10 @@ bool QCommandLineParser::addOption(const QCommandLineOption &option) if (!optionNames.isEmpty()) { for (const QString &name : optionNames) { - if (d->nameHash.contains(name)) + if (d->nameHash.contains(name)) { + qWarning() << "QCommandLineParser: already having an option named" << name; return false; + } } d->commandLineOptionList.append(option); diff --git a/src/corelib/global/qfloat16_p.h b/src/corelib/tools/qcontainertools_impl.h index f3fc96e119..c2de50b145 100644 --- a/src/corelib/global/qfloat16_p.h +++ b/src/corelib/tools/qcontainertools_impl.h @@ -1,7 +1,8 @@ /**************************************************************************** ** -** Copyright (C) 2016 by Southwest Research Institute (R) -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com> +** Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. ** @@ -37,59 +38,56 @@ ** ****************************************************************************/ -#ifndef QFLOAT16_P_H -#define QFLOAT16_P_H +#if 0 +#pragma qt_sync_skip_header_check +#pragma qt_sync_stop_processing +#endif -// -// 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. -// +#ifndef QCONTAINERTOOLS_IMPL_H +#define QCONTAINERTOOLS_IMPL_H -#include <QtCore/qfloat16.h> -#include <QtCore/qsysinfo.h> +#include <QtCore/qglobal.h> +#include <iterator> + +#ifndef Q_QDOC QT_BEGIN_NAMESPACE -static inline bool qt_is_inf(qfloat16 d) Q_DECL_NOTHROW +namespace QtPrivate { - bool is_inf; - uchar *ch = (uchar *)&d; - if (QSysInfo::ByteOrder == QSysInfo::BigEndian) - is_inf = (ch[0] & 0x7c) == 0x7c && (ch[0] & 0x02) == 0; - else - is_inf = (ch[1] & 0x7c) == 0x7c && (ch[1] & 0x02) == 0; - return is_inf; -} +template <typename Iterator> +using IfIsInputIterator = typename std::enable_if< + std::is_convertible<typename std::iterator_traits<Iterator>::iterator_category, std::input_iterator_tag>::value, + bool>::type; + +template <typename Iterator> +using IfIsForwardIterator = typename std::enable_if< + std::is_convertible<typename std::iterator_traits<Iterator>::iterator_category, std::forward_iterator_tag>::value, + bool>::type; -static inline bool qt_is_nan(qfloat16 d) Q_DECL_NOTHROW +template <typename Iterator> +using IfIsNotForwardIterator = typename std::enable_if< + !std::is_convertible<typename std::iterator_traits<Iterator>::iterator_category, std::forward_iterator_tag>::value, + bool>::type; + +template <typename Container, + typename InputIterator, + IfIsNotForwardIterator<InputIterator> = true> +void reserveIfForwardIterator(Container *, InputIterator, InputIterator) { - bool is_nan; - uchar *ch = (uchar *)&d; - if (QSysInfo::ByteOrder == QSysInfo::BigEndian) - is_nan = (ch[0] & 0x7c) == 0x7c && (ch[0] & 0x02) != 0; - else - is_nan = (ch[1] & 0x7c) == 0x7c && (ch[1] & 0x02) != 0; - return is_nan; } -static inline bool qt_is_finite(qfloat16 d) Q_DECL_NOTHROW +template <typename Container, + typename ForwardIterator, + IfIsForwardIterator<ForwardIterator> = true> +void reserveIfForwardIterator(Container *c, ForwardIterator f, ForwardIterator l) { - bool is_finite; - uchar *ch = (uchar *)&d; - if (QSysInfo::ByteOrder == QSysInfo::BigEndian) - is_finite = (ch[0] & 0x7c) != 0x7c; - else - is_finite = (ch[1] & 0x7c) != 0x7c; - return is_finite; + c->reserve(static_cast<typename Container::size_type>(std::distance(f, l))); } - +} // namespace QtPrivate QT_END_NAMESPACE -#endif // QFLOAT16_P_H +#endif // Q_QDOC + +#endif // QCONTAINERTOOLS_IMPL_H diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h index fdb9c6d19a..433e3f9ea4 100644 --- a/src/corelib/tools/qcontiguouscache.h +++ b/src/corelib/tools/qcontiguouscache.h @@ -107,10 +107,8 @@ public: #endif QContiguousCache<T> &operator=(const QContiguousCache<T> &other); -#ifdef Q_COMPILER_RVALUE_REFS inline QContiguousCache<T> &operator=(QContiguousCache<T> &&other) { qSwap(d, other.d); return *this; } -#endif inline void swap(QContiguousCache<T> &other) { qSwap(d, other.d); } bool operator==(const QContiguousCache<T> &other) const; inline bool operator!=(const QContiguousCache<T> &other) const { return !(*this == other); } diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 511dbf0db8..6fa735dab7 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -259,7 +259,7 @@ static QString toOffsetString(Qt::DateFormat format, int offset) #if QT_CONFIG(datestring) // Parse offset in [+-]HH[[:]mm] format -static int fromOffsetString(const QStringRef &offsetString, bool *valid) Q_DECL_NOTHROW +static int fromOffsetString(const QStringRef &offsetString, bool *valid) noexcept { *valid = false; @@ -1467,9 +1467,8 @@ bool QDate::isLeapYear(int y) /*! \fn QTime::QTime() - Constructs a null time object. A null time can be a QTime(0, 0, 0, 0) - (i.e., midnight) object, except that isNull() returns \c true and isValid() - returns \c false. + Constructs a null time object. For a null time, isNull() returns \c true and + isValid() returns \c false. If you need a zero time, use QTime(0, 0). \sa isNull(), isValid() */ @@ -3135,7 +3134,7 @@ inline qint64 QDateTimePrivate::zoneMSecsToEpochMSecs(qint64 zoneMSecs, const QT \sa isValid() */ -QDateTime::QDateTime() Q_DECL_NOEXCEPT_EXPR(Data::CanBeSmall) +QDateTime::QDateTime() noexcept(Data::CanBeSmall) { } @@ -3146,7 +3145,7 @@ QDateTime::QDateTime() Q_DECL_NOEXCEPT_EXPR(Data::CanBeSmall) */ QDateTime::QDateTime(const QDate &date) - : d(QDateTimePrivate::create(date, QTime(0, 0, 0), Qt::LocalTime, 0)) + : d(QDateTimePrivate::create(date, QTime(0, 0), Qt::LocalTime, 0)) { } @@ -3214,7 +3213,7 @@ QDateTime::QDateTime(const QDate &date, const QTime &time, const QTimeZone &time /*! Constructs a copy of the \a other datetime. */ -QDateTime::QDateTime(const QDateTime &other) Q_DECL_NOTHROW +QDateTime::QDateTime(const QDateTime &other) noexcept : d(other.d) { } @@ -3224,7 +3223,7 @@ QDateTime::QDateTime(const QDateTime &other) Q_DECL_NOTHROW Moves the content of the temporary \a other datetime to this object and leaves \a other in an unspecified (but proper) state. */ -QDateTime::QDateTime(QDateTime &&other) Q_DECL_NOTHROW +QDateTime::QDateTime(QDateTime &&other) noexcept : d(std::move(other.d)) { } @@ -3241,7 +3240,7 @@ QDateTime::~QDateTime() copy. */ -QDateTime &QDateTime::operator=(const QDateTime &other) Q_DECL_NOTHROW +QDateTime &QDateTime::operator=(const QDateTime &other) noexcept { d = other.d; return *this; @@ -4469,7 +4468,7 @@ QDateTime QDateTime::currentDateTimeUtc() return QDateTime(d, t, Qt::UTC); } -qint64 QDateTime::currentMSecsSinceEpoch() Q_DECL_NOTHROW +qint64 QDateTime::currentMSecsSinceEpoch() noexcept { SYSTEMTIME st; memset(&st, 0, sizeof(SYSTEMTIME)); @@ -4480,7 +4479,7 @@ qint64 QDateTime::currentMSecsSinceEpoch() Q_DECL_NOTHROW - julianDayFromDate(1970, 1, 1)) * Q_INT64_C(86400000); } -qint64 QDateTime::currentSecsSinceEpoch() Q_DECL_NOTHROW +qint64 QDateTime::currentSecsSinceEpoch() noexcept { SYSTEMTIME st; memset(&st, 0, sizeof(SYSTEMTIME)); @@ -4512,7 +4511,7 @@ QDateTime QDateTime::currentDateTimeUtc() return fromMSecsSinceEpoch(currentMSecsSinceEpoch(), Qt::UTC); } -qint64 QDateTime::currentMSecsSinceEpoch() Q_DECL_NOTHROW +qint64 QDateTime::currentMSecsSinceEpoch() noexcept { // posix compliant system // we have milliseconds @@ -4521,7 +4520,7 @@ qint64 QDateTime::currentMSecsSinceEpoch() Q_DECL_NOTHROW return qint64(tv.tv_sec) * Q_INT64_C(1000) + tv.tv_usec / 1000; } -qint64 QDateTime::currentSecsSinceEpoch() Q_DECL_NOTHROW +qint64 QDateTime::currentSecsSinceEpoch() noexcept { struct timeval tv; gettimeofday(&tv, 0); @@ -5418,7 +5417,7 @@ uint qHash(const QDateTime &key, uint seed) Returns the hash value for the \a key, using \a seed to seed the calculation. */ -uint qHash(const QDate &key, uint seed) Q_DECL_NOTHROW +uint qHash(const QDate &key, uint seed) noexcept { return qHash(key.toJulianDay(), seed); } @@ -5429,7 +5428,7 @@ uint qHash(const QDate &key, uint seed) Q_DECL_NOTHROW Returns the hash value for the \a key, using \a seed to seed the calculation. */ -uint qHash(const QTime &key, uint seed) Q_DECL_NOTHROW +uint qHash(const QTime &key, uint seed) noexcept { return qHash(key.msecsSinceStartOfDay(), seed); } diff --git a/src/corelib/tools/qdatetime.h b/src/corelib/tools/qdatetime.h index 8b2a60acaa..51d5dd9759 100644 --- a/src/corelib/tools/qdatetime.h +++ b/src/corelib/tools/qdatetime.h @@ -258,7 +258,7 @@ class Q_CORE_EXPORT QDateTime }; public: - QDateTime() Q_DECL_NOEXCEPT_EXPR(Data::CanBeSmall); + QDateTime() noexcept(Data::CanBeSmall); explicit QDateTime(const QDate &); QDateTime(const QDate &, const QTime &, Qt::TimeSpec spec = Qt::LocalTime); // ### Qt 6: Merge with above with default offsetSeconds = 0 @@ -266,16 +266,16 @@ public: #if QT_CONFIG(timezone) QDateTime(const QDate &date, const QTime &time, const QTimeZone &timeZone); #endif // timezone - QDateTime(const QDateTime &other) Q_DECL_NOTHROW; - QDateTime(QDateTime &&other) Q_DECL_NOTHROW; + QDateTime(const QDateTime &other) noexcept; + QDateTime(QDateTime &&other) noexcept; ~QDateTime(); #ifdef Q_COMPILER_RVALUE_REFS - QDateTime &operator=(QDateTime &&other) Q_DECL_NOTHROW { swap(other); return *this; } + QDateTime &operator=(QDateTime &&other) noexcept { swap(other); return *this; } #endif - QDateTime &operator=(const QDateTime &other) Q_DECL_NOTHROW; + QDateTime &operator=(const QDateTime &other) noexcept; - void swap(QDateTime &other) Q_DECL_NOTHROW { qSwap(d.d, other.d.d); } + void swap(QDateTime &other) noexcept { qSwap(d.d, other.d.d); } bool isNull() const; bool isValid() const; @@ -366,8 +366,8 @@ public: static QDateTime fromSecsSinceEpoch(qint64 secs, const QTimeZone &timeZone); #endif - static qint64 currentMSecsSinceEpoch() Q_DECL_NOTHROW; - static qint64 currentSecsSinceEpoch() Q_DECL_NOTHROW; + static qint64 currentMSecsSinceEpoch() noexcept; + static qint64 currentSecsSinceEpoch() noexcept; #if defined(Q_OS_DARWIN) || defined(Q_QDOC) static QDateTime fromCFDate(CFDateRef date); @@ -410,8 +410,8 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QDateTime &); // QDateTime is not noexcept for now -- to be revised once // timezone and calendaring support is added Q_CORE_EXPORT uint qHash(const QDateTime &key, uint seed = 0); -Q_CORE_EXPORT uint qHash(const QDate &key, uint seed = 0) Q_DECL_NOTHROW; -Q_CORE_EXPORT uint qHash(const QTime &key, uint seed = 0) Q_DECL_NOTHROW; +Q_CORE_EXPORT uint qHash(const QDate &key, uint seed = 0) noexcept; +Q_CORE_EXPORT uint qHash(const QTime &key, uint seed = 0) noexcept; QT_END_NAMESPACE diff --git a/src/corelib/tools/qdatetime_p.h b/src/corelib/tools/qdatetime_p.h index b3d00745d0..6018f8f7b0 100644 --- a/src/corelib/tools/qdatetime_p.h +++ b/src/corelib/tools/qdatetime_p.h @@ -135,7 +135,7 @@ public: #if QT_CONFIG(timezone) static qint64 zoneMSecsToEpochMSecs(qint64 msecs, const QTimeZone &zone, DaylightStatus hint = UnknownDaylightTime, - QDate *localDate = 0, QTime *localTime = 0); + QDate *localDate = nullptr, QTime *localTime = nullptr); // Inlined for its one caller in qdatetime.cpp inline void setUtcOffsetByTZ(qint64 atMSecsSinceEpoch); diff --git a/src/corelib/tools/qdatetimeparser.cpp b/src/corelib/tools/qdatetimeparser.cpp index e8470f6cde..5d1704daeb 100644 --- a/src/corelib/tools/qdatetimeparser.cpp +++ b/src/corelib/tools/qdatetimeparser.cpp @@ -47,7 +47,6 @@ #if QT_CONFIG(timezone) #include "qtimezone.h" #endif -#include "qregexp.h" #include "qdebug.h" //#define QDATETIMEPARSER_DEBUG diff --git a/src/corelib/tools/qdatetimeparser_p.h b/src/corelib/tools/qdatetimeparser_p.h index f7e6e351fe..e244fed09a 100644 --- a/src/corelib/tools/qdatetimeparser_p.h +++ b/src/corelib/tools/qdatetimeparser_p.h @@ -86,7 +86,7 @@ public: DateTimeEdit }; QDateTimeParser(QVariant::Type t, Context ctx) - : currentSectionIndex(-1), display(0), cachedDay(-1), parserType(t), + : currentSectionIndex(-1), display(nullptr), cachedDay(-1), parserType(t), fixday(false), spec(Qt::LocalTime), context(ctx) { defaultLocale = QLocale::system(); @@ -218,9 +218,9 @@ private: ParsedSection parseSection(const QDateTime ¤tValue, int sectionIndex, int offset, QString *text) const; int findMonth(const QString &str1, int monthstart, int sectionIndex, - QString *monthName = 0, int *used = 0) const; + QString *monthName = nullptr, int *used = nullptr) const; int findDay(const QString &str1, int intDaystart, int sectionIndex, - QString *dayName = 0, int *used = 0) const; + QString *dayName = nullptr, int *used = nullptr) const; ParsedSection findTimeZone(QStringRef str, const QDateTime &when, int maxVal, int minVal) const; #if QT_CONFIG(timezone) @@ -236,7 +236,7 @@ private: PossiblePM = 3, PossibleBoth = 4 }; - AmPmFinder findAmPm(QString &str, int index, int *used = 0) const; + AmPmFinder findAmPm(QString &str, int index, int *used = nullptr) const; #endif // datestring bool potentialValue(const QStringRef &str, int min, int max, int index, diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp index f82048db0f..9169b5c7f1 100644 --- a/src/corelib/tools/qeasingcurve.cpp +++ b/src/corelib/tools/qeasingcurve.cpp @@ -339,6 +339,23 @@ struct TCBPoint { }; Q_DECLARE_TYPEINFO(TCBPoint, Q_PRIMITIVE_TYPE); +QDataStream &operator<<(QDataStream &stream, const TCBPoint &point) +{ + stream << point._point + << point._t + << point._c + << point._b; + return stream; +} + +QDataStream &operator>>(QDataStream &stream, TCBPoint &point) +{ + stream >> point._point + >> point._t + >> point._c + >> point._b; + return stream; +} typedef QVector<TCBPoint> TCBPoints; @@ -363,6 +380,34 @@ public: }; +QDataStream &operator<<(QDataStream &stream, QEasingCurveFunction *func) +{ + if (func) { + stream << func->_p; + stream << func->_a; + stream << func->_o; + if (stream.version() > QDataStream::Qt_5_12) { + stream << func->_bezierCurves; + stream << func->_tcbPoints; + } + } + return stream; +} + +QDataStream &operator>>(QDataStream &stream, QEasingCurveFunction *func) +{ + if (func) { + stream >> func->_p; + stream >> func->_a; + stream >> func->_o; + if (stream.version() > QDataStream::Qt_5_12) { + stream >> func->_bezierCurves; + stream >> func->_tcbPoints; + } + } + return stream; +} + static QEasingCurve::EasingFunction curveToFunc(QEasingCurve::Type curve); qreal QEasingCurveFunction::value(qreal t) @@ -1480,9 +1525,7 @@ QDataStream &operator<<(QDataStream &stream, const QEasingCurve &easing) bool hasConfig = easing.d_ptr->config; stream << hasConfig; if (hasConfig) { - stream << easing.d_ptr->config->_p; - stream << easing.d_ptr->config->_a; - stream << easing.d_ptr->config->_o; + stream << easing.d_ptr->config; } return stream; } @@ -1515,9 +1558,7 @@ QDataStream &operator>>(QDataStream &stream, QEasingCurve &easing) easing.d_ptr->config = nullptr; if (hasConfig) { QEasingCurveFunction *config = curveToFunctionObject(type); - stream >> config->_p; - stream >> config->_a; - stream >> config->_o; + stream >> config; easing.d_ptr->config = config; } return stream; diff --git a/src/corelib/tools/qeasingcurve.h b/src/corelib/tools/qeasingcurve.h index 74bde5825a..1791f19199 100644 --- a/src/corelib/tools/qeasingcurve.h +++ b/src/corelib/tools/qeasingcurve.h @@ -81,12 +81,12 @@ public: QEasingCurve &operator=(const QEasingCurve &other) { if ( this != &other ) { QEasingCurve copy(other); swap(copy); } return *this; } #ifdef Q_COMPILER_RVALUE_REFS - QEasingCurve(QEasingCurve &&other) Q_DECL_NOTHROW : d_ptr(other.d_ptr) { other.d_ptr = nullptr; } - QEasingCurve &operator=(QEasingCurve &&other) Q_DECL_NOTHROW + QEasingCurve(QEasingCurve &&other) noexcept : d_ptr(other.d_ptr) { other.d_ptr = nullptr; } + QEasingCurve &operator=(QEasingCurve &&other) noexcept { qSwap(d_ptr, other.d_ptr); return *this; } #endif - void swap(QEasingCurve &other) Q_DECL_NOTHROW { qSwap(d_ptr, other.d_ptr); } + void swap(QEasingCurve &other) noexcept { qSwap(d_ptr, other.d_ptr); } bool operator==(const QEasingCurve &other) const; inline bool operator!=(const QEasingCurve &other) const diff --git a/src/corelib/tools/qfreelist_p.h b/src/corelib/tools/qfreelist_p.h index 63be0952ff..d72d6e1b4b 100644 --- a/src/corelib/tools/qfreelist_p.h +++ b/src/corelib/tools/qfreelist_p.h @@ -249,11 +249,11 @@ inline int QFreeList<T, ConstantsType>::next() if (!v) { v = allocate((id & ConstantsType::IndexMask) - at, ConstantsType::Sizes[block]); - if (!_v[block].testAndSetRelease(0, v)) { + if (!_v[block].testAndSetRelease(nullptr, v)) { // race with another thread lost delete [] v; v = _v[block].loadAcquire(); - Q_ASSERT(v != 0); + Q_ASSERT(v != nullptr); } } diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index 32e9a4269c..dd22a38be1 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -197,7 +197,7 @@ static uint crc32(...) } #endif -static inline uint hash(const uchar *p, size_t len, uint seed) Q_DECL_NOTHROW +static inline uint hash(const uchar *p, size_t len, uint seed) noexcept { uint h = seed; @@ -210,12 +210,12 @@ static inline uint hash(const uchar *p, size_t len, uint seed) Q_DECL_NOTHROW return h; } -uint qHashBits(const void *p, size_t len, uint seed) Q_DECL_NOTHROW +uint qHashBits(const void *p, size_t len, uint seed) noexcept { return hash(static_cast<const uchar*>(p), int(len), seed); } -static inline uint hash(const QChar *p, size_t len, uint seed) Q_DECL_NOTHROW +static inline uint hash(const QChar *p, size_t len, uint seed) noexcept { uint h = seed; @@ -228,29 +228,29 @@ static inline uint hash(const QChar *p, size_t len, uint seed) Q_DECL_NOTHROW return h; } -uint qHash(const QByteArray &key, uint seed) Q_DECL_NOTHROW +uint qHash(const QByteArray &key, uint seed) noexcept { return hash(reinterpret_cast<const uchar *>(key.constData()), size_t(key.size()), seed); } #if QT_STRINGVIEW_LEVEL < 2 -uint qHash(const QString &key, uint seed) Q_DECL_NOTHROW +uint qHash(const QString &key, uint seed) noexcept { return hash(key.unicode(), size_t(key.size()), seed); } -uint qHash(const QStringRef &key, uint seed) Q_DECL_NOTHROW +uint qHash(const QStringRef &key, uint seed) noexcept { return hash(key.unicode(), size_t(key.size()), seed); } #endif -uint qHash(QStringView key, uint seed) Q_DECL_NOTHROW +uint qHash(QStringView key, uint seed) noexcept { return hash(key.data(), key.size(), seed); } -uint qHash(const QBitArray &bitArray, uint seed) Q_DECL_NOTHROW +uint qHash(const QBitArray &bitArray, uint seed) noexcept { int m = bitArray.d.size() - 1; uint result = hash(reinterpret_cast<const uchar *>(bitArray.d.constData()), @@ -264,7 +264,7 @@ uint qHash(const QBitArray &bitArray, uint seed) Q_DECL_NOTHROW return result; } -uint qHash(QLatin1String key, uint seed) Q_DECL_NOTHROW +uint qHash(QLatin1String key, uint seed) noexcept { return hash(reinterpret_cast<const uchar *>(key.data()), size_t(key.size()), seed); } @@ -398,7 +398,7 @@ void qSetGlobalQHashSeed(int newSeed) This function can hash discontiguous memory by invoking it on each chunk, passing the previous's result in the next call's \a chained argument. */ -uint qt_hash(QStringView key, uint chained) Q_DECL_NOTHROW +uint qt_hash(QStringView key, uint chained) noexcept { auto n = key.size(); auto p = key.utf16(); @@ -938,7 +938,7 @@ void QHashData::checkSanity() Returns the hash value for the \a key, using \a seed to seed the calculation. */ -uint qHash(float key, uint seed) Q_DECL_NOTHROW +uint qHash(float key, uint seed) noexcept { return key != 0.0f ? hash(reinterpret_cast<const uchar *>(&key), sizeof(key), seed) : seed ; } @@ -948,7 +948,7 @@ uint qHash(float key, uint seed) Q_DECL_NOTHROW Returns the hash value for the \a key, using \a seed to seed the calculation. */ -uint qHash(double key, uint seed) Q_DECL_NOTHROW +uint qHash(double key, uint seed) noexcept { return key != 0.0 ? hash(reinterpret_cast<const uchar *>(&key), sizeof(key), seed) : seed ; } @@ -959,7 +959,7 @@ uint qHash(double key, uint seed) Q_DECL_NOTHROW Returns the hash value for the \a key, using \a seed to seed the calculation. */ -uint qHash(long double key, uint seed) Q_DECL_NOTHROW +uint qHash(long double key, uint seed) noexcept { return key != 0.0L ? hash(reinterpret_cast<const uchar *>(&key), sizeof(key), seed) : seed ; } diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index a586ca5671..120ee9cc85 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -240,7 +240,7 @@ class QHash static inline int alignOfNode() { return qMax<int>(sizeof(void*), Q_ALIGNOF(Node)); } public: - inline QHash() Q_DECL_NOTHROW : d(const_cast<QHashData *>(&QHashData::shared_null)) { } + inline QHash() noexcept : 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)) @@ -255,11 +255,11 @@ public: QHash &operator=(const QHash &other); #ifdef Q_COMPILER_RVALUE_REFS - QHash(QHash &&other) Q_DECL_NOTHROW : d(other.d) { other.d = const_cast<QHashData *>(&QHashData::shared_null); } - QHash &operator=(QHash &&other) Q_DECL_NOTHROW + QHash(QHash &&other) noexcept : d(other.d) { other.d = const_cast<QHashData *>(&QHashData::shared_null); } + QHash &operator=(QHash &&other) noexcept { QHash moved(std::move(other)); swap(moved); return *this; } #endif - void swap(QHash &other) Q_DECL_NOTHROW { qSwap(d, other.d); } + void swap(QHash &other) noexcept { qSwap(d, other.d); } bool operator==(const QHash &other) const; bool operator!=(const QHash &other) const { return !(*this == other); } @@ -473,7 +473,7 @@ public: inline const_key_value_iterator constKeyValueEnd() const { return const_key_value_iterator(end()); } QPair<iterator, iterator> equal_range(const Key &key); - QPair<const_iterator, const_iterator> equal_range(const Key &key) const Q_DECL_NOTHROW; + QPair<const_iterator, const_iterator> equal_range(const Key &key) const noexcept; iterator erase(iterator it) { return erase(const_iterator(it.i)); } iterator erase(const_iterator it); @@ -512,11 +512,11 @@ private: static void duplicateNode(QHashData::Node *originalNode, void *newNode); - bool isValidIterator(const iterator &it) const Q_DECL_NOTHROW + bool isValidIterator(const iterator &it) const noexcept { return isValidNode(it.i); } - bool isValidIterator(const const_iterator &it) const Q_DECL_NOTHROW + bool isValidIterator(const const_iterator &it) const noexcept { return isValidNode(it.i); } - bool isValidNode(QHashData::Node *node) const Q_DECL_NOTHROW + bool isValidNode(QHashData::Node *node) const noexcept { #if defined(QT_DEBUG) && !defined(Q_HASH_NO_ITERATOR_DEBUG) while (node->next) @@ -993,7 +993,7 @@ QPair<typename QHash<Key, T>::iterator, typename QHash<Key, T>::iterator> QHash< } template <class Key, class T> -QPair<typename QHash<Key, T>::const_iterator, typename QHash<Key, T>::const_iterator> QHash<Key, T>::equal_range(const Key &akey) const Q_DECL_NOTHROW +QPair<typename QHash<Key, T>::const_iterator, typename QHash<Key, T>::const_iterator> QHash<Key, T>::equal_range(const Key &akey) const noexcept { Node *node = *findNode(akey); const_iterator firstIt = const_iterator(node); @@ -1020,7 +1020,7 @@ template <class Key, class T> class QMultiHash : public QHash<Key, T> { public: - QMultiHash() Q_DECL_NOTHROW {} + QMultiHash() noexcept {} #ifdef Q_COMPILER_INITIALIZER_LISTS inline QMultiHash(std::initializer_list<std::pair<Key,T> > list) { @@ -1034,9 +1034,9 @@ public: QMultiHash(const QHash<Key, T> &other) : QHash<Key, T>(other) {} #ifdef Q_COMPILER_RVALUE_REFS - QMultiHash(QHash<Key, T> &&other) Q_DECL_NOTHROW : QHash<Key, T>(std::move(other)) {} + QMultiHash(QHash<Key, T> &&other) noexcept : QHash<Key, T>(std::move(other)) {} #endif - void swap(QMultiHash &other) Q_DECL_NOTHROW { QHash<Key, T>::swap(other); } // prevent QMultiHash<->QHash swaps + void swap(QMultiHash &other) noexcept { QHash<Key, T>::swap(other); } // prevent QMultiHash<->QHash swaps inline typename QHash<Key, T>::iterator replace(const Key &key, const T &value) { return QHash<Key, T>::insert(key, value); } @@ -1130,7 +1130,7 @@ Q_DECLARE_MUTABLE_ASSOCIATIVE_ITERATOR(Hash) template <class Key, class T> uint qHash(const QHash<Key, T> &key, uint seed = 0) - Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(std::declval<Key&>())) && noexcept(qHash(std::declval<T&>()))) + noexcept(noexcept(qHash(std::declval<Key&>())) && noexcept(qHash(std::declval<T&>()))) { QtPrivate::QHashCombineCommutative hash; for (auto it = key.begin(), end = key.end(); it != end; ++it) { @@ -1143,7 +1143,7 @@ uint qHash(const QHash<Key, T> &key, uint seed = 0) template <class Key, class T> inline uint qHash(const QMultiHash<Key, T> &key, uint seed = 0) - Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(std::declval<Key&>())) && noexcept(qHash(std::declval<T&>()))) + noexcept(noexcept(qHash(std::declval<Key&>())) && noexcept(qHash(std::declval<T&>()))) { const QHash<Key, T> &key2 = key; return qHash(key2, seed); diff --git a/src/corelib/tools/qhashfunctions.h b/src/corelib/tools/qhashfunctions.h index d013c26d66..5e714806ff 100644 --- a/src/corelib/tools/qhashfunctions.h +++ b/src/corelib/tools/qhashfunctions.h @@ -67,54 +67,54 @@ class QLatin1String; Q_CORE_EXPORT int qGlobalQHashSeed(); Q_CORE_EXPORT void qSetGlobalQHashSeed(int newSeed); -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHashBits(const void *p, size_t size, uint seed = 0) Q_DECL_NOTHROW; - -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(char key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(uchar key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(signed char key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(ushort key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(short key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(uint key, uint seed = 0) Q_DECL_NOTHROW { return key ^ seed; } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(int key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(ulong key, uint seed = 0) Q_DECL_NOTHROW +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHashBits(const void *p, size_t size, uint seed = 0) noexcept; + +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(char key, uint seed = 0) noexcept { return uint(key) ^ seed; } +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(uchar key, uint seed = 0) noexcept { return uint(key) ^ seed; } +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(signed char key, uint seed = 0) noexcept { return uint(key) ^ seed; } +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(ushort key, uint seed = 0) noexcept { return uint(key) ^ seed; } +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(short key, uint seed = 0) noexcept { return uint(key) ^ seed; } +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(uint key, uint seed = 0) noexcept { return key ^ seed; } +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(int key, uint seed = 0) noexcept { return uint(key) ^ seed; } +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(ulong key, uint seed = 0) noexcept { return (sizeof(ulong) > sizeof(uint)) ? (uint(((key >> (8 * sizeof(uint) - 1)) ^ key) & (~0U)) ^ seed) : (uint(key & (~0U)) ^ seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(long key, uint seed = 0) Q_DECL_NOTHROW { return qHash(ulong(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(quint64 key, uint seed = 0) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(long key, uint seed = 0) noexcept { return qHash(ulong(key), seed); } +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(quint64 key, uint seed = 0) noexcept { return uint(((key >> (8 * sizeof(uint) - 1)) ^ key) & (~0U)) ^ seed; } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(qint64 key, uint seed = 0) Q_DECL_NOTHROW { return qHash(quint64(key), seed); } -Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(float key, uint seed = 0) Q_DECL_NOTHROW; -Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(double key, uint seed = 0) Q_DECL_NOTHROW; +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(qint64 key, uint seed = 0) noexcept { return qHash(quint64(key), seed); } +Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(float key, uint seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(double key, uint seed = 0) noexcept; #if !defined(Q_OS_DARWIN) || defined(Q_CLANG_QDOC) -Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(long double key, uint seed = 0) Q_DECL_NOTHROW; +Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(long double key, uint seed = 0) noexcept; #endif -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(const QChar key, uint seed = 0) Q_DECL_NOTHROW { return qHash(key.unicode(), seed); } -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QByteArray &key, uint seed = 0) Q_DECL_NOTHROW; +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(const QChar key, uint seed = 0) noexcept { return qHash(key.unicode(), seed); } +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QByteArray &key, uint seed = 0) noexcept; #if QT_STRINGVIEW_LEVEL < 2 -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QString &key, uint seed = 0) Q_DECL_NOTHROW; -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QStringRef &key, uint seed = 0) Q_DECL_NOTHROW; +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QString &key, uint seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QStringRef &key, uint seed = 0) noexcept; #endif -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(QStringView key, uint seed = 0) Q_DECL_NOTHROW; -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QBitArray &key, uint seed = 0) Q_DECL_NOTHROW; -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(QLatin1String key, uint seed = 0) Q_DECL_NOTHROW; -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qt_hash(QStringView key, uint chained = 0) Q_DECL_NOTHROW; +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(QStringView key, uint seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QBitArray &key, uint seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(QLatin1String key, uint seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qt_hash(QStringView key, uint chained = 0) noexcept; -Q_DECL_CONST_FUNCTION inline uint qHash(std::nullptr_t, uint seed = 0) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION inline uint qHash(std::nullptr_t, uint seed = 0) noexcept { return qHash(reinterpret_cast<quintptr>(nullptr), seed); } -template <class T> inline uint qHash(const T *key, uint seed = 0) Q_DECL_NOTHROW +template <class T> inline uint qHash(const T *key, uint seed = 0) noexcept { return qHash(reinterpret_cast<quintptr>(key), seed); } template<typename T> inline uint qHash(const T &t, uint seed) - Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(t))) + noexcept(noexcept(qHash(t))) { return qHash(t) ^ seed; } namespace QtPrivate { @@ -122,7 +122,7 @@ namespace QtPrivate { struct QHashCombine { typedef uint result_type; template <typename T> - Q_DECL_CONSTEXPR result_type operator()(uint seed, const T &t) const Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(t))) + Q_DECL_CONSTEXPR result_type operator()(uint seed, const T &t) const noexcept(noexcept(qHash(t))) // combiner taken from N3876 / boost::hash_combine { return seed ^ (qHash(t) + 0x9e3779b9 + (seed << 6) + (seed >> 2)) ; } }; @@ -135,7 +135,7 @@ struct QHashCombineCommutative { // QHash). Therefore, provide a commutative combiner, too. typedef uint result_type; template <typename T> - Q_DECL_CONSTEXPR result_type operator()(uint seed, const T &t) const Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(t))) + Q_DECL_CONSTEXPR result_type operator()(uint seed, const T &t) const noexcept(noexcept(qHash(t))) { return seed + qHash(t); } // don't use xor! }; @@ -143,20 +143,20 @@ struct QHashCombineCommutative { template <typename InputIterator> inline uint qHashRange(InputIterator first, InputIterator last, uint seed = 0) - Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(*first))) // assume iterator operations don't throw + noexcept(noexcept(qHash(*first))) // assume iterator operations don't throw { return std::accumulate(first, last, seed, QtPrivate::QHashCombine()); } template <typename InputIterator> inline uint qHashRangeCommutative(InputIterator first, InputIterator last, uint seed = 0) - Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(*first))) // assume iterator operations don't throw + noexcept(noexcept(qHash(*first))) // assume iterator operations don't throw { return std::accumulate(first, last, seed, QtPrivate::QHashCombineCommutative()); } template <typename T1, typename T2> inline uint qHash(const QPair<T1, T2> &key, uint seed = 0) - Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(key.first, seed)) && noexcept(qHash(key.second, seed))) + noexcept(noexcept(qHash(key.first, seed)) && noexcept(qHash(key.second, seed))) { uint h1 = qHash(key.first, seed); uint h2 = qHash(key.second, seed); @@ -164,7 +164,7 @@ template <typename T1, typename T2> inline uint qHash(const QPair<T1, T2> &key, } template <typename T1, typename T2> inline uint qHash(const std::pair<T1, T2> &key, uint seed = 0) - Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(key.first, seed)) && noexcept(qHash(key.second, seed))) + noexcept(noexcept(qHash(key.first, seed)) && noexcept(qHash(key.second, seed))) { QtPrivate::QHashCombine hash; seed = hash(seed, key.first); diff --git a/src/corelib/tools/qiterator.h b/src/corelib/tools/qiterator.h index 586d26cbad..82212c3eb5 100644 --- a/src/corelib/tools/qiterator.h +++ b/src/corelib/tools/qiterator.h @@ -190,15 +190,15 @@ public: typedef const value_type &reference; QKeyValueIterator() = default; - Q_DECL_CONSTEXPR explicit QKeyValueIterator(Iterator o) Q_DECL_NOEXCEPT_EXPR(std::is_nothrow_move_constructible<Iterator>::value) + Q_DECL_CONSTEXPR explicit QKeyValueIterator(Iterator o) noexcept(std::is_nothrow_move_constructible<Iterator>::value) : i(std::move(o)) {} std::pair<Key, T> operator*() const { return std::pair<Key, T>(i.key(), i.value()); } - friend bool operator==(QKeyValueIterator lhs, QKeyValueIterator rhs) Q_DECL_NOEXCEPT { return lhs.i == rhs.i; } - friend bool operator!=(QKeyValueIterator lhs, QKeyValueIterator rhs) Q_DECL_NOEXCEPT { return lhs.i != rhs.i; } + friend bool operator==(QKeyValueIterator lhs, QKeyValueIterator rhs) noexcept { return lhs.i == rhs.i; } + friend bool operator!=(QKeyValueIterator lhs, QKeyValueIterator rhs) noexcept { return lhs.i != rhs.i; } inline QKeyValueIterator &operator++() { ++i; return *this; } inline QKeyValueIterator operator++(int) { return QKeyValueIterator(i++);} diff --git a/src/corelib/tools/qline.cpp b/src/corelib/tools/qline.cpp index 949f63ea15..6f3c22a6ec 100644 --- a/src/corelib/tools/qline.cpp +++ b/src/corelib/tools/qline.cpp @@ -805,6 +805,7 @@ qreal QLineF::angleTo(const QLineF &l) const return delta_normalized; } +#if QT_DEPRECATED_SINCE(5, 14) /*! \fn qreal QLineF::angle(const QLineF &line) const @@ -837,6 +838,7 @@ qreal QLineF::angle(const QLineF &l) const if (cos_line >= -1.0 && cos_line <= 1.0) rad = qAcos( cos_line ); return rad * 360 / M_2PI; } +#endif #ifndef QT_NO_DEBUG_STREAM diff --git a/src/corelib/tools/qline.h b/src/corelib/tools/qline.h index 6361c1af9f..14980b60a0 100644 --- a/src/corelib/tools/qline.h +++ b/src/corelib/tools/qline.h @@ -251,7 +251,10 @@ public: // ### Qt 6: rename intersects() or intersection() and rename IntersectType IntersectionType IntersectType intersect(const QLineF &l, QPointF *intersectionPoint) const; +#if QT_DEPRECATED_SINCE(5, 14) + QT_DEPRECATED_X("Use angleTo() instead, take care that the return value is between 0 and 360 degree.") qreal angle(const QLineF &l) const; +#endif Q_DECL_CONSTEXPR inline QPointF pointAt(qreal t) const; inline void translate(const QPointF &p); diff --git a/src/corelib/tools/qlinkedlist.cpp b/src/corelib/tools/qlinkedlist.cpp index d9d93862e5..c0450f5cd8 100644 --- a/src/corelib/tools/qlinkedlist.cpp +++ b/src/corelib/tools/qlinkedlist.cpp @@ -153,6 +153,14 @@ const QLinkedListData QLinkedListData::shared_null = { initializer lists. */ +/*! \fn template <class T> template<typename InputIterator> QLinkedList<T>::QLinkedList(InputIterator first, InputIterator last) + \since 5.14 + + Constructs a list with the contents in the iterator range [\a first, \a last). + + The value type of \c InputIterator must be convertible to \c T. +*/ + /*! \fn template <class T> QLinkedList<T>::~QLinkedList() Destroys the list. References to the values in the list, and all diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h index 1e6d4df474..83f70deceb 100644 --- a/src/corelib/tools/qlinkedlist.h +++ b/src/corelib/tools/qlinkedlist.h @@ -42,6 +42,7 @@ #include <QtCore/qiterator.h> #include <QtCore/qrefcount.h> +#include <QtCore/qcontainertools_impl.h> #include <iterator> #include <list> @@ -80,24 +81,27 @@ class QLinkedList union { QLinkedListData *d; QLinkedListNode<T> *e; }; public: - inline QLinkedList() Q_DECL_NOTHROW : d(const_cast<QLinkedListData *>(&QLinkedListData::shared_null)) { } + inline QLinkedList() noexcept : d(const_cast<QLinkedListData *>(&QLinkedListData::shared_null)) { } inline QLinkedList(const QLinkedList<T> &l) : d(l.d) { d->ref.ref(); if (!d->sharable) detach(); } #if defined(Q_COMPILER_INITIALIZER_LISTS) inline QLinkedList(std::initializer_list<T> list) - : d(const_cast<QLinkedListData *>(&QLinkedListData::shared_null)) + : QLinkedList(list.begin(), list.end()) {} +#endif + template <typename InputIterator, QtPrivate::IfIsInputIterator<InputIterator> = true> + inline QLinkedList(InputIterator first, InputIterator last) + : QLinkedList() { - std::copy(list.begin(), list.end(), std::back_inserter(*this)); + std::copy(first, last, std::back_inserter(*this)); } -#endif ~QLinkedList(); QLinkedList<T> &operator=(const QLinkedList<T> &); #ifdef Q_COMPILER_RVALUE_REFS - QLinkedList(QLinkedList<T> &&other) Q_DECL_NOTHROW + QLinkedList(QLinkedList<T> &&other) noexcept : d(other.d) { other.d = const_cast<QLinkedListData *>(&QLinkedListData::shared_null); } - QLinkedList<T> &operator=(QLinkedList<T> &&other) Q_DECL_NOTHROW + QLinkedList<T> &operator=(QLinkedList<T> &&other) noexcept { QLinkedList moved(std::move(other)); swap(moved); return *this; } #endif - inline void swap(QLinkedList<T> &other) Q_DECL_NOTHROW { qSwap(d, other.d); } + inline void swap(QLinkedList<T> &other) noexcept { qSwap(d, other.d); } bool operator==(const QLinkedList<T> &l) const; inline bool operator!=(const QLinkedList<T> &l) const { return !(*this == l); } @@ -137,10 +141,10 @@ public: inline iterator() : i(nullptr) {} inline iterator(Node *n) : i(n) {} #if QT_VERSION < QT_VERSION_CHECK(6,0,0) - iterator(const iterator &other) Q_DECL_NOTHROW : i(other.i) {} - iterator &operator=(const iterator &other) Q_DECL_NOTHROW { i = other.i; return *this; } - iterator(iterator &&other) Q_DECL_NOTHROW : i(other.i) {} - iterator &operator=(iterator &&other) Q_DECL_NOTHROW { return *this = other; } + iterator(const iterator &other) noexcept : i(other.i) {} + iterator &operator=(const iterator &other) noexcept { i = other.i; return *this; } + iterator(iterator &&other) noexcept : i(other.i) {} + iterator &operator=(iterator &&other) noexcept { return *this = other; } #endif inline T &operator*() const { return i->t; } inline T *operator->() const { return &i->t; } @@ -176,10 +180,10 @@ public: inline const_iterator(Node *n) : i(n) {} inline const_iterator(iterator ci) : i(ci.i){} #if QT_VERSION < QT_VERSION_CHECK(6,0,0) - const_iterator(const const_iterator &other) Q_DECL_NOTHROW : i(other.i) {} - const_iterator &operator=(const const_iterator &other) Q_DECL_NOTHROW { i = other.i; return *this; } - const_iterator(const_iterator &&other) Q_DECL_NOTHROW : i(other.i) {} - const_iterator &operator=(const_iterator &&other) Q_DECL_NOTHROW { return *this = other; } + const_iterator(const const_iterator &other) noexcept : i(other.i) {} + const_iterator &operator=(const const_iterator &other) noexcept { i = other.i; return *this; } + const_iterator(const_iterator &&other) noexcept : i(other.i) {} + const_iterator &operator=(const_iterator &&other) noexcept { return *this = other; } #endif inline const T &operator*() const { return i->t; } inline const T *operator->() const { return &i->t; } @@ -203,20 +207,20 @@ public: typedef std::reverse_iterator<const_iterator> const_reverse_iterator; inline iterator begin() { detach(); return e->n; } - inline const_iterator begin() const Q_DECL_NOTHROW { return e->n; } - inline const_iterator cbegin() const Q_DECL_NOTHROW { return e->n; } - inline const_iterator constBegin() const Q_DECL_NOTHROW { return e->n; } + inline const_iterator begin() const noexcept { return e->n; } + inline const_iterator cbegin() const noexcept { return e->n; } + inline const_iterator constBegin() const noexcept { return e->n; } inline iterator end() { detach(); return e; } - inline const_iterator end() const Q_DECL_NOTHROW { return e; } - inline const_iterator cend() const Q_DECL_NOTHROW { return e; } - inline const_iterator constEnd() const Q_DECL_NOTHROW { return e; } + inline const_iterator end() const noexcept { return e; } + inline const_iterator cend() const noexcept { return e; } + inline const_iterator constEnd() const noexcept { return e; } reverse_iterator rbegin() { return reverse_iterator(end()); } reverse_iterator rend() { return reverse_iterator(begin()); } - const_reverse_iterator rbegin() const Q_DECL_NOTHROW { return const_reverse_iterator(end()); } - const_reverse_iterator rend() const Q_DECL_NOTHROW { return const_reverse_iterator(begin()); } - const_reverse_iterator crbegin() const Q_DECL_NOTHROW { return const_reverse_iterator(end()); } - const_reverse_iterator crend() const Q_DECL_NOTHROW { return const_reverse_iterator(begin()); } + const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } + const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } + const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } iterator insert(iterator before, const T &t); iterator erase(iterator pos); diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp index 6f8084c676..48617f0539 100644 --- a/src/corelib/tools/qlist.cpp +++ b/src/corelib/tools/qlist.cpp @@ -545,6 +545,14 @@ void **QListData::erase(void **xi) \since 5.2 */ +/*! \fn template <class T> template<typename InputIterator> QList<T>::QList(InputIterator first, InputIterator last) + \since 5.14 + + Constructs a QList with the contents in the iterator range [\a first, \a last). + + The value type of \c InputIterator must be convertible to \c T. +*/ + /*! \fn template <class T> QList<T> QList<T>::mid(int pos, int length) const diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 6643288bd5..dfb8a8a4ab 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -46,6 +46,7 @@ #include <QtCore/qarraydata.h> #include <QtCore/qhashfunctions.h> #include <QtCore/qvector.h> +#include <QtCore/qcontainertools_impl.h> #include <iterator> #include <list> @@ -111,11 +112,11 @@ struct Q_CORE_EXPORT QListData { void remove(int i); void remove(int i, int n); void move(int from, int to); - inline int size() const Q_DECL_NOTHROW { return d->end - d->begin; } - inline bool isEmpty() const Q_DECL_NOTHROW { return d->end == d->begin; } - inline void **at(int i) const Q_DECL_NOTHROW { return d->array + d->begin + i; } - inline void **begin() const Q_DECL_NOTHROW { return d->array + d->begin; } - inline void **end() const Q_DECL_NOTHROW { return d->array + d->end; } + inline int size() const noexcept { return d->end - d->begin; } + inline bool isEmpty() const noexcept { return d->end == d->begin; } + inline void **at(int i) const noexcept { return d->array + d->begin + i; } + inline void **begin() const noexcept { return d->array + d->begin; } + inline void **end() const noexcept { return d->array + d->end; } }; namespace QtPrivate { @@ -156,26 +157,28 @@ private: union { QListData p; QListData::Data *d; }; public: - inline QList() Q_DECL_NOTHROW : d(const_cast<QListData::Data *>(&QListData::shared_null)) { } + inline QList() noexcept : d(const_cast<QListData::Data *>(&QListData::shared_null)) { } QList(const QList<T> &l); ~QList(); QList<T> &operator=(const QList<T> &l); #ifdef Q_COMPILER_RVALUE_REFS - inline QList(QList<T> &&other) Q_DECL_NOTHROW + inline QList(QList<T> &&other) noexcept : d(other.d) { other.d = const_cast<QListData::Data *>(&QListData::shared_null); } - inline QList &operator=(QList<T> &&other) Q_DECL_NOTHROW + inline QList &operator=(QList<T> &&other) noexcept { QList moved(std::move(other)); swap(moved); return *this; } #endif - inline void swap(QList<T> &other) Q_DECL_NOTHROW { qSwap(d, other.d); } + inline void swap(QList<T> &other) noexcept { qSwap(d, other.d); } #ifdef Q_COMPILER_INITIALIZER_LISTS inline QList(std::initializer_list<T> args) - : d(const_cast<QListData::Data *>(&QListData::shared_null)) - { reserve(int(args.size())); std::copy(args.begin(), args.end(), std::back_inserter(*this)); } + : QList(args.begin(), args.end()) {} #endif + template <typename InputIterator, QtPrivate::IfIsInputIterator<InputIterator> = true> + QList(InputIterator first, InputIterator last); + bool operator==(const QList<T> &l) const; inline bool operator!=(const QList<T> &l) const { return !(*this == l); } - inline int size() const Q_DECL_NOTHROW { return p.size(); } + inline int size() const noexcept { return p.size(); } inline void detach() { if (d->ref.isShared()) detach_helper(); } @@ -198,9 +201,9 @@ public: d->ref.setSharable(sharable); } #endif - inline bool isSharedWith(const QList<T> &other) const Q_DECL_NOTHROW { return d == other.d; } + inline bool isSharedWith(const QList<T> &other) const noexcept { return d == other.d; } - inline bool isEmpty() const Q_DECL_NOTHROW { return p.isEmpty(); } + inline bool isEmpty() const noexcept { return p.isEmpty(); } void clear(); @@ -243,34 +246,34 @@ public: typedef T *pointer; typedef T &reference; - inline iterator() Q_DECL_NOTHROW : i(nullptr) {} - inline iterator(Node *n) Q_DECL_NOTHROW : i(n) {} + inline iterator() noexcept : i(nullptr) {} + inline iterator(Node *n) noexcept : i(n) {} #if QT_VERSION < QT_VERSION_CHECK(6,0,0) // can't remove it in Qt 5, since doing so would make the type trivial, // which changes the way it's passed to functions by value. - inline iterator(const iterator &o) Q_DECL_NOTHROW : i(o.i){} + inline iterator(const iterator &o) noexcept : i(o.i){} #endif inline T &operator*() const { return i->t(); } inline T *operator->() const { return &i->t(); } inline T &operator[](difference_type j) const { return i[j].t(); } - inline bool operator==(const iterator &o) const Q_DECL_NOTHROW { return i == o.i; } - inline bool operator!=(const iterator &o) const Q_DECL_NOTHROW { return i != o.i; } - inline bool operator<(const iterator& other) const Q_DECL_NOTHROW { return i < other.i; } - inline bool operator<=(const iterator& other) const Q_DECL_NOTHROW { return i <= other.i; } - inline bool operator>(const iterator& other) const Q_DECL_NOTHROW { return i > other.i; } - inline bool operator>=(const iterator& other) const Q_DECL_NOTHROW { return i >= other.i; } + inline bool operator==(const iterator &o) const noexcept { return i == o.i; } + inline bool operator!=(const iterator &o) const noexcept { return i != o.i; } + inline bool operator<(const iterator& other) const noexcept { return i < other.i; } + inline bool operator<=(const iterator& other) const noexcept { return i <= other.i; } + inline bool operator>(const iterator& other) const noexcept { return i > other.i; } + inline bool operator>=(const iterator& other) const noexcept { return i >= other.i; } #ifndef QT_STRICT_ITERATORS - inline bool operator==(const const_iterator &o) const Q_DECL_NOTHROW + inline bool operator==(const const_iterator &o) const noexcept { return i == o.i; } - inline bool operator!=(const const_iterator &o) const Q_DECL_NOTHROW + inline bool operator!=(const const_iterator &o) const noexcept { return i != o.i; } - inline bool operator<(const const_iterator& other) const Q_DECL_NOTHROW + inline bool operator<(const const_iterator& other) const noexcept { return i < other.i; } - inline bool operator<=(const const_iterator& other) const Q_DECL_NOTHROW + inline bool operator<=(const const_iterator& other) const noexcept { return i <= other.i; } - inline bool operator>(const const_iterator& other) const Q_DECL_NOTHROW + inline bool operator>(const const_iterator& other) const noexcept { return i > other.i; } - inline bool operator>=(const const_iterator& other) const Q_DECL_NOTHROW + inline bool operator>=(const const_iterator& other) const noexcept { return i >= other.i; } #endif inline iterator &operator++() { ++i; return *this; } @@ -296,27 +299,27 @@ public: typedef const T *pointer; typedef const T &reference; - inline const_iterator() Q_DECL_NOTHROW : i(nullptr) {} - inline const_iterator(Node *n) Q_DECL_NOTHROW : i(n) {} + inline const_iterator() noexcept : i(nullptr) {} + inline const_iterator(Node *n) noexcept : i(n) {} #if QT_VERSION < QT_VERSION_CHECK(6,0,0) // can't remove it in Qt 5, since doing so would make the type trivial, // which changes the way it's passed to functions by value. - inline const_iterator(const const_iterator &o) Q_DECL_NOTHROW : i(o.i) {} + inline const_iterator(const const_iterator &o) noexcept : i(o.i) {} #endif #ifdef QT_STRICT_ITERATORS - inline explicit const_iterator(const iterator &o) Q_DECL_NOTHROW : i(o.i) {} + inline explicit const_iterator(const iterator &o) noexcept : i(o.i) {} #else - inline const_iterator(const iterator &o) Q_DECL_NOTHROW : i(o.i) {} + inline const_iterator(const iterator &o) noexcept : i(o.i) {} #endif inline const T &operator*() const { return i->t(); } inline const T *operator->() const { return &i->t(); } inline const T &operator[](difference_type j) const { return i[j].t(); } - inline bool operator==(const const_iterator &o) const Q_DECL_NOTHROW { return i == o.i; } - inline bool operator!=(const const_iterator &o) const Q_DECL_NOTHROW { return i != o.i; } - inline bool operator<(const const_iterator& other) const Q_DECL_NOTHROW { return i < other.i; } - inline bool operator<=(const const_iterator& other) const Q_DECL_NOTHROW { return i <= other.i; } - inline bool operator>(const const_iterator& other) const Q_DECL_NOTHROW { return i > other.i; } - inline bool operator>=(const const_iterator& other) const Q_DECL_NOTHROW { return i >= other.i; } + inline bool operator==(const const_iterator &o) const noexcept { return i == o.i; } + inline bool operator!=(const const_iterator &o) const noexcept { return i != o.i; } + inline bool operator<(const const_iterator& other) const noexcept { return i < other.i; } + inline bool operator<=(const const_iterator& other) const noexcept { return i <= other.i; } + inline bool operator>(const const_iterator& other) const noexcept { return i > other.i; } + inline bool operator>=(const const_iterator& other) const noexcept { return i >= other.i; } inline const_iterator &operator++() { ++i; return *this; } inline const_iterator operator++(int) { Node *n = i; ++i; return n; } inline const_iterator &operator--() { i--; return *this; } @@ -334,19 +337,19 @@ public: typedef std::reverse_iterator<iterator> reverse_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator; inline iterator begin() { detach(); return reinterpret_cast<Node *>(p.begin()); } - inline const_iterator begin() const Q_DECL_NOTHROW { return reinterpret_cast<Node *>(p.begin()); } - inline const_iterator cbegin() const Q_DECL_NOTHROW { return reinterpret_cast<Node *>(p.begin()); } - inline const_iterator constBegin() const Q_DECL_NOTHROW { return reinterpret_cast<Node *>(p.begin()); } + inline const_iterator begin() const noexcept { return reinterpret_cast<Node *>(p.begin()); } + inline const_iterator cbegin() const noexcept { return reinterpret_cast<Node *>(p.begin()); } + inline const_iterator constBegin() const noexcept { return reinterpret_cast<Node *>(p.begin()); } inline iterator end() { detach(); return reinterpret_cast<Node *>(p.end()); } - inline const_iterator end() const Q_DECL_NOTHROW { return reinterpret_cast<Node *>(p.end()); } - inline const_iterator cend() const Q_DECL_NOTHROW { return reinterpret_cast<Node *>(p.end()); } - inline const_iterator constEnd() const Q_DECL_NOTHROW { return reinterpret_cast<Node *>(p.end()); } + inline const_iterator end() const noexcept { return reinterpret_cast<Node *>(p.end()); } + inline const_iterator cend() const noexcept { return reinterpret_cast<Node *>(p.end()); } + inline const_iterator constEnd() const noexcept { return reinterpret_cast<Node *>(p.end()); } reverse_iterator rbegin() { return reverse_iterator(end()); } reverse_iterator rend() { return reverse_iterator(begin()); } - const_reverse_iterator rbegin() const Q_DECL_NOTHROW { return const_reverse_iterator(end()); } - const_reverse_iterator rend() const Q_DECL_NOTHROW { return const_reverse_iterator(begin()); } - const_reverse_iterator crbegin() const Q_DECL_NOTHROW { return const_reverse_iterator(end()); } - const_reverse_iterator crend() const Q_DECL_NOTHROW { return const_reverse_iterator(begin()); } + const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } + const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } + const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } iterator insert(iterator before, const T &t); iterator erase(iterator pos); iterator erase(iterator first, iterator last); @@ -423,7 +426,7 @@ private: void node_copy(Node *from, Node *to, Node *src); void node_destruct(Node *from, Node *to); - bool isValidIterator(const iterator &i) const Q_DECL_NOTHROW + bool isValidIterator(const iterator &i) const noexcept { const std::less<const Node *> less = {}; return !less(i.i, cbegin().i) && !less(cend().i, i.i); @@ -526,7 +529,7 @@ inline typename QList<T>::iterator QList<T>::insert(iterator before, const T &t) Q_ASSERT_X(isValidIterator(before), "QList::insert", "The specified iterator argument 'before' is invalid"); int iBefore = int(before.i - reinterpret_cast<Node *>(p.begin())); - Node *n = 0; + Node *n = nullptr; if (d->ref.isShared()) n = detach_helper_grow(iBefore, 1); else @@ -843,6 +846,15 @@ Q_OUTOFLINE_TEMPLATE QList<T>::~QList() } template <typename T> +template <typename InputIterator, QtPrivate::IfIsInputIterator<InputIterator>> +QList<T>::QList(InputIterator first, InputIterator last) + : QList() +{ + QtPrivate::reserveIfForwardIterator(this, first, last); + std::copy(first, last, std::back_inserter(*this)); +} + +template <typename T> Q_OUTOFLINE_TEMPLATE bool QList<T>::operator==(const QList<T> &l) const { if (d == l.d) @@ -1121,14 +1133,14 @@ Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(List) template <typename T> uint qHash(const QList<T> &key, uint seed = 0) - Q_DECL_NOEXCEPT_EXPR(noexcept(qHashRange(key.cbegin(), key.cend(), seed))) + noexcept(noexcept(qHashRange(key.cbegin(), key.cend(), seed))) { return qHashRange(key.cbegin(), key.cend(), seed); } template <typename T> bool operator<(const QList<T> &lhs, const QList<T> &rhs) - Q_DECL_NOEXCEPT_EXPR(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(), + noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()))) { return std::lexicographical_compare(lhs.begin(), lhs.end(), @@ -1137,21 +1149,21 @@ bool operator<(const QList<T> &lhs, const QList<T> &rhs) template <typename T> inline bool operator>(const QList<T> &lhs, const QList<T> &rhs) - Q_DECL_NOEXCEPT_EXPR(noexcept(lhs < rhs)) + noexcept(noexcept(lhs < rhs)) { return rhs < lhs; } template <typename T> inline bool operator<=(const QList<T> &lhs, const QList<T> &rhs) - Q_DECL_NOEXCEPT_EXPR(noexcept(lhs < rhs)) + noexcept(noexcept(lhs < rhs)) { return !(lhs > rhs); } template <typename T> inline bool operator>=(const QList<T> &lhs, const QList<T> &rhs) - Q_DECL_NOEXCEPT_EXPR(noexcept(lhs < rhs)) + noexcept(noexcept(lhs < rhs)) { return !(lhs < rhs); } diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index e55331a5f9..8e47d350d1 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -94,7 +94,7 @@ QT_BEGIN_INCLUDE_NAMESPACE #include "qlocale_data_p.h" QT_END_INCLUDE_NAMESPACE -QLocale::Language QLocalePrivate::codeToLanguage(QStringView code) Q_DECL_NOTHROW +QLocale::Language QLocalePrivate::codeToLanguage(QStringView code) noexcept { const auto len = code.size(); if (len != 2 && len != 3) @@ -138,7 +138,7 @@ QLocale::Language QLocalePrivate::codeToLanguage(QStringView code) Q_DECL_NOTHRO return QLocale::C; } -QLocale::Script QLocalePrivate::codeToScript(QStringView code) Q_DECL_NOTHROW +QLocale::Script QLocalePrivate::codeToScript(QStringView code) noexcept { const auto len = code.size(); if (len != 4) @@ -158,7 +158,7 @@ QLocale::Script QLocalePrivate::codeToScript(QStringView code) Q_DECL_NOTHROW return QLocale::AnyScript; } -QLocale::Country QLocalePrivate::codeToCountry(QStringView code) Q_DECL_NOTHROW +QLocale::Country QLocalePrivate::codeToCountry(QStringView code) noexcept { const auto len = code.size(); if (len != 2 && len != 3) @@ -982,7 +982,7 @@ bool QLocale::operator!=(const QLocale &other) const Returns the hash value for \a key, using \a seed to seed the calculation. */ -uint qHash(const QLocale &key, uint seed) Q_DECL_NOTHROW +uint qHash(const QLocale &key, uint seed) noexcept { QtPrivate::QHashCombine hash; seed = hash(seed, key.d->m_data); @@ -4143,6 +4143,29 @@ QStringList QLocale::uiLanguages() const } /*! + \since 5.13 + + Returns the locale to use for collation. + + The result is usually this locale; however, the system locale (which is + commonly the default locale) will return the system collation locale. + The result is suitable for passing to QCollator's constructor. + + \sa QCollator +*/ +QLocale QLocale::collation() const +{ +#ifndef QT_NO_SYSTEMLOCALE + if (d->m_data == systemData()) { + QString res = systemLocale()->query(QSystemLocale::Collation, QVariant()).toString(); + if (!res.isEmpty()) + return QLocale(res); + } +#endif + return *this; +} + +/*! \since 4.8 Returns a native name of the language for the locale. For example diff --git a/src/corelib/tools/qlocale.h b/src/corelib/tools/qlocale.h index 2b4f131552..3dc5ee0a01 100644 --- a/src/corelib/tools/qlocale.h +++ b/src/corelib/tools/qlocale.h @@ -59,7 +59,7 @@ class QTextStreamPrivate; class QLocalePrivate; -Q_CORE_EXPORT uint qHash(const QLocale &key, uint seed = 0) Q_DECL_NOTHROW; +Q_CORE_EXPORT uint qHash(const QLocale &key, uint seed = 0) noexcept; class Q_CORE_EXPORT QLocale { @@ -940,12 +940,12 @@ public: QLocale(Language language, Script script, Country country); QLocale(const QLocale &other); #ifdef Q_COMPILER_RVALUE_REFS - QLocale &operator=(QLocale &&other) Q_DECL_NOTHROW { swap(other); return *this; } + QLocale &operator=(QLocale &&other) noexcept { swap(other); return *this; } #endif QLocale &operator=(const QLocale &other); ~QLocale(); - void swap(QLocale &other) Q_DECL_NOTHROW { qSwap(d, other.d); } + void swap(QLocale &other) noexcept { qSwap(d, other.d); } Language language() const; Script script() const; @@ -1048,7 +1048,7 @@ public: QString pmText() const; MeasurementSystem measurementSystem() const; - + QLocale collation() const; Qt::LayoutDirection textDirection() const; QString toUpper(const QString &str) const; @@ -1108,7 +1108,7 @@ private: QLocale(QLocalePrivate &dd); friend class QLocalePrivate; friend class QSystemLocale; - friend Q_CORE_EXPORT uint qHash(const QLocale &key, uint seed) Q_DECL_NOTHROW; + friend Q_CORE_EXPORT uint qHash(const QLocale &key, uint seed) noexcept; QSharedDataPointer<QLocalePrivate> d; }; diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h index 70430beb00..16ded7650c 100644 --- a/src/corelib/tools/qlocale_p.h +++ b/src/corelib/tools/qlocale_p.h @@ -113,6 +113,7 @@ public: Weekdays, // QList<Qt::DayOfWeek> CurrencySymbol, // QString in: CurrencyToStringArgument CurrencyToString, // QString in: qlonglong, qulonglong or double + Collation, // QString UILanguages, // QStringList StringToStandardQuotation, // QString in: QStringRef to quote StringToAlternateQuotation, // QString in: QStringRef to quote @@ -249,7 +250,7 @@ public: if (qIsInf(d)) return float(d); if (std::fabs(d) > std::numeric_limits<float>::max()) { - if (ok != 0) + if (ok != nullptr) *ok = false; const float huge = std::numeric_limits<float>::infinity(); return d < 0 ? -huge : huge; @@ -365,9 +366,9 @@ public: static QLatin1String languageToCode(QLocale::Language language); static QLatin1String scriptToCode(QLocale::Script script); static QLatin1String countryToCode(QLocale::Country country); - static QLocale::Language codeToLanguage(QStringView code) Q_DECL_NOTHROW; - static QLocale::Script codeToScript(QStringView code) Q_DECL_NOTHROW; - static QLocale::Country codeToCountry(QStringView code) Q_DECL_NOTHROW; + static QLocale::Language codeToLanguage(QStringView code) noexcept; + static QLocale::Script codeToScript(QStringView code) noexcept; + static QLocale::Country codeToCountry(QStringView code) noexcept; static void getLangAndCountry(const QString &name, QLocale::Language &lang, QLocale::Script &script, QLocale::Country &cntry); diff --git a/src/corelib/tools/qlocale_unix.cpp b/src/corelib/tools/qlocale_unix.cpp index f202082213..ff4274d932 100644 --- a/src/corelib/tools/qlocale_unix.cpp +++ b/src/corelib/tools/qlocale_unix.cpp @@ -69,6 +69,7 @@ struct QSystemLocaleData QLocale lc_messages; QByteArray lc_messages_var; QByteArray lc_measurement_var; + QByteArray lc_collate_var; QStringList uiLanguages; }; @@ -82,6 +83,7 @@ void QSystemLocaleData::readEnvironment() QByteArray monetary = all.isEmpty() ? qgetenv("LC_MONETARY") : all; lc_messages_var = all.isEmpty() ? qgetenv("LC_MESSAGES") : all; lc_measurement_var = all.isEmpty() ? qgetenv("LC_MEASUREMENT") : all; + lc_collate_var = all.isEmpty() ? qgetenv("LC_COLLATE") : all; QByteArray lang = qgetenv("LANG"); if (lang.isEmpty()) lang = QByteArray("C"); @@ -95,6 +97,8 @@ void QSystemLocaleData::readEnvironment() lc_messages_var = lang; if (lc_measurement_var.isEmpty()) lc_measurement_var = lang; + if (lc_collate_var.isEmpty()) + lc_collate_var = lang; lc_numeric = QLocale(QString::fromLatin1(numeric)); lc_time = QLocale(QString::fromLatin1(time)); lc_monetary = QLocale(QString::fromLatin1(monetary)); @@ -247,13 +251,15 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const return QString(); } case MeasurementSystem: { - const QString meas_locale = QString::fromLatin1(d->lc_measurement_var.constData(), d->lc_measurement_var.size()); + const QString meas_locale = QString::fromLatin1(d->lc_measurement_var); if (meas_locale.compare(QLatin1String("Metric"), Qt::CaseInsensitive) == 0) return QLocale::MetricSystem; if (meas_locale.compare(QLatin1String("Other"), Qt::CaseInsensitive) == 0) return QLocale::MetricSystem; return QVariant((int)QLocale(meas_locale).measurementSystem()); } + case Collation: + return QString::fromLatin1(d->lc_collate_var); case UILanguages: { if (!d->uiLanguages.isEmpty()) return d->uiLanguages; diff --git a/src/corelib/tools/qlocale_win.cpp b/src/corelib/tools/qlocale_win.cpp index ebc4430046..dc904ad02d 100644 --- a/src/corelib/tools/qlocale_win.cpp +++ b/src/corelib/tools/qlocale_win.cpp @@ -120,6 +120,7 @@ struct QSystemLocalePrivate QVariant toString(const QTime &, QLocale::FormatType); QVariant toString(const QDateTime &, QLocale::FormatType); QVariant measurementSystem(); + QVariant collation(); QVariant amText(); QVariant pmText(); QVariant firstDayOfWeek(); @@ -455,6 +456,11 @@ QVariant QSystemLocalePrivate::measurementSystem() return QLocale::MetricSystem; } +QVariant QSystemLocalePrivate::collation() +{ + return getLocaleInfo(LOCALE_SSORTLOCALE); +} + QVariant QSystemLocalePrivate::amText() { wchar_t output[15]; // maximum length including terminating zero character for Win2003+ @@ -808,6 +814,8 @@ QVariant QSystemLocale::query(QueryType type, QVariant in = QVariant()) const return QVariant(QLocale::AnyScript); case MeasurementSystem: return d->measurementSystem(); + case Collation: + return d->collation(); case AMText: return d->amText(); case PMText: diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 1cf9299e26..103124f4ad 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -100,10 +100,10 @@ struct Q_CORE_EXPORT QMapNodeBase template <typename T> static typename std::enable_if<QTypeInfo<T>::isComplex>::type - callDestructorIfNecessary(T &t) Q_DECL_NOTHROW { Q_UNUSED(t); t.~T(); } // Q_UNUSED: silence MSVC unused 't' warning + callDestructorIfNecessary(T &t) noexcept { Q_UNUSED(t); t.~T(); } // Q_UNUSED: silence MSVC unused 't' warning template <typename T> static typename std::enable_if<!QTypeInfo<T>::isComplex>::type - callDestructorIfNecessary(T &) Q_DECL_NOTHROW {} + callDestructorIfNecessary(T &) noexcept {} }; template <class Key, class T> @@ -325,7 +325,7 @@ class QMap QMapData<Key, T> *d; public: - inline QMap() Q_DECL_NOTHROW : d(static_cast<QMapData<Key, T> *>(const_cast<QMapDataBase *>(&QMapDataBase::shared_null))) { } + inline QMap() noexcept : d(static_cast<QMapData<Key, T> *>(const_cast<QMapDataBase *>(&QMapDataBase::shared_null))) { } #ifdef Q_COMPILER_INITIALIZER_LISTS inline QMap(std::initializer_list<std::pair<Key,T> > list) : d(static_cast<QMapData<Key, T> *>(const_cast<QMapDataBase *>(&QMapDataBase::shared_null))) @@ -340,17 +340,17 @@ public: QMap<Key, T> &operator=(const QMap<Key, T> &other); #ifdef Q_COMPILER_RVALUE_REFS - inline QMap(QMap<Key, T> &&other) Q_DECL_NOTHROW + inline QMap(QMap<Key, T> &&other) noexcept : d(other.d) { other.d = static_cast<QMapData<Key, T> *>( const_cast<QMapDataBase *>(&QMapDataBase::shared_null)); } - inline QMap<Key, T> &operator=(QMap<Key, T> &&other) Q_DECL_NOTHROW + inline QMap<Key, T> &operator=(QMap<Key, T> &&other) noexcept { QMap moved(std::move(other)); swap(moved); return *this; } #endif - inline void swap(QMap<Key, T> &other) Q_DECL_NOTHROW { qSwap(d, other.d); } + inline void swap(QMap<Key, T> &other) noexcept { qSwap(d, other.d); } explicit QMap(const typename std::map<Key, T> &other); std::map<Key, T> toStdMap() const; @@ -1187,7 +1187,7 @@ template <class Key, class T> class QMultiMap : public QMap<Key, T> { public: - QMultiMap() Q_DECL_NOTHROW {} + QMultiMap() noexcept {} #ifdef Q_COMPILER_INITIALIZER_LISTS inline QMultiMap(std::initializer_list<std::pair<Key,T> > list) { @@ -1197,9 +1197,9 @@ public: #endif QMultiMap(const QMap<Key, T> &other) : QMap<Key, T>(other) {} #ifdef Q_COMPILER_RVALUE_REFS - QMultiMap(QMap<Key, T> &&other) Q_DECL_NOTHROW : QMap<Key, T>(std::move(other)) {} + QMultiMap(QMap<Key, T> &&other) noexcept : QMap<Key, T>(std::move(other)) {} #endif - void swap(QMultiMap<Key, T> &other) Q_DECL_NOTHROW { QMap<Key, T>::swap(other); } + void swap(QMultiMap<Key, T> &other) noexcept { QMap<Key, T>::swap(other); } inline typename QMap<Key, T>::iterator replace(const Key &key, const T &value) { return QMap<Key, T>::insert(key, value); } diff --git a/src/corelib/tools/qmargins.h b/src/corelib/tools/qmargins.h index 0c73235d26..447037daaa 100644 --- a/src/corelib/tools/qmargins.h +++ b/src/corelib/tools/qmargins.h @@ -51,28 +51,28 @@ QT_BEGIN_NAMESPACE class QMargins { public: - Q_DECL_CONSTEXPR QMargins() Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR QMargins(int left, int top, int right, int bottom) Q_DECL_NOTHROW; - - Q_DECL_CONSTEXPR bool isNull() const Q_DECL_NOTHROW; - - Q_DECL_CONSTEXPR int left() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR int top() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR int right() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR int bottom() const Q_DECL_NOTHROW; - - Q_DECL_RELAXED_CONSTEXPR void setLeft(int left) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR void setTop(int top) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR void setRight(int right) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR void setBottom(int bottom) Q_DECL_NOTHROW; - - Q_DECL_RELAXED_CONSTEXPR QMargins &operator+=(const QMargins &margins) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR QMargins &operator-=(const QMargins &margins) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR QMargins &operator+=(int) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR QMargins &operator-=(int) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR QMargins &operator*=(int) Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR QMargins() noexcept; + Q_DECL_CONSTEXPR QMargins(int left, int top, int right, int bottom) noexcept; + + Q_DECL_CONSTEXPR bool isNull() const noexcept; + + Q_DECL_CONSTEXPR int left() const noexcept; + Q_DECL_CONSTEXPR int top() const noexcept; + Q_DECL_CONSTEXPR int right() const noexcept; + Q_DECL_CONSTEXPR int bottom() const noexcept; + + Q_DECL_RELAXED_CONSTEXPR void setLeft(int left) noexcept; + Q_DECL_RELAXED_CONSTEXPR void setTop(int top) noexcept; + Q_DECL_RELAXED_CONSTEXPR void setRight(int right) noexcept; + Q_DECL_RELAXED_CONSTEXPR void setBottom(int bottom) noexcept; + + Q_DECL_RELAXED_CONSTEXPR QMargins &operator+=(const QMargins &margins) noexcept; + Q_DECL_RELAXED_CONSTEXPR QMargins &operator-=(const QMargins &margins) noexcept; + Q_DECL_RELAXED_CONSTEXPR QMargins &operator+=(int) noexcept; + Q_DECL_RELAXED_CONSTEXPR QMargins &operator-=(int) noexcept; + Q_DECL_RELAXED_CONSTEXPR QMargins &operator*=(int) noexcept; Q_DECL_RELAXED_CONSTEXPR QMargins &operator/=(int); - Q_DECL_RELAXED_CONSTEXPR QMargins &operator*=(qreal) Q_DECL_NOTHROW; + Q_DECL_RELAXED_CONSTEXPR QMargins &operator*=(qreal) noexcept; Q_DECL_RELAXED_CONSTEXPR QMargins &operator/=(qreal); private: @@ -81,8 +81,8 @@ private: int m_right; int m_bottom; - friend Q_DECL_CONSTEXPR inline bool operator==(const QMargins &, const QMargins &) Q_DECL_NOTHROW; - friend Q_DECL_CONSTEXPR inline bool operator!=(const QMargins &, const QMargins &) Q_DECL_NOTHROW; + friend Q_DECL_CONSTEXPR inline bool operator==(const QMargins &, const QMargins &) noexcept; + friend Q_DECL_CONSTEXPR inline bool operator!=(const QMargins &, const QMargins &) noexcept; }; Q_DECLARE_TYPEINFO(QMargins, Q_MOVABLE_TYPE); @@ -99,40 +99,40 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QMargins &); QMargins inline functions *****************************************************************************/ -Q_DECL_CONSTEXPR inline QMargins::QMargins() Q_DECL_NOTHROW : m_left(0), m_top(0), m_right(0), m_bottom(0) {} +Q_DECL_CONSTEXPR inline QMargins::QMargins() noexcept : m_left(0), m_top(0), m_right(0), m_bottom(0) {} -Q_DECL_CONSTEXPR inline QMargins::QMargins(int aleft, int atop, int aright, int abottom) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMargins::QMargins(int aleft, int atop, int aright, int abottom) noexcept : m_left(aleft), m_top(atop), m_right(aright), m_bottom(abottom) {} -Q_DECL_CONSTEXPR inline bool QMargins::isNull() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool QMargins::isNull() const noexcept { return m_left==0 && m_top==0 && m_right==0 && m_bottom==0; } -Q_DECL_CONSTEXPR inline int QMargins::left() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline int QMargins::left() const noexcept { return m_left; } -Q_DECL_CONSTEXPR inline int QMargins::top() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline int QMargins::top() const noexcept { return m_top; } -Q_DECL_CONSTEXPR inline int QMargins::right() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline int QMargins::right() const noexcept { return m_right; } -Q_DECL_CONSTEXPR inline int QMargins::bottom() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline int QMargins::bottom() const noexcept { return m_bottom; } -Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setLeft(int aleft) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setLeft(int aleft) noexcept { m_left = aleft; } -Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setTop(int atop) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setTop(int atop) noexcept { m_top = atop; } -Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setRight(int aright) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setRight(int aright) noexcept { m_right = aright; } -Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setBottom(int abottom) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setBottom(int abottom) noexcept { m_bottom = abottom; } -Q_DECL_CONSTEXPR inline bool operator==(const QMargins &m1, const QMargins &m2) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool operator==(const QMargins &m1, const QMargins &m2) noexcept { return m1.m_left == m2.m_left && @@ -141,7 +141,7 @@ Q_DECL_CONSTEXPR inline bool operator==(const QMargins &m1, const QMargins &m2) m1.m_bottom == m2.m_bottom; } -Q_DECL_CONSTEXPR inline bool operator!=(const QMargins &m1, const QMargins &m2) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool operator!=(const QMargins &m1, const QMargins &m2) noexcept { return m1.m_left != m2.m_left || @@ -150,55 +150,55 @@ Q_DECL_CONSTEXPR inline bool operator!=(const QMargins &m1, const QMargins &m2) m1.m_bottom != m2.m_bottom; } -Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &m1, const QMargins &m2) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &m1, const QMargins &m2) noexcept { return QMargins(m1.left() + m2.left(), m1.top() + m2.top(), m1.right() + m2.right(), m1.bottom() + m2.bottom()); } -Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &m1, const QMargins &m2) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &m1, const QMargins &m2) noexcept { return QMargins(m1.left() - m2.left(), m1.top() - m2.top(), m1.right() - m2.right(), m1.bottom() - m2.bottom()); } -Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &lhs, int rhs) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &lhs, int rhs) noexcept { return QMargins(lhs.left() + rhs, lhs.top() + rhs, lhs.right() + rhs, lhs.bottom() + rhs); } -Q_DECL_CONSTEXPR inline QMargins operator+(int lhs, const QMargins &rhs) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMargins operator+(int lhs, const QMargins &rhs) noexcept { return QMargins(rhs.left() + lhs, rhs.top() + lhs, rhs.right() + lhs, rhs.bottom() + lhs); } -Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &lhs, int rhs) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &lhs, int rhs) noexcept { return QMargins(lhs.left() - rhs, lhs.top() - rhs, lhs.right() - rhs, lhs.bottom() - rhs); } -Q_DECL_CONSTEXPR inline QMargins operator*(const QMargins &margins, int factor) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMargins operator*(const QMargins &margins, int factor) noexcept { return QMargins(margins.left() * factor, margins.top() * factor, margins.right() * factor, margins.bottom() * factor); } -Q_DECL_CONSTEXPR inline QMargins operator*(int factor, const QMargins &margins) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMargins operator*(int factor, const QMargins &margins) noexcept { return QMargins(margins.left() * factor, margins.top() * factor, margins.right() * factor, margins.bottom() * factor); } -Q_DECL_CONSTEXPR inline QMargins operator*(const QMargins &margins, qreal factor) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMargins operator*(const QMargins &margins, qreal factor) noexcept { return QMargins(qRound(margins.left() * factor), qRound(margins.top() * factor), qRound(margins.right() * factor), qRound(margins.bottom() * factor)); } -Q_DECL_CONSTEXPR inline QMargins operator*(qreal factor, const QMargins &margins) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMargins operator*(qreal factor, const QMargins &margins) noexcept { return QMargins(qRound(margins.left() * factor), qRound(margins.top() * factor), qRound(margins.right() * factor), qRound(margins.bottom() * factor)); @@ -216,17 +216,17 @@ Q_DECL_CONSTEXPR inline QMargins operator/(const QMargins &margins, qreal diviso qRound(margins.right() / divisor), qRound(margins.bottom() / divisor)); } -Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator+=(const QMargins &margins) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator+=(const QMargins &margins) noexcept { return *this = *this + margins; } -Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator-=(const QMargins &margins) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator-=(const QMargins &margins) noexcept { return *this = *this - margins; } -Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator+=(int margin) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator+=(int margin) noexcept { m_left += margin; m_top += margin; @@ -235,7 +235,7 @@ Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator+=(int margin) Q_DEC return *this; } -Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator-=(int margin) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator-=(int margin) noexcept { m_left -= margin; m_top -= margin; @@ -244,7 +244,7 @@ Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator-=(int margin) Q_DEC return *this; } -Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator*=(int factor) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator*=(int factor) noexcept { return *this = *this * factor; } @@ -254,7 +254,7 @@ Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator/=(int divisor) return *this = *this / divisor; } -Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator*=(qreal factor) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator*=(qreal factor) noexcept { return *this = *this * factor; } @@ -264,12 +264,12 @@ Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator/=(qreal divisor) return *this = *this / divisor; } -Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &margins) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &margins) noexcept { return margins; } -Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &margins) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &margins) noexcept { return QMargins(-margins.left(), -margins.top(), -margins.right(), -margins.bottom()); } @@ -285,30 +285,30 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QMargins &); class QMarginsF { public: - Q_DECL_CONSTEXPR QMarginsF() Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR QMarginsF(qreal left, qreal top, qreal right, qreal bottom) Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR QMarginsF(const QMargins &margins) Q_DECL_NOTHROW; - - Q_DECL_CONSTEXPR bool isNull() const Q_DECL_NOTHROW; - - Q_DECL_CONSTEXPR qreal left() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR qreal top() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR qreal right() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR qreal bottom() const Q_DECL_NOTHROW; - - Q_DECL_RELAXED_CONSTEXPR void setLeft(qreal left) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR void setTop(qreal top) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR void setRight(qreal right) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR void setBottom(qreal bottom) Q_DECL_NOTHROW; - - Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator+=(const QMarginsF &margins) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator-=(const QMarginsF &margins) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator+=(qreal addend) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator-=(qreal subtrahend) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator*=(qreal factor) Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR QMarginsF() noexcept; + Q_DECL_CONSTEXPR QMarginsF(qreal left, qreal top, qreal right, qreal bottom) noexcept; + Q_DECL_CONSTEXPR QMarginsF(const QMargins &margins) noexcept; + + Q_DECL_CONSTEXPR bool isNull() const noexcept; + + Q_DECL_CONSTEXPR qreal left() const noexcept; + Q_DECL_CONSTEXPR qreal top() const noexcept; + Q_DECL_CONSTEXPR qreal right() const noexcept; + Q_DECL_CONSTEXPR qreal bottom() const noexcept; + + Q_DECL_RELAXED_CONSTEXPR void setLeft(qreal left) noexcept; + Q_DECL_RELAXED_CONSTEXPR void setTop(qreal top) noexcept; + Q_DECL_RELAXED_CONSTEXPR void setRight(qreal right) noexcept; + Q_DECL_RELAXED_CONSTEXPR void setBottom(qreal bottom) noexcept; + + Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator+=(const QMarginsF &margins) noexcept; + Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator-=(const QMarginsF &margins) noexcept; + Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator+=(qreal addend) noexcept; + Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator-=(qreal subtrahend) noexcept; + Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator*=(qreal factor) noexcept; Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator/=(qreal divisor); - Q_DECL_CONSTEXPR inline QMargins toMargins() const Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR inline QMargins toMargins() const noexcept; private: qreal m_left; @@ -332,44 +332,44 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QMarginsF &); QMarginsF inline functions *****************************************************************************/ -Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF() Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF() noexcept : m_left(0), m_top(0), m_right(0), m_bottom(0) {} -Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(qreal aleft, qreal atop, qreal aright, qreal abottom) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(qreal aleft, qreal atop, qreal aright, qreal abottom) noexcept : m_left(aleft), m_top(atop), m_right(aright), m_bottom(abottom) {} -Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(const QMargins &margins) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(const QMargins &margins) noexcept : m_left(margins.left()), m_top(margins.top()), m_right(margins.right()), m_bottom(margins.bottom()) {} -Q_DECL_CONSTEXPR inline bool QMarginsF::isNull() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool QMarginsF::isNull() const noexcept { return qFuzzyIsNull(m_left) && qFuzzyIsNull(m_top) && qFuzzyIsNull(m_right) && qFuzzyIsNull(m_bottom); } -Q_DECL_CONSTEXPR inline qreal QMarginsF::left() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline qreal QMarginsF::left() const noexcept { return m_left; } -Q_DECL_CONSTEXPR inline qreal QMarginsF::top() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline qreal QMarginsF::top() const noexcept { return m_top; } -Q_DECL_CONSTEXPR inline qreal QMarginsF::right() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline qreal QMarginsF::right() const noexcept { return m_right; } -Q_DECL_CONSTEXPR inline qreal QMarginsF::bottom() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline qreal QMarginsF::bottom() const noexcept { return m_bottom; } -Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setLeft(qreal aleft) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setLeft(qreal aleft) noexcept { m_left = aleft; } -Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setTop(qreal atop) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setTop(qreal atop) noexcept { m_top = atop; } -Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setRight(qreal aright) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setRight(qreal aright) noexcept { m_right = aright; } -Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setBottom(qreal abottom) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setBottom(qreal abottom) noexcept { m_bottom = abottom; } -Q_DECL_CONSTEXPR inline bool operator==(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool operator==(const QMarginsF &lhs, const QMarginsF &rhs) noexcept { return qFuzzyCompare(lhs.left(), rhs.left()) && qFuzzyCompare(lhs.top(), rhs.top()) @@ -377,48 +377,48 @@ Q_DECL_CONSTEXPR inline bool operator==(const QMarginsF &lhs, const QMarginsF &r && qFuzzyCompare(lhs.bottom(), rhs.bottom()); } -Q_DECL_CONSTEXPR inline bool operator!=(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool operator!=(const QMarginsF &lhs, const QMarginsF &rhs) noexcept { return !operator==(lhs, rhs); } -Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, const QMarginsF &rhs) noexcept { return QMarginsF(lhs.left() + rhs.left(), lhs.top() + rhs.top(), lhs.right() + rhs.right(), lhs.bottom() + rhs.bottom()); } -Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, const QMarginsF &rhs) noexcept { return QMarginsF(lhs.left() - rhs.left(), lhs.top() - rhs.top(), lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom()); } -Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, qreal rhs) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, qreal rhs) noexcept { return QMarginsF(lhs.left() + rhs, lhs.top() + rhs, lhs.right() + rhs, lhs.bottom() + rhs); } -Q_DECL_CONSTEXPR inline QMarginsF operator+(qreal lhs, const QMarginsF &rhs) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMarginsF operator+(qreal lhs, const QMarginsF &rhs) noexcept { return QMarginsF(rhs.left() + lhs, rhs.top() + lhs, rhs.right() + lhs, rhs.bottom() + lhs); } -Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, qreal rhs) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, qreal rhs) noexcept { return QMarginsF(lhs.left() - rhs, lhs.top() - rhs, lhs.right() - rhs, lhs.bottom() - rhs); } -Q_DECL_CONSTEXPR inline QMarginsF operator*(const QMarginsF &lhs, qreal rhs) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMarginsF operator*(const QMarginsF &lhs, qreal rhs) noexcept { return QMarginsF(lhs.left() * rhs, lhs.top() * rhs, lhs.right() * rhs, lhs.bottom() * rhs); } -Q_DECL_CONSTEXPR inline QMarginsF operator*(qreal lhs, const QMarginsF &rhs) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMarginsF operator*(qreal lhs, const QMarginsF &rhs) noexcept { return QMarginsF(rhs.left() * lhs, rhs.top() * lhs, rhs.right() * lhs, rhs.bottom() * lhs); @@ -430,17 +430,17 @@ Q_DECL_CONSTEXPR inline QMarginsF operator/(const QMarginsF &lhs, qreal divisor) lhs.right() / divisor, lhs.bottom() / divisor); } -Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator+=(const QMarginsF &margins) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator+=(const QMarginsF &margins) noexcept { return *this = *this + margins; } -Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator-=(const QMarginsF &margins) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator-=(const QMarginsF &margins) noexcept { return *this = *this - margins; } -Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator+=(qreal addend) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator+=(qreal addend) noexcept { m_left += addend; m_top += addend; @@ -449,7 +449,7 @@ Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator+=(qreal addend) Q return *this; } -Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator-=(qreal subtrahend) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator-=(qreal subtrahend) noexcept { m_left -= subtrahend; m_top -= subtrahend; @@ -458,7 +458,7 @@ Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator-=(qreal subtrahen return *this; } -Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator*=(qreal factor) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator*=(qreal factor) noexcept { return *this = *this * factor; } @@ -468,17 +468,17 @@ Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator/=(qreal divisor) return *this = *this / divisor; } -Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &margins) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &margins) noexcept { return margins; } -Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &margins) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &margins) noexcept { return QMarginsF(-margins.left(), -margins.top(), -margins.right(), -margins.bottom()); } -Q_DECL_CONSTEXPR inline QMargins QMarginsF::toMargins() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QMargins QMarginsF::toMargins() const noexcept { return QMargins(qRound(m_left), qRound(m_top), qRound(m_right), qRound(m_bottom)); } diff --git a/src/corelib/tools/qpair.h b/src/corelib/tools/qpair.h index 94977fc826..6d1e67efb7 100644 --- a/src/corelib/tools/qpair.h +++ b/src/corelib/tools/qpair.h @@ -52,41 +52,41 @@ struct QPair typedef T2 second_type; Q_DECL_CONSTEXPR QPair() - Q_DECL_NOEXCEPT_EXPR((std::is_nothrow_default_constructible<T1>::value && + noexcept((std::is_nothrow_default_constructible<T1>::value && std::is_nothrow_default_constructible<T2>::value)) : first(), second() {} Q_DECL_CONSTEXPR QPair(const T1 &t1, const T2 &t2) - Q_DECL_NOEXCEPT_EXPR((std::is_nothrow_copy_constructible<T1>::value && + noexcept((std::is_nothrow_copy_constructible<T1>::value && std::is_nothrow_copy_constructible<T2>::value)) : first(t1), second(t2) {} // compiler-generated copy/move ctor/assignment operators are fine! template <typename TT1, typename TT2> Q_DECL_CONSTEXPR QPair(const QPair<TT1, TT2> &p) - Q_DECL_NOEXCEPT_EXPR((std::is_nothrow_constructible<T1, TT1&>::value && + noexcept((std::is_nothrow_constructible<T1, TT1&>::value && std::is_nothrow_constructible<T2, TT2&>::value)) : first(p.first), second(p.second) {} template <typename TT1, typename TT2> Q_DECL_RELAXED_CONSTEXPR QPair &operator=(const QPair<TT1, TT2> &p) - Q_DECL_NOEXCEPT_EXPR((std::is_nothrow_assignable<T1, TT1&>::value && + noexcept((std::is_nothrow_assignable<T1, TT1&>::value && std::is_nothrow_assignable<T2, TT2&>::value)) { first = p.first; second = p.second; return *this; } #ifdef Q_COMPILER_RVALUE_REFS template <typename TT1, typename TT2> Q_DECL_CONSTEXPR QPair(QPair<TT1, TT2> &&p) - Q_DECL_NOEXCEPT_EXPR((std::is_nothrow_constructible<T1, TT1>::value && + noexcept((std::is_nothrow_constructible<T1, TT1>::value && std::is_nothrow_constructible<T2, TT2>::value)) // can't use std::move here as it's not constexpr in C++11: : first(static_cast<TT1 &&>(p.first)), second(static_cast<TT2 &&>(p.second)) {} template <typename TT1, typename TT2> Q_DECL_RELAXED_CONSTEXPR QPair &operator=(QPair<TT1, TT2> &&p) - Q_DECL_NOEXCEPT_EXPR((std::is_nothrow_assignable<T1, TT1>::value && + noexcept((std::is_nothrow_assignable<T1, TT1>::value && std::is_nothrow_assignable<T2, TT2>::value)) { first = std::move(p.first); second = std::move(p.second); return *this; } #endif Q_DECL_RELAXED_CONSTEXPR void swap(QPair &other) - Q_DECL_NOEXCEPT_EXPR(noexcept(qSwap(other.first, other.first)) && noexcept(qSwap(other.second, other.second))) + noexcept(noexcept(qSwap(other.first, other.first)) && noexcept(qSwap(other.second, other.second))) { // use qSwap() to pick up ADL swaps automatically: qSwap(first, other.first); @@ -97,8 +97,13 @@ struct QPair T2 second; }; +#if defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201606 +template<class T1, class T2> +QPair(T1, T2) -> QPair<T1, T2>; +#endif + template <typename T1, typename T2> -void swap(QPair<T1, T2> &lhs, QPair<T1, T2> &rhs) Q_DECL_NOEXCEPT_EXPR(noexcept(lhs.swap(rhs))) +void swap(QPair<T1, T2> &lhs, QPair<T1, T2> &rhs) noexcept(noexcept(lhs.swap(rhs))) { lhs.swap(rhs); } // mark QPair<T1,T2> as complex/movable/primitive depending on the @@ -108,45 +113,45 @@ class QTypeInfo<QPair<T1, T2> > : public QTypeInfoMerger<QPair<T1, T2>, T1, T2> template <class T1, class T2> Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator==(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2) - Q_DECL_NOEXCEPT_EXPR(noexcept(p1.first == p2.first && p1.second == p2.second)) + noexcept(noexcept(p1.first == p2.first && p1.second == p2.second)) { return p1.first == p2.first && p1.second == p2.second; } template <class T1, class T2> Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator!=(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2) - Q_DECL_NOEXCEPT_EXPR(noexcept(!(p1 == p2))) + noexcept(noexcept(!(p1 == p2))) { return !(p1 == p2); } template <class T1, class T2> Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator<(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2) - Q_DECL_NOEXCEPT_EXPR(noexcept(p1.first < p2.first || (!(p2.first < p1.first) && p1.second < p2.second))) + noexcept(noexcept(p1.first < p2.first || (!(p2.first < p1.first) && p1.second < p2.second))) { return p1.first < p2.first || (!(p2.first < p1.first) && p1.second < p2.second); } template <class T1, class T2> Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator>(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2) - Q_DECL_NOEXCEPT_EXPR(noexcept(p2 < p1)) + noexcept(noexcept(p2 < p1)) { return p2 < p1; } template <class T1, class T2> Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator<=(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2) - Q_DECL_NOEXCEPT_EXPR(noexcept(!(p2 < p1))) + noexcept(noexcept(!(p2 < p1))) { return !(p2 < p1); } template <class T1, class T2> Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator>=(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2) - Q_DECL_NOEXCEPT_EXPR(noexcept(!(p1 < p2))) + noexcept(noexcept(!(p1 < p2))) { return !(p1 < p2); } template <class T1, class T2> Q_DECL_CONSTEXPR Q_OUTOFLINE_TEMPLATE QPair<T1, T2> qMakePair(const T1 &x, const T2 &y) - Q_DECL_NOEXCEPT_EXPR(noexcept(QPair<T1, T2>(x, y))) + noexcept(noexcept(QPair<T1, T2>(x, y))) { return QPair<T1, T2>(x, y); } diff --git a/src/corelib/tools/qpoint.h b/src/corelib/tools/qpoint.h index d7323f7707..34df673b93 100644 --- a/src/corelib/tools/qpoint.h +++ b/src/corelib/tools/qpoint.h @@ -94,7 +94,7 @@ public: friend Q_DECL_CONSTEXPR inline const QPoint operator/(const QPoint &, qreal); #if defined(Q_OS_DARWIN) || defined(Q_QDOC) - Q_REQUIRED_RESULT CGPoint toCGPoint() const Q_DECL_NOTHROW; + Q_REQUIRED_RESULT CGPoint toCGPoint() const noexcept; #endif private: @@ -256,8 +256,8 @@ public: Q_DECL_CONSTEXPR QPoint toPoint() const; #if defined(Q_OS_DARWIN) || defined(Q_QDOC) - Q_REQUIRED_RESULT static QPointF fromCGPoint(CGPoint point) Q_DECL_NOTHROW; - Q_REQUIRED_RESULT CGPoint toCGPoint() const Q_DECL_NOTHROW; + Q_REQUIRED_RESULT static QPointF fromCGPoint(CGPoint point) noexcept; + Q_REQUIRED_RESULT CGPoint toCGPoint() const noexcept; #endif private: diff --git a/src/corelib/tools/qqueue.h b/src/corelib/tools/qqueue.h index b55f210577..16229759ee 100644 --- a/src/corelib/tools/qqueue.h +++ b/src/corelib/tools/qqueue.h @@ -50,7 +50,7 @@ class QQueue : public QList<T> { public: // compiler-generated special member functions are fine! - inline void swap(QQueue<T> &other) Q_DECL_NOTHROW { QList<T>::swap(other); } // prevent QList<->QQueue swaps + inline void swap(QQueue<T> &other) noexcept { QList<T>::swap(other); } // prevent QList<->QQueue swaps #ifndef Q_QDOC // bring in QList::swap(int, int). We cannot say using QList<T>::swap, // because we don't want to make swap(QList&) available. diff --git a/src/corelib/tools/qrect.cpp b/src/corelib/tools/qrect.cpp index 6e51deebea..d622f92530 100644 --- a/src/corelib/tools/qrect.cpp +++ b/src/corelib/tools/qrect.cpp @@ -300,7 +300,7 @@ QT_BEGIN_NAMESPACE \sa isValid(), isEmpty() */ -QRect QRect::normalized() const Q_DECL_NOTHROW +QRect QRect::normalized() const noexcept { QRect r; if (x2 < x1 - 1) { // swap bad x values @@ -820,7 +820,7 @@ QRect QRect::normalized() const Q_DECL_NOTHROW \sa intersects() */ -bool QRect::contains(const QPoint &p, bool proper) const Q_DECL_NOTHROW +bool QRect::contains(const QPoint &p, bool proper) const noexcept { int l, r; if (x2 < x1 - 1) { @@ -884,7 +884,7 @@ bool QRect::contains(const QPoint &p, bool proper) const Q_DECL_NOTHROW rectangle (not on the edge). */ -bool QRect::contains(const QRect &r, bool proper) const Q_DECL_NOTHROW +bool QRect::contains(const QRect &r, bool proper) const noexcept { if (isNull() || r.isNull()) return false; @@ -962,7 +962,7 @@ bool QRect::contains(const QRect &r, bool proper) const Q_DECL_NOTHROW \sa operator|=(), united() */ -QRect QRect::operator|(const QRect &r) const Q_DECL_NOTHROW +QRect QRect::operator|(const QRect &r) const noexcept { if (isNull()) return r; @@ -1033,7 +1033,7 @@ QRect QRect::operator|(const QRect &r) const Q_DECL_NOTHROW \sa operator&=(), intersected() */ -QRect QRect::operator&(const QRect &r) const Q_DECL_NOTHROW +QRect QRect::operator&(const QRect &r) const noexcept { if (isNull() || r.isNull()) return QRect(); @@ -1112,7 +1112,7 @@ QRect QRect::operator&(const QRect &r) const Q_DECL_NOTHROW \sa contains() */ -bool QRect::intersects(const QRect &r) const Q_DECL_NOTHROW +bool QRect::intersects(const QRect &r) const noexcept { if (isNull() || r.isNull()) return false; @@ -1540,7 +1540,7 @@ QDebug operator<<(QDebug dbg, const QRect &r) \sa isValid(), isEmpty() */ -QRectF QRectF::normalized() const Q_DECL_NOTHROW +QRectF QRectF::normalized() const noexcept { QRectF r = *this; if (r.w < 0) { @@ -1964,7 +1964,7 @@ QRectF QRectF::normalized() const Q_DECL_NOTHROW \sa intersects() */ -bool QRectF::contains(const QPointF &p) const Q_DECL_NOTHROW +bool QRectF::contains(const QPointF &p) const noexcept { qreal l = xp; qreal r = xp; @@ -2010,7 +2010,7 @@ bool QRectF::contains(const QPointF &p) const Q_DECL_NOTHROW otherwise returns \c false. */ -bool QRectF::contains(const QRectF &r) const Q_DECL_NOTHROW +bool QRectF::contains(const QRectF &r) const noexcept { qreal l1 = xp; qreal r1 = xp; @@ -2148,7 +2148,7 @@ bool QRectF::contains(const QRectF &r) const Q_DECL_NOTHROW \sa united(), operator|=() */ -QRectF QRectF::operator|(const QRectF &r) const Q_DECL_NOTHROW +QRectF QRectF::operator|(const QRectF &r) const noexcept { if (isNull()) return r; @@ -2217,7 +2217,7 @@ QRectF QRectF::operator|(const QRectF &r) const Q_DECL_NOTHROW \sa operator&=(), intersected() */ -QRectF QRectF::operator&(const QRectF &r) const Q_DECL_NOTHROW +QRectF QRectF::operator&(const QRectF &r) const noexcept { qreal l1 = xp; qreal r1 = xp; @@ -2302,7 +2302,7 @@ QRectF QRectF::operator&(const QRectF &r) const Q_DECL_NOTHROW \sa contains() */ -bool QRectF::intersects(const QRectF &r) const Q_DECL_NOTHROW +bool QRectF::intersects(const QRectF &r) const noexcept { qreal l1 = xp; qreal r1 = xp; @@ -2369,7 +2369,7 @@ bool QRectF::intersects(const QRectF &r) const Q_DECL_NOTHROW \sa toRect() */ -QRect QRectF::toAlignedRect() const Q_DECL_NOTHROW +QRect QRectF::toAlignedRect() const noexcept { int xmin = int(qFloor(xp)); int xmax = int(qCeil(xp + w)); diff --git a/src/corelib/tools/qrect.h b/src/corelib/tools/qrect.h index 3b40055b5a..7aa2312f38 100644 --- a/src/corelib/tools/qrect.h +++ b/src/corelib/tools/qrect.h @@ -57,104 +57,104 @@ QT_BEGIN_NAMESPACE class Q_CORE_EXPORT QRect { public: - Q_DECL_CONSTEXPR QRect() Q_DECL_NOTHROW : x1(0), y1(0), x2(-1), y2(-1) {} - Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QPoint &bottomright) Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QSize &size) Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR QRect(int left, int top, int width, int height) Q_DECL_NOTHROW; - - Q_DECL_CONSTEXPR inline bool isNull() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline bool isEmpty() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOTHROW; - - Q_DECL_CONSTEXPR inline int left() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline int top() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline int right() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline int bottom() const Q_DECL_NOTHROW; - Q_REQUIRED_RESULT QRect normalized() const Q_DECL_NOTHROW; - - Q_DECL_CONSTEXPR inline int x() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline int y() const Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setLeft(int pos) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setTop(int pos) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setRight(int pos) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setBottom(int pos) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setX(int x) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setY(int y) Q_DECL_NOTHROW; - - Q_DECL_RELAXED_CONSTEXPR inline void setTopLeft(const QPoint &p) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setBottomRight(const QPoint &p) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setTopRight(const QPoint &p) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setBottomLeft(const QPoint &p) Q_DECL_NOTHROW; - - Q_DECL_CONSTEXPR inline QPoint topLeft() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline QPoint bottomRight() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline QPoint topRight() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline QPoint bottomLeft() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline QPoint center() const Q_DECL_NOTHROW; - - Q_DECL_RELAXED_CONSTEXPR inline void moveLeft(int pos) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void moveTop(int pos) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void moveRight(int pos) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void moveBottom(int pos) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void moveTopLeft(const QPoint &p) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void moveBottomRight(const QPoint &p) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void moveTopRight(const QPoint &p) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void moveBottomLeft(const QPoint &p) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void moveCenter(const QPoint &p) Q_DECL_NOTHROW; - - Q_DECL_RELAXED_CONSTEXPR inline void translate(int dx, int dy) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void translate(const QPoint &p) Q_DECL_NOTHROW; - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRect translated(int dx, int dy) const Q_DECL_NOTHROW; - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRect translated(const QPoint &p) const Q_DECL_NOTHROW; - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRect transposed() const Q_DECL_NOTHROW; - - Q_DECL_RELAXED_CONSTEXPR inline void moveTo(int x, int t) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void moveTo(const QPoint &p) Q_DECL_NOTHROW; - - Q_DECL_RELAXED_CONSTEXPR inline void setRect(int x, int y, int w, int h) Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR QRect() noexcept : x1(0), y1(0), x2(-1), y2(-1) {} + Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QPoint &bottomright) noexcept; + Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QSize &size) noexcept; + Q_DECL_CONSTEXPR QRect(int left, int top, int width, int height) noexcept; + + Q_DECL_CONSTEXPR inline bool isNull() const noexcept; + Q_DECL_CONSTEXPR inline bool isEmpty() const noexcept; + Q_DECL_CONSTEXPR inline bool isValid() const noexcept; + + Q_DECL_CONSTEXPR inline int left() const noexcept; + Q_DECL_CONSTEXPR inline int top() const noexcept; + Q_DECL_CONSTEXPR inline int right() const noexcept; + Q_DECL_CONSTEXPR inline int bottom() const noexcept; + Q_REQUIRED_RESULT QRect normalized() const noexcept; + + Q_DECL_CONSTEXPR inline int x() const noexcept; + Q_DECL_CONSTEXPR inline int y() const noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setLeft(int pos) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setTop(int pos) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setRight(int pos) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setBottom(int pos) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setX(int x) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setY(int y) noexcept; + + Q_DECL_RELAXED_CONSTEXPR inline void setTopLeft(const QPoint &p) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setBottomRight(const QPoint &p) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setTopRight(const QPoint &p) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setBottomLeft(const QPoint &p) noexcept; + + Q_DECL_CONSTEXPR inline QPoint topLeft() const noexcept; + Q_DECL_CONSTEXPR inline QPoint bottomRight() const noexcept; + Q_DECL_CONSTEXPR inline QPoint topRight() const noexcept; + Q_DECL_CONSTEXPR inline QPoint bottomLeft() const noexcept; + Q_DECL_CONSTEXPR inline QPoint center() const noexcept; + + Q_DECL_RELAXED_CONSTEXPR inline void moveLeft(int pos) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void moveTop(int pos) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void moveRight(int pos) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void moveBottom(int pos) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void moveTopLeft(const QPoint &p) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void moveBottomRight(const QPoint &p) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void moveTopRight(const QPoint &p) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void moveBottomLeft(const QPoint &p) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void moveCenter(const QPoint &p) noexcept; + + Q_DECL_RELAXED_CONSTEXPR inline void translate(int dx, int dy) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void translate(const QPoint &p) noexcept; + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRect translated(int dx, int dy) const noexcept; + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRect translated(const QPoint &p) const noexcept; + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRect transposed() const noexcept; + + Q_DECL_RELAXED_CONSTEXPR inline void moveTo(int x, int t) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void moveTo(const QPoint &p) noexcept; + + Q_DECL_RELAXED_CONSTEXPR inline void setRect(int x, int y, int w, int h) noexcept; Q_DECL_RELAXED_CONSTEXPR inline void getRect(int *x, int *y, int *w, int *h) const; - Q_DECL_RELAXED_CONSTEXPR inline void setCoords(int x1, int y1, int x2, int y2) Q_DECL_NOTHROW; + Q_DECL_RELAXED_CONSTEXPR inline void setCoords(int x1, int y1, int x2, int y2) noexcept; Q_DECL_RELAXED_CONSTEXPR inline void getCoords(int *x1, int *y1, int *x2, int *y2) const; - Q_DECL_RELAXED_CONSTEXPR inline void adjust(int x1, int y1, int x2, int y2) Q_DECL_NOTHROW; - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRect adjusted(int x1, int y1, int x2, int y2) const Q_DECL_NOTHROW; - - Q_DECL_CONSTEXPR inline QSize size() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline int width() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline int height() const Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setWidth(int w) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setHeight(int h) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setSize(const QSize &s) Q_DECL_NOTHROW; - - QRect operator|(const QRect &r) const Q_DECL_NOTHROW; - QRect operator&(const QRect &r) const Q_DECL_NOTHROW; - inline QRect& operator|=(const QRect &r) Q_DECL_NOTHROW; - inline QRect& operator&=(const QRect &r) Q_DECL_NOTHROW; - - bool contains(const QRect &r, bool proper = false) const Q_DECL_NOTHROW; - bool contains(const QPoint &p, bool proper=false) const Q_DECL_NOTHROW; - inline bool contains(int x, int y) const Q_DECL_NOTHROW; - inline bool contains(int x, int y, bool proper) const Q_DECL_NOTHROW; - Q_REQUIRED_RESULT inline QRect united(const QRect &other) const Q_DECL_NOTHROW; - Q_REQUIRED_RESULT inline QRect intersected(const QRect &other) const Q_DECL_NOTHROW; - bool intersects(const QRect &r) const Q_DECL_NOTHROW; - - Q_DECL_CONSTEXPR inline QRect marginsAdded(const QMargins &margins) const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline QRect marginsRemoved(const QMargins &margins) const Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline QRect &operator+=(const QMargins &margins) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline QRect &operator-=(const QMargins &margins) Q_DECL_NOTHROW; + Q_DECL_RELAXED_CONSTEXPR inline void adjust(int x1, int y1, int x2, int y2) noexcept; + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRect adjusted(int x1, int y1, int x2, int y2) const noexcept; + + Q_DECL_CONSTEXPR inline QSize size() const noexcept; + Q_DECL_CONSTEXPR inline int width() const noexcept; + Q_DECL_CONSTEXPR inline int height() const noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setWidth(int w) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setHeight(int h) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setSize(const QSize &s) noexcept; + + QRect operator|(const QRect &r) const noexcept; + QRect operator&(const QRect &r) const noexcept; + inline QRect& operator|=(const QRect &r) noexcept; + inline QRect& operator&=(const QRect &r) noexcept; + + bool contains(const QRect &r, bool proper = false) const noexcept; + bool contains(const QPoint &p, bool proper=false) const noexcept; + inline bool contains(int x, int y) const noexcept; + inline bool contains(int x, int y, bool proper) const noexcept; + Q_REQUIRED_RESULT inline QRect united(const QRect &other) const noexcept; + Q_REQUIRED_RESULT inline QRect intersected(const QRect &other) const noexcept; + bool intersects(const QRect &r) const noexcept; + + Q_DECL_CONSTEXPR inline QRect marginsAdded(const QMargins &margins) const noexcept; + Q_DECL_CONSTEXPR inline QRect marginsRemoved(const QMargins &margins) const noexcept; + Q_DECL_RELAXED_CONSTEXPR inline QRect &operator+=(const QMargins &margins) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline QRect &operator-=(const QMargins &margins) noexcept; #if QT_DEPRECATED_SINCE(5, 0) - Q_REQUIRED_RESULT QT_DEPRECATED QRect unite(const QRect &r) const Q_DECL_NOTHROW { return united(r); } - Q_REQUIRED_RESULT QT_DEPRECATED QRect intersect(const QRect &r) const Q_DECL_NOTHROW { return intersected(r); } + Q_REQUIRED_RESULT QT_DEPRECATED QRect unite(const QRect &r) const noexcept { return united(r); } + Q_REQUIRED_RESULT QT_DEPRECATED QRect intersect(const QRect &r) const noexcept { return intersected(r); } #endif - friend Q_DECL_CONSTEXPR inline bool operator==(const QRect &, const QRect &) Q_DECL_NOTHROW; - friend Q_DECL_CONSTEXPR inline bool operator!=(const QRect &, const QRect &) Q_DECL_NOTHROW; + friend Q_DECL_CONSTEXPR inline bool operator==(const QRect &, const QRect &) noexcept; + friend Q_DECL_CONSTEXPR inline bool operator!=(const QRect &, const QRect &) noexcept; #if defined(Q_OS_DARWIN) || defined(Q_QDOC) - Q_REQUIRED_RESULT CGRect toCGRect() const Q_DECL_NOTHROW; + Q_REQUIRED_RESULT CGRect toCGRect() const noexcept; #endif private: @@ -165,8 +165,8 @@ private: }; Q_DECLARE_TYPEINFO(QRect, Q_MOVABLE_TYPE); -Q_DECL_CONSTEXPR inline bool operator==(const QRect &, const QRect &) Q_DECL_NOTHROW; -Q_DECL_CONSTEXPR inline bool operator!=(const QRect &, const QRect &) Q_DECL_NOTHROW; +Q_DECL_CONSTEXPR inline bool operator==(const QRect &, const QRect &) noexcept; +Q_DECL_CONSTEXPR inline bool operator!=(const QRect &, const QRect &) noexcept; /***************************************************************************** @@ -181,97 +181,97 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRect &); QRect inline member functions *****************************************************************************/ -Q_DECL_CONSTEXPR inline QRect::QRect(int aleft, int atop, int awidth, int aheight) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRect::QRect(int aleft, int atop, int awidth, int aheight) noexcept : x1(aleft), y1(atop), x2(aleft + awidth - 1), y2(atop + aheight - 1) {} -Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QPoint &abottomRight) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QPoint &abottomRight) noexcept : x1(atopLeft.x()), y1(atopLeft.y()), x2(abottomRight.x()), y2(abottomRight.y()) {} -Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QSize &asize) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QSize &asize) noexcept : x1(atopLeft.x()), y1(atopLeft.y()), x2(atopLeft.x()+asize.width() - 1), y2(atopLeft.y()+asize.height() - 1) {} -Q_DECL_CONSTEXPR inline bool QRect::isNull() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool QRect::isNull() const noexcept { return x2 == x1 - 1 && y2 == y1 - 1; } -Q_DECL_CONSTEXPR inline bool QRect::isEmpty() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool QRect::isEmpty() const noexcept { return x1 > x2 || y1 > y2; } -Q_DECL_CONSTEXPR inline bool QRect::isValid() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool QRect::isValid() const noexcept { return x1 <= x2 && y1 <= y2; } -Q_DECL_CONSTEXPR inline int QRect::left() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline int QRect::left() const noexcept { return x1; } -Q_DECL_CONSTEXPR inline int QRect::top() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline int QRect::top() const noexcept { return y1; } -Q_DECL_CONSTEXPR inline int QRect::right() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline int QRect::right() const noexcept { return x2; } -Q_DECL_CONSTEXPR inline int QRect::bottom() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline int QRect::bottom() const noexcept { return y2; } -Q_DECL_CONSTEXPR inline int QRect::x() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline int QRect::x() const noexcept { return x1; } -Q_DECL_CONSTEXPR inline int QRect::y() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline int QRect::y() const noexcept { return y1; } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::setLeft(int pos) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::setLeft(int pos) noexcept { x1 = pos; } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::setTop(int pos) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::setTop(int pos) noexcept { y1 = pos; } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::setRight(int pos) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::setRight(int pos) noexcept { x2 = pos; } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::setBottom(int pos) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::setBottom(int pos) noexcept { y2 = pos; } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::setTopLeft(const QPoint &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::setTopLeft(const QPoint &p) noexcept { x1 = p.x(); y1 = p.y(); } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::setBottomRight(const QPoint &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::setBottomRight(const QPoint &p) noexcept { x2 = p.x(); y2 = p.y(); } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::setTopRight(const QPoint &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::setTopRight(const QPoint &p) noexcept { x2 = p.x(); y1 = p.y(); } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::setBottomLeft(const QPoint &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::setBottomLeft(const QPoint &p) noexcept { x1 = p.x(); y2 = p.y(); } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::setX(int ax) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::setX(int ax) noexcept { x1 = ax; } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::setY(int ay) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::setY(int ay) noexcept { y1 = ay; } -Q_DECL_CONSTEXPR inline QPoint QRect::topLeft() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QPoint QRect::topLeft() const noexcept { return QPoint(x1, y1); } -Q_DECL_CONSTEXPR inline QPoint QRect::bottomRight() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QPoint QRect::bottomRight() const noexcept { return QPoint(x2, y2); } -Q_DECL_CONSTEXPR inline QPoint QRect::topRight() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QPoint QRect::topRight() const noexcept { return QPoint(x2, y1); } -Q_DECL_CONSTEXPR inline QPoint QRect::bottomLeft() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QPoint QRect::bottomLeft() const noexcept { return QPoint(x1, y2); } -Q_DECL_CONSTEXPR inline QPoint QRect::center() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QPoint QRect::center() const noexcept { return QPoint(int((qint64(x1)+x2)/2), int((qint64(y1)+y2)/2)); } // cast avoids overflow on addition -Q_DECL_CONSTEXPR inline int QRect::width() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline int QRect::width() const noexcept { return x2 - x1 + 1; } -Q_DECL_CONSTEXPR inline int QRect::height() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline int QRect::height() const noexcept { return y2 - y1 + 1; } -Q_DECL_CONSTEXPR inline QSize QRect::size() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QSize QRect::size() const noexcept { return QSize(width(), height()); } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::translate(int dx, int dy) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::translate(int dx, int dy) noexcept { x1 += dx; y1 += dy; @@ -279,7 +279,7 @@ Q_DECL_RELAXED_CONSTEXPR inline void QRect::translate(int dx, int dy) Q_DECL_NOT y2 += dy; } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::translate(const QPoint &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::translate(const QPoint &p) noexcept { x1 += p.x(); y1 += p.y(); @@ -287,16 +287,16 @@ Q_DECL_RELAXED_CONSTEXPR inline void QRect::translate(const QPoint &p) Q_DECL_NO y2 += p.y(); } -Q_DECL_CONSTEXPR inline QRect QRect::translated(int dx, int dy) const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRect QRect::translated(int dx, int dy) const noexcept { return QRect(QPoint(x1 + dx, y1 + dy), QPoint(x2 + dx, y2 + dy)); } -Q_DECL_CONSTEXPR inline QRect QRect::translated(const QPoint &p) const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRect QRect::translated(const QPoint &p) const noexcept { return QRect(QPoint(x1 + p.x(), y1 + p.y()), QPoint(x2 + p.x(), y2 + p.y())); } -Q_DECL_CONSTEXPR inline QRect QRect::transposed() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRect QRect::transposed() const noexcept { return QRect(topLeft(), size().transposed()); } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTo(int ax, int ay) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTo(int ax, int ay) noexcept { x2 += ax - x1; y2 += ay - y1; @@ -304,7 +304,7 @@ Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTo(int ax, int ay) Q_DECL_NOTHRO y1 = ay; } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTo(const QPoint &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTo(const QPoint &p) noexcept { x2 += p.x() - x1; y2 += p.y() - y1; @@ -312,49 +312,49 @@ Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTo(const QPoint &p) Q_DECL_NOTHR y1 = p.y(); } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveLeft(int pos) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveLeft(int pos) noexcept { x2 += (pos - x1); x1 = pos; } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTop(int pos) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTop(int pos) noexcept { y2 += (pos - y1); y1 = pos; } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveRight(int pos) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveRight(int pos) noexcept { x1 += (pos - x2); x2 = pos; } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveBottom(int pos) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveBottom(int pos) noexcept { y1 += (pos - y2); y2 = pos; } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTopLeft(const QPoint &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTopLeft(const QPoint &p) noexcept { moveLeft(p.x()); moveTop(p.y()); } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveBottomRight(const QPoint &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveBottomRight(const QPoint &p) noexcept { moveRight(p.x()); moveBottom(p.y()); } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTopRight(const QPoint &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTopRight(const QPoint &p) noexcept { moveRight(p.x()); moveTop(p.y()); } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveBottomLeft(const QPoint &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveBottomLeft(const QPoint &p) noexcept { moveLeft(p.x()); moveBottom(p.y()); } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveCenter(const QPoint &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveCenter(const QPoint &p) noexcept { int w = x2 - x1; int h = y2 - y1; @@ -372,7 +372,7 @@ Q_DECL_RELAXED_CONSTEXPR inline void QRect::getRect(int *ax, int *ay, int *aw, i *ah = y2 - y1 + 1; } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::setRect(int ax, int ay, int aw, int ah) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::setRect(int ax, int ay, int aw, int ah) noexcept { x1 = ax; y1 = ay; @@ -388,7 +388,7 @@ Q_DECL_RELAXED_CONSTEXPR inline void QRect::getCoords(int *xp1, int *yp1, int *x *yp2 = y2; } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::setCoords(int xp1, int yp1, int xp2, int yp2) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::setCoords(int xp1, int yp1, int xp2, int yp2) noexcept { x1 = xp1; y1 = yp1; @@ -396,10 +396,10 @@ Q_DECL_RELAXED_CONSTEXPR inline void QRect::setCoords(int xp1, int yp1, int xp2, y2 = yp2; } -Q_DECL_CONSTEXPR inline QRect QRect::adjusted(int xp1, int yp1, int xp2, int yp2) const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRect QRect::adjusted(int xp1, int yp1, int xp2, int yp2) const noexcept { return QRect(QPoint(x1 + xp1, y1 + yp1), QPoint(x2 + xp2, y2 + yp2)); } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::adjust(int dx1, int dy1, int dx2, int dy2) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::adjust(int dx1, int dy1, int dx2, int dy2) noexcept { x1 += dx1; y1 += dy1; @@ -407,97 +407,97 @@ Q_DECL_RELAXED_CONSTEXPR inline void QRect::adjust(int dx1, int dy1, int dx2, in y2 += dy2; } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::setWidth(int w) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::setWidth(int w) noexcept { x2 = (x1 + w - 1); } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::setHeight(int h) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::setHeight(int h) noexcept { y2 = (y1 + h - 1); } -Q_DECL_RELAXED_CONSTEXPR inline void QRect::setSize(const QSize &s) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRect::setSize(const QSize &s) noexcept { x2 = (s.width() + x1 - 1); y2 = (s.height() + y1 - 1); } -inline bool QRect::contains(int ax, int ay, bool aproper) const Q_DECL_NOTHROW +inline bool QRect::contains(int ax, int ay, bool aproper) const noexcept { return contains(QPoint(ax, ay), aproper); } -inline bool QRect::contains(int ax, int ay) const Q_DECL_NOTHROW +inline bool QRect::contains(int ax, int ay) const noexcept { return contains(QPoint(ax, ay), false); } -inline QRect& QRect::operator|=(const QRect &r) Q_DECL_NOTHROW +inline QRect& QRect::operator|=(const QRect &r) noexcept { *this = *this | r; return *this; } -inline QRect& QRect::operator&=(const QRect &r) Q_DECL_NOTHROW +inline QRect& QRect::operator&=(const QRect &r) noexcept { *this = *this & r; return *this; } -inline QRect QRect::intersected(const QRect &other) const Q_DECL_NOTHROW +inline QRect QRect::intersected(const QRect &other) const noexcept { return *this & other; } -inline QRect QRect::united(const QRect &r) const Q_DECL_NOTHROW +inline QRect QRect::united(const QRect &r) const noexcept { return *this | r; } -Q_DECL_CONSTEXPR inline bool operator==(const QRect &r1, const QRect &r2) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool operator==(const QRect &r1, const QRect &r2) noexcept { return r1.x1==r2.x1 && r1.x2==r2.x2 && r1.y1==r2.y1 && r1.y2==r2.y2; } -Q_DECL_CONSTEXPR inline bool operator!=(const QRect &r1, const QRect &r2) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool operator!=(const QRect &r1, const QRect &r2) noexcept { return r1.x1!=r2.x1 || r1.x2!=r2.x2 || r1.y1!=r2.y1 || r1.y2!=r2.y2; } -Q_DECL_CONSTEXPR inline QRect operator+(const QRect &rectangle, const QMargins &margins) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRect operator+(const QRect &rectangle, const QMargins &margins) noexcept { return QRect(QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()), QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom())); } -Q_DECL_CONSTEXPR inline QRect operator+(const QMargins &margins, const QRect &rectangle) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRect operator+(const QMargins &margins, const QRect &rectangle) noexcept { return QRect(QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()), QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom())); } -Q_DECL_CONSTEXPR inline QRect operator-(const QRect &lhs, const QMargins &rhs) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRect operator-(const QRect &lhs, const QMargins &rhs) noexcept { return QRect(QPoint(lhs.left() + rhs.left(), lhs.top() + rhs.top()), QPoint(lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom())); } -Q_DECL_CONSTEXPR inline QRect QRect::marginsAdded(const QMargins &margins) const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRect QRect::marginsAdded(const QMargins &margins) const noexcept { return QRect(QPoint(x1 - margins.left(), y1 - margins.top()), QPoint(x2 + margins.right(), y2 + margins.bottom())); } -Q_DECL_CONSTEXPR inline QRect QRect::marginsRemoved(const QMargins &margins) const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRect QRect::marginsRemoved(const QMargins &margins) const noexcept { return QRect(QPoint(x1 + margins.left(), y1 + margins.top()), QPoint(x2 - margins.right(), y2 - margins.bottom())); } -Q_DECL_RELAXED_CONSTEXPR inline QRect &QRect::operator+=(const QMargins &margins) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QRect &QRect::operator+=(const QMargins &margins) noexcept { *this = marginsAdded(margins); return *this; } -Q_DECL_RELAXED_CONSTEXPR inline QRect &QRect::operator-=(const QMargins &margins) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QRect &QRect::operator-=(const QMargins &margins) noexcept { *this = marginsRemoved(margins); return *this; @@ -511,110 +511,110 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QRect &); class Q_CORE_EXPORT QRectF { public: - Q_DECL_CONSTEXPR QRectF() Q_DECL_NOTHROW : xp(0.), yp(0.), w(0.), h(0.) {} - Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QSizeF &size) Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QPointF &bottomRight) Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR QRectF(qreal left, qreal top, qreal width, qreal height) Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR QRectF(const QRect &rect) Q_DECL_NOTHROW; - - Q_DECL_CONSTEXPR inline bool isNull() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline bool isEmpty() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOTHROW; - Q_REQUIRED_RESULT QRectF normalized() const Q_DECL_NOTHROW; - - Q_DECL_CONSTEXPR inline qreal left() const Q_DECL_NOTHROW { return xp; } - Q_DECL_CONSTEXPR inline qreal top() const Q_DECL_NOTHROW { return yp; } - Q_DECL_CONSTEXPR inline qreal right() const Q_DECL_NOTHROW { return xp + w; } - Q_DECL_CONSTEXPR inline qreal bottom() const Q_DECL_NOTHROW { return yp + h; } - - Q_DECL_CONSTEXPR inline qreal x() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline qreal y() const Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setLeft(qreal pos) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setTop(qreal pos) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setRight(qreal pos) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setBottom(qreal pos) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setX(qreal pos) Q_DECL_NOTHROW { setLeft(pos); } - Q_DECL_RELAXED_CONSTEXPR inline void setY(qreal pos) Q_DECL_NOTHROW { setTop(pos); } - - Q_DECL_CONSTEXPR inline QPointF topLeft() const Q_DECL_NOTHROW { return QPointF(xp, yp); } - Q_DECL_CONSTEXPR inline QPointF bottomRight() const Q_DECL_NOTHROW { return QPointF(xp+w, yp+h); } - Q_DECL_CONSTEXPR inline QPointF topRight() const Q_DECL_NOTHROW { return QPointF(xp+w, yp); } - Q_DECL_CONSTEXPR inline QPointF bottomLeft() const Q_DECL_NOTHROW { return QPointF(xp, yp+h); } - Q_DECL_CONSTEXPR inline QPointF center() const Q_DECL_NOTHROW; - - Q_DECL_RELAXED_CONSTEXPR inline void setTopLeft(const QPointF &p) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setBottomRight(const QPointF &p) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setTopRight(const QPointF &p) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setBottomLeft(const QPointF &p) Q_DECL_NOTHROW; - - Q_DECL_RELAXED_CONSTEXPR inline void moveLeft(qreal pos) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void moveTop(qreal pos) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void moveRight(qreal pos) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void moveBottom(qreal pos) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void moveTopLeft(const QPointF &p) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void moveBottomRight(const QPointF &p) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void moveTopRight(const QPointF &p) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void moveBottomLeft(const QPointF &p) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void moveCenter(const QPointF &p) Q_DECL_NOTHROW; - - Q_DECL_RELAXED_CONSTEXPR inline void translate(qreal dx, qreal dy) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void translate(const QPointF &p) Q_DECL_NOTHROW; - - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRectF translated(qreal dx, qreal dy) const Q_DECL_NOTHROW; - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRectF translated(const QPointF &p) const Q_DECL_NOTHROW; - - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRectF transposed() const Q_DECL_NOTHROW; - - Q_DECL_RELAXED_CONSTEXPR inline void moveTo(qreal x, qreal y) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void moveTo(const QPointF &p) Q_DECL_NOTHROW; - - Q_DECL_RELAXED_CONSTEXPR inline void setRect(qreal x, qreal y, qreal w, qreal h) Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR QRectF() noexcept : xp(0.), yp(0.), w(0.), h(0.) {} + Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QSizeF &size) noexcept; + Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QPointF &bottomRight) noexcept; + Q_DECL_CONSTEXPR QRectF(qreal left, qreal top, qreal width, qreal height) noexcept; + Q_DECL_CONSTEXPR QRectF(const QRect &rect) noexcept; + + Q_DECL_CONSTEXPR inline bool isNull() const noexcept; + Q_DECL_CONSTEXPR inline bool isEmpty() const noexcept; + Q_DECL_CONSTEXPR inline bool isValid() const noexcept; + Q_REQUIRED_RESULT QRectF normalized() const noexcept; + + Q_DECL_CONSTEXPR inline qreal left() const noexcept { return xp; } + Q_DECL_CONSTEXPR inline qreal top() const noexcept { return yp; } + Q_DECL_CONSTEXPR inline qreal right() const noexcept { return xp + w; } + Q_DECL_CONSTEXPR inline qreal bottom() const noexcept { return yp + h; } + + Q_DECL_CONSTEXPR inline qreal x() const noexcept; + Q_DECL_CONSTEXPR inline qreal y() const noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setLeft(qreal pos) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setTop(qreal pos) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setRight(qreal pos) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setBottom(qreal pos) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setX(qreal pos) noexcept { setLeft(pos); } + Q_DECL_RELAXED_CONSTEXPR inline void setY(qreal pos) noexcept { setTop(pos); } + + Q_DECL_CONSTEXPR inline QPointF topLeft() const noexcept { return QPointF(xp, yp); } + Q_DECL_CONSTEXPR inline QPointF bottomRight() const noexcept { return QPointF(xp+w, yp+h); } + Q_DECL_CONSTEXPR inline QPointF topRight() const noexcept { return QPointF(xp+w, yp); } + Q_DECL_CONSTEXPR inline QPointF bottomLeft() const noexcept { return QPointF(xp, yp+h); } + Q_DECL_CONSTEXPR inline QPointF center() const noexcept; + + Q_DECL_RELAXED_CONSTEXPR inline void setTopLeft(const QPointF &p) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setBottomRight(const QPointF &p) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setTopRight(const QPointF &p) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setBottomLeft(const QPointF &p) noexcept; + + Q_DECL_RELAXED_CONSTEXPR inline void moveLeft(qreal pos) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void moveTop(qreal pos) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void moveRight(qreal pos) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void moveBottom(qreal pos) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void moveTopLeft(const QPointF &p) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void moveBottomRight(const QPointF &p) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void moveTopRight(const QPointF &p) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void moveBottomLeft(const QPointF &p) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void moveCenter(const QPointF &p) noexcept; + + Q_DECL_RELAXED_CONSTEXPR inline void translate(qreal dx, qreal dy) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void translate(const QPointF &p) noexcept; + + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRectF translated(qreal dx, qreal dy) const noexcept; + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRectF translated(const QPointF &p) const noexcept; + + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRectF transposed() const noexcept; + + Q_DECL_RELAXED_CONSTEXPR inline void moveTo(qreal x, qreal y) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void moveTo(const QPointF &p) noexcept; + + Q_DECL_RELAXED_CONSTEXPR inline void setRect(qreal x, qreal y, qreal w, qreal h) noexcept; Q_DECL_RELAXED_CONSTEXPR inline void getRect(qreal *x, qreal *y, qreal *w, qreal *h) const; - Q_DECL_RELAXED_CONSTEXPR inline void setCoords(qreal x1, qreal y1, qreal x2, qreal y2) Q_DECL_NOTHROW; + Q_DECL_RELAXED_CONSTEXPR inline void setCoords(qreal x1, qreal y1, qreal x2, qreal y2) noexcept; Q_DECL_RELAXED_CONSTEXPR inline void getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const; - Q_DECL_RELAXED_CONSTEXPR inline void adjust(qreal x1, qreal y1, qreal x2, qreal y2) Q_DECL_NOTHROW; - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const Q_DECL_NOTHROW; - - Q_DECL_CONSTEXPR inline QSizeF size() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline qreal width() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline qreal height() const Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setWidth(qreal w) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setHeight(qreal h) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setSize(const QSizeF &s) Q_DECL_NOTHROW; - - QRectF operator|(const QRectF &r) const Q_DECL_NOTHROW; - QRectF operator&(const QRectF &r) const Q_DECL_NOTHROW; - inline QRectF& operator|=(const QRectF &r) Q_DECL_NOTHROW; - inline QRectF& operator&=(const QRectF &r) Q_DECL_NOTHROW; - - bool contains(const QRectF &r) const Q_DECL_NOTHROW; - bool contains(const QPointF &p) const Q_DECL_NOTHROW; - inline bool contains(qreal x, qreal y) const Q_DECL_NOTHROW; - Q_REQUIRED_RESULT inline QRectF united(const QRectF &other) const Q_DECL_NOTHROW; - Q_REQUIRED_RESULT inline QRectF intersected(const QRectF &other) const Q_DECL_NOTHROW; - bool intersects(const QRectF &r) const Q_DECL_NOTHROW; - - Q_DECL_CONSTEXPR inline QRectF marginsAdded(const QMarginsF &margins) const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline QRectF marginsRemoved(const QMarginsF &margins) const Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline QRectF &operator+=(const QMarginsF &margins) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline QRectF &operator-=(const QMarginsF &margins) Q_DECL_NOTHROW; + Q_DECL_RELAXED_CONSTEXPR inline void adjust(qreal x1, qreal y1, qreal x2, qreal y2) noexcept; + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const noexcept; + + Q_DECL_CONSTEXPR inline QSizeF size() const noexcept; + Q_DECL_CONSTEXPR inline qreal width() const noexcept; + Q_DECL_CONSTEXPR inline qreal height() const noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setWidth(qreal w) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setHeight(qreal h) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setSize(const QSizeF &s) noexcept; + + QRectF operator|(const QRectF &r) const noexcept; + QRectF operator&(const QRectF &r) const noexcept; + inline QRectF& operator|=(const QRectF &r) noexcept; + inline QRectF& operator&=(const QRectF &r) noexcept; + + bool contains(const QRectF &r) const noexcept; + bool contains(const QPointF &p) const noexcept; + inline bool contains(qreal x, qreal y) const noexcept; + Q_REQUIRED_RESULT inline QRectF united(const QRectF &other) const noexcept; + Q_REQUIRED_RESULT inline QRectF intersected(const QRectF &other) const noexcept; + bool intersects(const QRectF &r) const noexcept; + + Q_DECL_CONSTEXPR inline QRectF marginsAdded(const QMarginsF &margins) const noexcept; + Q_DECL_CONSTEXPR inline QRectF marginsRemoved(const QMarginsF &margins) const noexcept; + Q_DECL_RELAXED_CONSTEXPR inline QRectF &operator+=(const QMarginsF &margins) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline QRectF &operator-=(const QMarginsF &margins) noexcept; #if QT_DEPRECATED_SINCE(5, 0) - Q_REQUIRED_RESULT QT_DEPRECATED QRectF unite(const QRectF &r) const Q_DECL_NOTHROW { return united(r); } - Q_REQUIRED_RESULT QT_DEPRECATED QRectF intersect(const QRectF &r) const Q_DECL_NOTHROW { return intersected(r); } + Q_REQUIRED_RESULT QT_DEPRECATED QRectF unite(const QRectF &r) const noexcept { return united(r); } + Q_REQUIRED_RESULT QT_DEPRECATED QRectF intersect(const QRectF &r) const noexcept { return intersected(r); } #endif - friend Q_DECL_CONSTEXPR inline bool operator==(const QRectF &, const QRectF &) Q_DECL_NOTHROW; - friend Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &, const QRectF &) Q_DECL_NOTHROW; + friend Q_DECL_CONSTEXPR inline bool operator==(const QRectF &, const QRectF &) noexcept; + friend Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &, const QRectF &) noexcept; - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRect toRect() const Q_DECL_NOTHROW; - Q_REQUIRED_RESULT QRect toAlignedRect() const Q_DECL_NOTHROW; + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QRect toRect() const noexcept; + Q_REQUIRED_RESULT QRect toAlignedRect() const noexcept; #if defined(Q_OS_DARWIN) || defined(Q_QDOC) - Q_REQUIRED_RESULT static QRectF fromCGRect(CGRect rect) Q_DECL_NOTHROW; - Q_REQUIRED_RESULT CGRect toCGRect() const Q_DECL_NOTHROW; + Q_REQUIRED_RESULT static QRectF fromCGRect(CGRect rect) noexcept; + Q_REQUIRED_RESULT CGRect toCGRect() const noexcept; #endif private: @@ -625,8 +625,8 @@ private: }; Q_DECLARE_TYPEINFO(QRectF, Q_MOVABLE_TYPE); -Q_DECL_CONSTEXPR inline bool operator==(const QRectF &, const QRectF &) Q_DECL_NOTHROW; -Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &, const QRectF &) Q_DECL_NOTHROW; +Q_DECL_CONSTEXPR inline bool operator==(const QRectF &, const QRectF &) noexcept; +Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &, const QRectF &) noexcept; /***************************************************************************** @@ -641,23 +641,23 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRectF &); QRectF inline member functions *****************************************************************************/ -Q_DECL_CONSTEXPR inline QRectF::QRectF(qreal aleft, qreal atop, qreal awidth, qreal aheight) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRectF::QRectF(qreal aleft, qreal atop, qreal awidth, qreal aheight) noexcept : xp(aleft), yp(atop), w(awidth), h(aheight) { } -Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QSizeF &asize) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QSizeF &asize) noexcept : xp(atopLeft.x()), yp(atopLeft.y()), w(asize.width()), h(asize.height()) { } -Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QPointF &abottomRight) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QPointF &abottomRight) noexcept : xp(atopLeft.x()), yp(atopLeft.y()), w(abottomRight.x() - atopLeft.x()), h(abottomRight.y() - atopLeft.y()) { } -Q_DECL_CONSTEXPR inline QRectF::QRectF(const QRect &r) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRectF::QRectF(const QRect &r) noexcept : xp(r.x()), yp(r.y()), w(r.width()), h(r.height()) { } @@ -666,117 +666,117 @@ QT_WARNING_PUSH QT_WARNING_DISABLE_CLANG("-Wfloat-equal") QT_WARNING_DISABLE_GCC("-Wfloat-equal") -Q_DECL_CONSTEXPR inline bool QRectF::isNull() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool QRectF::isNull() const noexcept { return w == 0. && h == 0.; } -Q_DECL_CONSTEXPR inline bool QRectF::isEmpty() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool QRectF::isEmpty() const noexcept { return w <= 0. || h <= 0.; } QT_WARNING_POP -Q_DECL_CONSTEXPR inline bool QRectF::isValid() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool QRectF::isValid() const noexcept { return w > 0. && h > 0.; } -Q_DECL_CONSTEXPR inline qreal QRectF::x() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline qreal QRectF::x() const noexcept { return xp; } -Q_DECL_CONSTEXPR inline qreal QRectF::y() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline qreal QRectF::y() const noexcept { return yp; } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setLeft(qreal pos) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setLeft(qreal pos) noexcept { qreal diff = pos - xp; xp += diff; w -= diff; } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setRight(qreal pos) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setRight(qreal pos) noexcept { w = pos - xp; } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setTop(qreal pos) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setTop(qreal pos) noexcept { qreal diff = pos - yp; yp += diff; h -= diff; } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setBottom(qreal pos) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setBottom(qreal pos) noexcept { h = pos - yp; } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setTopLeft(const QPointF &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setTopLeft(const QPointF &p) noexcept { setLeft(p.x()); setTop(p.y()); } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setTopRight(const QPointF &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setTopRight(const QPointF &p) noexcept { setRight(p.x()); setTop(p.y()); } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setBottomLeft(const QPointF &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setBottomLeft(const QPointF &p) noexcept { setLeft(p.x()); setBottom(p.y()); } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setBottomRight(const QPointF &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setBottomRight(const QPointF &p) noexcept { setRight(p.x()); setBottom(p.y()); } -Q_DECL_CONSTEXPR inline QPointF QRectF::center() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QPointF QRectF::center() const noexcept { return QPointF(xp + w/2, yp + h/2); } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveLeft(qreal pos) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveLeft(qreal pos) noexcept { xp = pos; } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTop(qreal pos) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTop(qreal pos) noexcept { yp = pos; } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveRight(qreal pos) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveRight(qreal pos) noexcept { xp = pos - w; } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveBottom(qreal pos) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveBottom(qreal pos) noexcept { yp = pos - h; } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTopLeft(const QPointF &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTopLeft(const QPointF &p) noexcept { moveLeft(p.x()); moveTop(p.y()); } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTopRight(const QPointF &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTopRight(const QPointF &p) noexcept { moveRight(p.x()); moveTop(p.y()); } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveBottomLeft(const QPointF &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveBottomLeft(const QPointF &p) noexcept { moveLeft(p.x()); moveBottom(p.y()); } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveBottomRight(const QPointF &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveBottomRight(const QPointF &p) noexcept { moveRight(p.x()); moveBottom(p.y()); } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveCenter(const QPointF &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveCenter(const QPointF &p) noexcept { xp = p.x() - w/2; yp = p.y() - h/2; } -Q_DECL_CONSTEXPR inline qreal QRectF::width() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline qreal QRectF::width() const noexcept { return w; } -Q_DECL_CONSTEXPR inline qreal QRectF::height() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline qreal QRectF::height() const noexcept { return h; } -Q_DECL_CONSTEXPR inline QSizeF QRectF::size() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QSizeF QRectF::size() const noexcept { return QSizeF(w, h); } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::translate(qreal dx, qreal dy) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::translate(qreal dx, qreal dy) noexcept { xp += dx; yp += dy; } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::translate(const QPointF &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::translate(const QPointF &p) noexcept { xp += p.x(); yp += p.y(); } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTo(qreal ax, qreal ay) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTo(qreal ax, qreal ay) noexcept { xp = ax; yp = ay; } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTo(const QPointF &p) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTo(const QPointF &p) noexcept { xp = p.x(); yp = p.y(); } -Q_DECL_CONSTEXPR inline QRectF QRectF::translated(qreal dx, qreal dy) const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRectF QRectF::translated(qreal dx, qreal dy) const noexcept { return QRectF(xp + dx, yp + dy, w, h); } -Q_DECL_CONSTEXPR inline QRectF QRectF::translated(const QPointF &p) const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRectF QRectF::translated(const QPointF &p) const noexcept { return QRectF(xp + p.x(), yp + p.y(), w, h); } -Q_DECL_CONSTEXPR inline QRectF QRectF::transposed() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRectF QRectF::transposed() const noexcept { return QRectF(topLeft(), size().transposed()); } Q_DECL_RELAXED_CONSTEXPR inline void QRectF::getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) const @@ -787,7 +787,7 @@ Q_DECL_RELAXED_CONSTEXPR inline void QRectF::getRect(qreal *ax, qreal *ay, qreal *aah = this->h; } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setRect(qreal ax, qreal ay, qreal aaw, qreal aah) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setRect(qreal ax, qreal ay, qreal aaw, qreal aah) noexcept { this->xp = ax; this->yp = ay; @@ -803,7 +803,7 @@ Q_DECL_RELAXED_CONSTEXPR inline void QRectF::getCoords(qreal *xp1, qreal *yp1, q *yp2 = yp + h; } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2) noexcept { xp = xp1; yp = yp1; @@ -811,105 +811,105 @@ Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setCoords(qreal xp1, qreal yp1, qre h = yp2 - yp1; } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::adjust(qreal xp1, qreal yp1, qreal xp2, qreal yp2) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::adjust(qreal xp1, qreal yp1, qreal xp2, qreal yp2) noexcept { xp += xp1; yp += yp1; w += xp2 - xp1; h += yp2 - yp1; } -Q_DECL_CONSTEXPR inline QRectF QRectF::adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRectF QRectF::adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) const noexcept { return QRectF(xp + xp1, yp + yp1, w + xp2 - xp1, h + yp2 - yp1); } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setWidth(qreal aw) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setWidth(qreal aw) noexcept { this->w = aw; } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setHeight(qreal ah) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setHeight(qreal ah) noexcept { this->h = ah; } -Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setSize(const QSizeF &s) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setSize(const QSizeF &s) noexcept { w = s.width(); h = s.height(); } -inline bool QRectF::contains(qreal ax, qreal ay) const Q_DECL_NOTHROW +inline bool QRectF::contains(qreal ax, qreal ay) const noexcept { return contains(QPointF(ax, ay)); } -inline QRectF& QRectF::operator|=(const QRectF &r) Q_DECL_NOTHROW +inline QRectF& QRectF::operator|=(const QRectF &r) noexcept { *this = *this | r; return *this; } -inline QRectF& QRectF::operator&=(const QRectF &r) Q_DECL_NOTHROW +inline QRectF& QRectF::operator&=(const QRectF &r) noexcept { *this = *this & r; return *this; } -inline QRectF QRectF::intersected(const QRectF &r) const Q_DECL_NOTHROW +inline QRectF QRectF::intersected(const QRectF &r) const noexcept { return *this & r; } -inline QRectF QRectF::united(const QRectF &r) const Q_DECL_NOTHROW +inline QRectF QRectF::united(const QRectF &r) const noexcept { return *this | r; } -Q_DECL_CONSTEXPR inline bool operator==(const QRectF &r1, const QRectF &r2) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool operator==(const QRectF &r1, const QRectF &r2) noexcept { return qFuzzyCompare(r1.xp, r2.xp) && qFuzzyCompare(r1.yp, r2.yp) && qFuzzyCompare(r1.w, r2.w) && qFuzzyCompare(r1.h, r2.h); } -Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &r1, const QRectF &r2) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &r1, const QRectF &r2) noexcept { return !qFuzzyCompare(r1.xp, r2.xp) || !qFuzzyCompare(r1.yp, r2.yp) || !qFuzzyCompare(r1.w, r2.w) || !qFuzzyCompare(r1.h, r2.h); } -Q_DECL_CONSTEXPR inline QRect QRectF::toRect() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRect QRectF::toRect() const noexcept { return QRect(QPoint(qRound(xp), qRound(yp)), QPoint(qRound(xp + w) - 1, qRound(yp + h) - 1)); } -Q_DECL_CONSTEXPR inline QRectF operator+(const QRectF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRectF operator+(const QRectF &lhs, const QMarginsF &rhs) noexcept { return QRectF(QPointF(lhs.left() - rhs.left(), lhs.top() - rhs.top()), QSizeF(lhs.width() + rhs.left() + rhs.right(), lhs.height() + rhs.top() + rhs.bottom())); } -Q_DECL_CONSTEXPR inline QRectF operator+(const QMarginsF &lhs, const QRectF &rhs) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRectF operator+(const QMarginsF &lhs, const QRectF &rhs) noexcept { return QRectF(QPointF(rhs.left() - lhs.left(), rhs.top() - lhs.top()), QSizeF(rhs.width() + lhs.left() + lhs.right(), rhs.height() + lhs.top() + lhs.bottom())); } -Q_DECL_CONSTEXPR inline QRectF operator-(const QRectF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRectF operator-(const QRectF &lhs, const QMarginsF &rhs) noexcept { return QRectF(QPointF(lhs.left() + rhs.left(), lhs.top() + rhs.top()), QSizeF(lhs.width() - rhs.left() - rhs.right(), lhs.height() - rhs.top() - rhs.bottom())); } -Q_DECL_CONSTEXPR inline QRectF QRectF::marginsAdded(const QMarginsF &margins) const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRectF QRectF::marginsAdded(const QMarginsF &margins) const noexcept { return QRectF(QPointF(xp - margins.left(), yp - margins.top()), QSizeF(w + margins.left() + margins.right(), h + margins.top() + margins.bottom())); } -Q_DECL_CONSTEXPR inline QRectF QRectF::marginsRemoved(const QMarginsF &margins) const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QRectF QRectF::marginsRemoved(const QMarginsF &margins) const noexcept { return QRectF(QPointF(xp + margins.left(), yp + margins.top()), QSizeF(w - margins.left() - margins.right(), h - margins.top() - margins.bottom())); } -Q_DECL_RELAXED_CONSTEXPR inline QRectF &QRectF::operator+=(const QMarginsF &margins) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QRectF &QRectF::operator+=(const QMarginsF &margins) noexcept { *this = marginsAdded(margins); return *this; } -Q_DECL_RELAXED_CONSTEXPR inline QRectF &QRectF::operator-=(const QMarginsF &margins) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QRectF &QRectF::operator-=(const QMarginsF &margins) noexcept { *this = marginsRemoved(margins); return *this; diff --git a/src/corelib/tools/qrefcount.h b/src/corelib/tools/qrefcount.h index 9586c3a79a..71adb41f28 100644 --- a/src/corelib/tools/qrefcount.h +++ b/src/corelib/tools/qrefcount.h @@ -51,7 +51,7 @@ namespace QtPrivate class RefCount { public: - inline bool ref() Q_DECL_NOTHROW { + inline bool ref() noexcept { int count = atomic.load(); #if !defined(QT_NO_UNSHARABLE_CONTAINERS) if (count == 0) // !isSharable @@ -62,7 +62,7 @@ public: return true; } - inline bool deref() Q_DECL_NOTHROW { + inline bool deref() noexcept { int count = atomic.load(); #if !defined(QT_NO_UNSHARABLE_CONTAINERS) if (count == 0) // !isSharable @@ -74,7 +74,7 @@ public: } #if !defined(QT_NO_UNSHARABLE_CONTAINERS) - bool setSharable(bool sharable) Q_DECL_NOTHROW + bool setSharable(bool sharable) noexcept { Q_ASSERT(!isShared()); if (sharable) @@ -83,27 +83,27 @@ public: return atomic.testAndSetRelaxed(1, 0); } - bool isSharable() const Q_DECL_NOTHROW + bool isSharable() const noexcept { // Sharable === Shared ownership. return atomic.load() != 0; } #endif - bool isStatic() const Q_DECL_NOTHROW + bool isStatic() const noexcept { // Persistent object, never deleted return atomic.load() == -1; } - bool isShared() const Q_DECL_NOTHROW + bool isShared() const noexcept { int count = atomic.load(); return (count != 1) && (count != 0); } - void initializeOwned() Q_DECL_NOTHROW { atomic.store(1); } - void initializeUnsharable() Q_DECL_NOTHROW { atomic.store(0); } + void initializeOwned() noexcept { atomic.store(1); } + void initializeUnsharable() noexcept { atomic.store(0); } QBasicAtomicInt atomic; }; diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp index 87b30c952e..d970843dea 100644 --- a/src/corelib/tools/qregexp.cpp +++ b/src/corelib/tools/qregexp.cpp @@ -58,9 +58,6 @@ QT_BEGIN_NAMESPACE -int qFindString(const QChar *haystack, int haystackLen, int from, - const QChar *needle, int needleLen, Qt::CaseSensitivity cs); - // error strings for the regexp parser #define RXERR_OK QT_TRANSLATE_NOOP("QRegExp", "no error occurred") #define RXERR_DISABLED QT_TRANSLATE_NOOP("QRegExp", "disabled feature used") @@ -893,7 +890,7 @@ static bool operator==(const QRegExpEngineKey &key1, const QRegExpEngineKey &key && key1.cs == key2.cs; } -static uint qHash(const QRegExpEngineKey &key, uint seed = 0) Q_DECL_NOTHROW +static uint qHash(const QRegExpEngineKey &key, uint seed = 0) noexcept { QtPrivate::QHashCombine hash; seed = hash(seed, key.pattern); @@ -1423,7 +1420,8 @@ void QRegExpMatchState::match(const QChar *str0, int len0, int pos0, #ifndef QT_NO_REGEXP_OPTIM if (eng->trivial && !oneTest) { - pos = qFindString(str0, len0, pos0, eng->goodStr.unicode(), eng->goodStr.length(), eng->cs); + // ### Qt6: qsize + pos = int(QtPrivate::findString(QStringView(str0, len0), pos0, QStringView(eng->goodStr.unicode(), eng->goodStr.length()), eng->cs)); matchLen = eng->goodStr.length(); matched = (pos != -1); } else @@ -4048,7 +4046,7 @@ bool QRegExp::operator==(const QRegExp &rx) const Returns the hash value for \a key, using \a seed to seed the calculation. */ -uint qHash(const QRegExp &key, uint seed) Q_DECL_NOTHROW +uint qHash(const QRegExp &key, uint seed) noexcept { QtPrivate::QHashCombine hash; seed = hash(seed, key.priv->engineKey); diff --git a/src/corelib/tools/qregexp.h b/src/corelib/tools/qregexp.h index b3fa242168..c043a06496 100644 --- a/src/corelib/tools/qregexp.h +++ b/src/corelib/tools/qregexp.h @@ -53,7 +53,7 @@ struct QRegExpPrivate; class QStringList; class QRegExp; -Q_CORE_EXPORT uint qHash(const QRegExp &key, uint seed = 0) Q_DECL_NOTHROW; +Q_CORE_EXPORT uint qHash(const QRegExp &key, uint seed = 0) noexcept; class Q_CORE_EXPORT QRegExp { @@ -74,9 +74,9 @@ public: ~QRegExp(); QRegExp &operator=(const QRegExp &rx); #ifdef Q_COMPILER_RVALUE_REFS - QRegExp &operator=(QRegExp &&other) Q_DECL_NOTHROW { swap(other); return *this; } + QRegExp &operator=(QRegExp &&other) noexcept { swap(other); return *this; } #endif - void swap(QRegExp &other) Q_DECL_NOTHROW { qSwap(priv, other.priv); } + void swap(QRegExp &other) noexcept { qSwap(priv, other.priv); } bool operator==(const QRegExp &rx) const; inline bool operator!=(const QRegExp &rx) const { return !operator==(rx); } @@ -112,7 +112,7 @@ public: static QString escape(const QString &str); - friend Q_CORE_EXPORT uint qHash(const QRegExp &key, uint seed) Q_DECL_NOTHROW; + friend Q_CORE_EXPORT uint qHash(const QRegExp &key, uint seed) noexcept; private: QRegExpPrivate *priv; diff --git a/src/corelib/tools/qregularexpression.cpp b/src/corelib/tools/qregularexpression.cpp index bdaa2d3243..ca1a866842 100644 --- a/src/corelib/tools/qregularexpression.cpp +++ b/src/corelib/tools/qregularexpression.cpp @@ -1810,7 +1810,7 @@ bool QRegularExpression::operator==(const QRegularExpression &re) const Returns the hash value for \a key, using \a seed to seed the calculation. */ -uint qHash(const QRegularExpression &key, uint seed) Q_DECL_NOTHROW +uint qHash(const QRegularExpression &key, uint seed) noexcept { QtPrivate::QHashCombine hash; seed = hash(seed, key.d->pattern); diff --git a/src/corelib/tools/qregularexpression.h b/src/corelib/tools/qregularexpression.h index f9e7029550..f16b7e91be 100644 --- a/src/corelib/tools/qregularexpression.h +++ b/src/corelib/tools/qregularexpression.h @@ -59,7 +59,7 @@ class QRegularExpressionMatchIterator; struct QRegularExpressionPrivate; class QRegularExpression; -Q_CORE_EXPORT uint qHash(const QRegularExpression &key, uint seed = 0) Q_DECL_NOTHROW; +Q_CORE_EXPORT uint qHash(const QRegularExpression &key, uint seed = 0) noexcept; class Q_CORE_EXPORT QRegularExpression { @@ -88,11 +88,11 @@ public: QRegularExpression &operator=(const QRegularExpression &re); #ifdef Q_COMPILER_RVALUE_REFS - QRegularExpression &operator=(QRegularExpression &&re) Q_DECL_NOTHROW + QRegularExpression &operator=(QRegularExpression &&re) noexcept { d.swap(re.d); return *this; } #endif - void swap(QRegularExpression &other) Q_DECL_NOTHROW { d.swap(other.d); } + void swap(QRegularExpression &other) noexcept { d.swap(other.d); } QString pattern() const; void setPattern(const QString &pattern); @@ -157,7 +157,7 @@ private: friend class QRegularExpressionMatch; friend struct QRegularExpressionMatchPrivate; friend class QRegularExpressionMatchIterator; - friend Q_CORE_EXPORT uint qHash(const QRegularExpression &key, uint seed) Q_DECL_NOTHROW; + friend Q_CORE_EXPORT uint qHash(const QRegularExpression &key, uint seed) noexcept; QRegularExpression(QRegularExpressionPrivate &dd); QExplicitlySharedDataPointer<QRegularExpressionPrivate> d; @@ -188,10 +188,10 @@ public: QRegularExpressionMatch &operator=(const QRegularExpressionMatch &match); #ifdef Q_COMPILER_RVALUE_REFS - QRegularExpressionMatch &operator=(QRegularExpressionMatch &&match) Q_DECL_NOTHROW + QRegularExpressionMatch &operator=(QRegularExpressionMatch &&match) noexcept { d.swap(match.d); return *this; } #endif - void swap(QRegularExpressionMatch &other) Q_DECL_NOTHROW { d.swap(other.d); } + void swap(QRegularExpressionMatch &other) noexcept { d.swap(other.d); } QRegularExpression regularExpression() const; QRegularExpression::MatchType matchType() const; @@ -258,10 +258,10 @@ public: QRegularExpressionMatchIterator(const QRegularExpressionMatchIterator &iterator); QRegularExpressionMatchIterator &operator=(const QRegularExpressionMatchIterator &iterator); #ifdef Q_COMPILER_RVALUE_REFS - QRegularExpressionMatchIterator &operator=(QRegularExpressionMatchIterator &&iterator) Q_DECL_NOTHROW + QRegularExpressionMatchIterator &operator=(QRegularExpressionMatchIterator &&iterator) noexcept { d.swap(iterator.d); return *this; } #endif - void swap(QRegularExpressionMatchIterator &other) Q_DECL_NOTHROW { d.swap(other.d); } + void swap(QRegularExpressionMatchIterator &other) noexcept { d.swap(other.d); } bool isValid() const; diff --git a/src/corelib/tools/qringbuffer.cpp b/src/corelib/tools/qringbuffer.cpp index 59650ed2f7..67cce57d01 100644 --- a/src/corelib/tools/qringbuffer.cpp +++ b/src/corelib/tools/qringbuffer.cpp @@ -59,7 +59,7 @@ void QRingChunk::detach() const int chunkSize = size(); QByteArray x(chunkSize, Qt::Uninitialized); ::memcpy(x.data(), chunk.constData() + headOffset, chunkSize); - chunk = qMove(x); + chunk = std::move(x); headOffset = 0; tailOffset = chunkSize; } diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h index 76ab4a5b62..838cb31697 100644 --- a/src/corelib/tools/qringbuffer_p.h +++ b/src/corelib/tools/qringbuffer_p.h @@ -65,11 +65,11 @@ class QRingChunk { public: // initialization and cleanup - inline QRingChunk() Q_DECL_NOTHROW : + inline QRingChunk() noexcept : headOffset(0), tailOffset(0) { } - inline QRingChunk(const QRingChunk &other) Q_DECL_NOTHROW : + inline QRingChunk(const QRingChunk &other) noexcept : chunk(other.chunk), headOffset(other.headOffset), tailOffset(other.tailOffset) { } @@ -77,30 +77,30 @@ public: chunk(alloc, Qt::Uninitialized), headOffset(0), tailOffset(0) { } - explicit inline QRingChunk(const QByteArray &qba) Q_DECL_NOTHROW : + explicit inline QRingChunk(const QByteArray &qba) noexcept : chunk(qba), headOffset(0), tailOffset(qba.size()) { } - inline QRingChunk &operator=(const QRingChunk &other) Q_DECL_NOTHROW + inline QRingChunk &operator=(const QRingChunk &other) noexcept { chunk = other.chunk; headOffset = other.headOffset; tailOffset = other.tailOffset; return *this; } - inline QRingChunk(QRingChunk &&other) Q_DECL_NOTHROW : + inline QRingChunk(QRingChunk &&other) noexcept : chunk(other.chunk), headOffset(other.headOffset), tailOffset(other.tailOffset) { other.headOffset = other.tailOffset = 0; } - inline QRingChunk &operator=(QRingChunk &&other) Q_DECL_NOTHROW + inline QRingChunk &operator=(QRingChunk &&other) noexcept { swap(other); return *this; } - inline void swap(QRingChunk &other) Q_DECL_NOTHROW + inline void swap(QRingChunk &other) noexcept { chunk.swap(other.chunk); qSwap(headOffset, other.headOffset); diff --git a/src/corelib/tools/qscopedpointer.h b/src/corelib/tools/qscopedpointer.h index 2a4083466b..af0c0ed336 100644 --- a/src/corelib/tools/qscopedpointer.h +++ b/src/corelib/tools/qscopedpointer.h @@ -97,7 +97,7 @@ class QScopedPointer { typedef T *QScopedPointer:: *RestrictedBool; public: - explicit QScopedPointer(T *p = nullptr) Q_DECL_NOTHROW : d(p) + explicit QScopedPointer(T *p = nullptr) noexcept : d(p) { } @@ -113,12 +113,12 @@ public: return *d; } - T *operator->() const Q_DECL_NOTHROW + T *operator->() const noexcept { return d; } - bool operator!() const Q_DECL_NOTHROW + bool operator!() const noexcept { return !d; } @@ -129,28 +129,28 @@ public: return isNull() ? nullptr : &QScopedPointer::d; } #else - operator RestrictedBool() const Q_DECL_NOTHROW + operator RestrictedBool() const noexcept { return isNull() ? nullptr : &QScopedPointer::d; } #endif - T *data() const Q_DECL_NOTHROW + T *data() const noexcept { return d; } - T *get() const Q_DECL_NOTHROW + T *get() const noexcept { return d; } - bool isNull() const Q_DECL_NOTHROW + bool isNull() const noexcept { return !d; } - void reset(T *other = nullptr) Q_DECL_NOEXCEPT_EXPR(noexcept(Cleanup::cleanup(std::declval<T *>()))) + void reset(T *other = nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval<T *>()))) { if (d == other) return; @@ -159,14 +159,14 @@ public: Cleanup::cleanup(oldD); } - T *take() Q_DECL_NOTHROW + T *take() noexcept { T *oldD = d; d = nullptr; return oldD; } - void swap(QScopedPointer<T, Cleanup> &other) Q_DECL_NOTHROW + void swap(QScopedPointer<T, Cleanup> &other) noexcept { qSwap(d, other.d); } @@ -181,43 +181,43 @@ private: }; template <class T, class Cleanup> -inline bool operator==(const QScopedPointer<T, Cleanup> &lhs, const QScopedPointer<T, Cleanup> &rhs) Q_DECL_NOTHROW +inline bool operator==(const QScopedPointer<T, Cleanup> &lhs, const QScopedPointer<T, Cleanup> &rhs) noexcept { return lhs.data() == rhs.data(); } template <class T, class Cleanup> -inline bool operator!=(const QScopedPointer<T, Cleanup> &lhs, const QScopedPointer<T, Cleanup> &rhs) Q_DECL_NOTHROW +inline bool operator!=(const QScopedPointer<T, Cleanup> &lhs, const QScopedPointer<T, Cleanup> &rhs) noexcept { return lhs.data() != rhs.data(); } template <class T, class Cleanup> -inline bool operator==(const QScopedPointer<T, Cleanup> &lhs, std::nullptr_t) Q_DECL_NOTHROW +inline bool operator==(const QScopedPointer<T, Cleanup> &lhs, std::nullptr_t) noexcept { return lhs.isNull(); } template <class T, class Cleanup> -inline bool operator==(std::nullptr_t, const QScopedPointer<T, Cleanup> &rhs) Q_DECL_NOTHROW +inline bool operator==(std::nullptr_t, const QScopedPointer<T, Cleanup> &rhs) noexcept { return rhs.isNull(); } template <class T, class Cleanup> -inline bool operator!=(const QScopedPointer<T, Cleanup> &lhs, std::nullptr_t) Q_DECL_NOTHROW +inline bool operator!=(const QScopedPointer<T, Cleanup> &lhs, std::nullptr_t) noexcept { return !lhs.isNull(); } template <class T, class Cleanup> -inline bool operator!=(std::nullptr_t, const QScopedPointer<T, Cleanup> &rhs) Q_DECL_NOTHROW +inline bool operator!=(std::nullptr_t, const QScopedPointer<T, Cleanup> &rhs) noexcept { return !rhs.isNull(); } template <class T, class Cleanup> -inline void swap(QScopedPointer<T, Cleanup> &p1, QScopedPointer<T, Cleanup> &p2) Q_DECL_NOTHROW +inline void swap(QScopedPointer<T, Cleanup> &p1, QScopedPointer<T, Cleanup> &p2) noexcept { p1.swap(p2); } template <typename T, typename Cleanup = QScopedPointerArrayDeleter<T> > @@ -244,7 +244,7 @@ public: return this->d[i]; } - void swap(QScopedArrayPointer &other) Q_DECL_NOTHROW // prevent QScopedPointer <->QScopedArrayPointer swaps + void swap(QScopedArrayPointer &other) noexcept // prevent QScopedPointer <->QScopedArrayPointer swaps { QScopedPointer<T, Cleanup>::swap(other); } private: @@ -263,7 +263,7 @@ private: }; template <typename T, typename Cleanup> -inline void swap(QScopedArrayPointer<T, Cleanup> &lhs, QScopedArrayPointer<T, Cleanup> &rhs) Q_DECL_NOTHROW +inline void swap(QScopedArrayPointer<T, Cleanup> &lhs, QScopedArrayPointer<T, Cleanup> &rhs) noexcept { lhs.swap(rhs); } QT_END_NAMESPACE diff --git a/src/corelib/tools/qscopedvaluerollback.h b/src/corelib/tools/qscopedvaluerollback.h index 5f76269388..f904b8dfcb 100644 --- a/src/corelib/tools/qscopedvaluerollback.h +++ b/src/corelib/tools/qscopedvaluerollback.h @@ -48,20 +48,20 @@ template <typename T> class QScopedValueRollback { public: - explicit QScopedValueRollback(T &var) : - varRef(var), oldValue(var) + explicit QScopedValueRollback(T &var) + : varRef(var), oldValue(var) { } - explicit QScopedValueRollback(T &var, T value) : - varRef(var), oldValue(var) + explicit QScopedValueRollback(T &var, T value) + : varRef(var), oldValue(std::move(var)) { - varRef = qMove(value); + varRef = std::move(value); } ~QScopedValueRollback() { - varRef = qMove(oldValue); + varRef = std::move(oldValue); } void commit() @@ -70,7 +70,7 @@ public: } private: - T& varRef; + T &varRef; T oldValue; Q_DISABLE_COPY(QScopedValueRollback) diff --git a/src/corelib/tools/qscopeguard.h b/src/corelib/tools/qscopeguard.h index 31100fcabb..41d0a6af68 100644 --- a/src/corelib/tools/qscopeguard.h +++ b/src/corelib/tools/qscopeguard.h @@ -50,10 +50,15 @@ template <typename F> class QScopeGuard; template <typename F> QScopeGuard<F> qScopeGuard(F f); template <typename F> -class QScopeGuard +class +#ifndef __INTEL_COMPILER +// error #2621: attribute "__warn_unused_result__" does not apply here +Q_REQUIRED_RESULT +#endif +QScopeGuard { public: - QScopeGuard(QScopeGuard &&other) Q_DECL_NOEXCEPT + QScopeGuard(QScopeGuard &&other) noexcept : m_func(std::move(other.m_func)) , m_invoke(other.m_invoke) { @@ -66,13 +71,13 @@ public: m_func(); } - void dismiss() Q_DECL_NOEXCEPT + void dismiss() noexcept { m_invoke = false; } private: - explicit QScopeGuard(F f) Q_DECL_NOEXCEPT + explicit QScopeGuard(F f) noexcept : m_func(std::move(f)) { } @@ -86,6 +91,10 @@ private: template <typename F> +#ifndef __INTEL_COMPILER +// Causes "error #3058: GNU attributes on a template redeclaration have no effect" +Q_REQUIRED_RESULT +#endif QScopeGuard<F> qScopeGuard(F f) { return QScopeGuard<F>(std::move(f)); diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h index 6640c8486d..7ae715d247 100644 --- a/src/corelib/tools/qset.h +++ b/src/corelib/tools/qset.h @@ -41,6 +41,8 @@ #define QSET_H #include <QtCore/qhash.h> +#include <QtCore/qcontainertools_impl.h> + #ifdef Q_COMPILER_INITIALIZER_LISTS #include <initializer_list> #endif @@ -56,19 +58,23 @@ class QSet typedef QHash<T, QHashDummyValue> Hash; public: - inline QSet() Q_DECL_NOTHROW {} + inline QSet() noexcept {} #ifdef Q_COMPILER_INITIALIZER_LISTS inline QSet(std::initializer_list<T> list) + : QSet(list.begin(), list.end()) {} +#endif + template <typename InputIterator, QtPrivate::IfIsInputIterator<InputIterator> = true> + inline QSet(InputIterator first, InputIterator last) { - reserve(int(list.size())); - for (typename std::initializer_list<T>::const_iterator it = list.begin(); it != list.end(); ++it) - insert(*it); + QtPrivate::reserveIfForwardIterator(this, first, last); + for (; first != last; ++first) + insert(*first); } -#endif + // compiler-generated copy/move ctor/assignment operators are fine! // compiler-generated destructor is fine! - inline void swap(QSet<T> &other) Q_DECL_NOTHROW { q_hash.swap(other.q_hash); } + inline void swap(QSet<T> &other) noexcept { q_hash.swap(other.q_hash); } inline bool operator==(const QSet<T> &other) const { return q_hash == other.q_hash; } @@ -176,20 +182,20 @@ public: typedef std::reverse_iterator<const_iterator> const_reverse_iterator; inline iterator begin() { return q_hash.begin(); } - inline const_iterator begin() const Q_DECL_NOTHROW { return q_hash.begin(); } - inline const_iterator cbegin() const Q_DECL_NOTHROW { return q_hash.begin(); } - inline const_iterator constBegin() const Q_DECL_NOTHROW { return q_hash.constBegin(); } + inline const_iterator begin() const noexcept { return q_hash.begin(); } + inline const_iterator cbegin() const noexcept { return q_hash.begin(); } + inline const_iterator constBegin() const noexcept { return q_hash.constBegin(); } inline iterator end() { return q_hash.end(); } - inline const_iterator end() const Q_DECL_NOTHROW { return q_hash.end(); } - inline const_iterator cend() const Q_DECL_NOTHROW { return q_hash.end(); } - inline const_iterator constEnd() const Q_DECL_NOTHROW { return q_hash.constEnd(); } + inline const_iterator end() const noexcept { return q_hash.end(); } + inline const_iterator cend() const noexcept { return q_hash.end(); } + inline const_iterator constEnd() const noexcept { return q_hash.constEnd(); } reverse_iterator rbegin() { return reverse_iterator(end()); } reverse_iterator rend() { return reverse_iterator(begin()); } - const_reverse_iterator rbegin() const Q_DECL_NOTHROW { return const_reverse_iterator(end()); } - const_reverse_iterator rend() const Q_DECL_NOTHROW { return const_reverse_iterator(begin()); } - const_reverse_iterator crbegin() const Q_DECL_NOTHROW { return const_reverse_iterator(end()); } - const_reverse_iterator crend() const Q_DECL_NOTHROW { return const_reverse_iterator(begin()); } + const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } + const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } + const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } iterator erase(iterator i) { return erase(m2c(i)); } @@ -252,14 +258,14 @@ public: private: Hash q_hash; - static const_iterator m2c(iterator it) Q_DECL_NOTHROW + static const_iterator m2c(iterator it) noexcept { return const_iterator(typename Hash::const_iterator(it.i.i)); } bool isValidIterator(const iterator &i) const { return q_hash.isValidIterator(reinterpret_cast<const typename Hash::iterator&>(i)); } - bool isValidIterator(const const_iterator &i) const Q_DECL_NOTHROW + bool isValidIterator(const const_iterator &i) const noexcept { return q_hash.isValidIterator(reinterpret_cast<const typename Hash::const_iterator&>(i)); } @@ -267,7 +273,7 @@ private: template <typename T> uint qHash(const QSet<T> &key, uint seed = 0) -Q_DECL_NOEXCEPT_EXPR(noexcept(qHashRangeCommutative(key.begin(), key.end(), seed))) +noexcept(noexcept(qHashRangeCommutative(key.begin(), key.end(), seed))) { return qHashRangeCommutative(key.begin(), key.end(), seed); } diff --git a/src/corelib/tools/qset.qdoc b/src/corelib/tools/qset.qdoc index 48863f2399..2e7a5a29ce 100644 --- a/src/corelib/tools/qset.qdoc +++ b/src/corelib/tools/qset.qdoc @@ -113,6 +113,17 @@ compiled in C++11 mode. */ +/*! \fn template <class T> template<typename InputIterator> QSet<T>::QSet(InputIterator first, InputIterator last) + \since 5.14 + + Constructs a set with the contents in the iterator range [\a first, \a last). + + The value type of \c InputIterator must be convertible to \c T. + + \note If the range [\a first, \a last) contains duplicate elements, + the first one is retained. +*/ + /*! \fn template <class T> void QSet<T>::swap(QSet<T> &other) diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h index 6930cb96a5..cbaa1aa3c4 100644 --- a/src/corelib/tools/qshareddata.h +++ b/src/corelib/tools/qshareddata.h @@ -88,7 +88,7 @@ public: inline QSharedDataPointer() { d = nullptr; } inline ~QSharedDataPointer() { if (d && !d->ref.deref()) delete d; } - explicit QSharedDataPointer(T *data) Q_DECL_NOTHROW; + explicit QSharedDataPointer(T *data) noexcept; 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) { @@ -113,8 +113,8 @@ public: return *this; } #ifdef Q_COMPILER_RVALUE_REFS - QSharedDataPointer(QSharedDataPointer &&o) Q_DECL_NOTHROW : d(o.d) { o.d = nullptr; } - inline QSharedDataPointer<T> &operator=(QSharedDataPointer<T> &&other) Q_DECL_NOTHROW + QSharedDataPointer(QSharedDataPointer &&o) noexcept : d(o.d) { o.d = nullptr; } + inline QSharedDataPointer<T> &operator=(QSharedDataPointer<T> &&other) noexcept { QSharedDataPointer moved(std::move(other)); swap(moved); @@ -124,7 +124,7 @@ public: inline bool operator!() const { return !d; } - inline void swap(QSharedDataPointer &other) Q_DECL_NOTHROW + inline void swap(QSharedDataPointer &other) noexcept { qSwap(d, other.d); } protected: @@ -181,7 +181,7 @@ public: inline QExplicitlySharedDataPointer() { d = nullptr; } inline ~QExplicitlySharedDataPointer() { if (d && !d->ref.deref()) delete d; } - explicit QExplicitlySharedDataPointer(T *data) Q_DECL_NOTHROW; + explicit QExplicitlySharedDataPointer(T *data) noexcept; inline QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<T> &o) : d(o.d) { if (d) d->ref.ref(); } template<class X> @@ -219,8 +219,8 @@ public: return *this; } #ifdef Q_COMPILER_RVALUE_REFS - inline QExplicitlySharedDataPointer(QExplicitlySharedDataPointer &&o) Q_DECL_NOTHROW : d(o.d) { o.d = nullptr; } - inline QExplicitlySharedDataPointer<T> &operator=(QExplicitlySharedDataPointer<T> &&other) Q_DECL_NOTHROW + inline QExplicitlySharedDataPointer(QExplicitlySharedDataPointer &&o) noexcept : d(o.d) { o.d = nullptr; } + inline QExplicitlySharedDataPointer<T> &operator=(QExplicitlySharedDataPointer<T> &&other) noexcept { QExplicitlySharedDataPointer moved(std::move(other)); swap(moved); @@ -230,7 +230,7 @@ public: inline bool operator!() const { return !d; } - inline void swap(QExplicitlySharedDataPointer &other) Q_DECL_NOTHROW + inline void swap(QExplicitlySharedDataPointer &other) noexcept { qSwap(d, other.d); } protected: @@ -243,7 +243,7 @@ private: }; template <class T> -Q_INLINE_TEMPLATE QSharedDataPointer<T>::QSharedDataPointer(T *adata) Q_DECL_NOTHROW +Q_INLINE_TEMPLATE QSharedDataPointer<T>::QSharedDataPointer(T *adata) noexcept : d(adata) { if (d) d->ref.ref(); } @@ -280,7 +280,7 @@ Q_OUTOFLINE_TEMPLATE void QExplicitlySharedDataPointer<T>::detach_helper() } template <class T> -Q_INLINE_TEMPLATE QExplicitlySharedDataPointer<T>::QExplicitlySharedDataPointer(T *adata) Q_DECL_NOTHROW +Q_INLINE_TEMPLATE QExplicitlySharedDataPointer<T>::QExplicitlySharedDataPointer(T *adata) noexcept : d(adata) { if (d) d->ref.ref(); } @@ -317,12 +317,12 @@ namespace std { QT_BEGIN_NAMESPACE template <class T> -Q_INLINE_TEMPLATE uint qHash(const QSharedDataPointer<T> &ptr, uint seed = 0) Q_DECL_NOTHROW +Q_INLINE_TEMPLATE uint qHash(const QSharedDataPointer<T> &ptr, uint seed = 0) noexcept { return qHash(ptr.data(), seed); } template <class T> -Q_INLINE_TEMPLATE uint qHash(const QExplicitlySharedDataPointer<T> &ptr, uint seed = 0) Q_DECL_NOTHROW +Q_INLINE_TEMPLATE uint qHash(const QExplicitlySharedDataPointer<T> &ptr, uint seed = 0) noexcept { return qHash(ptr.data(), seed); } diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index bccf8c5740..81d8dcd839 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -303,18 +303,18 @@ public: typedef const value_type &const_reference; typedef qptrdiff difference_type; - T *data() const Q_DECL_NOTHROW { return value; } - T *get() const Q_DECL_NOTHROW { return value; } - bool isNull() const Q_DECL_NOTHROW { return !data(); } - operator RestrictedBool() const Q_DECL_NOTHROW { return isNull() ? nullptr : &QSharedPointer::value; } - bool operator !() const Q_DECL_NOTHROW { return isNull(); } + T *data() const noexcept { return value; } + T *get() const noexcept { return value; } + bool isNull() const noexcept { return !data(); } + operator RestrictedBool() const noexcept { return isNull() ? nullptr : &QSharedPointer::value; } + bool operator !() const noexcept { return isNull(); } T &operator*() const { return *data(); } - T *operator->() const Q_DECL_NOTHROW { return data(); } + T *operator->() const noexcept { return data(); } - Q_DECL_CONSTEXPR QSharedPointer() Q_DECL_NOTHROW : value(nullptr), d(nullptr) { } + Q_DECL_CONSTEXPR QSharedPointer() noexcept : value(nullptr), d(nullptr) { } ~QSharedPointer() { deref(); } - Q_DECL_CONSTEXPR QSharedPointer(std::nullptr_t) Q_DECL_NOTHROW : value(nullptr), d(nullptr) { } + Q_DECL_CONSTEXPR QSharedPointer(std::nullptr_t) noexcept : value(nullptr), d(nullptr) { } template <class X> inline explicit QSharedPointer(X *ptr) : value(ptr) // noexcept @@ -327,22 +327,22 @@ public: template <typename Deleter> QSharedPointer(std::nullptr_t, Deleter) : value(nullptr), d(nullptr) { } - QSharedPointer(const QSharedPointer &other) Q_DECL_NOTHROW : value(other.value), d(other.d) + QSharedPointer(const QSharedPointer &other) noexcept : value(other.value), d(other.d) { if (d) ref(); } - QSharedPointer &operator=(const QSharedPointer &other) Q_DECL_NOTHROW + QSharedPointer &operator=(const QSharedPointer &other) noexcept { QSharedPointer copy(other); swap(copy); return *this; } #ifdef Q_COMPILER_RVALUE_REFS - QSharedPointer(QSharedPointer &&other) Q_DECL_NOTHROW + QSharedPointer(QSharedPointer &&other) noexcept : value(other.value), d(other.d) { other.d = nullptr; other.value = nullptr; } - QSharedPointer &operator=(QSharedPointer &&other) Q_DECL_NOTHROW + QSharedPointer &operator=(QSharedPointer &&other) noexcept { QSharedPointer moved(std::move(other)); swap(moved); @@ -350,7 +350,7 @@ public: } template <class X> - QSharedPointer(QSharedPointer<X> &&other) Q_DECL_NOTHROW + QSharedPointer(QSharedPointer<X> &&other) noexcept : value(other.value), d(other.d) { other.d = nullptr; @@ -358,7 +358,7 @@ public: } template <class X> - QSharedPointer &operator=(QSharedPointer<X> &&other) Q_DECL_NOTHROW + QSharedPointer &operator=(QSharedPointer<X> &&other) noexcept { QSharedPointer moved(std::move(other)); swap(moved); @@ -368,7 +368,7 @@ public: #endif template <class X> - QSharedPointer(const QSharedPointer<X> &other) Q_DECL_NOTHROW : value(other.value), d(other.d) + QSharedPointer(const QSharedPointer<X> &other) noexcept : value(other.value), d(other.d) { if (d) ref(); } template <class X> @@ -456,9 +456,9 @@ public: private: explicit QSharedPointer(Qt::Initialization) {} - void deref() Q_DECL_NOTHROW + void deref() noexcept { deref(d); } - static void deref(Data *dd) Q_DECL_NOTHROW + static void deref(Data *dd) noexcept { if (!dd) return; if (!dd->strongref.deref()) { @@ -499,7 +499,7 @@ private: enableSharedFromThis(ptr); } - void internalSwap(QSharedPointer &other) Q_DECL_NOTHROW + void internalSwap(QSharedPointer &other) noexcept { qSwap(d, other.d); qSwap(this->value, other.value); @@ -512,7 +512,7 @@ public: template <class X> friend class QWeakPointer; template <class X, class Y> friend QSharedPointer<X> QtSharedPointer::copyAndSetPointer(X * ptr, const QSharedPointer<Y> &src); #endif - void ref() const Q_DECL_NOTHROW { d->weakref.ref(); d->strongref.ref(); } + void ref() const noexcept { d->weakref.ref(); d->strongref.ref(); } inline void internalSet(Data *o, T *actual) { @@ -563,12 +563,12 @@ public: typedef const value_type &const_reference; typedef qptrdiff difference_type; - bool isNull() const Q_DECL_NOTHROW { return d == nullptr || d->strongref.load() == 0 || value == nullptr; } - operator RestrictedBool() const Q_DECL_NOTHROW { return isNull() ? nullptr : &QWeakPointer::value; } - bool operator !() const Q_DECL_NOTHROW { return isNull(); } - T *data() const Q_DECL_NOTHROW { return d == nullptr || d->strongref.load() == 0 ? nullptr : value; } + bool isNull() const noexcept { return d == nullptr || d->strongref.load() == 0 || value == nullptr; } + operator RestrictedBool() const noexcept { return isNull() ? nullptr : &QWeakPointer::value; } + bool operator !() const noexcept { return isNull(); } + T *data() const noexcept { return d == nullptr || d->strongref.load() == 0 ? nullptr : value; } - inline QWeakPointer() Q_DECL_NOTHROW : d(nullptr), value(nullptr) { } + inline QWeakPointer() noexcept : d(nullptr), value(nullptr) { } inline ~QWeakPointer() { if (d && !d->weakref.deref()) delete d; } #ifndef QT_NO_QOBJECT @@ -586,26 +586,26 @@ public: { return *this = QWeakPointer(ptr); } #endif - QWeakPointer(const QWeakPointer &other) Q_DECL_NOTHROW : d(other.d), value(other.value) + QWeakPointer(const QWeakPointer &other) noexcept : d(other.d), value(other.value) { if (d) d->weakref.ref(); } #ifdef Q_COMPILER_RVALUE_REFS - QWeakPointer(QWeakPointer &&other) Q_DECL_NOTHROW + QWeakPointer(QWeakPointer &&other) noexcept : d(other.d), value(other.value) { other.d = nullptr; other.value = nullptr; } - QWeakPointer &operator=(QWeakPointer &&other) Q_DECL_NOTHROW + QWeakPointer &operator=(QWeakPointer &&other) noexcept { QWeakPointer moved(std::move(other)); swap(moved); return *this; } #endif - QWeakPointer &operator=(const QWeakPointer &other) Q_DECL_NOTHROW + QWeakPointer &operator=(const QWeakPointer &other) noexcept { QWeakPointer copy(other); swap(copy); return *this; } - void swap(QWeakPointer &other) Q_DECL_NOTHROW + void swap(QWeakPointer &other) noexcept { qSwap(this->d, other.d); qSwap(this->value, other.value); @@ -633,11 +633,11 @@ public: } template <class X> - bool operator==(const QWeakPointer<X> &o) const Q_DECL_NOTHROW + bool operator==(const QWeakPointer<X> &o) const noexcept { return d == o.d && value == static_cast<const T *>(o.value); } template <class X> - bool operator!=(const QWeakPointer<X> &o) const Q_DECL_NOTHROW + bool operator!=(const QWeakPointer<X> &o) const noexcept { return !(*this == o); } template <class X> @@ -653,11 +653,11 @@ public: } template <class X> - bool operator==(const QSharedPointer<X> &o) const Q_DECL_NOTHROW + bool operator==(const QSharedPointer<X> &o) const noexcept { return d == o.d; } template <class X> - bool operator!=(const QSharedPointer<X> &o) const Q_DECL_NOTHROW + bool operator!=(const QSharedPointer<X> &o) const noexcept { return !(*this == o); } inline void clear() { *this = QWeakPointer(); } @@ -739,92 +739,92 @@ public: // operator== and operator!= // template <class T, class X> -bool operator==(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2) Q_DECL_NOTHROW +bool operator==(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2) noexcept { return ptr1.data() == ptr2.data(); } template <class T, class X> -bool operator!=(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2) Q_DECL_NOTHROW +bool operator!=(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2) noexcept { return ptr1.data() != ptr2.data(); } template <class T, class X> -bool operator==(const QSharedPointer<T> &ptr1, const X *ptr2) Q_DECL_NOTHROW +bool operator==(const QSharedPointer<T> &ptr1, const X *ptr2) noexcept { return ptr1.data() == ptr2; } template <class T, class X> -bool operator==(const T *ptr1, const QSharedPointer<X> &ptr2) Q_DECL_NOTHROW +bool operator==(const T *ptr1, const QSharedPointer<X> &ptr2) noexcept { return ptr1 == ptr2.data(); } template <class T, class X> -bool operator!=(const QSharedPointer<T> &ptr1, const X *ptr2) Q_DECL_NOTHROW +bool operator!=(const QSharedPointer<T> &ptr1, const X *ptr2) noexcept { return !(ptr1 == ptr2); } template <class T, class X> -bool operator!=(const T *ptr1, const QSharedPointer<X> &ptr2) Q_DECL_NOTHROW +bool operator!=(const T *ptr1, const QSharedPointer<X> &ptr2) noexcept { return !(ptr2 == ptr1); } template <class T, class X> -bool operator==(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2) Q_DECL_NOTHROW +bool operator==(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2) noexcept { return ptr2 == ptr1; } template <class T, class X> -bool operator!=(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2) Q_DECL_NOTHROW +bool operator!=(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2) noexcept { return ptr2 != ptr1; } template<class T> -inline bool operator==(const QSharedPointer<T> &lhs, std::nullptr_t) Q_DECL_NOTHROW +inline bool operator==(const QSharedPointer<T> &lhs, std::nullptr_t) noexcept { return lhs.isNull(); } template<class T> -inline bool operator!=(const QSharedPointer<T> &lhs, std::nullptr_t) Q_DECL_NOTHROW +inline bool operator!=(const QSharedPointer<T> &lhs, std::nullptr_t) noexcept { return !lhs.isNull(); } template<class T> -inline bool operator==(std::nullptr_t, const QSharedPointer<T> &rhs) Q_DECL_NOTHROW +inline bool operator==(std::nullptr_t, const QSharedPointer<T> &rhs) noexcept { return rhs.isNull(); } template<class T> -inline bool operator!=(std::nullptr_t, const QSharedPointer<T> &rhs) Q_DECL_NOTHROW +inline bool operator!=(std::nullptr_t, const QSharedPointer<T> &rhs) noexcept { return !rhs.isNull(); } template<class T> -inline bool operator==(const QWeakPointer<T> &lhs, std::nullptr_t) Q_DECL_NOTHROW +inline bool operator==(const QWeakPointer<T> &lhs, std::nullptr_t) noexcept { return lhs.isNull(); } template<class T> -inline bool operator!=(const QWeakPointer<T> &lhs, std::nullptr_t) Q_DECL_NOTHROW +inline bool operator!=(const QWeakPointer<T> &lhs, std::nullptr_t) noexcept { return !lhs.isNull(); } template<class T> -inline bool operator==(std::nullptr_t, const QWeakPointer<T> &rhs) Q_DECL_NOTHROW +inline bool operator==(std::nullptr_t, const QWeakPointer<T> &rhs) noexcept { return rhs.isNull(); } template<class T> -inline bool operator!=(std::nullptr_t, const QWeakPointer<T> &rhs) Q_DECL_NOTHROW +inline bool operator!=(std::nullptr_t, const QWeakPointer<T> &rhs) noexcept { return !rhs.isNull(); } diff --git a/src/corelib/tools/qsize.cpp b/src/corelib/tools/qsize.cpp index 3e97947ad2..fe508ad459 100644 --- a/src/corelib/tools/qsize.cpp +++ b/src/corelib/tools/qsize.cpp @@ -163,7 +163,7 @@ QT_BEGIN_NAMESPACE \sa setWidth(), setHeight(), transposed() */ -void QSize::transpose() Q_DECL_NOTHROW +void QSize::transpose() noexcept { qSwap(wd, ht); } @@ -222,7 +222,7 @@ void QSize::transpose() Q_DECL_NOTHROW Return a size scaled to a rectangle with the given size \a s, according to the specified \a mode. */ -QSize QSize::scaled(const QSize &s, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW +QSize QSize::scaled(const QSize &s, Qt::AspectRatioMode mode) const noexcept { if (mode == Qt::IgnoreAspectRatio || wd == 0 || ht == 0) { return s; @@ -594,7 +594,7 @@ QDebug operator<<(QDebug dbg, const QSize &s) \sa setWidth(), setHeight(), transposed() */ -void QSizeF::transpose() Q_DECL_NOTHROW +void QSizeF::transpose() noexcept { qSwap(wd, ht); } @@ -653,7 +653,7 @@ void QSizeF::transpose() Q_DECL_NOTHROW Returns a size scaled to a rectangle with the given size \a s, according to the specified \a mode. */ -QSizeF QSizeF::scaled(const QSizeF &s, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW +QSizeF QSizeF::scaled(const QSizeF &s, Qt::AspectRatioMode mode) const noexcept { if (mode == Qt::IgnoreAspectRatio || qIsNull(wd) || qIsNull(ht)) { return s; diff --git a/src/corelib/tools/qsize.h b/src/corelib/tools/qsize.h index bb29dca7c4..4114609856 100644 --- a/src/corelib/tools/qsize.h +++ b/src/corelib/tools/qsize.h @@ -52,46 +52,46 @@ QT_BEGIN_NAMESPACE class Q_CORE_EXPORT QSize { public: - Q_DECL_CONSTEXPR QSize() Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR QSize(int w, int h) Q_DECL_NOTHROW; - - Q_DECL_CONSTEXPR inline bool isNull() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline bool isEmpty() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOTHROW; - - Q_DECL_CONSTEXPR inline int width() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline int height() const Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setWidth(int w) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setHeight(int h) Q_DECL_NOTHROW; - void transpose() Q_DECL_NOTHROW; - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSize transposed() const Q_DECL_NOTHROW; - - inline void scale(int w, int h, Qt::AspectRatioMode mode) Q_DECL_NOTHROW; - inline void scale(const QSize &s, Qt::AspectRatioMode mode) Q_DECL_NOTHROW; - Q_REQUIRED_RESULT QSize scaled(int w, int h, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW; - Q_REQUIRED_RESULT QSize scaled(const QSize &s, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW; - - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSize expandedTo(const QSize &) const Q_DECL_NOTHROW; - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSize boundedTo(const QSize &) const Q_DECL_NOTHROW; - - Q_DECL_RELAXED_CONSTEXPR inline int &rwidth() Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline int &rheight() Q_DECL_NOTHROW; - - Q_DECL_RELAXED_CONSTEXPR inline QSize &operator+=(const QSize &) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline QSize &operator-=(const QSize &) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline QSize &operator*=(qreal c) Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR QSize() noexcept; + Q_DECL_CONSTEXPR QSize(int w, int h) noexcept; + + Q_DECL_CONSTEXPR inline bool isNull() const noexcept; + Q_DECL_CONSTEXPR inline bool isEmpty() const noexcept; + Q_DECL_CONSTEXPR inline bool isValid() const noexcept; + + Q_DECL_CONSTEXPR inline int width() const noexcept; + Q_DECL_CONSTEXPR inline int height() const noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setWidth(int w) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setHeight(int h) noexcept; + void transpose() noexcept; + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSize transposed() const noexcept; + + inline void scale(int w, int h, Qt::AspectRatioMode mode) noexcept; + inline void scale(const QSize &s, Qt::AspectRatioMode mode) noexcept; + Q_REQUIRED_RESULT QSize scaled(int w, int h, Qt::AspectRatioMode mode) const noexcept; + Q_REQUIRED_RESULT QSize scaled(const QSize &s, Qt::AspectRatioMode mode) const noexcept; + + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSize expandedTo(const QSize &) const noexcept; + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSize boundedTo(const QSize &) const noexcept; + + Q_DECL_RELAXED_CONSTEXPR inline int &rwidth() noexcept; + Q_DECL_RELAXED_CONSTEXPR inline int &rheight() noexcept; + + Q_DECL_RELAXED_CONSTEXPR inline QSize &operator+=(const QSize &) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline QSize &operator-=(const QSize &) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline QSize &operator*=(qreal c) noexcept; inline QSize &operator/=(qreal c); - friend inline Q_DECL_CONSTEXPR bool operator==(const QSize &, const QSize &) Q_DECL_NOTHROW; - friend inline Q_DECL_CONSTEXPR bool operator!=(const QSize &, const QSize &) Q_DECL_NOTHROW; - friend inline Q_DECL_CONSTEXPR const QSize operator+(const QSize &, const QSize &) Q_DECL_NOTHROW; - friend inline Q_DECL_CONSTEXPR const QSize operator-(const QSize &, const QSize &) Q_DECL_NOTHROW; - friend inline Q_DECL_CONSTEXPR const QSize operator*(const QSize &, qreal) Q_DECL_NOTHROW; - friend inline Q_DECL_CONSTEXPR const QSize operator*(qreal, const QSize &) Q_DECL_NOTHROW; + friend inline Q_DECL_CONSTEXPR bool operator==(const QSize &, const QSize &) noexcept; + friend inline Q_DECL_CONSTEXPR bool operator!=(const QSize &, const QSize &) noexcept; + friend inline Q_DECL_CONSTEXPR const QSize operator+(const QSize &, const QSize &) noexcept; + friend inline Q_DECL_CONSTEXPR const QSize operator-(const QSize &, const QSize &) noexcept; + friend inline Q_DECL_CONSTEXPR const QSize operator*(const QSize &, qreal) noexcept; + friend inline Q_DECL_CONSTEXPR const QSize operator*(qreal, const QSize &) noexcept; friend inline const QSize operator/(const QSize &, qreal); #if defined(Q_OS_DARWIN) || defined(Q_QDOC) - Q_REQUIRED_RESULT CGSize toCGSize() const Q_DECL_NOTHROW; + Q_REQUIRED_RESULT CGSize toCGSize() const noexcept; #endif private: @@ -114,74 +114,74 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QSize &); QSize inline functions *****************************************************************************/ -Q_DECL_CONSTEXPR inline QSize::QSize() Q_DECL_NOTHROW : wd(-1), ht(-1) {} +Q_DECL_CONSTEXPR inline QSize::QSize() noexcept : wd(-1), ht(-1) {} -Q_DECL_CONSTEXPR inline QSize::QSize(int w, int h) Q_DECL_NOTHROW : wd(w), ht(h) {} +Q_DECL_CONSTEXPR inline QSize::QSize(int w, int h) noexcept : wd(w), ht(h) {} -Q_DECL_CONSTEXPR inline bool QSize::isNull() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool QSize::isNull() const noexcept { return wd==0 && ht==0; } -Q_DECL_CONSTEXPR inline bool QSize::isEmpty() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool QSize::isEmpty() const noexcept { return wd<1 || ht<1; } -Q_DECL_CONSTEXPR inline bool QSize::isValid() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool QSize::isValid() const noexcept { return wd>=0 && ht>=0; } -Q_DECL_CONSTEXPR inline int QSize::width() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline int QSize::width() const noexcept { return wd; } -Q_DECL_CONSTEXPR inline int QSize::height() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline int QSize::height() const noexcept { return ht; } -Q_DECL_RELAXED_CONSTEXPR inline void QSize::setWidth(int w) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QSize::setWidth(int w) noexcept { wd = w; } -Q_DECL_RELAXED_CONSTEXPR inline void QSize::setHeight(int h) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QSize::setHeight(int h) noexcept { ht = h; } -Q_DECL_CONSTEXPR inline QSize QSize::transposed() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QSize QSize::transposed() const noexcept { return QSize(ht, wd); } -inline void QSize::scale(int w, int h, Qt::AspectRatioMode mode) Q_DECL_NOTHROW +inline void QSize::scale(int w, int h, Qt::AspectRatioMode mode) noexcept { scale(QSize(w, h), mode); } -inline void QSize::scale(const QSize &s, Qt::AspectRatioMode mode) Q_DECL_NOTHROW +inline void QSize::scale(const QSize &s, Qt::AspectRatioMode mode) noexcept { *this = scaled(s, mode); } -inline QSize QSize::scaled(int w, int h, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW +inline QSize QSize::scaled(int w, int h, Qt::AspectRatioMode mode) const noexcept { return scaled(QSize(w, h), mode); } -Q_DECL_RELAXED_CONSTEXPR inline int &QSize::rwidth() Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline int &QSize::rwidth() noexcept { return wd; } -Q_DECL_RELAXED_CONSTEXPR inline int &QSize::rheight() Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline int &QSize::rheight() noexcept { return ht; } -Q_DECL_RELAXED_CONSTEXPR inline QSize &QSize::operator+=(const QSize &s) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QSize &QSize::operator+=(const QSize &s) noexcept { wd+=s.wd; ht+=s.ht; return *this; } -Q_DECL_RELAXED_CONSTEXPR inline QSize &QSize::operator-=(const QSize &s) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QSize &QSize::operator-=(const QSize &s) noexcept { wd-=s.wd; ht-=s.ht; return *this; } -Q_DECL_RELAXED_CONSTEXPR inline QSize &QSize::operator*=(qreal c) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QSize &QSize::operator*=(qreal c) noexcept { wd = qRound(wd*c); ht = qRound(ht*c); return *this; } -Q_DECL_CONSTEXPR inline bool operator==(const QSize &s1, const QSize &s2) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool operator==(const QSize &s1, const QSize &s2) noexcept { return s1.wd == s2.wd && s1.ht == s2.ht; } -Q_DECL_CONSTEXPR inline bool operator!=(const QSize &s1, const QSize &s2) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool operator!=(const QSize &s1, const QSize &s2) noexcept { return s1.wd != s2.wd || s1.ht != s2.ht; } -Q_DECL_CONSTEXPR inline const QSize operator+(const QSize & s1, const QSize & s2) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline const QSize operator+(const QSize & s1, const QSize & s2) noexcept { return QSize(s1.wd+s2.wd, s1.ht+s2.ht); } -Q_DECL_CONSTEXPR inline const QSize operator-(const QSize &s1, const QSize &s2) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline const QSize operator-(const QSize &s1, const QSize &s2) noexcept { return QSize(s1.wd-s2.wd, s1.ht-s2.ht); } -Q_DECL_CONSTEXPR inline const QSize operator*(const QSize &s, qreal c) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline const QSize operator*(const QSize &s, qreal c) noexcept { return QSize(qRound(s.wd*c), qRound(s.ht*c)); } -Q_DECL_CONSTEXPR inline const QSize operator*(qreal c, const QSize &s) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline const QSize operator*(qreal c, const QSize &s) noexcept { return QSize(qRound(s.wd*c), qRound(s.ht*c)); } inline QSize &QSize::operator/=(qreal c) @@ -197,12 +197,12 @@ inline const QSize operator/(const QSize &s, qreal c) return QSize(qRound(s.wd/c), qRound(s.ht/c)); } -Q_DECL_CONSTEXPR inline QSize QSize::expandedTo(const QSize & otherSize) const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QSize QSize::expandedTo(const QSize & otherSize) const noexcept { return QSize(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht)); } -Q_DECL_CONSTEXPR inline QSize QSize::boundedTo(const QSize & otherSize) const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QSize QSize::boundedTo(const QSize & otherSize) const noexcept { return QSize(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht)); } @@ -215,50 +215,50 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QSize &); class Q_CORE_EXPORT QSizeF { public: - Q_DECL_CONSTEXPR QSizeF() Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR QSizeF(const QSize &sz) Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR QSizeF(qreal w, qreal h) Q_DECL_NOTHROW; - - inline bool isNull() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline bool isEmpty() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOTHROW; - - Q_DECL_CONSTEXPR inline qreal width() const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline qreal height() const Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setWidth(qreal w) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline void setHeight(qreal h) Q_DECL_NOTHROW; - void transpose() Q_DECL_NOTHROW; - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSizeF transposed() const Q_DECL_NOTHROW; - - inline void scale(qreal w, qreal h, Qt::AspectRatioMode mode) Q_DECL_NOTHROW; - inline void scale(const QSizeF &s, Qt::AspectRatioMode mode) Q_DECL_NOTHROW; - Q_REQUIRED_RESULT QSizeF scaled(qreal w, qreal h, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW; - Q_REQUIRED_RESULT QSizeF scaled(const QSizeF &s, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW; - - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSizeF expandedTo(const QSizeF &) const Q_DECL_NOTHROW; - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSizeF boundedTo(const QSizeF &) const Q_DECL_NOTHROW; - - Q_DECL_RELAXED_CONSTEXPR inline qreal &rwidth() Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline qreal &rheight() Q_DECL_NOTHROW; - - Q_DECL_RELAXED_CONSTEXPR inline QSizeF &operator+=(const QSizeF &) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline QSizeF &operator-=(const QSizeF &) Q_DECL_NOTHROW; - Q_DECL_RELAXED_CONSTEXPR inline QSizeF &operator*=(qreal c) Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR QSizeF() noexcept; + Q_DECL_CONSTEXPR QSizeF(const QSize &sz) noexcept; + Q_DECL_CONSTEXPR QSizeF(qreal w, qreal h) noexcept; + + inline bool isNull() const noexcept; + Q_DECL_CONSTEXPR inline bool isEmpty() const noexcept; + Q_DECL_CONSTEXPR inline bool isValid() const noexcept; + + Q_DECL_CONSTEXPR inline qreal width() const noexcept; + Q_DECL_CONSTEXPR inline qreal height() const noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setWidth(qreal w) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline void setHeight(qreal h) noexcept; + void transpose() noexcept; + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSizeF transposed() const noexcept; + + inline void scale(qreal w, qreal h, Qt::AspectRatioMode mode) noexcept; + inline void scale(const QSizeF &s, Qt::AspectRatioMode mode) noexcept; + Q_REQUIRED_RESULT QSizeF scaled(qreal w, qreal h, Qt::AspectRatioMode mode) const noexcept; + Q_REQUIRED_RESULT QSizeF scaled(const QSizeF &s, Qt::AspectRatioMode mode) const noexcept; + + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSizeF expandedTo(const QSizeF &) const noexcept; + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QSizeF boundedTo(const QSizeF &) const noexcept; + + Q_DECL_RELAXED_CONSTEXPR inline qreal &rwidth() noexcept; + Q_DECL_RELAXED_CONSTEXPR inline qreal &rheight() noexcept; + + Q_DECL_RELAXED_CONSTEXPR inline QSizeF &operator+=(const QSizeF &) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline QSizeF &operator-=(const QSizeF &) noexcept; + Q_DECL_RELAXED_CONSTEXPR inline QSizeF &operator*=(qreal c) noexcept; inline QSizeF &operator/=(qreal c); - friend Q_DECL_CONSTEXPR inline bool operator==(const QSizeF &, const QSizeF &) Q_DECL_NOTHROW; - friend Q_DECL_CONSTEXPR inline bool operator!=(const QSizeF &, const QSizeF &) Q_DECL_NOTHROW; - friend Q_DECL_CONSTEXPR inline const QSizeF operator+(const QSizeF &, const QSizeF &) Q_DECL_NOTHROW; - friend Q_DECL_CONSTEXPR inline const QSizeF operator-(const QSizeF &, const QSizeF &) Q_DECL_NOTHROW; - friend Q_DECL_CONSTEXPR inline const QSizeF operator*(const QSizeF &, qreal) Q_DECL_NOTHROW; - friend Q_DECL_CONSTEXPR inline const QSizeF operator*(qreal, const QSizeF &) Q_DECL_NOTHROW; + friend Q_DECL_CONSTEXPR inline bool operator==(const QSizeF &, const QSizeF &) noexcept; + friend Q_DECL_CONSTEXPR inline bool operator!=(const QSizeF &, const QSizeF &) noexcept; + friend Q_DECL_CONSTEXPR inline const QSizeF operator+(const QSizeF &, const QSizeF &) noexcept; + friend Q_DECL_CONSTEXPR inline const QSizeF operator-(const QSizeF &, const QSizeF &) noexcept; + friend Q_DECL_CONSTEXPR inline const QSizeF operator*(const QSizeF &, qreal) noexcept; + friend Q_DECL_CONSTEXPR inline const QSizeF operator*(qreal, const QSizeF &) noexcept; friend inline const QSizeF operator/(const QSizeF &, qreal); - Q_DECL_CONSTEXPR inline QSize toSize() const Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR inline QSize toSize() const noexcept; #if defined(Q_OS_DARWIN) || defined(Q_QDOC) - Q_REQUIRED_RESULT static QSizeF fromCGSize(CGSize size) Q_DECL_NOTHROW; - Q_REQUIRED_RESULT CGSize toCGSize() const Q_DECL_NOTHROW; + Q_REQUIRED_RESULT static QSizeF fromCGSize(CGSize size) noexcept; + Q_REQUIRED_RESULT CGSize toCGSize() const noexcept; #endif private: @@ -282,76 +282,76 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QSizeF &); QSizeF inline functions *****************************************************************************/ -Q_DECL_CONSTEXPR inline QSizeF::QSizeF() Q_DECL_NOTHROW : wd(-1.), ht(-1.) {} +Q_DECL_CONSTEXPR inline QSizeF::QSizeF() noexcept : wd(-1.), ht(-1.) {} -Q_DECL_CONSTEXPR inline QSizeF::QSizeF(const QSize &sz) Q_DECL_NOTHROW : wd(sz.width()), ht(sz.height()) {} +Q_DECL_CONSTEXPR inline QSizeF::QSizeF(const QSize &sz) noexcept : wd(sz.width()), ht(sz.height()) {} -Q_DECL_CONSTEXPR inline QSizeF::QSizeF(qreal w, qreal h) Q_DECL_NOTHROW : wd(w), ht(h) {} +Q_DECL_CONSTEXPR inline QSizeF::QSizeF(qreal w, qreal h) noexcept : wd(w), ht(h) {} -inline bool QSizeF::isNull() const Q_DECL_NOTHROW +inline bool QSizeF::isNull() const noexcept { return qIsNull(wd) && qIsNull(ht); } -Q_DECL_CONSTEXPR inline bool QSizeF::isEmpty() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool QSizeF::isEmpty() const noexcept { return wd <= 0. || ht <= 0.; } -Q_DECL_CONSTEXPR inline bool QSizeF::isValid() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool QSizeF::isValid() const noexcept { return wd >= 0. && ht >= 0.; } -Q_DECL_CONSTEXPR inline qreal QSizeF::width() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline qreal QSizeF::width() const noexcept { return wd; } -Q_DECL_CONSTEXPR inline qreal QSizeF::height() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline qreal QSizeF::height() const noexcept { return ht; } -Q_DECL_RELAXED_CONSTEXPR inline void QSizeF::setWidth(qreal w) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QSizeF::setWidth(qreal w) noexcept { wd = w; } -Q_DECL_RELAXED_CONSTEXPR inline void QSizeF::setHeight(qreal h) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline void QSizeF::setHeight(qreal h) noexcept { ht = h; } -Q_DECL_CONSTEXPR inline QSizeF QSizeF::transposed() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QSizeF QSizeF::transposed() const noexcept { return QSizeF(ht, wd); } -inline void QSizeF::scale(qreal w, qreal h, Qt::AspectRatioMode mode) Q_DECL_NOTHROW +inline void QSizeF::scale(qreal w, qreal h, Qt::AspectRatioMode mode) noexcept { scale(QSizeF(w, h), mode); } -inline void QSizeF::scale(const QSizeF &s, Qt::AspectRatioMode mode) Q_DECL_NOTHROW +inline void QSizeF::scale(const QSizeF &s, Qt::AspectRatioMode mode) noexcept { *this = scaled(s, mode); } -inline QSizeF QSizeF::scaled(qreal w, qreal h, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW +inline QSizeF QSizeF::scaled(qreal w, qreal h, Qt::AspectRatioMode mode) const noexcept { return scaled(QSizeF(w, h), mode); } -Q_DECL_RELAXED_CONSTEXPR inline qreal &QSizeF::rwidth() Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline qreal &QSizeF::rwidth() noexcept { return wd; } -Q_DECL_RELAXED_CONSTEXPR inline qreal &QSizeF::rheight() Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline qreal &QSizeF::rheight() noexcept { return ht; } -Q_DECL_RELAXED_CONSTEXPR inline QSizeF &QSizeF::operator+=(const QSizeF &s) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QSizeF &QSizeF::operator+=(const QSizeF &s) noexcept { wd += s.wd; ht += s.ht; return *this; } -Q_DECL_RELAXED_CONSTEXPR inline QSizeF &QSizeF::operator-=(const QSizeF &s) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QSizeF &QSizeF::operator-=(const QSizeF &s) noexcept { wd -= s.wd; ht -= s.ht; return *this; } -Q_DECL_RELAXED_CONSTEXPR inline QSizeF &QSizeF::operator*=(qreal c) Q_DECL_NOTHROW +Q_DECL_RELAXED_CONSTEXPR inline QSizeF &QSizeF::operator*=(qreal c) noexcept { wd *= c; ht *= c; return *this; } -Q_DECL_CONSTEXPR inline bool operator==(const QSizeF &s1, const QSizeF &s2) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool operator==(const QSizeF &s1, const QSizeF &s2) noexcept { return qFuzzyCompare(s1.wd, s2.wd) && qFuzzyCompare(s1.ht, s2.ht); } -Q_DECL_CONSTEXPR inline bool operator!=(const QSizeF &s1, const QSizeF &s2) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool operator!=(const QSizeF &s1, const QSizeF &s2) noexcept { return !qFuzzyCompare(s1.wd, s2.wd) || !qFuzzyCompare(s1.ht, s2.ht); } -Q_DECL_CONSTEXPR inline const QSizeF operator+(const QSizeF & s1, const QSizeF & s2) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline const QSizeF operator+(const QSizeF & s1, const QSizeF & s2) noexcept { return QSizeF(s1.wd+s2.wd, s1.ht+s2.ht); } -Q_DECL_CONSTEXPR inline const QSizeF operator-(const QSizeF &s1, const QSizeF &s2) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline const QSizeF operator-(const QSizeF &s1, const QSizeF &s2) noexcept { return QSizeF(s1.wd-s2.wd, s1.ht-s2.ht); } -Q_DECL_CONSTEXPR inline const QSizeF operator*(const QSizeF &s, qreal c) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline const QSizeF operator*(const QSizeF &s, qreal c) noexcept { return QSizeF(s.wd*c, s.ht*c); } -Q_DECL_CONSTEXPR inline const QSizeF operator*(qreal c, const QSizeF &s) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline const QSizeF operator*(qreal c, const QSizeF &s) noexcept { return QSizeF(s.wd*c, s.ht*c); } inline QSizeF &QSizeF::operator/=(qreal c) @@ -367,17 +367,17 @@ inline const QSizeF operator/(const QSizeF &s, qreal c) return QSizeF(s.wd/c, s.ht/c); } -Q_DECL_CONSTEXPR inline QSizeF QSizeF::expandedTo(const QSizeF & otherSize) const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QSizeF QSizeF::expandedTo(const QSizeF & otherSize) const noexcept { return QSizeF(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht)); } -Q_DECL_CONSTEXPR inline QSizeF QSizeF::boundedTo(const QSizeF & otherSize) const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QSizeF QSizeF::boundedTo(const QSizeF & otherSize) const noexcept { return QSizeF(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht)); } -Q_DECL_CONSTEXPR inline QSize QSizeF::toSize() const Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline QSize QSizeF::toSize() const noexcept { return QSize(qRound(wd), qRound(ht)); } diff --git a/src/corelib/tools/qstack.h b/src/corelib/tools/qstack.h index bf04935b50..e59212aa2a 100644 --- a/src/corelib/tools/qstack.h +++ b/src/corelib/tools/qstack.h @@ -50,7 +50,7 @@ class QStack : public QVector<T> { public: // compiler-generated special member functions are fine! - inline void swap(QStack<T> &other) Q_DECL_NOTHROW { QVector<T>::swap(other); } // prevent QVector<->QStack swaps + inline void swap(QStack<T> &other) noexcept { QVector<T>::swap(other); } // prevent QVector<->QStack swaps inline void push(const T &t) { QVector<T>::append(t); } T pop(); T &top(); diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index a123aa8e75..029499039c 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -2,6 +2,7 @@ ** ** Copyright (C) 2016 The Qt Company Ltd. ** Copyright (C) 2018 Intel Corporation. +** Copyright (C) 2019 Mail.ru Group. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -142,19 +143,11 @@ extern "C" void qt_toLatin1_mips_dsp_asm(uchar *dst, const ushort *src, int leng #endif // internal -int qFindString(const QChar *haystack, int haystackLen, int from, - const QChar *needle, int needleLen, Qt::CaseSensitivity cs); -int qFindStringBoyerMoore(const QChar *haystack, int haystackLen, int from, - const QChar *needle, int needleLen, Qt::CaseSensitivity cs); -static inline int qt_last_index_of(const QChar *haystack, int haystackLen, QChar needle, - int from, Qt::CaseSensitivity cs); -static inline int qt_string_count(const QChar *haystack, int haystackLen, - const QChar *needle, int needleLen, - Qt::CaseSensitivity cs); -static inline int qt_string_count(const QChar *haystack, int haystackLen, - QChar needle, Qt::CaseSensitivity cs); -static inline int qt_find_latin1_string(const QChar *hay, int size, QLatin1String needle, - int from, Qt::CaseSensitivity cs); +qsizetype qFindStringBoyerMoore(QStringView haystack, qsizetype from, QStringView needle, Qt::CaseSensitivity cs); +static inline qsizetype qt_last_index_of(QStringView haystack, QChar needle, qsizetype from, Qt::CaseSensitivity cs); +static inline qsizetype qt_string_count(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs); +static inline qsizetype qt_string_count(QStringView haystack, QChar needle, Qt::CaseSensitivity cs); + static inline bool qt_starts_with(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs); static inline bool qt_starts_with(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs); static inline bool qt_starts_with(QStringView haystack, QChar needle, Qt::CaseSensitivity cs); @@ -162,7 +155,7 @@ static inline bool qt_ends_with(QStringView haystack, QStringView needle, Qt::Ca static inline bool qt_ends_with(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs); static inline bool qt_ends_with(QStringView haystack, QChar needle, Qt::CaseSensitivity cs); -qsizetype QtPrivate::qustrlen(const ushort *str) Q_DECL_NOTHROW +qsizetype QtPrivate::qustrlen(const ushort *str) noexcept { qsizetype result = 0; @@ -208,7 +201,7 @@ qsizetype QtPrivate::qustrlen(const ushort *str) Q_DECL_NOTHROW return result; } -#if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) +#if !defined(__OPTIMIZE_SIZE__) namespace { template <uint MaxCount> struct UnrollTailLoop { @@ -460,7 +453,7 @@ static Q_ALWAYS_INLINE __m128i mm_load8_zero_extend(const void *ptr) // Note: ptr on output may be off by one and point to a preceding US-ASCII // character. Usually harmless. -bool qt_is_ascii(const char *&ptr, const char *end) Q_DECL_NOTHROW +bool qt_is_ascii(const char *&ptr, const char *end) noexcept { #if defined(__SSE2__) // Testing for the high bit can be done efficiently with just PMOVMSKB @@ -520,7 +513,7 @@ bool qt_is_ascii(const char *&ptr, const char *end) Q_DECL_NOTHROW return true; } -bool QtPrivate::isAscii(QLatin1String s) Q_DECL_NOTHROW +bool QtPrivate::isAscii(QLatin1String s) noexcept { const char *ptr = s.begin(); const char *end = s.end(); @@ -547,7 +540,7 @@ static bool isAscii(const QChar *&ptr, const QChar *end) return true; } -bool QtPrivate::isAscii(QStringView s) Q_DECL_NOTHROW +bool QtPrivate::isAscii(QStringView s) noexcept { const QChar *ptr = s.begin(); const QChar *end = s.end(); @@ -555,7 +548,7 @@ bool QtPrivate::isAscii(QStringView s) Q_DECL_NOTHROW return isAscii(ptr, end); } -bool QtPrivate::isLatin1(QStringView s) Q_DECL_NOTHROW +bool QtPrivate::isLatin1(QStringView s) noexcept { const QChar *ptr = s.begin(); const QChar *end = s.end(); @@ -595,7 +588,7 @@ bool QtPrivate::isLatin1(QStringView s) Q_DECL_NOTHROW } // conversion between Latin 1 and UTF-16 -void qt_from_latin1(ushort *dst, const char *str, size_t size) Q_DECL_NOTHROW +void qt_from_latin1(ushort *dst, const char *str, size_t size) noexcept { /* SIMD: * Unpacking with SSE has been shown to improve performance on recent CPUs @@ -638,7 +631,7 @@ void qt_from_latin1(ushort *dst, const char *str, size_t size) Q_DECL_NOTHROW size = size % 8; dst += offset; str += offset; -# if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) +# if !defined(__OPTIMIZE_SIZE__) return UnrollTailLoop<7>::exec(int(size), [=](int i) { dst[i] = (uchar)str[i]; }); # endif #endif @@ -1152,7 +1145,7 @@ static int ucstrncmp(const QChar *a, const uchar *c, size_t l) } template <typename Number> -Q_DECL_CONSTEXPR int lencmp(Number lhs, Number rhs) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR int lencmp(Number lhs, Number rhs) noexcept { return lhs == rhs ? 0 : lhs > rhs ? 1 : @@ -1176,7 +1169,7 @@ static int ucstrcmp(const QChar *a, size_t alen, const char *b, size_t blen) return cmp ? cmp : lencmp(alen, blen); } -static int qt_compare_strings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +static int qt_compare_strings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs) noexcept { if (cs == Qt::CaseSensitive) return ucstrcmp(lhs.begin(), lhs.size(), rhs.begin(), rhs.size()); @@ -1184,7 +1177,7 @@ static int qt_compare_strings(QStringView lhs, QStringView rhs, Qt::CaseSensitiv return ucstricmp(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); } -static int qt_compare_strings(QStringView lhs, QLatin1String rhs, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +static int qt_compare_strings(QStringView lhs, QLatin1String rhs, Qt::CaseSensitivity cs) noexcept { if (cs == Qt::CaseSensitive) return ucstrcmp(lhs.begin(), lhs.size(), rhs.begin(), rhs.size()); @@ -1192,12 +1185,12 @@ static int qt_compare_strings(QStringView lhs, QLatin1String rhs, Qt::CaseSensit return ucstricmp(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); } -static int qt_compare_strings(QLatin1String lhs, QStringView rhs, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +static int qt_compare_strings(QLatin1String lhs, QStringView rhs, Qt::CaseSensitivity cs) noexcept { return -qt_compare_strings(rhs, lhs, cs); } -static int qt_compare_strings(QLatin1String lhs, QLatin1String rhs, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +static int qt_compare_strings(QLatin1String lhs, QLatin1String rhs, Qt::CaseSensitivity cs) noexcept { if (cs == Qt::CaseInsensitive) return qstrnicmp(lhs.data(), lhs.size(), rhs.data(), rhs.size()); @@ -1222,7 +1215,7 @@ static int qt_compare_strings(QLatin1String lhs, QLatin1String rhs, Qt::CaseSens of the characters and is very fast, but is not what a human would expect. Consider sorting user-visible strings with QString::localeAwareCompare(). */ -int QtPrivate::compareStrings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +int QtPrivate::compareStrings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs) noexcept { return qt_compare_strings(lhs, rhs, cs); } @@ -1242,7 +1235,7 @@ int QtPrivate::compareStrings(QStringView lhs, QStringView rhs, Qt::CaseSensitiv of the characters and is very fast, but is not what a human would expect. Consider sorting user-visible strings with QString::localeAwareCompare(). */ -int QtPrivate::compareStrings(QStringView lhs, QLatin1String rhs, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +int QtPrivate::compareStrings(QStringView lhs, QLatin1String rhs, Qt::CaseSensitivity cs) noexcept { return qt_compare_strings(lhs, rhs, cs); } @@ -1262,7 +1255,7 @@ int QtPrivate::compareStrings(QStringView lhs, QLatin1String rhs, Qt::CaseSensit of the characters and is very fast, but is not what a human would expect. Consider sorting user-visible strings with QString::localeAwareCompare(). */ -int QtPrivate::compareStrings(QLatin1String lhs, QStringView rhs, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +int QtPrivate::compareStrings(QLatin1String lhs, QStringView rhs, Qt::CaseSensitivity cs) noexcept { return qt_compare_strings(lhs, rhs, cs); } @@ -1282,47 +1275,14 @@ int QtPrivate::compareStrings(QLatin1String lhs, QStringView rhs, Qt::CaseSensit of the characters and is very fast, but is not what a human would expect. Consider sorting user-visible strings with QString::localeAwareCompare(). */ -int QtPrivate::compareStrings(QLatin1String lhs, QLatin1String rhs, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +int QtPrivate::compareStrings(QLatin1String lhs, QLatin1String rhs, Qt::CaseSensitivity cs) noexcept { return qt_compare_strings(lhs, rhs, cs); } -/*! - \internal - - Returns the index position of the first occurrence of the - character \a ch in the string given by \a str and \a len, - searching forward from index - position \a from. Returns -1 if \a ch could not be found. -*/ -static int findChar(const QChar *str, int len, QChar ch, int from, - Qt::CaseSensitivity cs) -{ - const ushort *s = (const ushort *)str; - ushort c = ch.unicode(); - if (from < 0) - from = qMax(from + len, 0); - if (from < len) { - const ushort *n = s + from; - const ushort *e = s + len; - if (cs == Qt::CaseSensitive) { - n = QtPrivate::qustrchr(QStringView(n, e), c); - if (n != e) - return n - s; - } else { - c = foldCase(c); - --n; - while (++n != e) - if (foldCase(*n) == c) - return n - s; - } - } - return -1; -} - #define REHASH(a) \ - if (sl_minus_1 < sizeof(uint) * CHAR_BIT) \ - hashHaystack -= uint(a) << sl_minus_1; \ + if (sl_minus_1 < sizeof(std::size_t) * CHAR_BIT) \ + hashHaystack -= std::size_t(a) << sl_minus_1; \ hashHaystack <<= 1 inline bool qIsUpper(char ch) @@ -2090,7 +2050,7 @@ int QString::toUcs4_helper(const ushort *uc, int length, uint *out) \note This function does not append a null character to the array. - \sa utf16(), toUcs4(), toLatin1(), toUtf8(), toLocal8Bit(), toStdWString() + \sa utf16(), toUcs4(), toLatin1(), toUtf8(), toLocal8Bit(), toStdWString(), QStringView::toWCharArray() */ /*! \fn QString::QString(const QString &other) @@ -2411,7 +2371,7 @@ void QString::expand(int i) string. */ -QString &QString::operator=(const QString &other) Q_DECL_NOTHROW +QString &QString::operator=(const QString &other) noexcept { other.d->ref.ref(); if (!d->ref.deref()) @@ -3397,7 +3357,7 @@ QString &QString::replace(QChar c, QLatin1String after, Qt::CaseSensitivity cs) expect. Consider sorting user-interface strings with localeAwareCompare(). */ -bool operator==(const QString &s1, const QString &s2) Q_DECL_NOTHROW +bool operator==(const QString &s1, const QString &s2) noexcept { if (s1.d->size != s2.d->size) return false; @@ -3410,7 +3370,7 @@ bool operator==(const QString &s1, const QString &s2) Q_DECL_NOTHROW Returns \c true if this string is equal to \a other; otherwise returns \c false. */ -bool QString::operator==(QLatin1String other) const Q_DECL_NOTHROW +bool QString::operator==(QLatin1String other) const noexcept { if (d->size != other.size()) return false; @@ -3462,7 +3422,7 @@ bool QString::operator==(QLatin1String other) const Q_DECL_NOTHROW expect. Consider sorting user-interface strings using the QString::localeAwareCompare() function. */ -bool operator<(const QString &s1, const QString &s2) Q_DECL_NOTHROW +bool operator<(const QString &s1, const QString &s2) noexcept { return qt_compare_strings(s1, s2, Qt::CaseSensitive) < 0; } @@ -3473,7 +3433,7 @@ bool operator<(const QString &s1, const QString &s2) Q_DECL_NOTHROW Returns \c true if this string is lexically less than the parameter string called \a other; otherwise returns \c false. */ -bool QString::operator<(QLatin1String other) const Q_DECL_NOTHROW +bool QString::operator<(QLatin1String other) const noexcept { return qt_compare_strings(*this, other, Qt::CaseSensitive) < 0; } @@ -3582,7 +3542,7 @@ bool QString::operator<(QLatin1String other) const Q_DECL_NOTHROW Returns \c true if this string is lexically greater than the parameter string \a other; otherwise returns \c false. */ -bool QString::operator>(QLatin1String other) const Q_DECL_NOTHROW +bool QString::operator>(QLatin1String other) const noexcept { return qt_compare_strings(*this, other, Qt::CaseSensitive) > 0; } @@ -3739,7 +3699,8 @@ bool QString::operator>(QLatin1String other) const Q_DECL_NOTHROW */ int QString::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const { - return qFindString(unicode(), length(), from, str.unicode(), str.length(), cs); + // ### Qt6: qsize + return int(QtPrivate::findString(QStringView(unicode(), length()), from, QStringView(str.unicode(), str.length()), cs)); } /*! @@ -3763,85 +3724,8 @@ int QString::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const int QString::indexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const { - return qt_find_latin1_string(unicode(), size(), str, from, cs); -} - -int qFindString( - const QChar *haystack0, int haystackLen, int from, - const QChar *needle0, int needleLen, Qt::CaseSensitivity cs) -{ - const int l = haystackLen; - const int sl = needleLen; - if (from < 0) - from += l; - if (uint(sl + from) > (uint)l) - return -1; - if (!sl) - return from; - if (!l) - return -1; - - if (sl == 1) - return findChar(haystack0, haystackLen, needle0[0], from, cs); - - /* - We use the Boyer-Moore algorithm in cases where the overhead - for the skip table should pay off, otherwise we use a simple - hash function. - */ - if (l > 500 && sl > 5) - return qFindStringBoyerMoore(haystack0, haystackLen, from, - needle0, needleLen, cs); - - auto sv = [sl](const ushort *v) { return QStringView(v, sl); }; - /* - We use some hashing for efficiency's sake. Instead of - comparing strings, we compare the hash value of str with that - of a part of this QString. Only if that matches, we call - qt_string_compare(). - */ - const ushort *needle = (const ushort *)needle0; - const ushort *haystack = (const ushort *)haystack0 + from; - const ushort *end = (const ushort *)haystack0 + (l-sl); - const uint sl_minus_1 = sl - 1; - uint hashNeedle = 0, hashHaystack = 0; - int idx; - - if (cs == Qt::CaseSensitive) { - for (idx = 0; idx < sl; ++idx) { - hashNeedle = ((hashNeedle<<1) + needle[idx]); - hashHaystack = ((hashHaystack<<1) + haystack[idx]); - } - hashHaystack -= haystack[sl_minus_1]; - - while (haystack <= end) { - hashHaystack += haystack[sl_minus_1]; - if (hashHaystack == hashNeedle - && qt_compare_strings(sv(needle), sv(haystack), Qt::CaseSensitive) == 0) - return haystack - (const ushort *)haystack0; - - REHASH(*haystack); - ++haystack; - } - } else { - const ushort *haystack_start = (const ushort *)haystack0; - for (idx = 0; idx < sl; ++idx) { - hashNeedle = (hashNeedle<<1) + foldCase(needle + idx, needle); - hashHaystack = (hashHaystack<<1) + foldCase(haystack + idx, haystack_start); - } - hashHaystack -= foldCase(haystack + sl_minus_1, haystack_start); - - while (haystack <= end) { - hashHaystack += foldCase(haystack + sl_minus_1, haystack_start); - if (hashHaystack == hashNeedle - && qt_compare_strings(sv(needle), sv(haystack), Qt::CaseInsensitive) == 0) - return haystack - (const ushort *)haystack0; - - REHASH(foldCase(haystack, haystack_start)); - ++haystack; - } - } - return -1; + // ### Qt6: qsize + return int(QtPrivate::findString(QStringView(unicode(), size()), from, str, cs)); } /*! @@ -3853,7 +3737,8 @@ int qFindString( */ int QString::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const { - return findChar(unicode(), length(), ch, from, cs); + // ### Qt6: qsize + return int(QtPrivate::findChar(QStringView(unicode(), length()), ch, from, cs)); } /*! @@ -3870,7 +3755,8 @@ int QString::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const */ int QString::indexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const { - return qFindString(unicode(), length(), from, str.unicode(), str.length(), cs); + // ### Qt6: qsize + return int(QtPrivate::findString(QStringView(unicode(), length()), from, QStringView(str.unicode(), str.length()), cs)); } static int lastIndexOfHelper(const ushort *haystack, int from, const ushort *needle, int sl, Qt::CaseSensitivity cs) @@ -3993,7 +3879,8 @@ int QString::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) co */ int QString::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const { - return qt_last_index_of(unicode(), size(), ch, from, cs); + // ### Qt6: qsize + return int(qt_last_index_of(QStringView(unicode(), size()), ch, from, cs)); } /*! @@ -4326,7 +4213,8 @@ QString &QString::replace(const QRegularExpression &re, const QString &after) int QString::count(const QString &str, Qt::CaseSensitivity cs) const { - return qt_string_count(unicode(), size(), str.unicode(), str.size(), cs); + // ### Qt6: qsize + return int(qt_string_count(QStringView(unicode(), size()), QStringView(str.unicode(), str.size()), cs)); } /*! @@ -4342,8 +4230,9 @@ int QString::count(const QString &str, Qt::CaseSensitivity cs) const int QString::count(QChar ch, Qt::CaseSensitivity cs) const { - return qt_string_count(unicode(), size(), ch, cs); - } + // ### Qt6: qsize + return int(qt_string_count(QStringView(unicode(), size()), ch, cs)); +} /*! \since 4.8 @@ -4358,7 +4247,8 @@ int QString::count(QChar ch, Qt::CaseSensitivity cs) const */ int QString::count(const QStringRef &str, Qt::CaseSensitivity cs) const { - return qt_string_count(unicode(), size(), str.unicode(), str.size(), cs); + // ### Qt6: qsize + return int(qt_string_count(QStringView(unicode(), size()), QStringView(str.unicode(), str.size()), cs)); } @@ -4572,7 +4462,7 @@ int QString::indexOf(const QRegularExpression &re, int from, QRegularExpressionM if (match.hasMatch()) { const int ret = match.capturedStart(); if (rmatch) - *rmatch = qMove(match); + *rmatch = std::move(match); return ret; } @@ -4628,7 +4518,7 @@ int QString::lastIndexOf(const QRegularExpression &re, int from, QRegularExpress if (start < endpos) { lastIndex = start; if (rmatch) - *rmatch = qMove(match); + *rmatch = std::move(match); } else { break; } @@ -4671,7 +4561,7 @@ bool QString::contains(const QRegularExpression &re, QRegularExpressionMatch *ma QRegularExpressionMatch m = re.match(*this); bool hasMatch = m.hasMatch(); if (hasMatch && match) - *match = qMove(m); + *match = std::move(m); return hasMatch; } @@ -4831,7 +4721,7 @@ QString QString::section(const QString &sep, int start, int end, SectionFlags fl class qt_section_chunk { public: qt_section_chunk() {} - qt_section_chunk(int l, QStringRef s) : length(l), string(qMove(s)) {} + qt_section_chunk(int l, QStringRef s) : length(l), string(std::move(s)) {} int length; QStringRef string; }; @@ -5782,7 +5672,7 @@ QString QString::simplified_helper(QString &str) namespace { template <typename StringView> - StringView qt_trimmed(StringView s) Q_DECL_NOTHROW + StringView qt_trimmed(StringView s) noexcept { auto begin = s.begin(); auto end = s.end(); @@ -5806,12 +5696,12 @@ namespace { \sa QString::trimmed(), QStringView::trimmed(), QLatin1String::trimmed() */ -QStringView QtPrivate::trimmed(QStringView s) Q_DECL_NOTHROW +QStringView QtPrivate::trimmed(QStringView s) noexcept { return qt_trimmed(s); } -QLatin1String QtPrivate::trimmed(QLatin1String s) Q_DECL_NOTHROW +QLatin1String QtPrivate::trimmed(QLatin1String s) noexcept { return qt_trimmed(s); } @@ -6349,7 +6239,7 @@ QString& QString::fill(QChar ch, int size) Same as compare(*this, \a other, \a cs). */ -int QString::compare(const QString &other, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW +int QString::compare(const QString &other, Qt::CaseSensitivity cs) const noexcept { return qt_compare_strings(*this, other, cs); } @@ -6360,7 +6250,7 @@ int QString::compare(const QString &other, Qt::CaseSensitivity cs) const Q_DECL_ \since 4.5 */ int QString::compare_helper(const QChar *data1, int length1, const QChar *data2, int length2, - Qt::CaseSensitivity cs) Q_DECL_NOTHROW + Qt::CaseSensitivity cs) noexcept { Q_ASSERT(length1 >= 0); Q_ASSERT(length2 >= 0); @@ -6375,7 +6265,7 @@ int QString::compare_helper(const QChar *data1, int length1, const QChar *data2, Same as compare(*this, \a other, \a cs). */ -int QString::compare(QLatin1String other, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW +int QString::compare(QLatin1String other, Qt::CaseSensitivity cs) const noexcept { return qt_compare_strings(*this, other, cs); } @@ -6421,7 +6311,7 @@ int QString::compare_helper(const QChar *data1, int length1, const char *data2, \since 4.5 */ int QString::compare_helper(const QChar *data1, int length1, QLatin1String s2, - Qt::CaseSensitivity cs) Q_DECL_NOTHROW + Qt::CaseSensitivity cs) noexcept { Q_ASSERT(length1 >= 0); Q_ASSERT(data1 || length1 == 0); @@ -6723,7 +6613,7 @@ Q_NEVER_INLINE static QString detachAndConvertCase(T &str, QStringIterator it) { Q_ASSERT(!str.isEmpty()); - QString s = qMove(str); // will copy if T is const QString + QString s = std::move(str); // will copy if T is const QString QChar *pp = s.begin() + it.index(); // will detach if necessary do { @@ -6781,7 +6671,7 @@ static QString convertCase(T &str) return detachAndConvertCase<Traits>(str, it); } } - return qMove(str); + return std::move(str); } } // namespace QUnicodeTables @@ -6835,6 +6725,7 @@ QString QString::toUpper_helper(QString &str) return QUnicodeTables::convertCase<QUnicodeTables::UppercaseTraits>(str); } +#if QT_DEPRECATED_SINCE(5, 14) /*! \obsolete @@ -6848,6 +6739,7 @@ QString &QString::sprintf(const char *cformat, ...) va_end(ap); return *this; } +#endif // ### Qt 6: Consider whether this function shouldn't be removed See task 202871. /*! @@ -6893,6 +6785,7 @@ QString QString::asprintf(const char *cformat, ...) return s; } +#if QT_DEPRECATED_SINCE(5, 14) /*! \obsolete @@ -6902,6 +6795,7 @@ QString &QString::vsprintf(const char *cformat, va_list ap) { return *this = vasprintf(cformat, ap); } +#endif static void append_utf8(QString &qs, const char *cs, int len) { @@ -6911,7 +6805,7 @@ static void append_utf8(QString &qs, const char *cs, int len) qs.resize(newEnd - qs.constData()); } -static uint parse_flag_characters(const char * &c) Q_DECL_NOTHROW +static uint parse_flag_characters(const char * &c) noexcept { uint flags = QLocaleData::ZeroPadExponent; while (true) { @@ -6948,7 +6842,7 @@ static int parse_field_width(const char * &c) enum LengthMod { lm_none, lm_hh, lm_h, lm_l, lm_ll, lm_L, lm_j, lm_z, lm_t }; -static inline bool can_consume(const char * &c, char ch) Q_DECL_NOTHROW +static inline bool can_consume(const char * &c, char ch) noexcept { if (*c == ch) { ++c; @@ -6957,7 +6851,7 @@ static inline bool can_consume(const char * &c, char ch) Q_DECL_NOTHROW return false; } -static LengthMod parse_length_modifier(const char * &c) Q_DECL_NOTHROW +static LengthMod parse_length_modifier(const char * &c) noexcept { switch (*c++) { case 'h': return can_consume(c, 'h') ? lm_hh : lm_h; @@ -7782,10 +7676,10 @@ static ResultList splitString(const StringSource &source, const QChar *sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs, const int separatorSize) { ResultList list; - int start = 0; - int end; - int extra = 0; - while ((end = qFindString(source.constData(), source.size(), start + extra, sep, separatorSize, cs)) != -1) { + typename StringSource::size_type start = 0; + typename StringSource::size_type end; + typename StringSource::size_type extra = 0; + while ((end = QtPrivate::findString(QStringView(source.constData(), source.size()), start + extra, QStringView(sep, separatorSize), cs)) != -1) { if (start != end || behavior == QString::KeepEmptyParts) list.append(source.mid(start, end - start)); start = end + separatorSize; @@ -8920,7 +8814,7 @@ namespace { struct Part { Part() : stringRef(), number(0) {} - Part(const QString &s, int pos, int len, int num = -1) Q_DECL_NOTHROW + Part(const QString &s, int pos, int len, int num = -1) noexcept : stringRef(&s, pos, len), number(num) {} QStringRef stringRef; @@ -10489,7 +10383,7 @@ QString QStringRef::toString() const { Returns \c true if string reference \a s1 is lexically equal to string reference \a s2; otherwise returns \c false. */ -bool operator==(const QStringRef &s1,const QStringRef &s2) Q_DECL_NOTHROW +bool operator==(const QStringRef &s1,const QStringRef &s2) noexcept { return s1.size() == s2.size() && qt_compare_strings(s1, s2, Qt::CaseSensitive) == 0; } @@ -10499,7 +10393,7 @@ bool operator==(const QStringRef &s1,const QStringRef &s2) Q_DECL_NOTHROW Returns \c true if string \a s1 is lexically equal to string reference \a s2; otherwise returns \c false. */ -bool operator==(const QString &s1,const QStringRef &s2) Q_DECL_NOTHROW +bool operator==(const QString &s1,const QStringRef &s2) noexcept { return s1.size() == s2.size() && qt_compare_strings(s1, s2, Qt::CaseSensitive) == 0; } @@ -10509,7 +10403,7 @@ bool operator==(const QString &s1,const QStringRef &s2) Q_DECL_NOTHROW Returns \c true if string \a s1 is lexically equal to string reference \a s2; otherwise returns \c false. */ -bool operator==(QLatin1String s1, const QStringRef &s2) Q_DECL_NOTHROW +bool operator==(QLatin1String s1, const QStringRef &s2) noexcept { if (s1.size() != s2.size()) return false; @@ -10528,7 +10422,7 @@ bool operator==(QLatin1String s1, const QStringRef &s2) Q_DECL_NOTHROW expect. Consider sorting user-interface strings using the QString::localeAwareCompare() function. */ -bool operator<(const QStringRef &s1,const QStringRef &s2) Q_DECL_NOTHROW +bool operator<(const QStringRef &s1,const QStringRef &s2) noexcept { return qt_compare_strings(s1, s2, Qt::CaseSensitive) < 0; } @@ -11158,7 +11052,8 @@ QStringRef QString::midRef(int position, int n) const */ int QStringRef::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const { - return qFindString(unicode(), length(), from, str.unicode(), str.length(), cs); + // ### Qt6: qsize + return int(QtPrivate::findString(QStringView(unicode(), length()), from, QStringView(str.unicode(), str.length()), cs)); } /*! @@ -11173,7 +11068,8 @@ int QStringRef::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) co */ int QStringRef::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const { - return findChar(unicode(), length(), ch, from, cs); + // ### Qt6: qsize + return int(QtPrivate::findChar(QStringView(unicode(), length()), ch, from, cs)); } /*! @@ -11193,7 +11089,8 @@ int QStringRef::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const */ int QStringRef::indexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const { - return qt_find_latin1_string(unicode(), size(), str, from, cs); + // ### Qt6: qsize + return int(QtPrivate::findString(QStringView(unicode(), size()), from, str, cs)); } /*! @@ -11212,7 +11109,8 @@ int QStringRef::indexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) con */ int QStringRef::indexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const { - return qFindString(unicode(), size(), from, str.unicode(), str.size(), cs); + // ### Qt6: qsize + return int(QtPrivate::findString(QStringView(unicode(), size()), from, QStringView(str.unicode(), str.size()), cs)); } /*! @@ -11245,7 +11143,8 @@ int QStringRef::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs */ int QStringRef::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const { - return qt_last_index_of(unicode(), size(), ch, from, cs); + // ### Qt6: qsize + return int(qt_last_index_of(QStringView(unicode(), size()), ch, from, cs)); } template<typename T> @@ -11321,7 +11220,8 @@ int QStringRef::lastIndexOf(const QStringRef &str, int from, Qt::CaseSensitivity */ int QStringRef::count(const QString &str, Qt::CaseSensitivity cs) const { - return qt_string_count(unicode(), size(), str.unicode(), str.size(), cs); + // ### Qt6: qsize + return int(qt_string_count(QStringView(unicode(), size()), QStringView(str.unicode(), str.size()), cs)); } /*! @@ -11338,7 +11238,8 @@ int QStringRef::count(const QString &str, Qt::CaseSensitivity cs) const */ int QStringRef::count(QChar ch, Qt::CaseSensitivity cs) const { - return qt_string_count(unicode(), size(), ch, cs); + // ### Qt6: qsize + return int(qt_string_count(QStringView(unicode(), size()), ch, cs)); } /*! @@ -11355,7 +11256,8 @@ int QStringRef::count(QChar ch, Qt::CaseSensitivity cs) const */ int QStringRef::count(const QStringRef &str, Qt::CaseSensitivity cs) const { - return qt_string_count(unicode(), size(), str.unicode(), str.size(), cs); + // ### Qt6: qsize + return int(qt_string_count(QStringView(unicode(), size()), QStringView(str.unicode(), str.size()), cs)); } /*! @@ -11592,16 +11494,16 @@ bool QStringRef::endsWith(const QStringRef &str, Qt::CaseSensitivity cs) const \sa indexOf(), count() */ -static inline int qt_last_index_of(const QChar *haystack, int haystackLen, QChar needle, - int from, Qt::CaseSensitivity cs) +static inline qsizetype qt_last_index_of(QStringView haystack, QChar needle, + qsizetype from, Qt::CaseSensitivity cs) { - ushort c = needle.unicode(); if (from < 0) - from += haystackLen; - if (uint(from) >= uint(haystackLen)) + from += haystack.size(); + if (std::size_t(from) >= std::size_t(haystack.size())) return -1; if (from >= 0) { - const ushort *b = reinterpret_cast<const ushort*>(haystack); + ushort c = needle.unicode(); + const ushort *b = reinterpret_cast<const ushort*>(haystack.data()); const ushort *n = b + from; if (cs == Qt::CaseSensitive) { for (; n >= b; --n) @@ -11619,30 +11521,28 @@ static inline int qt_last_index_of(const QChar *haystack, int haystackLen, QChar } -static inline int qt_string_count(const QChar *haystack, int haystackLen, - const QChar *needle, int needleLen, - Qt::CaseSensitivity cs) +static inline qsizetype qt_string_count(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) { - int num = 0; - int i = -1; - if (haystackLen > 500 && needleLen > 5) { - QStringMatcher matcher(needle, needleLen, cs); - while ((i = matcher.indexIn(haystack, haystackLen, i + 1)) != -1) + qsizetype num = 0; + qsizetype i = -1; + if (haystack.size() > 500 && needle.size() > 5) { + QStringMatcher matcher(needle, cs); + while ((i = matcher.indexIn(haystack, i + 1)) != -1) ++num; } else { - while ((i = qFindString(haystack, haystackLen, i + 1, needle, needleLen, cs)) != -1) + while ((i = QtPrivate::findString(haystack, i + 1, needle, cs)) != -1) ++num; } return num; } -static inline int qt_string_count(const QChar *unicode, int size, QChar ch, +static inline qsizetype qt_string_count(QStringView haystack, QChar ch, Qt::CaseSensitivity cs) { ushort c = ch.unicode(); - int num = 0; - const ushort *b = reinterpret_cast<const ushort*>(unicode); - const ushort *i = b + size; + qsizetype num = 0; + const ushort *b = reinterpret_cast<const ushort*>(haystack.data()); + const ushort *i = b + haystack.size(); if (cs == Qt::CaseSensitive) { while (i != b) if (*--i == c) @@ -11656,24 +11556,8 @@ static inline int qt_string_count(const QChar *unicode, int size, QChar ch, return num; } -static inline int qt_find_latin1_string(const QChar *haystack, int size, - QLatin1String needle, - int from, Qt::CaseSensitivity cs) -{ - if (size < needle.size()) - return -1; - - const char *latin1 = needle.latin1(); - int len = needle.size(); - QVarLengthArray<ushort> s(len); - qt_from_latin1(s.data(), latin1, len); - - return qFindString(haystack, size, from, - reinterpret_cast<const QChar*>(s.constData()), len, cs); -} - template <typename Haystack, typename Needle> -bool qt_starts_with_impl(Haystack haystack, Needle needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +bool qt_starts_with_impl(Haystack haystack, Needle needle, Qt::CaseSensitivity cs) noexcept { if (haystack.isNull()) return needle.isNull(); // historical behavior, consider changing in ### Qt 6. @@ -11725,28 +11609,28 @@ static inline bool qt_starts_with(QStringView haystack, QChar needle, Qt::CaseSe \sa QtPrivate::endsWith(), QString::endsWith(), QStringView::endsWith(), QLatin1String::endsWith() */ -bool QtPrivate::startsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +bool QtPrivate::startsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) noexcept { return qt_starts_with_impl(haystack, needle, cs); } -bool QtPrivate::startsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +bool QtPrivate::startsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs) noexcept { return qt_starts_with_impl(haystack, needle, cs); } -bool QtPrivate::startsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +bool QtPrivate::startsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs) noexcept { return qt_starts_with_impl(haystack, needle, cs); } -bool QtPrivate::startsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +bool QtPrivate::startsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs) noexcept { return qt_starts_with_impl(haystack, needle, cs); } template <typename Haystack, typename Needle> -bool qt_ends_with_impl(Haystack haystack, Needle needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +bool qt_ends_with_impl(Haystack haystack, Needle needle, Qt::CaseSensitivity cs) noexcept { if (haystack.isNull()) return needle.isNull(); // historical behavior, consider changing in ### Qt 6. @@ -11798,27 +11682,148 @@ static inline bool qt_ends_with(QStringView haystack, QChar needle, Qt::CaseSens \sa QtPrivate::startsWith(), QString::endsWith(), QStringView::endsWith(), QLatin1String::endsWith() */ -bool QtPrivate::endsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +bool QtPrivate::endsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) noexcept { return qt_ends_with_impl(haystack, needle, cs); } -bool QtPrivate::endsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +bool QtPrivate::endsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs) noexcept { return qt_ends_with_impl(haystack, needle, cs); } -bool QtPrivate::endsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +bool QtPrivate::endsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs) noexcept { return qt_ends_with_impl(haystack, needle, cs); } -bool QtPrivate::endsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +bool QtPrivate::endsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs) noexcept { return qt_ends_with_impl(haystack, needle, cs); } /*! + \internal + + Returns the index position of the first occurrence of the + character \a ch in the string given by \a str and \a len, + searching forward from index + position \a from. Returns -1 if \a ch could not be found. +*/ + +qsizetype QtPrivate::findChar(QStringView str, QChar ch, qsizetype from, Qt::CaseSensitivity cs) noexcept +{ + if (from < 0) + from = qMax(from + str.size(), qsizetype(0)); + if (from < str.size()) { + const ushort *s = (const ushort *)str.data(); + ushort c = ch.unicode(); + const ushort *n = s + from; + const ushort *e = s + str.size(); + if (cs == Qt::CaseSensitive) { + n = QtPrivate::qustrchr(QStringView(n, e), c); + if (n != e) + return n - s; + } else { + c = foldCase(c); + --n; + while (++n != e) + if (foldCase(*n) == c) + return n - s; + } + } + return -1; +} + +qsizetype QtPrivate::findString(QStringView haystack0, qsizetype from, QStringView needle0, Qt::CaseSensitivity cs) noexcept +{ + const qsizetype l = haystack0.size(); + const qsizetype sl = needle0.size(); + if (from < 0) + from += l; + if (std::size_t(sl + from) > std::size_t(l)) + return -1; + if (!sl) + return from; + if (!l) + return -1; + + if (sl == 1) + return QtPrivate::findChar(haystack0, needle0[0], from, cs); + + /* + We use the Boyer-Moore algorithm in cases where the overhead + for the skip table should pay off, otherwise we use a simple + hash function. + */ + if (l > 500 && sl > 5) + return qFindStringBoyerMoore(haystack0, from, needle0, cs); + + auto sv = [sl](const ushort *v) { return QStringView(v, sl); }; + /* + We use some hashing for efficiency's sake. Instead of + comparing strings, we compare the hash value of str with that + of a part of this QString. Only if that matches, we call + qt_string_compare(). + */ + const ushort *needle = (const ushort *)needle0.data(); + const ushort *haystack = (const ushort *)(haystack0.data()) + from; + const ushort *end = (const ushort *)(haystack0.data()) + (l - sl); + const std::size_t sl_minus_1 = sl - 1; + std::size_t hashNeedle = 0, hashHaystack = 0; + qsizetype idx; + + if (cs == Qt::CaseSensitive) { + for (idx = 0; idx < sl; ++idx) { + hashNeedle = ((hashNeedle<<1) + needle[idx]); + hashHaystack = ((hashHaystack<<1) + haystack[idx]); + } + hashHaystack -= haystack[sl_minus_1]; + + while (haystack <= end) { + hashHaystack += haystack[sl_minus_1]; + if (hashHaystack == hashNeedle + && qt_compare_strings(needle0, sv(haystack), Qt::CaseSensitive) == 0) + return haystack - (const ushort *)haystack0.data(); + + REHASH(*haystack); + ++haystack; + } + } else { + const ushort *haystack_start = (const ushort *)haystack0.data(); + for (idx = 0; idx < sl; ++idx) { + hashNeedle = (hashNeedle<<1) + foldCase(needle + idx, needle); + hashHaystack = (hashHaystack<<1) + foldCase(haystack + idx, haystack_start); + } + hashHaystack -= foldCase(haystack + sl_minus_1, haystack_start); + + while (haystack <= end) { + hashHaystack += foldCase(haystack + sl_minus_1, haystack_start); + if (hashHaystack == hashNeedle + && qt_compare_strings(needle0, sv(haystack), Qt::CaseInsensitive) == 0) + return haystack - (const ushort *)haystack0.data(); + + REHASH(foldCase(haystack, haystack_start)); + ++haystack; + } + } + return -1; +} + +qsizetype QtPrivate::findString(QStringView haystack, qsizetype from, QLatin1String needle, Qt::CaseSensitivity cs) noexcept +{ + if (haystack.size() < needle.size()) + return -1; + + const char *latin1 = needle.latin1(); + const qsizetype len = needle.size(); + QVarLengthArray<ushort> s(len); + qt_from_latin1(s.data(), latin1, len); + + return QtPrivate::findString(haystack, from, QStringView(reinterpret_cast<const QChar*>(s.constData()), len), cs); +} + +/*! \since 4.8 Returns a Latin-1 representation of the string as a QByteArray. @@ -12270,7 +12275,7 @@ QString QString::toHtmlEscaped() const /*! \internal */ -void QAbstractConcatenable::appendLatin1To(const char *a, int len, QChar *out) Q_DECL_NOTHROW +void QAbstractConcatenable::appendLatin1To(const char *a, int len, QChar *out) noexcept { qt_from_latin1(reinterpret_cast<ushort *>(out), a, uint(len)); } diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index da76601e88..a526a6537a 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -91,19 +91,19 @@ template <typename T> class QVector; class QLatin1String { public: - Q_DECL_CONSTEXPR inline QLatin1String() Q_DECL_NOTHROW : m_size(0), m_data(nullptr) {} - Q_DECL_CONSTEXPR inline explicit QLatin1String(const char *s) Q_DECL_NOTHROW : m_size(s ? int(strlen(s)) : 0), m_data(s) {} + Q_DECL_CONSTEXPR inline QLatin1String() noexcept : m_size(0), m_data(nullptr) {} + Q_DECL_CONSTEXPR inline explicit QLatin1String(const char *s) noexcept : m_size(s ? int(strlen(s)) : 0), m_data(s) {} Q_DECL_CONSTEXPR explicit QLatin1String(const char *f, const char *l) : QLatin1String(f, int(l - f)) {} - Q_DECL_CONSTEXPR inline explicit QLatin1String(const char *s, int sz) Q_DECL_NOTHROW : m_size(sz), m_data(s) {} - inline explicit QLatin1String(const QByteArray &s) Q_DECL_NOTHROW : m_size(int(qstrnlen(s.constData(), s.size()))), m_data(s.constData()) {} + Q_DECL_CONSTEXPR inline explicit QLatin1String(const char *s, int sz) noexcept : m_size(sz), m_data(s) {} + inline explicit QLatin1String(const QByteArray &s) noexcept : m_size(int(qstrnlen(s.constData(), s.size()))), m_data(s.constData()) {} - Q_DECL_CONSTEXPR const char *latin1() const Q_DECL_NOTHROW { return m_data; } - Q_DECL_CONSTEXPR int size() const Q_DECL_NOTHROW { return m_size; } - Q_DECL_CONSTEXPR const char *data() const Q_DECL_NOTHROW { return m_data; } + Q_DECL_CONSTEXPR const char *latin1() const noexcept { return m_data; } + Q_DECL_CONSTEXPR int size() const noexcept { return m_size; } + Q_DECL_CONSTEXPR const char *data() const noexcept { return m_data; } - Q_DECL_CONSTEXPR bool isNull() const Q_DECL_NOTHROW { return !data(); } - Q_DECL_CONSTEXPR bool isEmpty() const Q_DECL_NOTHROW { return !size(); } + Q_DECL_CONSTEXPR bool isNull() const noexcept { return !data(); } + Q_DECL_CONSTEXPR bool isEmpty() const noexcept { return !size(); } Q_DECL_CONSTEXPR QLatin1Char at(int i) const { return Q_ASSERT(i >= 0), Q_ASSERT(i < size()), QLatin1Char(m_data[i]); } @@ -112,22 +112,22 @@ public: Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QLatin1Char front() const { return at(0); } Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QLatin1Char back() const { return at(size() - 1); } - Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::startsWith(*this, s, cs); } - Q_REQUIRED_RESULT bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::startsWith(*this, s, cs); } - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR bool startsWith(QChar c) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR bool startsWith(QChar c) const noexcept { return !isEmpty() && front() == c; } - Q_REQUIRED_RESULT inline bool startsWith(QChar c, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT inline bool startsWith(QChar c, Qt::CaseSensitivity cs) const noexcept { return QtPrivate::startsWith(*this, QStringView(&c, 1), cs); } - Q_REQUIRED_RESULT bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::endsWith(*this, s, cs); } - Q_REQUIRED_RESULT bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::endsWith(*this, s, cs); } - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR bool endsWith(QChar c) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR bool endsWith(QChar c) const noexcept { return !isEmpty() && back() == c; } - Q_REQUIRED_RESULT inline bool endsWith(QChar c, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT inline bool endsWith(QChar c, Qt::CaseSensitivity cs) const noexcept { return QtPrivate::endsWith(*this, QStringView(&c, 1), cs); } using value_type = const char; @@ -138,18 +138,18 @@ public: using difference_type = int; // violates Container concept requirements using size_type = int; // violates Container concept requirements - Q_DECL_CONSTEXPR const_iterator begin() const Q_DECL_NOTHROW { return data(); } - Q_DECL_CONSTEXPR const_iterator cbegin() const Q_DECL_NOTHROW { return data(); } - Q_DECL_CONSTEXPR const_iterator end() const Q_DECL_NOTHROW { return data() + size(); } - Q_DECL_CONSTEXPR const_iterator cend() const Q_DECL_NOTHROW { return data() + size(); } + Q_DECL_CONSTEXPR const_iterator begin() const noexcept { return data(); } + Q_DECL_CONSTEXPR const_iterator cbegin() const noexcept { return data(); } + Q_DECL_CONSTEXPR const_iterator end() const noexcept { return data() + size(); } + Q_DECL_CONSTEXPR const_iterator cend() const noexcept { return data() + size(); } using reverse_iterator = std::reverse_iterator<iterator>; using const_reverse_iterator = reverse_iterator; - const_reverse_iterator rbegin() const Q_DECL_NOTHROW { return const_reverse_iterator(end()); } - const_reverse_iterator crbegin() const Q_DECL_NOTHROW { return const_reverse_iterator(end()); } - const_reverse_iterator rend() const Q_DECL_NOTHROW { return const_reverse_iterator(begin()); } - const_reverse_iterator crend() const Q_DECL_NOTHROW { return const_reverse_iterator(begin()); } + const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } + const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } + const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } Q_DECL_CONSTEXPR QLatin1String mid(int pos) const { return Q_ASSERT(pos >= 0), Q_ASSERT(pos <= size()), QLatin1String(m_data + pos, m_size - pos); } @@ -167,14 +167,14 @@ public: Q_DECL_RELAXED_CONSTEXPR void truncate(int n) { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); m_size = n; } - Q_REQUIRED_RESULT QLatin1String trimmed() const Q_DECL_NOTHROW { return QtPrivate::trimmed(*this); } + Q_REQUIRED_RESULT QLatin1String trimmed() const noexcept { return QtPrivate::trimmed(*this); } - inline bool operator==(const QString &s) const Q_DECL_NOTHROW; - inline bool operator!=(const QString &s) const Q_DECL_NOTHROW; - inline bool operator>(const QString &s) const Q_DECL_NOTHROW; - inline bool operator<(const QString &s) const Q_DECL_NOTHROW; - inline bool operator>=(const QString &s) const Q_DECL_NOTHROW; - inline bool operator<=(const QString &s) const Q_DECL_NOTHROW; + inline bool operator==(const QString &s) const noexcept; + inline bool operator!=(const QString &s) const noexcept; + inline bool operator>(const QString &s) const noexcept; + inline bool operator<(const QString &s) const noexcept; + inline bool operator>=(const QString &s) const noexcept; + inline bool operator<=(const QString &s) const noexcept; #if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) inline QT_ASCII_CAST_WARN bool operator==(const char *s) const; @@ -204,15 +204,15 @@ typedef QLatin1String QLatin1Literal; // // QLatin1String inline implementations // -inline bool QtPrivate::isLatin1(QLatin1String) Q_DECL_NOTHROW +inline bool QtPrivate::isLatin1(QLatin1String) noexcept { return true; } // // QStringView members that require QLatin1String: // -bool QStringView::startsWith(QLatin1String s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW +bool QStringView::startsWith(QLatin1String s, Qt::CaseSensitivity cs) const noexcept { return QtPrivate::startsWith(*this, s, cs); } -bool QStringView::endsWith(QLatin1String s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW +bool QStringView::endsWith(QLatin1String s, Qt::CaseSensitivity cs) const noexcept { return QtPrivate::endsWith(*this, s, cs); } class Q_CORE_EXPORT QString @@ -220,22 +220,22 @@ class Q_CORE_EXPORT QString public: typedef QStringData Data; - inline QString() Q_DECL_NOTHROW; + inline QString() noexcept; explicit QString(const QChar *unicode, int size = -1); QString(QChar c); QString(int size, QChar c); inline QString(QLatin1String latin1); - inline QString(const QString &) Q_DECL_NOTHROW; + inline QString(const QString &) noexcept; inline ~QString(); QString &operator=(QChar c); - QString &operator=(const QString &) Q_DECL_NOTHROW; + QString &operator=(const QString &) noexcept; QString &operator=(QLatin1String latin1); #ifdef Q_COMPILER_RVALUE_REFS - inline QString(QString && other) Q_DECL_NOTHROW : d(other.d) { other.d = Data::sharedNull(); } - inline QString &operator=(QString &&other) Q_DECL_NOTHROW + inline QString(QString && other) noexcept : d(other.d) { other.d = Data::sharedNull(); } + inline QString &operator=(QString &&other) noexcept { qSwap(d, other.d); return *this; } #endif - inline void swap(QString &other) Q_DECL_NOTHROW { qSwap(d, other.d); } + inline void swap(QString &other) noexcept { qSwap(d, other.d); } inline int size() const { return d->size; } inline int count() const { return d->size; } inline int length() const; @@ -320,8 +320,12 @@ public: const QString &a4, const QString &a5, const QString &a6, const QString &a7, const QString &a8, const QString &a9) const; +#if QT_DEPRECATED_SINCE(5, 14) + QT_DEPRECATED_X("Use vasprintf(), arg() or QTextStream instead") QString &vsprintf(const char *format, va_list ap) Q_ATTRIBUTE_FORMAT_PRINTF(2, 0); + QT_DEPRECATED_X("Use asprintf(), arg() or QTextStream instead") QString &sprintf(const char *format, ...) Q_ATTRIBUTE_FORMAT_PRINTF(2, 3); +#endif static QString vasprintf(const char *format, va_list ap) Q_ATTRIBUTE_FORMAT_PRINTF(1, 0); static QString asprintf(const char *format, ...) Q_ATTRIBUTE_FORMAT_PRINTF(1, 2); @@ -395,7 +399,7 @@ public: bool startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool startsWith(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #endif - Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::startsWith(*this, s, cs); } bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool startsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; @@ -404,7 +408,7 @@ public: bool endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool endsWith(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #endif - Q_REQUIRED_RESULT bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::endsWith(*this, s, cs); } bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool endsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; @@ -609,25 +613,25 @@ public: inline QString &setUtf16(const ushort *utf16, int size); #if QT_STRINGVIEW_LEVEL < 2 - int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; - inline int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; + int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + inline int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; #endif - int compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; - inline int compare(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; + int compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + inline int compare(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; static inline int compare(const QString &s1, const QString &s2, - Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW + Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept { return s1.compare(s2, cs); } static inline int compare(const QString &s1, QLatin1String s2, - Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW + Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept { return s1.compare(s2, cs); } static inline int compare(QLatin1String s1, const QString &s2, - Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW + Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept { return -s2.compare(s1, cs); } static int compare(const QString &s1, const QStringRef &s2, - Qt::CaseSensitivity = Qt::CaseSensitive) Q_DECL_NOTHROW; + Qt::CaseSensitivity = Qt::CaseSensitive) noexcept; int localeAwareCompare(const QString& s) const; static int localeAwareCompare(const QString& s1, const QString& s2) @@ -667,19 +671,19 @@ public: static QString number(qulonglong, int base=10); static QString number(double, char f='g', int prec=6); - friend Q_CORE_EXPORT bool operator==(const QString &s1, const QString &s2) Q_DECL_NOTHROW; - friend Q_CORE_EXPORT bool operator<(const QString &s1, const QString &s2) Q_DECL_NOTHROW; - friend inline bool operator>(const QString &s1, const QString &s2) Q_DECL_NOTHROW { return s2 < s1; } - friend inline bool operator!=(const QString &s1, const QString &s2) Q_DECL_NOTHROW { return !(s1 == s2); } - friend inline bool operator<=(const QString &s1, const QString &s2) Q_DECL_NOTHROW { return !(s1 > s2); } - friend inline bool operator>=(const QString &s1, const QString &s2) Q_DECL_NOTHROW { return !(s1 < s2); } + friend Q_CORE_EXPORT bool operator==(const QString &s1, const QString &s2) noexcept; + friend Q_CORE_EXPORT bool operator<(const QString &s1, const QString &s2) noexcept; + friend inline bool operator>(const QString &s1, const QString &s2) noexcept { return s2 < s1; } + friend inline bool operator!=(const QString &s1, const QString &s2) noexcept { return !(s1 == s2); } + friend inline bool operator<=(const QString &s1, const QString &s2) noexcept { return !(s1 > s2); } + friend inline bool operator>=(const QString &s1, const QString &s2) noexcept { return !(s1 < s2); } - bool operator==(QLatin1String s) const Q_DECL_NOTHROW; - bool operator<(QLatin1String s) const Q_DECL_NOTHROW; - bool operator>(QLatin1String s) const Q_DECL_NOTHROW; - inline bool operator!=(QLatin1String s) const Q_DECL_NOTHROW { return !operator==(s); } - inline bool operator<=(QLatin1String s) const Q_DECL_NOTHROW { return !operator>(s); } - inline bool operator>=(QLatin1String s) const Q_DECL_NOTHROW { return !operator<(s); } + bool operator==(QLatin1String s) const noexcept; + bool operator<(QLatin1String s) const noexcept; + bool operator>(QLatin1String s) const noexcept; + inline bool operator!=(QLatin1String s) const noexcept { return !operator==(s); } + inline bool operator<=(QLatin1String s) const noexcept { return !operator>(s); } + inline bool operator>=(QLatin1String s) const noexcept { return !operator<(s); } // ASCII compatibility #if defined(QT_RESTRICTED_CAST_FROM_ASCII) @@ -840,15 +844,15 @@ private: Data *d; - friend inline bool operator==(QChar, const QString &) Q_DECL_NOTHROW; - friend inline bool operator< (QChar, const QString &) Q_DECL_NOTHROW; - friend inline bool operator> (QChar, const QString &) Q_DECL_NOTHROW; - friend inline bool operator==(QChar, const QStringRef &) Q_DECL_NOTHROW; - friend inline bool operator< (QChar, const QStringRef &) Q_DECL_NOTHROW; - friend inline bool operator> (QChar, const QStringRef &) Q_DECL_NOTHROW; - friend inline bool operator==(QChar, QLatin1String) Q_DECL_NOTHROW; - friend inline bool operator< (QChar, QLatin1String) Q_DECL_NOTHROW; - friend inline bool operator> (QChar, QLatin1String) Q_DECL_NOTHROW; + friend inline bool operator==(QChar, const QString &) noexcept; + friend inline bool operator< (QChar, const QString &) noexcept; + friend inline bool operator> (QChar, const QString &) noexcept; + friend inline bool operator==(QChar, const QStringRef &) noexcept; + friend inline bool operator< (QChar, const QStringRef &) noexcept; + friend inline bool operator> (QChar, const QStringRef &) noexcept; + friend inline bool operator==(QChar, QLatin1String) noexcept; + friend inline bool operator< (QChar, QLatin1String) noexcept; + friend inline bool operator> (QChar, QLatin1String) noexcept; void reallocData(uint alloc, bool grow = false); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) @@ -857,13 +861,13 @@ private: QString multiArg(int numArgs, const QString **args) const; static int compare_helper(const QChar *data1, int length1, const QChar *data2, int length2, - Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; + Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; static int compare_helper(const QChar *data1, int length1, const char *data2, int length2, Qt::CaseSensitivity cs = Qt::CaseSensitive); static int compare_helper(const QChar *data1, int length1, QLatin1String s2, - Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; + Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; static int localeAwareCompare_helper(const QChar *data1, int length1, const QChar *data2, int length2); static QString toLower_helper(const QString &str); @@ -952,7 +956,7 @@ inline bool QString::isDetached() const { return !d->ref.isShared(); } inline void QString::clear() { if (!isNull()) *this = QString(); } -inline QString::QString(const QString &other) Q_DECL_NOTHROW : d(other.d) +inline QString::QString(const QString &other) noexcept : d(other.d) { Q_ASSERT(&other != this); d->ref.ref(); } inline int QString::capacity() const { return d->alloc ? d->alloc - 1 : 0; } @@ -1017,12 +1021,7 @@ QT_WARNING_DISABLE_INTEL(111) // "statement is unreachable" inline int QString::toWCharArray(wchar_t *array) const { - if (sizeof(wchar_t) == sizeof(QChar)) { - memcpy(array, d->data(), sizeof(QChar) * size()); - return size(); - } else { - return toUcs4_helper(d->data(), size(), reinterpret_cast<uint *>(array)); - } + return QStringView(*this).toWCharArray(array); } QT_WARNING_POP @@ -1129,7 +1128,7 @@ inline void QCharRef::setRow(uchar arow) { QChar(*this).setRow(arow); } inline void QCharRef::setCell(uchar acell) { QChar(*this).setCell(acell); } -inline QString::QString() Q_DECL_NOTHROW : d(Data::sharedNull()) {} +inline QString::QString() noexcept : d(Data::sharedNull()) {} inline QString::~QString() { if (!d->ref.deref()) Data::deallocate(d); } inline void QString::reserve(int asize) @@ -1201,34 +1200,34 @@ QT_DEPRECATED_X("use !QString::isNull()") inline bool operator!=(const QString &s, QString::Null) { return !s.isNull(); } #endif -inline bool operator==(QLatin1String s1, QLatin1String s2) Q_DECL_NOTHROW +inline bool operator==(QLatin1String s1, QLatin1String s2) noexcept { return s1.size() == s2.size() && (!s1.size() || !memcmp(s1.latin1(), s2.latin1(), s1.size())); } -inline bool operator!=(QLatin1String s1, QLatin1String s2) Q_DECL_NOTHROW +inline bool operator!=(QLatin1String s1, QLatin1String s2) noexcept { return !operator==(s1, s2); } -inline bool operator<(QLatin1String s1, QLatin1String s2) Q_DECL_NOTHROW +inline bool operator<(QLatin1String s1, QLatin1String s2) noexcept { const int len = qMin(s1.size(), s2.size()); const int r = len ? memcmp(s1.latin1(), s2.latin1(), len) : 0; return r < 0 || (r == 0 && s1.size() < s2.size()); } -inline bool operator>(QLatin1String s1, QLatin1String s2) Q_DECL_NOTHROW +inline bool operator>(QLatin1String s1, QLatin1String s2) noexcept { return operator<(s2, s1); } -inline bool operator<=(QLatin1String s1, QLatin1String s2) Q_DECL_NOTHROW +inline bool operator<=(QLatin1String s1, QLatin1String s2) noexcept { return !operator>(s1, s2); } -inline bool operator>=(QLatin1String s1, QLatin1String s2) Q_DECL_NOTHROW +inline bool operator>=(QLatin1String s1, QLatin1String s2) noexcept { return !operator<(s1, s2); } -inline bool QLatin1String::operator==(const QString &s) const Q_DECL_NOTHROW +inline bool QLatin1String::operator==(const QString &s) const noexcept { return s == *this; } -inline bool QLatin1String::operator!=(const QString &s) const Q_DECL_NOTHROW +inline bool QLatin1String::operator!=(const QString &s) const noexcept { return s != *this; } -inline bool QLatin1String::operator>(const QString &s) const Q_DECL_NOTHROW +inline bool QLatin1String::operator>(const QString &s) const noexcept { return s < *this; } -inline bool QLatin1String::operator<(const QString &s) const Q_DECL_NOTHROW +inline bool QLatin1String::operator<(const QString &s) const noexcept { return s > *this; } -inline bool QLatin1String::operator>=(const QString &s) const Q_DECL_NOTHROW +inline bool QLatin1String::operator>=(const QString &s) const noexcept { return s <= *this; } -inline bool QLatin1String::operator<=(const QString &s) const Q_DECL_NOTHROW +inline bool QLatin1String::operator<=(const QString &s) const noexcept { return s >= *this; } #if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) @@ -1376,14 +1375,12 @@ inline std::wstring QString::toStdWString() const { std::wstring str; str.resize(length()); - -#ifdef Q_CC_MSVC - // VS2005 crashes if the string is empty - if (!length()) - return str; +#if __cplusplus >= 201703L + str.resize(toWCharArray(str.data())); +#else + if (length()) + str.resize(toWCharArray(&str.front())); #endif - - str.resize(toWCharArray(&(*str.begin()))); return str; } @@ -1437,14 +1434,14 @@ public: #if QT_VERSION < QT_VERSION_CHECK(6,0,0) // ### Qt 6: remove all of these, the implicit ones are fine - QStringRef(const QStringRef &other) Q_DECL_NOTHROW + QStringRef(const QStringRef &other) noexcept :m_string(other.m_string), m_position(other.m_position), m_size(other.m_size) {} #ifdef Q_COMPILER_RVALUE_REFS - QStringRef(QStringRef &&other) Q_DECL_NOTHROW : m_string(other.m_string), m_position(other.m_position), m_size(other.m_size) {} - QStringRef &operator=(QStringRef &&other) Q_DECL_NOTHROW { return *this = other; } + QStringRef(QStringRef &&other) noexcept : m_string(other.m_string), m_position(other.m_position), m_size(other.m_size) {} + QStringRef &operator=(QStringRef &&other) noexcept { return *this = other; } #endif - QStringRef &operator=(const QStringRef &other) Q_DECL_NOTHROW + QStringRef &operator=(const QStringRef &other) noexcept { m_string = other.m_string; m_position = other.m_position; m_size = other.m_size; return *this; @@ -1487,8 +1484,8 @@ public: Q_REQUIRED_RESULT QStringRef chopped(int n) const { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return left(size() - n); } - void truncate(int pos) Q_DECL_NOTHROW { m_size = qBound(0, pos, m_size); } - void chop(int n) Q_DECL_NOTHROW + void truncate(int pos) noexcept { m_size = qBound(0, pos, m_size); } + void chop(int n) noexcept { if (n >= m_size) m_size = 0; @@ -1498,7 +1495,7 @@ public: bool isRightToLeft() const; - Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::startsWith(*this, s, cs); } bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool startsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; @@ -1507,7 +1504,7 @@ public: bool startsWith(const QStringRef &c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #endif - Q_REQUIRED_RESULT bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::endsWith(*this, s, cs); } bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool endsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; @@ -1570,19 +1567,19 @@ public: inline QT_ASCII_CAST_WARN bool operator>=(const char *s) const; #endif - int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; - int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; - int compare(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; + int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + int compare(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; #if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) int compare(const QByteArray &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return QString::compare_helper(unicode(), size(), s.data(), qstrnlen(s.data(), s.size()), cs); } #endif static int compare(const QStringRef &s1, const QString &s2, - Qt::CaseSensitivity = Qt::CaseSensitive) Q_DECL_NOTHROW; + Qt::CaseSensitivity = Qt::CaseSensitive) noexcept; static int compare(const QStringRef &s1, const QStringRef &s2, - Qt::CaseSensitivity = Qt::CaseSensitive) Q_DECL_NOTHROW; + Qt::CaseSensitivity = Qt::CaseSensitive) noexcept; static int compare(const QStringRef &s1, QLatin1String s2, - Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; + Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; int localeAwareCompare(const QString &s) const; int localeAwareCompare(const QStringRef &s) const; @@ -1613,162 +1610,162 @@ inline QStringRef::QStringRef(const QString *aString) :m_string(aString), m_position(0), m_size(aString?aString->size() : 0){} // QStringRef <> QStringRef -Q_CORE_EXPORT bool operator==(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW; -inline bool operator!=(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW +Q_CORE_EXPORT bool operator==(const QStringRef &s1, const QStringRef &s2) noexcept; +inline bool operator!=(const QStringRef &s1, const QStringRef &s2) noexcept { return !(s1 == s2); } -Q_CORE_EXPORT bool operator<(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW; -inline bool operator>(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW +Q_CORE_EXPORT bool operator<(const QStringRef &s1, const QStringRef &s2) noexcept; +inline bool operator>(const QStringRef &s1, const QStringRef &s2) noexcept { return s2 < s1; } -inline bool operator<=(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW +inline bool operator<=(const QStringRef &s1, const QStringRef &s2) noexcept { return !(s1 > s2); } -inline bool operator>=(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW +inline bool operator>=(const QStringRef &s1, const QStringRef &s2) noexcept { return !(s1 < s2); } // QString <> QStringRef -Q_CORE_EXPORT bool operator==(const QString &lhs, const QStringRef &rhs) Q_DECL_NOTHROW; -inline bool operator!=(const QString &lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return lhs.compare(rhs) != 0; } -inline bool operator< (const QString &lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return lhs.compare(rhs) < 0; } -inline bool operator> (const QString &lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return lhs.compare(rhs) > 0; } -inline bool operator<=(const QString &lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return lhs.compare(rhs) <= 0; } -inline bool operator>=(const QString &lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return lhs.compare(rhs) >= 0; } - -inline bool operator==(const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs == lhs; } -inline bool operator!=(const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs != lhs; } -inline bool operator< (const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs > lhs; } -inline bool operator> (const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs < lhs; } -inline bool operator<=(const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs >= lhs; } -inline bool operator>=(const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs <= lhs; } +Q_CORE_EXPORT bool operator==(const QString &lhs, const QStringRef &rhs) noexcept; +inline bool operator!=(const QString &lhs, const QStringRef &rhs) noexcept { return lhs.compare(rhs) != 0; } +inline bool operator< (const QString &lhs, const QStringRef &rhs) noexcept { return lhs.compare(rhs) < 0; } +inline bool operator> (const QString &lhs, const QStringRef &rhs) noexcept { return lhs.compare(rhs) > 0; } +inline bool operator<=(const QString &lhs, const QStringRef &rhs) noexcept { return lhs.compare(rhs) <= 0; } +inline bool operator>=(const QString &lhs, const QStringRef &rhs) noexcept { return lhs.compare(rhs) >= 0; } + +inline bool operator==(const QStringRef &lhs, const QString &rhs) noexcept { return rhs == lhs; } +inline bool operator!=(const QStringRef &lhs, const QString &rhs) noexcept { return rhs != lhs; } +inline bool operator< (const QStringRef &lhs, const QString &rhs) noexcept { return rhs > lhs; } +inline bool operator> (const QStringRef &lhs, const QString &rhs) noexcept { return rhs < lhs; } +inline bool operator<=(const QStringRef &lhs, const QString &rhs) noexcept { return rhs >= lhs; } +inline bool operator>=(const QStringRef &lhs, const QString &rhs) noexcept { return rhs <= lhs; } #if QT_STRINGVIEW_LEVEL < 2 -inline int QString::compare(const QStringRef &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW +inline int QString::compare(const QStringRef &s, Qt::CaseSensitivity cs) const noexcept { return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); } #endif -inline int QString::compare(QStringView s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW +inline int QString::compare(QStringView s, Qt::CaseSensitivity cs) const noexcept { return -s.compare(*this, cs); } -inline int QString::compare(const QString &s1, const QStringRef &s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +inline int QString::compare(const QString &s1, const QStringRef &s2, Qt::CaseSensitivity cs) noexcept { return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); } -inline int QStringRef::compare(const QString &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW +inline int QStringRef::compare(const QString &s, Qt::CaseSensitivity cs) const noexcept { return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); } -inline int QStringRef::compare(const QStringRef &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW +inline int QStringRef::compare(const QStringRef &s, Qt::CaseSensitivity cs) const noexcept { return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); } -inline int QStringRef::compare(QLatin1String s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW +inline int QStringRef::compare(QLatin1String s, Qt::CaseSensitivity cs) const noexcept { return QString::compare_helper(constData(), length(), s, cs); } -inline int QStringRef::compare(const QStringRef &s1, const QString &s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +inline int QStringRef::compare(const QStringRef &s1, const QString &s2, Qt::CaseSensitivity cs) noexcept { return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); } -inline int QStringRef::compare(const QStringRef &s1, const QStringRef &s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +inline int QStringRef::compare(const QStringRef &s1, const QStringRef &s2, Qt::CaseSensitivity cs) noexcept { return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); } -inline int QStringRef::compare(const QStringRef &s1, QLatin1String s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +inline int QStringRef::compare(const QStringRef &s1, QLatin1String s2, Qt::CaseSensitivity cs) noexcept { return QString::compare_helper(s1.constData(), s1.length(), s2, cs); } // QLatin1String <> QStringRef -Q_CORE_EXPORT bool operator==(QLatin1String lhs, const QStringRef &rhs) Q_DECL_NOTHROW; -inline bool operator!=(QLatin1String lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return rhs.compare(lhs) != 0; } -inline bool operator< (QLatin1String lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return rhs.compare(lhs) > 0; } -inline bool operator> (QLatin1String lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return rhs.compare(lhs) < 0; } -inline bool operator<=(QLatin1String lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return rhs.compare(lhs) >= 0; } -inline bool operator>=(QLatin1String lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return rhs.compare(lhs) <= 0; } - -inline bool operator==(const QStringRef &lhs, QLatin1String rhs) Q_DECL_NOTHROW { return rhs == lhs; } -inline bool operator!=(const QStringRef &lhs, QLatin1String rhs) Q_DECL_NOTHROW { return rhs != lhs; } -inline bool operator< (const QStringRef &lhs, QLatin1String rhs) Q_DECL_NOTHROW { return rhs > lhs; } -inline bool operator> (const QStringRef &lhs, QLatin1String rhs) Q_DECL_NOTHROW { return rhs < lhs; } -inline bool operator<=(const QStringRef &lhs, QLatin1String rhs) Q_DECL_NOTHROW { return rhs >= lhs; } -inline bool operator>=(const QStringRef &lhs, QLatin1String rhs) Q_DECL_NOTHROW { return rhs <= lhs; } +Q_CORE_EXPORT bool operator==(QLatin1String lhs, const QStringRef &rhs) noexcept; +inline bool operator!=(QLatin1String lhs, const QStringRef &rhs) noexcept { return rhs.compare(lhs) != 0; } +inline bool operator< (QLatin1String lhs, const QStringRef &rhs) noexcept { return rhs.compare(lhs) > 0; } +inline bool operator> (QLatin1String lhs, const QStringRef &rhs) noexcept { return rhs.compare(lhs) < 0; } +inline bool operator<=(QLatin1String lhs, const QStringRef &rhs) noexcept { return rhs.compare(lhs) >= 0; } +inline bool operator>=(QLatin1String lhs, const QStringRef &rhs) noexcept { return rhs.compare(lhs) <= 0; } + +inline bool operator==(const QStringRef &lhs, QLatin1String rhs) noexcept { return rhs == lhs; } +inline bool operator!=(const QStringRef &lhs, QLatin1String rhs) noexcept { return rhs != lhs; } +inline bool operator< (const QStringRef &lhs, QLatin1String rhs) noexcept { return rhs > lhs; } +inline bool operator> (const QStringRef &lhs, QLatin1String rhs) noexcept { return rhs < lhs; } +inline bool operator<=(const QStringRef &lhs, QLatin1String rhs) noexcept { return rhs >= lhs; } +inline bool operator>=(const QStringRef &lhs, QLatin1String rhs) noexcept { return rhs <= lhs; } // QChar <> QString -inline bool operator==(QChar lhs, const QString &rhs) Q_DECL_NOTHROW +inline bool operator==(QChar lhs, const QString &rhs) noexcept { return rhs.size() == 1 && lhs == rhs.front(); } -inline bool operator< (QChar lhs, const QString &rhs) Q_DECL_NOTHROW +inline bool operator< (QChar lhs, const QString &rhs) noexcept { return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) < 0; } -inline bool operator> (QChar lhs, const QString &rhs) Q_DECL_NOTHROW +inline bool operator> (QChar lhs, const QString &rhs) noexcept { return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) > 0; } -inline bool operator!=(QChar lhs, const QString &rhs) Q_DECL_NOTHROW { return !(lhs == rhs); } -inline bool operator<=(QChar lhs, const QString &rhs) Q_DECL_NOTHROW { return !(lhs > rhs); } -inline bool operator>=(QChar lhs, const QString &rhs) Q_DECL_NOTHROW { return !(lhs < rhs); } +inline bool operator!=(QChar lhs, const QString &rhs) noexcept { return !(lhs == rhs); } +inline bool operator<=(QChar lhs, const QString &rhs) noexcept { return !(lhs > rhs); } +inline bool operator>=(QChar lhs, const QString &rhs) noexcept { return !(lhs < rhs); } -inline bool operator==(const QString &lhs, QChar rhs) Q_DECL_NOTHROW { return rhs == lhs; } -inline bool operator!=(const QString &lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs == lhs); } -inline bool operator< (const QString &lhs, QChar rhs) Q_DECL_NOTHROW { return rhs > lhs; } -inline bool operator> (const QString &lhs, QChar rhs) Q_DECL_NOTHROW { return rhs < lhs; } -inline bool operator<=(const QString &lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs < lhs); } -inline bool operator>=(const QString &lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs > lhs); } +inline bool operator==(const QString &lhs, QChar rhs) noexcept { return rhs == lhs; } +inline bool operator!=(const QString &lhs, QChar rhs) noexcept { return !(rhs == lhs); } +inline bool operator< (const QString &lhs, QChar rhs) noexcept { return rhs > lhs; } +inline bool operator> (const QString &lhs, QChar rhs) noexcept { return rhs < lhs; } +inline bool operator<=(const QString &lhs, QChar rhs) noexcept { return !(rhs < lhs); } +inline bool operator>=(const QString &lhs, QChar rhs) noexcept { return !(rhs > lhs); } // QChar <> QStringRef -inline bool operator==(QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW +inline bool operator==(QChar lhs, const QStringRef &rhs) noexcept { return rhs.size() == 1 && lhs == rhs.front(); } -inline bool operator< (QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW +inline bool operator< (QChar lhs, const QStringRef &rhs) noexcept { return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) < 0; } -inline bool operator> (QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW +inline bool operator> (QChar lhs, const QStringRef &rhs) noexcept { return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) > 0; } -inline bool operator!=(QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return !(lhs == rhs); } -inline bool operator<=(QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return !(lhs > rhs); } -inline bool operator>=(QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return !(lhs < rhs); } +inline bool operator!=(QChar lhs, const QStringRef &rhs) noexcept { return !(lhs == rhs); } +inline bool operator<=(QChar lhs, const QStringRef &rhs) noexcept { return !(lhs > rhs); } +inline bool operator>=(QChar lhs, const QStringRef &rhs) noexcept { return !(lhs < rhs); } -inline bool operator==(const QStringRef &lhs, QChar rhs) Q_DECL_NOTHROW { return rhs == lhs; } -inline bool operator!=(const QStringRef &lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs == lhs); } -inline bool operator< (const QStringRef &lhs, QChar rhs) Q_DECL_NOTHROW { return rhs > lhs; } -inline bool operator> (const QStringRef &lhs, QChar rhs) Q_DECL_NOTHROW { return rhs < lhs; } -inline bool operator<=(const QStringRef &lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs < lhs); } -inline bool operator>=(const QStringRef &lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs > lhs); } +inline bool operator==(const QStringRef &lhs, QChar rhs) noexcept { return rhs == lhs; } +inline bool operator!=(const QStringRef &lhs, QChar rhs) noexcept { return !(rhs == lhs); } +inline bool operator< (const QStringRef &lhs, QChar rhs) noexcept { return rhs > lhs; } +inline bool operator> (const QStringRef &lhs, QChar rhs) noexcept { return rhs < lhs; } +inline bool operator<=(const QStringRef &lhs, QChar rhs) noexcept { return !(rhs < lhs); } +inline bool operator>=(const QStringRef &lhs, QChar rhs) noexcept { return !(rhs > lhs); } // QChar <> QLatin1String -inline bool operator==(QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW +inline bool operator==(QChar lhs, QLatin1String rhs) noexcept { return rhs.size() == 1 && lhs == rhs.front(); } -inline bool operator< (QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW +inline bool operator< (QChar lhs, QLatin1String rhs) noexcept { return QString::compare_helper(&lhs, 1, rhs) < 0; } -inline bool operator> (QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW +inline bool operator> (QChar lhs, QLatin1String rhs) noexcept { return QString::compare_helper(&lhs, 1, rhs) > 0; } -inline bool operator!=(QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW { return !(lhs == rhs); } -inline bool operator<=(QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW { return !(lhs > rhs); } -inline bool operator>=(QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW { return !(lhs < rhs); } +inline bool operator!=(QChar lhs, QLatin1String rhs) noexcept { return !(lhs == rhs); } +inline bool operator<=(QChar lhs, QLatin1String rhs) noexcept { return !(lhs > rhs); } +inline bool operator>=(QChar lhs, QLatin1String rhs) noexcept { return !(lhs < rhs); } -inline bool operator==(QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return rhs == lhs; } -inline bool operator!=(QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs == lhs); } -inline bool operator< (QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return rhs > lhs; } -inline bool operator> (QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return rhs < lhs; } -inline bool operator<=(QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs < lhs); } -inline bool operator>=(QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs > lhs); } +inline bool operator==(QLatin1String lhs, QChar rhs) noexcept { return rhs == lhs; } +inline bool operator!=(QLatin1String lhs, QChar rhs) noexcept { return !(rhs == lhs); } +inline bool operator< (QLatin1String lhs, QChar rhs) noexcept { return rhs > lhs; } +inline bool operator> (QLatin1String lhs, QChar rhs) noexcept { return rhs < lhs; } +inline bool operator<=(QLatin1String lhs, QChar rhs) noexcept { return !(rhs < lhs); } +inline bool operator>=(QLatin1String lhs, QChar rhs) noexcept { return !(rhs > lhs); } // QStringView <> QStringView -inline bool operator==(QStringView lhs, QStringView rhs) Q_DECL_NOTHROW { return lhs.size() == rhs.size() && QtPrivate::compareStrings(lhs, rhs) == 0; } -inline bool operator!=(QStringView lhs, QStringView rhs) Q_DECL_NOTHROW { return !(lhs == rhs); } -inline bool operator< (QStringView lhs, QStringView rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) < 0; } -inline bool operator<=(QStringView lhs, QStringView rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) <= 0; } -inline bool operator> (QStringView lhs, QStringView rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) > 0; } -inline bool operator>=(QStringView lhs, QStringView rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) >= 0; } +inline bool operator==(QStringView lhs, QStringView rhs) noexcept { return lhs.size() == rhs.size() && QtPrivate::compareStrings(lhs, rhs) == 0; } +inline bool operator!=(QStringView lhs, QStringView rhs) noexcept { return !(lhs == rhs); } +inline bool operator< (QStringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) < 0; } +inline bool operator<=(QStringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) <= 0; } +inline bool operator> (QStringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) > 0; } +inline bool operator>=(QStringView lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) >= 0; } // QStringView <> QChar -inline bool operator==(QStringView lhs, QChar rhs) Q_DECL_NOTHROW { return lhs == QStringView(&rhs, 1); } -inline bool operator!=(QStringView lhs, QChar rhs) Q_DECL_NOTHROW { return lhs != QStringView(&rhs, 1); } -inline bool operator< (QStringView lhs, QChar rhs) Q_DECL_NOTHROW { return lhs < QStringView(&rhs, 1); } -inline bool operator<=(QStringView lhs, QChar rhs) Q_DECL_NOTHROW { return lhs <= QStringView(&rhs, 1); } -inline bool operator> (QStringView lhs, QChar rhs) Q_DECL_NOTHROW { return lhs > QStringView(&rhs, 1); } -inline bool operator>=(QStringView lhs, QChar rhs) Q_DECL_NOTHROW { return lhs >= QStringView(&rhs, 1); } - -inline bool operator==(QChar lhs, QStringView rhs) Q_DECL_NOTHROW { return QStringView(&lhs, 1) == rhs; } -inline bool operator!=(QChar lhs, QStringView rhs) Q_DECL_NOTHROW { return QStringView(&lhs, 1) != rhs; } -inline bool operator< (QChar lhs, QStringView rhs) Q_DECL_NOTHROW { return QStringView(&lhs, 1) < rhs; } -inline bool operator<=(QChar lhs, QStringView rhs) Q_DECL_NOTHROW { return QStringView(&lhs, 1) <= rhs; } -inline bool operator> (QChar lhs, QStringView rhs) Q_DECL_NOTHROW { return QStringView(&lhs, 1) > rhs; } -inline bool operator>=(QChar lhs, QStringView rhs) Q_DECL_NOTHROW { return QStringView(&lhs, 1) >= rhs; } +inline bool operator==(QStringView lhs, QChar rhs) noexcept { return lhs == QStringView(&rhs, 1); } +inline bool operator!=(QStringView lhs, QChar rhs) noexcept { return lhs != QStringView(&rhs, 1); } +inline bool operator< (QStringView lhs, QChar rhs) noexcept { return lhs < QStringView(&rhs, 1); } +inline bool operator<=(QStringView lhs, QChar rhs) noexcept { return lhs <= QStringView(&rhs, 1); } +inline bool operator> (QStringView lhs, QChar rhs) noexcept { return lhs > QStringView(&rhs, 1); } +inline bool operator>=(QStringView lhs, QChar rhs) noexcept { return lhs >= QStringView(&rhs, 1); } + +inline bool operator==(QChar lhs, QStringView rhs) noexcept { return QStringView(&lhs, 1) == rhs; } +inline bool operator!=(QChar lhs, QStringView rhs) noexcept { return QStringView(&lhs, 1) != rhs; } +inline bool operator< (QChar lhs, QStringView rhs) noexcept { return QStringView(&lhs, 1) < rhs; } +inline bool operator<=(QChar lhs, QStringView rhs) noexcept { return QStringView(&lhs, 1) <= rhs; } +inline bool operator> (QChar lhs, QStringView rhs) noexcept { return QStringView(&lhs, 1) > rhs; } +inline bool operator>=(QChar lhs, QStringView rhs) noexcept { return QStringView(&lhs, 1) >= rhs; } // QStringView <> QLatin1String -inline bool operator==(QStringView lhs, QLatin1String rhs) Q_DECL_NOTHROW { return lhs.size() == rhs.size() && QtPrivate::compareStrings(lhs, rhs) == 0; } -inline bool operator!=(QStringView lhs, QLatin1String rhs) Q_DECL_NOTHROW { return !(lhs == rhs); } -inline bool operator< (QStringView lhs, QLatin1String rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) < 0; } -inline bool operator<=(QStringView lhs, QLatin1String rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) <= 0; } -inline bool operator> (QStringView lhs, QLatin1String rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) > 0; } -inline bool operator>=(QStringView lhs, QLatin1String rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) >= 0; } - -inline bool operator==(QLatin1String lhs, QStringView rhs) Q_DECL_NOTHROW { return lhs.size() == rhs.size() && QtPrivate::compareStrings(lhs, rhs) == 0; } -inline bool operator!=(QLatin1String lhs, QStringView rhs) Q_DECL_NOTHROW { return !(lhs == rhs); } -inline bool operator< (QLatin1String lhs, QStringView rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) < 0; } -inline bool operator<=(QLatin1String lhs, QStringView rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) <= 0; } -inline bool operator> (QLatin1String lhs, QStringView rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) > 0; } -inline bool operator>=(QLatin1String lhs, QStringView rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) >= 0; } +inline bool operator==(QStringView lhs, QLatin1String rhs) noexcept { return lhs.size() == rhs.size() && QtPrivate::compareStrings(lhs, rhs) == 0; } +inline bool operator!=(QStringView lhs, QLatin1String rhs) noexcept { return !(lhs == rhs); } +inline bool operator< (QStringView lhs, QLatin1String rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) < 0; } +inline bool operator<=(QStringView lhs, QLatin1String rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) <= 0; } +inline bool operator> (QStringView lhs, QLatin1String rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) > 0; } +inline bool operator>=(QStringView lhs, QLatin1String rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) >= 0; } + +inline bool operator==(QLatin1String lhs, QStringView rhs) noexcept { return lhs.size() == rhs.size() && QtPrivate::compareStrings(lhs, rhs) == 0; } +inline bool operator!=(QLatin1String lhs, QStringView rhs) noexcept { return !(lhs == rhs); } +inline bool operator< (QLatin1String lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) < 0; } +inline bool operator<=(QLatin1String lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) <= 0; } +inline bool operator> (QLatin1String lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) > 0; } +inline bool operator>=(QLatin1String lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) >= 0; } #if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) // QStringRef <> QByteArray diff --git a/src/corelib/tools/qstringalgorithms.h b/src/corelib/tools/qstringalgorithms.h index cc0eda71f3..8e7fc0af9b 100644 --- a/src/corelib/tools/qstringalgorithms.h +++ b/src/corelib/tools/qstringalgorithms.h @@ -51,31 +51,36 @@ QT_BEGIN_NAMESPACE class QByteArray; class QLatin1String; class QStringView; +class QChar; template <typename T> class QVector; namespace QtPrivate { -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype qustrlen(const ushort *str) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype qustrlen(const ushort *str) noexcept; Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION const ushort *qustrchr(QStringView str, ushort ch) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QStringView lhs, QLatin1String rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QLatin1String lhs, QStringView rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QLatin1String lhs, QLatin1String rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QStringView lhs, QLatin1String rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QLatin1String lhs, QStringView rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QLatin1String lhs, QLatin1String rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION QStringView trimmed(QStringView s) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION QLatin1String trimmed(QLatin1String s) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype findChar(QStringView str, QChar ch, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype findString(QStringView haystack, qsizetype from, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype findString(QStringView haystack, qsizetype from, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; + +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION QStringView trimmed(QStringView s) noexcept; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION QLatin1String trimmed(QLatin1String s) noexcept; Q_REQUIRED_RESULT Q_CORE_EXPORT QByteArray convertToLatin1(QStringView str); Q_REQUIRED_RESULT Q_CORE_EXPORT QByteArray convertToUtf8(QStringView str); @@ -83,10 +88,10 @@ Q_REQUIRED_RESULT Q_CORE_EXPORT QByteArray convertToLocal8Bit(QStringView str); Q_REQUIRED_RESULT Q_CORE_EXPORT QVector<uint> convertToUcs4(QStringView str); Q_REQUIRED_RESULT Q_CORE_EXPORT bool isRightToLeft(QStringView string); -Q_REQUIRED_RESULT Q_CORE_EXPORT bool isAscii(QLatin1String s) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT bool isAscii(QStringView s) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT bool isLatin1(QLatin1String s) Q_DECL_NOTHROW; // in qstring.h -Q_REQUIRED_RESULT Q_CORE_EXPORT bool isLatin1(QStringView s) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT bool isAscii(QLatin1String s) noexcept; +Q_REQUIRED_RESULT Q_CORE_EXPORT bool isAscii(QStringView s) noexcept; +Q_REQUIRED_RESULT bool isLatin1(QLatin1String s) noexcept; // in qstring.h +Q_REQUIRED_RESULT Q_CORE_EXPORT bool isLatin1(QStringView s) noexcept; } // namespace QtPRivate diff --git a/src/corelib/tools/qstringalgorithms_p.h b/src/corelib/tools/qstringalgorithms_p.h index 4bcf697f78..64d9f2e676 100644 --- a/src/corelib/tools/qstringalgorithms_p.h +++ b/src/corelib/tools/qstringalgorithms_p.h @@ -77,7 +77,7 @@ template <typename StringType> struct QStringAlgorithms if (begin != data) memmove(data, begin, (end - begin) * sizeof(Char)); str.resize(end - begin); - return qMove(str); + return std::move(str); } static inline StringType trimmed_helper_inplace(const NakedStringType &, const Char *, const Char *) @@ -118,7 +118,7 @@ template <typename StringType> struct QStringAlgorithms const Char *end = str.cend(); NakedStringType result = isConst || !str.isDetached() ? StringType(str.size(), Qt::Uninitialized) : - qMove(str); + std::move(str); Char *dst = const_cast<Char *>(result.cbegin()); Char *ptr = dst; diff --git a/src/corelib/tools/qstringbuilder.cpp b/src/corelib/tools/qstringbuilder.cpp index 8afc83819b..cf443ec369 100644 --- a/src/corelib/tools/qstringbuilder.cpp +++ b/src/corelib/tools/qstringbuilder.cpp @@ -124,7 +124,7 @@ QT_BEGIN_NAMESPACE /*! \internal */ -void QAbstractConcatenable::convertFromAscii(const char *a, int len, QChar *&out) Q_DECL_NOTHROW +void QAbstractConcatenable::convertFromAscii(const char *a, int len, QChar *&out) noexcept { if (Q_UNLIKELY(len == -1)) { if (!a) diff --git a/src/corelib/tools/qstringbuilder.h b/src/corelib/tools/qstringbuilder.h index 1d96d70637..79ed10c7a8 100644 --- a/src/corelib/tools/qstringbuilder.h +++ b/src/corelib/tools/qstringbuilder.h @@ -58,12 +58,12 @@ QT_BEGIN_NAMESPACE struct Q_CORE_EXPORT QAbstractConcatenable { protected: - static void convertFromAscii(const char *a, int len, QChar *&out) Q_DECL_NOTHROW; - static inline void convertFromAscii(char a, QChar *&out) Q_DECL_NOTHROW + static void convertFromAscii(const char *a, int len, QChar *&out) noexcept; + static inline void convertFromAscii(char a, QChar *&out) noexcept { *out++ = QLatin1Char(a); } - static void appendLatin1To(const char *a, int len, QChar *out) Q_DECL_NOTHROW; + static void appendLatin1To(const char *a, int len, QChar *out) noexcept; }; template <typename T> struct QConcatenable {}; diff --git a/src/corelib/tools/qstringlist.cpp b/src/corelib/tools/qstringlist.cpp index cc6eaf8ad2..f6da7b1428 100644 --- a/src/corelib/tools/qstringlist.cpp +++ b/src/corelib/tools/qstringlist.cpp @@ -38,6 +38,7 @@ ****************************************************************************/ #include <qstringlist.h> +#include <qregexp.h> #include <qset.h> #if QT_CONFIG(regularexpression) # include <qregularexpression.h> @@ -847,5 +848,12 @@ int QtPrivate::QStringList_removeDuplicates(QStringList *that) lists. */ + /*! \fn template<typename InputIterator> QStringList::QStringList(InputIterator first, InputIterator last) + \since 5.14 + + Constructs a QStringList with the contents in the iterator range [\a first, \a last). + + The value type of \c InputIterator must be convertible to \c QString. + */ QT_END_NAMESPACE diff --git a/src/corelib/tools/qstringlist.h b/src/corelib/tools/qstringlist.h index b6c48488df..5ad01a0658 100644 --- a/src/corelib/tools/qstringlist.h +++ b/src/corelib/tools/qstringlist.h @@ -44,6 +44,7 @@ #define QSTRINGLIST_H #include <QtCore/qalgorithms.h> +#include <QtCore/qcontainertools_impl.h> #include <QtCore/qregexp.h> #include <QtCore/qstring.h> #include <QtCore/qstringmatcher.h> @@ -100,20 +101,23 @@ class QStringList : public QList<QString> { #endif public: - inline QStringList() Q_DECL_NOTHROW { } + inline QStringList() noexcept { } 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) Q_DECL_NOTHROW : QList<QString>(std::move(l)) { } + inline QStringList(QList<QString> &&l) noexcept : QList<QString>(std::move(l)) { } #endif #ifdef Q_COMPILER_INITIALIZER_LISTS inline QStringList(std::initializer_list<QString> args) : QList<QString>(args) { } #endif + template <typename InputIterator, QtPrivate::IfIsInputIterator<InputIterator> = true> + inline QStringList(InputIterator first, InputIterator last) + : QList<QString>(first, last) { } QStringList &operator=(const QList<QString> &other) { QList<QString>::operator=(other); return *this; } #ifdef Q_COMPILER_RVALUE_REFS - QStringList &operator=(QList<QString> &&other) Q_DECL_NOTHROW + QStringList &operator=(QList<QString> &&other) noexcept { QList<QString>::operator=(std::move(other)); return *this; } #endif diff --git a/src/corelib/tools/qstringliteral.h b/src/corelib/tools/qstringliteral.h index 64296b89fc..603f19c0b4 100644 --- a/src/corelib/tools/qstringliteral.h +++ b/src/corelib/tools/qstringliteral.h @@ -63,7 +63,7 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2, #define QT_UNICODE_LITERAL(str) u"" str #define QStringLiteral(str) \ - ([]() Q_DECL_NOEXCEPT -> QString { \ + ([]() noexcept -> QString { \ enum { Size = sizeof(QT_UNICODE_LITERAL(str))/2 - 1 }; \ static const QStaticStringData<Size> qstring_literal = { \ Q_STATIC_STRING_DATA_HEADER_INITIALIZER(Size), \ diff --git a/src/corelib/tools/qstringmatcher.cpp b/src/corelib/tools/qstringmatcher.cpp index 67d3f0ebc8..417910b6ec 100644 --- a/src/corelib/tools/qstringmatcher.cpp +++ b/src/corelib/tools/qstringmatcher.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 Mail.ru Group. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -41,43 +42,43 @@ QT_BEGIN_NAMESPACE -static void bm_init_skiptable(const ushort *uc, int len, uchar *skiptable, Qt::CaseSensitivity cs) +static void bm_init_skiptable(const ushort *uc, qsizetype len, uchar *skiptable, Qt::CaseSensitivity cs) { - int l = qMin(len, 255); - memset(skiptable, l, 256*sizeof(uchar)); + int l = int(qMin(len, qsizetype(255))); + memset(skiptable, l, 256 * sizeof(uchar)); uc += len - l; if (cs == Qt::CaseSensitive) { while (l--) { skiptable[*uc & 0xff] = l; - uc++; + ++uc; } } else { const ushort *start = uc; while (l--) { skiptable[foldCase(uc, start) & 0xff] = l; - uc++; + ++uc; } } } -static inline int bm_find(const ushort *uc, uint l, int index, const ushort *puc, uint pl, +static inline qsizetype bm_find(const ushort *uc, qsizetype l, qsizetype index, const ushort *puc, qsizetype pl, const uchar *skiptable, Qt::CaseSensitivity cs) { if (pl == 0) - return index > (int)l ? -1 : index; - const uint pl_minus_one = pl - 1; + return index > l ? -1 : index; + const qsizetype pl_minus_one = pl - 1; const ushort *current = uc + index + pl_minus_one; const ushort *end = uc + l; if (cs == Qt::CaseSensitive) { while (current < end) { - uint skip = skiptable[*current & 0xff]; + qsizetype skip = skiptable[*current & 0xff]; if (!skip) { // possible match while (skip < pl) { if (*(current - skip) != puc[pl_minus_one-skip]) break; - skip++; + ++skip; } if (skip > pl_minus_one) // we have a match return (current - uc) - pl_minus_one; @@ -95,13 +96,13 @@ static inline int bm_find(const ushort *uc, uint l, int index, const ushort *puc } } else { while (current < end) { - uint skip = skiptable[foldCase(current, uc) & 0xff]; + qsizetype skip = skiptable[foldCase(current, uc) & 0xff]; if (!skip) { // possible match while (skip < pl) { if (foldCase(current - skip, uc) != foldCase(puc + pl_minus_one - skip, puc)) break; - skip++; + ++skip; } if (skip > pl_minus_one) // we have a match return (current - uc) - pl_minus_one; @@ -175,14 +176,27 @@ QStringMatcher::QStringMatcher(const QString &pattern, Qt::CaseSensitivity cs) by \a uc with the given \a length and case sensitivity specified by \a cs. */ QStringMatcher::QStringMatcher(const QChar *uc, int len, Qt::CaseSensitivity cs) - : d_ptr(0), q_cs(cs) + : QStringMatcher(QStringView(uc, len), cs) { - p.uc = uc; - p.len = len; - bm_init_skiptable((const ushort *)p.uc, len, p.q_skiptable, cs); } /*! + \fn QStringMatcher::QStringMatcher(QStringView str, Qt::CaseSensitivity cs) + \since 5.14 + + Constructs a string matcher that will search for \a pattern, with + case sensitivity \a cs. + + Call indexIn() to perform a search. +*/ +QStringMatcher::QStringMatcher(QStringView str, Qt::CaseSensitivity cs) + : d_ptr(nullptr), q_cs(cs) +{ + p.uc = str.data(); + p.len = int(str.size()); + bm_init_skiptable((const ushort *)p.uc, p.len, p.q_skiptable, cs); +} +/*! Copies the \a other string matcher to this string matcher. */ QStringMatcher::QStringMatcher(const QStringMatcher &other) @@ -267,11 +281,7 @@ void QStringMatcher::setCaseSensitivity(Qt::CaseSensitivity cs) */ int QStringMatcher::indexIn(const QString &str, int from) const { - if (from < 0) - from = 0; - return bm_find((const ushort *)str.unicode(), str.size(), from, - (const ushort *)p.uc, p.len, - p.q_skiptable, q_cs); + return int(indexIn(QStringView(str), from)); } /*! @@ -288,9 +298,25 @@ int QStringMatcher::indexIn(const QString &str, int from) const */ int QStringMatcher::indexIn(const QChar *str, int length, int from) const { + return int(indexIn(QStringView(str, length), from)); +} + +/*! + \since 5.14 + + Searches the string \a str from character position \a from + (default 0, i.e. from the first character), for the string + pattern() that was set in the constructor or in the most recent + call to setPattern(). Returns the position where the pattern() + matched in \a str, or -1 if no match was found. + + \sa setPattern(), setCaseSensitivity() +*/ +qsizetype QStringMatcher::indexIn(QStringView str, qsizetype from) const +{ if (from < 0) from = 0; - return bm_find((const ushort *)str, length, from, + return bm_find((const ushort *)str.data(), str.size(), from, (const ushort *)p.uc, p.len, p.q_skiptable, q_cs); } @@ -307,16 +333,16 @@ int QStringMatcher::indexIn(const QChar *str, int length, int from) const \internal */ -int qFindStringBoyerMoore( - const QChar *haystack, int haystackLen, int haystackOffset, - const QChar *needle, int needleLen, Qt::CaseSensitivity cs) +qsizetype qFindStringBoyerMoore( + QStringView haystack, qsizetype haystackOffset, + QStringView needle, Qt::CaseSensitivity cs) { uchar skiptable[256]; - bm_init_skiptable((const ushort *)needle, needleLen, skiptable, cs); + bm_init_skiptable((const ushort *)needle.data(), needle.size(), skiptable, cs); if (haystackOffset < 0) haystackOffset = 0; - return bm_find((const ushort *)haystack, haystackLen, haystackOffset, - (const ushort *)needle, needleLen, skiptable, cs); + return bm_find((const ushort *)haystack.data(), haystack.size(), haystackOffset, + (const ushort *)needle.data(), needle.size(), skiptable, cs); } QT_END_NAMESPACE diff --git a/src/corelib/tools/qstringmatcher.h b/src/corelib/tools/qstringmatcher.h index 549bff9f29..6de4353930 100644 --- a/src/corelib/tools/qstringmatcher.h +++ b/src/corelib/tools/qstringmatcher.h @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 Mail.ru Group. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -41,6 +42,7 @@ #define QSTRINGMATCHER_H #include <QtCore/qstring.h> +#include <QtCore/qstringview.h> QT_BEGIN_NAMESPACE @@ -55,6 +57,8 @@ public: Qt::CaseSensitivity cs = Qt::CaseSensitive); QStringMatcher(const QChar *uc, int len, Qt::CaseSensitivity cs = Qt::CaseSensitive); + QStringMatcher(QStringView pattern, + Qt::CaseSensitivity cs = Qt::CaseSensitive); QStringMatcher(const QStringMatcher &other); ~QStringMatcher(); @@ -65,6 +69,7 @@ public: int indexIn(const QString &str, int from = 0) const; int indexIn(const QChar *str, int length, int from = 0) const; + qsizetype indexIn(QStringView str, qsizetype from = 0) const; QString pattern() const; inline Qt::CaseSensitivity caseSensitivity() const { return q_cs; } diff --git a/src/corelib/tools/qstringview.cpp b/src/corelib/tools/qstringview.cpp index b97e989110..c863ca7ce2 100644 --- a/src/corelib/tools/qstringview.cpp +++ b/src/corelib/tools/qstringview.cpp @@ -38,6 +38,7 @@ ****************************************************************************/ #include "qstringview.h" +#include "qstring.h" QT_BEGIN_NAMESPACE @@ -794,4 +795,34 @@ QT_BEGIN_NAMESPACE \sa QString::isRightToLeft() */ +/*! + \since 5.14 + + Transcribes this string into the given \a array. + + Caller is responsible for ensuring \a array is large enough to hold the \t + wchar_t encoding of this string (allocating the array with the same length + as the string is always sufficient). The array is encoded in UTF-16 on + platforms where \t wchar_t is 2 bytes wide (e.g. Windows); otherwise (Unix + systems), \t wchar_t is assumed to be 4 bytes wide and the data is written + in UCS-4. + + \note This function writes no null terminator to the end of \a array. + + Returns the number of \t wchar_t entries written to \a array. + + \sa QString::toWCharArray() +*/ + +int QStringView::toWCharArray(wchar_t *array) const +{ + if (sizeof(wchar_t) == sizeof(QChar)) { + memcpy(array, data(), sizeof(QChar) * size()); + return size(); + } else { + return QString::toUcs4_helper(reinterpret_cast<const ushort *>(data()), int(size()), + reinterpret_cast<uint *>(array)); + } +} + QT_END_NAMESPACE diff --git a/src/corelib/tools/qstringview.h b/src/corelib/tools/qstringview.h index 2e95c2b218..5b6d63b71c 100644 --- a/src/corelib/tools/qstringview.h +++ b/src/corelib/tools/qstringview.h @@ -139,13 +139,13 @@ private: using if_compatible_qstring_like = typename std::enable_if<std::is_same<T, QString>::value || std::is_same<T, QStringRef>::value, bool>::type; template <typename Char, size_t N> - static Q_DECL_CONSTEXPR qsizetype lengthHelperArray(const Char (&)[N]) Q_DECL_NOTHROW + static Q_DECL_CONSTEXPR qsizetype lengthHelperArray(const Char (&)[N]) noexcept { return qsizetype(N - 1); } template <typename Char> - static qsizetype lengthHelperPointer(const Char *str) Q_DECL_NOTHROW + static qsizetype lengthHelperPointer(const Char *str) noexcept { #if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) if (__builtin_constant_p(*str)) { @@ -157,21 +157,21 @@ private: #endif return QtPrivate::qustrlen(reinterpret_cast<const ushort *>(str)); } - static qsizetype lengthHelperPointer(const QChar *str) Q_DECL_NOTHROW + static qsizetype lengthHelperPointer(const QChar *str) noexcept { return QtPrivate::qustrlen(reinterpret_cast<const ushort *>(str)); } template <typename Char> - static const storage_type *castHelper(const Char *str) Q_DECL_NOTHROW + static const storage_type *castHelper(const Char *str) noexcept { return reinterpret_cast<const storage_type*>(str); } - static Q_DECL_CONSTEXPR const storage_type *castHelper(const storage_type *str) Q_DECL_NOTHROW + static Q_DECL_CONSTEXPR const storage_type *castHelper(const storage_type *str) noexcept { return str; } public: - Q_DECL_CONSTEXPR QStringView() Q_DECL_NOTHROW + Q_DECL_CONSTEXPR QStringView() noexcept : m_size(0), m_data(nullptr) {} - Q_DECL_CONSTEXPR QStringView(std::nullptr_t) Q_DECL_NOTHROW + Q_DECL_CONSTEXPR QStringView(std::nullptr_t) noexcept : QStringView() {} template <typename Char, if_compatible_char<Char> = true> @@ -185,38 +185,38 @@ public: #ifdef Q_CLANG_QDOC template <typename Char, size_t N> - Q_DECL_CONSTEXPR QStringView(const Char (&array)[N]) Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR QStringView(const Char (&array)[N]) noexcept; template <typename Char> - Q_DECL_CONSTEXPR QStringView(const Char *str) Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR QStringView(const Char *str) noexcept; #else template <typename Array, if_compatible_array<Array> = true> - Q_DECL_CONSTEXPR QStringView(const Array &str) Q_DECL_NOTHROW + Q_DECL_CONSTEXPR QStringView(const Array &str) noexcept : QStringView(str, lengthHelperArray(str)) {} template <typename Pointer, if_compatible_pointer<Pointer> = true> - Q_DECL_CONSTEXPR QStringView(const Pointer &str) Q_DECL_NOTHROW + Q_DECL_CONSTEXPR QStringView(const Pointer &str) noexcept : QStringView(str, str ? lengthHelperPointer(str) : 0) {} #endif #ifdef Q_CLANG_QDOC - QStringView(const QString &str) Q_DECL_NOTHROW; - QStringView(const QStringRef &str) Q_DECL_NOTHROW; + QStringView(const QString &str) noexcept; + QStringView(const QStringRef &str) noexcept; #else template <typename String, if_compatible_qstring_like<String> = true> - QStringView(const String &str) Q_DECL_NOTHROW + QStringView(const String &str) noexcept : QStringView(str.isNull() ? nullptr : str.data(), qsizetype(str.size())) {} #endif template <typename StdBasicString, if_compatible_string<StdBasicString> = true> - QStringView(const StdBasicString &str) Q_DECL_NOTHROW + QStringView(const StdBasicString &str) noexcept : QStringView(str.data(), qsizetype(str.size())) {} Q_REQUIRED_RESULT inline QString toString() const; // defined in qstring.h - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR qsizetype size() const Q_DECL_NOTHROW { return m_size; } - Q_REQUIRED_RESULT const_pointer data() const Q_DECL_NOTHROW { return reinterpret_cast<const_pointer>(m_data); } - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR const storage_type *utf16() const Q_DECL_NOTHROW { return m_data; } + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR qsizetype size() const noexcept { return m_size; } + Q_REQUIRED_RESULT const_pointer data() const noexcept { return reinterpret_cast<const_pointer>(m_data); } + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR const storage_type *utf16() const noexcept { return m_data; } Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QChar operator[](qsizetype n) const { return Q_ASSERT(n >= 0), Q_ASSERT(n < size()), QChar(m_data[n]); } @@ -248,51 +248,53 @@ public: Q_DECL_RELAXED_CONSTEXPR void chop(qsizetype n) { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); m_size -= n; } - Q_REQUIRED_RESULT QStringView trimmed() const Q_DECL_NOTHROW { return QtPrivate::trimmed(*this); } + Q_REQUIRED_RESULT QStringView trimmed() const noexcept { return QtPrivate::trimmed(*this); } - Q_REQUIRED_RESULT int compare(QStringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT int compare(QStringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::compareStrings(*this, other, cs); } - Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::startsWith(*this, s, cs); } - Q_REQUIRED_RESULT inline bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; - Q_REQUIRED_RESULT bool startsWith(QChar c) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT inline bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + Q_REQUIRED_RESULT bool startsWith(QChar c) const noexcept { return !empty() && front() == c; } - Q_REQUIRED_RESULT bool startsWith(QChar c, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT bool startsWith(QChar c, Qt::CaseSensitivity cs) const noexcept { return QtPrivate::startsWith(*this, QStringView(&c, 1), cs); } - Q_REQUIRED_RESULT bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::endsWith(*this, s, cs); } - Q_REQUIRED_RESULT inline bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; - Q_REQUIRED_RESULT bool endsWith(QChar c) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT inline bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + Q_REQUIRED_RESULT bool endsWith(QChar c) const noexcept { return !empty() && back() == c; } - Q_REQUIRED_RESULT bool endsWith(QChar c, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT bool endsWith(QChar c, Qt::CaseSensitivity cs) const noexcept { return QtPrivate::endsWith(*this, QStringView(&c, 1), cs); } - Q_REQUIRED_RESULT bool isRightToLeft() const Q_DECL_NOTHROW + Q_REQUIRED_RESULT bool isRightToLeft() const noexcept { return QtPrivate::isRightToLeft(*this); } + Q_REQUIRED_RESULT Q_CORE_EXPORT int toWCharArray(wchar_t *array) const; + // // STL compatibility API: // - Q_REQUIRED_RESULT const_iterator begin() const Q_DECL_NOTHROW { return data(); } - Q_REQUIRED_RESULT const_iterator end() const Q_DECL_NOTHROW { return data() + size(); } - Q_REQUIRED_RESULT const_iterator cbegin() const Q_DECL_NOTHROW { return begin(); } - Q_REQUIRED_RESULT const_iterator cend() const Q_DECL_NOTHROW { return end(); } - Q_REQUIRED_RESULT const_reverse_iterator rbegin() const Q_DECL_NOTHROW { return const_reverse_iterator(end()); } - Q_REQUIRED_RESULT const_reverse_iterator rend() const Q_DECL_NOTHROW { return const_reverse_iterator(begin()); } - Q_REQUIRED_RESULT const_reverse_iterator crbegin() const Q_DECL_NOTHROW { return rbegin(); } - Q_REQUIRED_RESULT const_reverse_iterator crend() const Q_DECL_NOTHROW { return rend(); } - - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR bool empty() const Q_DECL_NOTHROW { return size() == 0; } + Q_REQUIRED_RESULT const_iterator begin() const noexcept { return data(); } + Q_REQUIRED_RESULT const_iterator end() const noexcept { return data() + size(); } + Q_REQUIRED_RESULT const_iterator cbegin() const noexcept { return begin(); } + Q_REQUIRED_RESULT const_iterator cend() const noexcept { return end(); } + Q_REQUIRED_RESULT const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } + Q_REQUIRED_RESULT const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } + Q_REQUIRED_RESULT const_reverse_iterator crbegin() const noexcept { return rbegin(); } + Q_REQUIRED_RESULT const_reverse_iterator crend() const noexcept { return rend(); } + + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR bool empty() const noexcept { return size() == 0; } Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QChar front() const { return Q_ASSERT(!empty()), QChar(m_data[0]); } Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QChar back() const { return Q_ASSERT(!empty()), QChar(m_data[m_size - 1]); } // // Qt compatibility API: // - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR bool isNull() const Q_DECL_NOTHROW { return !m_data; } - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR bool isEmpty() const Q_DECL_NOTHROW { return empty(); } + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR bool isNull() const noexcept { return !m_data; } + Q_REQUIRED_RESULT Q_DECL_CONSTEXPR bool isEmpty() const noexcept { return empty(); } Q_REQUIRED_RESULT Q_DECL_CONSTEXPR int length() const /* not nothrow! */ { return Q_ASSERT(int(size()) == size()), int(size()); } Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QChar first() const { return front(); } @@ -306,7 +308,7 @@ Q_DECLARE_TYPEINFO(QStringView, Q_PRIMITIVE_TYPE); template <typename QStringLike, typename std::enable_if< std::is_same<QStringLike, QString>::value || std::is_same<QStringLike, QStringRef>::value, bool>::type = true> -inline QStringView qToStringViewIgnoringNull(const QStringLike &s) Q_DECL_NOTHROW +inline QStringView qToStringViewIgnoringNull(const QStringLike &s) noexcept { return QStringView(s.data(), s.size()); } QT_END_NAMESPACE diff --git a/src/corelib/tools/qtimezone.cpp b/src/corelib/tools/qtimezone.cpp index cbc6b50c98..ef323de14a 100644 --- a/src/corelib/tools/qtimezone.cpp +++ b/src/corelib/tools/qtimezone.cpp @@ -317,7 +317,7 @@ Q_GLOBAL_STATIC(QTimeZoneSingleton, global_tz); Create a null/invalid time zone instance. */ -QTimeZone::QTimeZone() Q_DECL_NOTHROW +QTimeZone::QTimeZone() noexcept : d(0) { } diff --git a/src/corelib/tools/qtimezone.h b/src/corelib/tools/qtimezone.h index 29d8a4dbe5..ca98986ec1 100644 --- a/src/corelib/tools/qtimezone.h +++ b/src/corelib/tools/qtimezone.h @@ -89,7 +89,7 @@ public: }; typedef QVector<OffsetData> OffsetDataList; - QTimeZone() Q_DECL_NOTHROW; + QTimeZone() noexcept; explicit QTimeZone(const QByteArray &ianaId); explicit QTimeZone(int offsetSeconds); /*implicit*/ QTimeZone(const QByteArray &zoneId, int offsetSeconds, const QString &name, @@ -100,10 +100,10 @@ public: QTimeZone &operator=(const QTimeZone &other); #ifdef Q_COMPILER_RVALUE_REFS - QTimeZone &operator=(QTimeZone &&other) Q_DECL_NOTHROW { swap(other); return *this; } + QTimeZone &operator=(QTimeZone &&other) noexcept { swap(other); return *this; } #endif - void swap(QTimeZone &other) Q_DECL_NOTHROW + void swap(QTimeZone &other) noexcept { d.swap(other.d); } bool operator==(const QTimeZone &other) const; diff --git a/src/corelib/tools/qtimezoneprivate_p.h b/src/corelib/tools/qtimezoneprivate_p.h index 24a9a00f11..b5e9286f6a 100644 --- a/src/corelib/tools/qtimezoneprivate_p.h +++ b/src/corelib/tools/qtimezoneprivate_p.h @@ -282,9 +282,9 @@ struct QTzTransitionRule quint8 abbreviationIndex; }; Q_DECLARE_TYPEINFO(QTzTransitionRule, Q_PRIMITIVE_TYPE); -Q_DECL_CONSTEXPR inline bool operator==(const QTzTransitionRule &lhs, const QTzTransitionRule &rhs) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool operator==(const QTzTransitionRule &lhs, const QTzTransitionRule &rhs) noexcept { return lhs.stdOffset == rhs.stdOffset && lhs.dstOffset == rhs.dstOffset && lhs.abbreviationIndex == rhs.abbreviationIndex; } -Q_DECL_CONSTEXPR inline bool operator!=(const QTzTransitionRule &lhs, const QTzTransitionRule &rhs) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline bool operator!=(const QTzTransitionRule &lhs, const QTzTransitionRule &rhs) noexcept { return !operator==(lhs, rhs); } class Q_AUTOTEST_EXPORT QTzTimeZonePrivate final : public QTimeZonePrivate diff --git a/src/corelib/tools/qtimezoneprivate_tz.cpp b/src/corelib/tools/qtimezoneprivate_tz.cpp index 7d85bc077d..fab0b2cbf1 100644 --- a/src/corelib/tools/qtimezoneprivate_tz.cpp +++ b/src/corelib/tools/qtimezoneprivate_tz.cpp @@ -468,7 +468,7 @@ struct PosixZone static PosixZone invalid() { return {QString(), InvalidOffset}; } static PosixZone parse(const char *&pos, const char *end); - bool hasValidOffset() const Q_DECL_NOTHROW { return offset != InvalidOffset; } + bool hasValidOffset() const noexcept { return offset != InvalidOffset; } }; } // unnamed namespace diff --git a/src/corelib/tools/qtools_p.h b/src/corelib/tools/qtools_p.h index 17d2ab852a..b239987871 100644 --- a/src/corelib/tools/qtools_p.h +++ b/src/corelib/tools/qtools_p.h @@ -57,17 +57,17 @@ QT_BEGIN_NAMESPACE namespace QtMiscUtils { -Q_DECL_CONSTEXPR inline char toHexUpper(uint value) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline char toHexUpper(uint value) noexcept { return "0123456789ABCDEF"[value & 0xF]; } -Q_DECL_CONSTEXPR inline char toHexLower(uint value) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline char toHexLower(uint value) noexcept { return "0123456789abcdef"[value & 0xF]; } -Q_DECL_CONSTEXPR inline int fromHex(uint c) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline int fromHex(uint c) noexcept { return ((c >= '0') && (c <= '9')) ? int(c - '0') : ((c >= 'A') && (c <= 'F')) ? int(c - 'A' + 10) : @@ -75,12 +75,12 @@ Q_DECL_CONSTEXPR inline int fromHex(uint c) Q_DECL_NOTHROW /* otherwise */ -1; } -Q_DECL_CONSTEXPR inline char toOct(uint value) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline char toOct(uint value) noexcept { return '0' + char(value & 0x7); } -Q_DECL_CONSTEXPR inline int fromOct(uint c) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline int fromOct(uint c) noexcept { return ((c >= '0') && (c <= '7')) ? int(c - '0') : -1; } @@ -98,9 +98,9 @@ struct CalculateGrowingBlockSizeResult { // implemented in qbytearray.cpp size_t Q_CORE_EXPORT Q_DECL_CONST_FUNCTION -qCalculateBlockSize(size_t elementCount, size_t elementSize, size_t headerSize = 0) Q_DECL_NOTHROW; +qCalculateBlockSize(size_t elementCount, size_t elementSize, size_t headerSize = 0) noexcept; CalculateGrowingBlockSizeResult Q_CORE_EXPORT Q_DECL_CONST_FUNCTION -qCalculateGrowingBlockSize(size_t elementCount, size_t elementSize, size_t headerSize = 0) Q_DECL_NOTHROW ; +qCalculateGrowingBlockSize(size_t elementCount, size_t elementSize, size_t headerSize = 0) noexcept ; QT_END_NAMESPACE diff --git a/src/corelib/tools/qunicodetables.cpp b/src/corelib/tools/qunicodetables.cpp index 4c4821802d..d57b39ff1f 100644 --- a/src/corelib/tools/qunicodetables.cpp +++ b/src/corelib/tools/qunicodetables.cpp @@ -8803,42 +8803,42 @@ static const Properties uc_properties[] = { { 12, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 12, 0 } }; -Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(uint ucs4) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(uint ucs4) noexcept { return uc_properties + GET_PROP_INDEX(ucs4); } -Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(ushort ucs2) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(ushort ucs2) noexcept { return uc_properties + GET_PROP_INDEX_UCS2(ucs2); } -Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4) noexcept { return qGetProp(ucs4); } -Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2) noexcept { return qGetProp(ucs2); } -Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(uint ucs4) Q_DECL_NOTHROW +Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(uint ucs4) noexcept { return static_cast<GraphemeBreakClass>(qGetProp(ucs4)->graphemeBreakClass); } -Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(uint ucs4) Q_DECL_NOTHROW +Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(uint ucs4) noexcept { return static_cast<WordBreakClass>(qGetProp(ucs4)->wordBreakClass); } -Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(uint ucs4) Q_DECL_NOTHROW +Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(uint ucs4) noexcept { return static_cast<SentenceBreakClass>(qGetProp(ucs4)->sentenceBreakClass); } -Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(uint ucs4) Q_DECL_NOTHROW +Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(uint ucs4) noexcept { return static_cast<LineBreakClass>(qGetProp(ucs4)->lineBreakClass); } diff --git a/src/corelib/tools/qunicodetables_p.h b/src/corelib/tools/qunicodetables_p.h index 3f2e91a9b2..cb7a211cb6 100644 --- a/src/corelib/tools/qunicodetables_p.h +++ b/src/corelib/tools/qunicodetables_p.h @@ -93,8 +93,8 @@ struct Properties { ushort script : 8; }; -Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4) Q_DECL_NOTHROW; -Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2) Q_DECL_NOTHROW; +Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4) noexcept; +Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2) noexcept; struct LowercaseTraits { @@ -209,20 +209,20 @@ enum LineBreakClass { NumLineBreakClasses }; -Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(uint ucs4) Q_DECL_NOTHROW; -inline GraphemeBreakClass graphemeBreakClass(QChar ch) Q_DECL_NOTHROW +Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(uint ucs4) noexcept; +inline GraphemeBreakClass graphemeBreakClass(QChar ch) noexcept { return graphemeBreakClass(ch.unicode()); } -Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(uint ucs4) Q_DECL_NOTHROW; -inline WordBreakClass wordBreakClass(QChar ch) Q_DECL_NOTHROW +Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(uint ucs4) noexcept; +inline WordBreakClass wordBreakClass(QChar ch) noexcept { return wordBreakClass(ch.unicode()); } -Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(uint ucs4) Q_DECL_NOTHROW; -inline SentenceBreakClass sentenceBreakClass(QChar ch) Q_DECL_NOTHROW +Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(uint ucs4) noexcept; +inline SentenceBreakClass sentenceBreakClass(QChar ch) noexcept { return sentenceBreakClass(ch.unicode()); } -Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(uint ucs4) Q_DECL_NOTHROW; -inline LineBreakClass lineBreakClass(QChar ch) Q_DECL_NOTHROW +Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(uint ucs4) noexcept; +inline LineBreakClass lineBreakClass(QChar ch) noexcept { return lineBreakClass(ch.unicode()); } } // namespace QUnicodeTables diff --git a/src/corelib/tools/qunicodetools.cpp b/src/corelib/tools/qunicodetools.cpp index c9d0868fef..d14118abf7 100644 --- a/src/corelib/tools/qunicodetools.cpp +++ b/src/corelib/tools/qunicodetools.cpp @@ -542,7 +542,7 @@ static const uchar breakTable[QUnicodeTables::LineBreak_SA][QUnicodeTables::Line } // namespace LB -static void getLineBreaks(const ushort *string, quint32 len, QCharAttributes *attributes) +static void getLineBreaks(const ushort *string, quint32 len, QCharAttributes *attributes, QUnicodeTools::CharAttributeOptions options) { quint32 nestart = 0; LB::NS::Class nelast = LB::NS::XX; @@ -564,6 +564,31 @@ static void getLineBreaks(const ushort *string, quint32 len, QCharAttributes *at QUnicodeTables::LineBreakClass ncls = (QUnicodeTables::LineBreakClass) prop->lineBreakClass; QUnicodeTables::LineBreakClass tcls; + if (options & QUnicodeTools::HangulLineBreakTailoring) { + if (Q_UNLIKELY((ncls >= QUnicodeTables::LineBreak_H2 + && ncls <= QUnicodeTables::LineBreak_JT) + || (ucs4 >= 0x3130 && ucs4 <= 0x318F && ncls == QUnicodeTables::LineBreak_ID)) + ) { + // LB27: use SPACE for line breaking + // "When Korean uses SPACE for line breaking, the classes in rule LB26, + // as well as characters of class ID, are often tailored to AL; see Section 8, Customization." + // In case of Korean syllables: "3130..318F HANGUL COMPATIBILITY JAMO" + ncls = QUnicodeTables::LineBreak_AL; + } else { + if (Q_UNLIKELY(ncls == QUnicodeTables::LineBreak_SA)) { + // LB1: resolve SA to AL, except of those that have Category Mn or Mc be resolved to CM + static const int test = FLAG(QChar::Mark_NonSpacing) | FLAG(QChar::Mark_SpacingCombining); + if (FLAG(prop->category) & test) + ncls = QUnicodeTables::LineBreak_CM; + } + if (Q_UNLIKELY(ncls == QUnicodeTables::LineBreak_CM)) { + // LB10: treat CM that follows SP, BK, CR, LF, NL, or ZW as AL + if (lcls == QUnicodeTables::LineBreak_ZW || lcls >= QUnicodeTables::LineBreak_SP) + ncls = QUnicodeTables::LineBreak_AL; + } + } + } + if (Q_UNLIKELY(ncls == QUnicodeTables::LineBreak_SA)) { // LB1: resolve SA to AL, except of those that have Category Mn or Mc be resolved to CM static const int test = FLAG(QChar::Mark_NonSpacing) | FLAG(QChar::Mark_SpacingCombining); @@ -716,7 +741,7 @@ Q_CORE_EXPORT void initCharAttributes(const ushort *string, int length, if (options & SentenceBreaks) getSentenceBreaks(string, length, attributes); if (options & LineBreaks) - getLineBreaks(string, length, attributes); + getLineBreaks(string, length, attributes, options); if (options & WhiteSpaces) getWhiteSpaces(string, length, attributes); diff --git a/src/corelib/tools/qunicodetools_p.h b/src/corelib/tools/qunicodetools_p.h index 5e2d56a226..ed6fcb5d65 100644 --- a/src/corelib/tools/qunicodetools_p.h +++ b/src/corelib/tools/qunicodetools_p.h @@ -88,6 +88,7 @@ enum CharAttributeOption { SentenceBreaks = 0x04, LineBreaks = 0x08, WhiteSpaces = 0x10, + HangulLineBreakTailoring = 0x20, DefaultOptionsCompat = GraphemeBreaks | LineBreaks | WhiteSpaces, // ### remove DontClearAttributes = 0x1000 diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 597e7464cb..c81af68593 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -43,6 +43,7 @@ #include <QtCore/qcontainerfwd.h> #include <QtCore/qglobal.h> #include <QtCore/qalgorithms.h> +#include <QtCore/qcontainertools_impl.h> #include <new> #include <string.h> @@ -71,13 +72,19 @@ public: #ifdef Q_COMPILER_INITIALIZER_LISTS QVarLengthArray(std::initializer_list<T> args) - : a(Prealloc), s(0), ptr(reinterpret_cast<T *>(array)) + : QVarLengthArray(args.begin(), args.end()) { - if (args.size()) - append(args.begin(), int(args.size())); } #endif + template <typename InputIterator, QtPrivate::IfIsInputIterator<InputIterator> = true> + inline QVarLengthArray(InputIterator first, InputIterator last) + : QVarLengthArray() + { + QtPrivate::reserveIfForwardIterator(this, first, last); + std::copy(first, last, std::back_inserter(*this)); + } + inline ~QVarLengthArray() { if (QTypeInfo<T>::isComplex) { T *i = ptr + s; @@ -570,7 +577,7 @@ bool operator!=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, template <typename T, int Prealloc1, int Prealloc2> bool operator<(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengthArray<T, Prealloc2> &rhs) - Q_DECL_NOEXCEPT_EXPR(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(), + noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()))) { return std::lexicographical_compare(lhs.begin(), lhs.end(), @@ -579,21 +586,21 @@ bool operator<(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengthArray<T template <typename T, int Prealloc1, int Prealloc2> inline bool operator>(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengthArray<T, Prealloc2> &rhs) - Q_DECL_NOEXCEPT_EXPR(noexcept(lhs < rhs)) + noexcept(noexcept(lhs < rhs)) { return rhs < lhs; } template <typename T, int Prealloc1, int Prealloc2> inline bool operator<=(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengthArray<T, Prealloc2> &rhs) - Q_DECL_NOEXCEPT_EXPR(noexcept(lhs < rhs)) + noexcept(noexcept(lhs < rhs)) { return !(lhs > rhs); } template <typename T, int Prealloc1, int Prealloc2> inline bool operator>=(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengthArray<T, Prealloc2> &rhs) - Q_DECL_NOEXCEPT_EXPR(noexcept(lhs < rhs)) + noexcept(noexcept(lhs < rhs)) { return !(lhs < rhs); } diff --git a/src/corelib/tools/qvarlengtharray.qdoc b/src/corelib/tools/qvarlengtharray.qdoc index bc8df82517..80769e3769 100644 --- a/src/corelib/tools/qvarlengtharray.qdoc +++ b/src/corelib/tools/qvarlengtharray.qdoc @@ -110,6 +110,14 @@ lists. */ +/*! \fn template<class T, int Prealloc> template<typename InputIterator> QVarLengthArray<T, Prealloc>::QVarLengthArray(InputIterator first, InputIterator last) + \since 5.14 + + Constructs an array with the contents in the iterator range [\a first, \a last). + + The value type of \c InputIterator must be convertible to \c T. +*/ + /*! \fn template<class T, int Prealloc> QVarLengthArray<T, Prealloc>::~QVarLengthArray() diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 988d5a9e1b..6cbf794c6c 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -45,6 +45,7 @@ #include <QtCore/qrefcount.h> #include <QtCore/qarraydata.h> #include <QtCore/qhashfunctions.h> +#include <QtCore/qcontainertools_impl.h> #include <iterator> #include <vector> @@ -65,21 +66,25 @@ class QVector Data *d; public: - inline QVector() Q_DECL_NOTHROW : d(Data::sharedNull()) { } + inline QVector() noexcept : d(Data::sharedNull()) { } explicit QVector(int size); QVector(int size, const T &t); inline QVector(const QVector<T> &v); inline ~QVector() { if (!d->ref.deref()) freeData(d); } QVector<T> &operator=(const QVector<T> &v); #if defined(Q_COMPILER_RVALUE_REFS) || defined(Q_CLANG_QDOC) - QVector(QVector<T> &&other) Q_DECL_NOTHROW : d(other.d) { other.d = Data::sharedNull(); } - QVector<T> &operator=(QVector<T> &&other) Q_DECL_NOTHROW + QVector(QVector<T> &&other) noexcept : d(other.d) { other.d = Data::sharedNull(); } + QVector<T> &operator=(QVector<T> &&other) noexcept { QVector moved(std::move(other)); swap(moved); return *this; } #endif - void swap(QVector<T> &other) Q_DECL_NOTHROW { qSwap(d, other.d); } + void swap(QVector<T> &other) noexcept { qSwap(d, other.d); } #ifdef Q_COMPILER_INITIALIZER_LISTS inline QVector(std::initializer_list<T> args); + QVector<T> &operator=(std::initializer_list<T> args); #endif + template <typename InputIterator, QtPrivate::IfIsInputIterator<InputIterator> = true> + inline QVector(InputIterator first, InputIterator last); + bool operator==(const QVector<T> &v) const; inline bool operator!=(const QVector<T> &v) const { return !(*this == v); } @@ -208,29 +213,29 @@ public: typedef std::reverse_iterator<const_iterator> const_reverse_iterator; #if !defined(QT_STRICT_ITERATORS) || defined(Q_CLANG_QDOC) inline iterator begin() { detach(); return d->begin(); } - inline const_iterator begin() const Q_DECL_NOTHROW { return d->constBegin(); } - inline const_iterator cbegin() const Q_DECL_NOTHROW { return d->constBegin(); } - inline const_iterator constBegin() const Q_DECL_NOTHROW { return d->constBegin(); } + inline const_iterator begin() const noexcept { return d->constBegin(); } + inline const_iterator cbegin() const noexcept { return d->constBegin(); } + inline const_iterator constBegin() const noexcept { return d->constBegin(); } inline iterator end() { detach(); return d->end(); } - inline const_iterator end() const Q_DECL_NOTHROW { return d->constEnd(); } - inline const_iterator cend() const Q_DECL_NOTHROW { return d->constEnd(); } - inline const_iterator constEnd() const Q_DECL_NOTHROW { return d->constEnd(); } + inline const_iterator end() const noexcept { return d->constEnd(); } + inline const_iterator cend() const noexcept { return d->constEnd(); } + inline const_iterator constEnd() const noexcept { return d->constEnd(); } #else inline iterator begin(iterator = iterator()) { detach(); return d->begin(); } - inline const_iterator begin(const_iterator = const_iterator()) const Q_DECL_NOTHROW { return d->constBegin(); } - inline const_iterator cbegin(const_iterator = const_iterator()) const Q_DECL_NOTHROW { return d->constBegin(); } - inline const_iterator constBegin(const_iterator = const_iterator()) const Q_DECL_NOTHROW { return d->constBegin(); } + inline const_iterator begin(const_iterator = const_iterator()) const noexcept { return d->constBegin(); } + inline const_iterator cbegin(const_iterator = const_iterator()) const noexcept { return d->constBegin(); } + inline const_iterator constBegin(const_iterator = const_iterator()) const noexcept { return d->constBegin(); } inline iterator end(iterator = iterator()) { detach(); return d->end(); } - inline const_iterator end(const_iterator = const_iterator()) const Q_DECL_NOTHROW { return d->constEnd(); } - inline const_iterator cend(const_iterator = const_iterator()) const Q_DECL_NOTHROW { return d->constEnd(); } - inline const_iterator constEnd(const_iterator = const_iterator()) const Q_DECL_NOTHROW { return d->constEnd(); } + inline const_iterator end(const_iterator = const_iterator()) const noexcept { return d->constEnd(); } + inline const_iterator cend(const_iterator = const_iterator()) const noexcept { return d->constEnd(); } + inline const_iterator constEnd(const_iterator = const_iterator()) const noexcept { return d->constEnd(); } #endif reverse_iterator rbegin() { return reverse_iterator(end()); } reverse_iterator rend() { return reverse_iterator(begin()); } - const_reverse_iterator rbegin() const Q_DECL_NOTHROW { return const_reverse_iterator(end()); } - const_reverse_iterator rend() const Q_DECL_NOTHROW { return const_reverse_iterator(begin()); } - const_reverse_iterator crbegin() const Q_DECL_NOTHROW { return const_reverse_iterator(end()); } - const_reverse_iterator crend() const Q_DECL_NOTHROW { return const_reverse_iterator(begin()); } + const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } + const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } + const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } iterator insert(iterator before, int n, const T &x); inline iterator insert(iterator before, const T &x) { return insert(before, 1, x); } inline iterator insert(iterator before, T &&x); @@ -542,10 +547,28 @@ QVector<T>::QVector(std::initializer_list<T> args) d = Data::sharedNull(); } } + +template <typename T> +QVector<T> &QVector<T>::operator=(std::initializer_list<T> args) +{ + QVector<T> tmp(args); + tmp.swap(*this); + return *this; +} + # if defined(Q_CC_MSVC) QT_WARNING_POP # endif // Q_CC_MSVC -#endif // Q_COMPILER_INITALIZER_LISTS +#endif // Q_COMPILER_INITIALIZER_LISTS + +template <typename T> +template <typename InputIterator, QtPrivate::IfIsInputIterator<InputIterator>> +QVector<T>::QVector(InputIterator first, InputIterator last) + : QVector() +{ + QtPrivate::reserveIfForwardIterator(this, first, last); + std::copy(first, last, std::back_inserter(*this)); +} template <typename T> void QVector<T>::freeData(Data *x) @@ -763,9 +786,9 @@ void QVector<T>::append(const T &t) realloc(isTooSmall ? d->size + 1 : d->alloc, opt); if (QTypeInfo<T>::isComplex) - new (d->end()) T(qMove(copy)); + new (d->end()) T(std::move(copy)); else - *d->end() = qMove(copy); + *d->end() = std::move(copy); } else { if (QTypeInfo<T>::isComplex) @@ -1052,14 +1075,14 @@ Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(Vector) template <typename T> uint qHash(const QVector<T> &key, uint seed = 0) - Q_DECL_NOEXCEPT_EXPR(noexcept(qHashRange(key.cbegin(), key.cend(), seed))) + noexcept(noexcept(qHashRange(key.cbegin(), key.cend(), seed))) { return qHashRange(key.cbegin(), key.cend(), seed); } template <typename T> bool operator<(const QVector<T> &lhs, const QVector<T> &rhs) - Q_DECL_NOEXCEPT_EXPR(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(), + noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()))) { return std::lexicographical_compare(lhs.begin(), lhs.end(), @@ -1068,21 +1091,21 @@ bool operator<(const QVector<T> &lhs, const QVector<T> &rhs) template <typename T> inline bool operator>(const QVector<T> &lhs, const QVector<T> &rhs) - Q_DECL_NOEXCEPT_EXPR(noexcept(lhs < rhs)) + noexcept(noexcept(lhs < rhs)) { return rhs < lhs; } template <typename T> inline bool operator<=(const QVector<T> &lhs, const QVector<T> &rhs) - Q_DECL_NOEXCEPT_EXPR(noexcept(lhs < rhs)) + noexcept(noexcept(lhs < rhs)) { return !(lhs > rhs); } template <typename T> inline bool operator>=(const QVector<T> &lhs, const QVector<T> &rhs) - Q_DECL_NOEXCEPT_EXPR(noexcept(lhs < rhs)) + noexcept(noexcept(lhs < rhs)) { return !(lhs < rhs); } diff --git a/src/corelib/tools/qvector.qdoc b/src/corelib/tools/qvector.qdoc index 75b17a4207..cb47d36356 100644 --- a/src/corelib/tools/qvector.qdoc +++ b/src/corelib/tools/qvector.qdoc @@ -243,6 +243,13 @@ lists. */ +/*! \fn template <typename T> template<typename InputIterator> QVector<T>::QVector(InputIterator first, InputIterator last) + \since 5.14 + + Constructs a vector with the contents in the iterator range [\a first, \a last). + + The value type of \c InputIterator must be convertible to \c T. +*/ /*! \fn template <typename T> QVector<T>::~QVector() @@ -263,6 +270,17 @@ \since 5.2 */ +/*! + \fn template <typename T> QVector<T> &QVector<T>::operator=(std::initializer_list<T> args) + + Assigns the collection of values in \a args to this QVector instance. + + This operator is only enabled if the compiler supports C++11 initializer + lists. + + \since 5.14 +*/ + /*! \fn template <typename T> void QVector<T>::swap(QVector<T> &other) \since 4.8 diff --git a/src/corelib/tools/qversionnumber.cpp b/src/corelib/tools/qversionnumber.cpp index b96e48252e..58e3c15560 100644 --- a/src/corelib/tools/qversionnumber.cpp +++ b/src/corelib/tools/qversionnumber.cpp @@ -235,7 +235,7 @@ QVersionNumber QVersionNumber::normalized() const \sa commonPrefix() */ -bool QVersionNumber::isPrefixOf(const QVersionNumber &other) const Q_DECL_NOTHROW +bool QVersionNumber::isPrefixOf(const QVersionNumber &other) const noexcept { if (segmentCount() > other.segmentCount()) return false; @@ -259,7 +259,7 @@ bool QVersionNumber::isPrefixOf(const QVersionNumber &other) const Q_DECL_NOTHRO \snippet qversionnumber/main.cpp 1 */ -int QVersionNumber::compare(const QVersionNumber &v1, const QVersionNumber &v2) Q_DECL_NOTHROW +int QVersionNumber::compare(const QVersionNumber &v1, const QVersionNumber &v2) noexcept { int commonlen; @@ -482,7 +482,7 @@ QVersionNumber QVersionNumber::fromString(QLatin1String string, int *suffixIndex if (suffixIndex) *suffixIndex = int(lastGoodEnd - string.begin()); - return QVersionNumber(qMove(seg)); + return QVersionNumber(std::move(seg)); } void QVersionNumber::SegmentStorage::setVector(int len, int maj, int min, int mic) diff --git a/src/corelib/tools/qversionnumber.h b/src/corelib/tools/qversionnumber.h index 1bfb4aab39..d51947c091 100644 --- a/src/corelib/tools/qversionnumber.h +++ b/src/corelib/tools/qversionnumber.h @@ -87,7 +87,7 @@ class QVersionNumber }; // set the InlineSegmentMarker and set length to zero - SegmentStorage() Q_DECL_NOTHROW : dummy(1) {} + SegmentStorage() noexcept : dummy(1) {} SegmentStorage(const QVector<int> &seg) { @@ -120,13 +120,13 @@ class QVersionNumber } #ifdef Q_COMPILER_RVALUE_REFS - SegmentStorage(SegmentStorage &&other) Q_DECL_NOTHROW + SegmentStorage(SegmentStorage &&other) noexcept : dummy(other.dummy) { other.dummy = 1; } - SegmentStorage &operator=(SegmentStorage &&other) Q_DECL_NOTHROW + SegmentStorage &operator=(SegmentStorage &&other) noexcept { qSwap(dummy, other.dummy); return *this; @@ -153,10 +153,10 @@ class QVersionNumber ~SegmentStorage() { if (isUsingPointer()) delete pointer_segments; } - bool isUsingPointer() const Q_DECL_NOTHROW + bool isUsingPointer() const noexcept { return (inline_segments[InlineSegmentMarker] & 1) == 0; } - int size() const Q_DECL_NOTHROW + int size() const noexcept { return isUsingPointer() ? pointer_segments->size() : (inline_segments[InlineSegmentMarker] >> 1); } void setInlineSize(int len) @@ -218,7 +218,7 @@ class QVersionNumber } m_segments; public: - inline QVersionNumber() Q_DECL_NOTHROW + inline QVersionNumber() noexcept : m_segments() {} inline explicit QVersionNumber(const QVector<int> &seg) @@ -248,34 +248,34 @@ public: inline explicit QVersionNumber(int maj, int min, int mic) { m_segments.setSegments(3, maj, min, mic); } - Q_REQUIRED_RESULT inline bool isNull() const Q_DECL_NOTHROW + Q_REQUIRED_RESULT inline bool isNull() const noexcept { return segmentCount() == 0; } - Q_REQUIRED_RESULT inline bool isNormalized() const Q_DECL_NOTHROW + Q_REQUIRED_RESULT inline bool isNormalized() const noexcept { return isNull() || segmentAt(segmentCount() - 1) != 0; } - Q_REQUIRED_RESULT inline int majorVersion() const Q_DECL_NOTHROW + Q_REQUIRED_RESULT inline int majorVersion() const noexcept { return segmentAt(0); } - Q_REQUIRED_RESULT inline int minorVersion() const Q_DECL_NOTHROW + Q_REQUIRED_RESULT inline int minorVersion() const noexcept { return segmentAt(1); } - Q_REQUIRED_RESULT inline int microVersion() const Q_DECL_NOTHROW + Q_REQUIRED_RESULT inline int microVersion() const noexcept { return segmentAt(2); } Q_REQUIRED_RESULT Q_CORE_EXPORT QVersionNumber normalized() const; Q_REQUIRED_RESULT Q_CORE_EXPORT QVector<int> segments() const; - Q_REQUIRED_RESULT inline int segmentAt(int index) const Q_DECL_NOTHROW + Q_REQUIRED_RESULT inline int segmentAt(int index) const noexcept { return (m_segments.size() > index) ? m_segments.at(index) : 0; } - Q_REQUIRED_RESULT inline int segmentCount() const Q_DECL_NOTHROW + Q_REQUIRED_RESULT inline int segmentCount() const noexcept { return m_segments.size(); } - Q_REQUIRED_RESULT Q_CORE_EXPORT bool isPrefixOf(const QVersionNumber &other) const Q_DECL_NOTHROW; + Q_REQUIRED_RESULT Q_CORE_EXPORT bool isPrefixOf(const QVersionNumber &other) const noexcept; - Q_REQUIRED_RESULT Q_CORE_EXPORT static int compare(const QVersionNumber &v1, const QVersionNumber &v2) Q_DECL_NOTHROW; + Q_REQUIRED_RESULT Q_CORE_EXPORT static int compare(const QVersionNumber &v1, const QVersionNumber &v2) noexcept; Q_REQUIRED_RESULT Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber commonPrefix(const QVersionNumber &v1, const QVersionNumber &v2); @@ -299,22 +299,22 @@ Q_DECLARE_TYPEINFO(QVersionNumber, Q_MOVABLE_TYPE); Q_CORE_EXPORT QDebug operator<<(QDebug, const QVersionNumber &version); #endif -Q_REQUIRED_RESULT inline bool operator> (const QVersionNumber &lhs, const QVersionNumber &rhs) Q_DECL_NOTHROW +Q_REQUIRED_RESULT inline bool operator> (const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept { return QVersionNumber::compare(lhs, rhs) > 0; } -Q_REQUIRED_RESULT inline bool operator>=(const QVersionNumber &lhs, const QVersionNumber &rhs) Q_DECL_NOTHROW +Q_REQUIRED_RESULT inline bool operator>=(const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept { return QVersionNumber::compare(lhs, rhs) >= 0; } -Q_REQUIRED_RESULT inline bool operator< (const QVersionNumber &lhs, const QVersionNumber &rhs) Q_DECL_NOTHROW +Q_REQUIRED_RESULT inline bool operator< (const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept { return QVersionNumber::compare(lhs, rhs) < 0; } -Q_REQUIRED_RESULT inline bool operator<=(const QVersionNumber &lhs, const QVersionNumber &rhs) Q_DECL_NOTHROW +Q_REQUIRED_RESULT inline bool operator<=(const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept { return QVersionNumber::compare(lhs, rhs) <= 0; } -Q_REQUIRED_RESULT inline bool operator==(const QVersionNumber &lhs, const QVersionNumber &rhs) Q_DECL_NOTHROW +Q_REQUIRED_RESULT inline bool operator==(const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept { return QVersionNumber::compare(lhs, rhs) == 0; } -Q_REQUIRED_RESULT inline bool operator!=(const QVersionNumber &lhs, const QVersionNumber &rhs) Q_DECL_NOTHROW +Q_REQUIRED_RESULT inline bool operator!=(const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept { return QVersionNumber::compare(lhs, rhs) != 0; } QT_END_NAMESPACE diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index 995bab694e..5dcb6c9ee0 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -18,6 +18,7 @@ HEADERS += \ tools/qcollator.h \ tools/qcollator_p.h \ tools/qcontainerfwd.h \ + tools/qcontainertools_impl.h \ tools/qcryptographichash.h \ tools/qdatetime.h \ tools/qdatetime_p.h \ |