From 647c0e80ed2e190778016c4208b5d6f1f9fd6543 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 15 Feb 2021 12:39:43 +0100 Subject: Enforce __cplusplus >= 201703L on MSVC Client code on MSVC *must* pass /Zc:__cplusplus when using Qt. Otherwise, this makes Qt code that relies on feature-testing macros a mess. For instance, in QTBUG-91117, we trip on this code: // C++ version guard is necessary: you may have the header, // but including it in pre-C++20 will cause an hard error #if __has_include() && __cplusplus > 201703L #include #endif #if defined(__cpp_lib_bitops) // use some functionality #endif The #define __cpp_lib_bitops should've come from the preceding include directive, but there's another possibility: that it comes from (or some other similar header) included transitively, when compiling in C++20 mode, and *without* a bumped __cplusplus. Yes, that's an actual possibility on MSVC. Then, since we did not include ourselves due to the __cplusplus version check, using the functionality will cause a compile error. We're not going to fix *every* post C++-17 feature detection macro because of MSVC and feature-test shenanigans. It's time to require compilers to tell us the truth about what they support. Fixes: QTBUG-91117 Change-Id: I9d74f9d8b74b5ac35dce3528e7a2006746a00676 Reviewed-by: Thiago Macieira Reviewed-by: Kai Koehne --- src/corelib/global/qglobal.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/corelib/global/qglobal.h') diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index d546f19cb8..2fadc6d83b 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -86,6 +86,16 @@ #include #include +// This could go to the very beginning of this file, but we're using compiler +// detection, so it's here. +#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 (__ELF__) # define Q_OF_ELF #endif -- cgit v1.2.3