Repository: InsightSoftwareConsortium/ITK (language: python)

Issue:
Address GCC 13.2 compilation issues
### Description

The forth coming LTR Ubuntu 24.04 (on April 25, 2024) is distributed with GCC 13.2 compiler.

ITK should build cleanly with this new standard compiler.

### Steps to Reproduce

1. clone itk
2. build in release mode (with Examples turned on)


### Expected behavior

no build warnings
no failing tests

### Actual behavior

3 test failures
```
	1012 - itkGDCMLegacyMultiFrameTest (Failed)
	1021 - itkGDCMImageReadWriteTest_MultiFrameMRIZSpacing (Failed)
	1023 - itkGDCM_ComplianceTest_singlebit (Failed)
```

199+ compiler warnings

```
```

### Reproducibility
all the time

### Versions
ITK master branch on 2024-04-23

git rev-parse --short HEAD
```
3235b3675c
```

### Environment

Ubuntu 24.04 
GCC 13.2 compiler


### Additional Information

```
242 |   alignas(SizeValueType) SizeValueType m_InternalArray[VDimension];
      |                                        ^~~~~~~~~~~~~~~
In member function ‘constexpr const itk::Size<VDimension>::value_type& itk::Size<VDimension>::operator[](size_type) const [with unsigned int VDimension = 2]’,
    inlined from ‘itk::Neighborhood<TPixel, VDimension, TAllocator>::SizeValueType itk::Neighborhood<TPixel, VDimension, TAllocator>::GetSize(DimensionValueType) const [with TPixel = float; unsigned int VDimension = 2; TAllocator = itk::NeighborhoodAllocator<float>]’ at [Modules/Core/Common/include/itkNeighborhood.h:147](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Core/Common/include/itkNeighborhood.h#L147):18,
    inlined from ‘void itk::NeighborhoodOperator<TPixel, VDimension, TAllocator>::FillCenteredDirectional(const CoefficientVector&) [with TPixel = float; unsigned int VDimension = 2; TAllocator = itk::NeighborhoodAllocator<float>]’ at [Modules/Core/Common/include/itkNeighborhoodOperator.hxx:107](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Core/Common/include/itkNeighborhoodOperator.hxx#L107):43,
    inlined from ‘void itk::DerivativeOperator<TPixel, VDimension, TAllocator>::Fill(const typename Superclass::CoefficientVector&) [with TPixel = float; unsigned int VDimension = 2; TAllocator = itk::NeighborhoodAllocator<float>]’ at [Modules/Core/Common/include/itkDerivativeOperator.h:116](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Core/Common/include/itkDerivativeOperator.h#L116):40,
    inlined from ‘void itk::NeighborhoodOperator<TPixel, VDimension, TAllocator>::CreateToRadius(const typename Superclass::SizeType&) [with TPixel = float; unsigned int VDimension = 2; TAllocator = itk::NeighborhoodAllocator<float>]’ at [Modules/Core/Common/include/itkNeighborhoodOperator.hxx:81](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Core/Common/include/itkNeighborhoodOperator.hxx#L81):13:

```




Discussion / hints:
```
/home/johnsonhj/Dashboard/src/ITK_master/Modules/Core/Common/include/itkIndex.h:430:73: warning: array subscript 1 is above array bounds of ‘itk::Index<1>::IndexValueType [1]’ {aka ‘long int [1]’} [-Warray-bounds=]
/home/johnsonhj/Dashboard/src/ITK_master/Modules/Core/Common/include/itkSize.h:354:73: warning: array subscript 1 is above array bounds of ‘itk::Size<1>::SizeValueType [1]’ {aka ‘long unsigned int [1]’} [-Warray-bounds=]
/home/johnsonhj/Dashboard/src/ITK_master/Modules/Core/Common/include/itkSize.h:356:85: warning: array subscript 2 is above array bounds of ‘const itk::Size<2>::SizeValueType [2]’ {aka ‘const long unsigned int [2]’} [-Warray-bounds=]
/home/johnsonhj/Dashboard/src/ITK_master/Modules/Core/QuadEdgeMesh/include/itkQuadEdge.h:245:15: warning: array subscript 0 is outside array bounds of ‘QEType [0]’ [-Warray-bounds=]
/home/johnsonhj/Dashboard/src/ITK_master-simple/KWStyle/kwsCheckIndent.cxx:615:39: warning: ‘__builtin___snprintf_chk’ output may be truncated before the last format character [-Wformat-truncation=]
```
FYI:  These two tests fail for ITK v5.2.1 on gcc 13.2

```
The following tests FAILED:
	853 - itkGDCMLegacyMultiFrameTest (Failed)
	860 - itkGDCM_ComplianceTest_singlebit (Failed)
Errors while running CTest
```

```
➜  cmake-build-release git:(gcc132-v5.2.2) ✗ ctest --rerun-failed --output-on-failure
Test project /home/johnsonhj/Dashboard/src/ITK/cmake-build-release
    Start 853: itkGDCMLegacyMultiFrameTest
1/1 Test #853: itkGDCMLegacyMultiFrameTest ......***Failed    0.36 sec
WARNING: In /home/johnsonhj/Dashboard/src/ITK/Modules/IO/Meta/src/itkMetaImageIO.cxx, line 667
MetaImageIO (0x5971e7d51690): Unsupported or empty metaData item 0008|0050 of type NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEfound, won't be written to image file

WARNING: In /home/johnsonhj/Dashboard/src/ITK/Modules/IO/Meta/src/itkMetaImageIO.cxx, line 667
MetaImageIO (0x5971e7d51690): Unsupported or empty metaData item 0008|0090 of type NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEfound, won't be written to image file

WARNING: In /home/johnsonhj/Dashboard/src/ITK/Modules/IO/Meta/src/itkMetaImageIO.cxx, line 667
MetaImageIO (0x5971e7d51690): Unsupported or empty metaData item 0008|1050 of type NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEfound, won't be written to image file

WARNING: In /home/johnsonhj/Dashboard/src/ITK/Modules/IO/Meta/src/itkMetaImageIO.cxx, line 667
MetaImageIO (0x5971e7d51690): Unsupported or empty metaData item 0020|1040 of type NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEfound, won't be written to image file

Exception detected while reading /home/johnsonhj/Dashboard/src/ITK/cmake-build-release/ExternalData/Modules/IO/GDCM/test/Baseline/itkGDCMLegacyMultiFrameTest.mha : ITK ERROR: ComparisonImageFilter(0x5971e7dc90c0): Inputs do not occupy the same physical space! 
InputImage Origin: [0.0000000e+00, 0.0000000e+00, 0.0000000e+00, 0.0000000e+00, 0.0000000e+00, 0.0000000e+00], InputImageValidInput Origin: [-8.3217715e+01, -1.2386938e+02, 1.5993408e+02, 0.0000000e+00, 0.0000000e+00, 0.0000000e+00]
	Tolerance: 1.0000000e-06
InputImage Spacing: [1.0000000e+00, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00], InputImageValidInput Spacing: [1.0000000e+00, 1.0000000e+00, 1.3300000e+00, 1.0000000e+00, 1.0000000e+00, 1.0000000e+00]
	Tolerance: 1.0000000e-06
InputImage Direction: 1.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00
0.0000000e+00 1.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00
0.0000000e+00 0.0000000e+00 1.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00
0.0000000e+00 0.0000000e+00 0.0000000e+00 1.0000000e+00 0.0000000e+00 0.0000000e+00
0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 1.0000000e+00 0.0000000e+00
0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 1.0000000e+00
, InputImageValidInput Direction: 4.3757128e-31 -1.0000000e-16 1.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00
9.7629602e-01 -2.1643955e-01 -2.1643955e-17 0.0000000e+00 0.0000000e+00 0.0000000e+00
-2.1643955e-01 -9.7629602e-01 -9.7629602e-17 0.0000000e+00 0.0000000e+00 0.0000000e+00
0.0000000e+00 0.0000000e+00 0.0000000e+00 1.0000000e+00 0.0000000e+00 0.0000000e+00
0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 1.0000000e+00 0.0000000e+00
0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 1.0000000e+00

	Tolerance: 1.0000000e-06
<DartMeasurement name="BaselineImageName" type="text/string">INVALID_BASELINE_GIVEN</DartMeasurement>
```

Fix patch:
diff --git a/.clang-format b/.clang-format
index f75427a27dc..69950423abc 100644
--- a/.clang-format
+++ b/.clang-format
@@ -152,7 +152,6 @@ StatementMacros:
   - ITK_GCC_SUPPRESS_Wformat_nonliteral
   - CLANG_PRAGMA_PUSH
   - CLANG_PRAGMA_POP
-  - CLANG_SUPPRESS_Wcpp14_extensions
   - INTEL_PRAGMA_WARN_PUSH
   - INTEL_PRAGMA_WARN_POP
   - INTEL_SUPPRESS_warning_1292
diff --git a/Modules/Core/Common/include/itkExtractImageFilter.hxx b/Modules/Core/Common/include/itkExtractImageFilter.hxx
index 430b7877d68..2b03120c2e2 100644
--- a/Modules/Core/Common/include/itkExtractImageFilter.hxx
+++ b/Modules/Core/Common/include/itkExtractImageFilter.hxx
@@ -62,7 +62,6 @@ ExtractImageFilter<TInputImage, TOutputImage>::SetExtractionRegion(InputImageReg
                 "InputImageDimension must be greater than OutputImageDimension");
   m_ExtractionRegion = extractRegion;
 
-  unsigned int        nonzeroSizeCount = 0;
   InputImageSizeType  inputSize = extractRegion.GetSize();
   OutputImageSizeType outputSize;
   outputSize.Fill(0);
@@ -73,12 +72,16 @@ ExtractImageFilter<TInputImage, TOutputImage>::SetExtractionRegion(InputImageReg
    * check to see if the number of non-zero entries in the extraction region
    * matches the number of dimensions in the output image.
    */
+  unsigned int nonzeroSizeCount = 0;
   for (unsigned int i = 0; i < InputImageDimension; ++i)
   {
     if (inputSize[i])
     {
-      outputSize[nonzeroSizeCount] = inputSize[i];
-      outputIndex[nonzeroSizeCount] = extractRegion.GetIndex()[i];
+      if (nonzeroSizeCount < OutputImageDimension)
+      {
+        outputSize[nonzeroSizeCount] = inputSize[i];
+        outputIndex[nonzeroSizeCount] = extractRegion.GetIndex()[i];
+      }
       ++nonzeroSizeCount;
     }
   }
@@ -116,11 +119,7 @@ ExtractImageFilter<TInputImage, TOutputImage>::GenerateOutputInformation()
   outputPtr->SetLargestPossibleRegion(m_OutputImageRegion);
 
   // Set the output spacing and origin
-  const ImageBase<InputImageDimension> * phyData;
-
-  phyData = dynamic_cast<const ImageBase<InputImageDimension> *>(this->GetInput());
-
-  if (phyData)
+  if (this->GetInput())
   {
     // Copy what we can from the image from spacing and origin of the input
     // This logic needs to be augmented with logic that select which
diff --git a/Modules/Core/Common/include/itkMacro.h b/Modules/Core/Common/include/itkMacro.h
index 480c4c2c6d1..031a43e6e04 100644
--- a/Modules/Core/Common/include/itkMacro.h
+++ b/Modules/Core/Common/include/itkMacro.h
@@ -120,15 +120,16 @@ namespace itk
 #if defined(__clang__) && defined(__has_warning)
 #  define CLANG_PRAGMA_PUSH ITK_PRAGMA(clang diagnostic push)
 #  define CLANG_PRAGMA_POP ITK_PRAGMA(clang diagnostic pop)
-#  if __has_warning("-Wc++14-extensions")
-#    define CLANG_SUPPRESS_Wcpp14_extensions ITK_PRAGMA(clang diagnostic ignored "-Wc++14-extensions")
-#  else
-#    define CLANG_SUPPRESS_Wcpp14_extensions
-#  endif
 #else
 #  define CLANG_PRAGMA_PUSH
 #  define CLANG_PRAGMA_POP
-#  define CLANG_SUPPRESS_Wcpp14_extensions
+#endif
+
+#if !defined(ITK_LEGACY_REMOVE)
+// Issue warning if deprecated preprocessor flag is used.
+#  define CLANG_SUPPRESS_Wcpp14_extensions                                                                \
+    [[deprecated("Remove deprecated CLANG_SUPPRESS_Wcpp14_extensions c++14 warning suppression")]] void * \
+      CLANG_SUPPRESS_Wcpp14_extensions = nullptr;
 #endif
 
 // Intel compiler convenience macros
diff --git a/Modules/Core/Common/include/itkMultiThreaderBase.h b/Modules/Core/Common/include/itkMultiThreaderBase.h
index 299d72cfcd8..5aa630aca60 100644
--- a/Modules/Core/Common/include/itkMultiThreaderBase.h
+++ b/Modules/Core/Common/include/itkMultiThreaderBase.h
@@ -238,8 +238,6 @@ ITK_GCC_PRAGMA_DIAG_PUSH()
 ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
 INTEL_PRAGMA_WARN_PUSH
 INTEL_SUPPRESS_warning_1292
-CLANG_PRAGMA_PUSH
-CLANG_SUPPRESS_Wcpp14_extensions
   // clang-format on
 #  ifdef ITK_LEGACY_SILENT
   struct ThreadInfoStruct
@@ -247,7 +245,6 @@ CLANG_SUPPRESS_Wcpp14_extensions
   struct [[deprecated("Use WorkUnitInfo, ThreadInfoStruct is deprecated since ITK 5.0")]] ThreadInfoStruct
 #  endif
     // clang-format off
-CLANG_PRAGMA_POP
 INTEL_PRAGMA_WARN_POP
   // clang-format on
   {
diff --git a/Modules/Core/Common/include/itkNeighborhood.h b/Modules/Core/Common/include/itkNeighborhood.h
index 511f50314cd..6456ed81d84 100644
--- a/Modules/Core/Common/include/itkNeighborhood.h
+++ b/Modules/Core/Common/include/itkNeighborhood.h
@@ -136,7 +136,7 @@ class ITK_TEMPLATE_EXPORT Neighborhood
   SizeValueType
   GetRadius(DimensionValueType n) const
   {
-    return m_Radius[n];
+    return m_Radius.at(n);
   }
 
   /** Returns the size (total length) of the neighborhood along
@@ -144,7 +144,7 @@ class ITK_TEMPLATE_EXPORT Neighborhood
   SizeValueType
   GetSize(DimensionValueType n) const
   {
-    return m_Size[n];
+    return m_Size.at(n);
   }
 
   /** Returns the size (total length of sides) of the neighborhood. */
diff --git a/Modules/Core/Common/include/itkNeighborhoodOperator.h b/Modules/Core/Common/include/itkNeighborhoodOperator.h
index a95d39f3f7b..55232f9e845 100644
--- a/Modules/Core/Common/include/itkNeighborhoodOperator.h
+++ b/Modules/Core/Common/include/itkNeighborhoodOperator.h
@@ -93,6 +93,11 @@ class ITK_TEMPLATE_EXPORT NeighborhoodOperator : public Neighborhood<TPixel, VDi
   void
   SetDirection(const unsigned long direction)
   {
+    if (direction >= VDimension)
+    {
+      itkExceptionMacro(<< " Can not set direction " << direction << " greater than dimensionality of neighborhood "
+                        << VDimension);
+    }
     m_Direction = direction;
   }
 
diff --git a/Modules/Filtering/ImageFusion/include/itkLabelMapContourOverlayImageFilter.hxx b/Modules/Filtering/ImageFusion/include/itkLabelMapContourOverlayImageFilter.hxx
index 39f36cec512..476359c02fe 100644
--- a/Modules/Filtering/ImageFusion/include/itkLabelMapContourOverlayImageFilter.hxx
+++ b/Modules/Filtering/ImageFusion/include/itkLabelMapContourOverlayImageFilter.hxx
@@ -157,7 +157,7 @@ LabelMapContourOverlayImageFilter<TLabelMap, TFeatureImage, TOutputImage>::Befor
   srad.Fill(typename RadiusType::SizeValueType{});
   for (unsigned int i = 0, j = 0; i < ImageDimension; ++i)
   {
-    if (j != static_cast<unsigned int>(m_SliceDimension))
+    if (j != static_cast<unsigned int>(m_SliceDimension) && (j < (ImageDimension - 1)))
     {
       srad[j] = m_ContourThickness[i];
       ++j;
diff --git a/Modules/Filtering/ImageIntensity/include/itkSymmetricEigenAnalysisImageFilter.h b/Modules/Filtering/ImageIntensity/include/itkSymmetricEigenAnalysisImageFilter.h
index 795acebae12..e21b47d00e1 100644
--- a/Modules/Filtering/ImageIntensity/include/itkSymmetricEigenAnalysisImageFilter.h
+++ b/Modules/Filtering/ImageIntensity/include/itkSymmetricEigenAnalysisImageFilter.h
@@ -56,7 +56,7 @@ class SymmetricEigenAnalysisFunction
   inline TOutput
   operator()(const TInput & x) const
   {
-    TOutput eigenValues;
+    TOutput eigenValues{};
 
     m_Calculator.ComputeEigenValues(x, eigenValues);
     return eigenValues;


Test patch:
diff --git a/Modules/Core/Common/test/itkShapedImageNeighborhoodRangeGTest.cxx b/Modules/Core/Common/test/itkShapedImageNeighborhoodRangeGTest.cxx
index 8c39d45396b..2550872be58 100644
--- a/Modules/Core/Common/test/itkShapedImageNeighborhoodRangeGTest.cxx
+++ b/Modules/Core/Common/test/itkShapedImageNeighborhoodRangeGTest.cxx
@@ -350,7 +350,7 @@ TEST(ShapedImageNeighborhoodRange, IteratorsCanBePassedToStdVectorConstructor)
 // second argument of std::reverse (which requires bidirectional iterators).
 TEST(ShapedImageNeighborhoodRange, IteratorsCanBePassedToStdReverseCopy)
 {
-  using PixelType = unsigned char;
+  using PixelType = unsigned short;
   using ImageType = itk::Image<PixelType>;
   enum
   {
@@ -366,11 +366,14 @@ TEST(ShapedImageNeighborhoodRange, IteratorsCanBePassedToStdReverseCopy)
   itk::ShapedImageNeighborhoodRange<ImageType> range{ *image, location, offsets };
 
   const unsigned int numberOfNeighborhoodPixels = 3;
+  ASSERT_EQ(numberOfNeighborhoodPixels, range.size());
 
   const std::vector<PixelType> stdVector(range.begin(), range.end());
-  std::vector<PixelType>       reversedStdVector1(numberOfNeighborhoodPixels);
-  std::vector<PixelType>       reversedStdVector2(numberOfNeighborhoodPixels);
-  std::vector<PixelType>       reversedStdVector3(numberOfNeighborhoodPixels);
+  ASSERT_EQ(stdVector.size(), numberOfNeighborhoodPixels);
+
+  std::vector<PixelType> reversedStdVector1(numberOfNeighborhoodPixels);
+  std::vector<PixelType> reversedStdVector2(numberOfNeighborhoodPixels);
+  std::vector<PixelType> reversedStdVector3(numberOfNeighborhoodPixels);
 
   // Checks bidirectionality of the ShapedImageNeighborhoodRange iterators!
   std::reverse_copy(stdVector.cbegin(), stdVector.cend(), reversedStdVector1.begin());
@@ -455,11 +458,13 @@ TEST(ShapedImageNeighborhoodRange, CanBeUsedAsExpressionOfRangeBasedForLoop)
   const itk::Size<ImageType::ImageDimension>                radius = { { 0, 1 } };
   const std::vector<itk::Offset<ImageType::ImageDimension>> offsets =
     itk::GenerateRectangularImageNeighborhoodOffsets(radius);
-  RangeType range{ *image, location, offsets };
+  RangeType           range{ *image, location, offsets };
+  constexpr PixelType reference_value = 42;
 
   for (const PixelType pixel : range)
   {
-    EXPECT_NE(pixel, 42);
+    // Initially not set to reference value
+    EXPECT_NE(pixel, reference_value);
   }
 
   // Note: instead of 'iterator::reference', you may also type 'auto&&', but
@@ -471,12 +476,12 @@ TEST(ShapedImageNeighborhoodRange, CanBeUsedAsExpressionOfRangeBasedForLoop)
   // https://bugs.llvm.org/show_bug.cgi?id=37392
   for (RangeType::iterator::reference pixel : range)
   {
-    pixel = 42;
+    pixel = reference_value;
   }
 
   for (const PixelType pixel : range)
   {
-    EXPECT_EQ(pixel, 42);
+    EXPECT_EQ(pixel, reference_value);
   }
 }
 
@@ -895,7 +900,7 @@ TEST(ShapedImageNeighborhoodRange, SupportsSubscript)
 
 TEST(ShapedImageNeighborhoodRange, ProvidesReverseIterators)
 {
-  using PixelType = unsigned char;
+  using PixelType = unsigned short;
   using ImageType = itk::Image<PixelType>;
   using RangeType = itk::ShapedImageNeighborhoodRange<ImageType>;
   enum
@@ -911,12 +916,15 @@ TEST(ShapedImageNeighborhoodRange, ProvidesReverseIterators)
     itk::GenerateRectangularImageNeighborhoodOffsets(radius);
   RangeType range{ *image, location, offsets };
 
-  const unsigned int numberOfNeighborhoodPixels = 3;
+  constexpr unsigned int numberOfNeighborhoodPixels = 3;
+  ASSERT_EQ(numberOfNeighborhoodPixels, range.size());
 
   const std::vector<PixelType> stdVector(range.begin(), range.end());
-  std::vector<PixelType>       reversedStdVector1(numberOfNeighborhoodPixels);
-  std::vector<PixelType>       reversedStdVector2(numberOfNeighborhoodPixels);
-  std::vector<PixelType>       reversedStdVector3(numberOfNeighborhoodPixels);
+  ASSERT_EQ(stdVector.size(), numberOfNeighborhoodPixels);
+
+  std::vector<PixelType> reversedStdVector1(numberOfNeighborhoodPixels);
+  std::vector<PixelType> reversedStdVector2(numberOfNeighborhoodPixels);
+  std::vector<PixelType> reversedStdVector3(numberOfNeighborhoodPixels);
 
   std::reverse_copy(stdVector.cbegin(), stdVector.cend(), reversedStdVector1.begin());
 
diff --git a/Modules/Core/QuadEdgeMesh/test/itkQuadEdgeMeshEulerOperatorSplitEdgeTest.cxx b/Modules/Core/QuadEdgeMesh/test/itkQuadEdgeMeshEulerOperatorSplitEdgeTest.cxx
index c0111d0f056..1d7e2620526 100644
--- a/Modules/Core/QuadEdgeMesh/test/itkQuadEdgeMeshEulerOperatorSplitEdgeTest.cxx
+++ b/Modules/Core/QuadEdgeMesh/test/itkQuadEdgeMeshEulerOperatorSplitEdgeTest.cxx
@@ -42,7 +42,7 @@ itkQuadEdgeMeshEulerOperatorSplitEdgeTest(int, char *[])
   auto splitEdge = SplitEdge::New();
   std::cout << "     "
             << "Test No Mesh Input";
-  if (splitEdge->Evaluate((QEType *)1))
+  if (splitEdge->Evaluate((QEType *)0))
   {
     std::cout << "FAILED." << std::endl;
     return EXIT_FAILURE;