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>
This commit is contained in:
parent
65b4937f34
commit
647c0e80ed
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user