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

ENH: Make default-constructors of RGBPixel and RGBAPixel constexpr #5087

Conversation

N-Dekker
Copy link
Contributor

Tested by means of CheckConstexprBeginAndEndOfContainer(). Note that these default-constructors were already constexpr implicitly, as implied by = default, when ITK_FUTURE_LEGACY_REMOVE would be enabled.

@github-actions github-actions bot added type:Enhancement Improvement of existing methods or implementation type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Core Issues affecting the Core module labels Dec 17, 2024
@N-Dekker
Copy link
Contributor Author

I did this pull request by a regular git push. Is that OK? Or should we still use our custom git review-push? What is the difference between the two commands?

@dzenanz
Copy link
Member

dzenanz commented Dec 17, 2024

I use TortoiseGit, which implicitly uses plain push. I forgot what review-push does, but I am sure it could be found in the documentation.

@N-Dekker N-Dekker marked this pull request as ready for review December 17, 2024 18:44
Copy link
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@N-Dekker awesome!!

Yes, both ways work for creating the PR.

@N-Dekker N-Dekker force-pushed the constexpr-default-constructors-RGBPixel-RGBAPixel branch from 7544cbd to 6464b88 Compare December 17, 2024 19:56
@@ -81,7 +81,9 @@ class ITK_TEMPLATE_EXPORT RGBAPixel : public FixedArray<TComponent, 4>
#ifdef ITK_FUTURE_LEGACY_REMOVE
RGBAPixel() = default;
#else
RGBAPixel() { this->Fill(0); }
constexpr RGBAPixel()
: Superclass()
Copy link
Contributor Author

@N-Dekker N-Dekker Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this force-push, replacing {} with (), I'm hoping to address the warnings at https://open.cdash.org/viewBuildError.php?type=1&buildid=10096694 saying:


In file included from Modules/Core/Common/test/itkNumericTraitsTest.cxx:42:
/.../s/Modules/Core/Common/include/itkNumericTraitsRGBPixel.h: In function 'void numeric_traits_test::CheckVariableLengthArrayTraits(const T&) [with T = itk::RGBPixel<char>]':

Modules/Core/Common/include/itkNumericTraitsRGBPixel.h:118:17: warning: '<anonymous>' may be used uninitialized in this function [-Wmaybe-uninitialized]

Copy link
Contributor Author

@N-Dekker N-Dekker Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that with the old Linux GCC 9.4.0, the constexpr default-constructors that I wrote just don't properly zero-initialize the components, as they should. I'll think of another workaround...

Update: almost reproduced the old compiler bug at https://godbolt.org/z/rzdv3GGG4:

struct FixedArray
{
    FixedArray() = default;
    FixedArray(int);      
    int m_InternalArray[3];
};

struct RGBPixel: FixedArray
{
    RGBPixel(): FixedArray() {}
};

int main()
{
    const auto x = RGBPixel();
    return x.m_InternalArray[0];
}

Saying:

 warning: 'x.RGBPixel::<anonymous>.FixedArray::m_InternalArray[0]' is used uninitialized in this function [-Wuninitialized]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another attempt, initializing by the seemingly redundant expression Superclass(Superclass()): force-push

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now might be a reasonable time to reconsider which compiler versions we support in ITK 6?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dzenanz It looks like this particular bug (as I reproduced with the example code at #5087 (comment)) is fixed with GCC 12.1 (which was released in May 2022): https://godbolt.org/z/of6Tdbzcj GCC 11 still appears to have the compiler bug. I'm not sure if we can already drop GCC 11 now. Ubuntu-22.04 still comes with GCC 11.4 🤷

Having said so, I think we have a workaround for this one now 😃

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My Linux workstation is on Ubuntu 22.04. So yes, we can't drop it yet 😄

@hjmjohnson
Copy link
Member

@N-Dekker I only use git push. The git review-push looks like it does extra work that is probably no longer needed.

@N-Dekker N-Dekker marked this pull request as draft December 17, 2024 22:25
@N-Dekker N-Dekker force-pushed the constexpr-default-constructors-RGBPixel-RGBAPixel branch from 6464b88 to 07ee85a Compare December 18, 2024 10:37
Tested by means of `CheckConstexprBeginAndEndOfContainer()`. Note that these
default-constructors were already `constexpr` _implicitly_, as implied by
`= default`, when `ITK_FUTURE_LEGACY_REMOVE` would be enabled.

Used the expression `Superclass(Superclass())` as a workaround for a compiler
bug from GCC 9.4.0, causing warnings like:

  In file included from itkNumericTraitsTest.cxx:42:
  itkNumericTraitsRGBPixel.h: In function 'CheckVariableLengthArrayTraits(const T&) [with T = itk::RGBPixel<char>]':
  itkNumericTraitsRGBPixel.h:118:17: warning: '<anonymous>' may be used uninitialized in this function [-Wmaybe-uninitialized]
@hjmjohnson
Copy link
Member

I think that "".github/workflows/itk_dict.txt"" needs to have "Wmaybe" added.

@N-Dekker N-Dekker force-pushed the constexpr-default-constructors-RGBPixel-RGBAPixel branch from 07ee85a to f407ae5 Compare December 18, 2024 14:34
@github-actions github-actions bot added the type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots label Dec 18, 2024
@hjmjohnson
Copy link
Member

I created an issue to track how this may be done automatically: #5092

@N-Dekker N-Dekker marked this pull request as ready for review December 18, 2024 19:24
@hjmjohnson hjmjohnson merged commit 52f6414 into InsightSoftwareConsortium:master Dec 18, 2024
15 checks passed
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:Enhancement Improvement of existing methods or implementation type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants