From: Jason Merrill Date: Thu, 7 Jul 2022 14:12:04 +0000 (-0400) Subject: c++: -Woverloaded-virtual and dtors [PR87729] X-Git-Tag: basepoints/gcc-14~5648 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=81bec060e31b6ef2feeb3046c6f13a207c6f698a;p=thirdparty%2Fgcc.git c++: -Woverloaded-virtual and dtors [PR87729] My earlier patch broke out of the loop over base members when we found a match, but that caused trouble for dtors, which can have multiple for which same_signature_p is true. But as the function comment says, we know this doesn't apply to [cd]tors, so skip them. PR c++/87729 gcc/cp/ChangeLog: * class.cc (warn_hidden): Ignore [cd]tors. gcc/testsuite/ChangeLog: * g++.dg/warn/Woverloaded-virt3.C: New test. --- diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc index 17683f421a7..eb69e7f985c 100644 --- a/gcc/cp/class.cc +++ b/gcc/cp/class.cc @@ -3020,6 +3020,9 @@ warn_hidden (tree t) tree binfo; unsigned j; + if (IDENTIFIER_CDTOR_P (name)) + continue; + /* Iterate through all of the base classes looking for possibly hidden functions. */ for (binfo = TYPE_BINFO (t), j = 0; diff --git a/gcc/testsuite/g++.dg/warn/Woverloaded-virt3.C b/gcc/testsuite/g++.dg/warn/Woverloaded-virt3.C new file mode 100644 index 00000000000..34214ba2557 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Woverloaded-virt3.C @@ -0,0 +1,7 @@ +// PR c++/87729 +// { dg-additional-options -Woverloaded-virtual } + +struct S1 {}; +struct S2: S1 { virtual ~S2(); }; +struct S3 { virtual ~S3(); }; +struct S4: S2, S3 { virtual ~S4(); };