From cce12a27fb3d9becef99317721ec9c2a54b4fb87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 6 Jun 2024 16:29:51 +0200 Subject: [PATCH] Ignore Clang's -Wdeprecated-literal-operator until we can drop GCC 4.8. And also remove the other space, to be consistent with Doxygen links, what Corrade uses, and have the literals easier to search for. --- src/Magnum/Math/Angle.h | 36 ++++++++++++++++++++++++++++++++---- src/Magnum/Math/Color.h | 30 ++++++++++++++++++++++-------- src/Magnum/Math/Half.h | 16 +++++++++++++++- src/Magnum/Math/Time.h | 22 ++++++++++++++++++---- 4 files changed, 87 insertions(+), 17 deletions(-) diff --git a/src/Magnum/Math/Angle.h b/src/Magnum/Math/Angle.h index 91a9cf1ba..5d0ce31b9 100644 --- a/src/Magnum/Math/Angle.h +++ b/src/Magnum/Math/Angle.h @@ -157,6 +157,17 @@ namespace Literals { #endif namespace AngleLiterals { +/* According to https://wg21.link/CWG2521, space between "" and literal name is + deprecated because _Uppercase or __double names could be treated as reserved + depending on whether the space was present or not, and whitespace is not + load-bearing in any other contexts. Clang 17+ adds an off-by-default warning + for this; GCC 4.8 however *requires* the space there, so until GCC 4.8 + support is dropped, we suppress this warning instead of removing the + space. */ +#if defined(CORRADE_TARGET_CLANG) && __clang_major__ >= 17 +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-literal-operator" +#endif /** @relatesalso Magnum::Math::Deg @brief Double-precision degree value literal @@ -167,7 +178,7 @@ Example usage: @see @link operator""_degf() @endlink, @link operator""_rad() @endlink @m_keywords{_deg deg} */ -constexpr Deg operator "" _deg(long double value) { return Deg(Double(value)); } +constexpr Deg operator"" _deg(long double value) { return Deg(Double(value)); } /** @relatesalso Magnum::Math::Deg @brief Single-precision degree value literal @@ -179,7 +190,10 @@ Example usage: @see @link operator""_deg() @endlink, @link operator""_radf() @endlink @m_keywords{_degf degf} */ -constexpr Deg operator "" _degf(long double value) { return Deg(Float(value)); } +constexpr Deg operator"" _degf(long double value) { return Deg(Float(value)); } +#if defined(CORRADE_TARGET_CLANG) && __clang_major__ >= 17 +#pragma clang diagnostic pop +#endif }} @@ -246,6 +260,17 @@ namespace Literals { #endif namespace AngleLiterals { +/* According to https://wg21.link/CWG2521, space between "" and literal name is + deprecated because _Uppercase or __double names could be treated as reserved + depending on whether the space was present or not, and whitespace is not + load-bearing in any other contexts. Clang 17+ adds an off-by-default warning + for this; GCC 4.8 however *requires* the space there, so until GCC 4.8 + support is dropped, we suppress this warning instead of removing the + space. */ +#if defined(CORRADE_TARGET_CLANG) && __clang_major__ >= 17 +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-literal-operator" +#endif /** @relatesalso Magnum::Math::Rad @brief Double-precision radian value literal @@ -253,7 +278,7 @@ See @link operator""_deg() @endlink for more information. @see @link operator""_radf() @endlink @m_keywords{_rad rad} */ -constexpr Rad operator "" _rad(long double value) { return Rad(Double(value)); } +constexpr Rad operator"" _rad(long double value) { return Rad(Double(value)); } /** @relatesalso Magnum::Math::Rad @brief Single-precision radian value literal @@ -262,7 +287,10 @@ See @link operator""_degf() @endlink for more information. @see @link operator""_rad() @endlink @m_keywords{_radf radf} */ -constexpr Rad operator "" _radf(long double value) { return Rad(Float(value)); } +constexpr Rad operator"" _radf(long double value) { return Rad(Float(value)); } +#if defined(CORRADE_TARGET_CLANG) && __clang_major__ >= 17 +#pragma clang diagnostic pop +#endif }} diff --git a/src/Magnum/Math/Color.h b/src/Magnum/Math/Color.h index 99f4b8f1d..83c21d581 100644 --- a/src/Magnum/Math/Color.h +++ b/src/Magnum/Math/Color.h @@ -1325,6 +1325,17 @@ namespace Literals { #endif namespace ColorLiterals { +/* According to https://wg21.link/CWG2521, space between "" and literal name is + deprecated because _Uppercase or __double names could be treated as reserved + depending on whether the space was present or not, and whitespace is not + load-bearing in any other contexts. Clang 17+ adds an off-by-default warning + for this; GCC 4.8 however *requires* the space there, so until GCC 4.8 + support is dropped, we suppress this warning instead of removing the + space. */ +#if defined(CORRADE_TARGET_CLANG) && __clang_major__ >= 17 +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-literal-operator" +#endif /** @relatesalso Magnum::Math::Color3 @brief 8bit-per-channel linear RGB literal @@ -1340,7 +1351,7 @@ Unpacks the literal into three 8-bit values. Example usage: @see @link operator""_rgba() @endlink, @link operator""_rgbf() @endlink @m_keywords{_rgb rgb} */ -constexpr Color3 operator "" _rgb(unsigned long long value) { +constexpr Color3 operator"" _rgb(unsigned long long value) { return {UnsignedByte(value >> 16), UnsignedByte(value >> 8), UnsignedByte(value)}; } @@ -1366,7 +1377,7 @@ RGB. Use this literal to document that given value is in sRGB. Example usage: */ /* Output is a Vector3 to hint that it doesn't have any (additive, multiplicative) semantics of a linear RGB color */ -constexpr Vector3 operator "" _srgb(unsigned long long value) { +constexpr Vector3 operator"" _srgb(unsigned long long value) { return {UnsignedByte(value >> 16), UnsignedByte(value >> 8), UnsignedByte(value)}; } @@ -1385,7 +1396,7 @@ Unpacks the literal into four 8-bit values. Example usage: @see @link operator""_rgb() @endlink, @link operator""_rgbaf() @endlink @m_keywords{_rgba rgba} */ -constexpr Color4 operator "" _rgba(unsigned long long value) { +constexpr Color4 operator"" _rgba(unsigned long long value) { return {UnsignedByte(value >> 24), UnsignedByte(value >> 16), UnsignedByte(value >> 8), UnsignedByte(value)}; } @@ -1412,7 +1423,7 @@ usage: */ /* Output is a Vector3 to hint that it doesn't have any (additive, multiplicative) semantics of a linear RGB color */ -constexpr Vector4 operator "" _srgba(unsigned long long value) { +constexpr Vector4 operator"" _srgba(unsigned long long value) { return {UnsignedByte(value >> 24), UnsignedByte(value >> 16), UnsignedByte(value >> 8), UnsignedByte(value)}; } @@ -1432,7 +1443,7 @@ Example usage: @see @link operator""_rgbaf() @endlink, @link operator""_rgb() @endlink @m_keywords{_rgbf rgbf} */ -constexpr Color3 operator "" _rgbf(unsigned long long value) { +constexpr Color3 operator"" _rgbf(unsigned long long value) { return {((value >> 16) & 0xff)/255.0f, ((value >> 8) & 0xff)/255.0f, ((value >> 0) & 0xff)/255.0f}; @@ -1449,7 +1460,7 @@ Calls @ref Color3::fromSrgbInt() on the literal value. Example usage: @link operator""_rgbf() @endlink @m_keywords{_srgbf srgbf} */ -inline Color3 operator "" _srgbf(unsigned long long value) { +inline Color3 operator"" _srgbf(unsigned long long value) { return Color3::fromSrgbInt(UnsignedInt(value)); } @@ -1469,7 +1480,7 @@ Example usage: @see @link operator""_rgbf() @endlink, @link operator""_rgba() @endlink @m_keywords{_rgbaf rgbaf} */ -constexpr Color4 operator "" _rgbaf(unsigned long long value) { +constexpr Color4 operator"" _rgbaf(unsigned long long value) { return {((value >> 24) & 0xff)/255.0f, ((value >> 16) & 0xff)/255.0f, ((value >> 8) & 0xff)/255.0f, @@ -1487,9 +1498,12 @@ Calls @ref Color4::fromSrgbAlphaInt() on the literal value. Example usage: @link operator""_rgbaf() @endlink @m_keywords{_srgbaf srgbaf} */ -inline Color4 operator "" _srgbaf(unsigned long long value) { +inline Color4 operator"" _srgbaf(unsigned long long value) { return Color4::fromSrgbAlphaInt(UnsignedInt(value)); } +#if defined(CORRADE_TARGET_CLANG) && __clang_major__ >= 17 +#pragma clang diagnostic pop +#endif }} diff --git a/src/Magnum/Math/Half.h b/src/Magnum/Math/Half.h index b265b983d..89dd62ae9 100644 --- a/src/Magnum/Math/Half.h +++ b/src/Magnum/Math/Half.h @@ -183,12 +183,26 @@ namespace Literals { #endif namespace HalfLiterals { +/* According to https://wg21.link/CWG2521, space between "" and literal name is + deprecated because _Uppercase or __double names could be treated as reserved + depending on whether the space was present or not, and whitespace is not + load-bearing in any other contexts. Clang 17+ adds an off-by-default warning + for this; GCC 4.8 however *requires* the space there, so until GCC 4.8 + support is dropped, we suppress this warning instead of removing the + space. */ +#if defined(CORRADE_TARGET_CLANG) && __clang_major__ >= 17 +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-literal-operator" +#endif /** @relatesalso Magnum::Math::Half @brief Half-float literal See @ref Half for more information. */ -inline Half operator "" _h(long double value) { return Half(Float(value)); } +inline Half operator"" _h(long double value) { return Half(Float(value)); } +#if defined(CORRADE_TARGET_CLANG) && __clang_major__ >= 17 +#pragma clang diagnostic pop +#endif }} diff --git a/src/Magnum/Math/Time.h b/src/Magnum/Math/Time.h index 4ce838d1c..b87724c34 100644 --- a/src/Magnum/Math/Time.h +++ b/src/Magnum/Math/Time.h @@ -288,6 +288,17 @@ namespace Literals { everything already. Seeing 15.0_sec in unfamiliar code doesn't feel ambiguous, seeing 127_s or 0.5_h definitely does. */ +/* According to https://wg21.link/CWG2521, space between "" and literal name is + deprecated because _Uppercase or __double names could be treated as reserved + depending on whether the space was present or not, and whitespace is not + load-bearing in any other contexts. Clang 17+ adds an off-by-default warning + for this; GCC 4.8 however *requires* the space there, so until GCC 4.8 + support is dropped, we suppress this warning instead of removing the + space. */ +#if defined(CORRADE_TARGET_CLANG) && __clang_major__ >= 17 +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-literal-operator" +#endif /** @relatesalso Magnum::Math::Nanoseconds @brief Nanosecond value literal @m_since_latest @@ -302,7 +313,7 @@ fractions of nanoseconds. Usage example: @link operator""_sec() @endlink @m_keywords{_nsec nsec} */ -constexpr Nanoseconds operator "" _nsec(unsigned long long value) { +constexpr Nanoseconds operator"" _nsec(unsigned long long value) { return Nanoseconds{Long(value)}; } @@ -325,7 +336,7 @@ precision on a range of roughly ±8 seconds. For example: @ref CORRADE_LONG_DOUBLE_SAME_AS_DOUBLE @m_keywords{_usec usec} */ -constexpr Nanoseconds operator "" _usec(long double value) { +constexpr Nanoseconds operator"" _usec(long double value) { return Nanoseconds{Long(value*1000.0l)}; } @@ -348,7 +359,7 @@ precision on a range of roughly ±2 hours. For example: @ref CORRADE_LONG_DOUBLE_SAME_AS_DOUBLE @m_keywords{_msec msec} */ -constexpr Nanoseconds operator "" _msec(long double value) { +constexpr Nanoseconds operator"" _msec(long double value) { return Nanoseconds{Long(value*1000000.0l)}; } @@ -371,9 +382,12 @@ precision on a range of roughly ±2 hours. For example: @ref CORRADE_LONG_DOUBLE_SAME_AS_DOUBLE @m_keywords{_sec sec} */ -constexpr Nanoseconds operator "" _sec(long double value) { +constexpr Nanoseconds operator"" _sec(long double value) { return Nanoseconds{Long(value*1000000000.0l)}; } +#if defined(CORRADE_TARGET_CLANG) && __clang_major__ >= 17 +#pragma clang diagnostic pop +#endif }}