summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qflags.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/global/qflags.h')
-rw-r--r--src/corelib/global/qflags.h20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/corelib/global/qflags.h b/src/corelib/global/qflags.h
index a23dbb53cd..cc028e0095 100644
--- a/src/corelib/global/qflags.h
+++ b/src/corelib/global/qflags.h
@@ -1,12 +1,12 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-#include <QtCore/qglobal.h>
-#include <QtCore/qcompare_impl.h>
-
#ifndef QFLAGS_H
#define QFLAGS_H
+#include <QtCore/qcompare_impl.h>
+#include <QtCore/qtypeinfo.h>
+
#include <initializer_list>
QT_BEGIN_NAMESPACE
@@ -24,7 +24,7 @@ public:
// 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)
+# if !defined(__LP64__) && !defined(Q_QDOC)
constexpr inline Q_IMPLICIT QFlag(long value) noexcept : i(int(value)) {}
constexpr inline Q_IMPLICIT QFlag(ulong value) noexcept : i(int(long(value))) {}
# endif
@@ -57,7 +57,7 @@ class QFlags
static_assert((std::is_enum<Enum>::value), "QFlags is only usable on enumeration types.");
public:
-#if defined(Q_CC_MSVC) || defined(Q_CLANG_QDOC)
+#if defined(Q_CC_MSVC) || defined(Q_QDOC)
// see above for MSVC
// the definition below is too complex for qdoc
typedef int Int;
@@ -179,26 +179,35 @@ typedef QFlags<Enum> 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<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) noexcept \
{ return QFlags<Flags::enum_type>(f1) | f2; } \
+[[maybe_unused]] \
constexpr inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> f2) noexcept \
{ return f2 | f1; } \
+[[maybe_unused]] \
constexpr inline QFlags<Flags::enum_type> operator&(Flags::enum_type f1, Flags::enum_type f2) noexcept \
{ return QFlags<Flags::enum_type>(f1) & f2; } \
+[[maybe_unused]] \
constexpr inline QFlags<Flags::enum_type> operator&(Flags::enum_type f1, QFlags<Flags::enum_type> f2) noexcept \
{ return f2 & f1; } \
+[[maybe_unused]] \
constexpr inline QFlags<Flags::enum_type> operator^(Flags::enum_type f1, Flags::enum_type f2) noexcept \
{ return QFlags<Flags::enum_type>(f1) ^ f2; } \
+[[maybe_unused]] \
constexpr inline QFlags<Flags::enum_type> operator^(Flags::enum_type f1, QFlags<Flags::enum_type> f2) noexcept \
{ return f2 ^ f1; } \
constexpr inline void operator+(Flags::enum_type f1, Flags::enum_type f2) noexcept = delete; \
@@ -218,6 +227,7 @@ QT_DECLARE_TYPESAFE_OPERATORS_FOR_FLAGS_ENUM(Flags)
#if __cplusplus > 201702L // assume compilers don't warn if in C++17 mode
// in C++20 mode, provide user-defined operators to override the deprecated operations:
# define Q_DECLARE_MIXED_ENUM_OPERATOR(op, Ret, LHS, RHS) \
+ [[maybe_unused]] \
constexpr inline Ret operator op (LHS lhs, RHS rhs) noexcept \
{ return static_cast<Ret>(qToUnderlying(lhs) op qToUnderlying(rhs)); } \
/* end */