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 ++++++++++++++++----------------- 1 file changed, 37 insertions(+), 40 deletions(-) (limited to 'src/corelib/global/qcompilerdetection.h') 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 -- cgit v1.2.3