From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2D32F3858427; Thu, 3 Nov 2022 19:46:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D32F3858427 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667504811; bh=XBjBm730P5nvHjMY5MPnQfWOIRi2Dt1YuV76QD1+f4s=; h=From:To:Subject:Date:In-Reply-To:References:From; b=P13pS6kxVKkm0CgelaD7UWbDFy8DH5EssXj9jGVLZHsRFDrbTchLo1QwA1rzr/WH/ YfVylHrlkApATd9OmwQ3xExZxto9VeXYl79Ja0qeUfRjH6WJJX+yJSYD+dWHs7Fjdo tIjIGwvNhaIMcPjXIS6Z1o5NO9174NYX8+owBkN0= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107488] [13 Regression] -Werror=dangling-reference false positives in cppunit Date: Thu, 03 Nov 2022 19:46:49 +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: P3 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=3D107488 --- Comment #2 from CVS Commits --- The trunk branch has been updated by Marek Polacek : https://gcc.gnu.org/g:32a06ce38a38bf37db468f0e6c83520fcc221534 commit r13-3642-g32a06ce38a38bf37db468f0e6c83520fcc221534 Author: Marek Polacek Date: Tue Nov 1 17:05:52 2022 -0400 c++: Quash -Wdangling-reference for member operator* [PR107488] -Wdangling-reference complains here: std::vector v =3D ...; std::vector::const_iterator it =3D v.begin(); while (it !=3D v.end()) { const int &r =3D *it++; // warning } because it sees a call to __gnu_cxx::__normal_iterator >::operator* which returns a reference and its argument is a TARGET_EXPR representing the result of __gnu_cxx::__normal_iterator >::operator++ But 'r' above refers to one of the int elements of the vector 'v', not to a temporary object. Therefore the warning is a false positive. I suppose code like the above is relatively common (the warning broke cppunit-1.15.1 and a few other projects), so presumably it makes sense to suppress the warning when it comes to member operator*. In this case it's defined as reference operator*() const _GLIBCXX_NOEXCEPT { return *_M_current; } and I'm guessing a lot of member operator* are like that, at least when it comes to iterators. I've looked at _Fwd_list_iterator, _Fwd_list_const_iterator, __shared_ptr_access, _Deque_iterator, istream_iterator, etc, and they're all like that, so adding #pragmas would be quite tedious. :/ PR c++/107488 gcc/cp/ChangeLog: * call.cc (do_warn_dangling_reference): Quash -Wdangling-refere= nce for member operator*. gcc/testsuite/ChangeLog: * g++.dg/warn/Wdangling-reference5.C: New test.=