From 0842b01f0269cdd8099a5fbe849c5c2876a0d744 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Thu, 20 Jan 2022 17:01:51 +0100 Subject: QProperty: Work around constexpr issues on MSVC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MSVC complains about illegal uses of void, even though the code should be guarded by an if constexpr statement. qproperty.h(85): error C2182: 'val': illegal use of type 'void' qproperty.h(92): error C2182: 'abstract declarator': illegal use of type 'void' Avoid the issue by using a dedicated dummy type instead of void. Fixes: QTBUG-100072 Task-number: QTQAINFRA-4242 Pick-to: 6.3 6.2 Change-Id: Idc4886c26c3794e709eb762ba836139f720f8133 Reviewed-by: MÃ¥rten Nordheim --- src/corelib/kernel/qpropertyprivate.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/corelib/kernel/qpropertyprivate.h') diff --git a/src/corelib/kernel/qpropertyprivate.h b/src/corelib/kernel/qpropertyprivate.h index 8fe8cc7ff2..ddb09bb119 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(); -- cgit v1.2.3