diff --git a/src/commandline_argv.cpp b/src/commandline_argv.cpp index 3631dc63ee3f..a1b78c180f95 100644 --- a/src/commandline_argv.cpp +++ b/src/commandline_argv.cpp @@ -76,11 +76,9 @@ std::vector win32_read_argv(const std::string& input) #endif -std::vector read_argv(int argc, char** argv) +std::vector read_argv([[maybe_unused]] int argc, [[maybe_unused]] char** argv) { #ifdef _WIN32 - UNUSED(argc); - UNUSED(argv); // On Windows, argv is ANSI-encoded by default. Wesnoth absolutely needs to // work with UTF-8 values in order to avoid losing or corrupting // information from the command line. diff --git a/src/desktop/open.cpp b/src/desktop/open.cpp index d4d5de232644..d281857ebf94 100644 --- a/src/desktop/open.cpp +++ b/src/desktop/open.cpp @@ -43,7 +43,7 @@ static lg::log_domain log_desktop("desktop"); namespace desktop { -bool open_object(const std::string& path_or_url) +bool open_object([[maybe_unused]] const std::string& path_or_url) { LOG_DU << "open_object(): requested object: " << path_or_url << '\n'; @@ -88,7 +88,6 @@ bool open_object(const std::string& path_or_url) #else - UNUSED(path_or_url); // silence gcc's -Wunused-parameter ERR_DU << "open_object(): unsupported platform" << std::endl; return false; diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 08b273d29717..da0017be207b 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -607,9 +607,7 @@ static bool is_path_relative_to_cwd(const std::string& str) void set_user_data_dir(std::string newprefdir) { - bool relative_ok = false; - // Not always but it can be unused in some configurations - UNUSED(relative_ok); + [[maybe_unused]] bool relative_ok = false; #ifdef PREFERENCES_DIR if(newprefdir.empty()) { diff --git a/src/gui/dialogs/lua_interpreter.cpp b/src/gui/dialogs/lua_interpreter.cpp index 6ee34ab6b2fd..5b631f680330 100644 --- a/src/gui/dialogs/lua_interpreter.cpp +++ b/src/gui/dialogs/lua_interpreter.cpp @@ -221,9 +221,8 @@ class lua_interpreter::input_model { } catch (...) { std::cerr << "Swallowed an exception when trying to write lua command line history\n";} } #endif - void add_to_history (const std::string& str) { + void add_to_history ([[maybe_unused]] const std::string& str) { prefix_ = ""; - UNUSED(str); #ifdef HAVE_HISTORY add_history(str.c_str()); #endif @@ -241,7 +240,7 @@ class lua_interpreter::input_model { LOG_LUA << "updated prefix\n"; } - std::string search( int direction ) { + std::string search([[maybe_unused]] int direction ) { #ifdef HAVE_HISTORY LOG_LUA << "searching in direction " << direction << " from position " << where_history() << "\n"; @@ -285,7 +284,6 @@ class lua_interpreter::input_model { // reset, set history to the end and prefix_ to empty, and return the current prefix_ for the user to edit end_of_history_ = true; - UNUSED(direction); std::string temp = prefix_; prefix_ = ""; return temp; @@ -330,7 +328,7 @@ class lua_interpreter::input_model { // Does history expansion in a command line. A return value of true indicates an error, // the error message will be returned in the string argument. A return value of false // indicates success and that execution should proceed. - bool do_history_expansion (std::string & cmd) { + bool do_history_expansion ([[maybe_unused]] std::string & cmd) { #ifdef HAVE_HISTORY // Do history expansions std::unique_ptr cmd_cstr(new char[cmd.length()+1]); @@ -349,7 +347,6 @@ class lua_interpreter::input_model { cmd = expansion; free(expansion); #endif - UNUSED(cmd); return false; } }; diff --git a/src/scripting/game_lua_kernel.cpp b/src/scripting/game_lua_kernel.cpp index 927bd7d15bc8..48aa07ef570f 100644 --- a/src/scripting/game_lua_kernel.cpp +++ b/src/scripting/game_lua_kernel.cpp @@ -1611,7 +1611,6 @@ int game_lua_kernel::impl_end_level_data_set(lua_State* L) static int impl_end_level_data_collect(lua_State* L) { end_level_data* data = static_cast(lua_touserdata(L, 1)); - UNUSED(data); // Suppress an erroneous MSVC warning (a destructor call doesn't count as a reference) data->~end_level_data(); return 0; } diff --git a/src/server/campaignd/server.cpp b/src/server/campaignd/server.cpp index 3f96845d3945..67204763e645 100644 --- a/src/server/campaignd/server.cpp +++ b/src/server/campaignd/server.cpp @@ -705,7 +705,7 @@ void server::write_config() DBG_CS << "... done\n"; } -void server::fire(const std::string& hook, const std::string& addon) +void server::fire(const std::string& hook, [[maybe_unused]] const std::string& addon) { const std::map::const_iterator itor = hooks_.find(hook); if(itor == hooks_.end()) { @@ -718,7 +718,6 @@ void server::fire(const std::string& hook, const std::string& addon) } #if defined(_WIN32) - UNUSED(addon); ERR_CS << "Tried to execute a script on an unsupported platform\n"; return; #else diff --git a/src/tests/test_config.cpp b/src/tests/test_config.cpp index f822a4d2f963..aa0a888ab238 100644 --- a/src/tests/test_config.cpp +++ b/src/tests/test_config.cpp @@ -256,24 +256,18 @@ BOOST_AUTO_TEST_CASE(test_variable_info) BOOST_CHECK_EQUAL(variable_access_const("tag1[1].tag2.length", nonempty).as_scalar(), 3); BOOST_CHECK_EQUAL(variable_access_const("tag1[1].tag2[2].atribute1", nonempty).as_scalar().to_int(), 88); int count = 0; - for(const config& child : variable_access_const("tag1", nonempty).as_array()) { - // silences unused variable warning. - UNUSED(child); + for([[maybe_unused]] const config& child : variable_access_const("tag1", nonempty).as_array()) { ++count; } BOOST_CHECK_EQUAL(count, 3); count = 0; - for(const config& child : variable_access_const("tag1.tag2", nonempty).as_array()) { - // silences unused variable warning. - UNUSED(child); + for([[maybe_unused]] const config& child : variable_access_const("tag1.tag2", nonempty).as_array()) { ++count; } BOOST_CHECK_EQUAL(count, 0); count = 0; // explicit indexes as range always return a one element range, whether they exist or not. - for(const config& child : variable_access_const("tag1.tag2[5]", nonempty).as_array()) { - // silences unused variable warning. - UNUSED(child); + for([[maybe_unused]] const config& child : variable_access_const("tag1.tag2[5]", nonempty).as_array()) { ++count; } BOOST_CHECK_EQUAL(count, 1);