https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88012
Bug ID: 88012 Summary: Expected -Wnarrowing not given inside template class method Product: gcc Version: 8.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: vz-gcc at zeitlins dot org Target Milestone: --- Host: x86_64-linux-gnu Target: x86_64-linux-gnu Using Debian 8.2.0-9 the following code compiles without any errors or warnings: % cat -n narrowing.cpp 1 using Number = unsigned int; 2 3 template <int> 4 struct S { 5 S() { 6 const Number x = {-1}; (void)x; 7 } 8 }; 9 10 int main() { 11 S<1> s; 12 // const Number y = {-1}; (void)y; 13 } % g++-8 -Wall -c narrowing.cpp % # i.e. no diagnostic output Uncommenting the line 12 results in the expected error: % g++-8 -Wall -c narrowing.cpp narrowing.cpp: In function ‘int main()’: narrowing.cpp:12:25: error: narrowing conversion of ‘-1’ from ‘int’ to ‘Number’ {aka ‘unsigned int’} inside { } [-Wnarrowing] const Number y = {-1}; (void)y; ^ AFAICS the same error should be given for the same code inside S ctor but somehow the narrowing conversion is not detected there. Sorry in advance if I'm missing something, but I couldn't find any reason for this code to be accepted, so reporting it here because it looks like a bug to me. FWIW both clang 7 and MSVS 15.7 do report the expected error (and the former even does it twice for some reason...).