1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:57:45 +00:00

Everywhere: Switch from (void) to [[maybe_unused]] (#4473)

Problem:
- `(void)` simply casts the expression to void. This is understood to
  indicate that it is ignored, but this is really a compiler trick to
  get the compiler to not generate a warning.

Solution:
- Use the `[[maybe_unused]]` attribute to indicate the value is unused.

Note:
- Functions taking a `(void)` argument list have also been changed to
  `()` because this is not needed and shows up in the same grep
  command.
This commit is contained in:
Lenny Maiorani 2020-12-20 16:09:48 -07:00 committed by GitHub
parent 4421d98e30
commit 765936ebae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
103 changed files with 219 additions and 362 deletions

View file

@ -41,7 +41,7 @@ __attribute__((noreturn)) void __assertion_failed(const char* msg);
} while (0)
# define ASSERT_NOT_REACHED() assert(false)
#else
# define assert(expr) ((void)0)
# define assert(expr) (void(0))
# define ASSERT_NOT_REACHED() CRASH()
#endif

View file

@ -36,15 +36,13 @@ int sched_yield()
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int sched_get_priority_min(int policy)
int sched_get_priority_min([[maybe_unused]] int policy)
{
(void)policy;
return 0; // Idle
}
int sched_get_priority_max(int policy)
int sched_get_priority_max([[maybe_unused]] int policy)
{
(void)policy;
return 3; // High
}

View file

@ -1179,15 +1179,13 @@ int vfscanf(FILE* stream, const char* fmt, va_list ap)
return vsscanf(buffer, fmt, ap);
}
void flockfile(FILE* filehandle)
void flockfile([[maybe_unused]] FILE* filehandle)
{
(void)filehandle;
dbgprintf("FIXME: Implement flockfile()\n");
}
void funlockfile(FILE* filehandle)
void funlockfile([[maybe_unused]] FILE* filehandle)
{
(void)filehandle;
dbgprintf("FIXME: Implement funlockfile()\n");
}

View file

@ -804,11 +804,9 @@ size_t mbstowcs(wchar_t*, const char*, size_t)
ASSERT_NOT_REACHED();
}
int mbtowc(wchar_t* wch, const char* data, size_t data_size)
int mbtowc(wchar_t* wch, const char* data, [[maybe_unused]] size_t data_size)
{
// FIXME: This needs a real implementation.
UNUSED_PARAM(data_size);
if (wch && data) {
*wch = *data;
return 1;
@ -1023,7 +1021,7 @@ unsigned long long strtoull(const char* str, char** endptr, int base)
// Serenity's PRNG is not cryptographically secure. Do not rely on this for
// any real crypto! These functions (for now) are for compatibility.
// TODO: In the future, rand can be made deterministic and this not.
uint32_t arc4random(void)
uint32_t arc4random()
{
char buf[4];
syscall(SC_getrandom, buf, 4, 0);
@ -1073,15 +1071,13 @@ int posix_openpt(int flags)
return open("/dev/ptmx", flags);
}
int grantpt(int fd)
int grantpt([[maybe_unused]] int fd)
{
(void)fd;
return 0;
}
int unlockpt(int fd)
int unlockpt([[maybe_unused]] int fd)
{
(void)fd;
return 0;
}
}

View file

@ -41,13 +41,13 @@ __BEGIN_DECLS
__attribute__((malloc)) __attribute__((alloc_size(1))) void* malloc(size_t);
__attribute__((malloc)) __attribute__((alloc_size(1, 2))) void* calloc(size_t nmemb, size_t);
size_t malloc_size(void*);
void serenity_dump_malloc_stats(void);
void serenity_dump_malloc_stats();
void free(void*);
__attribute__((alloc_size(2))) void* realloc(void* ptr, size_t);
char* getenv(const char* name);
int putenv(char*);
int unsetenv(const char*);
int clearenv(void);
int clearenv();
int setenv(const char* name, const char* value, int overwrite);
int atoi(const char*);
long atol(const char*);
@ -87,7 +87,7 @@ void srand(unsigned seed);
long int random();
void srandom(unsigned seed);
uint32_t arc4random(void);
uint32_t arc4random();
void arc4random_buf(void*, size_t);
uint32_t arc4random_uniform(uint32_t);

View file

@ -94,7 +94,7 @@ void closelog_r(struct syslog_data* data)
data->maskpri = LOG_UPTO(LOG_DEBUG);
}
void closelog(void)
void closelog()
{
closelog_r(&global_log_data);
}

View file

@ -61,8 +61,8 @@ struct syslog_data {
#define LOG_DAEMON ( 3 << 3)
#define LOG_AUTH ( 4 << 3)
#define LOG_SYSLOG ( 5 << 3)
#define LOG_LPR ( 6 << 3)
#define LOG_NEWS ( 7 << 3)
#define LOG_LPR ( 6 << 3)
#define LOG_NEWS ( 7 << 3)
#define LOG_UUCP ( 8 << 3)
#define LOG_CRON ( 9 << 3)
#define LOG_AUTHPRIV (10 << 3)
@ -169,7 +169,7 @@ void vsyslog(int, const char* message, va_list);
void vsyslog_r(int, struct syslog_data* data, const char* message, va_list);
void openlog(const char*, int, int);
void openlog_r(const char*, int, int, struct syslog_data*);
void closelog(void);
void closelog();
void closelog_r(struct syslog_data*);
int setlogmask(int);
int setlogmask_r(int, struct syslog_data*);

View file

@ -39,10 +39,8 @@ char PC;
char* UP;
char* BC;
int tgetent(char* bp, const char* name)
int tgetent([[maybe_unused]] char* bp, [[maybe_unused]] const char* name)
{
(void)bp;
(void)name;
#ifdef TERMCAP_DEBUG
fprintf(stderr, "tgetent: bp=%p, name='%s'\n", bp, name);
#endif
@ -120,9 +118,8 @@ char* tgetstr(const char* id, char** area)
#pragma GCC diagnostic pop
int tgetflag(const char* id)
int tgetflag([[maybe_unused]] const char* id)
{
(void)id;
#ifdef TERMCAP_DEBUG
fprintf(stderr, "tgetflag: '%s'\n", id);
#endif
@ -143,17 +140,13 @@ int tgetnum(const char* id)
ASSERT_NOT_REACHED();
}
char* tgoto(const char* cap, int col, int row)
char* tgoto([[maybe_unused]] const char* cap, [[maybe_unused]] int col, [[maybe_unused]] int row)
{
(void)cap;
(void)col;
(void)row;
ASSERT_NOT_REACHED();
}
int tputs(const char* str, int affcnt, int (*putc)(int))
int tputs(const char* str, [[maybe_unused]] int affcnt, int (*putc)(int))
{
(void)affcnt;
size_t len = strlen(str);
for (size_t i = 0; i < len; ++i)
putc(str[i]);

View file

@ -51,10 +51,8 @@ int tcsetattr(int fd, int optional_actions, const struct termios* t)
return -1;
}
int tcflow(int fd, int action)
int tcflow([[maybe_unused]] int fd, [[maybe_unused]] int action)
{
(void)fd;
(void)action;
ASSERT_NOT_REACHED();
}

View file

@ -31,18 +31,14 @@
extern "C" {
long ulimit(int cmd, long newlimit)
long ulimit([[maybe_unused]] int cmd, [[maybe_unused]] long newlimit)
{
(void)cmd;
(void)newlimit;
ASSERT_NOT_REACHED();
return -1;
}
int getrusage(int who, struct rusage* usage)
int getrusage([[maybe_unused]] int who, [[maybe_unused]] struct rusage* usage)
{
(void)who;
(void)usage;
dbg() << "LibC: getrusage is not implemented";
return -1;
}

View file

@ -515,11 +515,8 @@ int mknod(const char* pathname, mode_t mode, dev_t dev)
__RETURN_WITH_ERRNO(rc, rc, -1);
}
long fpathconf(int fd, int name)
long fpathconf([[maybe_unused]] int fd, [[maybe_unused]] int name)
{
(void)fd;
(void)name;
switch (name) {
case _PC_PATH_MAX:
return PATH_MAX;
@ -530,10 +527,8 @@ long fpathconf(int fd, int name)
ASSERT_NOT_REACHED();
}
long pathconf(const char* path, int name)
long pathconf([[maybe_unused]] const char* path, int name)
{
(void)path;
switch (name) {
case _PC_PATH_MAX:
return PATH_MAX;
@ -614,9 +609,8 @@ void sysbeep()
syscall(SC_beep);
}
int fsync(int fd)
int fsync([[maybe_unused]] int fd)
{
UNUSED_PARAM(fd);
dbgprintf("FIXME: Implement fsync()\n");
return 0;
}

View file

@ -770,8 +770,7 @@ Board::Result Board::game_result() const
return Result::InsufficientMaterial;
bool are_legal_moves = false;
generate_moves([&](Move m) {
(void)m;
generate_moves([&]([[maybe_unused]] Move m) {
are_legal_moves = true;
return IterationDecision::Break;
});

View file

@ -316,9 +316,8 @@ String BestMoveCommand::to_string() const
return builder.build();
}
InfoCommand InfoCommand::from_string(const StringView& command)
InfoCommand InfoCommand::from_string([[maybe_unused]] const StringView& command)
{
(void)command;
// FIXME: Implement this.
ASSERT_NOT_REACHED();
}

View file

@ -391,7 +391,7 @@ void DynamicLoader::do_relocations(size_t total_tls_size)
// Eagerly BIND_NOW the PLT entries, doing all the symbol looking goodness
// The patch method returns the address for the LAZY fixup path, but we don't need it here
VERBOSE("patching plt reloaction: 0x%x\n", relocation.offset_in_section());
(void)m_dynamic_object->patch_plt_entry(relocation.offset_in_section());
[[maybe_unused]] auto rc = m_dynamic_object->patch_plt_entry(relocation.offset_in_section());
} else {
// LAZY-ily bind the PLT slots by just adding the base address to the offsets stored there
// This avoids doing symbol lookup, which might be expensive
@ -408,7 +408,7 @@ void DynamicLoader::do_relocations(size_t total_tls_size)
}
// Defined in <arch>/plt_trampoline.S
extern "C" void _plt_trampoline(void) __attribute__((visibility("hidden")));
extern "C" void _plt_trampoline() __attribute__((visibility("hidden")));
void DynamicLoader::setup_plt_trampoline()
{

View file

@ -63,9 +63,8 @@ bool JSSyntaxHighlighter::is_identifier(void* token) const
return js_token == JS::TokenType::Identifier;
}
bool JSSyntaxHighlighter::is_navigatable(void* token) const
bool JSSyntaxHighlighter::is_navigatable([[maybe_unused]] void* token) const
{
(void)token;
return false;
}

View file

@ -364,13 +364,11 @@ Bitmap::~Bitmap()
delete[] m_palette;
}
void Bitmap::set_mmap_name(const StringView& name)
void Bitmap::set_mmap_name([[maybe_unused]] const StringView& name)
{
ASSERT(m_needs_munmap);
#ifdef __serenity__
::set_mmap_name(m_data, size_in_bytes(), name.to_string().characters());
#else
(void)name;
#endif
}
@ -431,7 +429,7 @@ ShareableBitmap Bitmap::to_shareable_bitmap(pid_t peer_pid) const
return ShareableBitmap(*bitmap);
}
Optional<BackingStore> Bitmap::allocate_backing_store(BitmapFormat format, const IntSize& size, Purgeable purgeable)
Optional<BackingStore> Bitmap::allocate_backing_store(BitmapFormat format, const IntSize& size, [[maybe_unused]] Purgeable purgeable)
{
if (size_would_overflow(format, size))
return {};
@ -444,7 +442,6 @@ Optional<BackingStore> Bitmap::allocate_backing_store(BitmapFormat format, const
int map_flags = purgeable == Purgeable::Yes ? (MAP_PURGEABLE | MAP_PRIVATE) : (MAP_ANONYMOUS | MAP_PRIVATE);
data = mmap_with_name(nullptr, data_size_in_bytes, PROT_READ | PROT_WRITE, map_flags, 0, 0, String::format("GraphicsBitmap [%dx%d]", size.width(), size.height()).characters());
#else
UNUSED_PARAM(purgeable);
int map_flags = (MAP_ANONYMOUS | MAP_PRIVATE);
data = mmap(nullptr, data_size_in_bytes, PROT_READ | PROT_WRITE, map_flags, 0, 0);
#endif

View file

@ -118,10 +118,8 @@ static int read_number(Streamer& streamer)
return sb.to_string().to_uint().value_or(0);
}
static bool read_comment(PBMLoadingContext& context, Streamer& streamer)
static bool read_comment([[maybe_unused]] PBMLoadingContext& context, Streamer& streamer)
{
(void)context;
bool exist = false;
u8 byte;

View file

@ -135,10 +135,8 @@ static bool read_number(Streamer& streamer, u16* value)
return true;
}
static bool read_comment(PGMLoadingContext& context, Streamer& streamer)
static bool read_comment([[maybe_unused]] PGMLoadingContext& context, Streamer& streamer)
{
(void)context;
bool exist = false;
u8 byte;

View file

@ -138,10 +138,8 @@ static bool read_number(Streamer& streamer, u16* value)
return true;
}
static bool read_comment(PPMLoadingContext& context, Streamer& streamer)
static bool read_comment([[maybe_unused]] PPMLoadingContext& context, Streamer& streamer)
{
(void)context;
bool exist = false;
u8 byte;

View file

@ -271,11 +271,10 @@ void Job::on_socket_connected()
// we've read everything, now let's get the next chunk
size = -1;
auto line = read_line(PAGE_SIZE);
[[maybe_unused]] auto line = read_line(PAGE_SIZE);
#ifdef JOB_DEBUG
dbg() << "Line following (should be empty): _" << line << "_";
#endif
(void)line;
}
m_current_chunk_remaining_size = size;
}

View file

@ -166,7 +166,7 @@ bool Decoder::decode(Dictionary& dictionary)
return true;
}
bool Decoder::decode(File& file)
bool Decoder::decode([[maybe_unused]] File& file)
{
#ifdef __serenity__
int fd = recvfd(m_sockfd);
@ -177,8 +177,7 @@ bool Decoder::decode(File& file)
file = File(fd);
return true;
#else
(void)file;
(void)m_sockfd;
[[maybe_unused]] auto fd = m_sockfd;
warnln("fd passing is not supported on this platform, sorry :(");
return false;
#endif

View file

@ -42,7 +42,7 @@
JS::Value name([[maybe_unused]] JS::VM& vm, [[maybe_unused]] JS::GlobalObject& global_object)
#define JS_DEFINE_NATIVE_SETTER(name) \
void name([[maybe_unused]] JS::VM& vm, [[maybe_unused]] JS::GlobalObject& global_object, JS::Value value)
void name([[maybe_unused]] JS::VM& vm, [[maybe_unused]] JS::GlobalObject& global_object, [[maybe_unused]] JS::Value value)
// NOTE: Proxy is not included here as it doesn't have a prototype - m_proxy_constructor is initialized separately.
#define JS_ENUMERATE_NATIVE_OBJECTS_EXCLUDING_TEMPLATES \

View file

@ -63,7 +63,7 @@ public:
if (!m_setter)
return;
// FIXME: It might be nice if we had a way to communicate to our caller if an exception happened after this.
(void)vm().call(*m_setter, this_value, setter_value);
[[maybe_unused]] auto rc = vm().call(*m_setter, this_value, setter_value);
}
void visit_edges(Cell::Visitor& visitor) override

View file

@ -87,9 +87,8 @@ Object* iterator_next(Object& iterator, Value value)
return &result.as_object();
}
void iterator_close(Object& iterator)
void iterator_close([[maybe_unused]] Object& iterator)
{
(void)iterator;
TODO();
}

View file

@ -225,10 +225,7 @@ public:
template<typename... Args>
[[nodiscard]] ALWAYS_INLINE Value call(Function& function, Value this_value, Args... args)
{
// Are there any values in this argpack?
// args = [] -> if constexpr (false)
// args = [x, y, z] -> if constexpr ((void)x, true || ...)
if constexpr ((((void)args, true) || ...)) {
if constexpr (sizeof...(Args) > 0) {
MarkedValueList arglist { heap() };
(..., arglist.append(move(args)));
return call(function, this_value, move(arglist));

View file

@ -1480,7 +1480,7 @@ Vector<size_t, 2> Editor::vt_dsr()
do {
more_junk_to_read = false;
(void)select(1, &readfds, nullptr, nullptr, &timeout);
[[maybe_unused]] auto rc = select(1, &readfds, nullptr, nullptr, &timeout);
if (FD_ISSET(0, &readfds)) {
auto nread = read(0, buf, 16);
if (nread < 0) {

View file

@ -460,19 +460,13 @@ int pthread_attr_setstacksize(pthread_attr_t* attributes, size_t stack_size)
return 0;
}
int pthread_getschedparam(pthread_t thread, int* policy, struct sched_param* param)
int pthread_getschedparam([[maybe_unused]] pthread_t thread, [[maybe_unused]] int* policy, [[maybe_unused]] struct sched_param* param)
{
(void)thread;
(void)policy;
(void)param;
return 0;
}
int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param* param)
int pthread_setschedparam([[maybe_unused]] pthread_t thread, [[maybe_unused]] int policy, [[maybe_unused]] const struct sched_param* param)
{
(void)thread;
(void)policy;
(void)param;
return 0;
}

View file

@ -67,7 +67,7 @@ int pthread_attr_setstack(pthread_attr_t* attr, void*, size_t);
int pthread_attr_getstacksize(const pthread_attr_t*, size_t*);
int pthread_attr_setstacksize(pthread_attr_t*, size_t);
int pthread_once(pthread_once_t*, void (*)(void));
int pthread_once(pthread_once_t*, void (*)());
#define PTHREAD_ONCE_INIT 0
void* pthread_getspecific(pthread_key_t key);
int pthread_setspecific(pthread_key_t key, const void* value);
@ -100,14 +100,14 @@ int pthread_cancel(pthread_t);
int pthread_cond_destroy(pthread_cond_t*);
int pthread_cond_timedwait(pthread_cond_t*, pthread_mutex_t*, const struct timespec*);
void pthread_testcancel(void);
void pthread_testcancel();
int pthread_spin_destroy(pthread_spinlock_t*);
int pthread_spin_init(pthread_spinlock_t*, int);
int pthread_spin_lock(pthread_spinlock_t*);
int pthread_spin_trylock(pthread_spinlock_t*);
int pthread_spin_unlock(pthread_spinlock_t*);
pthread_t pthread_self(void);
pthread_t pthread_self();
int pthread_detach(pthread_t);
int pthread_equal(pthread_t, pthread_t);
int pthread_mutexattr_init(pthread_mutexattr_t*);

View file

@ -37,7 +37,7 @@ enum State : i32 {
PERFORMING_WITH_WAITERS,
};
int pthread_once(pthread_once_t* self, void (*callback)(void))
int pthread_once(pthread_once_t* self, void (*callback)())
{
auto& state = reinterpret_cast<Atomic<State>&>(*self);

View file

@ -337,7 +337,6 @@ JS_DEFINE_NATIVE_GETTER(WindowObject::document_getter)
JS_DEFINE_NATIVE_SETTER(WindowObject::document_setter)
{
// FIXME: Figure out what we should do here. Just ignore attempts to set window.document for now.
UNUSED_PARAM(value);
}
JS_DEFINE_NATIVE_GETTER(WindowObject::performance_getter)

View file

@ -48,10 +48,9 @@ namespace Web::DOM {
// FIXME: This shouldn't be here, as retargeting is not only used by the event dispatcher.
// When moving this function, it needs to be generalized. https://dom.spec.whatwg.org/#retarget
static EventTarget* retarget(EventTarget* left, EventTarget* right)
static EventTarget* retarget(EventTarget* left, [[maybe_unused]] EventTarget* right)
{
// FIXME
UNUSED_PARAM(right);
for (;;) {
if (!is<Node>(left))
return left;
@ -110,7 +109,7 @@ bool EventDispatcher::inner_invoke(Event& event, Vector<EventTarget::EventListen
auto* this_value = Bindings::wrap(global, *event.current_target());
auto* wrapped_event = Bindings::wrap(global, event);
auto& vm = global.vm();
(void)vm.call(listener.listener->function(), this_value, wrapped_event);
[[maybe_unused]] auto rc = vm.call(listener.listener->function(), this_value, wrapped_event);
if (vm.exception()) {
vm.clear_exception();
// FIXME: Set legacyOutputDidListenersThrowFlag if given. (Only used by IndexedDB currently)

View file

@ -98,7 +98,7 @@ void Window::timer_did_fire(Badge<Timer>, Timer& timer)
m_timers.remove(timer.id());
}
(void)vm.call(timer.callback(), wrapper());
[[maybe_unused]] auto rc = vm.call(timer.callback(), wrapper());
if (vm.exception())
vm.clear_exception();
}
@ -132,7 +132,7 @@ i32 Window::request_animation_frame(JS::Function& callback)
auto& function = const_cast<JS::Function&>(static_cast<const JS::Function&>(*handle.cell()));
auto& vm = function.vm();
fake_timestamp += 10;
(void)vm.call(function, {}, JS::Value(fake_timestamp));
[[maybe_unused]] auto rc = vm.call(function, {}, JS::Value(fake_timestamp));
if (vm.exception())
vm.clear_exception();
GUI::DisplayLink::unregister_callback(link_id);

View file

@ -301,9 +301,8 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt
return true;
}
void EventHandler::dump_selection(const char* event_name) const
void EventHandler::dump_selection([[maybe_unused]] const char* event_name) const
{
UNUSED_PARAM(event_name);
#ifdef SELECTION_DEBUG
dbg() << event_name << " selection start: "
<< layout_root()->selection().start().layout_node << ":" << layout_root()->selection().start().index_in_node << ", end: "

View file

@ -359,7 +359,7 @@ inline void TreeNode<T>::append_child(NonnullRefPtr<T> node, bool notify)
m_first_child = m_last_child;
if (notify)
node->inserted_into(static_cast<T&>(*this));
(void)node.leak_ref();
[[maybe_unused]] auto& rc = node.leak_ref();
if (notify)
static_cast<T*>(this)->children_changed();
@ -394,7 +394,7 @@ inline void TreeNode<T>::insert_before(NonnullRefPtr<T> node, RefPtr<T> child, b
node->m_parent = static_cast<T*>(this);
if (notify)
node->inserted_into(static_cast<T&>(*this));
(void)node.leak_ref();
[[maybe_unused]] auto& rc = node.leak_ref();
if (notify)
static_cast<T*>(this)->children_changed();
@ -416,7 +416,7 @@ inline void TreeNode<T>::prepend_child(NonnullRefPtr<T> node)
if (!m_last_child)
m_last_child = m_first_child;
node->inserted_into(static_cast<T&>(*this));
(void)node.leak_ref();
[[maybe_unused]] auto& rc = node.leak_ref();
static_cast<T*>(this)->children_changed();
}