" 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 " 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
MantisBT

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0003142VCMIOtherpublic2020-10-01 00:002021-01-25 22:38
Reporterjambolo 
Assigned ToMikeLodz 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version1.next 
Summary0003142: Use of const std::shared_ptr
DescriptionThere 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.
Steps To Reproducevcmi\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)
Additional Informationconst 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 [^]
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0007936)
jambolo (reporter)
2020-10-02 22:59
edited on: 2020-10-02 23:00

Pull request 653 merged in commit 0d0f1cea2b290b81f5e3d4093455c415b2999889


- Issue History
Date Modified Username Field Change
2020-10-01 00:00 jambolo New Issue
2020-10-01 04:03 jambolo Note Added: 0007934
2020-10-01 04:42 jambolo Note Deleted: 0007934
2020-10-02 22:59 jambolo Note Added: 0007936
2020-10-02 23:00 jambolo Note Edited: 0007936 View Revisions
2021-01-25 22:38 MikeLodz Status new => resolved
2021-01-25 22:38 MikeLodz Fixed in Version => 1.next
2021-01-25 22:38 MikeLodz Resolution open => fixed
2021-01-25 22:38 MikeLodz Assigned To => MikeLodz

Site | Forums | Wiki | Slack | GitHub


Copyright © 2000 - 2024 MantisBT Team
Hosting provided by DigitalOcean