diff --git a/.travis.yml b/.travis.yml index 2fb77900d..5b78fe614 100644 --- a/.travis.yml +++ b/.travis.yml @@ -185,7 +185,7 @@ script: # libtorrent is the name of the test suite target - cd test - 'if [ "$tests" == "1" ]; then - travis_retry bjam -j3 warnings-as-errors=on crypto=$crypto debug-iterators=on picker-debugging=on asserts=on invariant-checks=full $toolset variant=$variant libtorrent test_natpmp enum_if -l300 && + travis_retry bjam -j3 warnings-as-errors=on warnings=all crypto=$crypto debug-iterators=on picker-debugging=on asserts=on invariant-checks=full $toolset variant=$variant libtorrent test_natpmp enum_if -l300 && if [ "$coverage" == "1" ]; then codecov --root .. --gcov-exec gcov-5; fi; @@ -193,13 +193,13 @@ script: - cd ../examples - 'if [ "$examples" == "1" ]; then - bjam -j3 warnings-as-errors=on crypto=$crypto debug-iterators=on picker-debugging=on asserts=on invariant-checks=full $toolset variant=$variant link=shared; + bjam -j3 warnings-as-errors=on warnings=all crypto=$crypto debug-iterators=on picker-debugging=on asserts=on invariant-checks=full $toolset variant=$variant link=shared; fi' - cd .. - cd tools - 'if [ "$tools" == "1" ]; then - bjam -j3 warnings-as-errors=on crypto=$crypto debug-iterators=on picker-debugging=on asserts=on invariant-checks=full $toolset variant=$variant link=shared; + bjam -j3 warnings-as-errors=on warnings=all crypto=$crypto debug-iterators=on picker-debugging=on asserts=on invariant-checks=full $toolset variant=$variant link=shared; fi' - cd .. @@ -211,7 +211,7 @@ script: # on OSX we need to use the brew version of python, for reasons explained above - cd bindings/python - 'if [[ "$python" == "1" ]]; then - bjam -j3 warnings-as-errors=on crypto=$crypto debug-iterators=on picker-debugging=on asserts=on invariant-checks=full $toolset variant=$variant stage_module stage_dependencies libtorrent-link=shared boost-link=shared && + bjam -j3 warnings-as-errors=on warnings=all crypto=$crypto debug-iterators=on picker-debugging=on asserts=on invariant-checks=full $toolset variant=$variant stage_module stage_dependencies libtorrent-link=shared boost-link=shared && if [[ $TRAVIS_OS_NAME == "osx" ]]; then DYLD_LIBRARY_PATH=./dependencies python2 test.py; else @@ -223,7 +223,7 @@ script: # simulation - cd simulation - 'if [[ "$sim" == "1" ]]; then - bjam -j2 crypto=built-in warnings-as-errors=on debug-iterators=on picker-debugging=on asserts=on invariant-checks=full $toolset deprecated-functions=off; + bjam -j2 crypto=built-in warnings-as-errors=on warnings=all debug-iterators=on picker-debugging=on asserts=on invariant-checks=full $toolset deprecated-functions=off; fi' - cd .. @@ -252,6 +252,6 @@ script: - cd test - 'if [[ "$arch" == "arm" ]]; then - bjam arm-tests warnings-as-errors=on crypto=$crypto variant=test_arm $toolset target-os=linux link=static testing.launcher="sudo cp -R bin rootfs/; sudo chroot rootfs"; + bjam arm-tests warnings-as-errors=on warnings=all crypto=$crypto variant=test_arm $toolset target-os=linux link=static testing.launcher="sudo cp -R bin rootfs/; sudo chroot rootfs"; fi' - cd .. diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index bffd136f4..6bdd702c0 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -281,15 +281,16 @@ namespace libtorrent { private: aux::allocation_slot m_name_idx; #ifndef TORRENT_NO_DEPRECATE -#if defined __clang__ && __clang_major__ > 9 + +#if defined __clang__ #pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wshadow-field" +#pragma clang diagnostic ignored "-Weverything" #endif public: std::string TORRENT_DEPRECATED_MEMBER name; -#if defined __clang__ && __clang_major__ > 9 +#if defined __clang__ #pragma clang diagnostic pop #endif #endif diff --git a/include/libtorrent/bt_peer_connection.hpp b/include/libtorrent/bt_peer_connection.hpp index 8240209a1..d80ae8e52 100644 --- a/include/libtorrent/bt_peer_connection.hpp +++ b/include/libtorrent/bt_peer_connection.hpp @@ -492,11 +492,6 @@ namespace libtorrent { std::array m_reserved_bits; #endif - -#if TORRENT_USE_ASSERTS - bool m_in_constructor = true; -#endif - }; } diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 0dd8fc070..74111c48e 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -160,9 +160,6 @@ namespace { peer_log(peer_log_alert::info, "CONSTRUCT", "bt_peer_connection"); #endif -#if TORRENT_USE_ASSERTS - m_in_constructor = false; -#endif #ifndef TORRENT_DISABLE_EXTENSIONS m_reserved_bits.fill(0); #endif diff --git a/src/ip_notifier.cpp b/src/ip_notifier.cpp index bcf4995db..37e56231c 100644 --- a/src/ip_notifier.cpp +++ b/src/ip_notifier.cpp @@ -268,8 +268,16 @@ CFRef create_dynamic_store(SCDynamicStoreCallBack callback, v SCDynamicStoreContext context = {0, nullptr, nullptr, nullptr, nullptr}; context.info = context_info; + +#if defined __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wold-style-cast" +#endif CFRef store{SCDynamicStoreCreate(nullptr , CFSTR("libtorrent.IPChangeNotifierStore"), callback, &context)}; +#if defined __clang__ +#pragma clang diagnostic pop +#endif if (!store) return CFRef(); diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index ec142df2b..b7e4d3eb7 100644 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -1685,7 +1685,8 @@ namespace libtorrent { << ", " << new_piece_priority << ")" << std::endl; #endif - TORRENT_ASSERT(new_piece_priority >= dont_download); + static_assert(std::is_unsigned::value + , "we need assert new_piece_priority >= dont_download"); TORRENT_ASSERT(new_piece_priority <= top_priority); piece_pos& p = m_piece_map[index]; diff --git a/src/torrent.cpp b/src/torrent.cpp index 5558cd285..442f9e77e 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -4872,15 +4872,18 @@ namespace libtorrent { bool const was_finished = is_finished(); for (auto const& p : pieces) { - TORRENT_ASSERT(p.second >= dont_download); + static_assert(std::is_unsigned::value + , "we need assert p.second >= dont_download"); TORRENT_ASSERT(p.second <= top_priority); TORRENT_ASSERT(p.first >= piece_index_t(0)); TORRENT_ASSERT(p.first < m_torrent_file->end_piece()); if (p.first < piece_index_t(0) || p.first >= m_torrent_file->end_piece() - || p.second < dont_download || p.second > top_priority) + || p.second > top_priority) { + static_assert(std::is_unsigned::value + , "we need additional condition: p.second < dont_download"); continue; } @@ -4922,7 +4925,9 @@ namespace libtorrent { bool const was_finished = is_finished(); for (auto prio : pieces) { - TORRENT_ASSERT(prio >= dont_download && prio <= top_priority); + static_assert(std::is_unsigned::value + , "we need assert prio >= dont_download"); + TORRENT_ASSERT(prio <= top_priority); filter_updated |= m_picker->set_piece_priority(index, prio); TORRENT_ASSERT(num_have() >= m_picker->num_have_filtered()); ++index; diff --git a/test/test.hpp b/test/test.hpp index 9b1457d72..939fa6882 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -49,14 +49,17 @@ POSSIBILITY OF SUCH DAMAGE. // tests are expected to even test deprecated functionality. There is no point // in warning about deprecated use in any of the tests. - +// the unreachable code warnings are disabled since the test macros may +// sometimes have conditions that are known at compile time #if defined __clang__ #pragma clang diagnostic ignored "-Wdeprecated" #pragma clang diagnostic ignored "-Wdeprecated-declarations" +#pragma clang diagnostic ignored "-Wunreachable-code" #elif defined __GNUC__ #pragma GCC diagnostic ignored "-Wdeprecated" #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#pragma GCC diagnostic ignored "-Wunreachable-code" #elif defined _MSC_VER #pragma warning(disable : 4996) diff --git a/test/test_crc32.cpp b/test/test_crc32.cpp index 3f0c58871..c2f6f5278 100644 --- a/test/test_crc32.cpp +++ b/test/test_crc32.cpp @@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/crc32c.hpp" #include "libtorrent/aux_/cpuid.hpp" +#include "libtorrent/aux_/byteswap.hpp" #include "libtorrent/assert.hpp" #include "test.hpp" @@ -44,24 +45,24 @@ TORRENT_TEST(crc32) std::uint32_t in1 = 0x5aa5feef; out = crc32c_32(in1); - TEST_EQUAL(out, htonl(0xd5b9e35e)); + TEST_EQUAL(out, aux::host_to_network(0xd5b9e35eU)); std::uint64_t buf[4]; memcpy(buf, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 32); out = crc32c(buf, 4); - TEST_EQUAL(out, htonl(0xaa36918a)); + TEST_EQUAL(out, aux::host_to_network(0xaa36918aU)); memcpy(buf, "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", 32); out = crc32c(buf, 4); - TEST_EQUAL(out, htonl(0x43aba862)); + TEST_EQUAL(out, aux::host_to_network(0x43aba862U)); memcpy(buf, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 32); out = crc32c(buf, 4); - TEST_EQUAL(out, htonl(0x4e79dd46)); + TEST_EQUAL(out, aux::host_to_network(0x4e79dd46U)); #if TORRENT_HAS_ARM TORRENT_ASSERT(aux::arm_crc32c_support);