COMP: Apply C++ Core Guidelines smart pointer fixes#5993
COMP: Apply C++ Core Guidelines smart pointer fixes#5993hjmjohnson wants to merge 3 commits intoInsightSoftwareConsortium:mainfrom
Conversation
c0430d0 to
8779182
Compare
Replace raw pointer members and new/delete with std::unique_ptr and std::make_unique. Use std::swap for all Swap* methods. Destructor is defaulted since unique_ptr handles cleanup. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
8779182 to
4863383
Compare
|
All issues from the greptile review have been addressed in the force-pushed v3:
|
ce7029e to
4863383
Compare
dzenanz
left a comment
There was a problem hiding this comment.
Looks good on a glance. I would prefer is someone else reviewed this too.
- Replace PointIdentifier array allocation with std::vector - Use .data() method for passing to SetPointIds Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace raw pointer return types and members with std::unique_ptr. Use std::make_unique for polymorphic factory creation. Destructor is defaulted since unique_ptr handles cleanup. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4863383 to
6862133
Compare
| std::unique_ptr<GenericCUBFileAdaptor> m_Reader{}; | ||
| std::unique_ptr<GenericCUBFileAdaptor> m_Writer{}; |
There was a problem hiding this comment.
In the past, the use of {} appeared problematic for smart pointers to a forward-declared class:
I don't know if that is still relevant nowadays. 🤷 For GCC std::unique_ptr, it was fixed with GCC 9.2. Do we require GCC >= 9.2?
If the {} do still cause a problem, simply remove them. Default-initialization of std::unique_ptr will work fine anyway!
There was a problem hiding this comment.
If memory serves me well, we support a rather old GCC version.
There was a problem hiding this comment.
GCC 7, according to:
So unfortunately then, these particular {} should be removed!
(The {} problem is specific for smart pointers to a forward-declared class. In other cases, {} usually just works fine.)
|
Sorry, but again, I would prefer these commits to be in separate PRs. |
|
Closing in favor of three focused single-commit PRs:
Each PR contains exactly one commit and can be reviewed and merged independently. |
Summary
Replace raw pointer ownership patterns with
std::unique_ptracross three modules, following C++ Core Guidelines R.11 (avoid callingnewanddeleteexplicitly) and R.20 (useunique_ptrto represent ownership).new/deleteof matrix and vector holders withstd::unique_ptrandstd::make_unique. Usestd::swapfor all swap methods. Default the destructor.new[]/delete[]array allocation withstd::vector, eliminating manual memory management in test code.std::unique_ptr<GenericCUBFileAdaptor>, usingstd::make_uniquefor polymorphic factory creation. Default the destructor.OpenCVVideoIO changes split to separate PR: #5994
Test plan
🤖 Generated with Claude Code