From b7a990d0b5a42d12f3dcd0d816778192b204de83 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sat, 25 May 2024 18:25:13 +0200 Subject: [PATCH] Use C++20 (#6877) --- .clang-tidy | 2 ++ .github/workflows/osrm-backend.yml | 31 +++++++++++++++++++++++++++++- CMakeLists.txt | 2 +- cmake/warnings.cmake | 7 ++++++- include/util/static_assert.hpp | 6 +++--- 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 229e2e69a..c724cc0c4 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -54,6 +54,7 @@ Checks: > performance-*, -performance-noexcept-move-constructor, -performance-no-int-to-ptr, + -performance-type-promotion-in-math-fn, readability-*, -readability-avoid-const-params-in-decls, -readability-braces-around-statements, @@ -82,6 +83,7 @@ Checks: > -readability-make-member-function-const, -readability-redundant-string-init, -readability-non-const-parameter, + -readability-container-contains, -readability-static-accessed-through-instance WarningsAsErrors: '*' diff --git a/.github/workflows/osrm-backend.yml b/.github/workflows/osrm-backend.yml index ed0407f68..63709e51a 100644 --- a/.github/workflows/osrm-backend.yml +++ b/.github/workflows/osrm-backend.yml @@ -396,7 +396,36 @@ jobs: elif [[ "${RUNNER_OS}" == "macOS" ]]; then echo "JOBS=$((`sysctl -n hw.ncpu` + 1))" >> $GITHUB_ENV fi + # See: https://github.com/actions/toolkit/issues/946#issuecomment-1590016041 + # We need it to be able to access system folders while restoring cached Boost below + - name: Give tar root ownership + if: runner.os == 'Linux' && matrix.ENABLE_CONAN != 'ON' + run: sudo chown root /bin/tar && sudo chmod u+s /bin/tar + - name: Cache Boost + if: runner.os == 'Linux' && matrix.ENABLE_CONAN != 'ON' + id: cache-boost + uses: actions/cache@v4 + with: + path: | + /usr/local/include/boost + /usr/local/lib/libboost* + key: v1-boost-${{ runner.os }}-${{ runner.arch }}-${{ matrix.runs-on }} + restore-keys: | + v1-boost-${{ runner.os }}-${{ runner.arch }}-${{ matrix.runs-on }} + - name: Install Boost + if: steps.cache-boost.outputs.cache-hit != 'true' && runner.os == 'Linux' && matrix.ENABLE_CONAN != 'ON' + run: | + BOOST_VERSION="1.85.0" + BOOST_VERSION_UNDERSCORE="${BOOST_VERSION//./_}" + wget -q https://boostorg.jfrog.io/artifactory/main/release/${BOOST_VERSION}/source/boost_${BOOST_VERSION_UNDERSCORE}.tar.gz + tar xzf boost_${BOOST_VERSION_UNDERSCORE}.tar.gz + cd boost_${BOOST_VERSION_UNDERSCORE} + sudo ./bootstrap.sh + sudo ./b2 install + cd .. + sudo rm -rf boost_${BOOST_VERSION_UNDERSCORE}* + - name: Install dev dependencies run: | python3 -m pip install "conan<2.0.0" || python3 -m pip install "conan<2.0.0" --break-system-packages @@ -417,7 +446,7 @@ jobs: # Linux dev packages if [ "${ENABLE_CONAN}" != "ON" ]; then sudo apt-get update -y - sudo apt-get install -y libbz2-dev libxml2-dev libzip-dev liblua5.2-dev libboost-all-dev + sudo apt-get install -y libbz2-dev libxml2-dev libzip-dev liblua5.2-dev if [[ "${CCOMPILER}" != clang-* ]]; then sudo apt-get install -y ${CXXCOMPILER} fi diff --git a/CMakeLists.txt b/CMakeLists.txt index 23bd0bcad..fb135888b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.18) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/cmake/warnings.cmake b/cmake/warnings.cmake index 89040aa0e..4006b0f2e 100644 --- a/cmake/warnings.cmake +++ b/cmake/warnings.cmake @@ -78,4 +78,9 @@ add_warning(switch-bool) add_warning(tautological-compare) add_warning(trampolines) # these warnings are not enabled by default -# no_warning(name-of-warning) \ No newline at end of file +# no_warning(name-of-warning) +no_warning(deprecated-comma-subscript) +no_warning(comma-subscript) +no_warning(ambiguous-reversed-operator) +no_warning(restrict) +no_warning(free-nonheap-object) diff --git a/include/util/static_assert.hpp b/include/util/static_assert.hpp index 234b26391..28e922fd3 100644 --- a/include/util/static_assert.hpp +++ b/include/util/static_assert.hpp @@ -1,6 +1,7 @@ #ifndef OSRM_STATIC_ASSERT_HPP #define OSRM_STATIC_ASSERT_HPP +#include #include namespace osrm::util @@ -8,14 +9,13 @@ namespace osrm::util template inline void static_assert_iter_value() { - using IterValueType = typename std::iterator_traits::value_type; - static_assert(std::is_same::value, ""); + static_assert(std::is_same_v, Value>, ""); } template inline void static_assert_iter_category() { using IterCategoryType = typename std::iterator_traits::iterator_category; - static_assert(std::is_base_of::value, ""); + static_assert(std::is_base_of_v, ""); } } // namespace osrm::util