Why is clang++ warning "suggest braces around initialization of subobject [-Wmissing-braces]"?
I have this code:
#include <array>
int main(int, char **argv)
{
std::array<int, 3> a = {1,2,3};
}
This compiles fine (-std=c++11) , but if you include -Wall it gives this warning that I don't understand:
clang_pp_error.cpp:5:28: warning: suggest braces around initialization of subobject [-Wmissing-braces]
std::array<int, 3> a = {1,2,3};
^~~~~
{ }
Solution 1:
This should be a bug: https://llvm.org/bugs/show_bug.cgi?id=21629.
See also Is it wise to ignore gcc/clang's "-Wmissing-braces" warning?.
Solution 2:
Use std::array<int, 3> a = {{1,2,3}};
instead.
See Why wasn't a double curly braces syntax preferred for constructors taking a std::initializer_list