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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/itk_dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ Wachowiak
Wanlin
Wdeprecated
Wi
Wmaybe
Wtautological
Xu
Y'CbCr
Expand Down
8 changes: 7 additions & 1 deletion Modules/Core/Common/include/itkRGBAPixel.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ class ITK_TEMPLATE_EXPORT RGBAPixel : public FixedArray<TComponent, 4>
#ifdef ITK_FUTURE_LEGACY_REMOVE
RGBAPixel() = default;
#else
RGBAPixel() { this->Fill(0); }
constexpr RGBAPixel()
: Superclass(Superclass())
{
// `: Superclass(Superclass())` is a workaround for an old compiler bug. A simple `: Superclass()` triggered
// warnings from GCC 9.4.0 saying: "warning: '<anonymous>' may be used uninitialized in this function
// [-Wmaybe-uninitialized]".
}
#endif

/** Pass-through constructor for the Array base class. */
Expand Down
8 changes: 7 additions & 1 deletion Modules/Core/Common/include/itkRGBPixel.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ class ITK_TEMPLATE_EXPORT RGBPixel : public FixedArray<TComponent, 3>
#ifdef ITK_FUTURE_LEGACY_REMOVE
RGBPixel() = default;
#else
RGBPixel() { this->Fill(0); }
constexpr RGBPixel()
: Superclass(Superclass())
{
// `: Superclass(Superclass())` is a workaround for an old compiler bug. A simple `: Superclass()` triggered
// warnings from GCC 9.4.0 saying: "warning: '<anonymous>' may be used uninitialized in this function
// [-Wmaybe-uninitialized]".
}
#endif

#if defined(ITK_LEGACY_REMOVE)
Expand Down
5 changes: 5 additions & 0 deletions Modules/Core/Common/test/itkRGBAPixelGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#include <gtest/gtest.h>


static_assert(itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::RGBAPixel<>>() &&
itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::RGBAPixel<std::uint8_t>>() &&
itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::RGBAPixel<float>>());


// Tests that a RGBAPixel that is "value-initialized" (by empty braces, `{}`) is zero-filled.
TEST(RGBAPixel, ValueInitializedIsZeroFilled)
{
Expand Down
5 changes: 5 additions & 0 deletions Modules/Core/Common/test/itkRGBPixelGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#include <gtest/gtest.h>


static_assert(itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::RGBPixel<>>() &&
itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::RGBPixel<std::uint8_t>>() &&
itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::RGBPixel<float>>());


// Tests that a RGBPixel that is "value-initialized" (by empty braces, `{}`) is zero-filled.
TEST(RGBPixel, ValueInitializedIsZeroFilled)
{
Expand Down
Loading