summaryrefslogtreecommitdiffstats
path: root/src/corelib/global
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-05-02 08:21:23 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-05-07 21:37:45 +0000
commit00d4d1bbe9286c1bd5a1aae469f8ecc2d2b7ca28 (patch)
tree08f15b9f0aea998236b0102b0a373aeaef22f194 /src/corelib/global
parent13669903528c0ae194abdf82afaf4246f435a3e5 (diff)
qcompilerdetection.h: add Q_CC_{GNU,MSVC,CLANG}_ONLY macros
As the standard compilers on their respective platforms, other compilers tend to mask as Clang, GCC, or MSVC, leading to complicated code when you actually mean just one of these compilers: #if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) This is particularly problematic when combined with version checks: #if defined(Q_CC_GNU) && Q_CC_GNU >= 900 will, e.g., not match Clang 10.0.0, which masks as GCC 4.2. The correct way (until a new kid on the block starts to mask as GCC, too) to check for GCC >= 9.0 atm is: #if defined(Q_CC_CLANG) || defined(Q_CC_INTEL) || !(defined(Q_CC_GNU) && Q_CC_GNU >= 900) The new macros make such checks intuitive and hard-to-misuse: #if defined(Q_CC_GNU_ONLY) && Q_CC_GNU >= 900 Use it in qcompilerdetection.h. Change-Id: Idcdf973fbc4708f58ed91c800be3d5e599e5b7e6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> (cherry picked from commit c95fd3a7ce9c33f1fca1bce02e2f3b4cfdddc96c) Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/global')
-rw-r--r--src/corelib/global/qcompilerdetection.h17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h
index 1ced6c8fb0..eb9a1d327e 100644
--- a/src/corelib/global/qcompilerdetection.h
+++ b/src/corelib/global/qcompilerdetection.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2021 The Qt Company Ltd.
+** Copyright (C) 2022 The Qt Company Ltd.
** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
@@ -83,11 +83,14 @@
# endif
#elif defined(_MSC_VER)
+# define Q_CC_MSVC (_MSC_VER)
+# define Q_CC_MSVC_NET
+# define Q_CC_MSVC_ONLY Q_CC_MSVC
# ifdef __clang__
+# undef Q_CC_MSVC_ONLY
# define Q_CC_CLANG ((__clang_major__ * 100) + __clang_minor__)
+# define Q_CC_CLANG_ONLY Q_CC_CLANG
# endif
-# define Q_CC_MSVC (_MSC_VER)
-# define Q_CC_MSVC_NET
# define Q_OUTOFLINE_TEMPLATE inline
# define Q_COMPILER_MANGLES_RETURN_TYPE
# define Q_FUNC_INFO __FUNCSIG__
@@ -106,6 +109,10 @@
# define QT_MAKE_CHECKED_ARRAY_ITERATOR(x, N) stdext::make_checked_array_iterator(x, size_t(N)) // Since _MSC_VER >= 1500
/* Intel C++ disguising as Visual C++: the `using' keyword avoids warnings */
# if defined(__INTEL_COMPILER)
+# undef Q_CC_MSVC_ONLY
+# ifdef Q_CC_CLANG_ONLY
+# undef Q_CC_CLANG_ONLY
+# endif
# define Q_DECL_VARIABLE_DEPRECATED
# define Q_CC_INTEL __INTEL_COMPILER
# endif
@@ -183,6 +190,7 @@
# else
# define Q_CC_CLANG ((__clang_major__ * 100) + __clang_minor__)
# endif
+# define Q_CC_CLANG_ONLY Q_CC_CLANG
# if __has_builtin(__builtin_assume)
# define Q_ASSUME_IMPL(expr) __builtin_assume(expr)
# else
@@ -205,6 +213,7 @@
# endif
# else
/* Plain GCC */
+# define Q_CC_GNU_ONLY Q_CC_GNU
# if Q_CC_GNU >= 405
# define Q_ASSUME_IMPL(expr) if (expr){} else __builtin_unreachable()
# define Q_UNREACHABLE_IMPL() __builtin_unreachable()
@@ -836,7 +845,7 @@
# define Q_DECL_UNUSED_MEMBER Q_DECL_UNUSED
#endif
-#if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && !defined(Q_CC_CLANG)
+#if defined(Q_CC_GNU_ONLY)
# define Q_COMPILER_RESTRICTED_VLA
# define Q_COMPILER_THREADSAFE_STATICS
# if Q_CC_GNU >= 403