From patchwork Wed Sep 27 13:46:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 145387 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2642853vqu; Wed, 27 Sep 2023 06:50:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGhY3AYJ9VG2XrPSJ+2vfrRz8bpIW/rbx7J44ItksJUBAIkkJnUiDOgs0Eue4LhiT2ZhboO X-Received: by 2002:a50:fb81:0:b0:52f:a162:f4c4 with SMTP id e1-20020a50fb81000000b0052fa162f4c4mr2242503edq.18.1695822611881; Wed, 27 Sep 2023 06:50:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695822611; cv=none; d=google.com; s=arc-20160816; b=L+vL3G4wZAebAB/KrY94jZZTFGoX50EEtrMlkxRMRYqJb2xTxu0XF392WkjGX9bg9N BqR+w6p544trUvj8y77sZMjf8OkhfhDy/wlGB1dpME9lv5FMRsNqqlStL9QfL4KPeFlz utuvwHccfkZlb8OwfrEFVTmBrL5eFLEef1xTibjYUYgQHkI7OqlZowH5yvFiis8yXL7C VpzR3ECxHMqQHnyyEKXIZy4q20+z7jGMn97Y/nsUoAB2yiBWdoi+uGpX8/emIYY0EdyP h7nwRrs4yY0a+lYcVo8aXt8Az/MG29fCaNe/AkdvSooZczUMehU2xbJX7v7VyZRANT/+ fgwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:dmarc-filter:delivered-to; bh=WVOvdTqauxKvcWHqgFLK/8DyKfamfC0tiJcC/Dud7xY=; fh=sJ+2/4g29YdyXkoRrFZSpsL2zxijepB7X/1rB0LDDh8=; b=loT0LUw19SBENosqph61em7jt02po90cw/SYzYMmjM5egwgKW+imVL8BTLKK+Z55WS uYD6p8o7vwtso49lBfTaL9M1aBM4au+ev5wr+xwn3J1fT3t2W4fF9AZgOlWoLUHZPS8h f2/sL2Q/IExnxbpJHWdoHp6+Axi6Gkzry5UVzlVqILZjoGJsLmK8xWbNpFVV4uaFuBYl dW2IrNQP5Xbr/SRYqDEhaQW/915kO7ul6cIHxYmOsmu050B/YxObPLzTv/lmfMyHuyXB +p+rdNJqp2fUhJ8KjSB8dbtOh2/Zofro36VJF8Y+tV0984PIe7FHElq6dz0b5ntG5JlS V7Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gWlpZ9I3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id be4-20020a0564021a2400b00532addba502si12478478edb.124.2023.09.27.06.50.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 06:50:11 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gWlpZ9I3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2FDA438768B0 for ; Wed, 27 Sep 2023 13:49:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 407B6386186B for ; Wed, 27 Sep 2023 13:48:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 407B6386186B 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=1695822515; 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=gWlpZ9I3PK5iXsb70xIVskSeUAqYClIx7pa/b6VL2fNF8eLLjsx7+NThu6TbQ3mprvVQHs imchE7SmGxBnyFzIIPTw/IZER52JlRzQvt6K9lcANulaSye/1OJ/RwQEEmdiit1Wv7QNEm kYNknpGzUtqD6rZRCrA9A35KZIkPJU4= 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 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=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777999202704543780 X-GMAIL-MSGID: 1778198890662280569 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)); +}