From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3D1C83858D32; Mon, 12 Jun 2023 03:47:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D1C83858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686541679; bh=Y+btgSZsxTTmMJu9TmyywEBhHg8aQSm8ugaxXDIICoY=; h=From:To:Subject:Date:From; b=tb7VUqWDxtpoHTmIbVbZB/5XB3zF9R1a7Q9HrHll5VaMEplxm26NFz/VlfOtH9Rn0 VNoDtO6EF2VZzrasmSUnBkUhYxk37eaCBT7ZcyFLRB1z+gZSRFjULmlSvaqb0jO/oU Uk6o6IIB0sw9dWy5JYVob2mAypu/zL+XHzosmgEY= From: "boris at kolpackov dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/110213] New: Bogus (as opposed to false positive) -Wdangling-reference warning Date: Mon, 12 Jun 2023 03:47:58 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: boris at kolpackov dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D110213 Bug ID: 110213 Summary: Bogus (as opposed to false positive) -Wdangling-reference warning Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: boris at kolpackov dot net Target Milestone: --- I have a call that, AFAICS, doesn't involve any binding of references to temporaries but which nevertheless still produces this warning. The code bo= ils down to the following: const target& search (const target&, name); void pattern::apply(target& t) const { name n =3D ...; const target& p (search (t, std::move (n))); // <- Warning points here. } However, I was not able to reduce it to a small reproducer so it seems to depend on the overall context. So I am attaching a partially preprocessed T= U. To reproduce, run: $ g++ -std=3Dc++23 -Wall -Wextra -fdirectives-only -c adhoc-rule-regex-patt= ern.ii adhoc-rule-regex-pattern.cxx: In member function =E2=80=98virtual void build2::adhoc_rule_regex_pattern::apply_prerequisites(build2::action, build2::target&, const scope&, build2::match_extra&) const=E2=80=99: adhoc-rule-regex-pattern.cxx:485:21: warning: possibly dangling reference t= o a temporary [-Wdangling-reference] 485 | const target& pt (search (t, move (n), *s, &e.type)); | ^~ adhoc-rule-regex-pattern.cxx:485:32: note: the temporary was destroyed at t= he end of the full expression=20 =E2=80=98build2::search((*(const build2::target*)(& t)), build2::name((* & std::move(n))), (* s), (& e.build2::adhoc_rule_regex_pattern::element::type))=E2=80=99 485 | const target& pt (search (t, move (n), *s, &e.type)); | ~~~~~~~^~ The last two arguments (*s, &e.type) in the call do not make any difference. Changing the search() function to take name by const& or && makes the warni= ng disappear. $ g++ --version g++-13 (Debian 13.1.0-3) 13.1.0=