JNI: remove implicit conversion of declared QtJniTypes to jobject
It's dangerous, as it results in implicit conversion to void * or bool, while hiding the object life time implications. Such objects are QJniObject subclasses, so make sure we don't end up in the catch-all assignment operator when assigning. Constrain that operator to types that are convertible to jobject. Change-Id: If31761c00a678490eeb0b2b038e89e78d8a51747 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>bb10
parent
8c9f5fba03
commit
180c7698e2
|
|
@ -534,7 +534,8 @@ public:
|
|||
// This function takes ownership of the jobject and releases the local ref. before returning.
|
||||
static QJniObject fromLocalRef(jobject lref);
|
||||
|
||||
template <typename T>
|
||||
template <typename T,
|
||||
std::enable_if_t<std::is_convertible_v<T, jobject>, bool> = true>
|
||||
QJniObject &operator=(T obj)
|
||||
{
|
||||
assign(static_cast<T>(obj));
|
||||
|
|
|
|||
|
|
@ -21,8 +21,6 @@ template<typename Type>
|
|||
struct Object : QJniObject
|
||||
{
|
||||
using Class = Type;
|
||||
operator jobject() const noexcept { return object(); }
|
||||
|
||||
Q_IMPLICIT Object(jobject object) : QJniObject(object) {}
|
||||
Q_IMPLICIT Object(const QJniObject &object) : QJniObject(object) {}
|
||||
Q_IMPLICIT Object(QJniObject &&object) : QJniObject(std::move(object)) {}
|
||||
|
|
|
|||
Loading…
Reference in New Issue