From 8fdba2aa39394f478fc7c1cbf9eeb04f822cf27e Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Wed, 9 May 2018 19:57:30 -0700 Subject: [PATCH] don't specialize standard type trait is_integral Concerning type traits, the C++ standard states: "The behavior of a program that adds specializations for any of the templates defined in this subclause is undefined unless otherwise specified." There is no exception for is_integral. --- include/libtorrent/aux_/numeric_cast.hpp | 3 +-- include/libtorrent/units.hpp | 4 ---- src/torrent.cpp | 6 +++--- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/include/libtorrent/aux_/numeric_cast.hpp b/include/libtorrent/aux_/numeric_cast.hpp index 4ad5056d4..1ab5779e5 100644 --- a/include/libtorrent/aux_/numeric_cast.hpp +++ b/include/libtorrent/aux_/numeric_cast.hpp @@ -54,8 +54,7 @@ namespace libtorrent { namespace aux { } // in C++ 17 you can use std::clamp - template ::value>::type> + template T clamp(T v, T lo, T hi) { TORRENT_ASSERT(lo <= hi); diff --git a/include/libtorrent/units.hpp b/include/libtorrent/units.hpp index a46db6ef4..594e44917 100644 --- a/include/libtorrent/units.hpp +++ b/include/libtorrent/units.hpp @@ -135,10 +135,6 @@ namespace libtorrent { namespace aux { namespace std { - template - struct is_integral> - : std::is_integral {}; - template class numeric_limits> : public std::numeric_limits { diff --git a/src/torrent.cpp b/src/torrent.cpp index d70f46f70..47dc1a709 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -4900,7 +4900,7 @@ bool is_downloading_state(int const st) bool const was_finished = is_finished(); for (auto const& p : pieces) { - static_assert(std::is_unsigned::value + 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)); @@ -4910,7 +4910,7 @@ bool is_downloading_state(int const st) || p.first >= m_torrent_file->end_piece() || p.second > top_priority) { - static_assert(std::is_unsigned::value + static_assert(std::is_unsigned::value , "we need additional condition: p.second < dont_download"); continue; } @@ -4953,7 +4953,7 @@ bool is_downloading_state(int const st) bool const was_finished = is_finished(); for (auto prio : pieces) { - static_assert(std::is_unsigned::value + 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);