Skip to content

Commit

Permalink
fix warnings in new versions of clang
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Feb 17, 2024
1 parent 166f6c5 commit 10bf56b
Show file tree
Hide file tree
Showing 21 changed files with 159 additions and 33 deletions.
11 changes: 11 additions & 0 deletions include/libtorrent/aux_/heterogeneous_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ see LICENSE file.
#include <sanitizer/common_interface_defs.h>
#endif

#ifdef __clang__
// disable these warnings until this class is re-worked in a way clang likes
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
#endif

namespace libtorrent {
namespace aux {

Expand Down Expand Up @@ -274,4 +281,8 @@ namespace aux {
};
} // namespace libtorrent

#ifdef __clang__
#pragma clang diagnostic pop
#endif

#endif
2 changes: 2 additions & 0 deletions include/libtorrent/aux_/netlink_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ namespace aux {
#pragma clang diagnostic ignored "-Wsign-compare"
#pragma clang diagnostic ignored "-Wcast-qual"
#pragma clang diagnostic ignored "-Wcast-align"
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
#endif
// these are here to concentrate all the shady casts these macros expand to,
// to disable the warnings for them all
Expand Down
3 changes: 2 additions & 1 deletion include/libtorrent/aux_/stat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ see LICENSE file.

#include "libtorrent/config.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/aux_/array.hpp"

namespace libtorrent::aux {

Expand Down Expand Up @@ -256,7 +257,7 @@ namespace libtorrent::aux {

private:

stat_channel m_stat[num_channels];
aux::array<stat_channel, num_channels> m_stat;
};

}
Expand Down
11 changes: 11 additions & 0 deletions include/libtorrent/bitfield.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ see LICENSE file.
#include <cstring> // for memset and memcpy
#include <cstdint> // uint32_t

#ifdef __clang__
// disable these warnings until this class is re-worked in a way clang likes
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
#endif

namespace libtorrent {

// The bitfield type stores any number of bits as a bitfield
Expand Down Expand Up @@ -330,4 +337,8 @@ namespace libtorrent {
};
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif

#endif // TORRENT_BITFIELD_HPP_INCLUDED
2 changes: 1 addition & 1 deletion include/libtorrent/flags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct bit_t
int m_bit_idx;
};

constexpr bit_t operator "" _bit(unsigned long long int b) { return bit_t{static_cast<int>(b)}; }
constexpr bit_t operator ""_bit(unsigned long long int b) { return bit_t{static_cast<int>(b)}; }

namespace flags {

Expand Down
11 changes: 11 additions & 0 deletions include/libtorrent/span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ namespace aux {
};
}

#ifdef __clang__
// disable these warnings until this class is re-worked in a way clang likes
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
#endif

template <typename T>
struct span
{
Expand Down Expand Up @@ -153,6 +160,10 @@ namespace aux {
difference_type m_len;
};

#ifdef __clang__
#pragma clang diagnostic pop
#endif

template <class T, class U>
inline bool operator==(span<T> const& lhs, span<U> const& rhs)
{
Expand Down
25 changes: 11 additions & 14 deletions src/alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1370,8 +1370,7 @@ namespace {
return {};
#else
char ret[600];
static char const* const reason_str[] =
{
static aux::array<char const*, 8> const reason_str{{
"ip_filter",
"port_filter",
"i2p_mixed",
Expand All @@ -1380,7 +1379,7 @@ namespace {
"tcp_disabled",
"invalid_local_interface",
"ssrf_mitigation"
};
}};

std::snprintf(ret, sizeof(ret), "%s: blocked peer [%s]"
, peer_alert::message().c_str(), reason_str[reason]);
Expand Down Expand Up @@ -1508,9 +1507,9 @@ namespace {
return {};
#else
char msg[200];
static char const* const msgs[] = {
static aux::array<char const*, 1> const msgs{{
"tracker is not anonymous, set a proxy"
};
}};
std::snprintf(msg, sizeof(msg), "%s: %s: %s"
, torrent_alert::message().c_str()
, msgs[kind], str.c_str());
Expand Down Expand Up @@ -2156,8 +2155,8 @@ namespace {
#ifdef TORRENT_DISABLE_ALERT_MSG
return {};
#else
static char const* const mode[] =
{ "<==", "==>", "<<<", ">>>", "***" };
static aux::array<char const*, 5, direction_t> const mode{
{ "<==", "==>", "<<<", ">>>", "***" }};
return peer_alert::message() + " [" + print_endpoint(endpoint) + "] "
+ mode[direction] + " " + event_type + " [ " + log_message() + " ]";
#endif
Expand Down Expand Up @@ -2385,14 +2384,13 @@ namespace {
#ifdef TORRENT_DISABLE_ALERT_MSG
return {};
#else
static char const* const dht_modules[] =
{
static aux::array<char const*, 5, dht_module_t> const dht_modules{{
"tracker",
"node",
"routing_table",
"rpc_manager",
"traversal"
};
}};

char ret[900];
std::snprintf(ret, sizeof(ret), "DHT %s: %s", dht_modules[module]
Expand Down Expand Up @@ -2434,7 +2432,7 @@ namespace {

std::string msg = print_entry(print, true);

static char const* const prefix[2] = {"<==", "==>"};
static aux::array<char const*, 2, direction_t> const prefix{{"<==", "==>"}};
char buf[1024];
std::snprintf(buf, sizeof(buf), "%s [%s] %s", prefix[direction]
, print_endpoint(node).c_str(), msg.c_str());
Expand Down Expand Up @@ -2589,8 +2587,7 @@ namespace {
#ifdef TORRENT_DISABLE_ALERT_MSG
return {};
#else
static char const* const flag_names[] =
{
static aux::array<char const*, 17> const flag_names{{
"partial_ratio ",
"prioritize_partials ",
"rarest_first_partials ",
Expand All @@ -2608,7 +2605,7 @@ namespace {
"backup2 ",
"end_game ",
"extent_affinity ",
};
}};

std::string ret = peer_alert::message();

Expand Down
22 changes: 21 additions & 1 deletion src/assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ see LICENSE file.

#include <cxxabi.h>

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
#endif

namespace libtorrent {
std::string demangle(char const* name)
{
// in case this string comes
// in case this string comes
// this is needed on linux
char const* start = std::strchr(name, '(');
if (start != nullptr)
Expand Down Expand Up @@ -83,6 +89,10 @@ std::string demangle(char const* name)
::free(unmangled);
return ret;
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif
}
#elif defined _WIN32 && !defined TORRENT_WINRT

Expand Down Expand Up @@ -113,6 +123,12 @@ std::string demangle(char const* name) { return name; }
#if TORRENT_USE_EXECINFO
#include <execinfo.h>

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
#endif

namespace libtorrent {

TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth, void*)
Expand All @@ -133,6 +149,10 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth, void*)
}
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif

#elif defined _WIN32 && !defined TORRENT_WINRT

#include "libtorrent/aux_/windows.hpp"
Expand Down
11 changes: 11 additions & 0 deletions src/bdecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ see LICENSE file.
#define BOOST_SYSTEM_NOEXCEPT throw()
#endif

#ifdef __clang__
// disable these warnings until this class is re-worked in a way clang likes
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
#endif

namespace libtorrent {

using aux::bdecode_token;
Expand Down Expand Up @@ -1160,3 +1167,7 @@ namespace aux {
return ret;
}
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif
12 changes: 12 additions & 0 deletions src/bitfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ see LICENSE file.
#include <intrin.h>
#endif

#ifdef __clang__
// disable these warnings until this class is re-worked in a way clang likes
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
#endif

namespace libtorrent {

bool bitfield::all_set() const noexcept
Expand Down Expand Up @@ -225,3 +232,8 @@ namespace libtorrent {
static_assert(std::is_nothrow_default_constructible<typed_bitfield<int>>::value
, "should be nothrow default constructible");
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif

10 changes: 10 additions & 0 deletions src/cpuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ namespace libtorrent {
namespace aux {
namespace {

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
#endif

#if TORRENT_HAS_SSE
// internal
void cpuid(std::uint32_t* info, int type) noexcept
Expand Down Expand Up @@ -130,6 +136,10 @@ namespace {
#endif
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif

} // anonymous namespace

bool const sse42_support = supports_sse42();
Expand Down
10 changes: 10 additions & 0 deletions src/crc32c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ see LICENSE file.
#include <arm_acle.h>
#endif

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
#endif

namespace libtorrent::aux {

std::uint32_t crc32c_32(std::uint32_t v)
Expand Down Expand Up @@ -126,3 +132,7 @@ namespace libtorrent::aux {
return crc.checksum();
}
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif
7 changes: 4 additions & 3 deletions src/error_code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ see LICENSE file.
#include "libtorrent/config.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/aux_/string_util.hpp" // for to_string()
#include "libtorrent/aux_/array.hpp"

#include <sstream>

Expand All @@ -33,7 +34,7 @@ namespace libtorrent {

std::string libtorrent_error_category::message(int ev) const
{
static char const* msgs[] =
static aux::array<char const*, errors::error_code_max> msgs{
{
"no error",
"torrent file collides with file from another torrent",
Expand Down Expand Up @@ -272,8 +273,8 @@ namespace libtorrent {
"a v2 file entry has no root hash",
"v1 and v2 hashes do not describe the same data",
"a file in the v2 metadata has the pad attribute set"
};
if (ev < 0 || ev >= int(sizeof(msgs)/sizeof(msgs[0])))
}};
if (ev < 0 || ev >= msgs.end_index())
return "Unknown error";
return msgs[ev];
}
Expand Down
Loading

0 comments on commit 10bf56b

Please sign in to comment.