From 7e3d0f240599cf89118f0feec6c8c86369e0f9dc Mon Sep 17 00:00:00 2001 From: Schaich Date: Thu, 11 Nov 2021 12:52:24 +0900 Subject: [PATCH] Fix compilation with Qt <= 5.12 The `__has_feature` macro is a clang extension that works like a macro. If zint is being compiled using a compiler other then clang, `__has_feature` is not defined. As it is not defined, it cannot be used as a function call expression. Any environment that doesn't have `__has_feature` should prevent the preprocessor from "seeing" the invokation of the macro, as invoking undefined macros is not supported by the C language. The usual procedure to assure this would be a construction like \#if defined(__has_feature) \# if __has_feature(...) \# endif \#endif which, combined with the GCC check we have here, would result in a 3 level nesting of if and elseif expressions .. and that's without covering microsoft's compiler. For this purpose, Qt >= 5.13 has been defining the `__has_feature` macro on non-clang environments, while defining all (clang) features to not be available. This allows to write feature checks with "less" nesting, as we have here. Mimic Qt-5.13's behavior and provide the `__has_feature` macro if it's not provided otherwise (either by clang or by Qt), allowing the function-call-like expression to be parsed on those systems. --- backend_qt/tests/test_qzint.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend_qt/tests/test_qzint.cpp b/backend_qt/tests/test_qzint.cpp index 13861d47..c2801256 100644 --- a/backend_qt/tests/test_qzint.cpp +++ b/backend_qt/tests/test_qzint.cpp @@ -30,7 +30,10 @@ public: { // Qt5 will trigger "detected memory leaks" if font used (libfontconfig) so skip if ASAN enabled #if QT_VERSION < 0x60000 -# if defined(__SANITIZE_ADDRESS__) || (defined(__has_feature) && __has_feature(address_sanitizer)) +# if !defined(__has_feature) +# define __has_feature(x) 0 +# endif +# if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer) m_skipIfFontUsed = true; # endif #endif