From patchwork Sat Jan 20 02:17:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1888729 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=D54W3ou6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TH0X80xC5z1yPJ for ; Sat, 20 Jan 2024 13:18:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A8E133858414 for ; Sat, 20 Jan 2024 02:18:25 +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 3FB0E3858D39 for ; Sat, 20 Jan 2024 02:18:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3FB0E3858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3FB0E3858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705717086; cv=none; b=fFiGlSWH9sphp8qW9ppHRZ8ZxGt9steLygwS7p2D88T4hVj18gEBKBY5dKn+sevdBGw/3ZgET6CcDZZVmfgOpbbe476xI2towW1BnduicFS0ts191dG25jfhdEq2Y6IMeqbvhmC2ZZ0HhbbB+h/SDaiRo5wlVSygc2K47yx4pyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705717086; c=relaxed/simple; bh=vVhrqy8K/C/kwwLxayzARppZwhxDreDpPme2tnh86Ao=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=o3EdlVDjXY/C99CYD5JEW0L+VHUuIXHPSXS/yC56A9Ohv5980h7gkD2N9UkpN0JhbebQQGK6HclOuLbzE45SUvLjxYGx52DkjGnTKAMsj0uQhmU9EEu1RCzceUtDIyCc/Ip+2YpXbGZMezBQYZ3xH23fK0VB/UCWhURE3D3Bi+Q= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705717083; 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; bh=ekn97KkOlIsybrouQRwWkXHs0KNxdrSiVpodDxJREFI=; b=D54W3ou6ZkKfW71BmDUWOkts9vrSCTGm/VNdZPQjqChaCldaKsf7XnyqLTApjquQYwLQPw 35N9ISTte1DmcOnYKrVdE8czHP6ruBiF4dHhKax+XBL3VOJzgwRml8azgjly0u7dDlYz3h VXXTA/p1P5afHSdQwA2UNpGcFZYT5aI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-33-iwVTtMxVN-OLbKMllZYeBQ-1; Fri, 19 Jan 2024 21:18:02 -0500 X-MC-Unique: iwVTtMxVN-OLbKMllZYeBQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B3135800074; Sat, 20 Jan 2024 02:18:01 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.9.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EC602877; Sat, 20 Jan 2024 02:18:01 +0000 (UTC) From: Marek Polacek To: GCC Patches , libstdc++ , Jonathan Wakely , Jason Merrill Subject: [PATCH] libstdc++: suppress -Wdangling-reference with operator| [PR111410] Date: Fri, 19 Jan 2024 21:17:51 -0500 Message-ID: <20240120021751.81798-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.3 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, T_SCC_BODY_TEXT_LINE autolearn=ham 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- It seems to me that we should exclude std::ranges::views::__adaptor::operator| from the -Wdangling-reference warning. It's commonly used when handling ranges. PR c++/111410 libstdc++-v3/ChangeLog: * include/std/ranges: Add #pragma to disable -Wdangling-reference with std::ranges::views::__adaptor::operator|. gcc/testsuite/ChangeLog: * g++.dg/warn/Wdangling-reference17.C: New test. --- gcc/testsuite/g++.dg/warn/Wdangling-reference17.C | 15 +++++++++++++++ libstdc++-v3/include/std/ranges | 3 +++ 2 files changed, 18 insertions(+) create mode 100644 gcc/testsuite/g++.dg/warn/Wdangling-reference17.C base-commit: 615e25c82de97acc17ab438f88d6788cf7ffe1d6 diff --git a/gcc/testsuite/g++.dg/warn/Wdangling-reference17.C b/gcc/testsuite/g++.dg/warn/Wdangling-reference17.C new file mode 100644 index 00000000000..223698422c2 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wdangling-reference17.C @@ -0,0 +1,15 @@ +// PR c++/111410 +// { dg-do compile { target c++20 } } +// { dg-options "-Wdangling-reference" } + +#include +#include + +int main() +{ + std::vector v{1, 2, 3, 4, 5}; + for (auto i : std::span{v} | std::views::take(1)) + { + (void) i; + } +} diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 7ef835f486a..f2413badd9c 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -942,6 +942,8 @@ namespace views::__adaptor concept __is_range_adaptor_closure = requires (_Tp __t) { __adaptor::__is_range_adaptor_closure_fn(__t, __t); }; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdangling-reference" // range | adaptor is equivalent to adaptor(range). template requires __is_range_adaptor_closure<_Self> @@ -961,6 +963,7 @@ namespace views::__adaptor return _Pipe, decay_t<_Rhs>>{std::forward<_Lhs>(__lhs), std::forward<_Rhs>(__rhs)}; } +#pragma GCC diagnostic pop // The base class of every range adaptor non-closure. //