Skip to content

Do not drop QAbstractItemModel::setRoleNames from liblightdm mock

When you're building a library which is to be a drop-in replacement for a library, you cannot override a method which is not overridden in the target library [1], as it breaks compilers' devirtualization.

See, if the compiler can proof that a pointer is of a certain type, it can skip looking up the virtual table and directly call what the virtual table would point to. In this case, QAbstractItemModel classes inside liblightdm does not re-implement QAbstractItemModel::roleNames(), so the compiler is free to directly call the base class' roleNames() implementation, bypassing our mock class' roleNames() method.

Thus, we cannot safely re-implement roleNames() in mocked liblightdm, and has to use QAbstractItemModel::setRoleNames() in the same way that the real liblightdm does.

I was going to go as far as removing the Mock* headers which have the equivalent in the real liblightdm, however they contain helper methods on the mocked classes themselves, which is safe to do but make removing the headers more complicated, so I didn't bother.

As for liblightdm inside IntegratedLightDM QML plugin, the build process does not involve the real liblightdm at all, but instead has all files statically linked into the QML plugin. Thus it's safe to reimplement roleNames() there.

This paritally reverts commit 48dbd8cc.

[1]: or at least, in the original library's header files.

Merge request reports