https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106384

            Bug ID: 106384
           Summary: -Wunused-variable is triggered for static const
                    type-deduced initializer lists
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: martingalvan at sourceware dot org
  Target Milestone: ---

It looks like -Wunused-variable is being triggered for global initializer
lists, even though they're declared as static const. This only seems to happen
if the list is declared using auto; if we explicitly write
std::initializer_list, the warning goes away.

For example, the following code triggers the warning:

#include <initializer_list>

static const auto list = {4, 2};

int main()
{
    return 0;
}

whereas the following works fine:

#include <initializer_list>

static const std::initializer_list list = {4, 2};

int main()
{
    return 0;
}

See also https://godbolt.org/z/evazo9zeM

IMHO auto shouldn't make any difference here; the warning shouldn't be
triggered as it doesn't imply -Wunused-const-variable for C++.

Reply via email to