[Development] gsl::owner (Was: Setters: Clarifying the ownership)

Иван Комиссаров abbapoh at gmail.com
Tue Jul 31 20:35:23 CEST 2018


I prefer the solution from the thread "unique_ptr and Qt" about using smart pointers for transferring ownership explicitly. We can use std::observer_ptr from c++20 to indicate the places that do not take ownership.
I think, using gsl::owner is a wrong way of doing things, it's the way that can be source and (maybe) binary compatible, but that's a workaround, not a solution.
However, the solution can require too much work to do.

Иван Комиссаров

> 31 июля 2018 г., в 16:04, Eric Lemanisser <eric.lemanissier at gmail.com> написал(а):
> 
> Please, don't introduce another type alias. It would loose the advantage of static analysis like http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-owning-memory.html
> 
>> Le mar. 31 juil. 2018 à 14:52, Giuseppe D'Angelo via Development <development at qt-project.org> a écrit :
>> Hi,
>> 
>> On 31/07/18 13:11, Sérgio Martins via Development wrote:
>> > I would recommend however that our docs show T* instead of gsl::owner<T>
>> > and continue to include "Takes ownership of foo" in the text.
>> > While I believe in self-documenting signatures I think it's too much
>> > noise and hurts readability, and most devs never heard of gsl.
>> > 
>> > Should be just an aid for tooling IMO.
>> 
>> I agree with the rest of your email, but I kind of disagree with this 
>> particular point, for different reasons:
>> 
>> 
>> * Because we need to educate our users that there's more C++ than Qt out 
>> there, and the Core Guidelines and the GSL are a fundamental part of 
>> knowledge for a C++ developer.
>> 
>> * Even if we consider talking about the GSL too much of a "distraction" 
>> in the docs, we can simply add our own qOwner type alias, with identical 
>> semantics, and document what it does and what it means in signatures.
>> 
>> * Leaving gsl::owner in the signature of a function documentation can 
>> help clarify situations where the textual documentation does not say 
>> anything about the ownership. At least, it's one more safeguard against 
>> adding functions that take/return pointers and don't clearly document 
>> the ownership.
>> 
>> 
>> However, from a practical point of view, unless someone adds gsl::owner 
>> _everywhere_ to Qt, we can't report it in the docs, as they would 
>> otherwise be inconsistent :-(
>> 
>> 
>> 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
>> 
>> _______________________________________________
>> Development mailing list
>> Development at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/development
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20180731/d2bd08af/attachment.html>


More information about the Development mailing list