c++: -Wdangling-reference and lambda false warning [PR109640]
commit9010fdba68063beccfbab0aa9ec8739f232ca2f4
authorMarek Polacek <polacek@redhat.com>
Fri, 19 Jan 2024 18:59:41 +0000 (19 13:59 -0500)
committerMarek Polacek <polacek@redhat.com>
Tue, 23 Jan 2024 21:35:31 +0000 (23 16:35 -0500)
tree28a49f0ba5a0ff17670eeb1a57173309e5f6997a
parented4c7893de2cbae0a07bb4984e408d57e6db06f3
c++: -Wdangling-reference and lambda false warning [PR109640]

-Wdangling-reference checks if a function receives a temporary as its
argument, and only warns if any of the arguments was a temporary.  But
we should not warn when the temporary represents a lambda or we generate
false positives as in the attached testcases.

PR c++/113256
PR c++/111607
PR c++/109640

gcc/cp/ChangeLog:

* call.cc (do_warn_dangling_reference): Don't warn if the temporary
is of lambda type.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wdangling-reference14.C: New test.
* g++.dg/warn/Wdangling-reference15.C: New test.
* g++.dg/warn/Wdangling-reference16.C: New test.
gcc/cp/call.cc
gcc/testsuite/g++.dg/warn/Wdangling-reference14.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wdangling-reference15.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wdangling-reference16.C [new file with mode: 0644]