fix(data): fix locked_ptr assignement operator and ambiguous ctor
Description
sight::data::mt::locked_ptr
assignment operator and ctor currently have several issues that, I believe, originate from the recent renaming pass:
-
using Lock = ...;
got formatted intousing lock = ...;
, which causes a compile error. -
boost::shared_lock
andboost::unique_lock
no longer have a member function namedreset()
(I am not sure why this worked before) -
operator=
is ambiguous when calling it with a prvalue / an xvalue (such as one obtained bymake_shared
). This is becauseweak_ptr
ctor is notexplicit
.
Steps to reproduce
See get-the-error.patch.
Diagnostic by gcc 11.4
:
Click to expand
/home/eduhamel/git/git.ircad.fr/sight/sight/modules/viz/scene3d/adaptor/volume_render.cpp: In member function ‘virtual void sight::module::viz::scene3d::adaptor::volume_render::starting()’:
/home/eduhamel/git/git.ircad.fr/sight/sight/modules/viz/scene3d/adaptor/volume_render.cpp:174:31: error: ambiguous overload for ‘operator=’ (operand types are ‘sight::data::mt::locked_ptr<const sight::data::transfer_function>’ and ‘std::remove_reference<std::shared_ptr<sight::data::transfer_function>&>::type’ {aka ‘std::shared_ptr<sight::data::transfer_function>’})
174 | tf = std::move(ptr);
| ^
In file included from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/__/service/base.hpp:33,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/__/service/macros.hpp:25,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/__/service/op.hpp:24,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/__/service/has_services.hpp:29,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/viz/scene3d/compositor/chain_manager.hpp:25,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/viz/scene3d/layer.hpp:33,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/viz/scene3d/render.hpp:26,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/viz/scene3d/adaptor.hpp:26,
from /home/eduhamel/git/git.ircad.fr/sight/sight/modules/viz/scene3d/adaptor/volume_render.hpp:27,
from /home/eduhamel/git/git.ircad.fr/sight/sight/modules/viz/scene3d/adaptor/volume_render.cpp:23:
/home/eduhamel/git/git.ircad.fr/sight/sight/libs/__/data/mt/locked_ptr.hpp:87:27: note: candidate: ‘constexpr sight::data::mt::locked_ptr<DATATYPE>& sight::data::mt::locked_ptr<DATATYPE>::operator=(const std::shared_ptr<_Tp>&) [with DATATYPE = const sight::data::transfer_function]’
87 | constexpr locked_ptr& operator=(const std::shared_ptr<DATATYPE>& _data) noexcept
| ^~~~~~~~
/home/eduhamel/git/git.ircad.fr/sight/sight/libs/__/data/mt/locked_ptr.hpp:121:27: note: candidate: ‘constexpr sight::data::mt::locked_ptr<DATATYPE>& sight::data::mt::locked_ptr<DATATYPE>::operator=(const std::weak_ptr<_Tp>&) [with DATATYPE = const sight::data::transfer_function]’
121 | constexpr locked_ptr& operator=(const std::weak_ptr<DATATYPE>& _data) noexcept
| ^~~~~~~~
/home/eduhamel/git/git.ircad.fr/sight/sight/modules/viz/scene3d/adaptor/volume_render.cpp:175:18: error: ambiguous overload for ‘operator=’ (operand types are ‘sight::data::mt::locked_ptr<const sight::data::transfer_function>’ and ‘std::shared_ptr<sight::data::transfer_function>’)
175 | tf = ptr;
| ^~~
In file included from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/__/service/base.hpp:33,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/__/service/macros.hpp:25,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/__/service/op.hpp:24,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/__/service/has_services.hpp:29,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/viz/scene3d/compositor/chain_manager.hpp:25,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/viz/scene3d/layer.hpp:33,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/viz/scene3d/render.hpp:26,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/viz/scene3d/adaptor.hpp:26,
from /home/eduhamel/git/git.ircad.fr/sight/sight/modules/viz/scene3d/adaptor/volume_render.hpp:27,
from /home/eduhamel/git/git.ircad.fr/sight/sight/modules/viz/scene3d/adaptor/volume_render.cpp:23:
/home/eduhamel/git/git.ircad.fr/sight/sight/libs/__/data/mt/locked_ptr.hpp:87:27: note: candidate: ‘constexpr sight::data::mt::locked_ptr<DATATYPE>& sight::data::mt::locked_ptr<DATATYPE>::operator=(const std::shared_ptr<_Tp>&) [with DATATYPE = const sight::data::transfer_function]’
87 | constexpr locked_ptr& operator=(const std::shared_ptr<DATATYPE>& _data) noexcept
| ^~~~~~~~
/home/eduhamel/git/git.ircad.fr/sight/sight/libs/__/data/mt/locked_ptr.hpp:121:27: note: candidate: ‘constexpr sight::data::mt::locked_ptr<DATATYPE>& sight::data::mt::locked_ptr<DATATYPE>::operator=(const std::weak_ptr<_Tp>&) [with DATATYPE = const sight::data::transfer_function]’
121 | constexpr locked_ptr& operator=(const std::weak_ptr<DATATYPE>& _data) noexcept
| ^~~~~~~~
/home/eduhamel/git/git.ircad.fr/sight/sight/modules/viz/scene3d/adaptor/volume_render.cpp:177:67: error: ambiguous overload for ‘operator=’ (operand types are ‘sight::data::mt::locked_ptr<const sight::data::transfer_function>’ and ‘std::shared_ptr<sight::data::transfer_function>’)
177 | tf = std::make_shared<sight::data::transfer_function>();
| ^
In file included from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/__/service/base.hpp:33,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/__/service/macros.hpp:25,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/__/service/op.hpp:24,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/__/service/has_services.hpp:29,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/viz/scene3d/compositor/chain_manager.hpp:25,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/viz/scene3d/layer.hpp:33,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/viz/scene3d/render.hpp:26,
from /home/eduhamel/git/git.ircad.fr/sight/sight/libs/viz/scene3d/adaptor.hpp:26,
from /home/eduhamel/git/git.ircad.fr/sight/sight/modules/viz/scene3d/adaptor/volume_render.hpp:27,
from /home/eduhamel/git/git.ircad.fr/sight/sight/modules/viz/scene3d/adaptor/volume_render.cpp:23:
/home/eduhamel/git/git.ircad.fr/sight/sight/libs/__/data/mt/locked_ptr.hpp:87:27: note: candidate: ‘constexpr sight::data::mt::locked_ptr<DATATYPE>& sight::data::mt::locked_ptr<DATATYPE>::operator=(const std::shared_ptr<_Tp>&) [with DATATYPE = const sight::data::transfer_function]’
87 | constexpr locked_ptr& operator=(const std::shared_ptr<DATATYPE>& _data) noexcept
| ^~~~~~~~
/home/eduhamel/git/git.ircad.fr/sight/sight/libs/__/data/mt/locked_ptr.hpp:121:27: note: candidate: ‘constexpr sight::data::mt::locked_ptr<DATATYPE>& sight::data::mt::locked_ptr<DATATYPE>::operator=(const std::weak_ptr<_Tp>&) [with DATATYPE = const sight::data::transfer_function]’
121 | constexpr locked_ptr& operator=(const std::weak_ptr<DATATYPE>& _data) noexcept
| ^~~~~~~~
Proposal
See this patch: save-locked-ptr.patch
TL;DR:
- Pass by value and perform explicit
std::move
when necessary. When passing by const reference, we already perform a copy upon call toshared_ptr::operator=(const shared_ptr&)
(resp. with its constructor) any way. The behaviour will not change. - Remove
operator=()
accepting aweak_ptr
. This overload is unused (AFAIK) and I believe anyone should be able to calldata = a_weak.lock();
Functional specifications
- Possible to use
operator=
oflocked_ptr
. - Disambiguation of the
ctor
s andoperator=
.
Technical specifications
Details of the implementation of the fix
Test plan
Unit testing. Add a new one in data_test
.