This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PR c++/17816] report redefinition of pure virtual functions


The attached patch fixes the problem reported in the testcase included
in the patch file.  I'm tempted to install as obvious, but...  Ok to
install if it passes regression testing?

Index: gcc/cp/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR c++/17816
	* decl.c (redeclaration_error_message): Report redefinition of
	pure virtual function.

Index: gcc/cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1359
diff -u -p -r1.1359 decl.c
--- gcc/cp/decl.c 1 Feb 2005 01:01:09 -0000 1.1359
+++ gcc/cp/decl.c 9 Feb 2005 13:01:28 -0000
@@ -1913,7 +1913,8 @@ redeclaration_error_message (tree newdec
       /* If this is a pure function, its olddecl will actually be
 	 the original initialization to `0' (which we force to call
 	 abort()).  Don't complain about redefinition in this case.  */
-      if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl))
+      if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
+	  && DECL_INITIAL (olddecl) == NULL_TREE)
 	return 0;
 
       /* If both functions come from different namespaces, this is not
Index: gcc/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR c++/17816
	* g++.dg/other/redecl2.C: New.

Index: gcc/testsuite/g++.dg/other/redecl2.C
===================================================================
RCS file: gcc/testsuite/g++.dg/other/redecl2.C
diff -N gcc/testsuite/g++.dg/other/redecl2.C
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/g++.dg/other/redecl2.C 9 Feb 2005 13:01:46 -0000
@@ -0,0 +1,11 @@
+// PR c++/17816
+// We failed to report duplicate definitions of pure virtual ns.
+
+// { dg-do compile }
+
+struct S {
+  virtual int foo() = 0;
+};
+ 
+int S::foo() { return 0; } // { dg-error "defined here" }
+int S::foo() { return 0; } // { dg-error "duplicate" }
-- 
Alexandre Oliva             http://www.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]