https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87292
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2018-09-13 Ever confirmed|0 |1 --- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Nuno Gonçalves from comment #4) > I found that the issue with enum have been extensively debated at #61414. > Sorry. Yes, we already have Bug 61414 for that. > So actually this bug report is only regarding the warning with initializer > list: > > struct{ > uint8_t c1:6; > uint8_t c2:6; > } a; > auto c = {a.c1, a.c2}; //warning: narrowing conversion of '(unsigned > char)c1' from 'unsigned char' to 'unsigned char:6' [-Wnarrowing] Confirmed. The initializers should be promoted before deciding the type of the std::initializer_list. This should compile: #include <initializer_list> struct { int c1 : 6; int c2 : 6; } a; auto c = { a.c1, a.c2 }; std::initializer_list<int>& r = c; n.cc:7:14: warning: narrowing conversion of '(int)a.<unnamed struct>::c1' from 'int' to 'signed char:6' [-Wnarrowing] 7 | auto c = { a.c1, a.c2 }; | ~~^~ n.cc:7:14: warning: narrowing conversion of 'a.<unnamed struct>::c1' from 'int' to 'signed char:6' [-Wnarrowing] n.cc:7:20: warning: narrowing conversion of '(int)a.<unnamed struct>::c2' from 'int' to 'signed char:6' [-Wnarrowing] 7 | auto c = { a.c1, a.c2 }; | ~~^~ n.cc:7:20: warning: narrowing conversion of 'a.<unnamed struct>::c2' from 'int' to 'signed char:6' [-Wnarrowing] n.cc:8:33: error: invalid initialization of reference of type 'std::initializer_list<int>&' from expression of type 'std::initializer_list<signed char:6>' 8 | std::initializer_list<int>& r = c; |