[Development] QProperty and library coding guide

Simon Hausmann hausmann at gmail.com
Sat Jul 18 08:32:41 CEST 2020


Hi,

Thiago Macieira <thiago.macieira at intel.com> schrieb am Fr. 17. Juli 2020 um
19:57:

> On Wednesday, 15 July 2020 13:20:33 PDT Thiago Macieira wrote:
> > In addition, I'd like someone to explain here:
> [snip]
>
> 5) How you're going to fix the UB in the code generated by moc. This
> requires
> a satisfactory answer of C++17 or C++2a strictly compliant code, or we'll
> have
> to stop using this feature.
>
> moc generates:
>
> Type Klass::_qt_property_api_propertyName::value() const
> {
>     const size_t propertyMemberOffset =
>      reinterpret_cast<size_t>(&(static_cast<Klass
> *>(nullptr)->propertyName));
>     const auto *thisPtr = reinterpret_cast<const Klass *>(
>         reinterpret_cast<const char *>(this) - propertyMemberOffset);
>     return thisPtr->d_func()->property.value();
> }
>
> The first two lines of this function are UB.
>
> It MUST be fixed.
>

This hack has been in QtQml in production since its release in 2010 (see
static cast selector).

It would be a shame if this stopped working :-/


Simon



>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20200718/768f94b8/attachment.html>


More information about the Development mailing list