From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1734) id 6EA443858D1E; Mon, 13 Mar 2023 15:21:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6EA443858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678720907; bh=AbawklTXk65wEAcd63a8CAVCW/WAqvbKYLLsDXOKSFg=; h=From:To:Subject:Date:From; b=DhYzaK/ISu1zHVzv1BWSRHRL1qNWG+9dph1MFMAdMPPsV+o2PrMFhXxNo3amKMp73 igT5iraEB4XJCB+2eeOYdmDgtGqwl7PEnB8+kNT8a7yMTRMCZAs8tIrszA8t4BJOR6 PTxE3AVBP0/X9Sl4s9bI/LdtZaMG7odLnK7+uIVY= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marek Polacek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6633] c++: suppress -Wdangling-reference for std::span [PR107532] X-Act-Checkin: gcc X-Git-Author: Marek Polacek X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 7ef44579787af646d5bae13a91a49ef5d2048f5c X-Git-Newrev: ced122b849b8961b854053f0d1ac96983c5802e5 Message-Id: <20230313152147.6EA443858D1E@sourceware.org> Date: Mon, 13 Mar 2023 15:21:47 +0000 (GMT) List-Id: https://gcc.gnu.org/g:ced122b849b8961b854053f0d1ac96983c5802e5 commit r13-6633-gced122b849b8961b854053f0d1ac96983c5802e5 Author: Marek Polacek Date: Fri Mar 10 12:23:13 2023 -0500 c++: suppress -Wdangling-reference for std::span [PR107532] std::span is a view and therefore should be treated as a reference wrapper class for the purposes of -Wdangling-reference. I'm not sure there's a pattern that we could check for. PR c++/107532 gcc/cp/ChangeLog: * call.cc (reference_like_class_p): Check for std::span. gcc/testsuite/ChangeLog: * g++.dg/warn/Wdangling-reference10.C: New test. Diff: --- gcc/cp/call.cc | 1 + gcc/testsuite/g++.dg/warn/Wdangling-reference10.C | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 3dfa12a0733..c01e7b82457 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -13800,6 +13800,7 @@ reference_like_class_p (tree ctype) tree name = DECL_NAME (tdecl); return (name && (id_equal (name, "reference_wrapper") + || id_equal (name, "span") || id_equal (name, "ref_view"))); } for (tree fields = TYPE_FIELDS (ctype); diff --git a/gcc/testsuite/g++.dg/warn/Wdangling-reference10.C b/gcc/testsuite/g++.dg/warn/Wdangling-reference10.C new file mode 100644 index 00000000000..733fb8cce63 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wdangling-reference10.C @@ -0,0 +1,12 @@ +// PR c++/107532 +// { dg-do compile { target c++20 } } +// { dg-options "-Wdangling-reference" } + +#include +#include + +void f(const std::vector& v) +{ + const int& r = std::span(v)[0]; // { dg-bogus "dangling reference" } + (void) r; +}