JNI: make converting QJniArray constructors explicit

Amend 80d4d55e25. It should not be
possible to convert a QJniArray<jobject> to e.g. a QJniArray<jstring>,
so SFINAE out any construction that would convert between unconvertible
element types. To prevent the fall-back to constructing from QJniObject,
make those constructors explicit, which they should have been anyway.

Change-Id: I17fd9dfcea425a7bfa34d7bef736bab2be42a536
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
Volker Hilsheimer 2023-10-19 15:12:29 +02:00
parent 66b5803ab9
commit 8cf199077f

View File

@ -70,16 +70,16 @@ class QJniArrayBase : public QJniObject
> : std::true_type {};
public:
QJniArrayBase(jarray array)
explicit QJniArrayBase(jarray array)
: QJniObject(static_cast<jobject>(array))
{
static_assert(sizeof(QJniArrayBase) == sizeof(QJniObject),
"QJniArrayBase must have the same size as QJniObject!");
}
QJniArrayBase(const QJniObject &object)
explicit QJniArrayBase(const QJniObject &object)
: QJniObject(object)
{}
QJniArrayBase(QJniObject &&object) noexcept
explicit QJniArrayBase(QJniObject &&object) noexcept
: QJniObject(std::move(object))
{}
@ -157,6 +157,12 @@ public:
, std::enable_if_t<QJniArrayBase::CanConvert<Container>, bool> = true
>
explicit QJniArray(Container &&container);
template <typename Other, std::enable_if_t<std::is_convertible_v<Other, Type>, bool> = true>
QJniArray(QJniArray<Other> &&other)
: QJniArrayBase(std::forward<QJniArray<Other>>(other))
{
}
~QJniArray() = default;
auto arrayObject() const