From 6b6ddf529f7da2e6436b07832849087b0285e9b1 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Fri, 17 Mar 2023 21:13:22 +0100 Subject: [PATCH 1/4] ENH: Upgrade ITK from C++14 to C++17 Follow-up to pull request https://github.com/InsightSoftwareConsortium/ITK/pull/2563 commit daec0fdd703b1bca16aeb07bc4e0a01101da950a "ENH: Upgrade ITK from C++11 to C++14" --- CMake/ITKInitializeCXXStandard.cmake | 2 +- CMake/itkCompilerChecks.cmake | 8 ++++---- CMakeLists.txt | 6 +++--- Wrapping/macro_files/itk_auto_load_submodules.cmake | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CMake/ITKInitializeCXXStandard.cmake b/CMake/ITKInitializeCXXStandard.cmake index 5345230b569..2f0b90a8ea9 100644 --- a/CMake/ITKInitializeCXXStandard.cmake +++ b/CMake/ITKInitializeCXXStandard.cmake @@ -1,6 +1,6 @@ ## Set the default target properties for ITK if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 14) # Supported values are 14, 17, 20, and 23. + set(CMAKE_CXX_STANDARD 17) # Supported values are 17, 20, and 23. endif() if(NOT CMAKE_CXX_STANDARD_REQUIRED) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/CMake/itkCompilerChecks.cmake b/CMake/itkCompilerChecks.cmake index e13a96b2821..3c47c41e1f8 100644 --- a/CMake/itkCompilerChecks.cmake +++ b/CMake/itkCompilerChecks.cmake @@ -28,13 +28,13 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND message(FATAL_ERROR "Intel C++ (ICC) 17.0 or later is required.") endif () -# Make sure we have C++14 enabled. -if(NOT ITK_IGNORE_CMAKE_CXX14_CHECKS) +# Make sure we have C++17 enabled. +if(NOT ITK_IGNORE_CMAKE_CXX17_CHECKS) # Needed to make sure libraries and executables not built by the - # itkModuleMacros still have the C++14 compiler flags enabled + # itkModuleMacros still have the C++17 compiler flags enabled # Wrap this in an escape hatch for unknown compilers if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 14) # Supported values are 14, 17, 20, and 23. + set(CMAKE_CXX_STANDARD 17) # Supported values are 17, 20, and 23. endif() if(NOT CMAKE_CXX_STANDARD_REQUIRED) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/CMakeLists.txt b/CMakeLists.txt index 74f424e6b46..54df5f0e9bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,9 +33,9 @@ endforeach() include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/ITKInitializeCXXStandard.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/ITKInitializeBuildType.cmake) -# ==== Define language standard configurations requiring at least c++14 standard -if(CMAKE_CXX_STANDARD EQUAL "98" OR CMAKE_CXX_STANDARD LESS "14") - message(FATAL_ERROR "C++98 to C++11 are no longer supported in ITK version 5.3 and greater.") +# ==== Define language standard configurations requiring at least c++17 standard +if(CMAKE_CXX_STANDARD EQUAL "98" OR CMAKE_CXX_STANDARD LESS "17") + message(FATAL_ERROR "C++98 to C++14 are no longer supported in ITK version 5.4 and greater.") endif() set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake ${CMAKE_MODULE_PATH}) diff --git a/Wrapping/macro_files/itk_auto_load_submodules.cmake b/Wrapping/macro_files/itk_auto_load_submodules.cmake index 386547db3fe..81873300b63 100644 --- a/Wrapping/macro_files/itk_auto_load_submodules.cmake +++ b/Wrapping/macro_files/itk_auto_load_submodules.cmake @@ -22,9 +22,9 @@ function(generate_castxml_commandline_flags) # Avoid missing omp.h include set(_castxml_cc_flags ${CMAKE_CXX_FLAGS}) if(CMAKE_CXX_EXTENSIONS) - set(_castxml_cc_flags "${_castxml_cc_flags} ${CMAKE_CXX14_EXTENSION_COMPILE_OPTION}") + set(_castxml_cc_flags "${_castxml_cc_flags} ${CMAKE_CXX17_EXTENSION_COMPILE_OPTION}") else() - set(_castxml_cc_flags "${_castxml_cc_flags} ${CMAKE_CXX14_STANDARD_COMPILE_OPTION}") + set(_castxml_cc_flags "${_castxml_cc_flags} ${CMAKE_CXX17_STANDARD_COMPILE_OPTION}") endif() # Aggressive optimization flags cause cast_xml to give invalid error conditions From a604a44eb772ab73dac6e9a34a4cb76981eabf58 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sat, 18 Mar 2023 10:28:23 +0100 Subject: [PATCH 2/4] COMP: Replace result_of_t with C++17 invoke_result_t in ThreadPool Addresses Visual C++ MSVC 19.29.30148.0 (MSVC/14.29.30133) warnings, saying: > warning C4996: 'std::result_of_t': warning STL4014: std::result_of and > std::result_of_t are deprecated in C++17. They are superseded by > std::invoke_result and std::invoke_result_t. You can define > _SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING or > _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have received > this warning. Note that C++20 has even removed `std::result_of_t`! --- Modules/Core/Common/include/itkThreadPool.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/Core/Common/include/itkThreadPool.h b/Modules/Core/Common/include/itkThreadPool.h index a4a2541e297..ca0be924e8b 100644 --- a/Modules/Core/Common/include/itkThreadPool.h +++ b/Modules/Core/Common/include/itkThreadPool.h @@ -84,9 +84,9 @@ auto result = pool->AddWork([](int param) { return param; }, 7); * std::cout << result.get() << std::endl; */ template auto - AddWork(Function && function, Arguments &&... arguments) -> std::future> + AddWork(Function && function, Arguments &&... arguments) -> std::future> { - using return_type = std::result_of_t; + using return_type = std::invoke_result_t; auto task = std::make_shared>( std::bind(std::forward(function), std::forward(arguments)...)); From 73372e85fb1fb5ae007e49ea9fb8033c1f26400d Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sat, 18 Mar 2023 11:04:08 +0100 Subject: [PATCH 3/4] COMP: Work around GCC < 10 bug, "no user-provided default constructor" Worked around a GCC bug which appeared when having compiler options "-Wextra" and "-std=c++17", that caused warning messages, like: > itkSizeGTest.cxx: In instantiation of 'Size_Fill_Test::TestBody()::: > Modules/Core/Common/test/itkSizeGTest.cxx:126:29: required from here > itkSize.h:70:28: note: 'struct itk::Size<1>' has no user-provided default constructor > itkSize.h:229:40: note: and the implicitly-defined constructor does not initialize 'itk::Size<1>::SizeValueType itk::Size<1>::m_InternalArray [1]' At Azure.fv-az105-696, Linux-Build9859 (GNU 9.4.0): https://open.cdash.org/viewBuildError.php?type=1&buildid=8556515 This compiler bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91070) was fixed with GCC version 10. --- Modules/Core/Common/test/itkSizeGTest.cxx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Modules/Core/Common/test/itkSizeGTest.cxx b/Modules/Core/Common/test/itkSizeGTest.cxx index 49329921f12..854326bc2ba 100644 --- a/Modules/Core/Common/test/itkSizeGTest.cxx +++ b/Modules/Core/Common/test/itkSizeGTest.cxx @@ -115,7 +115,12 @@ TEST(Size, Fill) itk::SizeValueType{ 2 }, std::numeric_limits::max() }) { - itk::Size actualSize; + // Added {} initializer to work around warnings from GCC "-Wextra -std=c++17" (before GCC 10), saying: + // "note: 'struct itk::Size' has no user-provided default constructor" + // as reported by Ignacy Gawedzki "Spurious notes about uninitialized members in C++17" + // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91070 + itk::Size actualSize{}; + actualSize.Fill(sizeValue); const auto expectedSize = itk::Size::Filled(sizeValue); EXPECT_EQ(actualSize, expectedSize); From de7124eacb3466359c1ba529f2e83b4d183ba74f Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Wed, 22 Mar 2023 16:26:21 +0100 Subject: [PATCH 4/4] COMP: Require compiler versions that support C++17 Follow-up to pull request https://github.com/InsightSoftwareConsortium/ITK/pull/2563 commit 4e812d60743a3ed7c09647e7f3f0e8498583c2da "COMP: Require compiler versions that support C++14" Resources: C++ reference - Compiler support for C++17 https://en.cppreference.com/w/cpp/compiler_support/17 Note that for C++17 "hardware interference size" support, we would need GCC 12 and Clang 15. C++17 Support in GCC https://gcc.gnu.org/projects/cxx-status.html#cxx17 Announcing: MSVC Conforms to the C++ Standard, Ulzii Luvsanbat, May 7th, 2018 https://devblogs.microsoft.com/cppblog/announcing-msvc-conforms-to-the-c-standard/ C++17 Features Supported by Intel C++ Compiler Classic, Last Updated: 09/12/2020 By Anoop Madhusoodhanan Prabha https://www.intel.com/content/www/us/en/developer/articles/news/c17-features-supported-by-c-compiler.html Xcode clang version record, Masayuki Yamaya, December 14, 2022 https://gist.github.com/yamaya/2924292 --- CMake/itkCompilerChecks.cmake | 24 +++++++++++----------- Documentation/SupportedCompilers.md | 13 ++++++------ Modules/Core/Common/include/itkMacro.h | 28 ++++++++++---------------- 3 files changed, 30 insertions(+), 35 deletions(-) diff --git a/CMake/itkCompilerChecks.cmake b/CMake/itkCompilerChecks.cmake index 3c47c41e1f8..ed60db6fa71 100644 --- a/CMake/itkCompilerChecks.cmake +++ b/CMake/itkCompilerChecks.cmake @@ -1,31 +1,31 @@ # Minimum compiler version check: GCC if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND - CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1) - message(FATAL_ERROR "GCC 5.1 or later is required.") + CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7) + message(FATAL_ERROR "GCC 7 or later is required.") endif () # Minimum compiler version check: LLVM Clang if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND - CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4) - message(FATAL_ERROR "LLVM Clang 3.4 or later is required.") + CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5) + message(FATAL_ERROR "LLVM Clang 5 or later is required.") endif () -# Minimum compiler version check: Apple Clang >= 7.0.2 (Xcode 7.2.1) +# Minimum compiler version check: Apple Clang >= 10.0.0 (Xcode 10.0) if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND - CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.2) - message(FATAL_ERROR "Apple Clang 7.0.2 or later is required.") + CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0.0) + message(FATAL_ERROR "Apple Clang 10.0.0 or later is required.") endif () -# Minimum compiler version check: Microsoft C/C++ >= 19.10 (MSVC 14.1, Visual Studio 15 2017) +# Minimum compiler version check: Microsoft C/C++ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND - CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10) - message(FATAL_ERROR "Microsoft Visual Studio 2017 or later is required.") + CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.14) + message(FATAL_ERROR "Microsoft Visual Studio 2017 15.7 (MSVC 19.14) or later is required.") endif () # Minimum compiler version check: Intel C++ (ICC) if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND - CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17.0) - message(FATAL_ERROR "Intel C++ (ICC) 17.0 or later is required.") + CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.1) + message(FATAL_ERROR "Intel C++ (ICC) 19.1 or later is required.") endif () # Make sure we have C++17 enabled. diff --git a/Documentation/SupportedCompilers.md b/Documentation/SupportedCompilers.md index cf10bb7bc8a..8ee9abae9f1 100644 --- a/Documentation/SupportedCompilers.md +++ b/Documentation/SupportedCompilers.md @@ -1,21 +1,22 @@ -ITK requires a compiler with C++14 support. +ITK requires a compiler with C++17 support. # Visual Studio * VS2015 and earlier: **NOT supported** -* MSVC toolset v141 (first shipped with VS2017): supported +* MSVC toolset v141 (first shipped with VS2017): supported from VS2017 version 15.7 * MSVC toolset v142 (first shipped with VS2019): supported +* MSVC toolset v143 (first shipped with VS2022): supported # GNU Compile Collection -* GCC 5.1 and later [should be supported](https://www.gnu.org/software/gcc/projects/cxx-status.html). +* GCC 7 and later [should be supported](https://www.gnu.org/software/gcc/projects/cxx-status.html). # LLVM Clang -* Clang 3.4 and later [should be supported](https://clang.llvm.org/cxx_status.html) +* Clang 5 and later [should be supported](https://clang.llvm.org/cxx_status.html) # AppleClang -* AppleClang 7.0.2 and later (from Xcode 7.2.1) [should be supported](https://en.wikipedia.org/wiki/Xcode#Version_history) +* AppleClang 10.0.0 and later (from Xcode 10.0) [should be supported](https://en.wikipedia.org/wiki/Xcode#Version_history) # Intel C++ Compiler -* Intel C++ 17.0 and later +* Intel C++ 19.1 and later # Future versions Future versions of these compilers should be backwards compatible, and thus ITK is expected to work with them. diff --git a/Modules/Core/Common/include/itkMacro.h b/Modules/Core/Common/include/itkMacro.h index a2d3b7aefd2..92929bcfae8 100644 --- a/Modules/Core/Common/include/itkMacro.h +++ b/Modules/Core/Common/include/itkMacro.h @@ -151,19 +151,14 @@ namespace itk #endif /* - * ITK only supports MSVC++ 14.0 and greater - * MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015 version 14.0) - * MSVC++ 14.1 _MSC_VER == 1910 (Visual Studio 2017 version 15.0) - * MSVC++ 14.11 _MSC_VER == 1911 (Visual Studio 2017 version 15.3) - * MSVC++ 14.12 _MSC_VER == 1912 (Visual Studio 2017 version 15.5) - * MSVC++ 14.13 _MSC_VER == 1913 (Visual Studio 2017 version 15.6) + * ITK only supports MSVC++ 14.14 and greater * MSVC++ 14.14 _MSC_VER == 1914 (Visual Studio 2017 version 15.7) * MSVC++ 14.15 _MSC_VER == 1915 (Visual Studio 2017 version 15.8) * MSVC++ 14.16 _MSC_VER == 1916 (Visual Studio 2017 version 15.9) * MSVC++ 14.2 _MSC_VER == 1920 (Visual Studio 2019 Version 16.0) */ -#if defined(_MSC_VER) && (_MSC_VER < 1910) -# error "Visual Studio < 2017 is not supported under ITKv5.3" +#if defined(_MSC_VER) && (_MSC_VER < 1914) +# error "MSVC version before Visual Studio 2017 version 15.7 is not supported under ITKv5.4" #endif #if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140) # error "SUNPro C++ < 5.14.0 is not supported under ITKv5 and above" @@ -177,9 +172,8 @@ namespace itk #if defined(__MWERKS__) # error "The MetroWerks compiler is not supported in ITKv4 and above" #endif -#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && \ - ((__GNUC__ < 5) || ((__GNUC__ == 5) && (__GNUC_MINOR__ < 1))) -# error "GCC < 5.1 is not supported under ITKv5.3" +#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && (__GNUC__ < 7) +# error "GCC < 7 is not supported under ITKv5.4" #endif #if defined(__sgi) // This is true for IRIX 6.5.18m with MIPSPro 7.3.1.3m. @@ -188,14 +182,14 @@ namespace itk # error "The SGI compiler is not supported under ITKv4 and above" #endif #if defined(__APPLE__) -# if defined(__clang__) && (__cplusplus < 201402L) -# error "Apple LLVM < 5.1 (clang < 3.4) or compiling with a standard less than C++14 is not supported under ITKv5.3" +# if defined(__clang__) && (__cplusplus < 201703L) +# error "Apple LLVM compiling with a standard less than C++17 is not supported under ITKv5.4" # endif -#elif defined(__clang__) && ((__clang_major__ < 3) || ((__clang_major__ == 3) && (__clang_minor__ < 4))) -# error "Clang < 3.4 is not supported under ITKv5.3" +#elif defined(__clang__) && (__clang_major__ < 5) +# error "Clang < 5 is not supported under ITKv5.4" #endif -#if defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1700) -# error "Intel C++ < 17.0 is not supported under ITKv5.3" +#if defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1910) +# error "Intel C++ < 19.1 is not supported under ITKv5.4" #endif // Setup symbol exports