From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 6A80538582BD; Wed, 27 Sep 2023 16:21:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A80538582BD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695831707; bh=l8VYcMRbmQ4lR+oFLMii7sq2BOTtAiXVOA+cwWS0/dE=; h=From:To:Subject:Date:From; b=r3FQTe/wr/hd0+xGIxfGkcgCwK44rhWwxuHl9s1zzzRi3L4/8W5IHPxLkuvNdGsSS nDYD5l8wpWJKs9QCTDRvJpBkZbnEUQuJFGrxoZQF1DrjJ7LES8MeB9yX3EerF/zC11 xjZM276XNcJjfUBRdkdyM8wTxErAxk3Nc2zXbP9I= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-11021] libstdc++: Prevent unwanted ADL in std::to_array [PR111512] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 4f9c509ed534a5fb1933ee5bf79a4c868f791c8c X-Git-Newrev: 97a33ab114187e7c6cd6c6c0f06cd8225e8aeef5 Message-Id: <20230927162147.6A80538582BD@sourceware.org> Date: Wed, 27 Sep 2023 16:21:47 +0000 (GMT) List-Id: 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) Diff: --- libstdc++-v3/include/std/array | 4 ++-- .../23_containers/array/creation/111512.cc | 25 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array index 0c6f33e3276..95c9b688cdc 100644 --- a/libstdc++-v3/include/std/array +++ b/libstdc++-v3/include/std/array @@ -409,7 +409,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 } @@ -421,7 +421,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 +#include + +struct incomplete; + +template +struct holder { + T t; // { dg-bogus "'holder::t' has incomplete type" } +}; + +// A complete type that cannot be used as an associated type for ADL. +using adl_bomb = holder*; + +int main() +{ + adl_bomb a[1]{}; + (void) std::to_array(a); + (void) std::to_array(std::move(a)); +}