From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 549603858D29; Mon, 17 Jun 2024 12:13:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 549603858D29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1718626399; bh=sP8Wy6P25g0YLRZMHMCfxqILUX5doAqT2faExeEvxCE=; h=From:To:Subject:Date:From; b=eg1WlaABJkPsjCvzNvolFXChmMy2gsRO+O2PMJnkQOhv3aM6fGAWZetXKLJnA+SAk cmrLmg0NfAr6nM3AmmKKWy0T09RG5TjOiXQ70ypuafJoBj0R11nUSfIXrRNKK6mIUU DW4P69qO9xMIE8KuwOyCYEHp8tmivjlVgvNvEQqw= From: "daniel.klauer at gin dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/115522] New: std::to_array no longer works for struct which is trivial but not default constructible Date: Mon, 17 Jun 2024 12:13:18 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: daniel.klauer at gin dot de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D115522 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 #include struct range { const int min, max; }; static_assert(std::is_trivial_v); static_assert(!std::is_default_constructible_v); static_assert(std::is_copy_constructible_v); auto my_array =3D std::to_array({{0, 0}}); Output from g++ 13.3.0 on x86_64-pc-linux-gnu, built with "--enable-languages=3Dc,c++ --prefix=3D/opt/gcc-13.3": $ /opt/gcc-13.3/bin/g++ -std=3Dc++20 e.cxx -c In file included from e.cxx:1: /opt/gcc-13.3/include/c++/13.3.0/array: In instantiation of =E2=80=98conste= xpr std::array >::type, _Nm> std::to_array(_Tp (&&)[_Nm]) [with _Tp =3D range; long unsigned int _Nm =3D= 1; typename remove_cv< >::type =3D range]=E2=80=99: e.cxx:9:37: required from here /opt/gcc-13.3/include/c++/13.3.0/array:460:44: error: use of deleted functi= on =E2=80=98std::array::array()=E2=80=99 460 | array, _Nm> __arr; | ^~~~~ /opt/gcc-13.3/include/c++/13.3.0/array:94:12: note: =E2=80=98std::array::array()=E2=80=99 is implicitly deleted because the default definition w= ould be ill-formed: 94 | struct array | ^~~~~ /opt/gcc-13.3/include/c++/13.3.0/array:94:12: error: use of deleted function =E2=80=98range::range()=E2=80=99 e.cxx:3:8: note: =E2=80=98range::range()=E2=80=99 is implicitly deleted bec= ause the default definition would be ill-formed: 3 | struct range { | ^~~~~ e.cxx:3:8: error: uninitialized const member in =E2=80=98struct range=E2=80= =99 e.cxx:4:15: note: =E2=80=98const int range::min=E2=80=99 should be initiali= zed 4 | const int min, max; | ^~~ e.cxx:3:8: error: uninitialized const member in =E2=80=98struct range=E2=80= =99 3 | struct range { | ^~~~~ e.cxx:4:20: note: =E2=80=98const int range::max=E2=80=99 should be initiali= zed 4 | const int min, max; | ^~~ /opt/gcc-13.3/include/c++/13.3.0/array:465:39: error: use of deleted functi= on =E2=80=98range& range::operator=3D(const range&)=E2=80=99 465 | __arr._M_elems[__i] =3D __a[__i]; | ~~~~~~~~~~~~~~~~~~~~^~~~~~ e.cxx:3:8: note: =E2=80=98range& range::operator=3D(const range&)=E2=80=99 = is implicitly deleted because the default definition would be ill-formed: 3 | struct range { | ^~~~~ e.cxx:3:8: error: non-static const member =E2=80=98const int range::min=E2= =80=99, cannot use default assignment operator e.cxx:3:8: error: non-static const member =E2=80=98const int range::max=E2= =80=99, cannot use default assignment operator It's not clear to me whether it should work in the first place, though it w= as my understanding that std::to_array does not necessarily require a default constructor, since it is closer to a move/copy operation.=