diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2022-01-20 17:01:51 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2022-01-23 23:11:50 +0100 |
commit | 0842b01f0269cdd8099a5fbe849c5c2876a0d744 (patch) | |
tree | 3babb6f6cad2d8a27cc972c1d2a9f805c26c97cb /src | |
parent | 228b5dd0741512bfa3796c9388169cc12617b823 (diff) |
QProperty: Work around constexpr issues on MSVC
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 <marten.nordheim@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qpropertyprivate.h | 12 |
1 files changed, 9 insertions, 3 deletions
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<typename Callable, typename PropertyType=void> + template<typename Callable, typename PropertyType=MSVCWorkAround> 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<bool, Callable, QMetaType, QUntypedPropertyData *> ); auto untypedEvaluationFunction = static_cast<Callable *>(f); return std::invoke(*untypedEvaluationFunction, metaType, dataPtr); - } else if constexpr (!std::is_same_v<PropertyType, void>) { // check for void to workaround MSVC issue + } else if constexpr (!std::is_same_v<PropertyType, MSVCWorkAround>) { Q_UNUSED(metaType); QPropertyData<PropertyType> *propertyPtr = static_cast<QPropertyData<PropertyType> *>(dataPtr); // That is allowed by POSIX even if Callable is a function pointer @@ -232,7 +238,7 @@ struct BindingFunctionVTable } }; -template<typename Callable, typename PropertyType=void> +template<typename Callable, typename PropertyType=MSVCWorkAround> inline constexpr BindingFunctionVTable bindingFunctionVTable = BindingFunctionVTable::createFor<Callable, PropertyType>(); |