mirror of
https://github.com/RGBCube/serenity
synced 2025-08-10 07:17:49 +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:
parent
4421d98e30
commit
765936ebae
103 changed files with 219 additions and 362 deletions
|
@ -188,8 +188,7 @@ static void allocate_tls()
|
|||
total_tls_size += data.value->tls_size();
|
||||
}
|
||||
if (total_tls_size) {
|
||||
void* tls_address = allocate_tls(total_tls_size);
|
||||
(void)tls_address;
|
||||
[[maybe_unused]] void* tls_address = allocate_tls(total_tls_size);
|
||||
VERBOSE("from userspace, tls_address: %p", tls_address);
|
||||
}
|
||||
g_total_tls_size = total_tls_size;
|
||||
|
@ -211,7 +210,7 @@ static void initialize_libc()
|
|||
|
||||
res = global_symbol_lookup("__libc_init");
|
||||
ASSERT(res.found);
|
||||
typedef void libc_init_func(void);
|
||||
typedef void libc_init_func();
|
||||
((libc_init_func*)res.address)();
|
||||
}
|
||||
|
||||
|
@ -262,8 +261,7 @@ static FlatPtr loader_main(auxv_t* auxvp)
|
|||
map_dependencies(main_program_name);
|
||||
|
||||
VERBOSE("loaded all dependencies");
|
||||
for (auto& lib : g_loaders) {
|
||||
(void)lib;
|
||||
for ([[maybe_unused]] auto& lib : g_loaders) {
|
||||
VERBOSE("%s - tls size: $u, tls offset: %u", lib.key.characters(), lib.value->tls_size(), lib.value->tls_offset());
|
||||
}
|
||||
|
||||
|
@ -301,8 +299,7 @@ void _start(int argc, char** argv, char** envp)
|
|||
|
||||
FlatPtr entry = loader_main(auxvp);
|
||||
VERBOSE("Loaded libs:\n");
|
||||
for (auto& obj : g_loaded_objects) {
|
||||
(void)obj;
|
||||
for ([[maybe_unused]] auto& obj : g_loaded_objects) {
|
||||
VERBOSE("%s: %p\n", obj.key.characters(), obj.value->base_address().as_ptr());
|
||||
}
|
||||
|
||||
|
|
|
@ -263,11 +263,11 @@ static long long cast_ll(double d)
|
|||
long long as_ll;
|
||||
};
|
||||
typedef char assert_double_8bytes[sizeof(double) == 8 ? 1 : -1];
|
||||
(void)sizeof(assert_double_8bytes);
|
||||
[[maybe_unused]] auto double_size = sizeof(assert_double_8bytes);
|
||||
typedef char assert_ll_8bytes[sizeof(long long) == 8 ? 1 : -1];
|
||||
(void)sizeof(assert_ll_8bytes);
|
||||
[[maybe_unused]] auto longlong_size = sizeof(assert_ll_8bytes);
|
||||
typedef char assert_readable_8bytes[sizeof(readable_t) == 8 ? 1 : -1];
|
||||
(void)sizeof(assert_readable_8bytes);
|
||||
[[maybe_unused]] auto readable8_size = sizeof(assert_readable_8bytes);
|
||||
readable_t readable;
|
||||
readable.as_double = d;
|
||||
return readable.as_ll;
|
||||
|
@ -280,9 +280,9 @@ static bool is_strtod_close(strtod_fn_t strtod_fn, const char* test_string, cons
|
|||
unsigned char as_bytes[8];
|
||||
};
|
||||
typedef char assert_double_8bytes[sizeof(double) == 8 ? 1 : -1];
|
||||
(void)sizeof(assert_double_8bytes);
|
||||
[[maybe_unused]] auto double_size = sizeof(assert_double_8bytes);
|
||||
typedef char assert_readable_8bytes[sizeof(readable_t) == 8 ? 1 : -1];
|
||||
(void)sizeof(assert_readable_8bytes);
|
||||
[[maybe_unused]] auto readable8_size = sizeof(assert_readable_8bytes);
|
||||
readable_t readable;
|
||||
char* endptr = (char*)0x123;
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static void usage(void)
|
||||
static void usage()
|
||||
{
|
||||
printf("usage: allocate [number [unit (B/KiB/MiB)]]\n");
|
||||
exit(1);
|
||||
|
|
|
@ -170,8 +170,7 @@ int main(int argc, char** argv)
|
|||
Crash("Division by zero", []() {
|
||||
volatile int lala = 10;
|
||||
volatile int zero = 0;
|
||||
volatile int test = lala / zero;
|
||||
UNUSED_PARAM(test);
|
||||
[[maybe_unused]] volatile int test = lala / zero;
|
||||
return Crash::Failure::DidNotCrash;
|
||||
}).run(run_type);
|
||||
}
|
||||
|
@ -196,8 +195,7 @@ int main(int argc, char** argv)
|
|||
if (!uninitialized_memory)
|
||||
return Crash::Failure::UnexpectedError;
|
||||
|
||||
volatile auto x = uninitialized_memory[0][0];
|
||||
UNUSED_PARAM(x);
|
||||
[[maybe_unused]] volatile auto x = uninitialized_memory[0][0];
|
||||
return Crash::Failure::DidNotCrash;
|
||||
}).run(run_type);
|
||||
}
|
||||
|
@ -209,8 +207,7 @@ int main(int argc, char** argv)
|
|||
return Crash::Failure::UnexpectedError;
|
||||
|
||||
free(uninitialized_memory);
|
||||
volatile auto x = uninitialized_memory[4][0];
|
||||
UNUSED_PARAM(x);
|
||||
[[maybe_unused]] volatile auto x = uninitialized_memory[4][0];
|
||||
return Crash::Failure::DidNotCrash;
|
||||
}).run(run_type);
|
||||
}
|
||||
|
@ -305,8 +302,7 @@ int main(int argc, char** argv)
|
|||
|
||||
free(ptr);
|
||||
dbgprintf("ptr = %p\n", ptr);
|
||||
volatile auto foo = *ptr;
|
||||
UNUSED_PARAM(foo);
|
||||
[[maybe_unused]] volatile auto foo = *ptr;
|
||||
return Crash::Failure::DidNotCrash;
|
||||
}).run(run_type);
|
||||
}
|
||||
|
|
|
@ -78,14 +78,11 @@ int main(int argc, char** argv)
|
|||
auto fs = fs_object.get("class_name").to_string();
|
||||
auto total_block_count = fs_object.get("total_block_count").to_u32();
|
||||
auto free_block_count = fs_object.get("free_block_count").to_u32();
|
||||
auto total_inode_count = fs_object.get("total_inode_count").to_u32();
|
||||
auto free_inode_count = fs_object.get("free_inode_count").to_u32();
|
||||
[[maybe_unused]] auto total_inode_count = fs_object.get("total_inode_count").to_u32();
|
||||
[[maybe_unused]] auto free_inode_count = fs_object.get("free_inode_count").to_u32();
|
||||
auto block_size = fs_object.get("block_size").to_u32();
|
||||
auto mount_point = fs_object.get("mount_point").to_string();
|
||||
|
||||
(void)total_inode_count;
|
||||
(void)free_inode_count;
|
||||
|
||||
printf("%-10s", fs.characters());
|
||||
|
||||
if (flag_human_readable) {
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
||||
{
|
||||
if (pledge("stdio rpath", nullptr) < 0) {
|
||||
perror("pledge");
|
||||
|
@ -45,8 +45,6 @@ int main(int argc, char** argv)
|
|||
|
||||
unveil(nullptr, nullptr);
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
auto f = Core::File::construct("/proc/dmesg");
|
||||
if (!f->open(Core::IODevice::ReadOnly)) {
|
||||
fprintf(stderr, "open: failed to open /proc/dmesg: %s\n", f->error_string());
|
||||
|
|
|
@ -84,7 +84,7 @@ static void print_syscall(PtraceRegisters& regs, size_t depth)
|
|||
|
||||
static NonnullOwnPtr<HashMap<void*, X86::Instruction>> instrument_code()
|
||||
{
|
||||
(void)demangle("foo"); // Required for linked with __cxa_demangle
|
||||
[[maybe_unused]] auto r = demangle("foo"); // Required for linked with __cxa_demangle
|
||||
auto instrumented = make<HashMap<void*, X86::Instruction>>();
|
||||
g_debug_session->elf().image().for_each_section_of_type(SHT_PROGBITS, [&](const ELF::Image::Section& section) {
|
||||
if (section.name() != ".text")
|
||||
|
|
|
@ -31,11 +31,8 @@
|
|||
#include <LibCore/File.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
||||
{
|
||||
UNUSED_PARAM(argc);
|
||||
UNUSED_PARAM(argv);
|
||||
|
||||
if (pledge("stdio rpath", nullptr) < 0) {
|
||||
perror("pledge");
|
||||
return 1;
|
||||
|
|
|
@ -32,11 +32,8 @@
|
|||
#include <LibPCIDB/Database.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
||||
{
|
||||
UNUSED_PARAM(argc);
|
||||
UNUSED_PARAM(argv);
|
||||
|
||||
if (pledge("stdio rpath", nullptr) < 0) {
|
||||
perror("pledge");
|
||||
return 1;
|
||||
|
|
|
@ -36,15 +36,12 @@ static void wait_for_key()
|
|||
printf("\033[7m--[ more ]--\033[0m");
|
||||
fflush(stdout);
|
||||
char dummy;
|
||||
(void)read(key_fd, &dummy, 1);
|
||||
[[maybe_unused]] auto rc = read(key_fd, &dummy, 1);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
if (pledge("stdio rpath tty", nullptr) < 0) {
|
||||
perror("pledge");
|
||||
return 1;
|
||||
|
|
|
@ -32,16 +32,13 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
||||
{
|
||||
if (pledge("stdio", nullptr) > 0) {
|
||||
perror("pledge");
|
||||
return 1;
|
||||
}
|
||||
|
||||
UNUSED_PARAM(argc);
|
||||
UNUSED_PARAM(argv);
|
||||
|
||||
Vector<String> lines;
|
||||
|
||||
for (;;) {
|
||||
|
|
|
@ -364,7 +364,7 @@ JSFileResult TestRunner::run_file_test(const String& test_path)
|
|||
new_interpreter.run(new_interpreter.global_object(), *file_program.value());
|
||||
|
||||
auto& before_initial_page_load = new_interpreter.vm().get_variable("__BeforeInitialPageLoad__", new_interpreter.global_object()).as_function();
|
||||
(void)new_interpreter.vm().call(before_initial_page_load, JS::js_undefined());
|
||||
[[maybe_unused]] auto rc_before = new_interpreter.vm().call(before_initial_page_load, JS::js_undefined());
|
||||
if (new_interpreter.exception())
|
||||
new_interpreter.vm().clear_exception();
|
||||
|
||||
|
@ -374,7 +374,7 @@ JSFileResult TestRunner::run_file_test(const String& test_path)
|
|||
|
||||
// Finally run the test by calling "__AfterInitialPageLoad__"
|
||||
auto& after_initial_page_load = new_interpreter.vm().get_variable("__AfterInitialPageLoad__", new_interpreter.global_object()).as_function();
|
||||
(void)new_interpreter.vm().call(after_initial_page_load, JS::js_undefined());
|
||||
[[maybe_unused]] auto rc_after = new_interpreter.vm().call(after_initial_page_load, JS::js_undefined());
|
||||
if (new_interpreter.exception())
|
||||
new_interpreter.vm().clear_exception();
|
||||
|
||||
|
|
|
@ -85,8 +85,7 @@ int main()
|
|||
json.value().as_object().for_each_member([&](auto& tty, auto& value) {
|
||||
const JsonObject& entry = value.as_object();
|
||||
auto uid = entry.get("uid").to_u32();
|
||||
auto pid = entry.get("pid").to_i32();
|
||||
(void)pid;
|
||||
[[maybe_unused]] auto pid = entry.get("pid").to_i32();
|
||||
|
||||
auto login_time = Core::DateTime::from_timestamp(entry.get("login_at").to_number<time_t>());
|
||||
auto login_at = login_time.to_string("%b%d %H:%M:%S");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue