MSVC: enforce that we are under /permissive-
MSVC defaults to a C++ dialect which is not standard-compliant. For a number of years, it has offered a switch (/permissive-) to enable standards conformance, but it was entirely opt-in. While we do build (and test) Qt under /permissive-, our users do not necessarily do that for their own software. Meaning, we risk subtle bugs and build issues for the code present in our headers (because users may use them in non-/permissive- mode). This has already happened multiple times (QTBUG-95880, as well as 19b5520abfb5f66d4b83c7a18cc72d68673d098a). So far, we couldn't *enforce* /permissive- for client code, as MSVC didn't deem it stable, and various SDKs (like Windows') were not even building under it. This has now changed. /permissive- is now deemed fully stable and supported, and turned on by default when using /std:c++20 (since VS 2019 16.11 [1]). So, starting from 6.3, we can now pretend its presence. Unfortunately /permissive- does not set any special macros for us to test [2], so test one of its side-effects: that an implicit conversion from std::nullptr_t to bool is ill-formed (the conversion is explicit). [1] https://devblogs.microsoft.com/cppblog/msvc-cpp20-and-the-std-cpp20-switch/ [2] https://developercommunity.visualstudio.com/t/Pre-define-a-macro-when-compiling-under/1253982?space=62&q=permissive-+sfinae&entry=myfeedback [ChangeLog][Platform Specific Changes][Windows] When using MSVC Qt now requires standards compliance mode. This requires passing the /permissive- command line switch. Note that when using C++20 or above, the /permissive- switch is implied by default. Change-Id: I464ed36ff707fa3ada52c543433a6b0ab715748e Reviewed-by: Kai Koehne <kai.koehne@qt.io>
This commit is contained in:
parent
00a5d9f849
commit
0dc6cc0551
@ -97,6 +97,15 @@
|
||||
# endif
|
||||
#endif // __cplusplus
|
||||
|
||||
#if defined(__cplusplus) && defined(Q_CC_MSVC)
|
||||
// On MSVC we require /permissive- set by user code. Check that we are
|
||||
// under its rules -- for instance, check that std::nullptr_t->bool is
|
||||
// not an implicit conversion, as per
|
||||
// https://docs.microsoft.com/en-us/cpp/overview/cpp-conformance-improvements?view=msvc-160#nullptr_t-is-only-convertible-to-bool-as-a-direct-initialization
|
||||
static_assert(!std::is_convertible_v<std::nullptr_t, bool>,
|
||||
"On MSVC you must pass the /permissive- option to the compiler.");
|
||||
#endif
|
||||
|
||||
#if defined (__ELF__)
|
||||
# define Q_OF_ELF
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user