diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-10-11 20:57:26 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-10-14 20:58:51 +0200 |
commit | a095a999a3904a53e78857759a79a0e8c7d8a474 (patch) | |
tree | cffb4b7a44eff0355d2852c9d9db41aa3a36e988 | |
parent | a8dc2a5b6dda85d63dd8f9f7570069df008941c6 (diff) |
Long live Q_IMPLICIT!
C++20 will give us explicit(bool). While we can't use it just yet
in its full potential, we can introduce a macro to start marking
our implicit conversions (aka `explicit(false)`), removing the need
for /* implicit */-like comments.
Port a few usages to it.
Change-Id: I336d5e4c8d51d8329627900d1059e59062c5cafd
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r-- | src/corelib/global/qglobal.h | 6 | ||||
-rw-r--r-- | src/corelib/global/qnamespace.h | 4 | ||||
-rw-r--r-- | src/corelib/kernel/qsocketnotifier.h | 6 | ||||
-rw-r--r-- | src/corelib/text/qchar.h | 24 | ||||
-rw-r--r-- | src/corelib/tools/qmap.h | 4 |
5 files changed, 25 insertions, 19 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index b22e2f526a..3e32a4815a 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1042,6 +1042,12 @@ constexpr T qExchange(T &t, U &&newValue) return old; } +#ifdef __cpp_conditional_explicit +#define Q_IMPLICIT explicit(false) +#else +#define Q_IMPLICIT +#endif + #ifndef QT_NO_FOREACH namespace QtPrivate { diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index 2cbe482fd4..d19f50512a 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -1873,7 +1873,7 @@ class QKeyCombination int combination; public: - constexpr /* implicit */ QKeyCombination(Qt::Key key = Qt::Key_unknown) noexcept + constexpr Q_IMPLICIT QKeyCombination(Qt::Key key = Qt::Key_unknown) noexcept : combination(int(key)) {} @@ -1909,7 +1909,7 @@ public: #if QT_DEPRECATED_SINCE(6, 0) QT_DEPRECATED_VERSION_X(6, 0, "Use QKeyCombination instead of int") - constexpr /* implicit */ operator int() const noexcept + constexpr Q_IMPLICIT operator int() const noexcept { return combination; } diff --git a/src/corelib/kernel/qsocketnotifier.h b/src/corelib/kernel/qsocketnotifier.h index 528f58a1e1..b8a5cc542a 100644 --- a/src/corelib/kernel/qsocketnotifier.h +++ b/src/corelib/kernel/qsocketnotifier.h @@ -102,14 +102,14 @@ public: #define Q_DECL_CONSTEXPR_NOT_WIN Q_DECL_CONSTEXPR #endif - /* implicit */ Q_DECL_CONSTEXPR_NOT_WIN + Q_DECL_CONSTEXPR_NOT_WIN Q_IMPLICIT QSocketDescriptor(DescriptorType descriptor = DescriptorType(-1)) noexcept : sockfd(descriptor) { } #if defined(Q_OS_WIN) || defined(Q_QDOC) - /* implicit */ QSocketDescriptor(qintptr desc) noexcept : sockfd(DescriptorType(desc)) {} - operator qintptr() const noexcept { return qintptr(sockfd); } + Q_IMPLICIT QSocketDescriptor(qintptr desc) noexcept : sockfd(DescriptorType(desc)) {} + Q_IMPLICIT operator qintptr() const noexcept { return qintptr(sockfd); } Q_DECL_CONSTEXPR Qt::HANDLE winHandle() const noexcept { return sockfd; } #endif Q_DECL_CONSTEXPR operator DescriptorType() const noexcept { return sockfd; } diff --git a/src/corelib/text/qchar.h b/src/corelib/text/qchar.h index 5d807d97a3..96a99aa1d3 100644 --- a/src/corelib/text/qchar.h +++ b/src/corelib/text/qchar.h @@ -94,28 +94,28 @@ public: LastValidCodePoint = 0x10ffff }; - constexpr QChar() noexcept : ucs(0) {} - constexpr QChar(ushort rc) noexcept : ucs(rc) {} - constexpr QChar(uchar c, uchar r) noexcept : ucs(char16_t((r << 8) | c)) {} - constexpr QChar(short rc) noexcept : ucs(char16_t(rc)) {} - constexpr QChar(uint rc) noexcept : ucs(char16_t(rc & 0xffff)) {} - constexpr QChar(int rc) noexcept : ucs(char16_t(rc & 0xffff)) {} - constexpr QChar(SpecialCharacter s) noexcept : ucs(char16_t(s)) {} // implicit - constexpr QChar(QLatin1Char ch) noexcept : ucs(ch.unicode()) {} // implicit - constexpr QChar(char16_t ch) noexcept : ucs(ch) {} // implicit + constexpr Q_IMPLICIT QChar() noexcept : ucs(0) {} + constexpr Q_IMPLICIT QChar(ushort rc) noexcept : ucs(rc) {} + constexpr Q_IMPLICIT QChar(uchar c, uchar r) noexcept : ucs(char16_t((r << 8) | c)) {} + constexpr Q_IMPLICIT QChar(short rc) noexcept : ucs(char16_t(rc)) {} + constexpr Q_IMPLICIT QChar(uint rc) noexcept : ucs(char16_t(rc & 0xffff)) {} + constexpr Q_IMPLICIT QChar(int rc) noexcept : ucs(char16_t(rc & 0xffff)) {} + constexpr Q_IMPLICIT QChar(SpecialCharacter s) noexcept : ucs(char16_t(s)) {} // implicit + constexpr Q_IMPLICIT QChar(QLatin1Char ch) noexcept : ucs(ch.unicode()) {} // implicit + constexpr Q_IMPLICIT QChar(char16_t ch) noexcept : ucs(ch) {} // implicit #if defined(Q_OS_WIN) static_assert(sizeof(wchar_t) == sizeof(char16_t)); #endif #if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC) # if !defined(_WCHAR_T_DEFINED) || defined(_NATIVE_WCHAR_T_DEFINED) - constexpr QChar(wchar_t ch) noexcept : ucs(char16_t(ch)) {} // implicit + constexpr Q_IMPLICIT QChar(wchar_t ch) noexcept : ucs(char16_t(ch)) {} // implicit # endif #endif #ifndef QT_NO_CAST_FROM_ASCII - QT_ASCII_CAST_WARN constexpr QChar(char c) noexcept : ucs(uchar(c)) { } + QT_ASCII_CAST_WARN constexpr Q_IMPLICIT QChar(char c) noexcept : ucs(uchar(c)) { } #ifndef QT_RESTRICTED_CAST_FROM_ASCII - QT_ASCII_CAST_WARN constexpr QChar(uchar c) noexcept : ucs(c) { } + QT_ASCII_CAST_WARN constexpr Q_IMPLICIT QChar(uchar c) noexcept : ucs(c) { } #endif #endif diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 24d82fa22d..f7915b149c 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -492,7 +492,7 @@ public: typedef const T &reference; const_iterator() = default; - /* implicit */ const_iterator(const iterator &o) { i = o.i; } + Q_IMPLICIT const_iterator(const iterator &o) { i = o.i; } const Key &key() const { return i->first; } const T &value() const { return i->second; } @@ -1116,7 +1116,7 @@ public: typedef const T &reference; const_iterator() = default; - /* implicit */ const_iterator(const iterator &o) { i = o.i; } + Q_IMPLICIT const_iterator(const iterator &o) { i = o.i; } const Key &key() const { return i->first; } const T &value() const { return i->second; } |