diff --git a/Documentation/AI/compiler-cautions.md b/Documentation/AI/compiler-cautions.md index 02c45eb05f9..4d0d15878e5 100644 --- a/Documentation/AI/compiler-cautions.md +++ b/Documentation/AI/compiler-cautions.md @@ -357,6 +357,35 @@ class Foo { }; ``` +### 6c. `-Wunused-but-set-variable` — GCC (declare-then-assign refactoring) + +After converting `T x; x = func();` to `const T x = func();`, GCC warns if +`x` is never read downstream. Apple Clang and MSVC typically don't fire this. +This is the most common warning introduced by STYLE: declare-then-assign +refactoring commits. + +```cpp +// Triggers warning — computed but never tested: +const MatrixType inverse = matrix.GetInverse(); + +// Fix for test code — add a meaningful assertion: +const MatrixType inverse = matrix.GetInverse(); +if (itk::Math::NotExactlyEquals(inverse(0, 0), expected)) +{ + std::cerr << "Problem with GetInverse()" << std::endl; + return EXIT_FAILURE; +} + +// Fix for production code — don't capture if unneeded: +matrix.GetInverse(); // called for side effect only +``` + +In test files, **always prefer adding a test assertion** over suppressing +with `[[maybe_unused]]` or `static_cast()`. Tests that compute values +without checking them are a missed coverage opportunity. + +**References:** PR #6044, CDash build 11198750. + --- ## 7. MSVC-Specific Warnings @@ -537,6 +566,7 @@ When refactoring existing code, verify each item: - [ ] `std::vector` replacing `new[]` — guard `data()` / `operator[]` calls on potentially empty vectors - [ ] Lambda captures — no unused captures; `constexpr` variables don't need capture - [ ] Loop variables initialized at declaration +- [ ] Declare-then-assign conversions: if `const T x = func()` is never read downstream, add a test assertion (in test code) or restructure (in production code) — GCC `-Wunused-but-set-variable` fires on captured-but-unread return values - [ ] `bool` not used with `|=` for exit-status accumulation — use `int` - [ ] Third-party header includes wrapped with appropriate `ITK_CLANG_SUPPRESS_*` macros - [ ] Explicit template instantiations in shared-build modules marked `ITK_TEMPLATE_EXPORT` diff --git a/Modules/Core/Common/include/itkConceptChecking.h b/Modules/Core/Common/include/itkConceptChecking.h index 606b7b3ef8a..91674f9c74b 100644 --- a/Modules/Core/Common/include/itkConceptChecking.h +++ b/Modules/Core/Common/include/itkConceptChecking.h @@ -775,9 +775,8 @@ struct HasZero void constraints() { - T a; + T a = T{}; - a = T{}; Detail::IgnoreUnusedVariable(a); } }; diff --git a/Modules/Core/Common/include/itkImage.hxx b/Modules/Core/Common/include/itkImage.hxx index 22d782043da..70f4679d132 100644 --- a/Modules/Core/Common/include/itkImage.hxx +++ b/Modules/Core/Common/include/itkImage.hxx @@ -38,10 +38,8 @@ template void Image::Allocate(bool initializePixels) { - SizeValueType num; - this->ComputeOffsetTable(); - num = static_cast(this->GetOffsetTable()[VImageDimension]); + SizeValueType num = static_cast(this->GetOffsetTable()[VImageDimension]); m_Buffer->Reserve(num, initializePixels); } diff --git a/Modules/Core/Common/include/itkPyImageFilter.hxx b/Modules/Core/Common/include/itkPyImageFilter.hxx index 0ee8cc3bb0d..f10a75a85f1 100644 --- a/Modules/Core/Common/include/itkPyImageFilter.hxx +++ b/Modules/Core/Common/include/itkPyImageFilter.hxx @@ -151,10 +151,8 @@ PyImageFilter::GenerateOutputInformation() // make sure that the CommandCallable is in fact callable if (PyCallable_Check(this->m_GenerateOutputInformationCallable)) { - PyObject * result; - PyObject * args = PyTuple_Pack(1, this->m_Self); - result = PyObject_Call(this->m_GenerateOutputInformationCallable, args, (PyObject *)NULL); + PyObject * result = PyObject_Call(this->m_GenerateOutputInformationCallable, args, (PyObject *)NULL); SWIG_Py_DECREF(args); if (result) @@ -214,10 +212,8 @@ PyImageFilter::GenerateInputRequestedRegion() // make sure that the CommandCallable is in fact callable if (PyCallable_Check(this->m_GenerateInputRequestedRegionCallable)) { - PyObject * result; - PyObject * args = PyTuple_Pack(1, this->m_Self); - result = PyObject_Call(this->m_GenerateInputRequestedRegionCallable, args, (PyObject *)NULL); + PyObject * result = PyObject_Call(this->m_GenerateInputRequestedRegionCallable, args, (PyObject *)NULL); SWIG_Py_DECREF(args); if (result) @@ -249,10 +245,8 @@ PyImageFilter::GenerateData() } else { - PyObject * result; - PyObject * args = PyTuple_Pack(1, this->m_Self); - result = PyObject_Call(this->m_GenerateDataCallable, args, (PyObject *)NULL); + PyObject * result = PyObject_Call(this->m_GenerateDataCallable, args, (PyObject *)NULL); SWIG_Py_DECREF(args); if (result) diff --git a/Modules/Core/Common/src/itkObjectFactoryBase.cxx b/Modules/Core/Common/src/itkObjectFactoryBase.cxx index 1b162e598bd..5ddc5b2612f 100644 --- a/Modules/Core/Common/src/itkObjectFactoryBase.cxx +++ b/Modules/Core/Common/src/itkObjectFactoryBase.cxx @@ -316,7 +316,7 @@ ObjectFactoryBase::LoadDynamicFactories() static std::string CreateFullPath(const char * path, const char * file) { - std::string ret; + std::string ret = path; # ifdef _WIN32 const char sep = '\\'; @@ -326,7 +326,6 @@ CreateFullPath(const char * path, const char * file) /** * make sure the end of path is a separator */ - ret = path; if (!ret.empty() && ret.back() != sep) { ret += sep; diff --git a/Modules/Core/Common/test/itkAnnulusOperatorGTest.cxx b/Modules/Core/Common/test/itkAnnulusOperatorGTest.cxx index 90d1646888d..aabcc38bf01 100644 --- a/Modules/Core/Common/test/itkAnnulusOperatorGTest.cxx +++ b/Modules/Core/Common/test/itkAnnulusOperatorGTest.cxx @@ -115,8 +115,7 @@ TEST(AnnulusOperator, CreateAndInspect) annulus.CreateOperator(); - OperatorType::SizeType annulusSize; - annulusSize = annulus.GetSize(); + OperatorType::SizeType annulusSize = annulus.GetSize(); std::cout << ", N = " << annulusSize << ", r = " << annulus.GetInnerRadius() << ", t = " << annulus.GetThickness() << ", i = " << annulus.GetInteriorValue() << ", a = " << annulus.GetAnnulusValue() << ", e = " << annulus.GetExteriorValue() << std::endl; diff --git a/Modules/Core/Common/test/itkBoundaryConditionGTest.cxx b/Modules/Core/Common/test/itkBoundaryConditionGTest.cxx index bb4f6dfd8f9..557bd835b3b 100644 --- a/Modules/Core/Common/test/itkBoundaryConditionGTest.cxx +++ b/Modules/Core/Common/test/itkBoundaryConditionGTest.cxx @@ -102,14 +102,12 @@ TEST(BoundaryCondition, ConstantBoundaryAtImageEdge) cbc.SetConstant(0.0f); it2d.OverrideBoundaryCondition(&cbc); - SmartIteratorType::NeighborhoodType tempN; - SmartIteratorType::NeighborhoodType temp2N; - temp2N = it2d.GetNeighborhood(); // initialize + SmartIteratorType::NeighborhoodType temp2N = it2d.GetNeighborhood(); it2d.GoToEnd(); --it2d; - tempN = it2d.GetNeighborhood(); + SmartIteratorType::NeighborhoodType tempN = it2d.GetNeighborhood(); printn(tempN.GetBufferReference(), tempN.GetSize()); // The 2D image is 30x15, filled with 100*j + i. @@ -169,8 +167,7 @@ TEST(BoundaryCondition, ZeroFluxNeumannBoundaryTraversal) cbc.SetConstant(0.0f); it2d.OverrideBoundaryCondition(&cbc); - SmartIteratorType::NeighborhoodType temp2N; - temp2N = it2d.GetNeighborhood(); // initialize + SmartIteratorType::NeighborhoodType temp2N = it2d.GetNeighborhood(); itk::ZeroFluxNeumannBoundaryCondition neumann; for (int yak = 0; yak < 2; ++yak) diff --git a/Modules/Core/Common/test/itkConstNeighborhoodIteratorWithOnlyIndexTest.cxx b/Modules/Core/Common/test/itkConstNeighborhoodIteratorWithOnlyIndexTest.cxx index f9129aea53d..286a8491360 100644 --- a/Modules/Core/Common/test/itkConstNeighborhoodIteratorWithOnlyIndexTest.cxx +++ b/Modules/Core/Common/test/itkConstNeighborhoodIteratorWithOnlyIndexTest.cxx @@ -208,10 +208,9 @@ itkConstNeighborhoodIteratorWithOnlyIndexTestRun() std::cout << "Creating ConstNeighborhoodIterator" << std::endl; ConstNeighborhoodIteratorType ra_it(radius, ra_img, ra_img->GetRequestedRegion()); - ConstNeighborhoodIteratorType copy_it; + ConstNeighborhoodIteratorType copy_it = ra_it; std::cout << "Test copying." << std::endl; - copy_it = ra_it; if (copy_it != ra_it || !(copy_it == ra_it)) { std::cerr << "Failure with copying or equality comparison." << std::endl; diff --git a/Modules/Core/Common/test/itkExceptionObjectTest.cxx b/Modules/Core/Common/test/itkExceptionObjectTest.cxx index 07e69b9a8c8..d26decd4c27 100644 --- a/Modules/Core/Common/test/itkExceptionObjectTest.cxx +++ b/Modules/Core/Common/test/itkExceptionObjectTest.cxx @@ -159,8 +159,7 @@ itkExceptionObjectTest(int, char *[]) Se.SetLocation("SE LOCATION"); Se.SetDescription("SE DESCRIPTION"); itk::SampleError Sf(Se); - itk::SampleError Sg; - Sg = Sf; + itk::SampleError Sg = Sf; std::cout << Sg << std::endl; diff --git a/Modules/Core/Common/test/itkExtractImageTest.cxx b/Modules/Core/Common/test/itkExtractImageTest.cxx index e181121dc3d..58e80c1c769 100644 --- a/Modules/Core/Common/test/itkExtractImageTest.cxx +++ b/Modules/Core/Common/test/itkExtractImageTest.cxx @@ -133,8 +133,8 @@ itkExtractImageTest(int, char *[]) std::cout << "Input Image: " << if2 << std::endl; // Create a filter - itk::ExtractImageFilter::Pointer extract; - extract = itk::ExtractImageFilter::New(); + const itk::ExtractImageFilter::Pointer extract = + itk::ExtractImageFilter::New(); extract->SetInput(if2); // fill in an image @@ -218,8 +218,8 @@ itkExtractImageTest(int, char *[]) extract->SetExtractionRegion(extractRegion); // Create a stream - itk::StreamingImageFilter::Pointer stream; - stream = itk::StreamingImageFilter::New(); + const itk::StreamingImageFilter::Pointer stream = + itk::StreamingImageFilter::New(); stream->SetInput(extract->GetOutput()); stream->SetNumberOfStreamDivisions(2); @@ -289,8 +289,8 @@ itkExtractImageTest(int, char *[]) } // Case 3: Try extracting a single row - itk::ExtractImageFilter::Pointer lineExtract; - lineExtract = itk::ExtractImageFilter::New(); + const itk::ExtractImageFilter::Pointer lineExtract = + itk::ExtractImageFilter::New(); lineExtract->SetDirectionCollapseToGuess(); lineExtract->SetInput(if2); @@ -307,9 +307,8 @@ itkExtractImageTest(int, char *[]) std::cout << "After 1D extraction. " << std::endl; // test the dimension collapse - LineImage::RegionType requestedLineRegion; + LineImage::RegionType requestedLineRegion = lineExtract->GetOutput()->GetRequestedRegion(); - requestedLineRegion = lineExtract->GetOutput()->GetRequestedRegion(); itk::ImageRegionIterator iteratorLineIn(lineExtract->GetOutput(), requestedLineRegion); diff --git a/Modules/Core/Common/test/itkImageIteratorTest.cxx b/Modules/Core/Common/test/itkImageIteratorTest.cxx index 3aba5f62bc2..6c8514d27dc 100644 --- a/Modules/Core/Common/test/itkImageIteratorTest.cxx +++ b/Modules/Core/Common/test/itkImageIteratorTest.cxx @@ -96,7 +96,8 @@ itkImageIteratorTest(int, char *[]) // Exercise copy constructor const VectorImageIterator itr3(itr1); - // Exercise assignment operator + // Exercise assignment operator — intentionally two-line; do NOT merge + // into `VectorImageIterator itr4 = itr1` which invokes copy constructor. VectorImageIterator itr4; itr4 = itr1; diff --git a/Modules/Core/Common/test/itkImageLinearIteratorTest.cxx b/Modules/Core/Common/test/itkImageLinearIteratorTest.cxx index f22cab5d9d5..e742c9e0d6e 100644 --- a/Modules/Core/Common/test/itkImageLinearIteratorTest.cxx +++ b/Modules/Core/Common/test/itkImageLinearIteratorTest.cxx @@ -231,8 +231,7 @@ itkImageLinearIteratorTest(int, char *[]) bot.SetDirection(0); // 0=x, 1=y, 2=z bot.GoToBegin(); - ImageType::IndexType testIndex; - testIndex = start; + ImageType::IndexType testIndex = start; testIndex[1] += 2; // advance two lines in Y bot.NextLine(); // advance two lines in Y @@ -274,8 +273,7 @@ itkImageLinearIteratorTest(int, char *[]) cbot.SetDirection(0); // 0=x, 1=y, 2=z cbot.GoToBegin(); - ImageType::IndexType testIndex; - testIndex = start; + ImageType::IndexType testIndex = start; testIndex[1] += 2; // advance two lines in Y cbot.NextLine(); // advance two lines in Y diff --git a/Modules/Core/Common/test/itkImageRegionConstIteratorWithOnlyIndexTest.cxx b/Modules/Core/Common/test/itkImageRegionConstIteratorWithOnlyIndexTest.cxx index fe184e0a86c..579fa930d66 100644 --- a/Modules/Core/Common/test/itkImageRegionConstIteratorWithOnlyIndexTest.cxx +++ b/Modules/Core/Common/test/itkImageRegionConstIteratorWithOnlyIndexTest.cxx @@ -122,9 +122,8 @@ class itkImageRegionConstIteratorWithOnlyIndexTestIteratorTester } // Test iterating fwd by line - IndexType index; it.GoToBegin(); - index = it.GetIndex(); + IndexType index = it.GetIndex(); for (unsigned int i = 0; i < region.GetSize()[0]; ++i) { ++it; diff --git a/Modules/Core/Common/test/itkMatrixTest.cxx b/Modules/Core/Common/test/itkMatrixTest.cxx index c2fe5fb027c..febf15b6b5f 100644 --- a/Modules/Core/Common/test/itkMatrixTest.cxx +++ b/Modules/Core/Common/test/itkMatrixTest.cxx @@ -76,14 +76,34 @@ itkMatrixTest(int, char *[]) matrix2.SetIdentity(); matrix2.GetVnlMatrix()(0, 0) = 10; - MatrixType matrixProduct; - matrixProduct = matrix * matrix2; + MatrixType matrixProduct = matrix * matrix2; - MatrixType matrix3; - matrix3 = matrix.GetInverse(); + // identity * matrix2 should equal matrix2 + if (itk::Math::NotExactlyEquals(matrixProduct(0, 0), 10) || itk::Math::NotExactlyEquals(matrixProduct(1, 1), 1) || + itk::Math::NotExactlyEquals(matrixProduct(2, 2), 1) || itk::Math::NotExactlyEquals(matrixProduct(0, 1), 0) || + itk::Math::NotExactlyEquals(matrixProduct(1, 0), 0)) + { + std::cerr << "Problem with matrix product" << std::endl; + return EXIT_FAILURE; + } + + const MatrixType matrix3 = matrix.GetInverse(); + // Inverse of identity should be identity + if (itk::Math::NotExactlyEquals(matrix3(0, 0), 1) || itk::Math::NotExactlyEquals(matrix3(1, 1), 1) || + itk::Math::NotExactlyEquals(matrix3(2, 2), 1) || itk::Math::NotExactlyEquals(matrix3(0, 1), 0)) + { + std::cerr << "Problem with GetInverse()" << std::endl; + return EXIT_FAILURE; + } - MatrixType matrix4; - matrix4 = matrix.GetTranspose(); + const MatrixType matrix4 = matrix.GetTranspose(); + // Transpose of identity should be identity + if (itk::Math::NotExactlyEquals(matrix4(0, 0), 1) || itk::Math::NotExactlyEquals(matrix4(1, 1), 1) || + itk::Math::NotExactlyEquals(matrix4(2, 2), 1) || itk::Math::NotExactlyEquals(matrix4(0, 1), 0)) + { + std::cerr << "Problem with GetTranspose()" << std::endl; + return EXIT_FAILURE; + } auto matrix5 = itk::MakeFilled(1.7); @@ -217,11 +237,9 @@ itkMatrixTest(int, char *[]) } } - AddSubtractMatrixType m3; - m3 = m1 + m2; + AddSubtractMatrixType m3 = m1 + m2; - AddSubtractMatrixType m4; - m4 = m1 - m2; + AddSubtractMatrixType m4 = m1 - m2; std::cout << "Results of ITK matrix addition" << std::endl; std::cout << "M1 = " << std::endl << m1 << std::endl; @@ -311,8 +329,7 @@ itkMatrixTest(int, char *[]) } } - MatrixType matrixC; - matrixC = vnlMatrixA; // Test assignment + MatrixType matrixC = vnlMatrixA; { // verify values constexpr double tolerance{ 1e-7 }; diff --git a/Modules/Core/Common/test/itkNeighborhoodAlgorithmTest.cxx b/Modules/Core/Common/test/itkNeighborhoodAlgorithmTest.cxx index c98d34f18e3..9a7df138eda 100644 --- a/Modules/Core/Common/test/itkNeighborhoodAlgorithmTest.cxx +++ b/Modules/Core/Common/test/itkNeighborhoodAlgorithmTest.cxx @@ -29,9 +29,8 @@ ImageBoundaryFaceCalculatorTest(TImage * image, using FaceCalculatorType = itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator; using FaceListType = typename FaceCalculatorType::FaceListType; FaceCalculatorType faceCalculator; - FaceListType faceList; + FaceListType faceList = faceCalculator(image, region, radius); - faceList = faceCalculator(image, region, radius); for (auto fit = faceList.begin(); fit != faceList.end(); ++fit) { std::cout << "Number of pixels : " << fit->GetNumberOfPixels() << std::endl; diff --git a/Modules/Core/Common/test/itkRangeGTestUtilities.h b/Modules/Core/Common/test/itkRangeGTestUtilities.h index 18778b2aa74..078d319e04e 100644 --- a/Modules/Core/Common/test/itkRangeGTestUtilities.h +++ b/Modules/Core/Common/test/itkRangeGTestUtilities.h @@ -82,6 +82,8 @@ class RangeGTestUtilities static void ExpectCopyAssignedRangeHasSameIteratorsAsOriginal(const TRange & originalRange) { + // Intentionally two-line; do NOT merge into `TRange copyAssignedRange = originalRange` + // which invokes copy constructor instead of operator=. TRange copyAssignedRange; copyAssignedRange = originalRange; @@ -106,6 +108,8 @@ class RangeGTestUtilities { const TRange originalRangeBeforeMove = originalRange; + // Intentionally two-line; do NOT merge into `TRange moveAssignedRange = std::move(...)` + // which invokes move constructor instead of operator=. TRange moveAssignedRange; moveAssignedRange = std::move(originalRange); diff --git a/Modules/Core/Common/test/itkSliceIteratorTest.cxx b/Modules/Core/Common/test/itkSliceIteratorTest.cxx index a07b7bbe142..b66751cc8a8 100644 --- a/Modules/Core/Common/test/itkSliceIteratorTest.cxx +++ b/Modules/Core/Common/test/itkSliceIteratorTest.cxx @@ -25,13 +25,12 @@ template void FillRegionSequential(itk::SmartPointer> I) { - itk::Size Index; + itk::Size Index = (I->GetRequestedRegion()).GetSize(); unsigned long Location[VDimension]; itk::ImageRegionIterator> data(I, I->GetRequestedRegion()); - Index = (I->GetRequestedRegion()).GetSize(); unsigned int ArrayLength = 1; for (unsigned int iDim = 0; iDim < VDimension; ++iDim) diff --git a/Modules/Core/Common/test/itkSmartPointerGTest.cxx b/Modules/Core/Common/test/itkSmartPointerGTest.cxx index 9f7c8ab9f73..49e92bc50a2 100644 --- a/Modules/Core/Common/test/itkSmartPointerGTest.cxx +++ b/Modules/Core/Common/test/itkSmartPointerGTest.cxx @@ -242,9 +242,8 @@ TEST(SmartPointer, ConvertingRegisterCount) const Derived1Pointer d1ptr = Derived1::New(); EXPECT_EQ(1, d1ptr->GetRegisterCount()); - Derived1Pointer d1ptr2; + const Derived1Pointer d1ptr2 = d1ptr; - d1ptr2 = d1ptr; EXPECT_EQ(2, d1ptr->GetRegisterCount()); EXPECT_EQ(2, d1ptr2->GetRegisterCount()); } @@ -254,9 +253,8 @@ TEST(SmartPointer, ConvertingRegisterCount) const Derived1Pointer d1ptr = Derived1::New(); EXPECT_EQ(1, d1ptr->GetRegisterCount()); - ConstDerived1Pointer cd1ptr; + const ConstDerived1Pointer cd1ptr = d1ptr; - cd1ptr = d1ptr; EXPECT_EQ(2, d1ptr->GetRegisterCount()); EXPECT_EQ(2, cd1ptr->GetRegisterCount()); } @@ -266,9 +264,8 @@ TEST(SmartPointer, ConvertingRegisterCount) const Derived1Pointer d1ptr = Derived1::New(); EXPECT_EQ(1, d1ptr->GetRegisterCount()); - BasePointer bptr; + const BasePointer bptr = d1ptr; - bptr = d1ptr; EXPECT_EQ(2, d1ptr->GetRegisterCount()); EXPECT_EQ(2, static_cast(bptr.GetPointer())->GetRegisterCount()); } @@ -328,8 +325,7 @@ TEST(SmartPointer, ConvertingRegisterCount) Derived1Pointer d1ptr = Derived1::New(); EXPECT_EQ(1, d1ptr->GetRegisterCount()); - Derived1Pointer d1ptr2; - d1ptr2 = std::move(d1ptr); + const Derived1Pointer d1ptr2 = std::move(d1ptr); EXPECT_EQ(1, d1ptr2->GetRegisterCount()); EXPECT_TRUE(d1ptr.IsNull()); } @@ -339,8 +335,7 @@ TEST(SmartPointer, ConvertingRegisterCount) Derived1Pointer d1ptr = Derived1::New(); EXPECT_EQ(1, d1ptr->GetRegisterCount()); - ConstDerived1Pointer cd1ptr; - cd1ptr = std::move(d1ptr); + const ConstDerived1Pointer cd1ptr = std::move(d1ptr); EXPECT_EQ(1, cd1ptr->GetRegisterCount()); EXPECT_TRUE(d1ptr.IsNull()); @@ -351,9 +346,8 @@ TEST(SmartPointer, ConvertingRegisterCount) Derived1Pointer d1ptr = Derived1::New(); EXPECT_EQ(1, d1ptr->GetRegisterCount()); - BasePointer bptr; + const BasePointer bptr = std::move(d1ptr); - bptr = std::move(d1ptr); EXPECT_EQ(1, static_cast(bptr.GetPointer())->GetRegisterCount()); EXPECT_TRUE(d1ptr.IsNull()); } diff --git a/Modules/Core/Common/test/itkSymmetricSecondRankTensorTest.cxx b/Modules/Core/Common/test/itkSymmetricSecondRankTensorTest.cxx index e40264cda7f..5a34dd11ad5 100644 --- a/Modules/Core/Common/test/itkSymmetricSecondRankTensorTest.cxx +++ b/Modules/Core/Common/test/itkSymmetricSecondRankTensorTest.cxx @@ -119,9 +119,8 @@ itkSymmetricSecondRankTensorTest(int, char *[]) pb[4] = 3.55; pb[5] = 5.55; - Float3DTensorType pc; + Float3DTensorType pc = pa + pb; - pc = pa + pb; std::cout << "addition = " << pc << std::endl; pc = pa - pb; diff --git a/Modules/Core/Common/test/itkVariableLengthVectorTest.cxx b/Modules/Core/Common/test/itkVariableLengthVectorTest.cxx index d8491fd8414..f4cf28c3a30 100644 --- a/Modules/Core/Common/test/itkVariableLengthVectorTest.cxx +++ b/Modules/Core/Common/test/itkVariableLengthVectorTest.cxx @@ -48,8 +48,7 @@ itkVariableLengthVectorTest(int, char *[]) g[0] = 4.0; g[1] = 5.0; g[2] = 6.0; - FloatVariableLengthVectorType h; - h = g + f; + FloatVariableLengthVectorType h = g + f; g = h++; h -= 1.1; h *= 2.0; diff --git a/Modules/Core/Common/test/itkVariableSizeMatrixTest.cxx b/Modules/Core/Common/test/itkVariableSizeMatrixTest.cxx index 19d8d3fe3dc..8fa8e6e5824 100644 --- a/Modules/Core/Common/test/itkVariableSizeMatrixTest.cxx +++ b/Modules/Core/Common/test/itkVariableSizeMatrixTest.cxx @@ -41,8 +41,7 @@ itkVariableSizeMatrixTest(int, char *[]) g(2, 0) = 1000.0; g(2, 1) = 1000.0; - FloatVariableSizeMatrixType h; - h = g + f; + FloatVariableSizeMatrixType h = g + f; h *= 2.0; h /= 2.0; h += g; diff --git a/Modules/Core/Common/test/itkVectorGeometryTest.cxx b/Modules/Core/Common/test/itkVectorGeometryTest.cxx index 8df629f77cd..4cea5f0a32e 100644 --- a/Modules/Core/Common/test/itkVectorGeometryTest.cxx +++ b/Modules/Core/Common/test/itkVectorGeometryTest.cxx @@ -42,30 +42,20 @@ itkVectorGeometryTest(int, char *[]) // Vector type using VectorType = itk::Vector; - /* - VectorType vv; - vv = 0, 2, 4; + const VectorType vv{ { 0, 2, 4 } }; - if( vv[0] != 0 || vv[1] != 2 || vv[2] != 4 ) - { - std::cerr << "Error initializing the Vector " << std::endl; - return EXIT_FAILURE; - } - */ + if (vv[0] != 0 || vv[1] != 2 || vv[2] != 4) + { + std::cerr << "Error initializing the Vector " << std::endl; + return EXIT_FAILURE; + } - VectorType va; - va[0] = 1.0; - va[1] = 2.0; - va[2] = 7.0; + VectorType va{ { 1.0, 2.0, 7.0 } }; std::cout << "va = { 1.0, 2.0, 7.0 } = "; std::cout << va << std::endl; - VectorType vb; - - vb[0] = 1.0; - vb[1] = 3.0; - vb[2] = 5.0; + const VectorType vb{ { 1.0, 3.0, 5.0 } }; std::cout << "vb = (1,3,5) = "; std::cout << vb << std::endl; @@ -147,40 +137,40 @@ itkVectorGeometryTest(int, char *[]) // Test for operator== and operator!= { - VectorType vv; - vv[0] = 1; - vv[1] = 3; - vv[2] = 5; + VectorType vv2; + vv2[0] = 1; + vv2[1] = 3; + vv2[2] = 5; constexpr VectorType vw{}; - if (vv == vw) + if (vv2 == vw) { std::cout << std::endl; std::cout << "Problem with operator==() " << std::endl; - std::cout << "Vector " << vv; + std::cout << "Vector " << vv2; std::cout << " is reported as being equal to " << std::endl; std::cout << "Vector " << vw << std::endl; return EXIT_FAILURE; } - const VectorType ww = vv; + const VectorType ww = vv2; - if (vv != ww) + if (vv2 != ww) { std::cout << std::endl; std::cout << "Problem with operator!=() " << std::endl; - std::cout << "Vector " << vv; + std::cout << "Vector " << vv2; std::cout << " is reported as being different from " << std::endl; std::cout << "Vector " << ww << std::endl; return EXIT_FAILURE; } - if (!(vv == ww)) + if (!(vv2 == ww)) { std::cout << std::endl; std::cout << "Problem with operator==() " << std::endl; - std::cout << "Vector " << vv; + std::cout << "Vector " << vv2; std::cout << " is reported as not being equal to " << std::endl; std::cout << "Vector " << ww << std::endl; return EXIT_FAILURE; diff --git a/Modules/Core/Common/test/itkVersorTest.cxx b/Modules/Core/Common/test/itkVersorTest.cxx index eba1470f0fc..11a537440c5 100644 --- a/Modules/Core/Common/test/itkVersorTest.cxx +++ b/Modules/Core/Common/test/itkVersorTest.cxx @@ -351,8 +351,7 @@ itkVersorTest(int, char *[]) VersorType qa; qa.Set(xa, angle); - VersorType qb; - qb = qa.SquareRoot(); + const VersorType qb = qa.SquareRoot(); if (itk::Math::Absolute(qa.GetAngle() - 2.0 * qb.GetAngle()) > epsilon) {