From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Prevent unwanted ADL in std::to_array [PR111512]
Date: Wed, 27 Sep 2023 14:46:49 +0100 [thread overview]
Message-ID: <20230927134831.2823229-1-jwakely@redhat.com> (raw)
In-Reply-To: <20230925085406.2744040-1-jwakely@redhat.com>
This is the fix for the release branches, where std::to_array is
implemented differently.
Tested x86_64-linux. Pushed to gcc-13 and gcc-12. Will push to gcc-11
after testing.
-- >8 --
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)
---
libstdc++-v3/include/std/array | 4 +--
.../23_containers/array/creation/111512.cc | 25 +++++++++++++++++++
2 files changed, 27 insertions(+), 2 deletions(-)
create mode 100644 libstdc++-v3/testsuite/23_containers/array/creation/111512.cc
diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array
index 70280c1beeb..97cca454ef9 100644
--- a/libstdc++-v3/include/std/array
+++ b/libstdc++-v3/include/std/array
@@ -436,7 +436,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static_assert(!is_array_v<_Tp>);
static_assert(is_constructible_v<_Tp, _Tp&>);
if constexpr (is_constructible_v<_Tp, _Tp&>)
- return __to_array(__a, make_index_sequence<_Nm>{});
+ return std::__to_array(__a, make_index_sequence<_Nm>{});
__builtin_unreachable(); // FIXME: see PR c++/91388
}
@@ -449,7 +449,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static_assert(!is_array_v<_Tp>);
static_assert(is_move_constructible_v<_Tp>);
if constexpr (is_move_constructible_v<_Tp>)
- return __to_array<1>(__a, make_index_sequence<_Nm>{});
+ return std::__to_array<1>(__a, make_index_sequence<_Nm>{});
__builtin_unreachable(); // FIXME: see PR c++/91388
}
#endif // C++20
diff --git a/libstdc++-v3/testsuite/23_containers/array/creation/111512.cc b/libstdc++-v3/testsuite/23_containers/array/creation/111512.cc
new file mode 100644
index 00000000000..f510480ae4b
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/array/creation/111512.cc
@@ -0,0 +1,25 @@
+// { dg-options "-std=gnu++20" }
+// { dg-do compile { target c++20 } }
+
+// Bug libstdc++/111511 - Incorrect ADL in std::to_array in GCC 11/12/13
+// Bug c++/111512 - GCC's __builtin_memcpy can trigger ADL
+
+#include <array>
+#include <utility>
+
+struct incomplete;
+
+template<class T>
+struct holder {
+ T t; // { dg-bogus "'holder<T>::t' has incomplete type" }
+};
+
+// A complete type that cannot be used as an associated type for ADL.
+using adl_bomb = holder<incomplete>*;
+
+int main()
+{
+ adl_bomb a[1]{};
+ (void) std::to_array(a);
+ (void) std::to_array(std::move(a));
+}
--
2.41.0
prev parent reply other threads:[~2023-09-27 13:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-25 8:53 Jonathan Wakely
2023-09-27 13:46 ` Jonathan Wakely [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230927134831.2823229-1-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).