Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation fails with GCC 8.4. #3643

Closed
maxaehle opened this issue Sep 21, 2022 · 4 comments · Fixed by #3645
Closed

Compilation fails with GCC 8.4. #3643

maxaehle opened this issue Sep 21, 2022 · 4 comments · Fixed by #3645
Assignees
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances

Comments

@maxaehle
Copy link
Contributor

Description

Compilation fails.

Steps to Reproduce

Clone ITK into ITK/src, cd into ITK/bin and

cmake ../src/ -DCMAKE_CXX_FLAGS:STRING=-std=c++11 -DBUILD_DOCUMENTATION=OFF -DBUILD_EXAMPLES=OFF -DBUILD_TESTING=OFF -DModule_RTK=ON -DRTK_USE_CUDA=OFF -DCMAKE_BUILD_TYPE=Release -DRTK_BUILD_APPLICATIONS=OFF
make

Expected behavior

Successful compilation.

Actual behavior

Compilation aborts with error message like this one:

[ 28%] Building CXX object Modules/Core/Common/src/CMakeFiles/ITKCommon.dir/__/itkBuildInformation.cxx.o
In file included from /software/gcc/8.4.0/include/c++/8.4.0/memory:80,
                 from /home/aehle/ITK/src/Modules/Core/Common/include/itkExceptionObject.h:22,
                 from /home/aehle/ITK/src/Modules/Core/Common/include/itkMacro.h:1368,
                 from /home/aehle/ITK/src/Modules/Core/Common/include/itkBuildInformation.h:21,
                 from /home/aehle/ITK/bin/Modules/Core/Common/itkBuildInformation.cxx:19:
/software/gcc/8.4.0/include/c++/8.4.0/bits/unique_ptr.h: In instantiation of ‘void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = itk::SubjectImplementation]’:
/software/gcc/8.4.0/include/c++/8.4.0/bits/unique_ptr.h:277:17:   required from ‘std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = itk::SubjectImplementation; _Dp = std::default_delete<itk::SubjectImplementation>]’
/home/aehle/ITK/src/Modules/Core/Common/include/itkObject.h:277:75:   required from here
/software/gcc/8.4.0/include/c++/8.4.0/bits/unique_ptr.h:79:16: error: invalid application of ‘sizeof’ to incomplete type ‘itk::SubjectImplementation’
  static_assert(sizeof(_Tp)>0,
                ^~~~~~~~~~~

Reproducibility

The above error happens consistently in the environment described below.

Versions

Current master branch, commit 171fb2b.

Environment

Linux, CMake 3.20.2, GCC 8.4.0.
(You can reproduce a similar environment with GCC 8.5.0, which also exhibits this problem, by building a Singularity container with this definition file: singularity.def.txt.)

Additional Information

The compilation error can be fixed by removing the initializer "{ nullptr }" of Object::m_SubjectImplementation. So maybe this problem is related to #3620.
With GCC 9.4 the problem does not come up.

@maxaehle maxaehle added the type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances label Sep 21, 2022
@github-actions
Copy link

Thank you for contributing an issue!

Welcome to the ITK community!

We are glad you are here and appreciate your contribution. Please keep in mind our community participation guidelines.
Also, please check existing open issues and consider discussion on the ITK Discourse.

@N-Dekker
Copy link
Contributor

The compilation error can be fixed by removing the initializer "{ nullptr }" of Object::m_SubjectImplementation.

@maxaehle Thanks, that's a very helpful suggestion, Max! The "{ nullptr }" initializer isn't really necessary for unique_ptrs, I just thought it might have improved code readability! 🤔 In this particular case, would an empty {} initializer still be OK for GCC 8.4?

@N-Dekker
Copy link
Contributor

cmake ../src/ -DCMAKE_CXX_FLAGS:STRING=-std=c++11

ITK now requires at least C++14. Does the compile error also occur when you do -DCMAKE_CXX_FLAGS:STRING=-std=c++11?

@N-Dekker
Copy link
Contributor

Thanks again Max. Just reproduced at https://godbolt.org/z/zM8PM5eTe even with GCC 9.1:


#include <memory>

class SubjectImplementation;

class Object
{
  Object();
  ~Object();
  std::unique_ptr<SubjectImplementation> m_SubjectImplementation{ nullptr };
};

Output:

In file included from /opt/compiler-explorer/gcc-9.1.0/include/c++/9.1.0/memory:80,
                 from <source>:5:
/opt/compiler-explorer/gcc-9.1.0/include/c++/9.1.0/bits/unique_ptr.h: In instantiation of 'void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = SubjectImplementation]':
/opt/compiler-explorer/gcc-9.1.0/include/c++/9.1.0/bits/unique_ptr.h:289:17:   required from 'std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = SubjectImplementation; _Dp = std::default_delete<SubjectImplementation>]'
<source>:13:75:   required from here
/opt/compiler-explorer/gcc-9.1.0/include/c++/9.1.0/bits/unique_ptr.h:79:16: error: invalid application of 'sizeof' to incomplete type 'SubjectImplementation'
   79 |  static_assert(sizeof(_Tp)>0,
      |                ^~~~~~~~~~~

I'll prepare a pull request, probably just having your suggested workaround.

N-Dekker added a commit to N-Dekker/ITK that referenced this issue Sep 21, 2022
Worked around a GCC bug which produced the following error:

> unique_ptr.h:79:16: error: invalid application of ‘sizeof’ to incomplete type

The issue InsightSoftwareConsortium#3643
"Compilation fails with GCC 8.4." was reported by Max Aehle. The GCC bug appears
to be fixed with GCC 9.2.

The workaround (removing "`{ nullptr }`") was also suggested by Max Aehle.
N-Dekker added a commit that referenced this issue Sep 21, 2022
Worked around a GCC bug which produced the following error:

> unique_ptr.h:79:16: error: invalid application of ‘sizeof’ to incomplete type

The issue #3643
"Compilation fails with GCC 8.4." was reported by Max Aehle. The GCC bug appears
to be fixed with GCC 9.2.

The workaround (removing "`{ nullptr }`") was also suggested by Max Aehle.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants