Patchwork C++ PATCH for c++/45473 (ICE with base virtual function named the same as derived class)

login
register
mail settings
Submitter Jason Merrill
Date Nov. 6, 2010, 1:43 a.m.
Message ID <4CD4B2BC.2090709@redhat.com>
Download mbox | patch
Permalink /patch/70318/
State New
Headers show

Comments

Jason Merrill - Nov. 6, 2010, 1:43 a.m.
In this testcase, we've always (at least as far back as 2.95) treated 
B::B() as overriding A::B(), which is wrong; constructors do not have 
names, so they cannot have the same name as a virtual function.

I was worried that this was going to be an ABI issue, but fortunately 
the testcase never actually compiled; past GCC versions emitted 
ill-formed assembly.

Tested x86_64-pc-linux-gnu, applied to trunk.
commit 650267e2d691dd2c42049a0214a6f691e72cb8e3
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Nov 5 20:40:28 2010 -0400

    	PR c++/45473
    	* search.c (look_for_overrides): A constructor is never virtual.

Patch

diff --git a/gcc/cp/search.c b/gcc/cp/search.c
index 0249fb0..76bf47c 100644
--- a/gcc/cp/search.c
+++ b/gcc/cp/search.c
@@ -1935,6 +1935,9 @@  look_for_overrides (tree type, tree fndecl)
   int ix;
   int found = 0;
 
+  if (DECL_CONSTRUCTOR_P (fndecl))
+    return 0;
+
   for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
     {
       tree basetype = BINFO_TYPE (base_binfo);
diff --git a/gcc/testsuite/g++.dg/inherit/virtual6.C b/gcc/testsuite/g++.dg/inherit/virtual6.C
new file mode 100644
index 0000000..f036969
--- /dev/null
+++ b/gcc/testsuite/g++.dg/inherit/virtual6.C
@@ -0,0 +1,15 @@ 
+// PR c++/45473
+
+struct A
+{
+  virtual void B ();
+};
+
+struct B : A
+{
+  B ();
+};
+
+struct C : B
+{
+};