From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 69C2B385480C; Tue, 7 Mar 2023 16:11:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 69C2B385480C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678205473; bh=Vj0lFZd7rAFh/oupZGrX+mu0Z2qVXGQ4jHCYdpCULHI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=J9vAnGk103icBxhfnm+BPHac3qOlzZjnwU0U6o8ZJiyq1evsMHdTiKnr0duVBODWT TQnbOfnlqL8mBFncvBcE3LZQHsko0wRoeRVeXABK6ZMcMorW/CfDqNu7wY4XAvVQAC eL/2Q5jnW3WWESAkj5QFHFai7QK47M1OfRfWDRjY= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107532] [13 Regression] -Werror=dangling-reference false positives in libcamera-0.0.1 Date: Tue, 07 Mar 2023 16:11:12 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: mpolacek at gcc dot gnu.org X-Bugzilla-Target-Milestone: 13.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107532 --- Comment #11 from CVS Commits --- The trunk branch has been updated by Marek Polacek : https://gcc.gnu.org/g:80f0052b3924569af904d1bab0858fe985f33a94 commit r13-6529-g80f0052b3924569af904d1bab0858fe985f33a94 Author: Marek Polacek Date: Tue Jan 17 17:34:58 2023 -0500 c++: -Wdangling-reference with reference wrapper [PR107532] Here, -Wdangling-reference triggers where it probably shouldn't, causing some grief. The code in question uses a reference wrapper with a member function returning a reference to a subobject of a non-temporary object: const Plane & meta =3D fm.planes().inner(); I've tried a few approaches, e.g., checking that the member function's return type is the same as the type of the enclosing class (which is the case for member functions returning *this), but that then breaks Wdangling-reference4.C with std::optional. This patch adjusts do_warn_dangling_reference so that we look through reference wrapper classes (meaning, has a reference member and a constructor taking the same reference type, or is std::reference_wrapper or std::ranges::ref_view) and don't warn for them, supposing that the member function returns a reference to a non-temporary object. PR c++/107532 gcc/cp/ChangeLog: * call.cc (reference_like_class_p): New. (do_warn_dangling_reference): Add new bool parameter. See thro= ugh reference_like_class_p. gcc/testsuite/ChangeLog: * g++.dg/warn/Wdangling-reference8.C: New test. * g++.dg/warn/Wdangling-reference9.C: New test.=