COMP: Support C17/C23 standards in VXL and modernize vcl iterator test#6558
COMP: Support C17/C23 standards in VXL and modernize vcl iterator test#6558thewtex wants to merge 1 commit into
Conversation
|
| Filename | Overview |
|---|---|
| Modules/ThirdParty/VNL/src/vxl/CMakeLists.txt | Adds C17/C23 to the accepted standards list, but does not reconcile those values with the file's CMake 3.16.3 minimum. |
| Modules/ThirdParty/VNL/src/vxl/vcl/tests/test_iterator.cxx | Replaces the deprecated std::iterator probe with runtime coverage of standard iterator utilities. |
Reviews (1): Last reviewed commit: "COMP: Support C17/C23 standards in VXL a..." | Re-trigger Greptile
Add "17" and "23" to VALID_C_STANDARDS in the vendored VXL CMake
configuration so ITK can be configured and built with the newer C17
and C23 language standards, matching the C++ standards already accepted
(11/14/17/20).
The "17" and "23" values of CMAKE_C_STANDARD were only added to CMake in
version 3.21, but this configuration declares a lower
cmake_minimum_required. To avoid a confusing downstream failure where an
older CMake accepts the value here and then errors when it tries to apply
a C standard it does not understand, the two new values are only appended
to VALID_C_STANDARDS when the running CMake is 3.21 or newer. On older
CMake, requesting C17/C23 now fails early with the existing clear
validation message. The C++ standards list needs no such guard because
its "17"/"20" values predate the declared CMake minimum.
The vcl test_iterator test previously probed std::iterator<float, int>:
void f(std::iterator<float, int> *) { }
std::iterator has been deprecated since C++17 and this usage triggers
-Werror=deprecated-declarations on GCC and Clang when building under
C++17 or later, breaking the vcl test suite.
Remove the deprecated probe and, rather than leaving an empty test body,
replace it with runtime coverage of the non-deprecated <iterator>
facilities: iterator_traits, distance/advance/next/prev, begin/end,
back_inserter, reverse_iterator, and the ostream/istream stream
iterators. The new test compiles warning-free under -Wall -Wextra
-Wdeprecated -Werror and passes with GCC and Clang across C++14, C++17,
C++20, and C++23.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
dzenanz
left a comment
There was a problem hiding this comment.
CMake change looks OK. I have not taken a good look at the test.
| int test_iterator_main(int /*argc*/,char* /*argv*/[]) | ||
| { | ||
| // invent some more tests. | ||
| return 0; |
There was a problem hiding this comment.
The old test did nothing, but the new tests only test the std:: behaviors on std:: objects, and there is not exercising of vnl objects. I think removing the file completely would be better than adding tests of the standard template library behavior. It is not clear to me what should be tested in this file.
| return 0; | ||
| bool fail = false; | ||
|
|
||
| // std::iterator_traits should expose the expected typedefs. |
There was a problem hiding this comment.
The vcl layer was vxl's 1990s/2000s compiler-portability shim, and vcl/tests/ historically validated that the platform's standard library was usable at all — meaningful on pre-standard compilers, obsolete now. This particular file had already decayed to a single declaration, void f(std::iterator<float,int>*), plus a // invent some more tests comment.
This test is no longer relavant in the ITK vendored vxl.
| # valid when the running CMake understands them. Otherwise a user could pass | ||
| # this validation on an older CMake and then hit a confusing failure when CMake | ||
| # tries to apply a C standard it does not know about. | ||
| if(NOT CMAKE_VERSION VERSION_LESS "3.21") |
There was a problem hiding this comment.
OK for the release-5.4, but unnecessary for the main release where cmake >3.22.1
| set(CMAKE_C_EXTENSIONS OFF) | ||
| endif() | ||
| set(VALID_C_STANDARDS "90" "99" "11") | ||
| # The "17" and "23" values of CMAKE_C_STANDARD were added in CMake 3.21. |
There was a problem hiding this comment.
This comment is verbose for what is fairly obvious from the code itself.
| # valid when the running CMake understands them. Otherwise a user could pass | ||
| # this validation on an older CMake and then hit a confusing failure when CMake | ||
| # tries to apply a C standard it does not know about. | ||
| if(NOT CMAKE_VERSION VERSION_LESS "3.21") |
There was a problem hiding this comment.
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.21")
hjmjohnson
left a comment
There was a problem hiding this comment.
The current test does not test anything related to vcl. The tests are required to pass for any compliant compiler, so it is really testing if std:: works, not if vxl works.
Summary
Enables configuring and building ITK's vendored VXL under the newer C17 and C23 language standards, and repairs the
vcltest_iteratortest, which failed to compile under C++17 and later.Motivation
Modules/ThirdParty/VNL/src/vxl/CMakeLists.txtvalidatesCMAKE_C_STANDARDagainst a hard-codedVALID_C_STANDARDSlist and issues aFATAL_ERRORfor anything outside it. The list only allowed90,99, and11, so configuring ITK with-DCMAKE_C_STANDARD=17(or23) aborted the build even though modern toolchains support these standards — and even though the C++ side already accepts11/14/17/20.Separately,
vcl/tests/test_iterator.cxxcontained a compile-time probe ofstd::iterator:std::iteratorhas been deprecated since C++17. Under-Werror=deprecated-declarations(used in ITK CI-style strict builds) this breaks thevcltest suite on both GCC and Clang when building with C++17 or newer.Changes
Modules/ThirdParty/VNL/src/vxl/CMakeLists.txt— add"17"and"23"toVALID_C_STANDARDSso those standards pass the existingIN_LISTvalidation guard.Modules/ThirdParty/VNL/src/vxl/vcl/tests/test_iterator.cxx— remove the deprecatedstd::iterator<float, int>probe. Rather than leaving the test body empty, add runtime coverage of the non-deprecated<iterator>facilities:std::iterator_traitsstd::distance/std::advance/std::next/std::prevstd::begin/std::end(containers and C arrays)std::back_inserterstd::reverse_iterator(viarbegin/rend)std::ostream_iterator/std::istream_iteratorThe test follows the
fail-flag style of the sibling tests (e.g.test_vector.cxx) and returns non-zero on any mismatch.Testing
The new test compiles warning-free under
-Wall -Wextra -Wdeprecated -Werrorand passes on both GCC and Clang across C++14, C++17, C++20, and C++23. The change is confined to a self-contained standard-library test and a CMake validation list; no public API is affected.🤖 Generated with Claude Code