[Interest] QSharedDataPointer detach too much ( don't call const )
Giuseppe D'Angelo
giuseppe.dangelo at kdab.com
Thu Sep 20 13:01:36 CEST 2018
On 20/09/18 12:43, Michal Lazo wrote:
> "So my whole C++ world just changed."
> Can you point me to right article in C++ documentation ?
http://eel.is/c++draft/over.match
See in particular [over.match.funcs] ยง11.3.1.4 , and then you need to
reason about the implications for the overload resolution.
> So Qt devs I found some code for example
> http://code.qt.io/cgit/qt/qtbase.git/tree/src/gui/text/qtextcursor.cpp#n1151
> And it looks like it should be better to call const variant
> what do you think ??
Possibly, but what's the big drama about that line?
It's not a mistery that QSharedDataPointer is very prone to "accidental"
detaches, so its usage is frowned upon in new code, in favour of
QExplictlySharedDataPointer (which however requires manual calls to
detach(), and one needs to remember about them).
For instance, in a setter such as
> void MyClass::setFoo(int newFoo) {
> if (d->foo == newFoo)
> return;
> d->foo = newFoo;
> }
(assuming d is a QSharedDataPointer<MyClassPrivate>) the d->foo access
in the if is supposed to be "readonly", yet it happily detaches the
private, even if the new value passed to the setter is identical to the
old value and thus one might expect that nothing needs to be done.
(No, noone is porting QTextCursor away from QSharedDataPointer at this
moment in time.)
My 2 c,
--
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4007 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180920/0b60633d/attachment.bin>
More information about the Interest
mailing list