[Development] Requesting forward BC exception for QtWaylandCompositor in 6.2 and 5.15

Lars Knoll lars.knoll at qt.io
Wed Feb 16 09:11:05 CET 2022

Hi Marc,

Two questions:

* Is there a work-around for the developers with the current state, e.g. by adding some casts?
* Could you add the missing operators inline, so they don’t add new symbols?


On 15 Feb 2022, at 16:54, Marc Mutz <marc.mutz at qt.io<mailto:marc.mutz at qt.io>> wrote:



The QWaylandBufferRef class has a very annoying bug in that its relational operators cannot compare `const` objects (only on the RHS). That's because these operators are implemented as members, but are not const. Since they're not const, they cannot be called with a const LHS...

That's the C++98 picture.

In C++20, the reversed version of these operators is also considered, which fixes (const == mutable), but makes mutable OP mutable ambiguous (hard error, not a warning).

This makes the operators all but useless in C++20, and awkward to use (swapping RHS and LHS, const_cast'ing) before that.

For Qt 6.3+, we can fix this by QT_REMOVED_SINCE the member and adding an exported friend op==(const, const): https://codereview.qt-project.org/c/qt/qtwayland/+/395784 This is backwards BC. For 6.2 and 5.15, forwards BC is required, though (no new symbols, unless fixing code that didn't compile before).

The problem now is that even if I make use of the didn't-compile-before exception, I still need to add overloads that at least a C++20 compiler would use in lieu of reversed signatures, breaking forward BC also for code that, without the fix, would have compiled.


    const QWaylandBufferRef lhs; QWaylandBufferRef rhs;
    lhs == rhs; // OK in C++20, fails in C++ < 20

The last expression currently calls the reversed member-op==. If I add the missing overloads, then it would instead call one of those, one it will not find when going back to an older Qt version. I cannot add the missing overloads as free unexported functions, because the member operator hides them and because at least the const, const overloads need to be out-of-line (const_cast is a UB when performed on an object originally declared const), or else we need to break the class' encapsulation by making it inline.

So, I'd like to ask for permission to add the full set of {mut, const} × {==, !=} × {mut, const} to 6.2 and 5.15 (two are present, so six are missing), and then rebasinghttps://codereview.qt-project.org/c/qt/qtwayland/+/395784 onto it to replace this hotfix with the real deal. I cannot use QT_REMOVED_SINCE in 6.2, as it's only available from 6.3.

If, after all this, the answer is that QtWaylandCompositor isn't under BC constraints, then at least you have learned how terribly complicated such glitches can become.

If you wish to apply your own gray matter to the problem, https://codereview.qt-project.org/c/qt/qtwayland/+/395783 contains just the test, to be passed in both C++17 and C++20 modes.


Marc Mutz
Principal Software Engineer
The Qt Company
Erich-Thilo-Str. 10 12489
Berlin, Germany
marc.mutz at qt.io<mailto:marc.mutz at qt.io>
Geschäftsführer: Mika Pälsi, Juha Varelius, Jouni Lintunen
Sitz der Gesellschaft: Berlin,
Registergericht: Amtsgericht Charlottenburg,
HRB 144331 B
[https://s3.eu-north-1.amazonaws.com/email-signature-tool-leroy/facebook.png]<https://www.facebook.com/qt/>     [https://s3.eu-north-1.amazonaws.com/email-signature-tool-leroy/twitter.png] <https://twitter.com/qtproject>    [https://s3.eu-north-1.amazonaws.com/email-signature-tool-leroy/linkedin.png] <https://www.linkedin.com/company/the-qt-company/>        [https://s3.eu-north-1.amazonaws.com/email-signature-tool-leroy/youtube.png] <https://www.youtube.com/QtStudios>

Development mailing list
Development at qt-project.org<mailto:Development at qt-project.org>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20220216/2780eaec/attachment-0001.htm>

More information about the Development mailing list