public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [pushed] c++: -Woverloaded-virtual false positive [PR87729]
Date: Mon, 25 Jul 2022 09:23:35 -0400	[thread overview]
Message-ID: <20220725132335.1106242-1-jason@redhat.com> (raw)

My attempt to shortcut unnecessary checking after finding a match was
also wrong for multiple inheritance, so let's give up on it.

Tested x86_64-pc-linux-gnu, applying to trunk.

	PR c++/87729

gcc/cp/ChangeLog:

	* class.cc (warn_hidden): Remove shortcut.

gcc/testsuite/ChangeLog:

	* g++.dg/warn/Woverloaded-virt4.C: New test.
---
 gcc/cp/class.cc                               | 11 +++++++----
 gcc/testsuite/g++.dg/warn/Woverloaded-virt4.C |  7 +++++++
 2 files changed, 14 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/warn/Woverloaded-virt4.C

diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc
index eb69e7f985c..a12d3673b96 100644
--- a/gcc/cp/class.cc
+++ b/gcc/cp/class.cc
@@ -3040,22 +3040,25 @@ warn_hidden (tree t)
 	bool seen_non_override = false;
 	for (tree fndecl : ovl_range (fns))
 	  {
+	    bool any_override = false;
 	    if (TREE_CODE (fndecl) == FUNCTION_DECL
 		&& DECL_VINDEX (fndecl))
 	      {
 		/* If the method from the base class has the same
 		   signature as the method from the derived class, it
-		   has been overridden.  */
+		   has been overridden.  Note that we can't move on
+		   after finding one match: fndecl might override
+		   multiple base fns.  */
 		for (size_t k = 0; k < base_fndecls.length (); k++)
 		  if (base_fndecls[k]
 		      && same_signature_p (fndecl, base_fndecls[k]))
 		    {
 		      base_fndecls[k] = NULL_TREE;
-		      goto next;
+		      any_override = true;
 		    }
 	      }
-	    seen_non_override = true;
-	  next:;
+	    if (!any_override)
+	      seen_non_override = true;
 	  }
 
 	if (!seen_non_override && warn_overloaded_virtual == 1)
diff --git a/gcc/testsuite/g++.dg/warn/Woverloaded-virt4.C b/gcc/testsuite/g++.dg/warn/Woverloaded-virt4.C
new file mode 100644
index 00000000000..b4d86689cf5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Woverloaded-virt4.C
@@ -0,0 +1,7 @@
+// PR c++/87729
+// { dg-additional-options -Woverloaded-virtual }
+
+struct S1 { virtual void f(); };
+struct S2: S1 {};
+struct S3: S1 {};
+struct S4: S2, S3 { void f(); };

base-commit: 718cf8d0bd32689192200d2156722167fd21a647
-- 
2.31.1


                 reply	other threads:[~2022-07-25 13:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220725132335.1106242-1-jason@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).