diff options
Diffstat (limited to 'src/corelib/global/qcompilerdetection.h')
-rw-r--r-- | src/corelib/global/qcompilerdetection.h | 340 |
1 files changed, 292 insertions, 48 deletions
diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index c3b0611018..673f1c795b 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -2,16 +2,24 @@ // 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> +#include <QtCore/qsystemdetection.h> + +#if 0 +#pragma qt_class(QtCompilerDetection) +#pragma qt_sync_skip_header_check +#pragma qt_sync_stop_processing #endif #ifndef QCOMPILERDETECTION_H #define QCOMPILERDETECTION_H +#include <QtCore/qprocessordetection.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++ @@ -38,6 +46,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 @@ -57,17 +70,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 -# undef Q_CC_MSVC_ONLY -# ifdef Q_CC_CLANG_ONLY -# undef Q_CC_CLANG_ONLY -# endif +# 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 @@ -111,7 +123,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 @@ -164,7 +180,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"))) @@ -220,7 +236,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 @@ -436,13 +451,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 @@ -484,9 +507,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 @@ -520,7 +548,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 @@ -618,10 +647,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 @@ -643,7 +672,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) @@ -822,6 +851,13 @@ # 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 # endif /* __cplusplus */ #endif // defined(Q_CC_MSVC) && !defined(Q_CC_CLANG) @@ -867,16 +903,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 @@ -922,6 +964,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]] @@ -971,6 +1027,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 @@ -1031,7 +1096,11 @@ * "Weak overloads" - makes an otherwise confliciting overload weaker * (by making it a template) */ -#define Q_WEAK_OVERLOAD template <typename = void> +#ifndef Q_QDOC +# define Q_WEAK_OVERLOAD template <typename = void> +#else +# define Q_WEAK_OVERLOAD +#endif /* * If one wants to add functions that use post-C++17 APIs, one needs to: @@ -1051,7 +1120,11 @@ * The workaround: declare such functions as function templates. * (Obviously a function template does not need this marker.) */ -#define QT_POST_CXX17_API_IN_EXPORTED_CLASS template <typename = void> +#ifndef Q_QDOC +# define QT_POST_CXX17_API_IN_EXPORTED_CLASS template <typename = void> +#else +# define QT_POST_CXX17_API_IN_EXPORTED_CLASS +#endif /* * Warning/diagnostic handling @@ -1110,6 +1183,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 */ @@ -1125,18 +1212,6 @@ #define qMove(x) (x) #endif -#define Q_UNREACHABLE() \ - do {\ - Q_ASSERT_X(false, "Q_UNREACHABLE()", "Q_UNREACHABLE was reached");\ - Q_UNREACHABLE_IMPL();\ - } while (false) - -#define Q_ASSUME(Expr) \ - [] (bool valueOfExpression) {\ - Q_ASSERT_X(valueOfExpression, "Q_ASSUME()", "Assumption in Q_ASSUME(\"" #Expr "\") was not correct");\ - Q_ASSUME_IMPL(valueOfExpression);\ - }(Expr) - #if defined(__cplusplus) #if __has_cpp_attribute(clang::fallthrough) # define Q_FALLTHROUGH() [[clang::fallthrough]] @@ -1147,11 +1222,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 @@ -1176,4 +1251,173 @@ # undef QT_COMPILER_SUPPORTS_MIPS_DSPR2 #endif +// Compiler version check +#if defined(__cplusplus) && (__cplusplus < 201703L) +# ifdef Q_CC_MSVC +# error "Qt requires a C++17 compiler, and a suitable value for __cplusplus. On MSVC, you must pass the /Zc:__cplusplus option to the compiler." +# else +# error "Qt requires a C++17 compiler" +# endif +#endif // __cplusplus + +#if defined(__cplusplus) && defined(Q_CC_MSVC) && !defined(Q_CC_CLANG) +# if Q_CC_MSVC < 1927 + // Check below only works with 16.7 or newer +# error "Qt requires at least Visual Studio 2019 version 16.7 (VC++ version 14.27). Please upgrade." +# endif + +// On MSVC we require /permissive- set by user code. Check that we are +// under its rules -- for instance, check that std::nullptr_t->bool is +// not an implicit conversion, as per +// https://docs.microsoft.com/en-us/cpp/overview/cpp-conformance-improvements?view=msvc-160#nullptr_t-is-only-convertible-to-bool-as-a-direct-initialization +static_assert(!std::is_convertible_v<std::nullptr_t, bool>, + "On MSVC you must pass the /permissive- option to the compiler."); +#endif + +#if defined(QT_BOOTSTRAPPED) || defined(QT_USE_PROTECTED_VISIBILITY) || !defined(__ELF__) || defined(__PIC__) +// this is fine +#elif defined(QT_REDUCE_RELOCATIONS) +# error "You must build your code with position independent code if Qt was configured with -reduce-relocations. "\ + "Compile your code with -fPIC (and not with -fPIE)." +#endif + +#ifdef Q_PROCESSOR_X86_32 +# if defined(Q_CC_GNU) +# define QT_FASTCALL __attribute__((regparm(3))) +# elif defined(Q_CC_MSVC) +# define QT_FASTCALL __fastcall +# else +# define QT_FASTCALL +# endif +#else +# define QT_FASTCALL +#endif + +// enable gcc warnings for printf-style functions +#if defined(Q_CC_GNU) && !defined(__INSURE__) +# if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG) +# define Q_ATTRIBUTE_FORMAT_PRINTF(A, B) \ + __attribute__((format(gnu_printf, (A), (B)))) +# else +# define Q_ATTRIBUTE_FORMAT_PRINTF(A, B) \ + __attribute__((format(printf, (A), (B)))) +# endif +#else +# define Q_ATTRIBUTE_FORMAT_PRINTF(A, B) +#endif + +#ifdef Q_CC_MSVC +# define Q_NEVER_INLINE __declspec(noinline) +# define Q_ALWAYS_INLINE __forceinline +#elif defined(Q_CC_GNU) +# define Q_NEVER_INLINE __attribute__((noinline)) +# define Q_ALWAYS_INLINE inline __attribute__((always_inline)) +#else +# define Q_NEVER_INLINE +# define Q_ALWAYS_INLINE inline +#endif + +//defines the type for the WNDPROC on windows +//the alignment needs to be forced for sse2 to not crash with mingw +#if defined(Q_OS_WIN) +# if defined(Q_CC_MINGW) && defined(Q_PROCESSOR_X86_32) +# define QT_ENSURE_STACK_ALIGNED_FOR_SSE __attribute__ ((force_align_arg_pointer)) +# else +# define QT_ENSURE_STACK_ALIGNED_FOR_SSE +# endif +# define QT_WIN_CALLBACK CALLBACK QT_ENSURE_STACK_ALIGNED_FOR_SSE +#endif + +#ifdef __cpp_conditional_explicit +#define Q_IMPLICIT explicit(false) +#else +#define Q_IMPLICIT +#endif + +#if defined(__cplusplus) + +#ifdef __cpp_constinit +# if defined(Q_CC_MSVC) && !defined(Q_CC_CLANG) + // https://developercommunity.visualstudio.com/t/C:-constinit-for-an-optional-fails-if-/1406069 +# define Q_CONSTINIT +# else +# define Q_CONSTINIT constinit +# 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_ONLY) && Q_CC_GNU >= 1000 +# define Q_CONSTINIT __constinit +#else +# define Q_CONSTINIT +#endif + +#ifndef Q_OUTOFLINE_TEMPLATE +# define Q_OUTOFLINE_TEMPLATE +#endif +#ifndef Q_INLINE_TEMPLATE +# define Q_INLINE_TEMPLATE inline +#endif + +/* + Avoid some particularly useless warnings from some stupid compilers. + To get ALL C++ compiler warnings, define QT_CC_WARNINGS or comment out + the line "#define QT_NO_WARNINGS". See also QTBUG-26877. +*/ +#if !defined(QT_CC_WARNINGS) +# define QT_NO_WARNINGS +#endif +#if defined(QT_NO_WARNINGS) +# if defined(Q_CC_MSVC) +QT_WARNING_DISABLE_MSVC(4251) /* class 'type' needs to have dll-interface to be used by clients of class 'type2' */ +QT_WARNING_DISABLE_MSVC(4244) /* conversion from 'type1' to 'type2', possible loss of data */ +QT_WARNING_DISABLE_MSVC(4275) /* non - DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier' */ +QT_WARNING_DISABLE_MSVC(4514) /* unreferenced inline function has been removed */ +QT_WARNING_DISABLE_MSVC(4800) /* 'type' : forcing value to bool 'true' or 'false' (performance warning) */ +QT_WARNING_DISABLE_MSVC(4097) /* typedef-name 'identifier1' used as synonym for class-name 'identifier2' */ +QT_WARNING_DISABLE_MSVC(4706) /* assignment within conditional expression */ +QT_WARNING_DISABLE_MSVC(4355) /* 'this' : used in base member initializer list */ +QT_WARNING_DISABLE_MSVC(4710) /* function not inlined */ +QT_WARNING_DISABLE_MSVC(4530) /* C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc */ +# elif defined(Q_CC_BOR) +# pragma option -w-inl +# pragma option -w-aus +# pragma warn -inl +# pragma warn -pia +# pragma warn -ccc +# pragma warn -rch +# pragma warn -sig +# 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 :/ +# define QT_COMPILER_HAS_P0846 +#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 |