https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110213
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 boils down to the following: const target& search (const target&, name); void pattern::apply(target& t) const { name n = ...; 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 TU. To reproduce, run: $ g++ -std=c++23 -Wall -Wextra -fdirectives-only -c adhoc-rule-regex-pattern.ii adhoc-rule-regex-pattern.cxx: In member function ‘virtual void build2::adhoc_rule_regex_pattern::apply_prerequisites(build2::action, build2::target&, const scope&, build2::match_extra&) const’: adhoc-rule-regex-pattern.cxx:485:21: warning: possibly dangling reference to 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 the end of the full expression ‘build2::search((*(const build2::target*)(& t)), build2::name((* & std::move<build2::name&>(n))), (* s), (& e.build2::adhoc_rule_regex_pattern::element::type))’ 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 warning disappear. $ g++ --version g++-13 (Debian 13.1.0-3) 13.1.0