]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: further -Wdangling-reference refinement [PR107532]
authorMarek Polacek <polacek@redhat.com>
Fri, 17 Mar 2023 18:36:10 +0000 (14:36 -0400)
committerMarek Polacek <polacek@redhat.com>
Thu, 23 Mar 2023 13:25:41 +0000 (09:25 -0400)
commit59bfdd5f467292a368d0d628084a4b65d1bb06bb
treef50a5eaa6ce601ea9751a42f0cb8cb7eae11d367
parent3b97715af0e848ef8703ac04665bde562b2ac159
c++: further -Wdangling-reference refinement [PR107532]

Based on <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107532#c24>,
it seems like we should treat *any* class with a reference member
as a reference wrapper.  To suppress the warning in

  int i = 42;
  auto const& v = std::get<0>(std::tuple<int&>(i));

we have to look into base classes as well.  For std::tuple, this means
that we have to check the _Head_base subobject, which is a non-direct
base class of std::tuple.  So I've employed a DFS walk.

PR c++/107532

gcc/cp/ChangeLog:

* call.cc (class_has_reference_member_p): New.
(class_has_reference_member_p_r): New.
(reference_like_class_p): Don't look for a specific constructor.
Use a DFS walk with class_has_reference_member_p_r.

gcc/testsuite/ChangeLog:

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