diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 18851cd120..bc13d516e6 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1167,6 +1167,10 @@ constexpr std::underlying_type_t qToUnderlying(Enum e) noexcept #ifdef __cpp_constinit # define Q_CONSTINIT constinit +# if defined(Q_CC_MSVC) && !defined(Q_CC_CLANG) + // https://developercommunity.visualstudio.com/t/C:-constinit-for-an-optional-fails-if-/1406069 +# define Q_THREAD_LOCAL_CONSTINIT +# endif #elif defined(__has_cpp_attribute) && __has_cpp_attribute(clang::require_constant_initialization) # define Q_CONSTINIT [[clang::require_constant_initialization]] #elif defined(Q_CC_GNU) && Q_CC_GNU >= 1000 @@ -1175,6 +1179,10 @@ constexpr std::underlying_type_t qToUnderlying(Enum e) noexcept # define Q_CONSTINIT #endif +#ifndef Q_THREAD_LOCAL_CONSTINIT +# define Q_THREAD_LOCAL_CONSTINIT Q_CONSTINIT +#endif + template inline T *qGetPtrHelper(T *ptr) noexcept { return ptr; } template inline auto qGetPtrHelper(Ptr &ptr) noexcept -> decltype(ptr.get()) { static_assert(noexcept(ptr.get()), "Smart d pointers for Q_DECLARE_PRIVATE must have noexcept get()"); return ptr.get(); } diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp index 297a672d6a..67c55e56aa 100644 --- a/src/corelib/kernel/qproperty.cpp +++ b/src/corelib/kernel/qproperty.cpp @@ -198,7 +198,7 @@ struct QPropertyDelayedNotifications } }; -Q_CONSTINIT static thread_local QBindingStatus bindingStatus; +Q_THREAD_LOCAL_CONSTINIT static thread_local QBindingStatus bindingStatus; /*! \since 6.2