Skip to content

Commit

Permalink
Replaced UNUSED with [[maybe_unused]] where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Jan 23, 2021
1 parent b713de3 commit a04f6d2
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 26 deletions.
4 changes: 1 addition & 3 deletions src/commandline_argv.cpp
Expand Up @@ -76,11 +76,9 @@ std::vector<std::string> win32_read_argv(const std::string& input)

#endif

std::vector<std::string> read_argv(int argc, char** argv)
std::vector<std::string> 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.
Expand Down
3 changes: 1 addition & 2 deletions src/desktop/open.cpp
Expand Up @@ -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';

Expand Down Expand Up @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions src/filesystem.cpp
Expand Up @@ -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()) {
Expand Down
9 changes: 3 additions & 6 deletions src/gui/dialogs/lua_interpreter.cpp
Expand Up @@ -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
Expand All @@ -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";

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<char[]> cmd_cstr(new char[cmd.length()+1]);
Expand All @@ -349,7 +347,6 @@ class lua_interpreter::input_model {
cmd = expansion;
free(expansion);
#endif
UNUSED(cmd);
return false;
}
};
Expand Down
1 change: 0 additions & 1 deletion src/scripting/game_lua_kernel.cpp
Expand Up @@ -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<end_level_data*>(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;
}
Expand Down
3 changes: 1 addition & 2 deletions src/server/campaignd/server.cpp
Expand Up @@ -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<std::string, std::string>::const_iterator itor = hooks_.find(hook);
if(itor == hooks_.end()) {
Expand All @@ -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
Expand Down
12 changes: 3 additions & 9 deletions src/tests/test_config.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit a04f6d2

Please sign in to comment.