From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3A7793858D37; Thu, 18 Jan 2024 22:02:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A7793858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705615364; bh=vwWvLn9Hqn7KXXYmBG+HuX7ml0auq5GPnXxZzls0LmE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=QG/FSe/gkbbQz3NfyxbqPyq45dD6X5DRvf6dn+gyl4PXQNZinYeboBiJXyl5/uOsI x/Yvz8a0vjC/jzlgERrr66ipduPuNHyajlBDnjoPDMKMBGaHC9ieOh9jZpIWQlqeHJ q5VGC7Uf1VRA95vGNtL9vYmn7lapiW3QuTIYCMW4= From: "mpolacek at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/111607] False positive -Wdangling-reference Date: Thu, 18 Jan 2024 22:02:43 +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: 14.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: mpolacek 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: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: assigned_to see_also cf_reconfirmed_on everconfirmed bug_status 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=3D111607 Marek Polacek changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot= gnu.org See Also| |https://gcc.gnu.org/bugzill | |a/show_bug.cgi?id=3D113256 Last reconfirmed| |2024-01-18 Ever confirmed|0 |1 Status|UNCONFIRMED |ASSIGNED --- Comment #1 from Marek Polacek --- Thanks for the report. I suppose we should not warn when the argument is a lambda type. This might also fix bug 113256. --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -14123,7 +14123,8 @@ do_warn_dangling_reference (tree expr, bool arg_p) tree e =3D expr; while (handled_component_p (e)) e =3D TREE_OPERAND (e, 0); - if (!reference_like_class_p (TREE_TYPE (e))) + if (!reference_like_class_p (TREE_TYPE (e)) + && !LAMBDA_TYPE_P (TREE_TYPE (e))) return expr; } @@ -14180,10 +14181,10 @@ do_warn_dangling_reference (tree expr, bool arg_p) initializing this reference parameter. */ if (do_warn_dangling_reference (arg, /*arg_p=3D*/true)) return expr; - /* Don't warn about member function like: + /* Don't warn about member functions like: std::any a(...); S& s =3D a.emplace({0}, 0); - which constructs a new object and returns a reference to it, but + which construct a new object and return a reference to it, but we still want to detect: struct S { const S& self () { return *this; } }; const S& s =3D S().self();=