[Bug c++/111512] GCC's __builtin_memcpy can trigger ADL

2023-09-27 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111512

--- Comment #6 from CVS Commits  ---
The releases/gcc-11 branch has been updated by Jonathan Wakely
:

https://gcc.gnu.org/g:97a33ab114187e7c6cd6c6c0f06cd8225e8aeef5

commit r11-11021-g97a33ab114187e7c6cd6c6c0f06cd8225e8aeef5
Author: Jonathan Wakely 
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)

[Bug c++/111512] GCC's __builtin_memcpy can trigger ADL

2023-09-26 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111512

--- Comment #5 from CVS Commits  ---
The releases/gcc-12 branch has been updated by Jonathan Wakely
:

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

commit r12-9894-g685a8c45d8e2c8c10171e672888484ea2c50662e
Author: Jonathan Wakely 
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)

[Bug c++/111512] GCC's __builtin_memcpy can trigger ADL

2023-09-26 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111512

--- Comment #4 from CVS Commits  ---
The releases/gcc-13 branch has been updated by Jonathan Wakely
:

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

commit r13-7844-g161a477f0ce93de1d083d379247d0770d4ef96af
Author: Jonathan Wakely 
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)

[Bug c++/111512] GCC's __builtin_memcpy can trigger ADL

2023-09-25 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111512

--- Comment #3 from Jonathan Wakely  ---
The library has a workaround, but the front end still does unwanted ADL for
__builtin_memcpy (and probably other built-ins).

[Bug c++/111512] GCC's __builtin_memcpy can trigger ADL

2023-09-25 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111512

--- Comment #2 from CVS Commits  ---
The master branch has been updated by Jonathan Wakely :

https://gcc.gnu.org/g:77cf3773021b0a20d89623e09d620747a05588ec

commit r14-4252-g77cf3773021b0a20d89623e09d620747a05588ec
Author: Jonathan Wakely 
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.

[Bug c++/111512] GCC's __builtin_memcpy can trigger ADL

2023-09-21 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111512

Jonathan Wakely  changed:

   What|Removed |Added

   Last reconfirmed||2023-09-21
 Status|UNCONFIRMED |NEW
 Ever confirmed|0   |1

--- Comment #1 from Jonathan Wakely  ---
Yes, that seems undesirable.

Reduced:

template
void to_array(T& from)
{
  T to;
  __builtin_memcpy(, , sizeof(T));
}

struct incomplete;

template
struct holder {
T t;
};

using validator = holder*;

int main()
{
validator a[1]{};
::to_array(a);
}

Casting the arguments to void avoids the problem:

  __builtin_memcpy((void*), (void*), sizeof(T));