Use Q_CC_{GNU,MSVC}_ONLY when comparing to particular versions

This prevents false-negatives and false-positives, as e.g. Clang
10.0.0 masks as GCC 4.2, so Q_CC_GNU is 402 on that
compiler. Depending on the test (Q_CC_GNU > NNN or Q_CC_GNU < NNN),
the result of the test is almost random.

Q_CC_<comp>_ONLY makes sure we match only GCC or MSVC, not bycatch
such as Clang or ICC.

Pick-to: 6.3 6.2 5.15
Change-Id: I4c550a11ecf85fc9a2216b330b69bd03d45b47e0
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2022-05-02 12:54:23 +02:00
parent 5b246e15f1
commit cdd4a95317
8 changed files with 9 additions and 9 deletions

View File

@ -1353,7 +1353,7 @@
#endif
#endif
#ifndef Q_FALLTHROUGH
# if (defined(Q_CC_GNU) && Q_CC_GNU >= 700) && !defined(Q_CC_INTEL)
# if defined(Q_CC_GNU_ONLY) && Q_CC_GNU >= 700
# define Q_FALLTHROUGH() __attribute__((fallthrough))
# else
# define Q_FALLTHROUGH() (void)0

View File

@ -1189,7 +1189,7 @@ constexpr std::underlying_type_t<Enum> qToUnderlying(Enum e) noexcept
# endif
#elif defined(__has_cpp_attribute) && __has_cpp_attribute(clang::require_constant_initialization)
# define Q_CONSTINIT [[clang::require_constant_initialization]]
#elif defined(Q_CC_GNU) && Q_CC_GNU >= 1000
#elif defined(Q_CC_GNU_ONLY) && Q_CC_GNU >= 1000
# define Q_CONSTINIT __constinit
#else
# define Q_CONSTINIT

View File

@ -2204,7 +2204,7 @@ constexpr auto typenameHelper()
constexpr int suffix = sizeof("]");
#endif
#if (defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && !defined(Q_CC_CLANG) && Q_CC_GNU < 804)
#if defined(Q_CC_GNU_ONLY) && Q_CC_GNU_ONLY < 804
auto func = Q_FUNC_INFO;
const char *begin = func + prefix;
const char *end = func + sizeof(Q_FUNC_INFO) - suffix;

View File

@ -134,7 +134,7 @@ Q_CORE_EXPORT char *qstrdup(const char *);
inline size_t qstrlen(const char *str)
{
QT_WARNING_PUSH
#if defined(Q_CC_GNU) && Q_CC_GNU >= 900 && Q_CC_GNU < 1000
#if defined(Q_CC_GNU_ONLY) && Q_CC_GNU >= 900 && Q_CC_GNU < 1000
// spurious compiler warning (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91490#c6)
// when Q_DECLARE_METATYPE_TEMPLATE_1ARG is used
QT_WARNING_DISABLE_GCC("-Wstringop-overflow")

View File

@ -40,7 +40,7 @@
#include "qglobal.h"
#if (defined(QT_STATIC) || defined(QT_BOOTSTRAPPED)) && defined(Q_CC_GNU) && Q_CC_GNU >= 1000
#if (defined(QT_STATIC) || defined(QT_BOOTSTRAPPED)) && defined(Q_CC_GNU_ONLY) && Q_CC_GNU >= 1000
QT_WARNING_DISABLE_GCC("-Wfree-nonheap-object") // false positive tracking
#endif

View File

@ -382,7 +382,7 @@ static uint64_t siphash(const uint8_t *in, uint64_t inlen, uint64_t seed, uint64
}
#if defined(Q_CC_GNU) && Q_CC_GNU >= 700
#if defined(Q_CC_GNU_ONLY) && Q_CC_GNU >= 700
QT_WARNING_DISABLE_GCC("-Wimplicit-fallthrough")
#endif
switch (left) {
@ -486,7 +486,7 @@ static uint siphash(const uint8_t *in, uint inlen, uint seed, uint seed2)
v0 ^= m;
}
#if defined(Q_CC_GNU) && Q_CC_GNU >= 700
#if defined(Q_CC_GNU_ONLY) && Q_CC_GNU >= 700
QT_WARNING_DISABLE_GCC("-Wimplicit-fallthrough")
#endif
switch (left) {

View File

@ -66,7 +66,7 @@ class tst_QOffsetStringArray;
QT_BEGIN_NAMESPACE
QT_WARNING_PUSH
#if defined(Q_CC_GNU) && Q_CC_GNU >= 1100
#if defined(Q_CC_GNU_ONLY) && Q_CC_GNU >= 1100
// we usually don't overread, but GCC has a false positive
QT_WARNING_DISABLE_GCC("-Wstringop-overread")
#endif

View File

@ -323,7 +323,7 @@ static const struct QTextHtmlEntity { const char name[9]; char16_t code; } entit
};
static_assert(MAX_ENTITY == sizeof entities / sizeof *entities);
#if defined(Q_CC_MSVC) && _MSC_VER < 1600
#if defined(Q_CC_MSVC_ONLY) && _MSC_VER < 1600
bool operator<(const QTextHtmlEntity &entity1, const QTextHtmlEntity &entity2)
{
return QLatin1StringView(entity1.name) < QLatin1StringView(entity2.name);