From a885ee6eb4b4ba2f6648598c258dd97e7fc440db Mon Sep 17 00:00:00 2001 From: Bernhard Manfred Gruber Date: Wed, 15 Dec 2021 12:14:49 +0100 Subject: [PATCH] switch unit tests to C++20 on MSVC and fix range support detection --- CMakeLists.txt | 1 + include/llama/ArrayIndexRange.hpp | 1 + include/llama/HasRanges.hpp | 16 ++++++++++++++++ include/llama/View.hpp | 1 + include/llama/VirtualRecord.hpp | 1 + include/llama/llama.hpp | 1 + include/llama/macros.hpp | 10 ---------- 7 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 include/llama/HasRanges.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index cd1033a32e..b6909f1f1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,7 @@ if (BUILD_TESTING) catch_discover_tests(tests) source_group(TREE "${CMAKE_CURRENT_LIST_DIR}/tests" FILES ${testSources}) if (MSVC) + target_compile_features(tests PRIVATE cxx_std_20) target_compile_options(tests PRIVATE /std:c++latest) # C++20 does not include ranges yet in MSVC, because the ABI is not finalized target_compile_options(tests PRIVATE /permissive- /constexpr:steps10000000 /diagnostics:caret) else() diff --git a/include/llama/ArrayIndexRange.hpp b/include/llama/ArrayIndexRange.hpp index 9539bbd892..4a3ea253a3 100644 --- a/include/llama/ArrayIndexRange.hpp +++ b/include/llama/ArrayIndexRange.hpp @@ -2,6 +2,7 @@ #include "ArrayExtents.hpp" #include "Core.hpp" +#include "HasRanges.hpp" #include #include diff --git a/include/llama/HasRanges.hpp b/include/llama/HasRanges.hpp new file mode 100644 index 0000000000..0dfe25db67 --- /dev/null +++ b/include/llama/HasRanges.hpp @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +// TODO(bgruber): clang 10-13 (libstdc++ from gcc 11.2) fail to compile this currently with the issue described here: +// https://stackoverflow.com/questions/64300832/why-does-clang-think-gccs-subrange-does-not-satisfy-gccs-ranges-begin-functi +// Intel LLVM compiler is also using the clang frontend +#define CAN_USE_RANGES 0 +#if __has_include() +# include +# if defined(__cpp_concepts) && defined(__cpp_lib_ranges) && (!defined(__clang__) || __clang_major__ >= 14) \ + && !defined(__INTEL_LLVM_COMPILER) +# undef CAN_USE_RANGES +# define CAN_USE_RANGES 1 +# endif +#endif diff --git a/include/llama/View.hpp b/include/llama/View.hpp index 5644b974bb..cacdf0a795 100644 --- a/include/llama/View.hpp +++ b/include/llama/View.hpp @@ -8,6 +8,7 @@ #include "BlobAllocators.hpp" #include "Concepts.hpp" #include "Core.hpp" +#include "HasRanges.hpp" #include "macros.hpp" #include "mapping/One.hpp" diff --git a/include/llama/VirtualRecord.hpp b/include/llama/VirtualRecord.hpp index 3d09c48f30..6e980fb572 100644 --- a/include/llama/VirtualRecord.hpp +++ b/include/llama/VirtualRecord.hpp @@ -4,6 +4,7 @@ #pragma once #include "View.hpp" +#include "HasRanges.hpp" #include #include diff --git a/include/llama/llama.hpp b/include/llama/llama.hpp index beaf7a66e0..e420fb5551 100644 --- a/include/llama/llama.hpp +++ b/include/llama/llama.hpp @@ -41,6 +41,7 @@ #include "Copy.hpp" #include "Core.hpp" #include "DumpMapping.hpp" +#include "HasRanges.hpp" #include "Meta.hpp" #include "ProxyRefOpMixin.hpp" #include "Vector.hpp" diff --git a/include/llama/macros.hpp b/include/llama/macros.hpp index aae5182a68..b8cb31bb95 100644 --- a/include/llama/macros.hpp +++ b/include/llama/macros.hpp @@ -116,16 +116,6 @@ /// Forces a copy of a value. This is useful to prevent ODR usage of constants when compiling for GPU targets. #define LLAMA_COPY(x) decltype(x)(x) -// TODO(bgruber): clang 10 and 11 fail to compile this currently with the issue described here: -// https://stackoverflow.com/questions/64300832/why-does-clang-think-gccs-subrange-does-not-satisfy-gccs-ranges-begin-functi -// let's try again with clang 12 -// Intel LLVM compiler is also using the clang frontend -#if(__has_include() && defined(__cpp_concepts) && !defined(__clang__) && !defined(__INTEL_LLVM_COMPILER)) -# define CAN_USE_RANGES 1 -#else -# define CAN_USE_RANGES 0 -#endif - // https://devblogs.microsoft.com/cppblog/optimizing-the-layout-of-empty-base-classes-in-vs2015-update-2-3/ #if defined(_MSC_VER) # define LLAMA_DECLSPEC_EMPTY_BASES __declspec(empty_bases)