public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/115522] New: std::to_array no longer works for struct which is trivial but not default constructible
@ 2024-06-17 12:13 daniel.klauer at gin dot de
  2024-06-17 15:11 ` [Bug libstdc++/115522] [13/14/15 Regression] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: daniel.klauer at gin dot de @ 2024-06-17 12:13 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-06-21  9:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-17 12:13 [Bug libstdc++/115522] New: std::to_array no longer works for struct which is trivial but not default constructible daniel.klauer at gin dot de
2024-06-17 15:11 ` [Bug libstdc++/115522] [13/14/15 Regression] " pinskia at gcc dot gnu.org
2024-06-17 15:15 ` pinskia at gcc dot gnu.org
2024-06-17 16:17 ` redi at gcc dot gnu.org
2024-06-17 19:03 ` redi at gcc dot gnu.org
2024-06-18 12:14 ` redi at gcc dot gnu.org
2024-06-18 12:47 ` redi at gcc dot gnu.org
2024-06-19 16:39 ` redi at gcc dot gnu.org
2024-06-20  2:31 ` de34 at live dot cn
2024-06-21  9:15 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).