[Development] QProperty and library coding guide

Thiago Macieira thiago.macieira at intel.com
Fri Jul 17 19:55:53 CEST 2020

On Wednesday, 15 July 2020 13:20:33 PDT Thiago Macieira wrote:
> In addition, I'd like someone to explain here:

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.

In the process, please also fix this code:

    auto prop = object->propertyName;
    return prop.value();

Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel System Software Products

More information about the Development mailing list