Skip to content

Commit 7910a2d

Browse files
authored
feat: Use cpp20 by default (#2839)
1 parent d0f0425 commit 7910a2d

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ target_include_directories(xtensor INTERFACE
194194
$<BUILD_INTERFACE:${XTENSOR_INCLUDE_DIR}>
195195
$<INSTALL_INTERFACE:include>)
196196

197-
target_compile_features(xtensor INTERFACE cxx_std_17)
197+
target_compile_features(xtensor INTERFACE cxx_std_20)
198198

199199
target_link_libraries(xtensor INTERFACE xtl)
200200

@@ -205,7 +205,7 @@ OPTION(BUILD_TESTS "xtensor test suite" OFF)
205205
OPTION(BUILD_BENCHMARK "xtensor benchmark" OFF)
206206
OPTION(DOWNLOAD_GBENCHMARK "download google benchmark and build from source" ON)
207207
OPTION(DEFAULT_COLUMN_MAJOR "set default layout to column major" OFF)
208-
OPTION(CPP20 "enables C++20 (experimental)" OFF)
208+
OPTION(CPP23 "enables C++23 (experimental)" OFF)
209209
OPTION(XTENSOR_DISABLE_EXCEPTIONS "Disable C++ exceptions" OFF)
210210
OPTION(DISABLE_MSVC_ITERATOR_CHECK "Disable the MVSC iterator check" ON)
211211

test/CMakeLists.txt

+10-10
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,27 @@ string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
3434

3535
include(set_compiler_flag.cmake)
3636

37-
if(CPP20)
38-
# User requested C++17, but compiler might not oblige.
37+
if(CPP23)
38+
# User requested C++23, but compiler might not oblige.
3939
set_compiler_flag(
4040
_cxx_std_flag CXX
41-
"-std=c++2a" # this should work with GNU, Intel, PGI
42-
"/std:c++20" # this should work with MSVC
41+
"-std=c++23" # this should work with GNU, Intel, PGI
42+
"/std:c++23" # this should work with MSVC
4343
)
4444
if(_cxx_std_flag)
45-
message(STATUS "Building with C++20")
45+
message(STATUS "Building with C++23")
4646
endif()
4747
else()
4848
set_compiler_flag(
4949
_cxx_std_flag CXX REQUIRED
50-
"-std=c++17" # this should work with GNU, Intel, PGI
51-
"/std:c++17" # this should work with MSVC
50+
"-std=c++20" # this should work with GNU, Intel, PGI
51+
"/std:c++20" # this should work with MSVC
5252
)
53-
message(STATUS "Building with C++17")
53+
message(STATUS "Building with C++20")
5454
endif()
5555

5656
if(NOT _cxx_std_flag)
57-
message(FATAL_ERROR "xtensor needs a C++17-compliant compiler.")
57+
message(FATAL_ERROR "xtensor needs a C++20-compliant compiler.")
5858
endif()
5959

6060
OPTION(XTENSOR_ENABLE_WERROR "Turn on -Werror" OFF)
@@ -74,7 +74,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR (CMAKE_CXX_COMPILER_ID MATCHES "Intel"
7474
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -DSKIP_ON_WERROR")
7575
endif()
7676
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
77-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} /MP /bigobj")
77+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} /Zc:__cplusplus /MP /bigobj")
7878
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
7979
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
8080
add_definitions(-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)

test/test_xbuilder.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,13 @@ namespace xt
676676

677677
xt::dynamic_shape<std::size_t> sd = {3, 2, 1};
678678
auto ed1 = empty<double>(sd);
679-
auto ed2 = empty<double, layout_type::column_major>(dynamic_shape<std::size_t>({3, 3, 3}));
679+
// TODO : The ed2 expression do not work on MSVC due to bad deduction since cpp20. We need to fix it for MSVC.
680+
#if defined(_MSVC_LANG)
681+
using ShapeType = xt::dynamic_shape<std::size_t>;
682+
auto ed2 = empty<double, xt::layout_type::column_major, ShapeType>(ShapeType({3, 3, 3}));
683+
#else
684+
auto ed2 = empty<double, xt::layout_type::column_major>(xt::dynamic_shape<std::size_t>({3, 3, 3}));
685+
#endif
680686
auto ed3 = empty<double>(std::vector<std::size_t>({3, 3, 3}));
681687
b = std::is_same<decltype(ed1), xarray<double>>::value;
682688
EXPECT_TRUE(b);

0 commit comments

Comments
 (0)