diff options
author | Marek Polacek <polacek@redhat.com> | 2022-11-09 19:35:26 -0500 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2022-11-10 13:17:09 -0500 |
commit | 7e3ce73849fef8b50efb427ec96f317e88c0e6cf (patch) | |
tree | 0e4432ebd86e247c6b999b8ead2b122b72da2607 /gcc/analyzer/infinite-recursion.cc | |
parent | 740cf7d6ab266cf4249fc5c247187622cb6a2c8f (diff) | |
download | gcc-7e3ce73849fef8b50efb427ec96f317e88c0e6cf.zip gcc-7e3ce73849fef8b50efb427ec96f317e88c0e6cf.tar.gz gcc-7e3ce73849fef8b50efb427ec96f317e88c0e6cf.tar.bz2 |
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.
Diffstat (limited to 'gcc/analyzer/infinite-recursion.cc')
0 files changed, 0 insertions, 0 deletions