Il 19/07/20 20:42, Thiago Macieira ha scritto:
In that sense, Peppe's suggestion of C++17 offsetof is better.

To clarify, I was proposing to do something like this:

Type Klass::_qt_property_api_propertyName::value() const
{
    /*1*/ const size_t propertyMemberOffset = 
reinterpret_cast<size_t>(&(static_cast<Klass *>(nullptr)->propertyName));
    /*2*/ const auto *thisPtr = reinterpret_cast<const Klass 
*>(reinterpret_cast<const char *>(this) - propertyMemberOffset);
    return thisPtr->d_func()->property.value();
}

* change /*1*/ become offsetof(Klass, propertyName);

* change /*2*/ to use ASM. We know the ABI of the platforms we support and we know how to calculate the correct pointer value, we just need to stop C/C++ from reason about it and flagging it as possible UB. Yes, it's a crude hack... :(

My 2 c,
--
Giuseppe D'Angelo | giuseppe.dang...@kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

Attachment: smime.p7s
Description: Firma crittografica S/MIME

_______________________________________________
Development mailing list
Development@qt-project.org
https://lists.qt-project.org/listinfo/development

Reply via email to