From ad5df9bbb05a4b19400be391205c681a96cd287f Mon Sep 17 00:00:00 2001 From: Pablo Hoch Date: Thu, 12 Sep 2024 16:34:52 +0200 Subject: [PATCH] CI Update (#21) --- .clang-tidy.in | 49 +++++++++++++------- .github/workflows/unix.yml | 64 +++++++++++++-------------- .github/workflows/windows.yml | 21 +++++++-- CMakeLists.txt | 4 +- include/utl/iterator_facade.h | 63 +++++++++++++++----------- include/utl/parser/arg_parser.h | 6 +-- include/utl/parser/cstr.h | 2 +- include/utl/parser/file.h | 31 +++++++------ include/utl/parser/mmap_reader_msvc.h | 2 +- include/utl/pipes/iota.h | 4 +- include/utl/pipes/transform.h | 3 +- include/utl/sorted_diff.h | 2 + include/utl/to_set.h | 4 +- 13 files changed, 152 insertions(+), 103 deletions(-) diff --git a/.clang-tidy.in b/.clang-tidy.in index 2b4fc65..ccc9852 100644 --- a/.clang-tidy.in +++ b/.clang-tidy.in @@ -1,6 +1,11 @@ Checks: "*,\ -llvmlibc-*,\ -abseil-*,\ +-readability-identifier-length,\ +-altera-unroll-loops,\ +-altera-id-dependent-backward-branch,\ +-bugprone-easily-swappable-parameters,\ +-bugprone-implicit-widening-of-multiplication-result,\ -llvm-else-after-return,\ -hicpp-named-parameter,\ -cert-err60-cpp,\ @@ -44,7 +49,7 @@ Checks: "*,\ -cppcoreguidelines-pro-bounds-constant-array-index,\ -*-avoid-c-arrays,\ -*-narrowing-conversions,\ --*-avoid-goto, +-*-avoid-goto,\ -hicpp-multiway-paths-covered,\ -clang-analyzer-cplusplus.NewDeleteLeaks,\ -clang-analyzer-cplusplus.NewDelete,\ @@ -62,10 +67,22 @@ Checks: "*,\ -llvm-else-after-return,\ -llvm-qualified-auto,\ -readability-qualified-auto,\ --google-readability-avoid-underscore-in-googletest-name" +-google-readability-avoid-underscore-in-googletest-name,\ +-readability-function-cognitive-complexity,\ +-readability-avoid-const-params-in-decls,\ +-cppcoreguidelines-avoid-const-or-ref-data-members,\ +-cppcoreguidelines-avoid-do-while,\ +-altera-struct-pack-align,\ +-bugprone-unchecked-optional-access,\ +-readability-identifier-naming,\ +-cert-dcl37-c,\ +-bugprone-reserved-identifier,\ +-cert-dcl51-cpp,\ +-misc-confusable-identifiers" WarningsAsErrors: '*' HeaderFilterRegex: '^${RELATIVE_SOURCE_DIR}include/' AnalyzeTemporaryDtors: false +UseColor: true User: root CheckOptions: - key: cert-err61-cpp.CheckThrowTemporaries @@ -336,22 +353,8 @@ CheckOptions: value: '' - key: readability-identifier-naming.TemplateParameterCase value: CamelCase - - key: readability-identifier-naming.TemplateParameterPrefix - value: '' - - key: readability-identifier-naming.TemplateParameterSuffix - value: '' - key: readability-identifier-naming.TemplateTemplateParameterCase value: CamelCase - - key: readability-identifier-naming.TemplateTemplateParameterPrefix - value: '' - - key: readability-identifier-naming.TemplateTemplateParameterSuffix - value: '' - - key: readability-identifier-naming.TypeTemplateParameterCase - value: CamelCase - - key: readability-identifier-naming.TypeTemplateParameterPrefix - value: '' - - key: readability-identifier-naming.TypeTemplateParameterSuffix - value: '' - key: readability-identifier-naming.TypedefCase value: lower_case - key: readability-identifier-naming.TypedefPrefix @@ -386,3 +389,17 @@ CheckOptions: value: '0' - key: readability-simplify-boolean-expr.ChainedConditionalReturn value: '0' + - key: performance-for-range-copy.AllowedTypes + value: 'offset_ptr;ptr' + - key: performance-unnecessary-value-param.AllowedTypes + value: 'offset_ptr;ptr' + - key: readability-identifier-naming.TypeTemplateParameterIgnoredRegexp + value: 'expr-type' + - key: readability-identifier-naming.TemplateParameterIgnoredRegexp + value: 'expr-type' + - key: readability-identifier-naming.TypeTemplateParameterIgnoredRegexp + value: 'expr-type' + - key: readability-identifier-naming.TemplateTemplateParameterIgnoredRegexp + value: 'expr-type' + - key: readability-identifier-naming.ValueTemplateParameterIgnoredRegexp + value: 'expr-type' diff --git a/.github/workflows/unix.yml b/.github/workflows/unix.yml index acac0cd..412a20a 100644 --- a/.github/workflows/unix.yml +++ b/.github/workflows/unix.yml @@ -8,7 +8,7 @@ on: jobs: formatting: - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v2 @@ -18,11 +18,11 @@ jobs: run: | wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 14 + sudo ./llvm.sh 18 rm llvm.sh - sudo apt-get install -y --no-install-recommends clang-format-14 + sudo apt-get install -y --no-install-recommends clang-format-18 - name: Format files - run: find test include -type f -not -name catch.hpp -a \( -name "*.cc" -o -name "*.h" \) -print0 | xargs -0 clang-format-14 -i + run: find test include -type f -not -name catch.hpp -a \( -name "*.cc" -o -name "*.h" \) -print0 | xargs -0 clang-format-18 -i - name: Check for differences run: | @@ -41,43 +41,43 @@ jobs: mode: Release cxxflags: -stdlib=libc++ os: macos-latest - - name: GCC 10 Release - cxx: g++-10 - cc: gcc-10 + - name: GCC 12 Release + cxx: g++-12 + cc: gcc-12 mode: Release - os: ubuntu-20.04 - - name: GCC 10 Release - cxx: g++-10 - cc: gcc-10 + os: ubuntu-24.04 + - name: GCC 12 Release + cxx: g++-12 + cc: gcc-12 mode: Release - os: ubuntu-20.04 - - name: GCC 10 Debug - cxx: g++-10 - cc: gcc-10 + os: ubuntu-24.04 + - name: GCC 12 Debug + cxx: g++-12 + cc: gcc-12 mode: Debug - os: ubuntu-20.04 - - name: Clang 14 Release - cxx: clang++-14 - cc: clang-14 + os: ubuntu-24.04 + - name: Clang 18 Release + cxx: clang++-18 + cc: clang-18 mode: Release cxxflags: -stdlib=libc++ ldflags: -lc++abi - os: ubuntu-20.04 + os: ubuntu-24.04 - name: Clang Tidy - cxx: clang++-14 - cc: clang-14 + cxx: clang++-18 + cc: clang-18 mode: Debug cxxflags: -stdlib=libc++ ldflags: -lc++abi lint: true - os: ubuntu-20.04 - - key: GCC 10 Sanitizer - cxx: g++-10 - cc: gcc-10 + os: ubuntu-24.04 + - key: GCC 12 Sanitizer + cxx: g++-12 + cc: gcc-12 mode: Release cflags: -fsanitize=address,undefined -fno-omit-frame-pointer cxxflags: -fsanitize=address,undefined -fno-omit-frame-pointer - os: ubuntu-20.04 + os: ubuntu-24.04 env: DEBIAN_FRONTEND: noninteractive UBSAN_OPTIONS: halt_on_error=1:abort_on_error=1 @@ -93,16 +93,16 @@ jobs: run: sudo apt-get update - name: Install LLVM - if: matrix.config.os != 'macos-latest' && matrix.config.cc == 'clang-14' + if: matrix.config.os != 'macos-latest' && matrix.config.cc == 'clang-18' run: | wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 14 + sudo ./llvm.sh 18 rm llvm.sh - sudo apt-get install -y --no-install-recommends libc++-14-dev libc++abi-14-dev clang-tidy-14 libunwind-14-dev llvm-14 + sudo apt-get install -y --no-install-recommends libc++-18-dev libc++abi-18-dev clang-tidy-18 libunwind-18-dev llvm-18 - name: Install Valgrind - if: matrix.config.mode == 'Debug' && matrix.config.cc == 'gcc-10' + if: matrix.config.mode == 'Debug' && matrix.config.cc == 'gcc-12' run: sudo apt-get install -y --no-install-recommends valgrind - name: Install Ninja @@ -133,5 +133,5 @@ jobs: # ==== VALGRIND ==== - name: Run Tests Valgrind - if: matrix.config.mode == 'Debug' && matrix.config.cc == 'gcc-10' + if: matrix.config.mode == 'Debug' && matrix.config.cc == 'gcc-12' run: valgrind --error-exitcode=1 --show-reachable=yes --leak-check=full ./build/utl-test diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 1724ce7..ade0131 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -6,13 +6,29 @@ on: pull_request: branches: [ master ] +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: build: runs-on: windows-latest strategy: + fail-fast: false matrix: - mode: [Debug, Release] + config: + - name: MSVC Debug + mode: Debug + - name: MSVC Release + mode: Release + - name: Clang Debug + mode: Debug + cmake-opt: -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl + cc: clang-cl + - name: Clang Release + mode: Release + cmake-opt: -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl steps: - uses: actions/checkout@v2 @@ -20,12 +36,11 @@ jobs: - name: Build run: | - $env:BOOST_ROOT = $env:BOOST_ROOT_1_72_0 $devShell = &"${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -find **\Microsoft.VisualStudio.DevShell.dll $installPath = &"${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationpath Import-Module $devShell Enter-VsDevShell -VsInstallPath $installPath -SkipAutomaticLocation -DevCmdArguments "-arch=amd64" - cmake -GNinja -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.mode }} + cmake -GNinja -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.config.mode }} ${{ matrix.config.cmake-opt }} cmake --build build --target utl-test - name: Run tests diff --git a/CMakeLists.txt b/CMakeLists.txt index 792cb45..e5a7ba6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ +cmake_minimum_required(VERSION 3.20) project(utl) -cmake_minimum_required(VERSION 3.16) option(UTL_LINT "Run clang-tidy with the compiler." OFF) if(UTL_LINT) @@ -14,7 +14,7 @@ add_library(utl STATIC ${utl-files}) target_link_libraries(utl PUBLIC fmt-header-only cista) target_include_directories(utl PUBLIC include) target_compile_options(utl PUBLIC -D_SCL_SECURE_NO_WARNINGS=1) -target_compile_features(utl PUBLIC cxx_std_17) +target_compile_features(utl PUBLIC cxx_std_23) if (MSVC) target_compile_definitions(utl PUBLIC NOMINMAX) endif() diff --git a/include/utl/iterator_facade.h b/include/utl/iterator_facade.h index 14c1201..201e355 100644 --- a/include/utl/iterator_facade.h +++ b/include/utl/iterator_facade.h @@ -260,7 +260,8 @@ class iterator_facade : detail::iterator_facade_base { */ [[nodiscard]] constexpr friend auto operator-(const self_type& left, const self_type& right) noexcept - requires detail::iter_is_random_access { + requires detail::iter_is_random_access + { return right.distance_to(left); } @@ -297,8 +298,9 @@ class iterator_facade : detail::iterator_facade_base { } } - constexpr self_type& operator--() noexcept requires - detail::iter_is_bidirectional { + constexpr self_type& operator--() noexcept + requires detail::iter_is_bidirectional + { if constexpr (detail::iter_has_decrement_method) { _self().decrement(); } else { @@ -307,31 +309,35 @@ class iterator_facade : detail::iterator_facade_base { return _self(); } - constexpr self_type operator--( - int) noexcept requires detail::iter_is_bidirectional { + constexpr self_type operator--(int) noexcept + requires detail::iter_is_bidirectional + { auto cp = _self(); --*this; return cp; } template Diff> - [[nodiscard]] constexpr friend self_type operator+( - self_type left, - Diff off) noexcept requires detail::iter_is_random_access { + [[nodiscard]] constexpr friend self_type operator+(self_type left, + Diff off) noexcept + requires detail::iter_is_random_access + { return left += off; } template D> [[nodiscard]] constexpr friend self_type operator+( - D off, const self_type& self) noexcept requires - detail::iter_is_random_access { + D off, const self_type& self) noexcept + requires detail::iter_is_random_access + { return self + off; } template D> - [[nodiscard]] constexpr friend self_type operator-( - const self_type& self, - D off) noexcept requires detail::iter_is_random_access { + [[nodiscard]] constexpr friend self_type operator-(const self_type& self, + D off) noexcept + requires detail::iter_is_random_access + { using diff_type = detail::infer_difference_type_t; using signed_diff_type = std::make_signed_t; return self + -static_cast(off); @@ -345,20 +351,23 @@ class iterator_facade : detail::iterator_facade_base { template D> constexpr friend self_type& operator+=(self_type& self, D off) noexcept - requires detail::iter_is_random_access { + requires detail::iter_is_random_access + { self.advance(off); return self; } template D> constexpr friend self_type& operator-=(self_type& self, D off) noexcept - requires detail::iter_is_random_access { + requires detail::iter_is_random_access + { return self = self - off; } template D> - [[nodiscard]] constexpr decltype(auto) operator[]( - D pos) const noexcept requires detail::iter_is_random_access { + [[nodiscard]] constexpr decltype(auto) operator[](D pos) const noexcept + requires detail::iter_is_random_access + { return *(_self() + pos); } @@ -422,13 +431,15 @@ class iterator_facade : detail::iterator_facade_base { */ [[nodiscard]] friend constexpr bool operator<(const self_type& left, const self_type& right) noexcept - requires detail::iter_is_random_access { + requires detail::iter_is_random_access + { return (left - right) < 0; } [[nodiscard]] friend constexpr bool operator<=( - const self_type& left, const self_type& right) noexcept requires - detail::iter_is_random_access { + const self_type& left, const self_type& right) noexcept + requires detail::iter_is_random_access + { return (left - right) <= 0; } @@ -437,13 +448,15 @@ class iterator_facade : detail::iterator_facade_base { */ [[nodiscard]] friend constexpr bool operator>(const self_type& left, const self_type& right) noexcept - requires detail::iter_is_random_access { + requires detail::iter_is_random_access + { return (left - right) > 0; } [[nodiscard]] friend constexpr bool operator>=( - const self_type& left, const self_type& right) noexcept requires - detail::iter_is_random_access { + const self_type& left, const self_type& right) noexcept + requires detail::iter_is_random_access + { return (left - right) >= 0; } }; // namespace utl @@ -484,8 +497,8 @@ class iterator_wrapper_facade : public iterator_facade { namespace std { template -requires std::is_base_of_v // + requires std::is_base_of_v // struct iterator_traits { static const Derived& _const_it; using reference = decltype(*_const_it); diff --git a/include/utl/parser/arg_parser.h b/include/utl/parser/arg_parser.h index bf924ff..d50755a 100644 --- a/include/utl/parser/arg_parser.h +++ b/include/utl/parser/arg_parser.h @@ -113,8 +113,7 @@ inline bool parse_arg(cstr& s, bool& b, bool const default_value = false) { std::tolower(s[1]) == 'r' && // std::tolower(s[2]) == 'u' && // std::tolower(s[3]) == 'e'; - for (int i = 0; i < 4 && s; ++i, ++s) - ; + for (int i = 0; i < 4 && s; ++i, ++s); return ret; } else if (c == 'f') { auto const ret = s.len == 5 && // @@ -122,8 +121,7 @@ inline bool parse_arg(cstr& s, bool& b, bool const default_value = false) { std::tolower(s[2]) == 'l' && // std::tolower(s[3]) == 's' && // std::tolower(s[4]) == 'e'; - for (int i = 0; i < 5 && s; ++i, ++s) - ; + for (int i = 0; i < 5 && s; ++i, ++s); return ret; } return false; diff --git a/include/utl/parser/cstr.h b/include/utl/parser/cstr.h index 6932305..2691fb8 100755 --- a/include/utl/parser/cstr.h +++ b/include/utl/parser/cstr.h @@ -2,8 +2,8 @@ #include #include -#include #include +#include #include #include diff --git a/include/utl/parser/file.h b/include/utl/parser/file.h index 2579d3b..9be1e1a 100644 --- a/include/utl/parser/file.h +++ b/include/utl/parser/file.h @@ -11,7 +11,7 @@ #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif -#include +#include #include "utl/parser/buffer.h" #include "utl/verify.h" @@ -60,7 +60,7 @@ struct file { size_t size() { LARGE_INTEGER filesize; check(GetFileSizeEx(f_, &filesize), "get file size error"); - return filesize.QuadPart; + return static_cast(filesize.QuadPart); } buffer content() { @@ -69,12 +69,13 @@ struct file { auto b = buffer(file_size); - chunk(block_size, size(), [&](size_t const from, unsigned block_size) { - OVERLAPPED overlapped = {0}; + chunk(block_size, size(), [&](size_t const from, unsigned bs) { + OVERLAPPED overlapped; overlapped.Offset = static_cast(from); overlapped.OffsetHigh = from >> 32u; - check(ReadFile(f_, b.data() + from, static_cast(block_size), - nullptr, &overlapped), + overlapped.hEvent = nullptr; + check(ReadFile(f_, b.data() + from, static_cast(bs), nullptr, + &overlapped), "file read error"); }); @@ -88,12 +89,13 @@ struct file { auto b = std::string{}; b.resize(file_size); - chunk(block_size, size(), [&](size_t const from, unsigned block_size) { - OVERLAPPED overlapped = {0}; + chunk(block_size, size(), [&](size_t const from, unsigned bs) { + OVERLAPPED overlapped = {}; overlapped.Offset = static_cast(from); overlapped.OffsetHigh = from >> 32u; - check(ReadFile(f_, b.data() + from, static_cast(block_size), - nullptr, &overlapped), + overlapped.hEvent = nullptr; + check(ReadFile(f_, b.data() + from, static_cast(bs), nullptr, + &overlapped), "file read error"); }); @@ -102,12 +104,13 @@ struct file { void write(void const* buf, size_t size) { constexpr auto block_size = 8192u; - chunk(block_size, size, [&](size_t const from, unsigned block_size) { - OVERLAPPED overlapped = {0}; + chunk(block_size, size, [&](size_t const from, unsigned bs) { + OVERLAPPED overlapped = {}; overlapped.Offset = static_cast(from); overlapped.OffsetHigh = from >> 32u; - check(WriteFile(f_, static_cast(buf) + from, - block_size, nullptr, &overlapped), + overlapped.hEvent = nullptr; + check(WriteFile(f_, static_cast(buf) + from, bs, + nullptr, &overlapped), "file write error"); }); } diff --git a/include/utl/parser/mmap_reader_msvc.h b/include/utl/parser/mmap_reader_msvc.h index 1eb7d74..d97b380 100644 --- a/include/utl/parser/mmap_reader_msvc.h +++ b/include/utl/parser/mmap_reader_msvc.h @@ -2,7 +2,7 @@ #define NOMINMAX #define WIN32_LEAN_AND_MEAN -#include +#include #include diff --git a/include/utl/pipes/iota.h b/include/utl/pipes/iota.h index d023477..42bb77c 100644 --- a/include/utl/pipes/iota.h +++ b/include/utl/pipes/iota.h @@ -44,8 +44,8 @@ struct iota_range { }; template -iota_range(FromIntType, ToIntType) - -> iota_range, clear_t>; +iota_range(FromIntType, + ToIntType) -> iota_range, clear_t>; template auto iota(FromIntType&& from, ToIntType&& to) { diff --git a/include/utl/pipes/transform.h b/include/utl/pipes/transform.h index 1656041..1b260cd 100644 --- a/include/utl/pipes/transform.h +++ b/include/utl/pipes/transform.h @@ -3,6 +3,7 @@ #include #include "utl/clear_t.h" +#include "utl/pipes/is_range.h" #include "utl/pipes/make_range.h" namespace utl { @@ -47,4 +48,4 @@ transform_t transform(Transform&& f) { template struct is_range> : std::true_type {}; -} // namespace utl \ No newline at end of file +} // namespace utl diff --git a/include/utl/sorted_diff.h b/include/utl/sorted_diff.h index 764eae9..6dfef47 100644 --- a/include/utl/sorted_diff.h +++ b/include/utl/sorted_diff.h @@ -1,6 +1,7 @@ #pragma once #include +#include namespace utl { @@ -11,6 +12,7 @@ constexpr std::string_view to_str(op const o) { case op::kAdd: return "add"; case op::kDel: return "del"; } + std::unreachable(); } template diff --git a/include/utl/to_set.h b/include/utl/to_set.h index d39015a..657bdee 100644 --- a/include/utl/to_set.h +++ b/include/utl/to_set.h @@ -7,8 +7,8 @@ namespace utl { template -inline auto to_set(It b, It e, UnaryOperation&& op) - -> std::set { +inline auto to_set(It b, It e, + UnaryOperation&& op) -> std::set { using set = std::set; set s(std::distance(s, e)); std::transform(b, e, std::insert_iterator(s), op);