https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108165
Bug ID: 108165 Summary: -Wdangling-reference false positive Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: romain.geissler at amadeus dot com Target Milestone: --- Hi, The following snippet issues a wrong -Wdangling-reference warning when compiled with -Wall with current gcc trunk: <<END_OF_FILE struct A {}; struct B { B(int) {} }; const A& f(const A& a, const B&) { return a; } const A& g(const A& a) { const A& result = f(a, 42); return result; } END_OF_FILE The warning is: <source>: In function 'const A& g(const A&)': <source>:13:14: warning: possibly dangling reference to a temporary [-Wdangling-reference] 13 | const A& result = f(a, 42); | ^~~~~~ <source>:13:24: note: the temporary was destroyed at the end of the full expression 'f((* & a), B(42))' 13 | const A& result = f(a, 42); | ~^~~~~~~ ASM generation compiler returned: 0 <source>: In function 'const A& g(const A&)': <source>:13:14: warning: possibly dangling reference to a temporary [-Wdangling-reference] 13 | const A& result = f(a, 42); | ^~~~~~ <source>:13:24: note: the temporary was destroyed at the end of the full expression 'f((* & a), B(42))' 13 | const A& result = f(a, 42); | ~^~~~~~~