From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 7747E3861883 for ; Wed, 27 Sep 2023 13:48:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7747E3861883 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695822514; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WVOvdTqauxKvcWHqgFLK/8DyKfamfC0tiJcC/Dud7xY=; b=dYEcTtlmkLl5jAoEiCguSEoopnh1HqtG4zaKFiafXloWQ17tVl+JntqAQqJVb9vU8FQBvH inFLeSdoephnxAgvaqLq2G7UMEcBpO8hSRtxTrGlabI60HLVDQGmNHGbW682Vvmi6HBNVR 3PXVm7H2oppf9ZSYyG+qZRAapocSg4w= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-385-lsXud3wrMG2_M4M1D7Im-A-1; Wed, 27 Sep 2023 09:48:32 -0400 X-MC-Unique: lsXud3wrMG2_M4M1D7Im-A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 60F27101A529; Wed, 27 Sep 2023 13:48:32 +0000 (UTC) Received: from localhost (unknown [10.42.28.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2665840C6EA8; Wed, 27 Sep 2023 13:48:32 +0000 (UTC) From: Jonathan Wakely 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 Message-ID: <20230927134831.2823229-1-jwakely@redhat.com> In-Reply-To: <20230925085406.2744040-1-jwakely@redhat.com> References: <20230925085406.2744040-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,URI_HEX autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 +#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)); +} -- 2.41.0