From c3bd5ffdc8a3b459f18ba6e35fca93e29f3b0ab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sun, 8 Dec 2019 23:47:10 +0100 Subject: Don't wrap feature detection macros with QT_HAS_FOO() variants Using wrappers for these macros is problematic when for example passing the -frewrite-includes flag to preprocess sources before shipping off to distcc or Icecream. It will also start producing warnings when compilers implement http://eel.is/c++draft/cpp.cond#7.sentence-2. See for example https://reviews.llvm.org/D49091 Both https://clang.llvm.org/docs/LanguageExtensions.html and the SD-6 document at https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations recommend defining '__has_foo(x) 0' as a fallback for compilers without the macros, so that's what we go for. Change-Id: I0298cd3b4a6ff6618821e34642a5ddd6728be767 Reviewed-by: Alex Richardson Reviewed-by: Thiago Macieira --- src/corelib/global/qcompilerdetection.h | 77 +++++++++++----------- src/corelib/global/qconfig-bootstrapped.h | 4 +- src/corelib/global/qendian.h | 4 +- src/corelib/global/qglobal.cpp | 4 +- src/corelib/global/qglobal.h | 2 +- src/corelib/global/qglobal_p.h | 4 +- src/corelib/global/qlogging.cpp | 8 +-- src/corelib/global/qnumeric_p.h | 2 +- src/corelib/io/qfilesystemengine_unix.cpp | 2 +- src/corelib/io/qprocess.cpp | 2 +- src/corelib/io/qstandardpaths.cpp | 2 +- src/corelib/io/qstorageinfo_unix.cpp | 2 +- src/corelib/kernel/qdeadlinetimer.h | 4 +- src/corelib/kernel/qobject.h | 4 +- src/corelib/kernel/qtimer.h | 6 +- src/corelib/kernel/qvariant.h | 6 +- src/corelib/serialization/qcborarray.h | 2 +- src/corelib/serialization/qcbormap.h | 2 +- src/corelib/serialization/qcborvalue.h | 6 +- src/corelib/text/qbytearray.cpp | 2 +- src/corelib/text/qbytearray.h | 2 +- src/corelib/text/qstring.h | 2 +- src/corelib/thread/qfutex_p.h | 4 +- src/corelib/thread/qmutex.h | 10 +-- src/corelib/tools/qalgorithms.h | 4 +- src/corelib/tools/qscopeguard.h | 4 +- tests/auto/corelib/global/qglobal/qglobal.c | 2 +- .../kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp | 4 +- tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp | 6 +- .../auto/corelib/kernel/qvariant/tst_qvariant.cpp | 4 +- .../serialization/qcborvalue/tst_qcborvalue.cpp | 2 +- tests/auto/corelib/thread/qmutex/tst_qmutex.cpp | 14 ++-- .../tst_containerapisymmetry.cpp | 2 +- .../thread/qreadwritelock/tst_qreadwritelock.cpp | 2 +- 34 files changed, 102 insertions(+), 105 deletions(-) diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index e47f284a42..60dc7ce688 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -505,6 +505,39 @@ # error "Qt has not been tested with this compiler - see http://www.qt-project.org/" #endif +/* + * SG10's SD-6 feature detection and some useful extensions from Clang and GCC + * https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations + * http://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros + * Not using wrapper macros, per http://eel.is/c++draft/cpp.cond#7.sentence-2 + */ +#ifndef __has_builtin +# define __has_builtin(x) 0 +#endif +#ifndef __has_feature +# define __has_feature(x) 0 +#endif +#ifndef __has_attribute +# define __has_attribute(x) 0 +#endif +#ifndef __has_cpp_attribute +# define __has_cpp_attribute(x) 0 +#endif +#ifndef __has_include +# define __has_include(x) 0 +#endif +#ifndef __has_include_next +# 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) + /* * C++11 support * @@ -1031,37 +1064,6 @@ # endif #endif -/* - * SG10's SD-6 feature detection and some useful extensions from Clang and GCC - * https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations - * http://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros - */ -#ifdef __has_builtin -# define QT_HAS_BUILTIN(x) __has_builtin(x) -#else -# define QT_HAS_BUILTIN(x) 0 -#endif -#ifdef __has_attribute -# define QT_HAS_ATTRIBUTE(x) __has_attribute(x) -#else -# define QT_HAS_ATTRIBUTE(x) 0 -#endif -#ifdef __has_cpp_attribute -# define QT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) -#else -# define QT_HAS_CPP_ATTRIBUTE(x) 0 -#endif -#ifdef __has_include -# define QT_HAS_INCLUDE(x) __has_include(x) -#else -# define QT_HAS_INCLUDE(x) 0 -#endif -#ifdef __has_include_next -# define QT_HAS_INCLUDE_NEXT(x) __has_include_next(x) -#else -# define QT_HAS_INCLUDE_NEXT(x) 0 -#endif - /* * C++11 keywords and expressions */ @@ -1138,7 +1140,7 @@ # define Q_DECL_ALIGN(n) alignas(n) #endif -#if QT_HAS_CPP_ATTRIBUTE(nodiscard) && !defined(Q_CC_CLANG) // P0188R1 +#if __has_cpp_attribute(nodiscard) && !defined(Q_CC_CLANG) // P0188R1 // Can't use [[nodiscard]] with Clang, see https://bugs.llvm.org/show_bug.cgi?id=33518 # undef Q_REQUIRED_RESULT # define Q_REQUIRED_RESULT [[nodiscard]] @@ -1240,11 +1242,6 @@ #ifndef QT_MAKE_CHECKED_ARRAY_ITERATOR # define QT_MAKE_CHECKED_ARRAY_ITERATOR(x, N) (x) #endif -#ifdef __has_feature -# define QT_HAS_FEATURE(x) __has_feature(x) -#else -# define QT_HAS_FEATURE(x) 0 -#endif /* * Warning/diagnostic handling @@ -1335,11 +1332,11 @@ } while (false) #if defined(__cplusplus) -#if QT_HAS_CPP_ATTRIBUTE(clang::fallthrough) +#if __has_cpp_attribute(clang::fallthrough) # define Q_FALLTHROUGH() [[clang::fallthrough]] -#elif QT_HAS_CPP_ATTRIBUTE(gnu::fallthrough) +#elif __has_cpp_attribute(gnu::fallthrough) # define Q_FALLTHROUGH() [[gnu::fallthrough]] -#elif QT_HAS_CPP_ATTRIBUTE(fallthrough) +#elif __has_cpp_attribute(fallthrough) # define Q_FALLTHROUGH() [[fallthrough]] #endif #endif diff --git a/src/corelib/global/qconfig-bootstrapped.h b/src/corelib/global/qconfig-bootstrapped.h index e6ad80525a..c6f071bc3f 100644 --- a/src/corelib/global/qconfig-bootstrapped.h +++ b/src/corelib/global/qconfig-bootstrapped.h @@ -75,13 +75,13 @@ # define QT_FEATURE_alloca_malloc_h -1 #endif #define QT_CRYPTOGRAPHICHASH_ONLY_SHA1 -#define QT_FEATURE_cxx11_random (QT_HAS_INCLUDE() ? 1 : -1) +#define QT_FEATURE_cxx11_random (__has_include() ? 1 : -1) #define QT_NO_DATASTREAM #define QT_FEATURE_datestring 1 #define QT_FEATURE_datetimeparser -1 #define QT_FEATURE_easingcurve -1 #define QT_FEATURE_etw -1 -#define QT_FEATURE_getauxval (QT_HAS_INCLUDE() ? 1 : -1) +#define QT_FEATURE_getauxval (__has_include() ? 1 : -1) #define QT_FEATURE_getentropy -1 #define QT_NO_GEOM_VARIANT #define QT_FEATURE_hijricalendar -1 diff --git a/src/corelib/global/qendian.h b/src/corelib/global/qendian.h index 5cd9d3160b..257efbbdbe 100644 --- a/src/corelib/global/qendian.h +++ b/src/corelib/global/qendian.h @@ -66,7 +66,7 @@ template Q_ALWAYS_INLINE void qToUnaligned(const T src, void *dest) // Using sizeof(T) inside memcpy function produces internal compiler error with // MSVC2008/ARM in tst_endian -> use extra indirection to resolve size of T. const size_t size = sizeof(T); -#if QT_HAS_BUILTIN(__builtin_memcpy) +#if __has_builtin(__builtin_memcpy) __builtin_memcpy #else memcpy @@ -78,7 +78,7 @@ template Q_ALWAYS_INLINE T qFromUnaligned(const void *src) { T dest; const size_t size = sizeof(T); -#if QT_HAS_BUILTIN(__builtin_memcpy) +#if __has_builtin(__builtin_memcpy) __builtin_memcpy #else memcpy diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 4ab5bd2edb..b662233d4e 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -92,7 +92,7 @@ # include #endif -#if defined(Q_OS_DARWIN) && QT_HAS_INCLUDE() +#if defined(Q_OS_DARWIN) && __has_include() # include # include #endif @@ -3041,7 +3041,7 @@ enum { */ QByteArray QSysInfo::machineUniqueId() { -#if defined(Q_OS_DARWIN) && QT_HAS_INCLUDE() +#if defined(Q_OS_DARWIN) && __has_include() char uuid[UuidStringLen + 1]; io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")); QCFString stringRef = (CFStringRef)IORegistryEntryCreateCFProperty(service, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0); diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 1e26e9453a..e335916eac 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -769,7 +769,7 @@ inline void qt_noop(void) {} #if !defined(QT_NO_EXCEPTIONS) # if !defined(Q_MOC_RUN) -# if (defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) && !QT_HAS_FEATURE(cxx_exceptions)) || \ +# if (defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) && !__has_feature(cxx_exceptions)) || \ (defined(Q_CC_GNU) && !defined(__EXCEPTIONS)) # define QT_NO_EXCEPTIONS # endif diff --git a/src/corelib/global/qglobal_p.h b/src/corelib/global/qglobal_p.h index 58bc8b7bf3..5ab84fa8be 100644 --- a/src/corelib/global/qglobal_p.h +++ b/src/corelib/global/qglobal_p.h @@ -74,7 +74,7 @@ Q_CORE_EXPORT time_t qMkTime(struct tm *when); QT_END_NAMESPACE -#if !QT_HAS_BUILTIN(__builtin_available) +#if !__has_builtin(__builtin_available) #include #include #include @@ -142,7 +142,7 @@ QT_END_NAMESPACE QT_BUILTIN_AVAILABLE1, \ QT_BUILTIN_AVAILABLE0, ) #define __builtin_available(...) QT_BUILTIN_AVAILABLE_CHOOSER(__VA_ARGS__)(__VA_ARGS__) -#endif // !QT_HAS_BUILTIN(__builtin_available) +#endif // !__has_builtin(__builtin_available) #endif // defined(__cplusplus) #endif // QGLOBAL_P_H diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 17f2246082..5a7f8242de 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -70,7 +70,7 @@ #if QT_CONFIG(slog2) #include #endif -#if QT_HAS_INCLUDE() +#if __has_include() #include #endif @@ -106,7 +106,7 @@ # if __UCLIBC_HAS_BACKTRACE__ # define QLOGGING_HAVE_BACKTRACE # endif -# elif (defined(__GLIBC__) && defined(__GLIBCXX__)) || (QT_HAS_INCLUDE() && QT_HAS_INCLUDE()) +# elif (defined(__GLIBC__) && defined(__GLIBCXX__)) || (__has_include() && __has_include()) # define QLOGGING_HAVE_BACKTRACE # endif #endif @@ -116,7 +116,7 @@ extern char *__progname; #endif #ifndef QT_BOOTSTRAPPED -#if defined(Q_OS_LINUX) && (defined(__GLIBC__) || QT_HAS_INCLUDE()) +#if defined(Q_OS_LINUX) && (defined(__GLIBC__) || __has_include()) # include # if defined(Q_OS_ANDROID) && !defined(SYS_gettid) @@ -1276,7 +1276,7 @@ void QMessagePattern::setPattern(const QString &pattern) #if defined(QLOGGING_HAVE_BACKTRACE) && !defined(QT_BOOTSTRAPPED) // make sure the function has "Message" in the name so the function is removed -#if ((defined(Q_CC_GNU) && defined(QT_COMPILER_SUPPORTS_SIMD_ALWAYS)) || QT_HAS_ATTRIBUTE(optimize)) \ +#if ((defined(Q_CC_GNU) && defined(QT_COMPILER_SUPPORTS_SIMD_ALWAYS)) || __has_attribute(optimize)) \ && !defined(Q_CC_INTEL) && !defined(Q_CC_CLANG) // force skipping the frame pointer, to save the backtrace() function some work __attribute__((optimize("omit-frame-pointer"))) diff --git a/src/corelib/global/qnumeric_p.h b/src/corelib/global/qnumeric_p.h index 86e7997680..fdfcbda6ca 100644 --- a/src/corelib/global/qnumeric_p.h +++ b/src/corelib/global/qnumeric_p.h @@ -249,7 +249,7 @@ QT_WARNING_POP // size_t. Implementations for 8- and 16-bit types will work but may not be as // efficient. Implementations for 64-bit may be missing on 32-bit platforms. -#if (defined(Q_CC_GNU) && (Q_CC_GNU >= 500) || (defined(Q_CC_INTEL) && !defined(Q_OS_WIN))) || QT_HAS_BUILTIN(__builtin_add_overflow) +#if (defined(Q_CC_GNU) && (Q_CC_GNU >= 500) || (defined(Q_CC_INTEL) && !defined(Q_OS_WIN))) || __has_builtin(__builtin_add_overflow) // GCC 5, ICC 18, and Clang 3.8 have builtins to detect overflows template inline diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index c3abec8989..38cb6a423d 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -55,7 +55,7 @@ #include #include -#if QT_HAS_INCLUDE() +#if __has_include() # include #endif #ifndef _PATH_TMP // from diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 35ca2542f7..3a77242d7c 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -100,7 +100,7 @@ QT_END_NAMESPACE #include #endif -#if QT_HAS_INCLUDE() +#if __has_include() #include #endif diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp index 02adda3d6c..bca454fc7a 100644 --- a/src/corelib/io/qstandardpaths.cpp +++ b/src/corelib/io/qstandardpaths.cpp @@ -48,7 +48,7 @@ #include #endif -#if QT_HAS_INCLUDE() +#if __has_include() #include #endif diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp index 1e72241e68..37b8a60c37 100644 --- a/src/corelib/io/qstorageinfo_unix.cpp +++ b/src/corelib/io/qstorageinfo_unix.cpp @@ -108,7 +108,7 @@ # endif // QT_LARGEFILE_SUPPORT #endif // Q_OS_BSD4 -#if QT_HAS_INCLUDE() +#if __has_include() # include #endif #ifndef _PATH_MOUNTED diff --git a/src/corelib/kernel/qdeadlinetimer.h b/src/corelib/kernel/qdeadlinetimer.h index 9dd92481d2..99e09eb31f 100644 --- a/src/corelib/kernel/qdeadlinetimer.h +++ b/src/corelib/kernel/qdeadlinetimer.h @@ -52,7 +52,7 @@ #include -#if QT_HAS_INCLUDE() +#if __has_include() # include #endif @@ -120,7 +120,7 @@ public: QDeadlineTimer &operator-=(qint64 msecs) { *this = *this + (-msecs); return *this; } -#if QT_HAS_INCLUDE() || defined(Q_CLANG_QDOC) +#if __has_include() || defined(Q_CLANG_QDOC) template QDeadlineTimer(std::chrono::time_point deadline_, Qt::TimerType type_ = Qt::CoarseTimer) : t2(0) diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index 540b8b32c1..f5d7c22e3a 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -55,7 +55,7 @@ #include -#if QT_HAS_INCLUDE() +#if __has_include() # include #endif @@ -160,7 +160,7 @@ public: void moveToThread(QThread *thread); int startTimer(int interval, Qt::TimerType timerType = Qt::CoarseTimer); -#if QT_HAS_INCLUDE() +#if __has_include() Q_ALWAYS_INLINE int startTimer(std::chrono::milliseconds time, Qt::TimerType timerType = Qt::CoarseTimer) { diff --git a/src/corelib/kernel/qtimer.h b/src/corelib/kernel/qtimer.h index eb7185c12d..6bbfd741d9 100644 --- a/src/corelib/kernel/qtimer.h +++ b/src/corelib/kernel/qtimer.h @@ -47,7 +47,7 @@ #include // conceptual inheritance #include -#if QT_HAS_INCLUDE() +#if __has_include() # include #endif @@ -177,7 +177,7 @@ Q_SIGNALS: void timeout(QPrivateSignal); public: -#if QT_HAS_INCLUDE() || defined(Q_QDOC) +#if __has_include() || defined(Q_QDOC) void setInterval(std::chrono::milliseconds value) { setInterval(int(value.count())); @@ -223,7 +223,7 @@ private: static void singleShotImpl(int msec, Qt::TimerType timerType, const QObject *receiver, QtPrivate::QSlotObjectBase *slotObj); -#if QT_HAS_INCLUDE() +#if __has_include() static Qt::TimerType defaultTypeFor(std::chrono::milliseconds interval) { return defaultTypeFor(int(interval.count())); } diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index e7d3d9c835..a4957472ec 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -53,7 +53,7 @@ #include #endif -#if QT_HAS_INCLUDE() && __cplusplus >= 201703L +#if __has_include() && __cplusplus >= 201703L #include #elif defined(Q_CLANG_QDOC) namespace std { template struct variant; } @@ -370,7 +370,7 @@ class Q_CORE_EXPORT QVariant static inline QVariant fromValue(const T &value) { return QVariant(qMetaTypeId(), &value, QTypeInfo::isPointer); } -#if (QT_HAS_INCLUDE() && __cplusplus >= 201703L) || defined(Q_CLANG_QDOC) +#if (__has_include() && __cplusplus >= 201703L) || defined(Q_CLANG_QDOC) template static inline QVariant fromStdVariant(const std::variant &value) { @@ -544,7 +544,7 @@ inline QVariant QVariant::fromValue(const QVariant &value) return value; } -#if QT_HAS_INCLUDE() && __cplusplus >= 201703L +#if __has_include() && __cplusplus >= 201703L template<> inline QVariant QVariant::fromValue(const std::monostate &) { diff --git a/src/corelib/serialization/qcborarray.h b/src/corelib/serialization/qcborarray.h index e06544f245..fe06b8630f 100644 --- a/src/corelib/serialization/qcborarray.h +++ b/src/corelib/serialization/qcborarray.h @@ -214,7 +214,7 @@ public: bool contains(const QCborValue &value) const; int compare(const QCborArray &other) const noexcept Q_DECL_PURE_FUNCTION; -#if 0 && QT_HAS_INCLUDE() +#if 0 && __has_include() std::strong_ordering operator<=>(const QCborArray &other) const { int c = compare(other); diff --git a/src/corelib/serialization/qcbormap.h b/src/corelib/serialization/qcbormap.h index 4aea901eef..6636ce776a 100644 --- a/src/corelib/serialization/qcbormap.h +++ b/src/corelib/serialization/qcbormap.h @@ -245,7 +245,7 @@ public: { const_iterator it = find(key); return it != end(); } int compare(const QCborMap &other) const noexcept Q_DECL_PURE_FUNCTION; -#if 0 && QT_HAS_INCLUDE() +#if 0 && __has_include() std::strong_ordering operator<=>(const QCborMap &other) const { int c = compare(other); diff --git a/src/corelib/serialization/qcborvalue.h b/src/corelib/serialization/qcborvalue.h index f79fc572c4..914103b0a5 100644 --- a/src/corelib/serialization/qcborvalue.h +++ b/src/corelib/serialization/qcborvalue.h @@ -59,7 +59,7 @@ # undef False #endif -#if 0 && QT_HAS_INCLUDE() +#if 0 && __has_include() # include #endif @@ -261,7 +261,7 @@ public: QCborValueRef operator[](const QString & key); int compare(const QCborValue &other) const; -#if 0 && QT_HAS_INCLUDE() +#if 0 && __has_include() std::strong_ordering operator<=>(const QCborValue &other) const { int c = compare(other); @@ -411,7 +411,7 @@ public: int compare(const QCborValue &other) const { return concrete().compare(other); } -#if 0 && QT_HAS_INCLUDE() +#if 0 && __has_include() std::strong_ordering operator<=>(const QCborValue &other) const { int c = compare(other); diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index c50e087c10..e89caabdb0 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -332,7 +332,7 @@ int qstricmp(const char *str1, const char *str2) return int(Incomplete); }; -#if defined(__SSE4_1__) && !(defined(__SANITIZE_ADDRESS__) || QT_HAS_FEATURE(address_sanitizer)) +#if defined(__SSE4_1__) && !(defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)) enum { PageSize = 4096, PageMask = PageSize - 1 }; const __m128i zero = _mm_setzero_si128(); forever { diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index 7c571706d8..5d8ccbfb1a 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -254,7 +254,7 @@ public: void chop(int n); #if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QSTRING_COMPAT_CPP) && !defined(Q_CLANG_QDOC) -# if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) && !QT_HAS_CPP_ATTRIBUTE(nodiscard) +# if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) && !__has_cpp_attribute(nodiscard) // required due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61941 # pragma push_macro("Q_REQUIRED_RESULT") # undef Q_REQUIRED_RESULT diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 5def2c81a1..1669d7c94a 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -487,7 +487,7 @@ public: Q_REQUIRED_RESULT QString rightJustified(int width, QChar fill = QLatin1Char(' '), bool trunc = false) const; #if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QSTRING_COMPAT_CPP) && !defined(Q_CLANG_QDOC) -# if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) && !QT_HAS_CPP_ATTRIBUTE(nodiscard) +# if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) && !__has_cpp_attribute(nodiscard) // required due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61941 # pragma push_macro("Q_REQUIRED_RESULT") # undef Q_REQUIRED_RESULT diff --git a/src/corelib/thread/qfutex_p.h b/src/corelib/thread/qfutex_p.h index 7bec4554b7..f287b752d7 100644 --- a/src/corelib/thread/qfutex_p.h +++ b/src/corelib/thread/qfutex_p.h @@ -81,7 +81,7 @@ QT_END_NAMESPACE // if not defined in linux/futex.h # define FUTEX_PRIVATE_FLAG 128 // added in v2.6.22 -# if QT_HAS_FEATURE(thread_sanitizer) || defined(__SANITIZE_THREAD__) +# if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__) # include inline void _q_tsan_acquire(void *addr, void *addr2) { @@ -98,7 +98,7 @@ inline void _q_tsan_release(void *addr, void *addr2) # else inline void _q_tsan_acquire(void *, void *) {} inline void _q_tsan_release(void *, void *) {} -# endif // QT_HAS_FEATURE(thread_sanitizer) || defined(__SANITIZE_THREAD__) +# endif // __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__) QT_BEGIN_NAMESPACE namespace QtLinuxFutex { diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h index c693ff65d8..93c4bf23e8 100644 --- a/src/corelib/thread/qmutex.h +++ b/src/corelib/thread/qmutex.h @@ -44,7 +44,7 @@ #include #include -#if QT_HAS_INCLUDE() +#if __has_include() # include # include #endif @@ -147,7 +147,7 @@ public: // Lockable concept bool try_lock() QT_MUTEX_LOCK_NOEXCEPT { return tryLock(); } -#if QT_HAS_INCLUDE() || defined(Q_CLANG_QDOC) +#if __has_include() || defined(Q_CLANG_QDOC) // TimedLockable concept template bool try_lock_for(std::chrono::duration duration) @@ -175,7 +175,7 @@ private: friend class QRecursiveMutex; friend class ::tst_QMutex; -#if QT_HAS_INCLUDE() +#if __has_include() template static int convertToMilliseconds(std::chrono::duration duration) { @@ -213,7 +213,7 @@ public: using QMutex::tryLock; using QMutex::unlock; using QMutex::try_lock; -#if QT_HAS_INCLUDE() +#if __has_include() using QMutex::try_lock_for; using QMutex::try_lock_until; #endif @@ -295,7 +295,7 @@ public: inline void unlock() noexcept {} inline bool isRecursive() const noexcept { return true; } -#if QT_HAS_INCLUDE() +#if __has_include() template inline bool try_lock_for(std::chrono::duration duration) noexcept { diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h index b01ce0db58..aa79e0d4a9 100644 --- a/src/corelib/tools/qalgorithms.h +++ b/src/corelib/tools/qalgorithms.h @@ -535,7 +535,7 @@ QT_DEPRECATED_X("Use std::binary_search") Q_OUTOFLINE_TEMPLATE RandomAccessItera # define QT_HAS_BUILTIN_CTZS Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctzs(quint16 v) noexcept { -# if QT_HAS_BUILTIN(__builtin_ctzs) +# if __has_builtin(__builtin_ctzs) return __builtin_ctzs(v); # else return __builtin_ctz(v); @@ -544,7 +544,7 @@ Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctzs(quint16 v) noexcept #define QT_HAS_BUILTIN_CLZS Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_clzs(quint16 v) noexcept { -# if QT_HAS_BUILTIN(__builtin_clzs) +# if __has_builtin(__builtin_clzs) return __builtin_clzs(v); # else return __builtin_clz(v) - 16U; diff --git a/src/corelib/tools/qscopeguard.h b/src/corelib/tools/qscopeguard.h index 45c3f93da4..40d2747b1d 100644 --- a/src/corelib/tools/qscopeguard.h +++ b/src/corelib/tools/qscopeguard.h @@ -51,7 +51,7 @@ template QScopeGuard qScopeGuard(F f); template class -#if QT_HAS_CPP_ATTRIBUTE(nodiscard) +#if __has_cpp_attribute(nodiscard) // Q_REQUIRED_RESULT can be defined as __warn_unused_result__ or as [[nodiscard]] // but the 1st one has some limitations for example can be placed only on functions. Q_REQUIRED_RESULT @@ -91,7 +91,7 @@ private: template -#if QT_HAS_CPP_ATTRIBUTE(nodiscard) +#if __has_cpp_attribute(nodiscard) Q_REQUIRED_RESULT #endif QScopeGuard qScopeGuard(F f) diff --git a/tests/auto/corelib/global/qglobal/qglobal.c b/tests/auto/corelib/global/qglobal/qglobal.c index c7124454d0..7a2266ae94 100644 --- a/tests/auto/corelib/global/qglobal/qglobal.c +++ b/tests/auto/corelib/global/qglobal/qglobal.c @@ -28,7 +28,7 @@ #include -#if QT_HAS_INCLUDE() || __STDC_VERSION__ >= 199901L +#if __has_include() || __STDC_VERSION__ >= 199901L # include #else # undef true diff --git a/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp b/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp index 4ca68550b9..4e105d7dc7 100644 --- a/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp +++ b/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp @@ -32,7 +32,7 @@ #include #include -#if QT_HAS_INCLUDE() +#if __has_include() # include #endif @@ -519,7 +519,7 @@ void tst_QDeadlineTimer::expire() void tst_QDeadlineTimer::stdchrono() { -#if !QT_HAS_INCLUDE() +#if !__has_include() QSKIP("std::chrono not found on this system"); #else using namespace std::chrono; diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index 8e0bdac520..1bd27cd0ce 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -223,7 +223,7 @@ void tst_QTimer::remainingTimeDuringActivation() namespace { -#if QT_HAS_INCLUDE() +#if __has_include() template std::chrono::milliseconds to_ms(T t) { return std::chrono::duration_cast(t); } @@ -233,7 +233,7 @@ namespace { void tst_QTimer::basic_chrono() { -#if !QT_HAS_INCLUDE() +#if !__has_include() QSKIP("This test requires C++11 support"); #else // duplicates zeroTimer, singleShotTimeout, interval and remainingTime @@ -871,7 +871,7 @@ void tst_QTimer::singleShotToFunctors() void tst_QTimer::singleShot_chrono() { -#if !QT_HAS_INCLUDE() +#if !__has_include() QSKIP("This test requires C++11 support"); #else // duplicates singleShotStaticFunctionZeroTimeout and singleShotToFunctors diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 9e0881f1a6..edb15a8db2 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -45,7 +45,7 @@ #include #include #include -#if QT_HAS_INCLUDE() && __cplusplus >= 201703L +#if __has_include() && __cplusplus >= 201703L #include #endif #include @@ -4992,7 +4992,7 @@ void tst_QVariant::accessSequentialContainerKey() void tst_QVariant::fromStdVariant() { -#if QT_HAS_INCLUDE() && __cplusplus >= 201703L +#if __has_include() && __cplusplus >= 201703L { typedef std::variant intorbool_t; intorbool_t stdvar = 5; diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp index 8deb780dd0..d5a9012f9f 100644 --- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp +++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp @@ -384,7 +384,7 @@ void tst_QCborValue::copyCompare() QCOMPARE(v, other); QVERIFY(!(v != other)); QVERIFY(!(v < other)); -#if 0 && QT_HAS_INCLUDE() +#if 0 && __has_include() QVERIFY(v <= other); QVERIFY(v >= other); QVERIFY(!(v > other)); diff --git a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp index 749aa45916..11f34343ab 100644 --- a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp +++ b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp @@ -89,7 +89,7 @@ enum { waitTime = 100 }; -#if QT_HAS_INCLUDE() +#if __has_include() static Q_CONSTEXPR std::chrono::milliseconds waitTimeAsDuration(waitTime); #endif @@ -100,7 +100,7 @@ void tst_QMutex::convertToMilliseconds_data() QTest::addColumn("intValue"); QTest::addColumn("expected"); -#if !QT_HAS_INCLUDE() +#if !__has_include() QSKIP("This test requires "); #endif @@ -156,7 +156,7 @@ void tst_QMutex::convertToMilliseconds_data() void tst_QMutex::convertToMilliseconds() { -#if !QT_HAS_INCLUDE() +#if !__has_include() QSKIP("This test requires "); #else QFETCH(TimeUnit, unit); @@ -325,7 +325,7 @@ void tst_QMutex::tryLock_non_recursive() } void tst_QMutex::try_lock_for_non_recursive() { -#if !QT_HAS_INCLUDE() +#if !__has_include() QSKIP("This test requires "); #else class Thread : public QThread @@ -454,7 +454,7 @@ void tst_QMutex::try_lock_for_non_recursive() { void tst_QMutex::try_lock_until_non_recursive() { -#if !QT_HAS_INCLUDE() +#if !__has_include() QSKIP("This test requires "); #else class Thread : public QThread @@ -707,7 +707,7 @@ void tst_QMutex::tryLock_recursive() void tst_QMutex::try_lock_for_recursive() { -#if !QT_HAS_INCLUDE() +#if !__has_include() QSKIP("This test requires "); #else class Thread : public QThread @@ -836,7 +836,7 @@ void tst_QMutex::try_lock_for_recursive() void tst_QMutex::try_lock_until_recursive() { -#if !QT_HAS_INCLUDE() +#if !__has_include() QSKIP("This test requires "); #else class Thread : public QThread diff --git a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp index 4b085d387d..88c0c5055c 100644 --- a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp +++ b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp @@ -51,7 +51,7 @@ #ifdef Q_CC_MSVC #define COMPILER_HAS_STDLIB_INCLUDE(x) 1 #else -#define COMPILER_HAS_STDLIB_INCLUDE(x) QT_HAS_INCLUDE(x) +#define COMPILER_HAS_STDLIB_INCLUDE(x) __has_include(x) #endif #if COMPILER_HAS_STDLIB_INCLUDE() diff --git a/tests/benchmarks/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp b/tests/benchmarks/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp index 1d47d98657..8f8e8300a1 100644 --- a/tests/benchmarks/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp +++ b/tests/benchmarks/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp @@ -30,7 +30,7 @@ #include #include #include -#if QT_HAS_INCLUDE() +#if __has_include() #if __cplusplus > 201103L #include #endif -- cgit v1.2.3