diff options
Diffstat (limited to 'src/corelib/global')
-rw-r--r-- | src/corelib/global/qcompilerdetection.h | 6 | ||||
-rw-r--r-- | src/corelib/global/qendian.h | 8 | ||||
-rw-r--r-- | src/corelib/global/qflags.h | 27 | ||||
-rw-r--r-- | src/corelib/global/qglobal.cpp | 12 | ||||
-rw-r--r-- | src/corelib/global/qnamespace.h | 7 | ||||
-rw-r--r-- | src/corelib/global/qrandom.cpp | 2 |
6 files changed, 53 insertions, 9 deletions
diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index d8a44655dd..d759548fbc 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -1259,7 +1259,11 @@ * "Weak overloads" - makes an otherwise confliciting overload weaker * (by making it a template) */ -#define Q_WEAK_OVERLOAD template <typename = void> +#ifndef Q_CLANG_QDOC +# define Q_WEAK_OVERLOAD template <typename = void> +#else +# define Q_WEAK_OVERLOAD +#endif /* * Warning/diagnostic handling diff --git a/src/corelib/global/qendian.h b/src/corelib/global/qendian.h index a97776c761..e9e51c4b93 100644 --- a/src/corelib/global/qendian.h +++ b/src/corelib/global/qendian.h @@ -372,8 +372,8 @@ public: QLEInteger &operator ^=(T i); QLEInteger &operator ++(); QLEInteger &operator --(); - QLEInteger &operator ++(int); - QLEInteger &operator --(int); + QLEInteger operator ++(int); + QLEInteger operator --(int); static Q_DECL_CONSTEXPR QLEInteger max(); static Q_DECL_CONSTEXPR QLEInteger min(); @@ -399,8 +399,8 @@ public: QBEInteger &operator ^=(T i); QBEInteger &operator ++(); QBEInteger &operator --(); - QBEInteger &operator ++(int); - QBEInteger &operator --(int); + QBEInteger operator ++(int); + QBEInteger operator --(int); static Q_DECL_CONSTEXPR QBEInteger max(); static Q_DECL_CONSTEXPR QBEInteger min(); diff --git a/src/corelib/global/qflags.h b/src/corelib/global/qflags.h index 4f46de5eaa..0fb0f8c6ae 100644 --- a/src/corelib/global/qflags.h +++ b/src/corelib/global/qflags.h @@ -192,6 +192,33 @@ typedef uint Flags; #endif /* Q_NO_TYPESAFE_FLAGS */ +// restore bit-wise enum-enum operators deprecated in C++20, +// but used in a few places in the API +#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) \ + constexpr inline Ret operator op (LHS lhs, RHS rhs) noexcept \ + { return static_cast<Ret>(std::underlying_type_t<LHS>(lhs) op std::underlying_type_t<RHS>(rhs)); } \ + /* end */ +#else + // in C++11-17 mode, statically-assert that this compiler's result of the + // operation is the same that the C++20 version would produce: +# define Q_DECLARE_MIXED_ENUM_OPERATOR(op, Ret, LHS, RHS) \ + Q_STATIC_ASSERT((std::is_same<decltype(std::declval<LHS>() op std::declval<RHS>()), Ret>::value)); +#endif + +#define Q_DECLARE_MIXED_ENUM_OPERATORS(Ret, Flags, Enum) \ + Q_DECLARE_MIXED_ENUM_OPERATOR(|, Ret, Flags, Enum) \ + Q_DECLARE_MIXED_ENUM_OPERATOR(&, Ret, Flags, Enum) \ + Q_DECLARE_MIXED_ENUM_OPERATOR(^, Ret, Flags, Enum) \ + /* end */ + +#define Q_DECLARE_MIXED_ENUM_OPERATORS_SYMMETRIC(Ret, Flags, Enum) \ + Q_DECLARE_MIXED_ENUM_OPERATORS(Ret, Flags, Enum) \ + Q_DECLARE_MIXED_ENUM_OPERATORS(Ret, Enum, Flags) \ + /* end */ + + QT_END_NAMESPACE #endif // QFLAGS_H diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index ac2e85c51e..5ad82c259d 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -3077,7 +3077,8 @@ QByteArray QSysInfo::machineUniqueId() { #if defined(Q_OS_DARWIN) && __has_include(<IOKit/IOKitLib.h>) char uuid[UuidStringLen + 1]; - io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")); + static const mach_port_t defaultPort = 0; // Effectively kIOMasterPortDefault/kIOMainPortDefault + io_service_t service = IOServiceGetMatchingService(defaultPort, IOServiceMatching("IOPlatformExpertDevice")); QCFString stringRef = (CFStringRef)IORegistryEntryCreateCFProperty(service, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0); CFStringGetCString(stringRef, uuid, sizeof(uuid), kCFStringEncodingMacRoman); return QByteArray(uuid); @@ -3722,6 +3723,15 @@ bool qEnvironmentVariableIsSet(const char *varName) noexcept */ bool qputenv(const char *varName, const QByteArray& value) { + // protect against non-NUL-terminated QByteArrays: + #define IS_RAW_DATA(d) ((d)->offset != sizeof(QByteArrayData)) // copied from qbytearray.cpp + if (IS_RAW_DATA(const_cast<QByteArray&>(value).data_ptr())) { + QByteArray copy(value); + copy.detach(); // ensures NUL termination + return qputenv(varName, copy); + } + #undef IS_RAW_DATA + const auto locker = qt_scoped_lock(environmentMutex); #if defined(Q_CC_MSVC) return _putenv_s(varName, value.constData()) == 0; diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index ad4150b317..deab11f729 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -235,9 +235,7 @@ public: AlignCenter = AlignVCenter | AlignHCenter }; - Q_DECLARE_FLAGS(Alignment, AlignmentFlag) - Q_DECLARE_OPERATORS_FOR_FLAGS(Alignment) enum TextFlag { TextSingleLine = 0x0100, @@ -260,6 +258,10 @@ public: , TextBypassShaping = 0x100000 #endif }; + Q_DECLARE_MIXED_ENUM_OPERATORS_SYMMETRIC(int, AlignmentFlag, TextFlag) + // *After* we've defined the mixed operators (or verified their sanity), + // otherwise the operators defined here mess with the mixed ones: + Q_DECLARE_OPERATORS_FOR_FLAGS(Alignment) enum TextElideMode { ElideLeft, @@ -267,6 +269,7 @@ public: ElideMiddle, ElideNone }; + Q_DECLARE_MIXED_ENUM_OPERATORS_SYMMETRIC(int, TextElideMode, TextFlag) enum WhiteSpaceMode { WhiteSpaceNormal, diff --git a/src/corelib/global/qrandom.cpp b/src/corelib/global/qrandom.cpp index 25f87c7e6a..0f0409976d 100644 --- a/src/corelib/global/qrandom.cpp +++ b/src/corelib/global/qrandom.cpp @@ -680,7 +680,7 @@ inline QRandomGenerator::SystemGenerator &QRandomGenerator::SystemGenerator::sel position in the deterministic sequence as the \a other object was. Both objects will generate the same sequence from this point on. - For that reason, it is not adviseable to create a copy of + For that reason, it is not advisable to create a copy of QRandomGenerator::global(). If one needs an exclusive deterministic generator, consider instead using securelySeeded() to obtain a new object that shares no relationship with the QRandomGenerator::global(). |