Skip to content

Commit

Permalink
Add indirection for QxJson::Converter<T> to better handle if constexpr
Browse files Browse the repository at this point in the history
See note about requirements for the discarded branch with if constexpr.
  • Loading branch information
oblivioncth committed Jul 27, 2023
1 parent 4951c7a commit fdf682e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/core/include/qx/core/qx-json.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -269,6 +268,13 @@ Qx::JsonError performOverrideConversion(T& value, const QJsonValue& jv)
{
return K::template QxJsonConversionOverride<N>::fromJson(value, jv);
}

template<typename T>
requires QxJson::json_convertible<T>
Qx::JsonError performRegularConversion(T& value, const QJsonValue& jv)
{
return QxJson::Converter<T>::fromJson(value, jv);
}
/*! @endcond */

} // namespace QxJsonPrivate
Expand Down Expand Up @@ -335,7 +341,7 @@ struct Converter<T>
if constexpr(json_override_convertible<T, mType, mName>)
cnvError = QxJsonPrivate::performOverrideConversion<T, mType, mName>(value.*mPtr, mValue);
else
cnvError = Converter<mType>::fromJson(value.*mPtr, mValue);
cnvError = QxJsonPrivate::performRegularConversion<mType>(value.*mPtr, mValue);

return !cnvError.isValid();
}() && ...);
Expand Down

0 comments on commit fdf682e

Please sign in to comment.