* [Bug libstdc++/115522] [13/14/15 Regression] std::to_array no longer works for struct which is trivial but not default constructible
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 ` pinskia at gcc dot gnu.org
2024-06-17 15:15 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-17 15:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115522
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pinskia at gcc dot gnu.org
Summary|std::to_array no longer |[13/14/15 Regression]
|works for struct which is |std::to_array no longer
|trivial but not default |works for struct which is
|constructible |trivial but not default
| |constructible
Keywords| |rejects-valid
Status|UNCONFIRMED |NEW
Known to work| |12.3.0, 13.2.0
Ever confirmed|0 |1
Known to fail| |13.3.0, 14.1.0
Target Milestone|--- |13.4
Last reconfirmed| |2024-06-17
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libstdc++/115522] [13/14/15 Regression] std::to_array no longer works for struct which is trivial but not default constructible
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
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-17 15:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115522
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=110167
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Looks like the check (that was added in r13-8421-g4c6bb36e88d5c8 /
r14-1647-g960de5dd886572711ef86fa1e15e30d3810eccb9 ), constexpr
(is_trivial_v<_Tp>) should be added on to, something like:
constexpr (is_trivial_v<_Tp> && is_default_constructible_v<_Tp>)
Or maybe more, I am not 100% sure.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libstdc++/115522] [13/14/15 Regression] std::to_array no longer works for struct which is trivial but not default constructible
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
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2024-06-17 16:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115522
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
That shouldn't be needed, because a trivial class has to have a trivial default
constructor.
The problem is that we default-initialize the array, which requires the const
members to be initialized.
We also need to check for assignability, because trivial classes can have
deleted assignment operators (for some reason).
--- a/libstdc++-v3/include/std/array
+++ b/libstdc++-v3/include/std/array
@@ -434,7 +434,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static_assert(is_constructible_v<_Tp, _Tp&>);
if constexpr (is_constructible_v<_Tp, _Tp&>)
{
- if constexpr (is_trivial_v<_Tp>)
+ if constexpr (is_trivial_v<_Tp> && is_default_constructible_v<_Tp>
+ && is_copy_assignable_v<_Tp>)
{
array<remove_cv_t<_Tp>, _Nm> __arr;
if (!__is_constant_evaluated() && _Nm != 0)
@@ -463,7 +464,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static_assert(is_move_constructible_v<_Tp>);
if constexpr (is_move_constructible_v<_Tp>)
{
- if constexpr (is_trivial_v<_Tp>)
+ if constexpr (is_trivial_v<_Tp> && is_default_constructible_v<_Tp>
+ && is_move_assignable_v<_Tp>)
{
array<remove_cv_t<_Tp>, _Nm> __arr;
if (!__is_constant_evaluated() && _Nm != 0)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libstdc++/115522] [13/14/15 Regression] std::to_array no longer works for struct which is trivial but not default constructible
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
` (2 preceding siblings ...)
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
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2024-06-17 19:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115522
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #3)
> static_assert(is_constructible_v<_Tp, _Tp&>);
> if constexpr (is_constructible_v<_Tp, _Tp&>)
> {
> - if constexpr (is_trivial_v<_Tp>)
> + if constexpr (is_trivial_v<_Tp> && is_default_constructible_v<_Tp>
> + && is_copy_assignable_v<_Tp>)
For the testcase above, it would be sufficient to do:
if constexpr (is_trivial_v<_Tp> && is_copy_assignable_v<_Tp>)
The type with const members isn't assignable.
I'm not sure if this covers all cases. I think combined with is_trivial it
should do, but then I don't understand why the struct ranges type is trivial in
the first place.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libstdc++/115522] [13/14/15 Regression] std::to_array no longer works for struct which is trivial but not default constructible
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
` (3 preceding siblings ...)
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
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2024-06-18 12:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115522
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=85723
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Ah, it looks like is_trivial is just wrong for types with a deleted default
constructor, that's PR 85723
The std::to_array code _should_ work correctly for this case :-\
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libstdc++/115522] [13/14/15 Regression] std::to_array no longer works for struct which is trivial but not default constructible
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
` (4 preceding siblings ...)
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
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2024-06-18 12:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115522
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libstdc++/115522] [13/14/15 Regression] std::to_array no longer works for struct which is trivial but not default constructible
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
` (5 preceding siblings ...)
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
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2024-06-19 16:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115522
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
URL| |https://gcc.gnu.org/piperma
| |il/gcc-patches/2024-June/65
| |5146.html
Keywords| |patch
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Patch posted: https://gcc.gnu.org/pipermail/gcc-patches/2024-June/655146.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libstdc++/115522] [13/14/15 Regression] std::to_array no longer works for struct which is trivial but not default constructible
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
` (6 preceding siblings ...)
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
8 siblings, 0 replies; 10+ messages in thread
From: de34 at live dot cn @ 2024-06-20 2:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115522
Jiang An <de34 at live dot cn> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |de34 at live dot cn
--- Comment #7 from Jiang An <de34 at live dot cn> ---
(In reply to Jonathan Wakely from comment #5)
> Ah, it looks like is_trivial is just wrong for types with a deleted default
> constructor, that's PR 85723
>
> The std::to_array code _should_ work correctly for this case :-\
I guess we still need to check is_default_constructible_v even after
__is_trivial gets fixed because the default construct may be protected or
private...
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libstdc++/115522] [13/14/15 Regression] std::to_array no longer works for struct which is trivial but not default constructible
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
` (7 preceding siblings ...)
2024-06-20 2:31 ` de34 at live dot cn
@ 2024-06-21 9:15 ` cvs-commit at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-21 9:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115522
--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:510ce5eed69ee1bea9c2c696fe3b2301e16d1486
commit r15-1533-g510ce5eed69ee1bea9c2c696fe3b2301e16d1486
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Jun 18 13:27:02 2024 +0100
libstdc++: Fix std::to_array for trivial-ish types [PR115522]
Due to PR c++/85723 the std::is_trivial trait is true for types with a
deleted default constructor, so the use of std::is_trivial in
std::to_array is not sufficient to ensure the type can be trivially
default constructed then filled using memcpy.
I also forgot that a type with a deleted assignment operator can still
be trivial, so we also need to check that it's assignable because the
is_constant_evaluated() path can't use memcpy.
Replace the uses of std::is_trivial with std::is_trivially_copyable
(needed for memcpy), std::is_trivially_default_constructible (needed so
that the default construction is valid and does no work) and
std::is_copy_assignable (needed for the constant evaluation case).
libstdc++-v3/ChangeLog:
PR libstdc++/115522
* include/std/array (to_array): Workaround the fact that
std::is_trivial is not sufficient to check that a type is
trivially default constructible and assignable.
* testsuite/23_containers/array/creation/115522.cc: New test.
^ permalink raw reply [flat|nested] 10+ messages in thread