https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115522
Bug ID: 115522 Summary: std::to_array no longer works for struct which is trivial but not default constructible Product: gcc Version: 13.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: daniel.klauer at gin dot de Target Milestone: --- Hi, The following example used to compile successfully with gcc 13.2 or older, but it no longer compiles in gcc 13.3 and 14.1: #include <array> #include <type_traits> struct range { const int min, max; }; static_assert(std::is_trivial_v<range>); static_assert(!std::is_default_constructible_v<range>); static_assert(std::is_copy_constructible_v<range>); auto my_array = std::to_array<range>({{0, 0}}); Output from g++ 13.3.0 on x86_64-pc-linux-gnu, built with "--enable-languages=c,c++ --prefix=/opt/gcc-13.3": $ /opt/gcc-13.3/bin/g++ -std=c++20 e.cxx -c In file included from e.cxx:1: /opt/gcc-13.3/include/c++/13.3.0/array: In instantiation of ‘constexpr std::array<typename std::remove_cv< <template-parameter-1-1> >::type, _Nm> std::to_array(_Tp (&&)[_Nm]) [with _Tp = range; long unsigned int _Nm = 1; typename remove_cv< <template-parameter-1-1> >::type = range]’: e.cxx:9:37: required from here /opt/gcc-13.3/include/c++/13.3.0/array:460:44: error: use of deleted function ‘std::array<range, 1>::array()’ 460 | array<remove_cv_t<_Tp>, _Nm> __arr; | ^~~~~ /opt/gcc-13.3/include/c++/13.3.0/array:94:12: note: ‘std::array<range, 1>::array()’ is implicitly deleted because the default definition would be ill-formed: 94 | struct array | ^~~~~ /opt/gcc-13.3/include/c++/13.3.0/array:94:12: error: use of deleted function ‘range::range()’ e.cxx:3:8: note: ‘range::range()’ is implicitly deleted because the default definition would be ill-formed: 3 | struct range { | ^~~~~ e.cxx:3:8: error: uninitialized const member in ‘struct range’ e.cxx:4:15: note: ‘const int range::min’ should be initialized 4 | const int min, max; | ^~~ e.cxx:3:8: error: uninitialized const member in ‘struct range’ 3 | struct range { | ^~~~~ e.cxx:4:20: note: ‘const int range::max’ should be initialized 4 | const int min, max; | ^~~ /opt/gcc-13.3/include/c++/13.3.0/array:465:39: error: use of deleted function ‘range& range::operator=(const range&)’ 465 | __arr._M_elems[__i] = __a[__i]; | ~~~~~~~~~~~~~~~~~~~~^~~~~~ e.cxx:3:8: note: ‘range& range::operator=(const range&)’ is implicitly deleted because the default definition would be ill-formed: 3 | struct range { | ^~~~~ e.cxx:3:8: error: non-static const member ‘const int range::min’, cannot use default assignment operator e.cxx:3:8: error: non-static const member ‘const int range::max’, cannot use default assignment operator It's not clear to me whether it should work in the first place, though it was my understanding that std::to_array does not necessarily require a default constructor, since it is closer to a move/copy operation.