Skip to content

COMP: Remove in class init of SmartPointer of forward declaration#3927

Merged
N-Dekker merged 1 commit intoInsightSoftwareConsortium:masterfrom
SimonRit:InClassInitOfForward
Feb 17, 2023
Merged

COMP: Remove in class init of SmartPointer of forward declaration#3927
N-Dekker merged 1 commit intoInsightSoftwareConsortium:masterfrom
SimonRit:InClassInitOfForward

Conversation

@SimonRit
Copy link
Copy Markdown

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.

PR Checklist

  • No API changes were made (or the changes have been approved)
  • No major design changes were made (or the changes have been approved)
  • Added test (or behavior not changed)
  • Updated API documentation (or API not changed)
  • Added license to new files (if any)
  • Added Python wrapping to new files (if any) as described in ITK Software Guide Section 9.5
  • Added ITK examples for all new major features (if any)

Refer to the ITK Software Guide for
further development details if necessary.

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.
@github-actions github-actions Bot added type:Compiler Compiler support or related warnings area:Core Issues affecting the Core module labels Feb 15, 2023
@dzenanz dzenanz requested a review from N-Dekker February 15, 2023 13:50
@N-Dekker
Copy link
Copy Markdown
Contributor

Thanks again @SimonRit

It is indeed quite similar to the problem you fixed with #3877 It appears to be an old GCC bug, fixed with GCC 9.2. I just tried the following minimal example at https://godbolt.org/z/bP6frqqKo

template <typename TObjectType>
class SmartPointer
{
public:
  SmartPointer() = default;

  template <typename T>
  SmartPointer(const SmartPointer<T> &);

  ~SmartPointer()
  {
    if (m_Pointer)
    {
      m_Pointer->UnRegister();
    }
  }

  TObjectType * m_Pointer{ nullptr };
};

class ForwardDeclaredClass;

class ProcessObject
{
  SmartPointer<ForwardDeclaredClass> m_Data{};
};

The existence of a templated constructor SmartPointer(const SmartPointer<T> &) appears to trigger the old GCC bug.

@N-Dekker
Copy link
Copy Markdown
Contributor

/azp run ITK.Linux.Python

@N-Dekker N-Dekker merged commit f5f8367 into InsightSoftwareConsortium:master Feb 17, 2023
N-Dekker added a commit to N-Dekker/ITKSoftwareGuide that referenced this pull request Mar 1, 2023
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"
@SimonRit SimonRit deleted the InClassInitOfForward branch March 14, 2023 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module type:Compiler Compiler support or related warnings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants