public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/101960] New: std::tuple with an array element is rejected as a named return type
@ 2021-08-18 14:01 wjwray at gmail dot com
  2021-08-18 14:26 ` [Bug libstdc++/101960] " redi at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: wjwray at gmail dot com @ 2021-08-18 14:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101960

            Bug ID: 101960
           Summary: std::tuple with an array element is rejected as a
                    named return type
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wjwray at gmail dot com
  Target Milestone: ---

This fails to compile, going back many revisions, in any std version:
https://godbolt.org/z/Kz9Mnz9aW

    #include <tuple>

    std::tuple<int[1]> f() {
        std::tuple<int[1]> t;
        return t;
    }

GCC rejects with:    ​error: array used as initializer
Clang rejects with:  error: array initializer must be an initializer list

(The Compiler Explorer link shows it working in Clang+libc++ and MSVC.)

However, this works:

    std::tuple<int[1]> g() { return {}; }

and so does this (workaround: return by-reference, then copy):

    constexpr std::tuple<int[1]>& h(std::tuple<int[1]>&& t = {}) {
        return t;
    }
    constexpr auto t = h();

(The only way I find with libstdc++ to make a constexpr tuple<T[N]>)

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

* [Bug libstdc++/101960] std::tuple with an array element is rejected as a named return type
  2021-08-18 14:01 [Bug libstdc++/101960] New: std::tuple with an array element is rejected as a named return type wjwray at gmail dot com
@ 2021-08-18 14:26 ` redi at gcc dot gnu.org
  2021-08-18 14:28 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-18 14:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101960

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-08-18
           Keywords|                            |rejects-valid
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
--- a/libstdc++-v3/include/std/tuple
+++ b/libstdc++-v3/include/std/tuple
@@ -441,7 +441,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       constexpr
       _Tuple_impl(_Tuple_impl&& __in)
       noexcept(is_nothrow_move_constructible<_Head>::value)
-      : _Base(std::forward<_Head>(_M_head(__in)))
+      : _Base(std::forward<_Base>(__in))
       { }

       template<typename _UHead>

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

* [Bug libstdc++/101960] std::tuple with an array element is rejected as a named return type
  2021-08-18 14:01 [Bug libstdc++/101960] New: std::tuple with an array element is rejected as a named return type wjwray at gmail dot com
  2021-08-18 14:26 ` [Bug libstdc++/101960] " redi at gcc dot gnu.org
@ 2021-08-18 14:28 ` redi at gcc dot gnu.org
  2021-08-19 12:03 ` cvs-commit at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-18 14:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101960

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
N.B. simply defining it as defaulted would make it trivial for some
specializations, which might be an ABI break.

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

* [Bug libstdc++/101960] std::tuple with an array element is rejected as a named return type
  2021-08-18 14:01 [Bug libstdc++/101960] New: std::tuple with an array element is rejected as a named return type wjwray at gmail dot com
  2021-08-18 14:26 ` [Bug libstdc++/101960] " redi at gcc dot gnu.org
  2021-08-18 14:28 ` redi at gcc dot gnu.org
@ 2021-08-19 12:03 ` cvs-commit at gcc dot gnu.org
  2021-08-19 14:09 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-08-19 12:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101960

--- Comment #3 from CVS 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:0187e0d7360f327f88d8b2294668669306ae4630

commit r12-3022-g0187e0d7360f327f88d8b2294668669306ae4630
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Aug 19 11:48:40 2021 +0100

    libstdc++: Fix move construction of std::tuple with array elements
[PR101960]

    An array member cannot be direct-initialized in a ctor-initializer-list,
    so use the base class' move constructor, which does the right thing for
    both arrays and non-arrays.

    This constructor could be defaulted, but that would make it trivial for
    some specializations, which would change the argument passing ABI. Do
    that for the versioned namespace only.

    Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

    libstdc++-v3/ChangeLog:

            PR libstdc++/101960
            * include/std/tuple (_Tuple_impl(_Tuple_impl&&)): Use base
            class' move constructor. Define as defaulted for versioned
            namespace.
            * testsuite/20_util/tuple/cons/101960.cc: New test.

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

* [Bug libstdc++/101960] std::tuple with an array element is rejected as a named return type
  2021-08-18 14:01 [Bug libstdc++/101960] New: std::tuple with an array element is rejected as a named return type wjwray at gmail dot com
                   ` (2 preceding siblings ...)
  2021-08-19 12:03 ` cvs-commit at gcc dot gnu.org
@ 2021-08-19 14:09 ` redi at gcc dot gnu.org
  2021-09-03 17:02 ` hewillk at gmail dot com
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-19 14:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101960

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed on trunk, but I plan to backport it.

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

* [Bug libstdc++/101960] std::tuple with an array element is rejected as a named return type
  2021-08-18 14:01 [Bug libstdc++/101960] New: std::tuple with an array element is rejected as a named return type wjwray at gmail dot com
                   ` (3 preceding siblings ...)
  2021-08-19 14:09 ` redi at gcc dot gnu.org
@ 2021-09-03 17:02 ` hewillk at gmail dot com
  2021-10-12 10:59 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: hewillk at gmail dot com @ 2021-09-03 17:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101960

康桓瑋 <hewillk at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hewillk at gmail dot com

--- Comment #5 from 康桓瑋 <hewillk at gmail dot com> ---
(In reply to Jonathan Wakely from comment #4)
> Fixed on trunk, but I plan to backport it.

You neglected the recursive one.

#include <tuple>

std::tuple<int[1], int[2]> t;
auto t2 = std::move(t);

https://godbolt.org/z/b4jrs1fYb

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

* [Bug libstdc++/101960] std::tuple with an array element is rejected as a named return type
  2021-08-18 14:01 [Bug libstdc++/101960] New: std::tuple with an array element is rejected as a named return type wjwray at gmail dot com
                   ` (4 preceding siblings ...)
  2021-09-03 17:02 ` hewillk at gmail dot com
@ 2021-10-12 10:59 ` cvs-commit at gcc dot gnu.org
  2021-10-12 15:49 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-12 10:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101960

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:00967465fe8093661a4d42356821eeb04170e09d

commit r11-9116-g00967465fe8093661a4d42356821eeb04170e09d
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Aug 19 11:48:40 2021 +0100

    libstdc++: Fix move construction of std::tuple with array elements
[PR101960]

    An array member cannot be direct-initialized in a ctor-initializer-list,
    so use the base class' move constructor, which does the right thing for
    both arrays and non-arrays.

    This constructor could be defaulted, but that would make it trivial for
    some specializations, which would change the argument passing ABI. Do
    that for the versioned namespace only.

    Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

    libstdc++-v3/ChangeLog:

            PR libstdc++/101960
            * include/std/tuple (_Tuple_impl(_Tuple_impl&&)): Use base
            class' move constructor. Define as defaulted for versioned
            namespace.
            * testsuite/20_util/tuple/cons/101960.cc: New test.

    (cherry picked from commit 0187e0d7360f327f88d8b2294668669306ae4630)

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

* [Bug libstdc++/101960] std::tuple with an array element is rejected as a named return type
  2021-08-18 14:01 [Bug libstdc++/101960] New: std::tuple with an array element is rejected as a named return type wjwray at gmail dot com
                   ` (5 preceding siblings ...)
  2021-10-12 10:59 ` cvs-commit at gcc dot gnu.org
@ 2021-10-12 15:49 ` cvs-commit at gcc dot gnu.org
  2021-10-12 16:24 ` cvs-commit at gcc dot gnu.org
  2021-10-12 17:46 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-12 15:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101960

--- Comment #7 from CVS 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:7481021364e75ba583972e15ed421a53988368ea

commit r12-4356-g7481021364e75ba583972e15ed421a53988368ea
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Oct 12 15:09:50 2021 +0100

    libstdc++: Fix move construction of std::tuple with array elements
[PR101960]

    The r12-3022 commit only fixed the case where an array is the last
    element of the tuple. This fixes the other cases too. We can just define
    the move constructor as defaulted, which does the right thing. Changing
    the move constructor to be trivial would be an ABI break, but since the
    last base class still has a non-trivial move constructor, defining the
    derived ones as defaulted doesn't change anything.

    libstdc++-v3/ChangeLog:

            PR libstdc++/101960
            * include/std/tuple (_Tuple_impl(_Tuple_impl&&)): Define as
            defauled.
            * testsuite/20_util/tuple/cons/101960.cc: Check tuples with
            array elements before the last element.

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

* [Bug libstdc++/101960] std::tuple with an array element is rejected as a named return type
  2021-08-18 14:01 [Bug libstdc++/101960] New: std::tuple with an array element is rejected as a named return type wjwray at gmail dot com
                   ` (6 preceding siblings ...)
  2021-10-12 15:49 ` cvs-commit at gcc dot gnu.org
@ 2021-10-12 16:24 ` cvs-commit at gcc dot gnu.org
  2021-10-12 17:46 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-12 16:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101960

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:e748216c237cff2915390e9653de2db63b2161ac

commit r11-9121-ge748216c237cff2915390e9653de2db63b2161ac
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Oct 12 15:09:50 2021 +0100

    libstdc++: Fix move construction of std::tuple with array elements
[PR101960]

    The r12-3022 commit only fixed the case where an array is the last
    element of the tuple. This fixes the other cases too. We can just define
    the move constructor as defaulted, which does the right thing. Changing
    the move constructor to be trivial would be an ABI break, but since the
    last base class still has a non-trivial move constructor, defining the
    derived ones as defaulted doesn't change anything.

    libstdc++-v3/ChangeLog:

            PR libstdc++/101960
            * include/std/tuple (_Tuple_impl(_Tuple_impl&&)): Define as
            defauled.
            * testsuite/20_util/tuple/cons/101960.cc: Check tuples with
            array elements before the last element.

    (cherry picked from commit 7481021364e75ba583972e15ed421a53988368ea)

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

* [Bug libstdc++/101960] std::tuple with an array element is rejected as a named return type
  2021-08-18 14:01 [Bug libstdc++/101960] New: std::tuple with an array element is rejected as a named return type wjwray at gmail dot com
                   ` (7 preceding siblings ...)
  2021-10-12 16:24 ` cvs-commit at gcc dot gnu.org
@ 2021-10-12 17:46 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2021-10-12 17:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101960

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|---                         |11.3

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 11.3

Given that nobody noticed this before now, I don't think backporting it further
is necessary. Thanks for the report.

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

end of thread, other threads:[~2021-10-12 17:46 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-18 14:01 [Bug libstdc++/101960] New: std::tuple with an array element is rejected as a named return type wjwray at gmail dot com
2021-08-18 14:26 ` [Bug libstdc++/101960] " redi at gcc dot gnu.org
2021-08-18 14:28 ` redi at gcc dot gnu.org
2021-08-19 12:03 ` cvs-commit at gcc dot gnu.org
2021-08-19 14:09 ` redi at gcc dot gnu.org
2021-09-03 17:02 ` hewillk at gmail dot com
2021-10-12 10:59 ` cvs-commit at gcc dot gnu.org
2021-10-12 15:49 ` cvs-commit at gcc dot gnu.org
2021-10-12 16:24 ` cvs-commit at gcc dot gnu.org
2021-10-12 17:46 ` redi 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).