From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 59B2F38708AA; Thu, 23 Mar 2023 15:22:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 59B2F38708AA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679584945; bh=VmEEeVWDZNL3pGIwU/ULR8xtH9HqRQaMVRlQoXCp5bM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=bKG5rzz05IbvedFMiBKgF7wpekw3xmyv3QIW3S8Y+ArZ5UcFLBYc27BXKfRVF6ukO PwTFzQ1bTIzUk2Gl2IwdK6TG45mGMN+MpZKszTxjg7+wRHT5M8s/2mqGt7RQ1rXlQ6 wIrxwQ0GJxEPY1hKy7vnn7DyOcm0oScie1E72680= From: "gcc-bugzilla at al42and dot me" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107532] [13 Regression] -Werror=dangling-reference false positives in libcamera-0.0.1 Date: Thu, 23 Mar 2023 15:22:24 +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: gcc-bugzilla at al42and dot me X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: FIXED 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 #29 from Andrey Alekseenko --- > it seems like we should treat *any* class with a reference member as a re= ference wrapper.=20 And any class with a pointer, I suspect. This is a reduced/simplified example from our codebase still triggering the error even with 59bfdd5f467292a368d0d628084a4b65d1bb06bb: $ cat test.cpp=20 struct ArrayRef { ArrayRef(int* ptr) : ptr_(ptr) {} int& operator[](int n) const { return ptr_[n]; } int* ptr_; }; int main() { int a; const int& r =3D ArrayRef(&a)[0]; } $ g++ -std=3Dc++17 -Wdangling-reference test.cpp -o test test.cpp: In function =E2=80=98int main()=E2=80=99: test.cpp:11:16: warning: possibly dangling reference to a temporary [-Wdangling-reference] 11 | const int& r =3D ArrayRef(&a)[0]; | ^ test.cpp:11:34: note: the temporary was destroyed at the end of the full expression =E2=80=98ArrayRef((& a)).ArrayRef::operator[](0)=E2=80=99 11 | const int& r =3D ArrayRef(&a)[0]; | ^=