Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is clang++ warning "suggest braces around initialization of subobject [-Wmissing-braces]"?

Tags:

clang++

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};
                           ^~~~~
                           {    }
like image 363
Scooter Avatar asked Jul 22 '15 06:07

Scooter


2 Answers

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

like image 160
FrankHB Avatar answered Nov 07 '22 10:11

FrankHB


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

like image 27
Sohail Si Avatar answered Nov 07 '22 09:11

Sohail Si