From acb06f72cdc291f519abbcb55aee09c430be34e3 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 13 Jan 2025 11:44:03 -0800 Subject: [PATCH] replace __UNUSED with maybe_unused Standard C++17. Signed-off-by: Rosen Penev --- configure.ac | 5 ---- rak/allocators.h | 2 +- rak/string_manip.h | 6 ++--- src/data/chunk.cc | 4 ++-- src/download/chunk_selector.cc | 2 +- src/torrent/poll_kqueue.cc | 30 ++++++++++++------------ src/torrent/utils/resume.cc | 4 ++-- src/tracker/tracker_udp.cc | 2 +- test/configure.ac | 7 +----- test/torrent/utils/test_queue_buckets.cc | 2 +- 10 files changed, 27 insertions(+), 37 deletions(-) diff --git a/configure.ac b/configure.ac index 3210144bc..b898eaac3 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/rak/allocators.h b/rak/allocators.h index 0a1b71177..0398aa7ee 100644 --- a/rak/allocators.h +++ b/rak/allocators.h @@ -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; } diff --git a/rak/string_manip.h b/rak/string_manip.h index 1a09c3775..6be1afac2 100644 --- a/rak/string_manip.h +++ b/rak/string_manip.h @@ -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; @@ -161,7 +161,7 @@ split_iterator(const Sequence& seq, typename Sequence::value_type delim) { template inline split_iterator_t -split_iterator(__UNUSED const Sequence& seq) { +split_iterator([[maybe_unused]] const Sequence& seq) { return split_iterator_t(); } diff --git a/src/data/chunk.cc b/src/data/chunk.cc index 7f4a38513..19b4d1a02 100644 --- a/src/data/chunk.cc +++ b/src/data/chunk.cc @@ -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()); diff --git a/src/download/chunk_selector.cc b/src/download/chunk_selector.cc index 90bbdaecd..81fd65059 100644 --- a/src/download/chunk_selector.cc +++ b/src/download/chunk_selector.cc @@ -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; diff --git a/src/torrent/poll_kqueue.cc b/src/torrent/poll_kqueue.cc index 61c45e6b9..a1efc5235 100644 --- a/src/torrent/poll_kqueue.cc +++ b/src/torrent/poll_kqueue.cc @@ -394,7 +394,7 @@ PollKQueue::remove_error(Event* event) { #else // USE_QUEUE PollKQueue* -PollKQueue::create(__UNUSED int maxOpenSockets) { +PollKQueue::create([[maybe_unused]] int maxOpenSockets) { return NULL; } @@ -402,7 +402,7 @@ 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."); } @@ -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."); } diff --git a/src/torrent/utils/resume.cc b/src/torrent/utils/resume.cc index ca79625c1..25537f311 100644 --- a/src/torrent/utils/resume.cc +++ b/src/torrent/utils/resume.cc @@ -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()) @@ -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 diff --git a/src/tracker/tracker_udp.cc b/src/tracker/tracker_udp.cc index d9f1585dd..b8d608956 100644 --- a/src/tracker/tracker_udp.cc +++ b/src/tracker/tracker_udp.cc @@ -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); } diff --git a/test/configure.ac b/test/configure.ac index 671634114..5114df5d7 100644 --- a/test/configure.ac +++ b/test/configure.ac @@ -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 -]) \ No newline at end of file +]) diff --git a/test/torrent/utils/test_queue_buckets.cc b/test/torrent/utils/test_queue_buckets.cc index 49d1bae69..401bb6c51 100644 --- a/test/torrent/utils/test_queue_buckets.cc +++ b/test/torrent/utils/test_queue_buckets.cc @@ -44,7 +44,7 @@ static int items_destroyed = 0; template <> void -test_constants::destroy(__UNUSED int& obj) { +test_constants::destroy([[maybe_unused]] int& obj) { items_destroyed++; }