Skip to content

Commit

Permalink
replace __UNUSED with maybe_unused
Browse files Browse the repository at this point in the history
Standard C++17.

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Jan 14, 2025
1 parent 7ec229a commit acb06f7
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 37 deletions.
5 changes: 0 additions & 5 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@ AC_SUBST(LIBTORRENT_CFLAGS)

AC_DEFINE(HAVE_CONFIG_H, 1, true if config.h was included)

CC_ATTRIBUTE_UNUSED(
AC_DEFINE([__UNUSED], [__attribute__((unused))], [Wrapper around unused attribute]),
AC_DEFINE([__UNUSED], [], [Null-wrapper if unused attribute is unsupported])
)

AC_CONFIG_FILES([
libtorrent.pc
Makefile
Expand Down
2 changes: 1 addition & 1 deletion rak/allocators.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class cacheline_allocator {

static pointer alloc_size(size_type size) {
pointer ptr = NULL;
int __UNUSED result = posix_memalign((void**)&ptr, LT_SMP_CACHE_BYTES, size);
[[maybe_unused]] int result = posix_memalign((void**)&ptr, LT_SMP_CACHE_BYTES, size);

return ptr;
}
Expand Down
6 changes: 3 additions & 3 deletions rak/string_manip.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ class split_iterator_t {
return *this;
}

bool operator == (__UNUSED const split_iterator_t& itr) const { return m_pos == m_seq->end(); }
bool operator != (__UNUSED const split_iterator_t& itr) const { return m_pos != m_seq->end(); }
bool operator == ([[maybe_unused]] const split_iterator_t& itr) const { return m_pos == m_seq->end(); }
bool operator != ([[maybe_unused]] const split_iterator_t& itr) const { return m_pos != m_seq->end(); }

private:
const Sequence* m_seq;
Expand All @@ -161,7 +161,7 @@ split_iterator(const Sequence& seq, typename Sequence::value_type delim) {

template <typename Sequence>
inline split_iterator_t<Sequence>
split_iterator(__UNUSED const Sequence& seq) {
split_iterator([[maybe_unused]] const Sequence& seq) {
return split_iterator_t<Sequence>();
}

Expand Down
4 changes: 2 additions & 2 deletions src/data/chunk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ Chunk::preload(uint32_t position, uint32_t length, bool useAdvise) {

} else {
for (char* first = (char*)data.first, *last = (char*)data.first + data.second; first < last; first += 4096)
volatile char __UNUSED touchChunk = *(char*)data.first;
[[maybe_unused]] volatile char touchChunk = *(char*)data.first;

// Make sure we touch the last page in the range.
volatile char __UNUSED touchChunk = *((char*)data.first + data.second - 1);
[[maybe_unused]] volatile char ouchChunk = *((char*)data.first + data.second - 1);
}

} while (itr.next());
Expand Down
2 changes: 1 addition & 1 deletion src/download/chunk_selector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ ChunkSelector::update_priorities() {
}

uint32_t
ChunkSelector::find(PeerChunks* pc, __UNUSED bool highPriority) {
ChunkSelector::find(PeerChunks* pc, [[maybe_unused]] bool highPriority) {
// This needs to be re-enabled.
if (m_position == invalid_chunk)
return invalid_chunk;
Expand Down
30 changes: 15 additions & 15 deletions src/torrent/poll_kqueue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -394,15 +394,15 @@ PollKQueue::remove_error(Event* event) {
#else // USE_QUEUE

PollKQueue*
PollKQueue::create(__UNUSED int maxOpenSockets) {
PollKQueue::create([[maybe_unused]] int maxOpenSockets) {
return NULL;
}

PollKQueue::~PollKQueue() {
}

int
PollKQueue::poll(__UNUSED int msec) {
PollKQueue::poll([[maybe_unused]] int msec) {
throw internal_error("An PollKQueue function was called, but it is disabled.");
}

Expand All @@ -422,57 +422,57 @@ PollKQueue::open_max() const {
}

void
PollKQueue::open(__UNUSED torrent::Event* event) {
PollKQueue::open([[maybe_unused]] torrent::Event* event) {
}

void
PollKQueue::close(__UNUSED torrent::Event* event) {
PollKQueue::close([[maybe_unused]] torrent::Event* event) {
}

void
PollKQueue::closed(__UNUSED torrent::Event* event) {
PollKQueue::closed([[maybe_unused]] torrent::Event* event) {
}

bool
PollKQueue::in_read(__UNUSED torrent::Event* event) {
PollKQueue::in_read([[maybe_unused]] torrent::Event* event) {
throw internal_error("An PollKQueue function was called, but it is disabled.");
}

bool
PollKQueue::in_write(__UNUSED torrent::Event* event) {
PollKQueue::in_write([[maybe_unused]] torrent::Event* event) {
throw internal_error("An PollKQueue function was called, but it is disabled.");
}

bool
PollKQueue::in_error(__UNUSED torrent::Event* event) {
PollKQueue::in_error([[maybe_unused]] torrent::Event* event) {
throw internal_error("An PollKQueue function was called, but it is disabled.");
}

void
PollKQueue::insert_read(__UNUSED torrent::Event* event) {
PollKQueue::insert_read([[maybe_unused]] torrent::Event* event) {
}

void
PollKQueue::insert_write(__UNUSED torrent::Event* event) {
PollKQueue::insert_write([[maybe_unused]] torrent::Event* event) {
}

void
PollKQueue::insert_error(__UNUSED torrent::Event* event) {
PollKQueue::insert_error([[maybe_unused]] torrent::Event* event) {
}

void
PollKQueue::remove_read(__UNUSED torrent::Event* event) {
PollKQueue::remove_read([[maybe_unused]] torrent::Event* event) {
}

void
PollKQueue::remove_write(__UNUSED torrent::Event* event) {
PollKQueue::remove_write([[maybe_unused]] torrent::Event* event) {
}

void
PollKQueue::remove_error(__UNUSED torrent::Event* event) {
PollKQueue::remove_error([[maybe_unused]] torrent::Event* event) {
}

PollKQueue::PollKQueue(__UNUSED int fd, __UNUSED int maxEvents, __UNUSED int maxOpenSockets) {
PollKQueue::PollKQueue([[maybe_unused]] int fd, [[maybe_unused]] int maxEvents, [[maybe_unused]] int maxOpenSockets) {
throw internal_error("An PollKQueue function was called, but it is disabled.");
}

Expand Down
4 changes: 2 additions & 2 deletions src/torrent/utils/resume.cc
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ resume_save_uncertain_pieces(Download download, Object& object) {
}

bool
resume_check_target_files(Download download, __UNUSED const Object& object) {
resume_check_target_files(Download download, [[maybe_unused]] const Object& object) {
FileList* fileList = download.file_list();

if (!fileList->is_open())
Expand Down Expand Up @@ -423,7 +423,7 @@ resume_check_target_files(Download download, __UNUSED const Object& object) {
} else {
// We consider empty file lists as being valid.
return fileList->empty() || fileList->front()->is_created();
}
}
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/tracker/tracker_udp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ TrackerUdp::event_write() {
if (m_writeBuffer->size_end() == 0)
throw internal_error("TrackerUdp::write() called but the write buffer is empty.");

int __UNUSED s = write_datagram(m_writeBuffer->begin(), m_writeBuffer->size_end(), &m_connectAddress);
[[maybe_unused]] int s = write_datagram(m_writeBuffer->begin(), m_writeBuffer->size_end(), &m_connectAddress);

manager->poll()->remove_write(this);
}
Expand Down
7 changes: 1 addition & 6 deletions test/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ TORRENT_CHECK_CACHELINE()
TORRENT_MINCORE()
TORRENT_OTFD()

CC_ATTRIBUTE_UNUSED(
AC_DEFINE([__UNUSED], [__attribute__((unused))], [Wrapper around unused attribute]),
AC_DEFINE([__UNUSED], [], [Null-wrapper if unused attribute is unsupported])
)

AC_OUTPUT([
Makefile
])
])
2 changes: 1 addition & 1 deletion test/torrent/utils/test_queue_buckets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static int items_destroyed = 0;

template <>
void
test_constants::destroy<int>(__UNUSED int& obj) {
test_constants::destroy<int>([[maybe_unused]] int& obj) {
items_destroyed++;
}

Expand Down

0 comments on commit acb06f7

Please sign in to comment.