From d29a10c18933af05bd39a1c8ac968d9b7d565972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Wed, 21 Sep 2022 17:29:31 +0200 Subject: [PATCH] QFlags: Mark the operators declared in macro maybe_unused Because, when used in a .cpp file, the compiler can verify that they are. With warnings-are-errors this breaks compilation for me on windows with clang++. Change-Id: Ib29c3b0b485be2c7d7cf6f1fa4541cac8fe32708 Reviewed-by: Marc Mutz Reviewed-by: Thiago Macieira (cherry picked from commit 2c6c76374eeb649f40787c840f9b4b38e5d48ccb) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/global/qflags.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/corelib/global/qflags.h b/src/corelib/global/qflags.h index 92bcb0df9c0..c791c26ac1f 100644 --- a/src/corelib/global/qflags.h +++ b/src/corelib/global/qflags.h @@ -179,26 +179,35 @@ typedef QFlags Flags; // These are opt-in, for backwards compatibility #define QT_DECLARE_TYPESAFE_OPERATORS_FOR_FLAGS_ENUM(Flags) \ +[[maybe_unused]] \ constexpr inline Flags operator~(Flags::enum_type e) noexcept \ { return ~Flags(e); } \ +[[maybe_unused]] \ constexpr inline void operator|(Flags::enum_type f1, int f2) noexcept = delete; #else #define QT_DECLARE_TYPESAFE_OPERATORS_FOR_FLAGS_ENUM(Flags) \ +[[maybe_unused]] \ constexpr inline QIncompatibleFlag operator|(Flags::enum_type f1, int f2) noexcept \ { return QIncompatibleFlag(int(f1) | f2); } #endif #define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags) \ +[[maybe_unused]] \ constexpr inline QFlags operator|(Flags::enum_type f1, Flags::enum_type f2) noexcept \ { return QFlags(f1) | f2; } \ +[[maybe_unused]] \ constexpr inline QFlags operator|(Flags::enum_type f1, QFlags f2) noexcept \ { return f2 | f1; } \ +[[maybe_unused]] \ constexpr inline QFlags operator&(Flags::enum_type f1, Flags::enum_type f2) noexcept \ { return QFlags(f1) & f2; } \ +[[maybe_unused]] \ constexpr inline QFlags operator&(Flags::enum_type f1, QFlags f2) noexcept \ { return f2 & f1; } \ +[[maybe_unused]] \ constexpr inline QFlags operator^(Flags::enum_type f1, Flags::enum_type f2) noexcept \ { return QFlags(f1) ^ f2; } \ +[[maybe_unused]] \ constexpr inline QFlags operator^(Flags::enum_type f1, QFlags f2) noexcept \ { return f2 ^ f1; } \ constexpr inline void operator+(Flags::enum_type f1, Flags::enum_type f2) noexcept = delete; \