public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/111511] New: Incorrect ADL in std::to_array in GCC 11/12/13
@ 2023-09-21  6:17 de34 at live dot cn
  2023-09-21  8:03 ` [Bug libstdc++/111511] " redi at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: de34 at live dot cn @ 2023-09-21  6:17 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111511
           Summary: Incorrect ADL in std::to_array in GCC 11/12/13
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: de34 at live dot cn
  Target Milestone: ---

The following program is incorrectly rejected when using libstdc++
(https://godbolt.org/z/x6K6r5svM).

```
#include <array>
#include <utility>

struct incomplete;

template<class T>
struct holder {
    T t;
};

using validator = holder<incomplete>*;

int main()
{
    validator a[1]{};
    (void) std::to_array(a);
    (void) std::to_array(std::move(a));
}
```

The error is caused by aunqualified calls to the `__to_array` internal
function, which triggers ADL for `incomplete` and requires it to be complete.

Not sure whether this should be WONTFIX since the implementation is
fundamentally changed in GCC 14 (PR 110167).

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

* [Bug libstdc++/111511] Incorrect ADL in std::to_array in GCC 11/12/13
  2023-09-21  6:17 [Bug libstdc++/111511] New: Incorrect ADL in std::to_array in GCC 11/12/13 de34 at live dot cn
@ 2023-09-21  8:03 ` redi at gcc dot gnu.org
  2023-09-21 10:33 ` m.cencora at gmail dot com
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2023-09-21  8:03 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2023-09-21
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jiang An from comment #0)
> Not sure whether this should be WONTFIX since the implementation is
> fundamentally changed in GCC 14 (PR 110167).

There's no reason we can't fix the old version in the release branches.

I did notice this when rewriting it, but I didn't think to change the branches
to avoid ADL there, because I plan to backport the new implementation
eventually anyway.

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

* [Bug libstdc++/111511] Incorrect ADL in std::to_array in GCC 11/12/13
  2023-09-21  6:17 [Bug libstdc++/111511] New: Incorrect ADL in std::to_array in GCC 11/12/13 de34 at live dot cn
  2023-09-21  8:03 ` [Bug libstdc++/111511] " redi at gcc dot gnu.org
@ 2023-09-21 10:33 ` m.cencora at gmail dot com
  2023-09-21 10:42 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: m.cencora at gmail dot com @ 2023-09-21 10:33 UTC (permalink / raw)
  To: gcc-bugs

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

m.cencora at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |m.cencora at gmail dot com

--- Comment #2 from m.cencora at gmail dot com ---
(In reply to Jonathan Wakely from comment #1)
> (In reply to Jiang An from comment #0)
> > Not sure whether this should be WONTFIX since the implementation is
> > fundamentally changed in GCC 14 (PR 110167).
> 
> There's no reason we can't fix the old version in the release branches.
> 
> I did notice this when rewriting it, but I didn't think to change the
> branches to avoid ADL there, because I plan to backport the new
> implementation eventually anyway.

On a semi-related topic:
Can't we use __builtin_bit_cast as even simpler implementation of to_array for
trivial types?

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

* [Bug libstdc++/111511] Incorrect ADL in std::to_array in GCC 11/12/13
  2023-09-21  6:17 [Bug libstdc++/111511] New: Incorrect ADL in std::to_array in GCC 11/12/13 de34 at live dot cn
  2023-09-21  8:03 ` [Bug libstdc++/111511] " redi at gcc dot gnu.org
  2023-09-21 10:33 ` m.cencora at gmail dot com
@ 2023-09-21 10:42 ` redi at gcc dot gnu.org
  2023-09-21 10:45 ` m.cencora at gmail dot com
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2023-09-21 10:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Until all supported compilers implement it, that won't be simpler. We'll still
need the memcpy version as a fallback.

And it probably generated exactly the same code, although I haven't checked.

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

* [Bug libstdc++/111511] Incorrect ADL in std::to_array in GCC 11/12/13
  2023-09-21  6:17 [Bug libstdc++/111511] New: Incorrect ADL in std::to_array in GCC 11/12/13 de34 at live dot cn
                   ` (2 preceding siblings ...)
  2023-09-21 10:42 ` redi at gcc dot gnu.org
@ 2023-09-21 10:45 ` m.cencora at gmail dot com
  2023-09-21 11:37 ` de34 at live dot cn
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: m.cencora at gmail dot com @ 2023-09-21 10:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from m.cencora at gmail dot com ---
Ack

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

* [Bug libstdc++/111511] Incorrect ADL in std::to_array in GCC 11/12/13
  2023-09-21  6:17 [Bug libstdc++/111511] New: Incorrect ADL in std::to_array in GCC 11/12/13 de34 at live dot cn
                   ` (3 preceding siblings ...)
  2023-09-21 10:45 ` m.cencora at gmail dot com
@ 2023-09-21 11:37 ` de34 at live dot cn
  2023-09-25  8:53 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: de34 at live dot cn @ 2023-09-21 11:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jiang An <de34 at live dot cn> ---
(In reply to m.cencora from comment #2)
> (In reply to Jonathan Wakely from comment #1)
> > (In reply to Jiang An from comment #0)
> > > Not sure whether this should be WONTFIX since the implementation is
> > > fundamentally changed in GCC 14 (PR 110167).
> > 
> > There's no reason we can't fix the old version in the release branches.
> > 
> > I did notice this when rewriting it, but I didn't think to change the
> > branches to avoid ADL there, because I plan to backport the new
> > implementation eventually anyway.
> 
> On a semi-related topic:
> Can't we use __builtin_bit_cast as even simpler implementation of to_array
> for trivial types?

__builtin_bit_cast results in constant evaluation failure when the element type
is or contains a pointer or a union, which heavily restricts its usability in
to_array.

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

* [Bug libstdc++/111511] Incorrect ADL in std::to_array in GCC 11/12/13
  2023-09-21  6:17 [Bug libstdc++/111511] New: Incorrect ADL in std::to_array in GCC 11/12/13 de34 at live dot cn
                   ` (4 preceding siblings ...)
  2023-09-21 11:37 ` de34 at live dot cn
@ 2023-09-25  8:53 ` cvs-commit at gcc dot gnu.org
  2023-09-26 20:15 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-25  8:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 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:77cf3773021b0a20d89623e09d620747a05588ec

commit r14-4252-g77cf3773021b0a20d89623e09d620747a05588ec
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Sep 21 09:14:57 2023 +0100

    libstdc++: Prevent unwanted ADL in std::to_array [PR111512]

    As noted in PR c++/111512, GCC does ADL for __builtin_memcpy if it is
    unqualified, which can cause errors for template argument types which
    cannot be completed.

    Casting the memcpy arguments to void* prevents ADL from considering the
    problem type.

    libstdc++-v3/ChangeLog:

            PR libstdc++/111511
            PR c++/111512
            * include/std/array (to_array): Cast memcpy arguments to void*.
            * testsuite/23_containers/array/creation/111512.cc: New test.

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

* [Bug libstdc++/111511] Incorrect ADL in std::to_array in GCC 11/12/13
  2023-09-21  6:17 [Bug libstdc++/111511] New: Incorrect ADL in std::to_array in GCC 11/12/13 de34 at live dot cn
                   ` (5 preceding siblings ...)
  2023-09-25  8:53 ` cvs-commit at gcc dot gnu.org
@ 2023-09-26 20:15 ` cvs-commit at gcc dot gnu.org
  2023-09-26 22:55 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-26 20:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:161a477f0ce93de1d083d379247d0770d4ef96af

commit r13-7844-g161a477f0ce93de1d083d379247d0770d4ef96af
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Sep 21 09:14:57 2023 +0100

    libstdc++: Prevent unwanted ADL in std::to_array [PR111512]

    Qualify the calls to the __to_array helper to prevent ADL, so we don't
    try to complete associated classes.

    libstdc++-v3/ChangeLog:

            PR libstdc++/111511
            PR c++/111512
            * include/std/array (to_array): Qualify calls to __to_array.
            * testsuite/23_containers/array/creation/111512.cc: New test.

    (cherry picked from commit 77cf3773021b0a20d89623e09d620747a05588ec)

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

* [Bug libstdc++/111511] Incorrect ADL in std::to_array in GCC 11/12/13
  2023-09-21  6:17 [Bug libstdc++/111511] New: Incorrect ADL in std::to_array in GCC 11/12/13 de34 at live dot cn
                   ` (6 preceding siblings ...)
  2023-09-26 20:15 ` cvs-commit at gcc dot gnu.org
@ 2023-09-26 22:55 ` cvs-commit at gcc dot gnu.org
  2023-09-27 16:21 ` cvs-commit at gcc dot gnu.org
  2023-09-27 16:23 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-26 22:55 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:685a8c45d8e2c8c10171e672888484ea2c50662e

commit r12-9894-g685a8c45d8e2c8c10171e672888484ea2c50662e
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Sep 21 09:14:57 2023 +0100

    libstdc++: Prevent unwanted ADL in std::to_array [PR111512]

    Qualify the calls to the __to_array helper to prevent ADL, so we don't
    try to complete associated classes.

    libstdc++-v3/ChangeLog:

            PR libstdc++/111511
            PR c++/111512
            * include/std/array (to_array): Qualify calls to __to_array.
            * testsuite/23_containers/array/creation/111512.cc: New test.

    (cherry picked from commit 77cf3773021b0a20d89623e09d620747a05588ec)

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

* [Bug libstdc++/111511] Incorrect ADL in std::to_array in GCC 11/12/13
  2023-09-21  6:17 [Bug libstdc++/111511] New: Incorrect ADL in std::to_array in GCC 11/12/13 de34 at live dot cn
                   ` (7 preceding siblings ...)
  2023-09-26 22:55 ` cvs-commit at gcc dot gnu.org
@ 2023-09-27 16:21 ` cvs-commit at gcc dot gnu.org
  2023-09-27 16:23 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-27 16:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 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:97a33ab114187e7c6cd6c6c0f06cd8225e8aeef5

commit r11-11021-g97a33ab114187e7c6cd6c6c0f06cd8225e8aeef5
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Sep 21 09:14:57 2023 +0100

    libstdc++: Prevent unwanted ADL in std::to_array [PR111512]

    Qualify the calls to the __to_array helper to prevent ADL, so we don't
    try to complete associated classes.

    libstdc++-v3/ChangeLog:

            PR libstdc++/111511
            PR c++/111512
            * include/std/array (to_array): Qualify calls to __to_array.
            * testsuite/23_containers/array/creation/111512.cc: New test.

    (cherry picked from commit 77cf3773021b0a20d89623e09d620747a05588ec)

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

* [Bug libstdc++/111511] Incorrect ADL in std::to_array in GCC 11/12/13
  2023-09-21  6:17 [Bug libstdc++/111511] New: Incorrect ADL in std::to_array in GCC 11/12/13 de34 at live dot cn
                   ` (8 preceding siblings ...)
  2023-09-27 16:21 ` cvs-commit at gcc dot gnu.org
@ 2023-09-27 16:23 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2023-09-27 16:23 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
std::to_array is fixed on all branches, thanks for the reports.

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

end of thread, other threads:[~2023-09-27 16:23 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-21  6:17 [Bug libstdc++/111511] New: Incorrect ADL in std::to_array in GCC 11/12/13 de34 at live dot cn
2023-09-21  8:03 ` [Bug libstdc++/111511] " redi at gcc dot gnu.org
2023-09-21 10:33 ` m.cencora at gmail dot com
2023-09-21 10:42 ` redi at gcc dot gnu.org
2023-09-21 10:45 ` m.cencora at gmail dot com
2023-09-21 11:37 ` de34 at live dot cn
2023-09-25  8:53 ` cvs-commit at gcc dot gnu.org
2023-09-26 20:15 ` cvs-commit at gcc dot gnu.org
2023-09-26 22:55 ` cvs-commit at gcc dot gnu.org
2023-09-27 16:21 ` cvs-commit at gcc dot gnu.org
2023-09-27 16:23 ` 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).