COMP: Exceptions should be caught by constant reference#1492
Conversation
Modules/Core/SpatialObjects/test/itkContourSpatialObjectTest.cxx:244:31: warning: catching polymorphic type ‘class itk::ExceptionObject’ by value [-Wcatch-value=] Catching by value is problematic in the face of inheritance hierarchies. https://clang.llvm.org/extra/clang-tidy/checks/misc-throw-by-value-catch-by-reference.html https://wiki.sei.cmu.edu/confluence/display/cplusplus/ERR61-CPP.+Catch+exceptions+by+lvalue+reference
be9f2d4 to
fcdac9b
Compare
The second argument to the stream insertion operator should be a constant reference or pointer. operator<<(std::ostream & os, const EventObject & e) Stream insertion should not modify the object being inserted.
When throwing exceptions, getting the data object pointer should be always be constant.
dzenanz
left a comment
There was a problem hiding this comment.
Great! Do we also need to update the software guide with recommendations and examples regarding catching exceptions by reference?
That is "C++" best practices, so I think it would be OK, but not necessary. I'd be cautious to not be too TLDR; regarding details like this. |
|
What I meant, update the examples in the software guide to follow this, and if there are statements opposite to this update or remove them. I did not think of expansion. |
|
@dzenanz Oh. the Examples are already updated in the PR. I am working on a bash script to detect this in the SphinxExamples too, but that might be a few weeks before I get to it. |
|
I meant update code snippets such as these. |
|
Python failures are not related to these changes. @thewtex something is happening related to swig. https://open.cdash.org/viewTest.php?onlyfailed&buildid=6252493 Would @thewtex or @dzenanz merge when satisfied that python failures are some other problem? |
Something that is not reproducible sometimes causes these test failures on Linux CI builds. |
Modules/Core/SpatialObjects/test/itkContourSpatialObjectTest.cxx:244:31:
warning: catching polymorphic type ‘class itk::ExceptionObject’ by value [-Wcatch-value=]
Exceptions should be caught by constant reference, not by value.