diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2021-02-15 12:39:43 +0100 |
---|---|---|
committer | Kai Koehne <kai.koehne@qt.io> | 2021-03-22 19:57:07 +0000 |
commit | 647c0e80ed2e190778016c4208b5d6f1f9fd6543 (patch) | |
tree | db4161ce0da22f078d09f9951d8ec06984332033 /src/corelib/global/qglobal.h | |
parent | 65b4937f341134fbb1082050b7ae8ecf5c0ba564 (diff) |
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(<bit>) && __cplusplus > 201703L
#include <bit>
#endif
#if defined(__cpp_lib_bitops)
// use some <bit> functionality
#endif
The #define __cpp_lib_bitops should've come from the preceding include
directive, but there's another possibility: that it comes from
<version> (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 <bit> 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 <thiago.macieira@intel.com>
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Diffstat (limited to 'src/corelib/global/qglobal.h')
-rw-r--r-- | src/corelib/global/qglobal.h | 10 |
1 files changed, 10 insertions, 0 deletions
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 <QtCore/qprocessordetection.h> #include <QtCore/qcompilerdetection.h> +// 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 |