From fdf682e15cd881d478d8b2dc3c2f0a743fc8b5e6 Mon Sep 17 00:00:00 2001 From: Christian Heimlich Date: Thu, 27 Jul 2023 04:58:05 -0400 Subject: [PATCH] Add indirection for QxJson::Converter to better handle if constexpr See note about requirements for the discarded branch with if constexpr. --- lib/core/include/qx/core/qx-json.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/core/include/qx/core/qx-json.h b/lib/core/include/qx/core/qx-json.h index f77cea7c..fceea644 100644 --- a/lib/core/include/qx/core/qx-json.h +++ b/lib/core/include/qx/core/qx-json.h @@ -242,8 +242,7 @@ namespace QxJsonPrivate * false branches are taken. Different compilers seem to discard the untaken * branch of the value dependent statement at different stages as it compiled * fine with MSVC and a newer version of GCC, but not clang or older GCC versions. - * To clarify, compi - * lation would fail due to the type in the not-yet-discarded + * To clarify, compilation would fail due to the type in the not-yet-discarded * branch not being declared. * * Putting the reference of the potentially undeclared types behind these functions @@ -269,6 +268,13 @@ Qx::JsonError performOverrideConversion(T& value, const QJsonValue& jv) { return K::template QxJsonConversionOverride::fromJson(value, jv); } + +template + requires QxJson::json_convertible +Qx::JsonError performRegularConversion(T& value, const QJsonValue& jv) +{ + return QxJson::Converter::fromJson(value, jv); +} /*! @endcond */ } // namespace QxJsonPrivate @@ -335,7 +341,7 @@ struct Converter if constexpr(json_override_convertible) cnvError = QxJsonPrivate::performOverrideConversion(value.*mPtr, mValue); else - cnvError = Converter::fromJson(value.*mPtr, mValue); + cnvError = QxJsonPrivate::performRegularConversion(value.*mPtr, mValue); return !cnvError.isValid(); }() && ...);