No Subject

Mark Mitchell mmitchell@usa.net
Tue Oct 7 21:35:00 GMT 1997


>>>>> "Miloslav" == Miloslav GRUNDMANN <grundman@mip.ups-tlse.fr> writes:

    Miloslav> // // gcc version egcs-2.90.10 970924 (gcc2-970802
    Miloslav> experimental) //

    Miloslav> template <class T > class X { public : bool
    Miloslav> operator==(int i) const { return true; }; };

    Miloslav> // this line causes the bug : template <class T > bool
    Miloslav> X<T>::operator==(int) const;

By the way, this is illegal, although g++ doesn't warn about it, even
with -pedantic.  You are not allowed to redeclare member functions
outside of the class, without a definition.  You are allowed to
explicitly instantiate a template, but that's not what you did.

None-the-less, the compiler shouldn't abort!  I've attached a patch
which fixes this problem.

    Miloslav> bool main() { X<int> a; return a==0; }

-- 
Mark Mitchell		mmitchell@usa.net
Stanford University	http://www.stanford.edu

Tue Oct  7 21:32:25 1997  Mark Mitchell  <mmitchell@usa.net>

	* decl.c (duplicate_decls): When declaring a function after it
has
	been defined, copy DECL_SAVED_TREE to the new declaration.

Index: decl.c
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/decl.c,v
retrieving revision 1.11
diff -c -p -r1.11 decl.c
*** decl.c	1997/10/05 00:46:26	1.11
--- decl.c	1997/10/08 04:31:35
*************** duplicate_decls (newdecl, olddecl)
*** 2805,2810 ****
--- 2805,2816 ----
	  && DECL_INITIAL (olddecl) != NULL_TREE)
	{
	  DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
+	  if (DECL_LANG_SPECIFIC (olddecl)) 
+	    {
+	      my_friendly_assert (DECL_LANG_SPECIFIC (newdecl) != 0,
+				  0);
+	      DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
+	    }
	  DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl);
	  DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl);
	}



More information about the Gcc-bugs mailing list