diff --git a/src/corelib/kernel/qpropertyprivate.h b/src/corelib/kernel/qpropertyprivate.h index 8fe8cc7ff23..ddb09bb1196 100644 --- a/src/corelib/kernel/qpropertyprivate.h +++ b/src/corelib/kernel/qpropertyprivate.h @@ -184,6 +184,12 @@ struct QPropertyProxyBindingData namespace QtPrivate { struct BindingEvaluationState; +/* used in BindingFunctionVTable::createFor; on all other compilers, void would work, but on + MSVC this causes C2182 when compiling in C++20 mode. As we only need to provide some default + value which gets ignored, we introduce this dummy type. +*/ +struct MSVCWorkAround {}; + struct BindingFunctionVTable { using CallFn = bool(*)(QMetaType, QUntypedPropertyData *, void *); @@ -194,7 +200,7 @@ struct BindingFunctionVTable const MoveCtrFn moveConstruct; const qsizetype size; - template + template static constexpr BindingFunctionVTable createFor() { static_assert (alignof(Callable) <= alignof(std::max_align_t), "Bindings do not support overaligned functors!"); @@ -205,7 +211,7 @@ struct BindingFunctionVTable static_assert (std::is_invocable_r_v ); auto untypedEvaluationFunction = static_cast(f); return std::invoke(*untypedEvaluationFunction, metaType, dataPtr); - } else if constexpr (!std::is_same_v) { // check for void to workaround MSVC issue + } else if constexpr (!std::is_same_v) { Q_UNUSED(metaType); QPropertyData *propertyPtr = static_cast *>(dataPtr); // That is allowed by POSIX even if Callable is a function pointer @@ -232,7 +238,7 @@ struct BindingFunctionVTable } }; -template +template inline constexpr BindingFunctionVTable bindingFunctionVTable = BindingFunctionVTable::createFor();