QMetaType::id(): Fix ABI breakage

We cannot replace a non-inline method with an inline one without
breaking the ABI. Instead, we now create a version with a dummy int
parameter (to avoid ODR violations), and hide the non-inline version
behind an ifdef, so that it is only visible in qmetatype.cpp.

Pick-to: 6.1
Change-Id: Ib4e82e44071bdf5c37227409a56d377ff2e07ee0
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Fabian Kosmale 2021-03-25 13:59:55 +01:00
parent 547228bf86
commit e05d666d42
3 changed files with 23 additions and 1 deletions

View File

@ -264,6 +264,8 @@ qt_internal_add_module(Core
# special case end
)
qt_update_ignore_pch_source(Core kernel/qmetatype.cpp )
# special case begin
add_dependencies(Core qmodule_pri)
add_dependencies(Core ${QT_CMAKE_EXPORT_NAMESPACE}::moc)

View File

@ -37,7 +37,9 @@
**
****************************************************************************/
#define QT_QMETATYPE_BC_COMPAT 1
#include "qmetatype.h"
#undef QT_QMETATYPE_BC_COMPAT
#include "qmetatype_p.h"
#include "qobjectdefs.h"
#include "qdatetime.h"
@ -489,6 +491,18 @@ bool QMetaType::isRegistered() const
Returns id type hold by this QMetatype instance.
*/
// keep in sync with version in header
// ### Qt 7::remove BC helper
int QMetaType::id() const
{
if (d_ptr) {
if (int id = d_ptr->typeId.loadRelaxed())
return id;
return idHelper();
}
return 0;
}
/*!
\internal
The slowpath of id(). Precondition: d_ptr != nullptr

View File

@ -444,7 +444,12 @@ public:
bool isValid() const;
bool isRegistered() const;
int id() const
#if defined(QT_QMETATYPE_BC_COMPAT)
int id() const;
#else
// ### Qt 7: Remove traces of out of line version
// unused int parameter is used to avoid ODR violation
int id(int = 0) const
{
if (d_ptr) {
if (int id = d_ptr->typeId.loadRelaxed())
@ -453,6 +458,7 @@ public:
}
return 0;
};
#endif
constexpr qsizetype sizeOf() const;
constexpr qsizetype alignOf() const;
constexpr TypeFlags flags() const;