COMP: Remove in-class {} member initializers of unique_ptr#3877
COMP: Remove in-class {} member initializers of unique_ptr#3877dzenanz merged 1 commit intoInsightSoftwareConsortium:masterfrom
Conversation
|
Wow, thanks @SimonRit I knew about an in-class But I see now, at https://godbolt.org/z/8Y5vMMYfG Still produces:
Apparently, this bug is fixed with GCC 9.2. Update March 24, 2023: For the record, this was indeed a GCC bug, and indeed, fixed with GCC 9.2: Bug 85552 - Adding curly braces to the declaration of a std::unique_ptr to a forward declared class breaks compilation, reported by Parker Coates, 2018-04-27. |
| std::unique_ptr<vnl_matrix<long>[]> m_ThreadedEvaluateIndex {}; | ||
| std::unique_ptr<vnl_matrix<double>[]> m_ThreadedWeights {}; | ||
| std::unique_ptr<vnl_matrix<double>[]> m_ThreadedWeightsDerivative {}; | ||
| std::unique_ptr<vnl_matrix<long>[]> m_ThreadedEvaluateIndex ; |
There was a problem hiding this comment.
These spaces were actually introduced automatically by Clang-Format (with my PR #3851), when adding the {}! I think it's a Clang-Format bug!
There was a problem hiding this comment.
Just force pushed a slightly modified version of the regexp to cope with this, linter is happy now!
Patch 5e2c49f causes the following errors on GCC 7.4.1: /usr/include/c++/7/bits/unique_ptr.h:76:22: error: invalid application of ‘sizeof’ to incomplete type ‘itk::NiftiImageIO::NiftiImageProxy’ /usr/include/c++/7/bits/unique_ptr.h:76:22: error: invalid application of ‘sizeof’ to incomplete type ‘itk::LBFGSBOptimizerHelper’ /usr/include/c++/7/bits/unique_ptr.h:76:22: error: invalid application of ‘sizeof’ to incomplete type ‘gdcm::SerieHelper’ /usr/include/c++/7/bits/unique_ptr.h:76:22: error: invalid application of ‘sizeof’ to incomplete type ‘itk::NiftiImageIO::NiftiImageProxy’ /usr/include/c++/7/bits/unique_ptr.h:76:22: error: invalid application of ‘sizeof’ to incomplete type ‘itk::GiftiMeshIO::GiftiImageProxy’ /usr/include/c++/7/bits/unique_ptr.h:76:22: error: invalid application of ‘sizeof’ to incomplete type ‘itk::GiftiMeshIO::GiftiImageProxy’ The issue has already been fixed in the past, see d7c0128 All instances have been removed with the script: for i in $(find Modules -type f) do sed -i "s/\(unique_ptr.*\)\( *{}\)/\1/g" $i done
d84575e to
719c3ce
Compare
N-Dekker
left a comment
There was a problem hiding this comment.
As far as I can see, the old GCC errors only occur for unique_ptr<T> data members whose type T is a forward-declared class. So it should not affect all unique_ptr data members.
Anyway, I see that it's easiest to just remove the in-class {} initializers from all of them. Approved.
…ration
GCC 7.4.1 raised the following errors on Linux:
Modules/Core/Common/include/itkSmartPointer.h:214:18: error: invalid use
of incomplete type ‘using ObjectType = class itk::MultiThreaderBase {aka
class itk::MultiThreaderBase}’
This is a compiler bug (as discussed in
InsightSoftwareConsortium#3877 (comment)
and the same issue has been fixed for unique_ptr by
719c3ce.
GCC 7.4.1 raised the following errors on Linux:
Modules/Core/Common/include/itkSmartPointer.h:214:18: error: invalid use
of incomplete type ‘using ObjectType = class itk::MultiThreaderBase {aka
class itk::MultiThreaderBase}’
This is a compiler bug (as discussed in
InsightSoftwareConsortium#3877 (comment)
and the same issue has been fixed for unique_ptr by
719c3ce.
GCC 7.4.1 raised the following errors on Linux:
Modules/Core/Common/include/itkSmartPointer.h:214:18: error: invalid use
of incomplete type ‘using ObjectType = class itk::MultiThreaderBase {aka
class itk::MultiThreaderBase}’
This is a compiler bug (as discussed in
InsightSoftwareConsortium#3877 (comment))
and the same issue has been fixed for unique_ptr by
719c3ce.
GCC 7.4.1 raised the following errors on Linux:
Modules/Core/Common/include/itkSmartPointer.h:214:18: error: invalid use
of incomplete type ‘using ObjectType = class itk::MultiThreaderBase {aka
class itk::MultiThreaderBase}’
This is a compiler bug (as discussed in
#3877 (comment))
and the same issue has been fixed for unique_ptr by
719c3ce.
Excluded padding data, `std::unique_ptr`, `itk::SmartPointer` and low level utility classes from the guideline that says that "all member variables must be initialized when they are declared". `std::unique_ptr` and `itk::SmartPointer` are excluded because of some GCC compile errors, which were addressed in ITK by Simon Rit: - pull request InsightSoftwareConsortium/ITK#3877 commit InsightSoftwareConsortium/ITK@eac289d "COMP: Remove in-class {} member initializers of unique_ptr" - pull request InsightSoftwareConsortium/ITK#3927 commit InsightSoftwareConsortium/ITK@f5f8367 "COMP: Remove in class init of SmartPointer of forward declaration"
Errors showed up in (e.g.) https://my.cdash.org/viewBuildError.php?buildid=2273357
Patch 5e2c49f causes the following errors on GCC 7.4.1:
/usr/include/c++/7/bits/unique_ptr.h:76:22: error: invalid application of ‘sizeof’ to incomplete type ‘itk::NiftiImageIO::NiftiImageProxy’ /usr/include/c++/7/bits/unique_ptr.h:76:22: error: invalid application of ‘sizeof’ to incomplete type ‘itk::LBFGSBOptimizerHelper’ /usr/include/c++/7/bits/unique_ptr.h:76:22: error: invalid application of ‘sizeof’ to incomplete type ‘gdcm::SerieHelper’ /usr/include/c++/7/bits/unique_ptr.h:76:22: error: invalid application of ‘sizeof’ to incomplete type ‘itk::NiftiImageIO::NiftiImageProxy’ /usr/include/c++/7/bits/unique_ptr.h:76:22: error: invalid application of ‘sizeof’ to incomplete type ‘itk::GiftiMeshIO::GiftiImageProxy’ /usr/include/c++/7/bits/unique_ptr.h:76:22: error: invalid application of ‘sizeof’ to incomplete type ‘itk::GiftiMeshIO::GiftiImageProxy’
The issue has already been fixed in the past, see
d7c0128
All instances have been removed with the script:
for i in $(find Modules -type f)
do
sed -i "s/(unique_ptr.*) *{}/\1/g" $i
done
PR Checklist
Refer to the ITK Software Guide for
further development details if necessary.