Skip to content

Conversation

@hjmjohnson
Copy link
Member

Implements detection of local variables which could be declared as const but
are not. Declaring variables as const is recommended by many coding
guidelines, such as: ES.25 from the C++ Core Guidelines.

cd ${BLDDIR}
run-clang-tidy.py -extra-arg=-D__clang__ -checks=-,misc-const-correctness -header-filter=. -fix

PR Checklist

@hjmjohnson hjmjohnson added the type:Style Style changes: no logic impact (indentation, comments, naming) label Dec 9, 2024
@hjmjohnson hjmjohnson added this to the ITK 6.0 Beta 1 milestone Dec 9, 2024
@hjmjohnson hjmjohnson self-assigned this Dec 9, 2024
@github-actions github-actions bot added type:Design Improvement in the design of a given area and removed type:Style Style changes: no logic impact (indentation, comments, naming) labels Dec 9, 2024
@hjmjohnson
Copy link
Member Author

Builds upon #5023
Builds upon #5024

@hjmjohnson hjmjohnson force-pushed the instrument-with-const branch 2 times, most recently from e48075b to 0f5134c Compare December 9, 2024 12:42
@hjmjohnson hjmjohnson force-pushed the instrument-with-const branch 7 times, most recently from 610b541 to f17aa08 Compare December 10, 2024 02:41
@hjmjohnson hjmjohnson marked this pull request as ready for review December 10, 2024 02:42
@hjmjohnson
Copy link
Member Author

The last two commits represent warnings that appear only on Windows/Linux builds. I left them broken out as separate patchsets to help document what warning occurred and show how they were overcome.

@hjmjohnson hjmjohnson force-pushed the instrument-with-const branch from 4495fa0 to b044168 Compare December 10, 2024 17:50
@thewtex thewtex requested a review from N-Dekker December 10, 2024 19:49
@hjmjohnson hjmjohnson force-pushed the instrument-with-const branch from b044168 to eef6d4c Compare December 10, 2024 20:47
@hjmjohnson hjmjohnson added the type:Style Style changes: no logic impact (indentation, comments, naming) label Dec 10, 2024
@hjmjohnson hjmjohnson force-pushed the instrument-with-const branch from eef6d4c to 2c66c13 Compare December 11, 2024 01:54
@github-actions github-actions bot removed the type:Style Style changes: no logic impact (indentation, comments, naming) label Dec 11, 2024
Implements detection of local variables which could be declared as const but
are not. Declaring variables as const is recommended by many coding
guidelines, such as: ES.25 from the C++ Core Guidelines.

cd ${BLDDIR}
run-clang-tidy.py -extra-arg=-D__clang__ -checks=-*,misc-const-correctness -header-filter=.* -fix
lambda capture 'n' is not required to be captured for this use [-Wunused-lambda-capture]
Modules\IO\Meta\test\testMetaImage.cxx(154): error C2666: 'MetaImage::SequenceID': 2 overloads have similar conversions
Modules\ThirdParty\MetaIO\src\MetaIO\src\metaImage.h(182): note: could be 'void MetaImage::SequenceID(const float *)'
Modules\ThirdParty\MetaIO\src\MetaIO\src\metaImage.h(180): note: or       'float MetaImage::SequenceID(int) const'
Modules\IO\Meta\test\testMetaImage.cxx(154): note: while trying to match the argument list '(const int)'
Modules\IO\Meta\test\testMetaImage.cxx(154): note: note: qualification adjustment (const/volatile) may be causing the ambiguity

Modules\IO\Meta\test\testMetaImage.cxx(165): error C2666: 'MetaImage::ElementSize': 3 overloads have similar conversions
Modules\ThirdParty\MetaIO\src\MetaIO\src\metaImage.h(201): note: could be 'void MetaImage::ElementSize(const float *)'
Modules\ThirdParty\MetaIO\src\MetaIO\src\metaImage.h(199): note: or       'void MetaImage::ElementSize(const double *)'
Modules\ThirdParty\MetaIO\src\MetaIO\src\metaImage.h(197): note: or       'double MetaImage::ElementSize(int) const'
Modules\IO\Meta\test\testMetaImage.cxx(165): note: while trying to match the argument list '(const int)'
Modules\IO\Meta\test\testMetaImage.cxx(165): note: note: qualification adjustment (const/volatile) may be causing the ambiguity
Modules\Filtering\LabelMap\include\itkShapeKeepNObjectsLabelMapFilter.h(156):

warning C4269: 'comparator': 'const' automatic data initialized with compiler generated default constructor produces unreliable results
Modules/Core/Common/test/itkImageBufferRangeGTest.cxx: In lambda function:
Modules/Core/Common/test/itkImageBufferRangeGTest.cxx:670:61:
      warning: declaration of 'n' shadows a previous local [-Wshadow]
  670 |     const auto expectedResult = [&r](const difference_type n) {
      |                                                             ^
Modules/Core/Common/test/itkImageBufferRangeGTest.cxx:667:31:
      note: shadowed declaration is here
  667 |     constexpr difference_type n = 3;
      |                               ^
Modules/Core/Common/test/itkImageBufferRangeGTest.cxx: In lambda function:
@hjmjohnson hjmjohnson force-pushed the instrument-with-const branch from 2c66c13 to 9683b52 Compare December 11, 2024 01:56
@thewtex thewtex merged commit 9683b52 into InsightSoftwareConsortium:master Dec 11, 2024
17 checks passed
@hjmjohnson hjmjohnson deleted the instrument-with-const branch January 26, 2025 21:46
@hjmjohnson hjmjohnson restored the instrument-with-const branch February 4, 2025 23:21
@hjmjohnson hjmjohnson deleted the instrument-with-const branch November 1, 2025 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:Design Improvement in the design of a given area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants