public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106384] New: -Wunused-variable is triggered for static const type-deduced initializer lists
@ 2022-07-21 15:00 martingalvan at sourceware dot org
  0 siblings, 0 replies; only message in thread
From: martingalvan at sourceware dot org @ 2022-07-21 15:00 UTC (permalink / raw)
  To: gcc-bugs

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++.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-21 15:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-21 15:00 [Bug c++/106384] New: -Wunused-variable is triggered for static const type-deduced initializer lists martingalvan at sourceware dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).