From 394fc03b3def44b6417d195d8481f624d70249d7 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Thu, 6 Feb 2025 10:44:31 +0100 Subject: [PATCH] EXP: [C++] Require C++20 --- c_glib/meson.build | 2 +- ci/appveyor-cpp-build.bat | 2 +- ci/scripts/cpp_build.sh | 4 ++-- cpp/CMakeLists.txt | 6 +++--- cpp/cmake_modules/GandivaAddBitcode.cmake | 2 +- cpp/cmake_modules/SetupCxxFlags.cmake | 8 ++++---- cpp/examples/minimal_build/CMakeLists.txt | 4 ++-- cpp/examples/minimal_build/run_static.sh | 2 +- cpp/examples/parquet/parquet_arrow/CMakeLists.txt | 4 ++-- cpp/examples/tutorial_examples/CMakeLists.txt | 2 +- cpp/src/arrow/util/string.h | 6 ++---- dev/release/verify-apt.sh | 2 +- dev/release/verify-yum.sh | 2 +- dev/tasks/conda-recipes/arrow-cpp/build-arrow.bat | 2 +- dev/tasks/conda-recipes/arrow-cpp/build-arrow.sh | 2 +- dev/tasks/homebrew-formulae/apache-arrow.rb | 2 +- docs/source/java/cdata.rst | 4 ++-- docs/source/python/integration/extending.rst | 2 +- matlab/CMakeLists.txt | 2 +- python/CMakeLists.txt | 2 +- python/pyarrow/tests/test_cython.py | 4 ++-- 21 files changed, 32 insertions(+), 34 deletions(-) diff --git a/c_glib/meson.build b/c_glib/meson.build index 017765cd14626..84f119ef98673 100644 --- a/c_glib/meson.build +++ b/c_glib/meson.build @@ -20,7 +20,7 @@ project('arrow-glib', 'c', 'cpp', default_options: [ 'c_std=c99', - 'cpp_std=c++17', + 'cpp_std=c++20', ], license: 'Apache-2.0', # Debian: diff --git a/ci/appveyor-cpp-build.bat b/ci/appveyor-cpp-build.bat index b1237fc9958c1..f8e60d2c92a23 100644 --- a/ci/appveyor-cpp-build.bat +++ b/ci/appveyor-cpp-build.bat @@ -93,7 +93,7 @@ cmake -G "%GENERATOR%" %ARROW_CMAKE_ARGS% ^ -DARROW_WITH_ZSTD=ON ^ -DCMAKE_BUILD_TYPE="Release" ^ -DCMAKE_CXX_FLAGS_RELEASE="/MD /Od /UNDEBUG" ^ - -DCMAKE_CXX_STANDARD=17 ^ + -DCMAKE_CXX_STANDARD=20 ^ -DCMAKE_INSTALL_PREFIX=%CONDA_PREFIX%\Library ^ -DCMAKE_UNITY_BUILD=ON ^ -DCMAKE_VERBOSE_MAKEFILE=OFF ^ diff --git a/ci/scripts/cpp_build.sh b/ci/scripts/cpp_build.sh index c1e7adf6a05e0..af68950be5006 100755 --- a/ci/scripts/cpp_build.sh +++ b/ci/scripts/cpp_build.sh @@ -125,7 +125,7 @@ if [ "${ARROW_EMSCRIPTEN:-OFF}" = "ON" ]; then -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE_MAKEFILE:-OFF} \ -DCMAKE_C_FLAGS="${CFLAGS:-}" \ -DCMAKE_CXX_FLAGS="${CXXFLAGS:-}" \ - -DCMAKE_CXX_STANDARD="${CMAKE_CXX_STANDARD:-17}" \ + -DCMAKE_CXX_STANDARD="${CMAKE_CXX_STANDARD:-20}" \ -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR:-lib} \ -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX:-${ARROW_HOME}} \ -DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD:-OFF} \ @@ -216,7 +216,7 @@ else -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE_MAKEFILE:-OFF} \ -DCMAKE_C_FLAGS="${CFLAGS:-}" \ -DCMAKE_CXX_FLAGS="${CXXFLAGS:-}" \ - -DCMAKE_CXX_STANDARD="${CMAKE_CXX_STANDARD:-17}" \ + -DCMAKE_CXX_STANDARD="${CMAKE_CXX_STANDARD:-20}" \ -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR:-lib} \ -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX:-${ARROW_HOME}} \ -DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD:-OFF} \ diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index a7d80c2e96c23..c231fe2adb39c 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -553,10 +553,10 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARROW_CXXFLAGS}") # C++ specific flags. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CXX_COMMON_FLAGS} ${ARROW_CXXFLAGS}") -# Remove --std=c++17 to avoid errors from C compilers -string(REPLACE "-std=c++17" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) +# Remove -std=c++20 to avoid errors from C compilers +string(REPLACE "-std=c++20" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) -# Add C++-only flags, like -std=c++17 +# Add C++-only flags, like -std=c++20 set(CMAKE_CXX_FLAGS "${CXX_ONLY_FLAGS} ${CMAKE_CXX_FLAGS}") # ASAN / TSAN / UBSAN diff --git a/cpp/cmake_modules/GandivaAddBitcode.cmake b/cpp/cmake_modules/GandivaAddBitcode.cmake index 98847f8a186fe..5daf05f9e52ed 100644 --- a/cpp/cmake_modules/GandivaAddBitcode.cmake +++ b/cpp/cmake_modules/GandivaAddBitcode.cmake @@ -17,7 +17,7 @@ # Create bitcode for the given source file. function(gandiva_add_bitcode SOURCE) - set(CLANG_OPTIONS -std=c++17) + set(CLANG_OPTIONS -std=c++20) if(MSVC) # "19.20" means that it's compatible with Visual Studio 16 2019. # We can update this to "19.30" when we dropped support for Visual diff --git a/cpp/cmake_modules/SetupCxxFlags.cmake b/cpp/cmake_modules/SetupCxxFlags.cmake index fdb28b540e2d2..b5a0b48e8b87d 100644 --- a/cpp/cmake_modules/SetupCxxFlags.cmake +++ b/cpp/cmake_modules/SetupCxxFlags.cmake @@ -137,12 +137,12 @@ endif() # This ensures that things like c++17 get passed correctly if(NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 17) -elseif(${CMAKE_CXX_STANDARD} VERSION_LESS 17) - message(FATAL_ERROR "Cannot set a CMAKE_CXX_STANDARD smaller than 17") + set(CMAKE_CXX_STANDARD 20) +elseif(${CMAKE_CXX_STANDARD} VERSION_LESS 20) + message(FATAL_ERROR "Cannot set a CMAKE_CXX_STANDARD smaller than 20") endif() -# We require a C++17 compliant compiler +# We require a C++20 compliant compiler set(CMAKE_CXX_STANDARD_REQUIRED ON) # ARROW-6848: Do not use GNU (or other CXX) extensions diff --git a/cpp/examples/minimal_build/CMakeLists.txt b/cpp/examples/minimal_build/CMakeLists.txt index 95dad34221add..463bbce48ea20 100644 --- a/cpp/examples/minimal_build/CMakeLists.txt +++ b/cpp/examples/minimal_build/CMakeLists.txt @@ -24,10 +24,10 @@ option(ARROW_LINK_SHARED "Link to the Arrow shared library" ON) find_package(Arrow REQUIRED) if(NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD 20) endif() -# We require a C++17 compliant compiler +# We require a C++20 compliant compiler set(CMAKE_CXX_STANDARD_REQUIRED ON) if(NOT CMAKE_BUILD_TYPE) diff --git a/cpp/examples/minimal_build/run_static.sh b/cpp/examples/minimal_build/run_static.sh index 189f59a007b2a..26019227a7bad 100755 --- a/cpp/examples/minimal_build/run_static.sh +++ b/cpp/examples/minimal_build/run_static.sh @@ -86,7 +86,7 @@ echo rm -rf $EXAMPLE_BUILD_DIR mkdir -p $EXAMPLE_BUILD_DIR -${CXX:-c++} -std=c++17 \ +${CXX:-c++} -std=c++20 \ -o $EXAMPLE_BUILD_DIR/arrow-example \ $EXAMPLE_DIR/example.cc \ $(PKG_CONFIG_PATH=$ARROW_BUILD_DIR/lib/pkgconfig \ diff --git a/cpp/examples/parquet/parquet_arrow/CMakeLists.txt b/cpp/examples/parquet/parquet_arrow/CMakeLists.txt index 0480391e3800e..2032594b756de 100644 --- a/cpp/examples/parquet/parquet_arrow/CMakeLists.txt +++ b/cpp/examples/parquet/parquet_arrow/CMakeLists.txt @@ -28,10 +28,10 @@ option(PARQUET_LINK_SHARED "Link to the Parquet shared library" ON) # This ensures that things like -std=gnu++... get passed correctly if(NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD 20) endif() -# We require a C++17 compliant compiler +# We require a C++20 compliant compiler set(CMAKE_CXX_STANDARD_REQUIRED ON) # Look for installed packages the system diff --git a/cpp/examples/tutorial_examples/CMakeLists.txt b/cpp/examples/tutorial_examples/CMakeLists.txt index 8788501484c87..2af42a2c5785a 100644 --- a/cpp/examples/tutorial_examples/CMakeLists.txt +++ b/cpp/examples/tutorial_examples/CMakeLists.txt @@ -21,7 +21,7 @@ project(ArrowTutorialExamples) find_package(ArrowDataset) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra") set(CMAKE_BUILD_TYPE Release) diff --git a/cpp/src/arrow/util/string.h b/cpp/src/arrow/util/string.h index f2081d0937b77..d39b7a295e748 100644 --- a/cpp/src/arrow/util/string.h +++ b/cpp/src/arrow/util/string.h @@ -54,14 +54,12 @@ namespace internal { /// Like std::string_view::starts_with in C++20 inline bool StartsWith(std::string_view s, std::string_view prefix) { - return s.length() >= prefix.length() && - (s.empty() || s.substr(0, prefix.length()) == prefix); + return s.starts_with(prefix); } /// Like std::string_view::ends_with in C++20 inline bool EndsWith(std::string_view s, std::string_view suffix) { - return s.length() >= suffix.length() && - (s.empty() || s.substr(s.length() - suffix.length()) == suffix); + return s.ends_with(suffix); } /// \brief Split a string with a delimiter diff --git a/dev/release/verify-apt.sh b/dev/release/verify-apt.sh index 7cef30357d141..7e359ba354bb6 100755 --- a/dev/release/verify-apt.sh +++ b/dev/release/verify-apt.sh @@ -165,7 +165,7 @@ pushd build/minimal_build cmake . make -j$(nproc) ./arrow-example -c++ -o arrow-example example.cc $(pkg-config --cflags --libs arrow) -std=c++17 +c++ -o arrow-example example.cc $(pkg-config --cflags --libs arrow) -std=c++20 ./arrow-example popd echo "::endgroup::" diff --git a/dev/release/verify-yum.sh b/dev/release/verify-yum.sh index 31ed9c160b48e..25d25d72e9592 100755 --- a/dev/release/verify-yum.sh +++ b/dev/release/verify-yum.sh @@ -228,7 +228,7 @@ pushd build/minimal_build ${cmake_command} . make -j$(nproc) ./arrow-example -c++ -o arrow-example example.cc $(pkg-config --cflags --libs arrow) -std=c++17 +c++ -o arrow-example example.cc $(pkg-config --cflags --libs arrow) -std=c++20 ./arrow-example popd echo "::endgroup::" diff --git a/dev/tasks/conda-recipes/arrow-cpp/build-arrow.bat b/dev/tasks/conda-recipes/arrow-cpp/build-arrow.bat index 1268771643d4f..fbd93ad29f5ef 100644 --- a/dev/tasks/conda-recipes/arrow-cpp/build-arrow.bat +++ b/dev/tasks/conda-recipes/arrow-cpp/build-arrow.bat @@ -52,7 +52,7 @@ cmake -G "Ninja" ^ -DBUILD_SHARED_LIBS=ON ^ -DBoost_NO_BOOST_CMAKE=ON ^ -DCMAKE_BUILD_TYPE=release ^ - -DCMAKE_CXX_STANDARD=17 ^ + -DCMAKE_CXX_STANDARD=20 ^ -DCMAKE_INSTALL_PREFIX="%LIBRARY_PREFIX%" ^ -DCMAKE_UNITY_BUILD=ON ^ -DLLVM_TOOLS_BINARY_DIR="%LIBRARY_BIN%" ^ diff --git a/dev/tasks/conda-recipes/arrow-cpp/build-arrow.sh b/dev/tasks/conda-recipes/arrow-cpp/build-arrow.sh index ef0b038812a01..3a8d8e68bf5bb 100755 --- a/dev/tasks/conda-recipes/arrow-cpp/build-arrow.sh +++ b/dev/tasks/conda-recipes/arrow-cpp/build-arrow.sh @@ -107,7 +107,7 @@ cmake -GNinja \ -DARROW_WITH_ZSTD=ON \ -DBUILD_SHARED_LIBS=ON \ -DCMAKE_BUILD_TYPE=release \ - -DCMAKE_CXX_STANDARD=17 \ + -DCMAKE_CXX_STANDARD=20 \ -DCMAKE_INSTALL_LIBDIR=lib \ -DCMAKE_INSTALL_PREFIX=$PREFIX \ -DLLVM_TOOLS_BINARY_DIR=$PREFIX/bin \ diff --git a/dev/tasks/homebrew-formulae/apache-arrow.rb b/dev/tasks/homebrew-formulae/apache-arrow.rb index caf82b8db89d4..46a274cc9f9d9 100644 --- a/dev/tasks/homebrew-formulae/apache-arrow.rb +++ b/dev/tasks/homebrew-formulae/apache-arrow.rb @@ -110,7 +110,7 @@ def install return 0; } EOS - system ENV.cxx, "test.cpp", "-std=c++17", "-I#{include}", "-L#{lib}", "-larrow", "-o", "test" + system ENV.cxx, "test.cpp", "-std=c++20", "-I#{include}", "-L#{lib}", "-larrow", "-o", "test" system "./test" end end diff --git a/docs/source/java/cdata.rst b/docs/source/java/cdata.rst index 69f7ab0b0787c..55bb5fe382781 100644 --- a/docs/source/java/cdata.rst +++ b/docs/source/java/cdata.rst @@ -154,7 +154,7 @@ without writing JNI bindings ourselves. include = { "CDataCppBridge.h" }, - compiler = {"cpp17"}, + compiler = {"cpp20"}, linkpath = {"/arrow/cpp/build/debug/"}, link = {"arrow"} ) @@ -436,7 +436,7 @@ CMakeLists.txt definition file: find_package(Arrow REQUIRED) message(STATUS "Arrow version: ${ARROW_VERSION}") include_directories(${JNI_INCLUDE_DIRS}) - set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD 20) add_executable(${PROJECT_NAME} main.cpp) target_link_libraries(cdatacpptojava PRIVATE Arrow::arrow_shared) target_link_libraries(cdatacpptojava PRIVATE ${JNI_LIBRARIES}) diff --git a/docs/source/python/integration/extending.rst b/docs/source/python/integration/extending.rst index d4d099bcf43c8..b8e8f22c72b13 100644 --- a/docs/source/python/integration/extending.rst +++ b/docs/source/python/integration/extending.rst @@ -441,7 +441,7 @@ To build this module, you will need a slightly customized ``setup.py`` file ext.library_dirs.extend(pa.get_library_dirs()) if os.name == 'posix': - ext.extra_compile_args.append('-std=c++17') + ext.extra_compile_args.append('-std=c++20') setup(ext_modules=ext_modules) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index cd6d8768d03ee..854afad5da1ba 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -98,7 +98,7 @@ function(build_arrow) endfunction() -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(MLARROW_VERSION "20.0.0-SNAPSHOT") string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" MLARROW_BASE_VERSION "${MLARROW_VERSION}") diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 0b0275f200d9d..c4723ca1bfbb6 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -230,7 +230,7 @@ endif() # For any C code, use the same flags. set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}") -# Add C++-only flags, like -std=c++17 +# Add C++-only flags, like -std=c++20 set(CMAKE_CXX_FLAGS "${CXX_ONLY_FLAGS} ${CMAKE_CXX_FLAGS}") message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}") diff --git a/python/pyarrow/tests/test_cython.py b/python/pyarrow/tests/test_cython.py index 937d927f831b0..27e0f65cddd72 100644 --- a/python/pyarrow/tests/test_cython.py +++ b/python/pyarrow/tests/test_cython.py @@ -28,9 +28,9 @@ here = os.path.dirname(os.path.abspath(__file__)) test_ld_path = os.environ.get('PYARROW_TEST_LD_PATH', '') if os.name == 'posix': - compiler_opts = ['-std=c++17'] + compiler_opts = ['-std=c++20'] elif os.name == 'nt': - compiler_opts = ['-D_ENABLE_EXTENDED_ALIGNED_STORAGE', '/std:c++17'] + compiler_opts = ['-D_ENABLE_EXTENDED_ALIGNED_STORAGE', '/std:c++20'] else: compiler_opts = []