Open SimeonEhrig opened 3 weeks ago
Even when the compiler supports C++20, problems will occur when including Alpaka into a code that itself is still C++17. So, this check should be more specifically about the C++ configuration of downstream codes that include Alpaka. I expect that this will be a common pitfall during the time shortly after Alpaka switches to C++20.
Isn't it enough to check
#if __cplusplus < 202002L
#error Alpaka supports only C++ 20 and later standards
#endif
in one of the main alpaka headers ?
Isn't it enough to check
#if __cplusplus < 202002L #error Alpaka supports only C++ 20 and later standards #endif
in one of the main alpaka headers ?
Yes, and we should implement this for the approach if you don't use CMake. For CMake it would be a fall back, because in the configure phase of CMake, there is no code compiled. Therefore it will not fail at configure time. Therefore we have to solutions:
Looks like mdspan has our solution :-) If I compile with mdspan, I get following message if I run CMake configure:
[cmake] -- Detected support for C++23 standard
And I found the following CMake code in mdspan:
if("cxx_std_23" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
set(CMAKE_CXX_STANDARD 23)
message(STATUS "Detected support for C++23 standard")
elseif("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
set(CMAKE_CXX_STANDARD 20)
message(STATUS "Detected support for C++20 standard")
elseif("cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
set(CMAKE_CXX_STANDARD 17)
message(STATUS "Detected support for C++17 standard")
elseif("cxx_std_14" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
set(CMAKE_CXX_STANDARD 14)
message(STATUS "Detected support for C++14 standard")
else()
message(FATAL_ERROR "Cannot detect CXX_STANDARD of C++14 or newer.")
endif()
In a offline discussion with @franzpoeschel he told me, that there are some confusion because alpaka does not compile with C++17 anymore. The reason is because the dev branch only supports C++20 and newer but the latest release (1.2) supports C++17.
Therefore an improvement would be to check the supported C++ standard of the compiler in CMake and display a message that the compiler does not support C++20 and maybe the message also to upgrade the compiler or use alpaka 1.2.