From a86ac8241d55a1182e25de3cefc9b5d03a730a08 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Tue, 25 Dec 2018 19:50:53 +0100 Subject: [PATCH 1/4] fix clang-tidy --- src/cpp-utils/either.h | 36 +++++++++++++++++----------------- test/cpp-utils/either_test.cpp | 36 +++++++++++++++++----------------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/cpp-utils/either.h b/src/cpp-utils/either.h index 06c7d28d..e718a63b 100644 --- a/src/cpp-utils/either.h +++ b/src/cpp-utils/either.h @@ -27,18 +27,18 @@ namespace cpputils { either(const either &rhs) noexcept(noexcept(std::declval>()._construct_left(rhs._left)) && noexcept(std::declval>()._construct_right(rhs._right))) : _side(rhs._side) { if(_side == Side::left) { - _construct_left(rhs._left); + _construct_left(rhs._left); // NOLINT(cppcoreguidelines-pro-type-union-access) } else { - _construct_right(rhs._right); + _construct_right(rhs._right); // NOLINT(cppcoreguidelines-pro-type-union-access) } } either(either &&rhs) /* TODO noexcept(noexcept(_construct_left(std::move(rhs._left))) && noexcept(_construct_right(std::move(rhs._right)))) */ : _side(rhs._side) { if(_side == Side::left) { - _construct_left(std::move(rhs._left)); + _construct_left(std::move(rhs._left)); // NOLINT(cppcoreguidelines-pro-type-union-access) } else { - _construct_right(std::move(rhs._right)); + _construct_right(std::move(rhs._right)); // NOLINT(cppcoreguidelines-pro-type-union-access) } } @@ -51,9 +51,9 @@ namespace cpputils { _destruct(); _side = rhs._side; if (_side == Side::left) { - _construct_left(rhs._left); + _construct_left(rhs._left); // NOLINT(cppcoreguidelines-pro-type-union-access) } else { - _construct_right(rhs._right); + _construct_right(rhs._right); // NOLINT(cppcoreguidelines-pro-type-union-access) } return *this; } @@ -62,9 +62,9 @@ namespace cpputils { _destruct(); _side = rhs._side; if (_side == Side::left) { - _construct_left(std::move(rhs._left)); + _construct_left(std::move(rhs._left)); // NOLINT(cppcoreguidelines-pro-type-union-access) } else { - _construct_right(std::move(rhs._right)); + _construct_right(std::move(rhs._right)); // NOLINT(cppcoreguidelines-pro-type-union-access) } return *this; } @@ -83,7 +83,7 @@ namespace cpputils { if (!is_left()) { throw std::logic_error("Tried to get left side of an either which is right."); } - return _left; + return _left; // NOLINT(cppcoreguidelines-pro-type-union-access) } Left &left() & { return const_cast(const_cast*>(this)->left()); @@ -96,7 +96,7 @@ namespace cpputils { if (!is_right()) { throw std::logic_error("Tried to get right side of an either which is left."); } - return _right; + return _right; // NOLINT(cppcoreguidelines-pro-type-union-access) } Right &right() & { return const_cast(const_cast*>(this)->right()); @@ -107,14 +107,14 @@ namespace cpputils { boost::optional left_opt() const& noexcept { if (_side == Side::left) { - return _left; + return _left; // NOLINT(cppcoreguidelines-pro-type-union-access) } else { return boost::none; } } boost::optional left_opt() & noexcept { if (_side == Side::left) { - return _left; + return _left; // NOLINT(cppcoreguidelines-pro-type-union-access) } else { return boost::none; } @@ -123,14 +123,14 @@ namespace cpputils { boost::optional right_opt() const& noexcept { if (_side == Side::right) { - return _right; + return _right; // NOLINT(cppcoreguidelines-pro-type-union-access) } else { return boost::none; } } boost::optional right_opt() & noexcept { if (_side == Side::right) { - return _right; + return _right; // NOLINT(cppcoreguidelines-pro-type-union-access) } else { return boost::none; } @@ -148,17 +148,17 @@ namespace cpputils { template void _construct_left(Args&&... args) noexcept(noexcept(new Left(std::forward(args)...))) { - new(&_left)Left(std::forward(args)...); + new(&_left)Left(std::forward(args)...); // NOLINT(cppcoreguidelines-pro-type-union-access) } template void _construct_right(Args&&... args) noexcept(noexcept(new Right(std::forward(args)...))) { - new(&_right)Right(std::forward(args)...); + new(&_right)Right(std::forward(args)...); // NOLINT(cppcoreguidelines-pro-type-union-access) } void _destruct() noexcept { if (_side == Side::left) { - _left.~Left(); + _left.~Left(); // NOLINT(cppcoreguidelines-pro-type-union-access) } else { - _right.~Right(); + _right.~Right(); // NOLINT(cppcoreguidelines-pro-type-union-access) } } diff --git a/test/cpp-utils/either_test.cpp b/test/cpp-utils/either_test.cpp index fb450130..c1daeb66 100644 --- a/test/cpp-utils/either_test.cpp +++ b/test/cpp-utils/either_test.cpp @@ -345,7 +345,7 @@ TEST(EitherTest, givenLeftMoveConstructedFromValue_thenOldIsCorrect) { [] (const auto& test) { MovableOnly a(3); either b(std::move(a)); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS(MovableOnly(0)) // 0 is moved-from value @@ -369,7 +369,7 @@ TEST(EitherTest, givenRightMoveConstructedFromValue_thenOldIsCorrect) { [] (const auto& test) { MovableOnly a(3); either b(std::move(a)); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS(MovableOnly(0)) // 0 is moved-from value @@ -472,12 +472,12 @@ TEST(EitherTest, givenLeftMoveAssignedFromValue_thenOldIsCorrect) { MovableOnly a(3); either b("2"); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) }, [] (const auto& test) { MovableOnly a(3); either b(MovableOnly(0)); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS(MovableOnly(0)) @@ -508,12 +508,12 @@ TEST(EitherTest, givenRightMoveAssignedFromValue_thenOldIsCorrect) { MovableOnly a(3); either b("2"); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) }, [] (const auto& test) { MovableOnly a(3); either b(MovableOnly(2)); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS(MovableOnly(0)) // 0 is moved-from value @@ -635,7 +635,7 @@ TEST(EitherTest, givenLeftMoveConstructed_thenOldIsCorrect) { [] (const auto& test) { either a(MovableOnly(3)); either b(std::move(a)); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS_LEFT(MovableOnly(0)) // 0 is moved-from value @@ -659,7 +659,7 @@ TEST(EitherTest, givenLeftMoveConstructed_withSameType_thenOldIsCorrect) { [] (const auto& test) { either a = make_left(MovableOnly(3)); either b(std::move(a)); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS_LEFT(MovableOnly(0)) // 0 is moved-from value @@ -683,7 +683,7 @@ TEST(EitherTest, givenRightMoveConstructed_thenOldIsCorrect) { [] (const auto& test) { either a(MovableOnly(3)); either b(std::move(a)); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS_RIGHT(MovableOnly(0)) // 0 is moved-from value @@ -707,7 +707,7 @@ TEST(EitherTest, givenRightMoveConstructed_withSameType_thenOldIsCorrect) { [] (const auto& test) { either a = make_right(MovableOnly(3)); either b(std::move(a)); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS_RIGHT(MovableOnly(0)) // 0 is moved-from value @@ -882,12 +882,12 @@ TEST(EitherTest, givenLeftMoveAssigned_thenOldIsCorrect) { either a(MovableOnly(3)); either b(2); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) }, [] (const auto& test) { either a(MovableOnly(3)); either b(MovableOnly(2)); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS_LEFT(MovableOnly(0)) // 0 is moved-from value @@ -918,12 +918,12 @@ TEST(EitherTest, givenLeftMoveAssigned_withSameType_thenOldIsCorrect) { either a = make_left(3); either b = make_right(2); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) }, [] (const auto& test) { either a = make_left(3); either b = make_left(2); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS_LEFT(MovableOnly(0)) // 0 is moved-from value @@ -954,12 +954,12 @@ TEST(EitherTest, givenRightMoveAssigned_thenOldIsCorrect) { either a(MovableOnly(3)); either b("2"); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) }, [] (const auto& test) { either a(MovableOnly(3)); either b(MovableOnly(2)); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS_RIGHT(MovableOnly(0)) // 0 is moved-from value @@ -990,12 +990,12 @@ TEST(EitherTest, givenRightMoveAssigned_withSameType_thenOldIsCorrect) { either a = make_right(3); either b = make_left(2); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) }, [] (const auto& test) { either a = make_right(3); either b = make_right(2); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS_RIGHT(MovableOnly(0)) // 0 is moved-from value From e489ce9880e9722ac6963c4a16e3cfdfe08f2a91 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Tue, 25 Dec 2018 19:53:33 +0100 Subject: [PATCH 2/4] Fix for travis --- test/cpp-utils/either_test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/cpp-utils/either_test.cpp b/test/cpp-utils/either_test.cpp index c1daeb66..92e8cd7a 100644 --- a/test/cpp-utils/either_test.cpp +++ b/test/cpp-utils/either_test.cpp @@ -1037,22 +1037,22 @@ TEST(EitherTest, givenRight_whenModified_thenValueIsChanged) { TEST(EitherTest, canEmplaceConstructLeft) { test_with_matrix({ [] (const auto& test) { - either, tuple> a(2, 3); + either, tuple> a(2, 3); test(a); } }, - EXPECT_IS_LEFT, tuple>(tuple(2, 3)) + EXPECT_IS_LEFT, tuple>(tuple(2, 3)) ); } TEST(EitherTest, canEmplaceConstructRight) { test_with_matrix({ [] (const auto& test) { - either, tuple> a(2, 3, 4); + either, tuple> a(2, "3", 4); test(a); } }, - EXPECT_IS_RIGHT, tuple>(tuple(2, 3, 4)) + EXPECT_IS_RIGHT, tuple>(tuple(2, "3", 4)) ); } From b531942445f8c3bc703f239bc5d3089298d5558d Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Tue, 25 Dec 2018 07:54:15 +0100 Subject: [PATCH 3/4] Upgrade to boost 1.58 --- .circleci/config.yml | 16 ++++++++-------- README.md | 2 +- cmake-utils/utils.cmake | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9b45b568..f9194ef6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -90,12 +90,12 @@ references: restore_cache: keys: # Find the most recent cache from any branch - - v3_upgrade_boost_cache_{{ checksum "/tmp/_build_env_vars" }}_{{ arch }} + - v4_upgrade_boost_cache_{{ checksum "/tmp/_build_env_vars" }}_{{ arch }} upgrade_boost_post: &upgrade_boost_post save_cache: - key: v3_upgrade_boost_cache_{{ checksum "/tmp/_build_env_vars" }}_{{ arch }} + key: v4_upgrade_boost_cache_{{ checksum "/tmp/_build_env_vars" }}_{{ arch }} paths: - - /tmp/boost_1_57_0 + - /tmp/boost_1_58_0 upgrade_boost: &upgrade_boost run: name: Upgrade Boost @@ -104,10 +104,10 @@ references: export NUMCORES=`nproc` echo Using $NUMCORES cores # Download and prepare boost (only if not already present from cache) - if [ ! -d "/tmp/boost_1_57_0" ]; then + if [ ! -d "/tmp/boost_1_58_0" ]; then echo "Didn't find boost in cache. Downloading and building." - wget -O /tmp/boost.tar.bz2 https://sourceforge.net/projects/boost/files/boost/1.57.0/boost_1_57_0.tar.bz2/download - if [ $(sha512sum /tmp/boost.tar.bz2 | awk '{print $1;}') == "61881440fd89644c43c6e3bc6292e9fed75a6d3a76f98654b189d0ed4e1087d77b585884e882270c08bf9f7132b173bfc1fde05848e06aa78ba7f1008d10714d" ]; then + wget -O /tmp/boost.tar.bz2 https://sourceforge.net/projects/boost/files/boost/1.58.0/boost_1_58_0.tar.bz2/download + if [ $(sha512sum /tmp/boost.tar.bz2 | awk '{print $1;}') == "7480ec713b0aa13f0ec990603e87e3b5c8d53f4411329b10fae37fc963b90aad12dbd9290a33c3669ae801e9012a68683eadff057591e9ca2ebcd22b1a67b5d1" ]; then echo Correct sha512sum else echo Wrong sha512sum @@ -117,14 +117,14 @@ references: echo Extracting... tar -xf /tmp/boost.tar.bz2 -C /tmp rm -rf boost.tar.bz2 - cd /tmp/boost_1_57_0 + cd /tmp/boost_1_58_0 ./bootstrap.sh --with-toolset=${BUILD_TOOLSET} --with-libraries=filesystem,thread,chrono,program_options cd .. else echo Found boost in cache. Use cache and build. fi # Compile and install boost (if cached, this should be fast) - cd /tmp/boost_1_57_0 + cd /tmp/boost_1_58_0 sudo ./b2 toolset=${BUILD_TOOLSET} link=static cxxflags=-fPIC -d0 -j$NUMCORES install build_pre: &build_pre restore_cache: diff --git a/README.md b/README.md index fc2a26f0..58e6fa40 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Requirements - GCC version >= 5.0 or Clang >= 4.0 - CMake version >= 3.0 - libcurl4 (including development headers) - - Boost libraries version >= 1.57 (including development headers) + - Boost libraries version >= 1.58 (including development headers) - filesystem - system - chrono diff --git a/cmake-utils/utils.cmake b/cmake-utils/utils.cmake index 72cac168..6648871c 100644 --- a/cmake-utils/utils.cmake +++ b/cmake-utils/utils.cmake @@ -108,7 +108,7 @@ endfunction(target_enable_style_warnings) function(target_add_boost TARGET) # Load boost libraries if(NOT DEFINED Boost_USE_STATIC_LIBS OR Boost_USE_STATIC_LIBS) - # Many supported systems don't have boost >= 1.57. Better link it statically. + # Many supported systems don't have boost >= 1.58. Better link it statically. message(STATUS "Boost will be statically linked") set(Boost_USE_STATIC_LIBS ON) else(NOT DEFINED Boost_USE_STATIC_LIBS OR Boost_USE_STATIC_LIBS) @@ -116,7 +116,7 @@ function(target_add_boost TARGET) set(Boost_USE_STATIC_LIBS OFF) endif(NOT DEFINED Boost_USE_STATIC_LIBS OR Boost_USE_STATIC_LIBS) set(BOOST_THREAD_VERSION 4) - find_package(Boost 1.57.0 + find_package(Boost 1.58.0 REQUIRED COMPONENTS ${ARGN}) target_include_directories(${TARGET} SYSTEM PUBLIC ${Boost_INCLUDE_DIRS}) From 1fdfdb34371a1ba2cfdd7844ace1076d5a210cac Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Tue, 25 Dec 2018 07:54:32 +0100 Subject: [PATCH 4/4] Change either_test to use optional correctly --- test/cpp-utils/either_test.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/test/cpp-utils/either_test.cpp b/test/cpp-utils/either_test.cpp index 92e8cd7a..af5de759 100644 --- a/test/cpp-utils/either_test.cpp +++ b/test/cpp-utils/either_test.cpp @@ -69,11 +69,9 @@ std::vector&)>> EXPECT_IS_LEFT(const Left }, [&] (auto& obj) { EXPECT_ANY_THROW(std::move(obj).right()); }, [&] (auto& obj) { - auto a = obj.left_opt(); - EXPECT_EQ(expected, a.value()); + EXPECT_EQ(expected, obj.left_opt().value()); }, [&] (auto& obj) { - auto a = std::move(obj).left_opt(); - EXPECT_EQ(expected, a.value()); + EXPECT_EQ(expected, std::move(obj).left_opt().value()); }, [&] (auto& obj) { EXPECT_EQ(boost::none, obj.right_opt()); }, [&] (auto& obj) { @@ -98,11 +96,9 @@ std::vector&)>> EXPECT_IS_RIGHT(const Rig }, [&] (auto& obj) { EXPECT_ANY_THROW(std::move(obj).left()); }, [&] (auto& obj) { - auto a = obj.right_opt(); - EXPECT_EQ(expected, a.value()); + EXPECT_EQ(expected, obj.right_opt().value()); }, [&] (auto& obj) { - auto a = std::move(obj).right_opt(); - EXPECT_EQ(expected, a.value()); + EXPECT_EQ(expected, std::move(obj).right_opt().value()); }, [&] (auto& obj) { EXPECT_EQ(boost::none, obj.left_opt()); }, [&] (auto& obj) {