diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 11658b7..e3e5ea8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -155,11 +155,10 @@ jobs: version: "*" cxx: "clang++" cc: "clang" - runs-on: "macos-11" + runs-on: "macos-14" b2-toolset: "clang" is-latest: true - is-earliest: true - name: "Apple-Clang" + name: "Apple-Clang (macOS 14)" build-type: "Release" build-cmake: true @@ -167,10 +166,10 @@ jobs: version: "*" cxx: "clang++" cc: "clang" - runs-on: "macos-11" + runs-on: "macos-14" b2-toolset: "clang" is-latest: true - name: "Apple-Clang (ubsan)" + name: "Apple-Clang (macOS 14, ubsan)" build-type: "RelWithDebInfo" ubsan: true @@ -178,123 +177,154 @@ jobs: version: "*" cxx: "clang++" cc: "clang" - runs-on: "macos-11" + runs-on: "macos-14" b2-toolset: "clang" is-latest: true - name: "Apple-Clang (asan)" + name: "Apple-Clang (macOS 14, asan)" build-type: "RelWithDebInfo" asan: true + - compiler: "apple-clang" + version: "*" + cxx: "clang++" + cc: "clang" + runs-on: "macos-13" + b2-toolset: "clang" + name: "Apple-Clang (macOS 13)" + build-type: "Release" + + - compiler: "apple-clang" + version: "*" + cxx: "clang++" + cc: "clang" + runs-on: "macos-12" + b2-toolset: "clang" + name: "Apple-Clang (macOS 12)" + build-type: "Release" + # Linux compilers # - compiler: "gcc" - version: "13" + version: "14" cxxstd: "17,20" latest-cxxstd: "20" - cxx: "g++-13" - cc: "gcc-13" + cxx: "g++-14" + cc: "gcc-14" runs-on: "ubuntu-latest" - container: "ubuntu:23.04" + container: "ubuntu:24.04" b2-toolset: "gcc" is-latest: true - name: "GCC 13: C++17-20" + name: "GCC 14: C++17-20" build-type: "Release" build-cmake: true - compiler: "gcc" - version: "13" + version: "14" cxxstd: "17,20" latest-cxxstd: "20" - cxx: "g++-13" - cc: "gcc-13" + cxx: "g++-14" + cc: "gcc-14" runs-on: "ubuntu-latest" - container: "ubuntu:23.04" + container: "ubuntu:24.04" b2-toolset: "gcc" is-latest: true - name: "GCC 13: C++17-20 (x86)" + name: "GCC 14: C++17-20 (x86)" x86: true build-type: "Release" - install: "gcc-13-multilib g++-13-multilib" + install: "gcc-14-multilib g++-14-multilib" - compiler: "gcc" - version: "13" + version: "14" cxxstd: "17,20" latest-cxxstd: "20" - cxx: "g++-13" - cc: "gcc-13" + cxx: "g++-14" + cc: "gcc-14" runs-on: "ubuntu-latest" - container: "ubuntu:23.04" + container: "ubuntu:24.04" b2-toolset: "gcc" is-latest: true - name: "GCC 13: C++17-20 (coverage)" - coverage: true - build-type: "Debug" - cxxflags: "--coverage -fprofile-arcs -ftest-coverage" - ccflags: "--coverage -fprofile-arcs -ftest-coverage" - install: "lcov wget unzip" + name: "GCC 14: C++17-20 (shared)" + shared: true + build-type: "Release" + build-cmake: true - compiler: "gcc" - version: "13" + version: "14" cxxstd: "17,20" latest-cxxstd: "20" - cxx: "g++-13" - cc: "gcc-13" + cxx: "g++-14" + cc: "gcc-14" runs-on: "ubuntu-latest" - container: "ubuntu:23.04" + container: "ubuntu:24.04" b2-toolset: "gcc" is-latest: true - name: "GCC 13: C++17-20 (shared)" + name: "GCC 14: C++17-20 (shared, x86)" shared: true + x86: true build-type: "Release" + install: "gcc-14-multilib g++-14-multilib" build-cmake: true - compiler: "gcc" - version: "13" + version: "14" cxxstd: "17,20" latest-cxxstd: "20" - cxx: "g++-13" - cc: "gcc-13" + cxx: "g++-14" + cc: "gcc-14" runs-on: "ubuntu-latest" - container: "ubuntu:23.04" + container: "ubuntu:24.04" b2-toolset: "gcc" is-latest: true - name: "GCC 13: C++17-20 (shared, x86)" - shared: true - x86: true - build-type: "Release" - install: "gcc-13-multilib g++-13-multilib" - build-cmake: true + name: "GCC 14: C++17-20 (asan)" + asan: true + build-type: "RelWithDebInfo" - compiler: "gcc" - version: "13" + version: "14" cxxstd: "17,20" latest-cxxstd: "20" - cxx: "g++-13" - cc: "gcc-13" + cxx: "g++-14" + cc: "gcc-14" runs-on: "ubuntu-latest" - container: "ubuntu:23.04" + container: "ubuntu:24.04" b2-toolset: "gcc" is-latest: true - name: "GCC 13: C++17-20 (asan)" + name: "GCC 14: C++17-20 (asan, x86)" asan: true + x86: true build-type: "RelWithDebInfo" + install: "gcc-14-multilib g++-14-multilib" - compiler: "gcc" - version: "13" + version: "14" cxxstd: "17,20" latest-cxxstd: "20" - cxx: "g++-13" - cc: "gcc-13" + cxx: "g++-14" + cc: "gcc-14" runs-on: "ubuntu-latest" - container: "ubuntu:23.04" + container: "ubuntu:24.04" b2-toolset: "gcc" is-latest: true - name: "GCC 13: C++17-20 (asan, x86)" - asan: true + name: "GCC 14: C++17-20 (ubsan)" + ubsan: true + build-type: "RelWithDebInfo" + + - compiler: "gcc" + version: "14" + cxxstd: "17,20" + latest-cxxstd: "20" + cxx: "g++-14" + cc: "gcc-14" + runs-on: "ubuntu-latest" + container: "ubuntu:24.04" + b2-toolset: "gcc" + is-latest: true + name: "GCC 14: C++17-20 (ubsan, x86)" + ubsan: true x86: true build-type: "RelWithDebInfo" - install: "gcc-13-multilib g++-13-multilib" + install: "gcc-14-multilib g++-14-multilib" - compiler: "gcc" version: "13" @@ -305,10 +335,8 @@ jobs: runs-on: "ubuntu-latest" container: "ubuntu:23.04" b2-toolset: "gcc" - is-latest: true - name: "GCC 13: C++17-20 (ubsan)" - ubsan: true - build-type: "RelWithDebInfo" + name: "GCC 13: C++17-20" + build-type: "Release" - compiler: "gcc" version: "13" @@ -320,11 +348,12 @@ jobs: container: "ubuntu:23.04" b2-toolset: "gcc" is-latest: true - name: "GCC 13: C++17-20 (ubsan, x86)" - ubsan: true - x86: true - build-type: "RelWithDebInfo" - install: "gcc-13-multilib g++-13-multilib" + name: "GCC 13: C++17-20 (coverage)" + coverage: true + build-type: "Debug" + cxxflags: "--coverage -fprofile-arcs -ftest-coverage" + ccflags: "--coverage -fprofile-arcs -ftest-coverage" + install: "lcov wget unzip" - compiler: "gcc" version: "12" @@ -424,45 +453,45 @@ jobs: build-type: "Release" - compiler: "clang" - version: "17" + version: "18" cxxstd: "17,20" latest-cxxstd: "20" - cxx: "clang++-17" - cc: "clang-17" + cxx: "clang++-18" + cc: "clang-18" runs-on: "ubuntu-latest" - container: "ubuntu:23.10" + container: "ubuntu:24.04" b2-toolset: "clang" is-latest: true - name: "Clang 17: C++17-20" + name: "Clang 18: C++17-20" build-type: "Release" build-cmake: true - compiler: "clang" - version: "17" + version: "18" cxxstd: "17,20" latest-cxxstd: "20" - cxx: "clang++-17" - cc: "clang-17" + cxx: "clang++-18" + cc: "clang-18" runs-on: "ubuntu-latest" - container: "ubuntu:23.10" + container: "ubuntu:24.04" b2-toolset: "clang" is-latest: true - name: "Clang 17: C++17-20 (x86)" + name: "Clang 18: C++17-20 (x86)" x86: true build-type: "Release" install: "gcc-multilib g++-multilib" - compiler: "clang" - version: "17" + version: "18" cxxstd: "20" latest-cxxstd: "20" - cxx: "clang++-17" - cc: "clang-17" + cxx: "clang++-18" + cc: "clang-18" runs-on: "ubuntu-latest" - container: "ubuntu:23.10" + container: "ubuntu:24.04" b2-toolset: "clang" is-latest: true - name: "Clang 17: C++20 (time-trace)" + name: "Clang 18: C++20 (time-trace)" time-trace: true build-type: "Release" cxxflags: "-ftime-trace" @@ -470,65 +499,77 @@ jobs: install: "wget unzip" - compiler: "clang" - version: "17" + version: "18" cxxstd: "17,20" latest-cxxstd: "20" - cxx: "clang++-17" - cc: "clang-17" + cxx: "clang++-18" + cc: "clang-18" runs-on: "ubuntu-latest" - container: "ubuntu:23.10" + container: "ubuntu:24.04" b2-toolset: "clang" is-latest: true - name: "Clang 17: C++17-20 (asan)" + name: "Clang 18: C++17-20 (asan)" asan: true build-type: "RelWithDebInfo" - compiler: "clang" - version: "17" + version: "18" cxxstd: "17,20" latest-cxxstd: "20" - cxx: "clang++-17" - cc: "clang-17" + cxx: "clang++-18" + cc: "clang-18" runs-on: "ubuntu-latest" - container: "ubuntu:23.10" + container: "ubuntu:24.04" b2-toolset: "clang" is-latest: true - name: "Clang 17: C++17-20 (asan, x86)" + name: "Clang 18: C++17-20 (asan, x86)" asan: true x86: true build-type: "RelWithDebInfo" install: "gcc-multilib g++-multilib" - compiler: "clang" - version: "17" + version: "18" cxxstd: "17,20" latest-cxxstd: "20" - cxx: "clang++-17" - cc: "clang-17" + cxx: "clang++-18" + cc: "clang-18" runs-on: "ubuntu-latest" - container: "ubuntu:23.10" + container: "ubuntu:24.04" b2-toolset: "clang" is-latest: true - name: "Clang 17: C++17-20 (ubsan)" + name: "Clang 18: C++17-20 (ubsan)" ubsan: true build-type: "RelWithDebInfo" - compiler: "clang" - version: "17" + version: "18" cxxstd: "17,20" latest-cxxstd: "20" - cxx: "clang++-17" - cc: "clang-17" + cxx: "clang++-18" + cc: "clang-18" runs-on: "ubuntu-latest" - container: "ubuntu:23.10" + container: "ubuntu:24.04" b2-toolset: "clang" is-latest: true - name: "Clang 17: C++17-20 (ubsan, x86)" + name: "Clang 18: C++17-20 (ubsan, x86)" ubsan: true x86: true build-type: "RelWithDebInfo" install: "gcc-multilib g++-multilib" + - compiler: "clang" + version: "17" + cxxstd: "17,20" + latest-cxxstd: "20" + cxx: "clang++-17" + cc: "clang-17" + runs-on: "ubuntu-latest" + container: "ubuntu:23.10" + b2-toolset: "clang" + name: "Clang 17: C++17-20" + build-type: "Release" + - compiler: "clang" version: "16" cxxstd: "17,20" @@ -686,16 +727,16 @@ jobs: build-type: "Release" - compiler: "clang" - version: "^3.8" + version: "3.9" cxxstd: "11" latest-cxxstd: "11" - cxx: "clang++-3.8" - cc: "clang-3.8" + cxx: "clang++-3.9" + cc: "clang-3.9" runs-on: "ubuntu-latest" - container: "ubuntu:16.04" + container: "ubuntu:18.04" b2-toolset: "clang" is-earliest: true - name: "Clang ^3.8: C++11" + name: "Clang 3.9: C++11" build-type: "Release" name: ${{ matrix.name }} @@ -704,6 +745,10 @@ jobs: timeout-minutes: 120 steps: + - name: Enable Node 16 + run: | + echo "ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION=true" >> $GITHUB_ENV + - name: Clone Boost.Buffers uses: actions/checkout@v3 with: diff --git a/include/boost/buffers/flat_buffer.hpp b/include/boost/buffers/flat_buffer.hpp index 46099e6..b7b00df 100644 --- a/include/boost/buffers/flat_buffer.hpp +++ b/include/boost/buffers/flat_buffer.hpp @@ -96,7 +96,7 @@ class flat_buffer std::size_t capacity() const noexcept { - return cap_ - in_pos_; + return cap_ - (in_pos_ + in_size_); } const_buffers_type @@ -111,7 +111,7 @@ class flat_buffer prepare(std::size_t n) { // n exceeds available space - if(n > cap_ - in_size_) + if( n > capacity() ) detail::throw_invalid_argument(); out_size_ = n; diff --git a/test/flat_buffer.cpp b/test/flat_buffer.cpp index 16762e9..97956ae 100644 --- a/test/flat_buffer.cpp +++ b/test/flat_buffer.cpp @@ -51,7 +51,7 @@ struct flat_buffer_test flat_buffer fb(&s[0], s.size(), 6); BOOST_TEST_EQ(fb.size(), 6); BOOST_TEST_EQ(fb.max_size(), s.size()); - BOOST_TEST_EQ(fb.capacity(), s.size()); + BOOST_TEST_EQ(fb.capacity(), s.size() - 6); } { std::string s = pat; @@ -78,7 +78,7 @@ struct flat_buffer_test &s[0], s.size()), 6); BOOST_TEST_EQ(fb.size(), 6); BOOST_TEST_EQ(fb.max_size(), s.size()); - BOOST_TEST_EQ(fb.capacity(), s.size()); + BOOST_TEST_EQ(fb.capacity(), s.size() - 6); } // flat_buffer(flat_buffer const&) @@ -110,6 +110,18 @@ struct flat_buffer_test fb.prepare(s.size() + 1), std::invalid_argument); } + { + std::string s = pat; + flat_buffer fb(&s[0], s.size(), 6); + BOOST_TEST_THROWS( + fb.prepare(s.size() + 1), + std::invalid_argument); + + BOOST_TEST_EQ(fb.max_size(), s.size()); + BOOST_TEST_EQ( + fb.size() + fb.capacity(), + fb.max_size()); + } // commit(std::size_t) { @@ -129,6 +141,38 @@ struct flat_buffer_test // consume(std::size_t) { + std::string s = pat; + flat_buffer fb(&s[0], s.size(), s.size()); + BOOST_TEST_EQ( + test_to_string(fb.data()), pat); + + auto const cap = fb.capacity(); + + while( fb.size() > 0 ) + { + fb.prepare(fb.capacity()); + fb.consume(1); + + if( fb.size() > 0 ) + BOOST_TEST_EQ(fb.capacity(), cap); + } + + BOOST_TEST_EQ(fb.capacity(), s.size()); + } + { + std::string s = pat; + flat_buffer fb(&s[0], s.size(), 6); + + auto const cap = fb.capacity(); + + BOOST_TEST_NO_THROW( + fb.prepare(fb.max_size() - fb.size())); + + fb.consume(1); + BOOST_TEST_EQ(fb.capacity(), cap); + BOOST_TEST_THROWS( + fb.prepare(cap + 1), + std::invalid_argument); } }