MantisBT - VCMI
View Issue Details
0003142VCMIOtherpublic2020-10-01 00:002021-01-25 22:38
jambolo 
MikeLodz 
normalminorhave not tried
resolvedfixed 
 
1.next 
0003142: Use of const std::shared_ptr
There are several instances of "const std:shared_ptr<...>" in the code. There is generally no good reason for const.

I suspect that in many cases the intention is to prevent modification of the referenced object. In those cases, "const std:shared_ptr<...>" could be changed to "std:shared_ptr<const ...>"

There are also many cases of "const TBonusListPtr" where TBonusListPtr is defined elsewhere by "typedef std::shared_ptr<BonusList> TBonusListPtr". These may have the same issue. In these cases, the following may be better:

typedef std::shared_ptr<const BonusList> TConstBonusListPtr


Note that "const std:shared_ptr<...> &" is a valid use of const.
vcmi\source\lib\battle\CBattleInfoCallback.cpp(752)
vcmi\source\lib\battle\CBattleInfoCallback.cpp(775)
vcmi\source\lib\CGameState.cpp(1901)
vcmi\source\lib\CHeroHandler.cpp(595)
vcmi\source\lib\CStack.cpp(145)
vcmi\source\lib\HeroBonus.cpp(384)
vcmi\source\lib\HeroBonus.cpp(385)
vcmi\source\lib\HeroBonus.cpp(497)
vcmi\source\lib\HeroBonus.cpp(781)
vcmi\source\lib\HeroBonus.cpp(803)
vcmi\source\lib\HeroBonus.cpp(939)
vcmi\source\lib\HeroBonus.cpp(2129)
vcmi\source\lib\HeroBonus.cpp(2152)
vcmi\source\lib\HeroBonus.cpp(2189)
vcmi\source\lib\HeroBonus.cpp(2215)
vcmi\source\lib\HeroBonus.h(550)
vcmi\source\lib\HeroBonus.h(553)
vcmi\source\lib\HeroBonus.h(554)
vcmi\source\lib\HeroBonus.h(571)
vcmi\source\lib\HeroBonus.h(665)
vcmi\source\lib\HeroBonus.h(710)
vcmi\source\lib\HeroBonus.h(770)
vcmi\source\lib\HeroBonus.h(782)
vcmi\source\lib\HeroBonus.h(1168)
vcmi\source\lib\HeroBonus.h(1193)
vcmi\source\lib\HeroBonus.h(1208)
vcmi\source\lib\HeroBonus.h(1223)
vcmi\source\lib\mapObjects\CGTownInstance.cpp(560)
vcmi\source\lib\mapObjects\CGTownInstance.cpp(565)
vcmi\source\lib\mapObjects\MiscObjects.cpp(1425)
vcmi\source\lib\serializer\CTypeList.h(167)

vcmi\source\lib\battle\CUnitState.cpp(899)
vcmi\source\lib\battle\CUnitState.h(271)
vcmi\source\lib\HeroBonus.cpp(645)
vcmi\source\lib\HeroBonus.cpp(650)
vcmi\source\lib\HeroBonus.cpp(852)
vcmi\source\lib\HeroBonus.cpp(905)
vcmi\source\lib\HeroBonus.h(703)
vcmi\source\lib\HeroBonus.h(707)
vcmi\source\lib\HeroBonus.h(708)
vcmi\source\lib\HeroBonus.h(769)
vcmi\source\lib\HeroBonus.h(780)
vcmi\source\lib\mapObjects\CGHeroInstance.cpp(819)
const std::shared_ptr only makes reset() and swap() inaccessible.

"const std:shared_ptr<T> foo" is equivalent to "T * const foo"
"std:shared_ptr<const T> foo" is equivalent to "const T * foo"

See https://stackoverflow.com/questions/17793333/difference-between-const-shared-ptrt-and-shared-ptrconst-t [^]
No tags attached.
Issue History
2020-10-01 00:00jamboloNew Issue
2020-10-01 04:03jamboloNote Added: 0007934
2020-10-01 04:42jamboloNote Deleted: 0007934
2020-10-02 22:59jamboloNote Added: 0007936
2020-10-02 23:00jamboloNote Edited: 0007936bug_revision_view_page.php?bugnote_id=7936#r3609
2021-01-25 22:38MikeLodzStatusnew => resolved
2021-01-25 22:38MikeLodzFixed in Version => 1.next
2021-01-25 22:38MikeLodzResolutionopen => fixed
2021-01-25 22:38MikeLodzAssigned To => MikeLodz

Notes
(0007936)
jambolo   
2020-10-02 22:59   
(edited on: 2020-10-02 23:00)
Pull request 653 merged in commit 0d0f1cea2b290b81f5e3d4093455c415b2999889