jeudi 28 septembre 2017

How to handle unused warnings caused by empty template parameter pack expansions?

An issue I keep facing is one where the compiler complains about an unused variable, even though the variable is used, but it's only used inside a parameter pack expansion that happens to be empty for a specific instantiation. For example:

template <std::size_t... I>
auto func1(std::index_sequence<I...>)
{
  auto var = get_tuple();
  return func2(std::get<I>(var)...);
}

auto a = func1(std::make_index_sequence<0>());

See live example (try changing the tuple at line 4, by adding an int inside <> to see the warning go away). I know I could add a (void)var; line to make the warning go away, but it feels dirty to me, especially when the function is actually just a single line. I also don't want to disable this warning globally, because it does provide insight sometimes. I've encountered this issue for local function variables and also for lambda capture (-Wunused-lambda-capture).

Aucun commentaire:

Enregistrer un commentaire