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 18, 2024
1 parent 9503e29 commit ce8f313
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 2 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
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
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
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
11 changes: 11 additions & 0 deletions src/fingerprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ namespace libtorrent {
return ret;
}

#ifdef __clang__
// TODO: the fingerprint constructor should take a string_view
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
#endif

fingerprint::fingerprint(const char* id_string, int major, int minor
, int revision, int tag)
: major_version(major)
Expand All @@ -68,6 +75,10 @@ namespace libtorrent {
name[1] = id_string[1];
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif

#if TORRENT_ABI_VERSION == 1
std::string fingerprint::to_string() const
{
Expand Down
11 changes: 11 additions & 0 deletions src/http_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ see LICENSE file.
#include "libtorrent/time.hpp" // for seconds32
#include "libtorrent/aux_/numeric_cast.hpp"

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

namespace libtorrent::aux {

bool is_ok_status(int http_status)
Expand Down Expand Up @@ -623,3 +629,8 @@ namespace libtorrent::aux {
return buffer.first(write_ptr - buffer.data());
}
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif

2 changes: 1 addition & 1 deletion src/torrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10436,7 +10436,7 @@ namespace {
int num_peers = 0;
int num_downloaders = 0;
int missing_pieces = 0;
for (auto* p : m_connections)
for (auto const* const p : m_connections)
{
TORRENT_INCREMENT(m_iterating_connections);
if (p->is_connecting()) continue;
Expand Down

0 comments on commit ce8f313

Please sign in to comment.