[Development] QProperty and library coding guide

Thiago Macieira thiago.macieira at intel.com
Wed Jul 22 01:50:54 CEST 2020


On Tuesday, 21 July 2020 16:13:52 PDT Thiago Macieira wrote:
> The memcpys qualify under all of those conditions, with even explicit
> workarounds in the compilers. I don't see why you think qobject_cast has UB;
> did you mean qFindChildren?

I also want to make a distinction based on the potential danger.

UB inside the library, where we control the conditions of build and can apply 
compiler-flag workarounds have limited damage. We can patch it with proper 
code if we find out we had broken code.

UB where there's a different, albeit possibly slower, implementation in case 
we were wrong have limited damage.

In this particular case, however, we have:
a) code that is present in user's applications (generated by moc)
b) compiler under the user's compiler settings
c) with limited ability to apply workarounds for

This is a very large damage if conditions change.

It's very different to detect we've had UB all along from jumping with both 
feet into a new one.

At least we have found a possible workaround, which is to write the 
subtraction in assembly, thereby hiding from the compiler and denying it any 
ability to optimise things incorrectly. (which is kind of dumb, because we 
don't want the code to add and subtract the same quantity, wasting two cycles; 
see https://godbolt.org/z/PvK987).

I'm just trying to find out if there's a better way so we don't have to throw 
this design out.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel DPG Cloud Engineering





More information about the Development mailing list