diff options
Diffstat (limited to 'src/corelib/global/qcompilerdetection.h')
-rw-r--r-- | src/corelib/global/qcompilerdetection.h | 178 |
1 files changed, 144 insertions, 34 deletions
diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index cab2b01a76..b2340bff8e 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -2,11 +2,8 @@ // Copyright (C) 2016 Intel Corporation. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only -#ifndef QGLOBAL_H -# include <QtCore/qglobal.h> -#endif - #if 0 +#pragma qt_class(QtCompilerDetection) #pragma qt_sync_skip_header_check #pragma qt_sync_stop_processing #endif @@ -15,10 +12,13 @@ #define QCOMPILERDETECTION_H #include <QtCore/qprocessordetection.h> +#include <QtCore/qsystemdetection.h> +#include <QtCore/qtconfiginclude.h> /* The compiler, must be one of: (Q_CC_x) + COVERITY - Coverity cov-scan SYM - Digital Mars C/C++ (used to be Symantec C++) MSVC - Microsoft Visual C/C++, Intel C++ for Windows BOR - Borland/Turbo C++ @@ -45,6 +45,11 @@ Should be sorted most to least authoritative. */ +#if defined(__COVERITY__) +# define Q_CC_COVERITY +# define Q_COMPILER_COMPLAINS_ABOUT_RETURN_AFTER_UNREACHABLE +#endif + /* Symantec C++ is now Digital Mars */ #if defined(__DMC__) || defined(__SC__) # define Q_CC_SYM @@ -64,13 +69,16 @@ # endif # define Q_OUTOFLINE_TEMPLATE inline # define Q_COMPILER_MANGLES_RETURN_TYPE +# define Q_COMPILER_MANGLES_ACCESS_SPECIFIER # define Q_FUNC_INFO __FUNCSIG__ # define Q_ASSUME_IMPL(expr) __assume(expr) # define Q_UNREACHABLE_IMPL() __assume(0) # define Q_DECL_EXPORT __declspec(dllexport) # define Q_DECL_IMPORT __declspec(dllimport) -# define QT_MAKE_UNCHECKED_ARRAY_ITERATOR(x) stdext::make_unchecked_array_iterator(x) // Since _MSC_VER >= 1800 -# define QT_MAKE_CHECKED_ARRAY_ITERATOR(x, N) stdext::make_checked_array_iterator(x, size_t(N)) // Since _MSC_VER >= 1500 +# if _MSC_VER < 1938 // stdext is deprecated since VS 2022 17.8 +# define QT_MAKE_CHECKED_ARRAY_ITERATOR(x, N) stdext::make_checked_array_iterator(x, size_t(N)) // Since _MSC_VER >= 1500 +# endif +# define Q_COMPILER_COMPLAINS_ABOUT_RETURN_AFTER_UNREACHABLE #elif defined(__BORLANDC__) || defined(__TURBOC__) # define Q_CC_BOR @@ -114,7 +122,11 @@ // define to verify the Clang version we hard-code the versions // based on the best available info we have about the actual // version: http://en.wikipedia.org/wiki/Xcode#Toolchain_Versions -# if __apple_build_version__ >= 13160021 // Xcode 13.3 +# if __apple_build_version__ >= 14030022 // Xcode 14.3 +# define Q_CC_CLANG 1500 +# elif __apple_build_version__ >= 14000029 // Xcode 14.0 +# define Q_CC_CLANG 1400 +# elif __apple_build_version__ >= 13160021 // Xcode 13.3 # define Q_CC_CLANG 1300 # elif __apple_build_version__ >= 13000029 // Xcode 13.0 # define Q_CC_CLANG 1200 @@ -167,7 +179,7 @@ # ifdef Q_OS_WIN # define Q_DECL_EXPORT __declspec(dllexport) # define Q_DECL_IMPORT __declspec(dllimport) -# elif defined(QT_VISIBILITY_AVAILABLE) +# else # define Q_DECL_EXPORT_OVERRIDABLE __attribute__((visibility("default"), weak)) # ifdef QT_USE_PROTECTED_VISIBILITY # define Q_DECL_EXPORT __attribute__((visibility("protected"))) @@ -223,7 +235,6 @@ but it is not defined on older compilers like C Set 3.1 */ #elif defined(__xlC__) # define Q_CC_XLC -# define Q_FULL_TEMPLATE_INSTANTIATION # if __xlC__ < 0x400 # error "Compiler not supported" # elif __xlC__ >= 0x0600 @@ -439,13 +450,21 @@ # define __has_include_next(x) 0 #endif -// Kept around until all submodules have transitioned -#define QT_HAS_BUILTIN(x) __has_builtin(x) -#define QT_HAS_FEATURE(x) __has_feature(x) -#define QT_HAS_ATTRIBUTE(x) __has_attribute(x) -#define QT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) -#define QT_HAS_INCLUDE(x) __has_include(x) -#define QT_HAS_INCLUDE_NEXT(x) __has_include_next(x) +/* + detecting ASAN can be helpful to disable slow tests + clang uses feature, gcc defines __SANITIZE_ADDRESS__ + unconditionally check both in case other compilers mirror + either of those options + */ +#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) +# define QT_ASAN_ENABLED +#endif + +#ifdef __cplusplus +# if __has_include(<version>) /* remove this check once Integrity, QNX have caught up */ +# include <version> +# endif +#endif /* * C++11 support @@ -487,9 +506,14 @@ * N1653 Q_COMPILER_VARIADIC_MACROS * N2242 N2555 Q_COMPILER_VARIADIC_TEMPLATES __cpp_variadic_templates = 200704 * - * For any future version of the C++ standard, we use only the SD-6 macro. - * For full listing, see - * http://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations + * + * For the C++ standards C++14 and C++17, we use only the SD-6 macro. + * + * For any future version of the C++ standard, we use only the C++20 feature test macro. + * For library features, we assume <version> is present (this header includes it). + * + * For a full listing of feature test macros, see + * https://en.cppreference.com/w/cpp/feature_test * * C++ extensions: * Q_COMPILER_RESTRICTED_VLA variable-length arrays, prior to __cpp_runtime_arrays @@ -523,7 +547,8 @@ # endif /* C++11 features, see http://clang.llvm.org/cxx_status.html */ -# if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) +# if (defined(__cplusplus) && __cplusplus >= 201103L) \ + || defined(__GXX_EXPERIMENTAL_CXX0X__) /* Detect C++ features using __has_feature(), see http://clang.llvm.org/docs/LanguageExtensions.html#cxx11 */ # if __has_feature(cxx_alignas) # define Q_COMPILER_ALIGNAS @@ -621,10 +646,10 @@ # if Q_CC_CLANG >= 209 /* since clang 2.9 */ # define Q_COMPILER_EXTERN_TEMPLATES # endif -# endif +# endif // (defined(__cplusplus) && __cplusplus >= 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X__) /* C++1y features, deprecated macros. Do not update this list. */ -# if __cplusplus > 201103L +# if defined(__cplusplus) && __cplusplus > 201103L //# if __has_feature(cxx_binary_literals) //# define Q_COMPILER_BINARY_LITERALS // see above //# endif @@ -646,7 +671,7 @@ # if __has_feature(cxx_runtime_array) # define Q_COMPILER_VLA # endif -# endif +# endif // if defined(__cplusplus) && __cplusplus > 201103L # if defined(__STDC_VERSION__) # if __has_feature(c_static_assert) @@ -825,6 +850,15 @@ # if _MSC_VER >= 1910 # define Q_COMPILER_CONSTEXPR # endif +// MSVC versions before 19.36 have a bug in C++20 comparison implementation. +// This leads to ambiguities when resolving comparison operator overloads in +// certain scenarios (the buggy MSVC versions were checked using our CI and +// compiler explorer). +# if _MSC_VER < 1936 +# define Q_COMPILER_LACKS_THREE_WAY_COMPARE_SYMMETRY +# endif +// QTBUG-124376: MSVC is slow at compiling qstrnlen() +# define Q_COMPILER_SLOW_QSTRNLEN_COMPILATION # endif /* __cplusplus */ #endif // defined(Q_CC_MSVC) && !defined(Q_CC_CLANG) @@ -870,16 +904,22 @@ # endif // !_HAS_CONSTEXPR # endif // !__GLIBCXX__ && !_LIBCPP_VERSION # endif // Q_OS_QNX -# if defined(Q_CC_CLANG) && defined(Q_OS_MAC) && defined(__GNUC_LIBSTD__) \ - && ((__GNUC_LIBSTD__-0) * 100 + __GNUC_LIBSTD_MINOR__-0 <= 402) +# if defined(Q_CC_CLANG) && defined(Q_OS_DARWIN) +# if defined(__GNUC_LIBSTD__) && ((__GNUC_LIBSTD__-0) * 100 + __GNUC_LIBSTD_MINOR__-0 <= 402) // Apple has not updated libstdc++ since 2007, which means it does not have // <initializer_list> or std::move. Let's disable these features -# undef Q_COMPILER_INITIALIZER_LISTS -# undef Q_COMPILER_RVALUE_REFS -# undef Q_COMPILER_REF_QUALIFIERS +# undef Q_COMPILER_INITIALIZER_LISTS +# undef Q_COMPILER_RVALUE_REFS +# undef Q_COMPILER_REF_QUALIFIERS // Also disable <atomic>, since it's clearly not there -# undef Q_COMPILER_ATOMICS -# endif +# undef Q_COMPILER_ATOMICS +# endif +# if defined(__cpp_lib_memory_resource) \ + && ((defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 140000) \ + || (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 170000)) +# undef __cpp_lib_memory_resource // Only supported on macOS 14 and iOS 17 +# endif +# endif // defined(Q_CC_CLANG) && defined(Q_OS_DARWIN) #endif // Don't break code that is already using Q_COMPILER_DEFAULT_DELETE_MEMBERS @@ -925,6 +965,20 @@ # define Q_REQUIRED_RESULT [[nodiscard]] #endif +#if __has_cpp_attribute(nodiscard) >= 201907L /* used for both P1771 and P1301... */ +// [[nodiscard]] constructor (P1771) +# ifndef Q_NODISCARD_CTOR +# define Q_NODISCARD_CTOR [[nodiscard]] +# endif +// [[nodiscard("reason")]] (P1301) +# ifndef Q_NODISCARD_X +# define Q_NODISCARD_X(message) [[nodiscard(message)]] +# endif +# ifndef Q_NODISCARD_CTOR_X +# define Q_NODISCARD_CTOR_X(message) [[nodiscard(message)]] +# endif +#endif + #if __has_cpp_attribute(maybe_unused) # undef Q_DECL_UNUSED # define Q_DECL_UNUSED [[maybe_unused]] @@ -974,6 +1028,15 @@ #ifndef Q_REQUIRED_RESULT # define Q_REQUIRED_RESULT #endif +#ifndef Q_NODISCARD_X +# define Q_NODISCARD_X(message) Q_REQUIRED_RESULT +#endif +#ifndef Q_NODISCARD_CTOR +# define Q_NODISCARD_CTOR +#endif +#ifndef Q_NODISCARD_CTOR_X +# define Q_NODISCARD_CTOR_X(message) Q_NODISCARD_CTOR +#endif #ifndef Q_DECL_DEPRECATED # define Q_DECL_DEPRECATED #endif @@ -1034,7 +1097,7 @@ * "Weak overloads" - makes an otherwise confliciting overload weaker * (by making it a template) */ -#ifndef Q_CLANG_QDOC +#ifndef Q_QDOC # define Q_WEAK_OVERLOAD template <typename = void> #else # define Q_WEAK_OVERLOAD @@ -1058,7 +1121,7 @@ * The workaround: declare such functions as function templates. * (Obviously a function template does not need this marker.) */ -#ifndef Q_CLANG_QDOC +#ifndef Q_QDOC # define QT_POST_CXX17_API_IN_EXPORTED_CLASS template <typename = void> #else # define QT_POST_CXX17_API_IN_EXPORTED_CLASS @@ -1121,6 +1184,20 @@ QT_WARNING_POP #endif +// The body must be a statement: +#define Q_CAST_IGNORE_ALIGN(body) QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wcast-align") body QT_WARNING_POP + +// This macro can be used to calculate member offsets for types with a non standard layout. +// It uses the fact that offsetof() is allowed to support those types since C++17 as an optional +// feature. All our compilers do support this, but some issue a warning, so we wrap the offsetof() +// call in a macro that disables the compiler warning. +#define Q_OFFSETOF(Class, member) \ + []() -> size_t { \ + QT_WARNING_PUSH QT_WARNING_DISABLE_INVALID_OFFSETOF \ + return offsetof(Class, member); \ + QT_WARNING_POP \ + }() + /* Proper for-scoping in MIPSpro CC */ @@ -1146,11 +1223,11 @@ #endif #endif #ifndef Q_FALLTHROUGH -# if defined(Q_CC_GNU_ONLY) && Q_CC_GNU >= 700 +# ifdef Q_CC_GNU # define Q_FALLTHROUGH() __attribute__((fallthrough)) # else # define Q_FALLTHROUGH() (void)0 -#endif +# endif #endif @@ -1313,6 +1390,39 @@ QT_WARNING_DISABLE_MSVC(4530) /* C++ exception handler used, but unwind semantic # endif #endif +#if !defined(QT_NO_EXCEPTIONS) +# if !defined(Q_MOC_RUN) +# if defined(Q_CC_GNU) && !defined(__cpp_exceptions) +# define QT_NO_EXCEPTIONS +# endif +# elif defined(QT_BOOTSTRAPPED) +# define QT_NO_EXCEPTIONS +# endif +#endif + +// libstdc++ shipped with gcc < 11 does not have a fix for defect LWG 3346 +#if __cplusplus >= 202002L && (!defined(_GLIBCXX_RELEASE) || _GLIBCXX_RELEASE >= 11) +# define QT_COMPILER_HAS_LWG3346 +#endif + +#if defined(__cplusplus) && __cplusplus >= 202002L // P0846 doesn't have a feature macro :/ +# if !defined(Q_CC_MSVC_ONLY) || Q_CC_MSVC < 1939 // claims C++20 support but lacks P0846 + // 1939 is known to work + // 1936 is known to fail +# define QT_COMPILER_HAS_P0846 +# endif +#endif + +#ifdef QT_COMPILER_HAS_P0846 +# define QT_ENABLE_P0846_SEMANTICS_FOR(func) +#else + class QT_CLASS_JUST_FOR_P0846_SIMULATION; +# define QT_ENABLE_P0846_SEMANTICS_FOR(func) \ + template <typename T> \ + void func (QT_CLASS_JUST_FOR_P0846_SIMULATION *); \ + /* end */ +#endif // !P0846 + #endif // __cplusplus #endif // QCOMPILERDETECTION_H |