]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: -Wdangling-reference and empty class [PR115361]
authorJason Merrill <jason@redhat.com>
Sun, 15 Sep 2024 11:50:04 +0000 (13:50 +0200)
committerJason Merrill <jason@redhat.com>
Wed, 18 Sep 2024 12:58:52 +0000 (08:58 -0400)
commit8733d5d3873977d6ca82d71b28728650f988e9c8
tree1430a816602f810b813da7b2599a91f7a5a41f78
parent6f3b6a451771cd54c98768e7db3c5d58aab2b6aa
c++: -Wdangling-reference and empty class [PR115361]

We can't have a dangling reference to an empty class unless it's
specifically to that class or one of its bases.  This was giving a
false positive on the _ExtractKey pattern in libstdc++ hashtable.h.

This also adjusts the order of arguments to reference_related_p, which
is relevant for empty classes (unlike scalars).

Several of the classes in the testsuite needed to gain data members to
continue to warn.

PR c++/115361

gcc/cp/ChangeLog:

* call.cc (do_warn_dangling_reference): Check is_empty_class.

gcc/testsuite/ChangeLog:

* g++.dg/ext/attr-no-dangling6.C
* g++.dg/ext/attr-no-dangling7.C
* g++.dg/ext/attr-no-dangling8.C
* g++.dg/ext/attr-no-dangling9.C
* g++.dg/warn/Wdangling-reference1.C
* g++.dg/warn/Wdangling-reference2.C
* g++.dg/warn/Wdangling-reference3.C: Make classes non-empty.
* g++.dg/warn/Wdangling-reference23.C: New test.
gcc/cp/call.cc
gcc/testsuite/g++.dg/ext/attr-no-dangling6.C
gcc/testsuite/g++.dg/ext/attr-no-dangling7.C
gcc/testsuite/g++.dg/ext/attr-no-dangling8.C
gcc/testsuite/g++.dg/ext/attr-no-dangling9.C
gcc/testsuite/g++.dg/warn/Wdangling-reference1.C
gcc/testsuite/g++.dg/warn/Wdangling-reference2.C
gcc/testsuite/g++.dg/warn/Wdangling-reference23.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wdangling-reference3.C