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

            Bug ID: 95330
           Summary: Unneeded -Wmissing-braces warning when initialising
                    std::array
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: szotsaki at gmail dot com
  Target Milestone: ---

Example code:

#include <array>
int main() {
    const volatile std::array<int, 3> a = {1, 2, 3};
    return 0;
}

Compile with "-std=c++17 -Wmissing-braces" and the following warning is shown:

t.cpp: In function ‘int main()’:
t.cpp:3:48: warning: missing braces around initializer for
‘std::__array_traits<int, 3>::_Type’ {aka ‘int [3]’} [-Wmissing-braces]
    3 |  const volatile std::array<int, 3> a = {1, 2, 3};
      |                                                ^

The same message occurs when you initialise in either way:
  * std::array<int, 3> a = {1, 2, 3};
  * std::array<int, 3> a{1, 2, 3};

According to cppreference.com [1] it's not necessary to use the second level of
braces since CWG 1270 [2] from C++11 on.

clang does not warn for the same line of code.

[1]: https://en.cppreference.com/w/cpp/container/array 
[2]: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1270

Reply via email to