public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111512] New: GCC's __builtin_memcpy can trigger ADL
@ 2023-09-21 6:27 de34 at live dot cn
2023-09-21 8:11 ` [Bug c++/111512] " redi at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: de34 at live dot cn @ 2023-09-21 6:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111512
Bug ID: 111512
Summary: GCC's __builtin_memcpy can trigger ADL
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: rejects-valid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: de34 at live dot cn
Target Milestone: ---
When using libstdc++ in GCC 14, the following program compiles with Clang but
is rejected by GCC (https://godbolt.org/z/WKbe1c3v7).
```
#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 implementation can be made to work for GCC if `::` is added before the call
to __builtin_memcpy (https://godbolt.org/z/6Mx11T3f9).
So the reason for failure seems to be that GCC's __builtin_memcpy can trigger
ADL like a real function.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/111512] GCC's __builtin_memcpy can trigger ADL
2023-09-21 6:27 [Bug c++/111512] New: GCC's __builtin_memcpy can trigger ADL de34 at live dot cn
@ 2023-09-21 8:11 ` redi at gcc dot gnu.org
2023-09-25 8:53 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2023-09-21 8:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111512
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2023-09-21
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Yes, that seems undesirable.
Reduced:
template<typename T>
void to_array(T& from)
{
T to;
__builtin_memcpy(&to, &from, sizeof(T));
}
struct incomplete;
template<class T>
struct holder {
T t;
};
using validator = holder<incomplete>*;
int main()
{
validator a[1]{};
::to_array(a);
}
Casting the arguments to void avoids the problem:
__builtin_memcpy((void*)&to, (void*)&from, sizeof(T));
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/111512] GCC's __builtin_memcpy can trigger ADL
2023-09-21 6:27 [Bug c++/111512] New: GCC's __builtin_memcpy can trigger ADL de34 at live dot cn
2023-09-21 8:11 ` [Bug c++/111512] " redi at gcc dot gnu.org
@ 2023-09-25 8:53 ` cvs-commit at gcc dot gnu.org
2023-09-25 8:59 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ 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=111512
--- Comment #2 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] 7+ messages in thread
* [Bug c++/111512] GCC's __builtin_memcpy can trigger ADL
2023-09-21 6:27 [Bug c++/111512] New: GCC's __builtin_memcpy can trigger ADL de34 at live dot cn
2023-09-21 8:11 ` [Bug c++/111512] " redi at gcc dot gnu.org
2023-09-25 8:53 ` cvs-commit at gcc dot gnu.org
@ 2023-09-25 8:59 ` redi at gcc dot gnu.org
2023-09-26 20:15 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2023-09-25 8:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111512
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The library has a workaround, but the front end still does unwanted ADL for
__builtin_memcpy (and probably other built-ins).
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/111512] GCC's __builtin_memcpy can trigger ADL
2023-09-21 6:27 [Bug c++/111512] New: GCC's __builtin_memcpy can trigger ADL de34 at live dot cn
` (2 preceding siblings ...)
2023-09-25 8:59 ` redi 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
5 siblings, 0 replies; 7+ 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=111512
--- Comment #4 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] 7+ messages in thread
* [Bug c++/111512] GCC's __builtin_memcpy can trigger ADL
2023-09-21 6:27 [Bug c++/111512] New: GCC's __builtin_memcpy can trigger ADL de34 at live dot cn
` (3 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
5 siblings, 0 replies; 7+ 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=111512
--- Comment #5 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] 7+ messages in thread
* [Bug c++/111512] GCC's __builtin_memcpy can trigger ADL
2023-09-21 6:27 [Bug c++/111512] New: GCC's __builtin_memcpy can trigger ADL de34 at live dot cn
` (4 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
5 siblings, 0 replies; 7+ 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=111512
--- 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: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] 7+ messages in thread
end of thread, other threads:[~2023-09-27 16:21 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-21 6:27 [Bug c++/111512] New: GCC's __builtin_memcpy can trigger ADL de34 at live dot cn
2023-09-21 8:11 ` [Bug c++/111512] " redi at gcc dot gnu.org
2023-09-25 8:53 ` cvs-commit at gcc dot gnu.org
2023-09-25 8:59 ` redi 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
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).