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

            Bug ID: 98450
           Summary: Inconsistent Wunused-variable warning for std::array
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: maic23 at live dot de
  Target Milestone: ---

When using std::array in C++17 mode, -Wunused-variable behaves inconsistent:


$ cat /tmp/a.cpp 
#include <array>
static constexpr std::array         bay{9};
static constexpr std::array<int, 1> bax{9};

$ gcc -std=c++17 -Wall -S /tmp/a.cpp 
/tmp/a.cpp:2:37: warning: ‘bay’ defined but not used [-Wunused-variable]
    2 | static constexpr std::array         bay{9};
      |                                     ^~~


Now, if the two lines are switched, there is no warning:

$ cat /tmp/b.cpp 
#include <array>
static constexpr std::array<int, 1> bax{9};
static constexpr std::array         bay{9};

$ gcc -std=c++17 -Wall -S /tmp/b.cpp 
(no warning)

It makes it really hard to debug and fix this warning when it occurs only
sporadically.

The warning should probably not appear at all, because static const(expr)
variables are put in header files, but not used everywhere where the header
file is included in a cpp file.

Reply via email to