diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2021-05-28 20:01:50 +0200 |
---|---|---|
committer | Kai Koehne <kai.koehne@qt.io> | 2021-09-29 18:01:29 +0000 |
commit | 0dc6cc055174a0556f2e41ca269013b3a7056c86 (patch) | |
tree | 1dfdd7ed5a300fca7a9ad5ae90f0c3461f7c74ec /src/corelib/global | |
parent | 00a5d9f84922e43a6242392de0270d7a77a04b58 (diff) |
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>
Diffstat (limited to 'src/corelib/global')
-rw-r--r-- | src/corelib/global/qglobal.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 429da158d3..fff959505b 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -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 |