1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-11 21:17:28 +03:00

Fix -Wunused-variable warnings

https://github.com/rui314/mold/issues/708
This commit is contained in:
Rui Ueyama 2022-09-14 15:00:48 +08:00
parent 75c142f321
commit 07636727c7
5 changed files with 11 additions and 8 deletions

View File

@ -20,7 +20,11 @@
#include <zlib.h>
#include <zstd.h>
#define CHECK(fn) do { int r = (fn); assert(r == Z_OK); } while (0)
#define CHECK(fn) \
do { \
[[maybe_unused]] int r = (fn); \
assert(r == Z_OK); \
} while (0)
namespace mold {

View File

@ -500,7 +500,7 @@ static void load_plugin(Context<E> &ctx) {
tv.emplace_back(LDPT_GET_API_VERSION, get_api_version<E>);
tv.emplace_back(LDPT_NULL, 0);
PluginStatus status = onload(tv.data());
[[maybe_unused]] PluginStatus status = onload(tv.data());
assert(status == LDPS_OK);
}

View File

@ -495,8 +495,7 @@ void add_synthetic_symbols(Context<E> &ctx) {
template <typename E>
void check_cet_errors(Context<E> &ctx) {
bool warning = (ctx.arg.z_cet_report == CET_REPORT_WARNING);
bool error = (ctx.arg.z_cet_report == CET_REPORT_ERROR);
assert(warning || error);
assert(warning || (ctx.arg.z_cet_report == CET_REPORT_ERROR));
for (ObjectFile<E> *file : ctx.objs) {
if (!(file->features & GNU_PROPERTY_X86_FEATURE_1_IBT)) {

View File

@ -49,7 +49,7 @@ std::function<void()> fork_child() {
return [=] {
char buf[] = {1};
int n = write(pipefd[1], buf, 1);
[[maybe_unused]] int n = write(pipefd[1], buf, 1);
assert(n == 1);
};
}
@ -81,8 +81,8 @@ static std::string find_dso(Context<E> &ctx, std::filesystem::path self) {
template <typename E>
[[noreturn]]
void process_run_subcommand(Context<E> &ctx, int argc, char **argv) {
std::string_view arg1 = argv[1];
assert(arg1 == "-run" || arg1 == "--run");
assert(argv[1] == "-run"s || argv[1] == "--run"s);
if (!argv[2])
Fatal(ctx) << "-run: argument missing";

View File

@ -118,7 +118,7 @@ static i64 parse_version(const std::string &arg) {
static std::regex re(R"((\d+)(?:\.(\d+))?(?:\.(\d+))?)", flags);
std::smatch m;
bool ok = std::regex_match(arg, m, re);
[[maybe_unused]] bool ok = std::regex_match(arg, m, re);
assert(ok);
i64 major = (m[1].length() == 0) ? 0 : stoi(m[1]);