Add [[gsl::Owner]] to std::shared_ptr?
Opened this issue · 2 comments
We currently do not hardcode the gsl::Owner attribute for std::shared_ptr. When removing the force-template-instantiation hack from the type categorization, std::shared_ptr will also not be recognized as an Owner there.
This breaks two example sfrom the paper/warn-lifetime-godbolt.cpp
: https://godbolt.org/z/UE-Mb0 https://godbolt.org/z/1xAGOH
But should std::shared_ptr really be an Owner? Our current description of an Owner is: "After the Owner is destroyed, Pointers into the Owner dangle", but this is not true for shared_ptrs, where Pointers into the Owner might be still good due to other shared_ptrs that keep them alive.
To avoid false-positives, I'm currently leaning towards not adding [[gsl::Owner]] to std::shared_ptr.
fyi @Xazax-hun
I think Herb has a very opinionated view on this such that if you know for sure another shared pointer is keeping the thing alive you should not have used a shared pointer in the first place. But to reduce noise, it is definitely better not to add shared_ptr
. We can ask him tomorrow.
The examples from the paper in warn-lifetime-godbolt.cpp are now fixed.