c++: Extend -Wdangling-reference for std::minmax
This patch extends -Wdangling-reference to also warn for
auto v = std::minmax(1, 2);
which dangles because this overload of std::minmax returns
a std::pair<const int&, const int&> where the two references are
bound to the temporaries created for the arguments of std::minmax.
This is a common footgun, also described at
<https://en.cppreference.com/w/cpp/algorithm/minmax> in Notes.
It works by extending do_warn_dangling_reference to also warn when the
function returns a std::pair<const T&, const T&>. std_pair_ref_ref_p
is a new helper to check that.
gcc/cp/ChangeLog:
* call.cc (std_pair_ref_ref_p): New.
(do_warn_dangling_reference): Also warn when the function returns
std::pair<const T&, const T&>. Recurse into TARGET_EXPR_INITIAL.
(maybe_warn_dangling_reference): Don't return early if we're
initializing a std_pair_ref_ref_p.
gcc/ChangeLog:
* doc/gcc/gcc-command-options/options-controlling-c++-dialect.rst:
Extend the description of -Wdangling-reference.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wdangling-reference6.C: New test.