[Development] QProperty and library coding guide

Oswald Buddenhagen oswald.buddenhagen at gmx.de
Sun Jul 19 12:51:00 CEST 2020


On Sat, Jul 18, 2020 at 10:10:41AM -0700, Thiago Macieira wrote:
>On Friday, 17 July 2020 23:32:41 PDT Simon Hausmann wrote:
>> 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 
>
>The problem here is the damage that can happen if a breakage happens.
>
i can think of only two ways how this can stop working:
- the compiler becomes intentionally belligerent, in which case an 
   override switch will be provided as well (if not instantly, then after 
   the outcry that immediately follows)
- the compiler somehow starts to actually make use of the freedom 
   granted by the fact that QObject is not standard-layout (this, btw, is 
   also the reason why peppe's suggestion to use offsetof doesn't fix 
   UB). however, this would also come with a massive BC break, in which 
   case we'd have bigger problems anyway. so it's guaranteed that a 
   compat switch would be provided as well, exactly because much code 
   wants to stay BC. anyway, i consider this case entirely hypothetical, 
   as there is no reason to break this when compiling for real hardware 
   (or something that resembles it, like wasm, afaik); it might be 
   different for some vms.

>So what's the [efficient] non-UB solution?
>
<insert your brilliant idea here> ;-)


More information about the Development mailing list