https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876
Bug ID: 109876 Summary: initializer_list not usable in constant expressions in a template Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: barry.revzin at gmail dot com Target Milestone: --- Consider this example: #include <initializer_list> template <int S> struct Array { }; #ifdef USE_TEMPLATE template <int N> #endif struct Foo { static constexpr std::initializer_list<int> num = { 1, 2 }; Array<num.size()> ctx; }; #ifdef USE_TEMPLATE void f(Foo<5>) { } #else void f(Foo) { } #endif In all recent versions of gcc, compiling with -DUSE_TEMPLATE fails with an error like: <source>:15:17: in 'constexpr' expansion of 'Foo<N>::num.std::initializer_list<int>::size()' <source>:15:19: error: the value of 'Foo<N>::num' is not usable in a constant expression 15 | Array<num.size()> ctx; | ^ This used to work in gcc 7 and gcc 8 (except 8.1), and I don't think there's anything about Foo being a template that should prevent this from working. The non-template case works on all gcc versions I've tried.