diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-08-19 19:11:37 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-09-06 18:31:43 +0200 |
commit | 68198de4dbe71ae97dc733606871f51bde804c1e (patch) | |
tree | df68d428265f876367c7cd54d5e2c14f007c1964 /src/corelib/global | |
parent | d3ff95dcb84861e8f42b480910d822b4ca8715b1 (diff) |
Use C++17 [[maybe_unused]]
In some places needs to be ordered before const/constexpr though.
Change-Id: I57a521ac0ad22b5a018761c4d52befbef69d64c0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/global')
-rw-r--r-- | src/corelib/global/qcompilerdetection.h | 5 | ||||
-rw-r--r-- | src/corelib/global/qglobal.h | 20 | ||||
-rw-r--r-- | src/corelib/global/qnamespace.h | 2 |
3 files changed, 16 insertions, 11 deletions
diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index a287bebc26..f88640dd81 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -1135,6 +1135,11 @@ # define Q_REQUIRED_RESULT [[nodiscard]] #endif +#if __has_cpp_attribute(maybe_unused) +# undef Q_DECL_UNUSED +# define Q_DECL_UNUSED [[maybe_unused]] +#endif + #if defined(__cpp_enumerator_attributes) && __cpp_enumerator_attributes >= 201411 #if defined(Q_CC_MSVC) // Can't mark enum values as __declspec(deprecated) with MSVC, also can't move diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 642ea2b1f3..d32f1b420c 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -380,7 +380,7 @@ typedef double qreal; // A tag to help mark stuff deprecated (cf. QStringViewLiteral) namespace QtPrivate { enum class Deprecated_t {}; -constexpr Q_DECL_UNUSED Deprecated_t Deprecated = {}; +Q_DECL_UNUSED constexpr Deprecated_t Deprecated = {}; } #endif @@ -868,22 +868,22 @@ typedef void (*QFunctionPointer)(); # define Q_UNIMPLEMENTED() qWarning("Unimplemented code.") #endif -Q_REQUIRED_RESULT constexpr static inline Q_DECL_UNUSED bool qFuzzyCompare(double p1, double p2) +Q_REQUIRED_RESULT Q_DECL_UNUSED constexpr static inline bool qFuzzyCompare(double p1, double p2) { return (qAbs(p1 - p2) * 1000000000000. <= qMin(qAbs(p1), qAbs(p2))); } -Q_REQUIRED_RESULT constexpr static inline Q_DECL_UNUSED bool qFuzzyCompare(float p1, float p2) +Q_REQUIRED_RESULT Q_DECL_UNUSED constexpr static inline bool qFuzzyCompare(float p1, float p2) { return (qAbs(p1 - p2) * 100000.f <= qMin(qAbs(p1), qAbs(p2))); } -Q_REQUIRED_RESULT constexpr static inline Q_DECL_UNUSED bool qFuzzyIsNull(double d) +Q_REQUIRED_RESULT Q_DECL_UNUSED constexpr static inline bool qFuzzyIsNull(double d) { return qAbs(d) <= 0.000000000001; } -Q_REQUIRED_RESULT constexpr static inline Q_DECL_UNUSED bool qFuzzyIsNull(float f) +Q_REQUIRED_RESULT Q_DECL_UNUSED constexpr static inline bool qFuzzyIsNull(float f) { return qAbs(f) <= 0.00001f; } @@ -891,12 +891,12 @@ Q_REQUIRED_RESULT constexpr static inline Q_DECL_UNUSED bool qFuzzyIsNull(float QT_WARNING_PUSH QT_WARNING_DISABLE_FLOAT_COMPARE -Q_REQUIRED_RESULT constexpr static inline Q_DECL_UNUSED bool qIsNull(double d) noexcept +Q_REQUIRED_RESULT Q_DECL_UNUSED constexpr static inline bool qIsNull(double d) noexcept { return d == 0.0; } -Q_REQUIRED_RESULT constexpr static inline Q_DECL_UNUSED bool qIsNull(float f) noexcept +Q_REQUIRED_RESULT Q_DECL_UNUSED constexpr static inline bool qIsNull(float f) noexcept { return f == 0.0f; } @@ -1219,9 +1219,9 @@ struct QOverload : QConstOverload<Args...>, QNonConstOverload<Args...> }; #if defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304 // C++14 -template <typename... Args> constexpr Q_DECL_UNUSED QOverload<Args...> qOverload = {}; -template <typename... Args> constexpr Q_DECL_UNUSED QConstOverload<Args...> qConstOverload = {}; -template <typename... Args> constexpr Q_DECL_UNUSED QNonConstOverload<Args...> qNonConstOverload = {}; +template <typename... Args> Q_DECL_UNUSED constexpr QOverload<Args...> qOverload = {}; +template <typename... Args> Q_DECL_UNUSED constexpr QConstOverload<Args...> qConstOverload = {}; +template <typename... Args> Q_DECL_UNUSED constexpr QNonConstOverload<Args...> qNonConstOverload = {}; #endif #endif diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index 0c4b4fc8bf..6edd84534b 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -1606,7 +1606,7 @@ namespace Qt { enum class Initialization { Uninitialized }; - static constexpr Q_DECL_UNUSED Initialization Uninitialized = Initialization::Uninitialized; + Q_DECL_UNUSED static constexpr Initialization Uninitialized = Initialization::Uninitialized; #else enum Initialization { Uninitialized |